wp/wp-includes/js/customize-base.js
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
window.wp = window.wp || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
(function( exports, $ ){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     4
	var api = {}, ctor, inherits,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
		slice = Array.prototype.slice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
	// Shared empty constructor function to aid in prototype-chain creation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
	ctor = function() {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
	 * Helper function to correctly set up the prototype chain, for subclasses.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
	 * Similar to `goog.inherits`, but uses a hash of prototype properties and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	 * class properties to be extended.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	 * @param  object parent      Parent class constructor to inherit from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	 * @param  object protoProps  Properties to apply to the prototype for use as class instance properties.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	 * @param  object staticProps Properties to apply directly to the class constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 * @return child              The subclassed constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	inherits = function( parent, protoProps, staticProps ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
		var child;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		// The constructor function for the new subclass is either defined by you
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		// (the "constructor" property in your `extend` definition), or defaulted
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		// by us to simply call `super()`.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		if ( protoProps && protoProps.hasOwnProperty( 'constructor' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
			child = protoProps.constructor;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
			child = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
				// Storing the result `super()` before returning the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
				// prevents a bug in Opera where, if the constructor returns
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
				// a function, Opera will reject the return value in favor of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
				// the original object. This causes all sorts of trouble.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
				var result = parent.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
				return result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		// Inherit class (static) properties from parent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		$.extend( child, parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		// Set the prototype chain to inherit from `parent`, without calling
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		// `parent`'s constructor function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		ctor.prototype  = parent.prototype;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		child.prototype = new ctor();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		// Add prototype properties (instance properties) to the subclass,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		// if supplied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		if ( protoProps )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			$.extend( child.prototype, protoProps );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		// Add static properties to the constructor function, if supplied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		if ( staticProps )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			$.extend( child, staticProps );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		// Correctly set child's `prototype.constructor`.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		child.prototype.constructor = child;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		// Set a convenience property in case the parent's prototype is needed later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		child.__super__ = parent.prototype;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		return child;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	 * Base class for object inheritance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	api.Class = function( applicator, argsArray, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		var magic, args = arguments;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		if ( applicator && argsArray && api.Class.applicator === applicator ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			args = argsArray;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
			$.extend( this, options || {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		magic = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		if ( this.instance ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			magic = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
				return magic.instance.apply( magic, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			$.extend( magic, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		magic.initialize.apply( magic, args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		return magic;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	 * Creates a subclass of the class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
	 * @param  object protoProps  Properties to apply to the prototype.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	 * @param  object staticProps Properties to apply directly to the class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
	 * @return child              The subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	api.Class.extend = function( protoProps, classProps ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
		var child = inherits( this, protoProps, classProps );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		child.extend = this.extend;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
		return child;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	api.Class.applicator = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	api.Class.prototype.initialize = function() {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 * Checks whether a given instance extended a constructor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 * The magic surrounding the instance parameter causes the instanceof
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * keyword to return inaccurate results; it defaults to the function's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 * prototype instead of the constructor chain. Hence this function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	api.Class.prototype.extended = function( constructor ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		var proto = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		while ( typeof proto.constructor !== 'undefined' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			if ( proto.constructor === constructor )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			if ( typeof proto.constructor.__super__ === 'undefined' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			proto = proto.constructor.__super__;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	 * An events manager object, offering the ability to bind to and trigger events.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
	 * Used as a mixin.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	api.Events = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		trigger: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			if ( this.topics && this.topics[ id ] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
				this.topics[ id ].fireWith( this, slice.call( arguments, 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		bind: function( id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			this.topics = this.topics || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
			this.topics[ id ] = this.topics[ id ] || $.Callbacks();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
			this.topics[ id ].add.apply( this.topics[ id ], slice.call( arguments, 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
		unbind: function( id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			if ( this.topics && this.topics[ id ] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
				this.topics[ id ].remove.apply( this.topics[ id ], slice.call( arguments, 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 * Observable values that support two-way binding.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	 * @constuctor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	api.Value = api.Class.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		initialize: function( initial, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			this._value = initial; // @todo: potentially change this to a this.set() call.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			this.callbacks = $.Callbacks();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
			this._dirty = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			$.extend( this, options || {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			this.set = $.proxy( this.set, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		 * Magic. Returns a function that will become the instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		 * Set to null to prevent the instance from extending a function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		instance: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
			return arguments.length ? this.set.apply( this, arguments ) : this.get();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		get: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			return this._value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		set: function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			var from = this._value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
			to = this._setter.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			to = this.validate( to );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			// Bail if the sanitized value is null or unchanged.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			if ( null === to || _.isEqual( from, to ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
				return this;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			this._value = to;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
			this._dirty = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
			this.callbacks.fireWith( this, [ to, from ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		_setter: function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			return to;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		setter: function( callback ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			var from = this.get();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			this._setter = callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			// Temporarily clear value so setter can decide if it's valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			this._value = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			this.set( from );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		resetSetter: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			this._setter = this.constructor.prototype._setter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			this.set( this.get() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		validate: function( value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			return value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
		bind: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			this.callbacks.add.apply( this.callbacks, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
		unbind: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			this.callbacks.remove.apply( this.callbacks, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		link: function() { // values*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			var set = this.set;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			$.each( arguments, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
				this.bind( set );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		unlink: function() { // values*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			var set = this.set;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			$.each( arguments, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
				this.unbind( set );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		sync: function() { // values*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			var that = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			$.each( arguments, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
				that.link( this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
				this.link( that );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		unsync: function() { // values*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
			var that = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
			$.each( arguments, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
				that.unlink( this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
				this.unlink( that );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	 * A collection of observable values.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	 * @constuctor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
	 * @augments wp.customize.Class
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
	 * @mixes wp.customize.Events
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	api.Values = api.Class.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		defaultConstructor: api.Value,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		initialize: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			$.extend( this, options || {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			this._value = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
			this._deferreds = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		instance: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			if ( arguments.length === 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
				return this.value( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			return this.when.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
		value: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			return this._value[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		has: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
			return typeof this._value[ id ] !== 'undefined';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		add: function( id, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
			if ( this.has( id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
				return this.value( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
			this._value[ id ] = value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
			value.parent = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			if ( value.extended( api.Value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				value.bind( this._change );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
			this.trigger( 'add', value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			if ( this._deferreds[ id ] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				this._deferreds[ id ].resolve();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
			return this._value[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		create: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
			return this.add( id, new this.defaultConstructor( api.Class.applicator, slice.call( arguments, 1 ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
		each: function( callback, context ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			context = typeof context === 'undefined' ? this : context;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			$.each( this._value, function( key, obj ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
				callback.call( context, obj, key );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		remove: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
			var value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
			if ( this.has( id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				value = this.value( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
				this.trigger( 'remove', value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
				if ( value.extended( api.Value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
					value.unbind( this._change );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
				delete value.parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
			delete this._value[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
			delete this._deferreds[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		 * Runs a callback once all requested values exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		 * when( ids*, [callback] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		 * For example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		 *     when( id1, id2, id3, function( value1, value2, value3 ) {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		 * @returns $.Deferred.promise();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		when: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			var self = this,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
				ids  = slice.call( arguments ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
				dfd  = $.Deferred();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
			// If the last argument is a callback, bind it to .done()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			if ( $.isFunction( ids[ ids.length - 1 ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
				dfd.done( ids.pop() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			$.when.apply( $, $.map( ids, function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
				if ( self.has( id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
				return self._deferreds[ id ] = self._deferreds[ id ] || $.Deferred();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			})).done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				var values = $.map( ids, function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
						return self( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				// If a value is missing, we've used at least one expired deferred.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
				// Call Values.when again to generate a new deferred.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				if ( values.length !== ids.length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
					// ids.push( callback );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
					self.when.apply( self, ids ).done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
						dfd.resolveWith( self, values );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
				dfd.resolveWith( self, values );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			return dfd.promise();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		_change: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
			this.parent.trigger( 'change', this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	$.extend( api.Values.prototype, api.Events );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
	 * Cast a string to a jQuery collection if it isn't already.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
	 * @param {string|jQuery collection} element
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	api.ensure = function( element ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
		return typeof element == 'string' ? $( element ) : element;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
	 * An observable value that syncs with an element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
	 * Handles inputs, selects, and textareas by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	 * @constuctor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	 * @augments wp.customize.Value
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	 * @augments wp.customize.Class
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	api.Element = api.Value.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		initialize: function( element, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			var self = this,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
				synchronizer = api.Element.synchronizer.html,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
				type, update, refresh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			this.element = api.ensure( element );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			this.events = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			if ( this.element.is('input, select, textarea') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
				this.events += 'change';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
				synchronizer = api.Element.synchronizer.val;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
				if ( this.element.is('input') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
					type = this.element.prop('type');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
					if ( api.Element.synchronizer[ type ] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
						synchronizer = api.Element.synchronizer[ type ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
					if ( 'text' === type || 'password' === type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
						this.events += ' keyup';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
					} else if ( 'range' === type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
						this.events += ' input propertychange';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
				} else if ( this.element.is('textarea') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
					this.events += ' keyup';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			api.Value.prototype.initialize.call( this, null, $.extend( options || {}, synchronizer ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
			this._value = this.get();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
			update  = this.update;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
			refresh = this.refresh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
			this.update = function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
				if ( to !== refresh.call( self ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
					update.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			this.refresh = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
				self.set( refresh.call( self ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
			this.bind( this.update );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			this.element.bind( this.events, this.refresh );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		find: function( selector ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			return $( selector, this.element );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
		refresh: function() {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		update: function() {}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	api.Element.synchronizer = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
	$.each( [ 'html', 'val' ], function( index, method ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
		api.Element.synchronizer[ method ] = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
			update: function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
				this.element[ method ]( to );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			refresh: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
				return this.element[ method ]();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	api.Element.synchronizer.checkbox = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		update: function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			this.element.prop( 'checked', to );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		refresh: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
			return this.element.prop( 'checked' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	api.Element.synchronizer.radio = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		update: function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
			this.element.filter( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
				return this.value === to;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			}).prop( 'checked', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		refresh: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
			return this.element.filter( ':checked' ).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	$.support.postMessage = !! window.postMessage;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
	 * Messenger for postMessage.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
	 * @constuctor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
	 * @augments wp.customize.Class
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
	 * @mixes wp.customize.Events
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	api.Messenger = api.Class.extend({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
		 * Create a new Value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
		 * @param  {string} key     Unique identifier.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
		 * @param  {mixed}  initial Initial value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
		 * @param  {mixed}  options Options hash. Optional.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
		 * @return {Value}          Class instance of the Value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		add: function( key, initial, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			return this[ key ] = new api.Value( initial, options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
		 * Initialize Messenger.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		 * @param  {object} params        Parameters to configure the messenger.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		 *         {string} .url          The URL to communicate with.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
		 *         {window} .targetWindow The window instance to communicate with. Default window.parent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
		 *         {string} .channel      If provided, will send the channel with each message and only accept messages a matching channel.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		 * @param  {object} options       Extend any instance parameter or method with this object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		initialize: function( params, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
			// Target the parent frame by default, but only if a parent frame exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
			var defaultTarget = window.parent == window ? null : window.parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
			$.extend( this, options || {} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
			this.add( 'channel', params.channel );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
			this.add( 'url', params.url || '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
			this.add( 'origin', this.url() ).link( this.url ).setter( function( to ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
				return to.replace( /([^:]+:\/\/[^\/]+).*/, '$1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
			// first add with no value
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
			this.add( 'targetWindow', null );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
			// This avoids SecurityErrors when setting a window object in x-origin iframe'd scenarios.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
			this.targetWindow.set = function( to ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
				var from = this._value;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
				to = this._setter.apply( this, arguments );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
				to = this.validate( to );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
				if ( null === to || from === to ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
					return this;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
				this._value = to;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
				this._dirty = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
				this.callbacks.fireWith( this, [ to, from ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
				return this;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
			};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
			// now set it
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
			this.targetWindow( params.targetWindow || defaultTarget );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
			// Since we want jQuery to treat the receive function as unique
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
			// to this instance, we give the function a new guid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
			//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
			// This will prevent every Messenger's receive function from being
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
			// unbound when calling $.off( 'message', this.receive );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
			this.receive = $.proxy( this.receive, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
			this.receive.guid = $.guid++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			$( window ).on( 'message', this.receive );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		destroy: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
			$( window ).off( 'message', this.receive );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
		receive: function( event ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
			var message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
			event = event.originalEvent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
			if ( ! this.targetWindow() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
			// Check to make sure the origin is valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
			if ( this.origin() && event.origin !== this.origin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
			// Ensure we have a string that's JSON.parse-able
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
			if ( typeof event.data !== 'string' || event.data[0] !== '{' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			message = JSON.parse( event.data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
			// Check required message properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
			if ( ! message || ! message.id || typeof message.data === 'undefined' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
			// Check if channel names match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			if ( ( message.channel || this.channel() ) && this.channel() !== message.channel )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
			this.trigger( message.id, message.data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
		send: function( id, data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
			var message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			data = typeof data === 'undefined' ? null : data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			if ( ! this.url() || ! this.targetWindow() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
			message = { id: id, data: data };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
			if ( this.channel() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
				message.channel = this.channel();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
			this.targetWindow().postMessage( JSON.stringify( message ), this.origin() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	// Add the Events mixin to api.Messenger.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	$.extend( api.Messenger.prototype, api.Events );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
	// Core customize object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	api = $.extend( new api.Values(), api );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	api.get = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
		var result = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
		this.each( function( obj, key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
			result[ key ] = obj.get();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		return result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
	// Expose the API publicly on window.wp.customize
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	exports.customize = api;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
})( wp, jQuery );