WordPress/wp-admin/js/widgets.min.js

1 line
8.3 KiB
JavaScript
Raw Normal View History

var wpWidgets;!function(a){wpWidgets={init:function(){var b,c,d=this,e=a(".widgets-chooser"),f=e.find(".widgets-chooser-sidebars"),g=a("div.widgets-sortables"),h=!("undefined"==typeof isRtl||!isRtl);a("#widgets-right .sidebar-name").click(function(){var b=a(this),c=b.closest(".widgets-holder-wrap");c.hasClass("closed")?(c.removeClass("closed"),b.parent().sortable("refresh")):c.addClass("closed")}),a("#widgets-left .sidebar-name").click(function(){a(this).closest(".widgets-holder-wrap").toggleClass("closed")}),a(document.body).bind("click.widgets-toggle",function(b){var c,d,e,f,g,i=a(b.target),j={"z-index":100};i.parents(".widget-top").length&&!i.parents("#available-widgets").length?(c=i.closest("div.widget"),d=c.children(".widget-inside"),e=parseInt(c.find("input.widget-width").val(),10),f=c.parent().width(),d.is(":hidden")?(e>250&&e+30>f&&c.closest("div.widgets-sortables").length&&(g=c.closest("div.widget-liquid-right").length?h?"margin-right":"margin-left":h?"margin-left":"margin-right",j[g]=f-(e+30)+"px",c.css(j)),c.addClass("open"),d.slideDown("fast")):d.slideUp("fast",function(){c.attr("style",""),c.removeClass("open")}),b.preventDefault()):i.hasClass("widget-control-save")?(wpWidgets.save(i.closest("div.widget"),0,1,0),b.preventDefault()):i.hasClass("widget-control-remove")?(wpWidgets.save(i.closest("div.widget"),1,1,0),b.preventDefault()):i.hasClass("widget-control-close")&&(c=i.closest("div.widget"),c.removeClass("open"),wpWidgets.close(c),b.preventDefault())}),g.children(".widget").each(function(){var b=a(this);wpWidgets.appendTitle(this),b.find("p.widget-error").length&&b.find("a.widget-action").trigger("click")}),a("#widget-list").children(".widget").draggable({connectToSortable:"div.widgets-sortables",handle:"> .widget-top > .widget-title",distance:2,helper:"clone",zIndex:100,containment:"document",start:function(b,e){var f=a(this).find(".widgets-chooser");e.helper.find("div.widget-description").hide(),c=this.id,f.length&&(a("#wpbody-content").append(f.hide()),e.helper.find(".widgets-chooser").remove(),d.clearWidgetSelection())},stop:function(){b&&a(b).hide(),b=""}}),g.sortable({placeholder:"widget-placeholder",items:"> .widget",handle:"> .widget-top > .widget-title",cursor:"move",distance:2,containment:"document",start:function(b,c){var d,e=a(this),f=e.parent(),g=c.item.children(".widget-inside");"block"===g.css("display")&&(g.hide(),a(this).sortable("refreshPositions")),f.hasClass("closed")||(d=c.item.hasClass("ui-draggable")?e.height():1+e.height(),e.css("min-height",d+"px"))},stop:function(d,e){var f,g,h,i,j,k,l=e.item,m=c;return l.hasClass("deleting")?(wpWidgets.save(l,1,0,1),void l.remove()):(f=l.find("input.add_new").val(),g=l.find("input.multi_number").val(),l.attr("style","").removeClass("ui-draggable"),c="",f&&("multi"===f?(l.html(l.html().replace(/<[^<>]+>/g,function(a){return a.replace(/__i__|%i%/g,g)})),l.attr("id",m.replace("__i__",g)),g++,a("div#"+m).find("input.multi_number").val(g)):"single"===f&&(l.attr("id","new-"+m),b="div#"+m),wpWidgets.save(l,0,0,1),l.find("input.add_new").val(""),a(document).trigger("widget-added",[l])),h=l.parent(),h.parent().hasClass("closed")&&(h.parent().removeClass("closed"),i=h.children(".widget"),i.length>1&&(j=i.get(0),k=l.get(0),j.id&&k.id&&j.id!==k.id&&a(j).before(l))),void(f?l.find("a.widget-action").trigger("click"):wpWidgets.saveOrder(h.attr("id"))))},activate:function(){a(this).parent().addClass("widget-hover")},deactivate:function(){a(this).css("min-height","").parent().removeClass("widget-hover")},receive:function(b,c){var d=a(c.sender);return this.id.indexOf("orphaned_widgets")>-1?void d.sortable("cancel"):void(d.attr("id").indexOf("orphaned_widgets")>-1&&!d.children(".widget").length&&d.parents(".orphan-sidebar").slideUp(400,function(){a(this).remove()}))}}).sortable("option","connectWith","div.widgets-sortables"),a("#available-widgets").droppable({tolerance:"pointer",accept:function(b){return"widget-list"!==a(b).parent().attr("id")},drop:function(b,c){c.draggable.addClass("deleting"),a("#removing-widget").hide().children("span").empty()},over:functio