Changeset 29450 for trunk/src/wp-includes/js/customize-base.js
- Timestamp:
- 08/08/2014 10:09:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/customize-base.js
r26702 r29450 2 2 3 3 (function( exports, $ ){ 4 var api , extend, ctor, inherits,4 var api = {}, ctor, inherits, 5 5 slice = Array.prototype.slice; 6 7 /* =====================================================================8 * Micro-inheritance - thank you, backbone.js.9 * ===================================================================== */10 11 extend = function( protoProps, classProps ) {12 var child = inherits( this, protoProps, classProps );13 child.extend = this.extend;14 return child;15 };16 6 17 7 // Shared empty constructor function to aid in prototype-chain creation. 18 8 ctor = function() {}; 19 9 20 // Helper function to correctly set up the prototype chain, for subclasses. 21 // Similar to `goog.inherits`, but uses a hash of prototype properties and 22 // class properties to be extended. 10 /** 11 * Helper function to correctly set up the prototype chain, for subclasses. 12 * Similar to `goog.inherits`, but uses a hash of prototype properties and 13 * class properties to be extended. 14 * 15 * @param object parent Parent class constructor to inherit from. 16 * @param object protoProps Properties to apply to the prototype for use as class instance properties. 17 * @param object staticProps Properties to apply directly to the class constructor. 18 * @return child The subclassed constructor. 19 */ 23 20 inherits = function( parent, protoProps, staticProps ) { 24 21 var child; … … 66 63 }; 67 64 68 api = {}; 69 70 /* ===================================================================== 71 * Base class. 72 * ===================================================================== */ 73 65 /** 66 * Base class for object inheritance. 67 */ 74 68 api.Class = function( applicator, argsArray, options ) { 75 69 var magic, args = arguments; … … 91 85 magic.initialize.apply( magic, args ); 92 86 return magic; 87 }; 88 89 /** 90 * Creates a subclass of the class. 91 * 92 * @param object protoProps Properties to apply to the prototype. 93 * @param object staticProps Properties to apply directly to the class. 94 * @return child The subclass. 95 */ 96 api.Class.extend = function( protoProps, classProps ) { 97 var child = inherits( this, protoProps, classProps ); 98 child.extend = this.extend; 99 return child; 93 100 }; 94 101 … … 117 124 }; 118 125 119 api.Class.extend = extend; 120 121 /* ===================================================================== 122 * Events mixin. 123 * ===================================================================== */ 124 126 /** 127 * An events manager object, offering the ability to bind to and trigger events. 128 * 129 * Used as a mixin. 130 */ 125 131 api.Events = { 126 132 trigger: function( id ) { … … 144 150 }; 145 151 146 /* =====================================================================152 /** 147 153 * Observable values that support two-way binding. 148 * ===================================================================== */ 149 154 * 155 * @constuctor 156 */ 150 157 api.Value = api.Class.extend({ 151 158 initialize: function( initial, options ) { … … 255 262 }); 256 263 257 /* =====================================================================264 /** 258 265 * A collection of observable values. 259 * ===================================================================== */ 260 266 * 267 * @constuctor 268 * @augments wp.customize.Class 269 * @mixes wp.customize.Events 270 */ 261 271 api.Values = api.Class.extend({ 262 272 defaultConstructor: api.Value, … … 380 390 $.extend( api.Values.prototype, api.Events ); 381 391 382 /* ===================================================================== 383 * An observable value that syncs with an element.384 * 385 * Handles inputs, selects, and textareas by default.386 * ===================================================================== */387 392 393 /** 394 * Cast a string to a jQuery collection if it isn't already. 395 * 396 * @param {string|jQuery collection} element 397 */ 388 398 api.ensure = function( element ) { 389 399 return typeof element == 'string' ? $( element ) : element; 390 400 }; 391 401 402 /** 403 * An observable value that syncs with an element. 404 * 405 * Handles inputs, selects, and textareas by default. 406 * 407 * @constuctor 408 * @augments wp.customize.Value 409 * @augments wp.customize.Class 410 */ 392 411 api.Element = api.Value.extend({ 393 412 initialize: function( element, options ) { … … 443 462 api.Element.synchronizer = {}; 444 463 445 $.each( [ 'html', 'val' ], function( i , method ) {464 $.each( [ 'html', 'val' ], function( index, method ) { 446 465 api.Element.synchronizer[ method ] = { 447 466 update: function( to ) { … … 474 493 }; 475 494 476 /* ===================================================================== 495 $.support.postMessage = !! window.postMessage; 496 497 /** 477 498 * Messenger for postMessage. 478 * ===================================================================== */ 479 480 $.support.postMessage = !! window.postMessage; 481 499 * 500 * @constuctor 501 * @augments wp.customize.Class 502 * @mixes wp.customize.Events 503 */ 482 504 api.Messenger = api.Class.extend({ 505 /** 506 * Create a new Value. 507 * 508 * @param {string} key Unique identifier. 509 * @param {mixed} initial Initial value. 510 * @param {mixed} options Options hash. Optional. 511 * @return {Value} Class instance of the Value. 512 */ 483 513 add: function( key, initial, options ) { 484 514 return this[ key ] = new api.Value( initial, options ); … … 571 601 $.extend( api.Messenger.prototype, api.Events ); 572 602 573 /* ===================================================================== 574 * Core customize object. 575 * ===================================================================== */ 576 603 // Core customize object. 577 604 api = $.extend( new api.Values(), api ); 578 605 api.get = function() { … … 586 613 }; 587 614 588 // Expose the API to the world.615 // Expose the API publicly on window.wp.customize 589 616 exports.customize = api; 590 617 })( wp, jQuery );
Note: See TracChangeset
for help on using the changeset viewer.