mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-18 16:45:31 +01:00
4d7ad21379
git-svn-id: http://svn.automattic.com/wordpress/trunk@10457 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
(function(c){var b=false,a={add:"ajaxAdd",del:"ajaxDel",dim:"ajaxDim",process:"process",recolor:"recolor"},d;d={settings:{url:wpListL10n.url,type:"POST",response:"ajax-response",what:"",alt:"alternate",altOffset:0,addColor:null,delColor:null,dimAddColor:null,dimDelColor:null,confirm:null,addBefore:null,addAfter:null,delBefore:null,delAfter:null,dimBefore:null,dimAfter:null},nonce:function(h,g){var f=wpAjax.unserialize(h.attr("href"));return g.nonce||f._ajax_nonce||c("#"+g.element+" input[name=_ajax_nonce]").val()||f._wpnonce||c("#"+g.element+" input[name=_wpnonce]").val()||0},parseClass:function(i,g){var j=[],f;try{f=c(i).attr("class")||"";f=f.match(new RegExp(g+":[\\S]+"));if(f){j=f[0].split(":")}}catch(h){}return j},pre:function(j,h,f){var g,i;h=c.extend({},this.wpList.settings,{element:null,nonce:0,target:j.get(0)},h||{});if(c.isFunction(h.confirm)){if("add"!=f){g=c("#"+h.element).css("backgroundColor");c("#"+h.element).css("backgroundColor","#FF9966")}i=h.confirm.call(this,j,h,f,g);if("add"!=f){c("#"+h.element).css("backgroundColor",g)}if(!i){return false}}return h},ajaxAdd:function(k,g){k=c(k);g=g||{};var i=this,f=d.parseClass(k,"add"),l,h,j;g=d.pre.call(i,k,g,"add");g.element=f[2]||k.attr("id")||g.element||null;if(f[3]){g.addColor="#"+f[3]}else{g.addColor=g.addColor||"#FFFF33"}if(!g){return false}if(!k.is("[class^=add:"+i.id+":]")){return !d.add.call(i,k,g)}if(!g.element){return true}g.action="add-"+g.what;g.nonce=d.nonce(k,g);l=c("#"+g.element+" :input").not("[name=_ajax_nonce], [name=_wpnonce], [name=action]");h=wpAjax.validateForm("#"+g.element);if(!h){return false}g.data=c.param(c.extend({_ajax_nonce:g.nonce,action:g.action},wpAjax.unserialize(f[4]||"")));j=c.isFunction(l.fieldSerialize)?l.fieldSerialize():l.serialize();if(j){g.data+="&"+j}if(c.isFunction(g.addBefore)){g=g.addBefore(g);if(!g){return true}}if(!g.data.match(/_ajax_nonce=[a-f0-9]+/)){return true}g.success=function(m){var e=wpAjax.parseAjaxResponse(m,g.response,g.element),n;if(!e||e.errors){return false}if(true===e){return true}jQuery.each(e.responses,function(){d.add.call(i,this.data,c.extend({},g,{pos:this.position||0,id:this.id||0,oldId:this.oldId||null}))});if(c.isFunction(g.addAfter)){n=this.complete;this.complete=function(o,p){var q=c.extend({xml:o,status:p,parsed:e},g);g.addAfter(m,q);if(c.isFunction(n)){n(o,p)}}}i.wpList.recolor();d.clear.call(i,"#"+g.element)};c.ajax(g);return false},ajaxDel:function(k,h){k=c(k);h=h||{};var j=this,f=d.parseClass(k,"delete"),g,i;h=d.pre.call(j,k,h,"delete");h.element=f[2]||h.element||null;if(f[3]){h.delColor="#"+f[3]}else{h.delColor=h.delColor||"#FF3333"}if(!h||!h.element){return false}h.action="delete-"+h.what;h.nonce=d.nonce(k,h);h.data=c.extend({action:h.action,id:h.element.split("-").pop(),_ajax_nonce:h.nonce},wpAjax.unserialize(f[4]||""));if(c.isFunction(h.delBefore)){h=h.delBefore(h);if(!h){return true}}if(!h.data._ajax_nonce){return true}g=c("#"+h.element);if("none"!=h.delColor){i="slideUp";if(g.css("display").match(/table/)){i="fadeOut"}g.animate({backgroundColor:h.delColor},"fast")[i]("fast").queue(function(){j.wpList.recolor();c(this).dequeue()})}else{j.wpList.recolor()}h.success=function(l){var e=wpAjax.parseAjaxResponse(l,h.response,h.element),m;if(!e||e.errors){g.stop().stop().css("backgroundColor","#FF3333").show().queue(function(){j.wpList.recolor();c(this).dequeue()});return false}if(c.isFunction(h.delAfter)){m=this.complete;this.complete=function(n,o){g.queue(function(){var p=c.extend({xml:n,status:o,parsed:e},h);h.delAfter(l,p);if(c.isFunction(m)){m(n,o)}}).dequeue()}}};c.ajax(h);return false},ajaxDim:function(l,i){if(c(l).parent().css("display")=="none"){return false}l=c(l);i=i||{};var k=this,f=d.parseClass(l,"dim"),h,m,g,j;i=d.pre.call(k,l,i,"dim");i.element=f[2]||i.element||null;i.dimClass=f[3]||i.dimClass||null;if(f[4]){i.dimAddColor="#"+f[4]}else{i.dimAddColor=i.dimAddColor||"#FFFF33"}if(f[5]){i.dimDelColor="#"+f[5]}else{i.dimDelColor=i.dimDelColor||"#FF3333"}if(!i||!i.element||!i.dimClass){return true}i.action="dim-"+i.what;i.nonce=d.nonce(l,i);i.data=c.extend({action:i.action,id:i.element.split("-").pop(),dimClass:i.dimClass,_ajax_nonce:i.nonce},wpAjax.unserialize(f[6]||""));if(c.isFunction(i.dimBefore)){i=i.dimBefore(i);if(!i){return true}}h=c("#"+i.element);m=h.toggleClass(i.dimClass).is("."+i.dimClass);g=d.getColor(h);h.toggleClass(i.dimClass);j=m?i.dimAddColor:i.dimDelColor;if("none"!=j){h.animate({backgroundColor:j},"fast").queue(function(){h.toggleClass(i.dimClass);c(this).dequeue()}).animate({backgroundColor:g},{complete:function(){c(this).css("backgroundColor","")}})}if(!i.data._ajax_nonce){return true}i.success=function(n){var e=wpAjax.parseAjaxResponse(n,i.response,i.element),p;if(!e||e.errors){h.stop().stop().css("backgroundColor","#FF3333")[m?"removeClass":"addClass"](i.dimClass).show().queue(function(){k.wpList.recolor();c(this).dequeue()});return false}if(c.isFunction(i.dimAfter)){p=this.complete;this.complete=function(o,q){h.queue(function(){var r=c.extend({xml:o,status:q,parsed:e},i);i.dimAfter(n,r);if(c.isFunction(p)){p(o,q)}}).dequeue()}}};c.ajax(i);return false},getColor:function(f){if(f.constructor==Object){f=f.get(0)}var g=f,e,h=new RegExp("rgba\\(\\s*0,\\s*0,\\s*0,\\s*0\\s*\\)","i");do{e=jQuery.curCSS(g,"backgroundColor");if(e!=""&&e!="transparent"&&!e.match(h)||jQuery.nodeName(g,"body")){break}}while(g=g.parentNode);return e||"#ffffff"},add:function(l,h){l=c(l);var j=c(this),f=false,k={pos:0,id:0,oldId:null},m,i,g;if("string"==typeof h){h={what:h}}h=c.extend(k,this.wpList.settings,h);if(!l.size()||!h.what){return false}if(h.oldId){f=c("#"+h.what+"-"+h.oldId)}if(h.id&&(h.id!=h.oldId||!f||!f.size())){c("#"+h.what+"-"+h.id).remove()}if(f&&f.size()){f.replaceWith(l)}else{if(isNaN(h.pos)){m="after";if("-"==h.pos.substr(0,1)){h.pos=h.pos.substr(1);m="before"}i=j.find("#"+h.pos);if(1===i.size()){i[m](l)}else{j.append(l)}}else{if(h.pos<0){j.prepend(l)}else{j.append(l)}}}if(h.alt){if((j.children(":visible").index(l[0])+h.altOffset)%2){l.removeClass(h.alt)}else{l.addClass(h.alt)}}if("none"!=h.addColor){g=d.getColor(l);l.css("backgroundColor",h.addColor).animate({backgroundColor:g},{complete:function(){c(this).css("backgroundColor","")}})}j.each(function(){this.wpList.process(l)});return l},clear:function(i){var h=this,g,f;i=c(i);if(h.wpList&&i.parents("#"+h.id).size()){return}i.find(":input").each(function(){if(c(this).parents(".form-no-clear").size()){return}g=this.type.toLowerCase();f=this.tagName.toLowerCase();if("text"==g||"password"==g||"textarea"==f){this.value=""}else{if("checkbox"==g||"radio"==g){this.checked=false}else{if("select"==f){this.selectedIndex=null}}}})},process:function(e){var f=this;c("[class^=add:"+f.id+":]",e||null).filter("form").submit(function(){return f.wpList.add(this)}).end().not("form").click(function(){return f.wpList.add(this)}).each(function(){var j=this,i=d.parseClass(this,"add")[2]||j.id,g=[],h=[];if(!i){return}c("#"+i+" :input").focus(function(){b=this}).blur(function(){b=false}).each(function(){h.push(this);var k=c(this).parents("form:first").get(0);if(c.inArray(k,g)<0){g.push(k)}});c(g).submit(function(){if(0<=c.inArray(b,h)){c(j).trigger("click");c(b).focus();return false}})});c("[class^=delete:"+f.id+":]",e||null).click(function(){return f.wpList.del(this)});c("[class^=dim:"+f.id+":]",e||null).click(function(){return f.wpList.dim(this)})},recolor:function(){var g=this,f,e;if(!g.wpList.settings.alt){return}f=c(".list-item:visible",g);if(!f.size()){f=c(g).children(":visible")}e=[":even",":odd"];if(g.wpList.settings.altOffset%2){e.reverse()}f.filter(e[0]).addClass(g.wpList.settings.alt).end().filter(e[1]).removeClass(g.wpList.settings.alt)},init:function(){var e=this;e.wpList.process=function(f){e.each(function(){this.wpList.process(f)})};e.wpList.recolor=function(){e.each(function(){this.wpList.recolor()})}}};c.fn.wpList=function(e){this.each(function(){var f=this;this.wpList={settings:c.extend({},d.settings,{what:d.parseClass(this,"list")[1]||""},e)};c.each(a,function(g,h){f.wpList[g]=function(j,i){return d[h].call(f,j,i)}})});d.init.call(this);this.wpList.process();return this}})(jQuery); |