WordPress/wp-includes/js/customize-base.min.js

1 line
6.7 KiB
JavaScript

window.wp=window.wp||{},function(t,h){var a={},s=Array.prototype.slice,r=function(){},i=function(t,e,i){var n=e&&e.hasOwnProperty("constructor")?e.constructor:function(){return t.apply(this,arguments)};return h.extend(n,t),r.prototype=t.prototype,n.prototype=new r,e&&h.extend(n.prototype,e),i&&h.extend(n,i),(n.prototype.constructor=n).__super__=t.prototype,n};a.Class=function(t,e,i){var n,s=arguments;return t&&e&&a.Class.applicator===t&&(s=e,h.extend(this,i||{})),(n=this).instance&&(n=function(){return n.instance.apply(n,arguments)},h.extend(n,this)),n.initialize.apply(n,s),n},a.Class.extend=function(t,e){e=i(this,t,e);return e.extend=this.extend,e},a.Class.applicator={},a.Class.prototype.initialize=function(){},a.Class.prototype.extended=function(t){for(var e=this;void 0!==e.constructor;){if(e.constructor===t)return!0;if(void 0===e.constructor.__super__)return!1;e=e.constructor.__super__}return!1},a.Events={trigger:function(t){return this.topics&&this.topics[t]&&this.topics[t].fireWith(this,s.call(arguments,1)),this},bind:function(t){return this.topics=this.topics||{},this.topics[t]=this.topics[t]||h.Callbacks(),this.topics[t].add.apply(this.topics[t],s.call(arguments,1)),this},unbind:function(t){return this.topics&&this.topics[t]&&this.topics[t].remove.apply(this.topics[t],s.call(arguments,1)),this}},a.Value=a.Class.extend({initialize:function(t,e){this._value=t,this.callbacks=h.Callbacks(),this._dirty=!1,h.extend(this,e||{}),this.set=h.proxy(this.set,this)},instance:function(){return arguments.length?this.set.apply(this,arguments):this.get()},get:function(){return this._value},set:function(t){var e=this._value;return t=this._setter.apply(this,arguments),null===(t=this.validate(t))||_.isEqual(e,t)||(this._value=t,this._dirty=!0,this.callbacks.fireWith(this,[t,e])),this},_setter:function(t){return t},setter:function(t){var e=this.get();return this._setter=t,this._value=null,this.set(e),this},resetSetter:function(){return this._setter=this.constructor.prototype._setter,this.set(this.get()),this},validate:function(t){return t},bind:function(){return this.callbacks.add.apply(this.callbacks,arguments),this},unbind:function(){return this.callbacks.remove.apply(this.callbacks,arguments),this},link:function(){var t=this.set;return h.each(arguments,function(){this.bind(t)}),this},unlink:function(){var t=this.set;return h.each(arguments,function(){this.unbind(t)}),this},sync:function(){var t=this;return h.each(arguments,function(){t.link(this),this.link(t)}),this},unsync:function(){var t=this;return h.each(arguments,function(){t.unlink(this),this.unlink(t)}),this}}),a.Values=a.Class.extend({defaultConstructor:a.Value,initialize:function(t){h.extend(this,t||{}),this._value={},this._deferreds={}},instance:function(t){return 1===arguments.length?this.value(t):this.when.apply(this,arguments)},value:function(t){return this._value[t]},has:function(t){return void 0!==this._value[t]},add:function(t,e){return this.has(t)?this.value(t):((this._value[t]=e).parent=this,e.extended(a.Value)&&e.bind(this._change),this.trigger("add",e),this._deferreds[t]&&this._deferreds[t].resolve(),this._value[t])},create:function(t){return this.add(t,new this.defaultConstructor(a.Class.applicator,s.call(arguments,1)))},each:function(i,n){n=void 0===n?this:n,h.each(this._value,function(t,e){i.call(n,e,t)})},remove:function(t){var e;this.has(t)&&(e=this.value(t),this.trigger("remove",e),e.extended(a.Value)&&e.unbind(this._change),delete e.parent),delete this._value[t],delete this._deferreds[t]},when:function(){var e=this,i=s.call(arguments),n=h.Deferred();return h.isFunction(i[i.length-1])&&n.done(i.pop()),h.when.apply(h,h.map(i,function(t){if(!e.has(t))return e._deferreds[t]=e._deferreds[t]||h.Deferred()})).done(function(){var t=h.map(i,function(t){return e(t)});t.length===i.length?n.resolveWith(e,t):e.when.apply(e,i).done(function(){n.resolveWith(e,t)})}),n.promise()},_change:function(){this.parent.trigger("change",this)}}),h.extend(a.Values.prototype,a.Events),a.ensure=function(t){return"string"==typeof t?h(t):t},a.Element=a.Value.extend({initialize:function(t,e){var i,n,s=this,r=a.Element.synchronizer.html;this.element=a.ensure(t),this.events="",this.element.is("input, select, textarea")&&(this.events+="change",r=a.Element.synchronizer.val,this.element.is("input")?(t=this.element.prop("type"),a.Element.synchronizer[t]&&(r=a.Element.synchronizer[t]),"text"===t||"password"===t?this.events+=" keyup":"range"===t&&(this.events+=" input propertychange")):this.element.is("textarea")&&(this.events+=" keyup")),a.Value.prototype.initialize.call(this,null,h.extend(e||{},r)),this._value=this.get(),i=this.update,n=this.refresh,this.update=function(t){t!==n.call(s)&&i.apply(this,arguments)},this.refresh=function(){s.set(n.call(s))},this.bind(this.update),this.element.bind(this.events,this.refresh)},find:function(t){return h(t,this.element)},refresh:function(){},update:function(){}}),a.Element.synchronizer={},h.each(["html","val"],function(t,e){a.Element.synchronizer[e]={update:function(t){this.element[e](t)},refresh:function(){return this.element[e]()}}}),a.Element.synchronizer.checkbox={update:function(t){this.element.prop("checked",t)},refresh:function(){return this.element.prop("checked")}},a.Element.synchronizer.radio={update:function(t){this.element.filter(function(){return this.value===t}).prop("checked",!0)},refresh:function(){return this.element.filter(":checked").val()}},h.support.postMessage=!!window.postMessage,a.Messenger=a.Class.extend({add:function(t,e,i){return this[t]=new a.Value(e,i)},initialize:function(t,e){var i=window.parent==window?null:window.parent;h.extend(this,e||{}),this.add("channel",t.channel),this.add("url",t.url||""),this.add("origin",this.url()).link(this.url).setter(function(t){return t.replace(/([^:]+:\/\/[^\/]+).*/,"$1")}),this.add("targetWindow",null),this.targetWindow.set=function(t){var e=this._value;return t=this._setter.apply(this,arguments),null===(t=this.validate(t))||e===t||(this._value=t,this._dirty=!0,this.callbacks.fireWith(this,[t,e])),this},this.targetWindow(t.targetWindow||i),this.receive=h.proxy(this.receive,this),this.receive.guid=h.guid++,h(window).on("message",this.receive)},destroy:function(){h(window).off("message",this.receive)},receive:function(t){var e;t=t.originalEvent,this.targetWindow()&&(this.origin()&&t.origin!==this.origin()||"string"==typeof t.data&&"{"===t.data[0]&&(e=JSON.parse(t.data))&&e.id&&void 0!==e.data&&((e.channel||this.channel())&&this.channel()!==e.channel||this.trigger(e.id,e.data)))},send:function(t,e){e=void 0===e?null:e,this.url()&&this.targetWindow()&&(e={id:t,data:e},this.channel()&&(e.channel=this.channel()),this.targetWindow().postMessage(JSON.stringify(e),this.origin()))}}),h.extend(a.Messenger.prototype,a.Events),(a=h.extend(new a.Values,a)).get=function(){var i={};return this.each(function(t,e){i[e]=t.get()}),i},t.customize=a}(wp,jQuery);