2011-10-06 10:43:01 +02:00
|
|
|
var postboxes;(function(a){postboxes={add_postbox_toggles:function(c,b){this.init(c,b);a(".postbox h3, .postbox .handlediv").click(function(){var d=a(this).parent(".postbox"),e=d.attr("id");if("dashboard_browser_nag"==e){return}d.toggleClass("closed");postboxes.save_state(c);if(e){if(!d.hasClass("closed")&&a.isFunction(postboxes.pbshow)){postboxes.pbshow(e)}else{if(d.hasClass("closed")&&a.isFunction(postboxes.pbhide)){postboxes.pbhide(e)}}}});a(".postbox h3 a").click(function(d){d.stopPropagation()});a(".postbox a.dismiss").click(function(f){var d=a(this).parents(".postbox").attr("id")+"-hide";a("#"+d).prop("checked",false).triggerHandler("click");return false});a(".hide-postbox-tog").click(function(){var d=a(this).val();if(a(this).prop("checked")){a("#"+d).show();if(a.isFunction(postboxes.pbshow)){postboxes.pbshow(d)}}else{a("#"+d).hide();if(a.isFunction(postboxes.pbhide)){postboxes.pbhide(d)}}postboxes.save_state(c)});a('.columns-prefs input[type="radio"]').click(function(){var e=a(this).val(),f,g,d,h=a("#poststuff");e=parseInt(e,10);if(h.length){if(e==2){a(".wrap").removeClass("columns-1").addClass("columns-2");h.addClass("has-right-sidebar");if(!a("#side-info-column #side-sortables").length){a("#side-info-column").append(a("#side-sortables"))}}else{if(e==1){a(".wrap").removeClass("columns-2").addClass("columns-1");h.removeClass("has-right-sidebar");if(!a("#post-body-content #side-sortables").length){a("#normal-sortables").before(a("#side-sortables"))}}}}else{for(f=4;(f>e&&f>1);f--){g=a("#"+postboxes._colname(f)+"-sortables");a("#"+postboxes._colname(f-1)+"-sortables").append(g.children(".postbox"));g.parent().hide()}for(f=e;f>0;f--){g=a("#"+postboxes._colname(f)+"-sortables");d=false;if(g.parent().is(":hidden")){switch(f){case 4:if(a("#column3-sortables .postbox").length>1){g.append(a("#column3-sortables .postbox").last());d=true}case 3:if(!d&&a("#side-sortables .postbox").length>1){g.append(a("#side-sortables .postbox").last());d=true}case 2:if(!d&&a("#normal-sortables .postbox").length>1){g.append(a("#normal-sortables .postbox").last());d=true}default:if(!d){g.addClass("empty-container")}}g.parent().show()}}a(".postbox-container:visible").css("width",100/e+"%")}postboxes.save_order(c)})},init:function(c,b){a.extend(this,b||{});a("#wpbody-content").css("overflow","hidden");a(".meta-box-sortables").sortable({placeholder:"sortable-placeholder",connectWith:".meta-box-sortables",items:".postbox",handle:".hndle",cursor:"move",distance:2,tolerance:"pointer",forcePlaceholderSize:true,helper:"clone",opacity:0.65,stop:function(f,d){if(a(this).find("#dashboard_browser_nag").is(":visible")&&"dashboard_browser_nag"!=this.firstChild.id){a(this).sortable("cancel");return}postboxes.save_order(c);d.item.parent().removeClass("temp-border")},receive:function(f,d){if("dashboard_browser_nag"==d.item[0].id){a(d.sender).sortable("cancel")}a.each(a(".postbox-container:visible"),function(h,e){var g=a(".meta-box-sortables:first",e);if(!g.children(".postbox:visible").length){g.addClass("empty-container")}else{g.removeClass("empty-container")}})}})},save_state:function(d){var b=a(".postbox").filter(".closed").map(function(){return this.id}).get().join(","),c=a(".postbox").filter(":hidden").map(function(){return this.id}).get().join(",");a.post(ajaxurl,{action:"closed-postboxes",closed:b,hidden:c,closedpostboxesnonce:jQuery("#closedpostboxesnonce").val(),page:d})},save_order:function(c){var b,d=a(".columns-prefs input:checked").val()||0;b={action:"meta-box-order",_ajax_nonce:a("#meta-box-order-nonce").val(),page_columns:d,page:c};a(".meta-box-sortables").each(function(){b["order["+this.id.split("-")[0]+"]"]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b)},_colname:function(b){switch(b){case 1:return"normal";break;case 2:return"side";break;case 3:return"column3";break;case 4:return"column4";break;default:return""}},pbshow:false,pbhide:false}}(jQuery));
|