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

1 line
7.4 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,a,o=this,i=d.parseData(e,"add");return(n=d.pre.call(o,e,n,"add")).element=i[2]||e.attr("id")||n.element||null,i[3]?n.addColor="#"+i[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(i[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),a=e,!(!s||s.errors)&&(!0===s||(jQuery.each(s.responses,function(){d.add.call(o,this.data,r.extend({},n,{pos:this.position||0,id:this.id||0,oldId:this.oldId||null}))}),o.wpList.recolor(),r(o).trigger("wpListAddEnd",[n,o.wpList]),void d.clear.call(o,"#"+n.element)))},n.complete=function(e,t){r.isFunction(n.addAfter)&&(t=r.extend({xml:e,status:t,parsed:s},n),n.addAfter(a,t))},r.ajax(n),!1)))):!d.add.call(o,e,n))},ajaxDel:function(e,s){e=r(e),s=s||{};var a,o,i,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||(a=r("#"+s.element),"none"!=s.delColor?a.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(o=wpAjax.parseAjaxResponse(e,s.response,s.element),i=e,!o||o.errors)return a.stop().stop().css("backgroundColor","#faa").show().queue(function(){t.wpList.recolor(),r(this).dequeue()}),!1},s.complete=function(t,n){r.isFunction(s.delAfter)&&a.queue(function(){var e=r.extend({xml:t,status:n,parsed:o},s);s.delAfter(i,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 a,n,o,i,l=this,t=d.parseData(e,"dim");return(s=d.pre.call(l,e,s,"dim")).element=t[2]||s.element||null,s.dimClass=t[3]||s.dimClass||null,t[4]?s.dimAddColor="#"+t[4]:s.dimAddColor=s.dimAddColor||"#FFFF33",t[5]?s.dimDelColor="#"+t[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(t[6]||"")),!(!r.isFunction(s.dimBefore)||(s=s.dimBefore(s)))||(a=r("#"+s.element),n=a.toggleClass(s.dimClass).is("."+s.dimClass),e=d.getColor(a),a.toggleClass(s.dimClass),"none"!=(t=n?s.dimAddColor:s.dimDelColor)?a.animate({backgroundColor:t},"fast").queue(function(){a.toggleClass(s.dimClass),r(this).dequeue()}).animate({backgroundColor:e},{complete:function(){r(this).css("backgroundColor",""),r(l).trigger("wpListDimEnd",[s,l.wpList])}}):r(l).trigger("wpListDimEnd",[s,l.wpList]),!s.data._ajax_nonce||(s.success=function(e){return o=wpAjax.parseAjaxResponse(e,s.response,s.element),i=e,!0===o||(!o||o.errors?(a.stop().stop().css("backgroundColor","#FF3333")[n?"removeClass":"addClass"](s.dimClass).show().queue(function(){l.wpList.recolor(),r(this).dequeue()}),!1):void(void 0!==o.responses[0].supplemental.comment_link&&(e=(t=a.find(".submitted-on")).find("a"),""!==o.responses[0].supplemental.comment_link?t.html(r("<a></a>").text(t.text()).prop("href",o.responses[0].supplemental.comment_link)):e.length&&t.text(e.text()))));var t},s.complete=function(t,n){r.isFunction(s.dimAfter)&&a.queue(function(){var e=r.extend({xml:t,status:n,parsed:o},s);s.dimAfter(i,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),a=!1;return"string"==typeof t&&(t={what:t}),t=r.extend({pos:0,id:0,oldId:null},this.wpList.settings,t),!(!e.length||!t.what)&&(t.oldId&&(a=r("#"+t.what+"-"+t.oldId)),!t.id||t.id==t.oldId&&a&&a.length||r("#"+t.what+"-"+t.id).remove(),a&&a.length?(a.before(e),a.remove()):isNaN(t.pos)?(n="after","-"==t.pos.substr(0,1)&&(t.pos=t.pos.substr(1),n="before"),1===(a=s.find("#"+t.pos)).length?a[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).length||e.find(":input").each(function(){r(this).parents(".form-no-clear").length||(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)).length||(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);