summaryrefslogtreecommitdiff
blob: 4e98e155ba6f9dd4b5466cde09be98efd580b185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function( $, customize ){
	/**
	 * Helper function to qet a control by ID
	 * @param  {string} controlId Control ID
	 * @return {object}           jQuery object of the container
	 */
	function _getControl ( controlId ) {
		var control = customize.control.value( controlId );
		if ( control ) {
			return control.container;
		}
		return null;
	}

	/**
	 * Add some labels that the default checkbox controls don't allow.
	 * Add CSS Revisions and CSS Help links.
	 */
	$(document).ready( function(){
		var cssModeControl = _getControl( 'jetpack_css_mode_control' );
		if ( cssModeControl ) {
			cssModeControl.prepend( '<span class="customize-control-title">' + window._jp_css_settings.l10n.mode + '</span>' );
		}

		var mobileCssControl = _getControl( 'jetpack_mobile_css_control' );
		if ( mobileCssControl ) {
			mobileCssControl.prepend( '<span class="customize-control-title">' + window._jp_css_settings.l10n.mobile + '</span>' );
		}

		var widthControl = _getControl( 'wpcom_custom_css_content_width_control' );
		if ( widthControl ) {
			widthControl.append( '<span class="description">' + window._jp_css_settings.l10n.contentWidth + '<span>' );
			widthControl.find( 'input' ).after( '<span>px</span>' );
		}

		$( '<div />', {
			id      : 'css-help-links',
			'class' : 'css-help'
		}).appendTo( _getControl( 'custom_css' ) );

		$( '<a />', {
			id     : 'help-link',
			target : '_blank',
			href   : window._jp_css_settings.cssHelpUrl,
			text   : window._jp_css_settings.l10n.css_help_title
		}).prependTo( '#css-help-links' );

		// Only show the revisions link if there are revisions
		if ( window._jp_css_settings.areThereCssRevisions ) {
			$( '<a />', {
				id     : 'revisions-link',
				target : '_blank',
				href   : window._jp_css_settings.revisionsUrl,
				text   : window._jp_css_settings.l10n.revisions
			}).prependTo( '#css-help-links' );
		}

		customize( 'jetpack_custom_css[preprocessor]', function( preprocessorSetting ) {
			preprocessorSetting.bind( function( curr ) {
				var preprocessor_modes = {
						'default' : 'text/css',
						less      : 'text/x-less',
						sass      : 'text/x-scss'
					},
					new_mode = 'text/css';

				if ( 'undefined' !== typeof preprocessor_modes[ curr ] ) {
					new_mode = preprocessor_modes[ curr ];
				}

				customize.control( 'custom_css' ).deferred.codemirror.done( function ( cm ) {
					cm.setOption( 'mode', new_mode );
					if ( 'text/css' === new_mode ) {
						cm.setOption( 'lint', true );
					} else {
						cm.setOption( 'lint', false );
					}
				});
			});
		});
	});

})( jQuery, this.wp.customize );