<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41957] trunk: Code Editor: Improve ability to create Customizer `CodeEditorControl` instances in JS, lessening PHP dependencies.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41957">41957</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41957","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-10-20 16:38:35 +0000 (Fri, 20 Oct 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Code Editor: Improve ability to create Customizer `CodeEditorControl` instances in JS, lessening PHP dependencies.
Allow `CodeEditorControl` to be instantiated with a `editor_settings` param which is merged with `wp.codeEditor.defaultSettings`.
Also:
* Turn redundant "CSS Code" control label into screen reader text for Additional CSS.
* Remove `code-editor` as script dependency for `custom-html-widgets` since enqueueing is determined by `wp_enqueue_code_editor()`.
* Remove useless exporting of `code_type` param to JS in `WP_Customize_Code_Editor_Control`.
* Add `disabled` class to Custom HTML widget's Save button when linting errors are present.
* Remove redundant `span` inside CodeEditorControl's `label`.
See <a href="https://core.trac.wordpress.org/ticket/41897">#41897</a>, <a href="https://core.trac.wordpress.org/ticket/12423">#12423</a>, <a href="https://core.trac.wordpress.org/ticket/41872">#41872</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjscustomizecontrolsjs">trunk/src/wp-admin/js/customize-controls.js</a></li>
<li><a href="#trunksrcwpadminjswidgetscustomhtmlwidgetsjs">trunk/src/wp-admin/js/widgets/custom-html-widgets.js</a></li>
<li><a href="#trunksrcwpincludescustomizeclasswpcustomizecodeeditorcontrolphp">trunk/src/wp-includes/customize/class-wp-customize-code-editor-control.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunktestsphpunittestswidgetscustomhtmlwidgetphp">trunk/tests/phpunit/tests/widgets/custom-html-widget.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjscustomizecontrolsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-controls.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-controls.js 2017-10-20 14:06:42 UTC (rev 41956)
+++ trunk/src/wp-admin/js/customize-controls.js 2017-10-20 16:38:35 UTC (rev 41957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5152,15 +5152,43 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @returns {void}
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> initEditor: function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var control = this, element;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var control = this, element, editorSettings = false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Obtain editorSettings for instantiation.
+ if ( wp.codeEditor && ( _.isUndefined( control.params.editor_settings ) || false !== control.params.editor_settings ) ) {
+
+ // Obtain default editor settings.
+ editorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {};
+ editorSettings.codemirror = _.extend(
+ {},
+ editorSettings.codemirror,
+ {
+ indentUnit: 2,
+ tabSize: 2
+ }
+ );
+
+ // Merge editor_settings param on top of defaults.
+ if ( _.isObject( control.params.editor_settings ) ) {
+ _.each( control.params.editor_settings, function( value, key ) {
+ if ( _.isObject( value ) ) {
+ editorSettings[ key ] = _.extend(
+ {},
+ editorSettings[ key ],
+ value
+ );
+ }
+ } );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> element = new api.Element( control.container.find( 'textarea' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> control.elements.push( element );
</span><span class="cx" style="display: block; padding: 0 10px"> element.sync( control.setting );
</span><span class="cx" style="display: block; padding: 0 10px"> element.set( control.setting() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( control.params.editor_settings ) {
- control.initSyntaxHighlightingEditor( control.params.editor_settings );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( editorSettings ) {
+ control.initSyntaxHighlightingEditor( editorSettings );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> control.initPlainTextareaEditor();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8839,6 +8867,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> sectionReady.done( function setupSectionDescription( section ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var control = api.control( 'custom_css' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Hide redundant label for visual users.
+ control.container.find( '.customize-control-title:first' ).addClass( 'screen-reader-text' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Close the section description when clicking the close button.
</span><span class="cx" style="display: block; padding: 0 10px"> section.container.find( '.section-description-buttons .section-description-close' ).on( 'click', function() {
</span><span class="cx" style="display: block; padding: 0 10px"> section.container.find( '.section-meta .customize-section-description:first' )
</span></span></pre></div>
<a id="trunksrcwpadminjswidgetscustomhtmlwidgetsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/widgets/custom-html-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/custom-html-widgets.js 2017-10-20 14:06:42 UTC (rev 41956)
+++ trunk/src/wp-admin/js/widgets/custom-html-widgets.js 2017-10-20 16:38:35 UTC (rev 41957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -204,7 +204,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @returns {void}
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> onUpdateErrorNotice: function onUpdateErrorNotice( errorAnnotations ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- control.saveButton.toggleClass( 'validation-blocked', errorAnnotations.length );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.saveButton.toggleClass( 'validation-blocked disabled', errorAnnotations.length );
</ins><span class="cx" style="display: block; padding: 0 10px"> control.updateErrorNotice( errorAnnotations );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span></span></pre></div>
<a id="trunksrcwpincludescustomizeclasswpcustomizecodeeditorcontrolphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/customize/class-wp-customize-code-editor-control.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/customize/class-wp-customize-code-editor-control.php 2017-10-20 14:06:42 UTC (rev 41956)
+++ trunk/src/wp-includes/customize/class-wp-customize-code-editor-control.php 2017-10-20 16:38:35 UTC (rev 41957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,7 +69,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function json() {
</span><span class="cx" style="display: block; padding: 0 10px"> $json = parent::json();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $json['code_type'] = $this->code_type;
</del><span class="cx" style="display: block; padding: 0 10px"> $json['editor_settings'] = $this->editor_settings;
</span><span class="cx" style="display: block; padding: 0 10px"> $json['input_attrs'] = $this->input_attrs;
</span><span class="cx" style="display: block; padding: 0 10px"> return $json;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,8 +90,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <# var elementIdPrefix = 'el' + String( Math.random() ); #>
</span><span class="cx" style="display: block; padding: 0 10px"> <# if ( data.label ) { #>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <label for="{{ elementIdPrefix }}_editor">
- <span class="customize-control-title">{{ data.label }}</span>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <label for="{{ elementIdPrefix }}_editor" class="customize-control-title">
+ {{ data.label }}
</ins><span class="cx" style="display: block; padding: 0 10px"> </label>
</span><span class="cx" style="display: block; padding: 0 10px"> <# } #>
</span><span class="cx" style="display: block; padding: 0 10px"> <# if ( data.description ) { #>
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php 2017-10-20 14:06:42 UTC (rev 41956)
+++ trunk/src/wp-includes/script-loader.php 2017-10-20 16:38:35 UTC (rev 41957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -720,7 +720,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'media-gallery-widget', "/wp-admin/js/widgets/media-gallery-widget$suffix.js", array( 'media-widgets' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'code-editor', 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestswidgetscustomhtmlwidgetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/widgets/custom-html-widget.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/widgets/custom-html-widget.php 2017-10-20 14:06:42 UTC (rev 41956)
+++ trunk/tests/phpunit/tests/widgets/custom-html-widget.php 2017-10-20 16:38:35 UTC (rev 41957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -263,8 +263,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $widget->enqueue_admin_scripts();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( wp_script_is( 'custom-html-widgets', 'enqueued' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( wp_script_is( 'code-editor', 'enqueued' ) );
- $this->assertTrue( wp_script_is( 'wp-codemirror', 'enqueued' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFalse( wp_script_is( 'code-editor', 'enqueued' ) );
+ $this->assertFalse( wp_script_is( 'wp-codemirror', 'enqueued' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( wp_script_is( 'csslint', 'enqueued' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( wp_script_is( 'jshint', 'enqueued' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( wp_script_is( 'htmlhint', 'enqueued' ) );
</span></span></pre>
</div>
</div>
</body>
</html>