<!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>[40941] trunk: Widgets: Add accessibility mode support for TinyMCE-enhanced Text and Media widgets (Video, Audio, Images).</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/40941">40941</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/40941","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-06-25 18:47:13 +0000 (Sun, 25 Jun 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'>Widgets: Add accessibility mode support for TinyMCE-enhanced Text and Media widgets (Video, Audio, Images).
Amends <a href="https://core.trac.wordpress.org/changeset/40640">[40640]</a>, <a href="https://core.trac.wordpress.org/changeset/40631">[40631]</a>.
Props westonruter, afercia.
See <a href="https://core.trac.wordpress.org/ticket/35243">#35243</a>, <a href="https://core.trac.wordpress.org/ticket/32417">#32417</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/40986">#40986</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjswidgetsmediawidgetsjs">trunk/src/wp-admin/js/widgets/media-widgets.js</a></li>
<li><a href="#trunksrcwpadminjswidgetstextwidgetsjs">trunk/src/wp-admin/js/widgets/text-widgets.js</a></li>
<li><a href="#trunktestsqunitwpadminjswidgetstestmediaimagewidgetjs">trunk/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js</a></li>
<li><a href="#trunktestsqunitwpadminjswidgetstestmediavideowidgetjs">trunk/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjswidgetsmediawidgetsjs"></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/media-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/media-widgets.js 2017-06-25 18:45:33 UTC (rev 40940)
+++ trunk/src/wp-admin/js/widgets/media-widgets.js 2017-06-25 18:47:13 UTC (rev 40941)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -435,7 +435,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param {Object} options - Options.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param {Backbone.Model} options.model - Model.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param {jQuery} options.el - Control container element.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param {jQuery} options.el - Control field container element.
+ * @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
</ins><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"> initialize: function initialize( options ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -443,13 +444,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Backbone.View.prototype.initialize.call( control, options );
</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.el ) {
- throw new Error( 'Missing options.el' );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! ( control.model instanceof component.MediaWidgetModel ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error( 'Missing options.model' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! options.el ) {
+ throw new Error( 'Missing options.el' );
+ }
+ if ( ! options.syncContainer ) {
+ throw new Error( 'Missing options.syncContainer' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.syncContainer = options.syncContainer;
+
+ control.$el.addClass( 'media-widget-control' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Allow methods to be passed in with control context preserved.
</span><span class="cx" style="display: block; padding: 0 10px"> _.bindAll( control, 'syncModelToInputs', 'render', 'updateSelectedAttachment', 'renderPreview' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -553,7 +561,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> syncModelToInputs: function syncModelToInputs() {
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- control.$el.next( '.widget-content' ).find( '.media-widget-instance-property' ).each( function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.syncContainer.find( '.media-widget-instance-property' ).each( function() {
</ins><span class="cx" style="display: block; padding: 0 10px"> var input = $( this ), value;
</span><span class="cx" style="display: block; padding: 0 10px"> value = control.model.get( input.data( 'property' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( _.isUndefined( value ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1009,9 +1017,8 @@
</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"> component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var widgetContent, controlContainer, widgetForm, idBase, ControlConstructor, ModelConstructor, modelAttributes, widgetControl, widgetModel, widgetId, widgetInside, animatedCheckDelay = 50, renderWhenAnimationDone;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var fieldContainer, syncContainer, widgetForm, idBase, ControlConstructor, ModelConstructor, modelAttributes, widgetControl, widgetModel, widgetId, widgetInside, animatedCheckDelay = 50, renderWhenAnimationDone;
</ins><span class="cx" style="display: block; padding: 0 10px"> widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- widgetContent = widgetForm.find( '> .widget-content' );
</del><span class="cx" style="display: block; padding: 0 10px"> idBase = widgetForm.find( '> .id_base' ).val();
</span><span class="cx" style="display: block; padding: 0 10px"> widgetId = widgetForm.find( '> .widget-id' ).val();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1038,8 +1045,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * components", the JS template is rendered outside of the normal form
</span><span class="cx" style="display: block; padding: 0 10px"> * container.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- controlContainer = $( '<div class="media-widget-control"></div>' );
- widgetContent.before( controlContainer );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ fieldContainer = $( '<div></div>' );
+ syncContainer = widgetContainer.find( '.widget-content:first' );
+ syncContainer.before( fieldContainer );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * Sync the widget instance model attributes onto the hidden inputs that widgets currently use to store the state.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1047,7 +1055,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * from the start, without having to sync with hidden fields. See <https://core.trac.wordpress.org/ticket/33507>.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> modelAttributes = {};
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- widgetContent.find( '.media-widget-instance-property' ).each( function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ syncContainer.find( '.media-widget-instance-property' ).each( function() {
</ins><span class="cx" style="display: block; padding: 0 10px"> var input = $( this );
</span><span class="cx" style="display: block; padding: 0 10px"> modelAttributes[ input.data( 'property' ) ] = input.val();
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1056,7 +1064,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> widgetModel = new ModelConstructor( modelAttributes );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> widgetControl = new ControlConstructor({
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- el: controlContainer,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: fieldContainer,
+ syncContainer: syncContainer,
</ins><span class="cx" style="display: block; padding: 0 10px"> model: widgetModel
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1085,6 +1094,51 @@
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Setup widget in accessibility mode.
+ *
+ * @returns {void}
+ */
+ component.setupAccessibleMode = function setupAccessibleMode() {
+ var widgetForm, widgetId, idBase, widgetControl, ControlConstructor, ModelConstructor, modelAttributes, fieldContainer, syncContainer;
+ widgetForm = $( '.editwidget > form' );
+ if ( 0 === widgetForm.length ) {
+ return;
+ }
+
+ idBase = widgetForm.find( '> .widget-control-actions > .id_base' ).val();
+
+ ControlConstructor = component.controlConstructors[ idBase ];
+ if ( ! ControlConstructor ) {
+ return;
+ }
+
+ widgetId = widgetForm.find( '> .widget-control-actions > .widget-id' ).val();
+
+ ModelConstructor = component.modelConstructors[ idBase ] || component.MediaWidgetModel;
+ fieldContainer = $( '<div></div>' );
+ syncContainer = widgetForm.find( '> .widget-inside' );
+ syncContainer.before( fieldContainer );
+
+ modelAttributes = {};
+ syncContainer.find( '.media-widget-instance-property' ).each( function() {
+ var input = $( this );
+ modelAttributes[ input.data( 'property' ) ] = input.val();
+ });
+ modelAttributes.widget_id = widgetId;
+
+ widgetControl = new ControlConstructor({
+ el: fieldContainer,
+ syncContainer: syncContainer,
+ model: new ModelConstructor( modelAttributes )
+ });
+
+ component.modelCollection.add( [ widgetControl.model ] );
+ component.widgetControls[ widgetControl.model.get( 'widget_id' ) ] = widgetControl;
+
+ widgetControl.render();
+ };
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Sync widget instance data sanitized from server back onto widget model.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * This gets called via the 'widget-updated' event when saving a widget from
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1152,6 +1206,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var widgetContainer = $( this );
</span><span class="cx" style="display: block; padding: 0 10px"> component.handleWidgetAdded( new jQuery.Event( 'widget-added' ), widgetContainer );
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Accessibility mode.
+ $( window ).on( 'load', function() {
+ component.setupAccessibleMode();
+ });
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</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="trunksrcwpadminjswidgetstextwidgetsjs"></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/text-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/text-widgets.js 2017-06-25 18:45:33 UTC (rev 40940)
+++ trunk/src/wp-admin/js/widgets/text-widgets.js 2017-06-25 18:47:13 UTC (rev 40941)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -24,9 +24,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Initialize.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param {Object} options - Options.
- * @param {Backbone.Model} options.model - Model.
- * @param {jQuery} options.el - Control container element.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param {Object} options - Options.
+ * @param {jQuery} options.el - Control field container element.
+ * @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
</ins><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"> initialize: function initialize( options ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -35,34 +35,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! options.el ) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new Error( 'Missing options.el' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! options.syncContainer ) {
+ throw new Error( 'Missing options.syncContainer' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Backbone.View.prototype.initialize.call( control, options );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.syncContainer = options.syncContainer;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * Create a container element for the widget control fields.
- * This is inserted into the DOM immediately before the the .widget-content
- * element because the contents of this element are essentially "managed"
- * by PHP, where each widget update cause the entire element to be emptied
- * and replaced with the rendered output of WP_Widget::form() which is
- * sent back in Ajax request made to save/update the widget instance.
- * To prevent a "flash of replaced DOM elements and re-initialized JS
- * components", the JS template is rendered outside of the normal form
- * container.
- */
- control.fieldContainer = $( '<div class="text-widget-fields"></div>' );
- control.fieldContainer.html( wp.template( 'widget-text-control-fields' ) );
- control.widgetContentContainer = control.$el.find( '.widget-content:first' );
- control.widgetContentContainer.before( control.fieldContainer );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.$el.addClass( 'text-widget-fields' );
+ control.$el.html( wp.template( 'widget-text-control-fields' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> control.fields = {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- title: control.fieldContainer.find( '.title' ),
- text: control.fieldContainer.find( '.text' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ title: control.$el.find( '.title' ),
+ text: control.$el.find( '.text' )
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Sync input fields to hidden sync fields which actually get sent to the server.
</span><span class="cx" style="display: block; padding: 0 10px"> _.each( control.fields, function( fieldInput, fieldName ) {
</span><span class="cx" style="display: block; padding: 0 10px"> fieldInput.on( 'input change', function updateSyncField() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var syncInput = control.widgetContentContainer.find( 'input[type=hidden].' + fieldName );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var syncInput = control.syncContainer.find( 'input[type=hidden].' + fieldName );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( syncInput.val() !== $( this ).val() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> syncInput.val( $( this ).val() );
</span><span class="cx" style="display: block; padding: 0 10px"> syncInput.trigger( 'change' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,7 +61,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Note that syncInput cannot be re-used because it will be destroyed with each widget-updated event.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- fieldInput.val( control.widgetContentContainer.find( 'input[type=hidden].' + fieldName ).val() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ fieldInput.val( control.syncContainer.find( 'input[type=hidden].' + fieldName ).val() );
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,11 +78,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this, syncInput;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! control.fields.title.is( document.activeElement ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- syncInput = control.widgetContentContainer.find( 'input[type=hidden].title' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ syncInput = control.syncContainer.find( 'input[type=hidden].title' );
</ins><span class="cx" style="display: block; padding: 0 10px"> control.fields.title.val( syncInput.val() );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- syncInput = control.widgetContentContainer.find( 'input[type=hidden].text' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ syncInput = control.syncContainer.find( 'input[type=hidden].text' );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( control.fields.text.is( ':visible' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! control.fields.text.is( document.activeElement ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> control.fields.text.val( syncInput.val() );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -219,7 +210,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"> component.handleWidgetAdded = function handleWidgetAdded( event, widgetContainer ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, widgetInside, renderWhenAnimationDone;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var widgetForm, idBase, widgetControl, widgetId, animatedCheckDelay = 50, widgetInside, renderWhenAnimationDone, fieldContainer, syncContainer;
</ins><span class="cx" style="display: block; padding: 0 10px"> widgetForm = widgetContainer.find( '> .widget-inside > .form, > .widget-inside > form' ); // Note: '.form' appears in the customizer, whereas 'form' on the widgets admin screen.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> idBase = widgetForm.find( '> .id_base' ).val();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -228,13 +219,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Prevent initializing already-added widgets.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- widgetId = widgetForm.find( '> .widget-id' ).val();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ widgetId = widgetForm.find( '.widget-id' ).val();
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( component.widgetControls[ widgetId ] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Create a container element for the widget control fields.
+ * This is inserted into the DOM immediately before the the .widget-content
+ * element because the contents of this element are essentially "managed"
+ * by PHP, where each widget update cause the entire element to be emptied
+ * and replaced with the rendered output of WP_Widget::form() which is
+ * sent back in Ajax request made to save/update the widget instance.
+ * To prevent a "flash of replaced DOM elements and re-initialized JS
+ * components", the JS template is rendered outside of the normal form
+ * container.
+ */
+ fieldContainer = $( '<div></div>' );
+ syncContainer = widgetContainer.find( '.widget-content:first' );
+ syncContainer.before( fieldContainer );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> widgetControl = new component.TextWidgetControl({
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- el: widgetContainer
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: fieldContainer,
+ syncContainer: syncContainer
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> component.widgetControls[ widgetId ] = widgetControl;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -257,6 +264,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Setup widget in accessibility mode.
+ *
+ * @returns {void}
+ */
+ component.setupAccessibleMode = function setupAccessibleMode() {
+ var widgetForm, idBase, widgetControl, fieldContainer, syncContainer;
+ widgetForm = $( '.editwidget > form' );
+ if ( 0 === widgetForm.length ) {
+ return;
+ }
+
+ idBase = widgetForm.find( '> .widget-control-actions > .id_base' ).val();
+ if ( 'text' !== idBase ) {
+ return;
+ }
+
+ fieldContainer = $( '<div></div>' );
+ syncContainer = widgetForm.find( '> .widget-inside' );
+ syncContainer.before( fieldContainer );
+
+ widgetControl = new component.TextWidgetControl({
+ el: fieldContainer,
+ syncContainer: syncContainer
+ });
+
+ widgetControl.initializeEditor();
+ };
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Sync widget instance data sanitized from server back onto widget model.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * This gets called via the 'widget-updated' event when saving a widget from
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -319,6 +355,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var widgetContainer = $( this );
</span><span class="cx" style="display: block; padding: 0 10px"> component.handleWidgetAdded( new jQuery.Event( 'widget-added' ), widgetContainer );
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Accessibility mode.
+ $( window ).on( 'load', function() {
+ component.setupAccessibleMode();
+ });
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</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="trunktestsqunitwpadminjswidgetstestmediaimagewidgetjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js 2017-06-25 18:45:33 UTC (rev 40940)
+++ trunk/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js 2017-06-25 18:47:13 UTC (rev 40941)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> imageWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_image();
</span><span class="cx" style="display: block; padding: 0 10px"> imageWidgetControlInstance = new ImageWidgetControl({
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: jQuery( '<div></div>' ),
+ syncContainer: jQuery( '<div></div>' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> model: imageWidgetModelInstance
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -84,6 +86,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> imageWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_image();
</span><span class="cx" style="display: block; padding: 0 10px"> imageWidgetControlInstance = new wp.mediaWidgets.controlConstructors.media_image({
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: jQuery( '<div></div>' ),
+ syncContainer: jQuery( '<div></div>' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> model: imageWidgetModelInstance
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> equal( imageWidgetControlInstance.$el.find( 'img' ).length, 0, 'No images should be rendered' );
</span></span></pre></div>
<a id="trunktestsqunitwpadminjswidgetstestmediavideowidgetjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js 2017-06-25 18:45:33 UTC (rev 40940)
+++ trunk/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js 2017-06-25 18:47:13 UTC (rev 40941)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> videoWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_video();
</span><span class="cx" style="display: block; padding: 0 10px"> videoWidgetControlInstance = new VideoWidgetControl({
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: jQuery( '<div></div>' ),
+ syncContainer: jQuery( '<div></div>' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> model: videoWidgetModelInstance
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,6 +48,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> videoWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_video();
</span><span class="cx" style="display: block; padding: 0 10px"> videoWidgetControlInstance = new wp.mediaWidgets.controlConstructors.media_video({
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ el: jQuery( '<div></div>' ),
+ syncContainer: jQuery( '<div></div>' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> model: videoWidgetModelInstance
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> equal( videoWidgetControlInstance.$el.find( 'a' ).length, 0, 'No video links should be rendered' );
</span></span></pre>
</div>
</div>
</body>
</html>