[wp-trac] [WordPress Trac] #33507: Allow widget controls to be JS-driven
WordPress Trac
noreply at wordpress.org
Sat Aug 22 05:53:31 UTC 2015
#33507: Allow widget controls to be JS-driven
-------------------------+--------------------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.4
Component: Widgets | Version: 3.9
Severity: normal | Resolution:
Keywords: | Focuses: javascript, performance
-------------------------+--------------------------------------
Comment (by westonruter):
Aside: we need to make it easier to work with setting values that are
objects. The usual pattern to update a setting with an object value is:
{{{#!js
var value = wp.customize( 'foo' ).get();
value = _.clone( value );
value.someProperty = 'bar';
wp.customize( 'foo' ).set( value );
}}}
The cloning is needed because objects are passed by reference. So
`Setting.set( value )` should be updated to automatically clone any object
passed as its value argument, so you could replace the above with:
{{{#!js
wp.customize( 'foo' ).set( $.extend(
{},
wp.customize( 'foo' ).get(),
{ someProperty: 'bar' }
) );
}}}
We could also consider adding a `Setting.extend( obj )` which would take
any properties in `obj` and set them on the existing cloned value, in a
way similar to `jQuery.extend()`. You could then replace the above with:
{{{#!js
wp.customize( 'foo' ).extend( { someProperty: 'bar' } );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33507#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list