WordPress/wp-admin/js/postbox.js

1 line
5.0 KiB
JavaScript
Raw Normal View History

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 d=a(this).val(),f=a("#poststuff"),e=a(".wrap").first();if(d=="auto"){setUserSetting("responsive","1");a(document.body).addClass("responsive");a(window).bind("resize.responsive",function(){postboxes.auto_columns()});if(f.length){e.removeClass("columns-1").removeClass("columns-2")}postboxes.auto_columns()}else{d=parseInt(d,10);deleteUserSetting("responsive");a(document.body).removeClass("responsive");if(f.length){if(d==2){e.removeClass("columns-1").addClass("columns-2");f.addClass("has-right-sidebar");if(!a("#side-info-column #side-sortables").length){a("#side-info-column").append(a("#side-sortables"))}}else{if(d==1){e.removeClass("columns-2").addClass("columns-1");f.removeClass("has-right-sidebar");a("#normal-sortables").before(a("#side-sortables"))}}}else{postboxes._dash_columns(d)}}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")}}})},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)},auto_columns:function(){var c,b;if(!a(document.body).hasClass("responsive")){return}if(adminpage=="post-php"){c=a("#post-body").width();if(c<800){a("#poststuff").removeClass("has-right-sidebar");a("#normal-sortables").before(a("#side-sortables"))}if(c>=800&&c<1150){a("#poststuff").addClass("has-right-sidebar");a("#side-info-column").append(a("#side-sortables"));a(document.body).removeClass("wide-window")}if(c>=1150){a(document.body).addClass("wide-window")}}else{if(adminpage=="index-php"){b=a("#dashboard-widgets-wrap").width();if(b<700){this._dash_columns(1)}if(b>=700&&b<1100){this._dash_columns(2)}if(b>=1100&&b<1500){this._dash_columns(3)}if(b>=1500){this._dash_columns(4)}}}},_dash_columns:function(b){switch(b){case 1:a("#postbox-container-1").append(a("#side-sortables, #column3-sortables, #column4-sortables"));a("#postbox-container-2, #postbox-container-3, #postbox-container-4").hide();break;case 2:a("#postbox-container-2").append(a("#side-sortables, #column3-sortables, #column4-sortables"