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

1 line
9.7 KiB
JavaScript
Raw Normal View History

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