mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-06 10:50:56 +01:00
715efd86f0
git-svn-id: http://svn.automattic.com/wordpress/trunk@20521 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
5.8 KiB
JavaScript
1 line
5.8 KiB
JavaScript
if(typeof wp==="undefined"){var wp={}}(function(a,d){var b,g,c,f,e=Array.prototype.slice;g=function(h,i){var j=f(this,h,i);j.extend=this.extend;return j};c=function(){};f=function(i,h,j){var k;if(h&&h.hasOwnProperty("constructor")){k=h.constructor}else{k=function(){var l=i.apply(this,arguments);return l}}d.extend(k,i);c.prototype=i.prototype;k.prototype=new c();if(h){d.extend(k.prototype,h)}if(j){d.extend(k,j)}k.prototype.constructor=k;k.__super__=i.prototype;return k};b={};b.Class=function(l,k,i){var j,h=arguments;if(l&&k&&b.Class.applicator===l){h=k;d.extend(this,i||{})}j=this;if(this.instance){j=function(){return j.instance.apply(j,arguments)};d.extend(j,this)}j.initialize.apply(j,h);return j};b.Class.applicator={};b.Class.prototype.initialize=function(){};b.Class.prototype.extended=function(h){var i=this;while(typeof i.constructor!=="undefined"){if(i.constructor===h){return true}if(typeof i.constructor.__super__==="undefined"){return false}i=i.constructor.__super__}return false};b.Class.extend=g;b.Value=b.Class.extend({initialize:function(i,h){this._value=i;this.callbacks=d.Callbacks();d.extend(this,h||{});this.set=d.proxy(this.set,this)},instance:function(){return arguments.length?this.set.apply(this,arguments):this.get()},get:function(){return this._value},set:function(i){var h=this._value;i=this._setter.apply(this,arguments);i=this.validate(i);if(null===i||this._value===i){return this}this._value=i;this.callbacks.fireWith(this,[i,h]);return this},_setter:function(h){return h},setter:function(h){this._setter=h;this.set(this.get());return this},resetSetter:function(){this._setter=this.constructor.prototype._setter;this.set(this.get());return this},validate:function(h){return h},bind:function(h){this.callbacks.add.apply(this.callbacks,arguments);return this},unbind:function(h){this.callbacks.remove.apply(this.callbacks,arguments);return this},link:function(){var h=this.set;d.each(arguments,function(){this.bind(h)});return this},unlink:function(){var h=this.set;d.each(arguments,function(){this.unbind(h)});return this},sync:function(){var h=this;d.each(arguments,function(){h.link(this);this.link(h)});return this},unsync:function(){var h=this;d.each(arguments,function(){h.unlink(this);this.unlink(h)});return this}});b.Values=b.Class.extend({defaultConstructor:b.Value,initialize:function(h){d.extend(this,h||{});this._value={};this._deferreds={}},instance:function(h){if(arguments.length===1){return this.value(h)}return this.when.apply(this,arguments)},value:function(h){return this._value[h]},has:function(h){return typeof this._value[h]!=="undefined"},add:function(i,h){if(this.has(i)){return this.value(i)}this._value[i]=h;this._value[i].parent=this;if(this._deferreds[i]){this._deferreds[i].resolve()}return this._value[i]},set:function(h){if(this.has(h)){return this.pass("set",arguments)}return this.add(h,new this.defaultConstructor(b.Class.applicator,e.call(arguments,1)))},remove:function(h){delete this._value[h];delete this._deferreds[h]},pass:function(i,h){var k,j;h=e.call(h);k=h.shift();if(!this.has(k)){return}j=this.value(k);return j[i].apply(j,h)},when:function(){var h=this,i=e.call(arguments),j=i.pop();d.when.apply(d,d.map(i,function(k){if(h.has(k)){return}return h._deferreds[k]||(h._deferreds[k]=d.Deferred())})).done(function(){var k=d.map(i,function(l){return h(l)});if(k.length!==i.length){i.push(j);h.when.apply(h,i);return}j.apply(h,k)})}});d.each(["get","bind","unbind","link","unlink","sync","unsync","setter","resetSetter"],function(h,j){b.Values.prototype[j]=function(){return this.pass(j,arguments)}});b.ensure=function(h){return typeof h=="string"?d(h):h};b.Element=b.Value.extend({initialize:function(j,i){var h=this,m=b.Element.synchronizer.html,l,n,k;this.element=b.ensure(j);this.events="";if(this.element.is("input, select, textarea")){this.events+="change";m=b.Element.synchronizer.val;if(this.element.is("input")){l=this.element.prop("type");if(b.Element.synchronizer[l]){m=b.Element.synchronizer[l]}if("text"===l||"password"===l){this.events+=" keyup"}}}b.Value.prototype.initialize.call(this,null,d.extend(i||{},m));this._value=this.get();n=this.update;k=this.refresh;this.update=function(o){if(o!==k.call(h)){n.apply(this,arguments)}};this.refresh=function(){h.set(k.call(h))};this.bind(this.update);this.element.bind(this.events,this.refresh)},find:function(h){return d(h,this.element)},refresh:function(){},update:function(){}});b.Element.synchronizer={};d.each(["html","val"],function(h,j){b.Element.synchronizer[j]={update:function(i){this.element[j](i)},refresh:function(){return this.element[j]()}}});b.Element.synchronizer.checkbox={update:function(h){this.element.prop("checked",h)},refresh:function(){return this.element.prop("checked")}};b.Element.synchronizer.radio={update:function(h){this.element.filter(function(){return this.value===h}).prop("checked",true)},refresh:function(){return this.element.filter(":checked").val()}};b.Messenger=b.Class.extend({add:function(j,i,h){return this[j]=new b.Value(i,h)},initialize:function(i,j,h){d.extend(this,h||{});i=this.add("url",i);this.add("targetWindow",j||window.parent);this.add("origin",i()).link(i).setter(function(k){return k.replace(/([^:]+:\/\/[^\/]+).*/,"$1")});this.topics={};this.receive=d.proxy(this.receive,this);d(window).on("message",this.receive)},destroy:function(){d(window).off("message",this.receive)},receive:function(i){var h;i=i.originalEvent;if(this.origin()&&i.origin!==this.origin()){return}h=JSON.parse(i.data);if(h&&h.id&&h.data&&this.topics[h.id]){this.topics[h.id].fireWith(this,[h.data])}},send:function(j,i){var h;i=i||{};if(!this.url()){return}h=JSON.stringify({id:j,data:i});this.targetWindow().postMessage(h,this.origin())},bind:function(j,i){var h=this.topics[j]||(this.topics[j]=d.Callbacks());h.add(i)},unbind:function(i,h){if(this.topics[i]){this.topics[i].remove(h)}}});b=d.extend(new b.Values(),b);a.customize=b})(wp,jQuery); |