mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 02:57:45 +01:00
1 line
6.1 KiB
JavaScript
1 line
6.1 KiB
JavaScript
|
var wpWidgets;(function(a){wpWidgets={init:function(){var f,d=a("div.widgets-sortables"),c=!!("undefined"!=typeof isRtl&&isRtl),e=(isRtl?"marginRight":"marginLeft"),b;a("#widgets-right").children(".widgets-holder-wrap").children(".sidebar-name").click(function(){var h=a(this).siblings(".widgets-sortables"),g=a(this).parent();if(!g.hasClass("closed")){h.sortable("disable");g.addClass("closed")}else{g.removeClass("closed");h.sortable("enable").sortable("refresh")}});a("#widgets-left").children(".widgets-holder-wrap").children(".sidebar-name").click(function(){a(this).parent().toggleClass("closed")});d.each(function(){if(a(this).parent().hasClass("inactive")){return true}var i=50,g=a(this).children(".widget").length;i=i+parseInt(g*48,10);a(this).css("minHeight",i+"px")});a(document.body).bind("click.widgets-toggle",function(l){var k=a(l.target),i={},j,g,h;if(k.parents(".widget-top").length&&!k.parents("#available-widgets").length){j=k.closest("div.widget");g=j.children(".widget-inside");h=parseInt(j.find("input.widget-width").val(),10);if(g.is(":hidden")){if(h>250&&g.closest("div.widgets-sortables").length){i.width=h+30+"px";if(g.closest("div.widget-liquid-right").length){i[e]=235-h+"px"}j.css(i)}wpWidgets.fixLabels(j);g.slideDown("fast")}else{g.slideUp("fast",function(){j.css({width:"",margin:""})})}l.preventDefault()}else{if(k.hasClass("widget-control-save")){wpWidgets.save(k.closest("div.widget"),0,1,0);l.preventDefault()}else{if(k.hasClass("widget-control-remove")){wpWidgets.save(k.closest("div.widget"),1,1,0);l.preventDefault()}else{if(k.hasClass("widget-control-close")){wpWidgets.close(k.closest("div.widget"));l.preventDefault()}}}}});d.children(".widget").each(function(){wpWidgets.appendTitle(this);if(a("p.widget-error",this).length){a("a.widget-action",this).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(h,g){g.helper.find("div.widget-description").hide();b=this.id},stop:function(h,g){if(f){a(f).hide()}f=""}});d.sortable({placeholder:"widget-placeholder",items:"> .widget",handle:"> .widget-top > .widget-title",cursor:"move",distance:2,containment:"document",start:function(h,g){g.item.children(".widget-inside").hide();g.item.css({margin:"",width:""})},stop:function(i,g){if(g.item.hasClass("ui-draggable")&&g.item.data("draggable")){g.item.draggable("destroy")}if(g.item.hasClass("deleting")){wpWidgets.save(g.item,1,0,1);g.item.remove();return}var h=g.item.find("input.add_new").val(),l=g.item.find("input.multi_number").val(),k=b,j=a(this).attr("id");g.item.css({margin:"",width:""});b="";if(h){if("multi"==h){g.item.html(g.item.html().replace(/<[^<>]+>/g,function(n){return n.replace(/__i__|%i%/g,l)}));g.item.attr("id",k.replace("__i__",l));l++;a("div#"+k).find("input.multi_number").val(l)}else{if("single"==h){g.item.attr("id","new-"+k);f="div#"+k}}wpWidgets.save(g.item,0,0,1);g.item.find("input.add_new").val("");g.item.find("a.widget-action").click();return}wpWidgets.saveOrder(j)},receive:function(i,h){var g=a(h.sender);if(!a(this).is(":visible")||this.id.indexOf("orphaned_widgets")!=-1){g.sortable("cancel")}if(g.attr("id").indexOf("orphaned_widgets")!=-1&&!g.children(".widget").length){g.parents(".orphan-sidebar").slideUp(400,function(){a(this).remove()})}}}).sortable("option","connectWith","div.widgets-sortables").parent().filter(".closed").children(".widgets-sortables").sortable("disable");a("#available-widgets").droppable({tolerance:"pointer",accept:function(g){return a(g).parent().attr("id")!="widget-list"},drop:function(h,g){g.draggable.addClass("deleting");a("#removing-widget").hide().children("span").html("")},over:function(h,g){g.draggable.addClass("deleting");a("div.widget-placeholder").hide();if(g.draggable.hasClass("ui-sortable-helper")){a("#removing-widget").show().children("span").html(g.draggable.find("div.widget-title").children("h4").html())}},out:function(h,g){g.draggable.removeClass("deleting");a("div.widget-placeholder").show();a("#rem
|