WordPress/wp-includes/js/wp-lists.min.js

1 line
7.1 KiB
JavaScript

!function(r){var t={add:"ajaxAdd",del:"ajaxDel",dim:"ajaxDim",process:"process",recolor:"recolor"},d={settings:{url:ajaxurl,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(e,t){e=wpAjax.unserialize(e.attr("href"));return t.nonce||e._ajax_nonce||r("#"+t.element+' input[name="_ajax_nonce"]').val()||e._wpnonce||r("#"+t.element+' input[name="_wpnonce"]').val()||0},parseData:function(e,t){var n,s=[];try{(n=(n=r(e).attr("data-wp-lists")||"").match(new RegExp(t+":[\\S]+")))&&(s=n[0].split(":"))}catch(e){}return s},pre:function(e,t,n){var s;return t=r.extend({},this.wpList.settings,{element:null,nonce:0,target:e.get(0)},t||{}),!(r.isFunction(t.confirm)&&("add"!=n&&(s=r("#"+t.element).css("backgroundColor"),r("#"+t.element).css("backgroundColor","#FF9966")),e=t.confirm.call(this,e,t,n,s),"add"!=n&&r("#"+t.element).css("backgroundColor",s),!e))&&t},ajaxAdd:function(e,n){e=r(e),n=n||{};var t,s,i,a=this,o=d.parseData(e,"add");return(n=d.pre.call(a,e,n,"add")).element=o[2]||e.attr("id")||n.element||null,o[3]?n.addColor="#"+o[3]:n.addColor=n.addColor||"#FFFF33",!!n&&(e.is('[id="'+n.element+'-submit"]')?!n.element||(n.action="add-"+n.what,n.nonce=d.nonce(e,n),t=r("#"+n.element+" :input").not('[name="_ajax_nonce"], [name="_wpnonce"], [name="action"]'),!!wpAjax.validateForm("#"+n.element)&&(n.data=r.param(r.extend({_ajax_nonce:n.nonce,action:n.action},wpAjax.unserialize(o[4]||""))),(t=r.isFunction(t.fieldSerialize)?t.fieldSerialize():t.serialize())&&(n.data+="&"+t),!(!r.isFunction(n.addBefore)||(n=n.addBefore(n)))||(!n.data.match(/_ajax_nonce=[a-f0-9]+/)||(n.success=function(e){return s=wpAjax.parseAjaxResponse(e,n.response,n.element),i=e,!(!s||s.errors)&&(!0===s||(jQuery.each(s.responses,function(){d.add.call(a,this.data,r.extend({},n,{pos:this.position||0,id:this.id||0,oldId:this.oldId||null}))}),a.wpList.recolor(),r(a).trigger("wpListAddEnd",[n,a.wpList]),void d.clear.call(a,"#"+n.element)))},n.complete=function(e,t){r.isFunction(n.addAfter)&&(t=r.extend({xml:e,status:t,parsed:s},n),n.addAfter(i,t))},r.ajax(n),!1)))):!d.add.call(a,e,n))},ajaxDel:function(e,s){e=r(e),s=s||{};var i,a,o,t=this,n=d.parseData(e,"delete");return(s=d.pre.call(t,e,s,"delete")).element=n[2]||s.element||null,n[3]?s.delColor="#"+n[3]:s.delColor=s.delColor||"#faa",!(!s||!s.element)&&(s.action="delete-"+s.what,s.nonce=d.nonce(e,s),s.data=r.extend({action:s.action,id:s.element.split("-").pop(),_ajax_nonce:s.nonce},wpAjax.unserialize(n[4]||"")),!(!r.isFunction(s.delBefore)||(s=s.delBefore(s,t)))||(!s.data._ajax_nonce||(i=r("#"+s.element),"none"!=s.delColor?i.css("backgroundColor",s.delColor).fadeOut(350,function(){t.wpList.recolor(),r(t).trigger("wpListDelEnd",[s,t.wpList])}):(t.wpList.recolor(),r(t).trigger("wpListDelEnd",[s,t.wpList])),s.success=function(e){if(a=wpAjax.parseAjaxResponse(e,s.response,s.element),o=e,!a||a.errors)return i.stop().stop().css("backgroundColor","#faa").show().queue(function(){t.wpList.recolor(),r(this).dequeue()}),!1},s.complete=function(t,n){r.isFunction(s.delAfter)&&i.queue(function(){var e=r.extend({xml:t,status:n,parsed:a},s);s.delAfter(o,e)}).dequeue()},r.ajax(s),!1)))},ajaxDim:function(e,s){if("none"==r(e).parent().css("display"))return!1;e=r(e),s=s||{};var i,t,a,o,n=this,l=d.parseData(e,"dim");return(s=d.pre.call(n,e,s,"dim")).element=l[2]||s.element||null,s.dimClass=l[3]||s.dimClass||null,l[4]?s.dimAddColor="#"+l[4]:s.dimAddColor=s.dimAddColor||"#FFFF33",l[5]?s.dimDelColor="#"+l[5]:s.dimDelColor=s.dimDelColor||"#FF3333",!(s&&s.element&&s.dimClass)||(s.action="dim-"+s.what,s.nonce=d.nonce(e,s),s.data=r.extend({action:s.action,id:s.element.split("-").pop(),dimClass:s.dimClass,_ajax_nonce:s.nonce},wpAjax.unserialize(l[6]||"")),!(!r.isFunction(s.dimBefore)||(s=s.dimBefore(s)))||(i=r("#"+s.element),t=i.toggleClass(s.dimClass).is("."+s.dimClass),e=d.getColor(i),i.toggleClass(s.dimClass),"none"!=(l=t?s.dimAddColor:s.dimDelColor)?i.animate({backgroundColor:l},"fast").queue(function(){i.toggleClass(s.dimClass),r(this).dequeue()}).animate({backgroundColor:e},{complete:function(){r(this).css("backgroundColor",""),r(n).trigger("wpListDimEnd",[s,n.wpList])}}):r(n).trigger("wpListDimEnd",[s,n.wpList]),!s.data._ajax_nonce||(s.success=function(e){if(a=wpAjax.parseAjaxResponse(e,s.response,s.element),o=e,!a||a.errors)return i.stop().stop().css("backgroundColor","#FF3333")[t?"removeClass":"addClass"](s.dimClass).show().queue(function(){n.wpList.recolor(),r(this).dequeue()}),!1},s.complete=function(t,n){r.isFunction(s.dimAfter)&&i.queue(function(){var e=r.extend({xml:t,status:n,parsed:a},s);s.dimAfter(o,e)}).dequeue()},r.ajax(s),!1)))},getColor:function(e){return jQuery(e).css("backgroundColor")||"#ffffff"},add:function(e,t){e=r("string"==typeof e?r.trim(e):e);var n,s=r(this),i=!1;return"string"==typeof t&&(t={what:t}),t=r.extend({pos:0,id:0,oldId:null},this.wpList.settings,t),!(!e.size()||!t.what)&&(t.oldId&&(i=r("#"+t.what+"-"+t.oldId)),!t.id||t.id==t.oldId&&i&&i.size()||r("#"+t.what+"-"+t.id).remove(),i&&i.size()?(i.before(e),i.remove()):isNaN(t.pos)?(n="after","-"==t.pos.substr(0,1)&&(t.pos=t.pos.substr(1),n="before"),1===(i=s.find("#"+t.pos)).size()?i[n](e):s.append(e)):"comment"==t.what&&0!==r("#"+t.element).length||(t.pos<0?s.prepend(e):s.append(e)),t.alt&&((s.children(":visible").index(e[0])+t.altOffset)%2?e.removeClass(t.alt):e.addClass(t.alt)),"none"!=t.addColor&&(n=d.getColor(e),e.css("backgroundColor",t.addColor).animate({backgroundColor:n},{complete:function(){r(this).css("backgroundColor","")}})),s.each(function(){this.wpList.process(e)}),e)},clear:function(e){var t,n;e=r(e),this.wpList&&e.parents("#"+this.id).size()||e.find(":input").each(function(){r(this).parents(".form-no-clear").size()||(t=this.type.toLowerCase(),n=this.tagName.toLowerCase(),"text"==t||"password"==t||"textarea"==n?this.value="":"checkbox"==t||"radio"==t?this.checked=!1:"select"==n&&(this.selectedIndex=null))})},process:function(e){var t=this,e=r(e||document);e.delegate('form[data-wp-lists^="add:'+t.id+':"]',"submit",function(){return t.wpList.add(this)}),e.delegate('a[data-wp-lists^="add:'+t.id+':"], input[data-wp-lists^="add:'+t.id+':"]',"click",function(){return t.wpList.add(this)}),e.delegate('[data-wp-lists^="delete:'+t.id+':"]',"click",function(){return t.wpList.del(this)}),e.delegate('[data-wp-lists^="dim:'+t.id+':"]',"click",function(){return t.wpList.dim(this)})},recolor:function(){var e,t,n=this;n.wpList.settings.alt&&((e=r(".list-item:visible",n)).size()||(e=r(n).children(":visible")),t=[":even",":odd"],n.wpList.settings.altOffset%2&&t.reverse(),e.filter(t[0]).addClass(n.wpList.settings.alt).end().filter(t[1]).removeClass(n.wpList.settings.alt))},init:function(){var t=this;t.wpList.process=function(e){t.each(function(){this.wpList.process(e)})},t.wpList.recolor=function(){t.each(function(){this.wpList.recolor()})}}};r.fn.wpList=function(e){return this.each(function(){var s=this;this.wpList={settings:r.extend({},d.settings,{what:d.parseData(this,"list")[1]||""},e)},r.each(t,function(e,n){s.wpList[e]=function(e,t){return d[n].call(s,e,t)}})}),d.init.call(this),this.wpList.process(),this}}(jQuery);