From b198c61062fcf5ecae18252e4f12c9fc1aabd385 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Wed, 29 Feb 2012 06:18:17 +0000 Subject: [PATCH] Theme Customizer: Trigger UI updates only when necessary. git-svn-id: http://svn.automattic.com/wordpress/trunk@20034 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/customize-base.dev.js | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/wp-includes/js/customize-base.dev.js b/wp-includes/js/customize-base.dev.js index 5b5a67fd9c..3a656ce7b6 100644 --- a/wp-includes/js/customize-base.dev.js +++ b/wp-includes/js/customize-base.dev.js @@ -280,21 +280,11 @@ if ( typeof wp === 'undefined' ) return typeof element == 'string' ? $( element ) : element; }; - sync = { - 'val': { - update: function() { - this.element[ this._updater ]( this._value ); - }, - refresh: function() { - this.set( this.element[ this._refresher ]() ); - } - } - } - api.Element = api.Value.extend({ initialize: function( element, options ) { - var synchronizer = api.Element.synchronizer.html, - type; + var self = this, + synchronizer = api.Element.synchronizer.html, + type, update, refresh; this.element = api.ensure( element ); this.events = ''; @@ -315,9 +305,18 @@ if ( typeof wp === 'undefined' ) api.Value.prototype.initialize.call( this, null, $.extend( options || {}, synchronizer ) ); this._value = this.get(); - this.bind( this.update ); + update = this.update; + refresh = this.refresh; - this.refresh = $.proxy( this.refresh, this ); + this.update = function( to ) { + if ( to !== refresh.call( self ) ) + update.apply( this, arguments ); + }; + this.refresh = function() { + self.set( refresh.call( self ) ); + }; + + this.bind( this.update ); this.element.bind( this.events, this.refresh ); }, @@ -337,7 +336,7 @@ if ( typeof wp === 'undefined' ) this.element[ method ]( to ); }, refresh: function() { - this.set( this.element[ method ]() ); + return this.element[ method ](); } }; }); @@ -347,7 +346,7 @@ if ( typeof wp === 'undefined' ) this.element.prop( 'checked', to ); }, refresh: function() { - this.set( this.element.prop( 'checked' ) ); + return this.element.prop( 'checked' ); } }; @@ -358,7 +357,7 @@ if ( typeof wp === 'undefined' ) }).prop( 'checked', true ); }, refresh: function() { - this.set( this.element.filter( ':checked' ).val() ); + return this.element.filter( ':checked' ).val(); } };