mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-18 16:45:31 +01:00
59c45c41e4
- Enable arranging only when the Screen Options tab is open. - Prevent accidental/unintended dragging. Seen it happen mostly on laptops when using the mousepad/trackpad. - Improve discoverability and usefulness by always showing the "drop zones" outline when postboxes are draggable/arrangeable. - Add some (brief) explanation to the Screen Options tab helping the user understand what options are available and how to change them. This is especially helpful for screen reader users to give an idea how to use the screen options and what to expect. - Fix/enhance some of the code in `postbox.js` and make it coding standards compliant. See #50699. Built from https://develop.svn.wordpress.org/trunk@49179 git-svn-id: http://core.svn.wordpress.org/trunk@48941 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
7.0 KiB
JavaScript
2 lines
7.0 KiB
JavaScript
/*! This file is auto-generated */
|
|
!function(i){var a=i(document),r=i("body"),d=wp.i18n.__;window.postboxes={handle_click:function(){var e,s=i(this),o=s.closest(".postbox"),t=o.attr("id");"dashboard_browser_nag"!==t&&(o.toggleClass("closed"),e=!o.hasClass("closed"),s.hasClass("handlediv")?s.attr("aria-expanded",e):s.closest(".postbox").find("button.handlediv").attr("aria-expanded",e),"press-this"!==postboxes.page&&postboxes.save_state(),t&&(!o.hasClass("closed")&&i.isFunction(postboxes.pbshow)?postboxes.pbshow(t):o.hasClass("closed")&&i.isFunction(postboxes.pbhide)&&postboxes.pbhide(t)),a.trigger("postbox-toggled",o))},handleOrder:function(){var e,s=i(this),o=s.closest(".postbox"),t=o.attr("id"),a=o.closest(".meta-box-sortables").find(".postbox:visible"),r=a.length,n=a.index(o);if("dashboard_browser_nag"!==t){if("true"===s.attr("aria-disabled"))return e=s.hasClass("handle-order-higher")?d("The box is on the first position"):d("The box is on the last position"),void wp.a11y.speak(e);if(s.hasClass("handle-order-higher")){if(0===n)return void postboxes.handleOrderBetweenSortables("previous",s,o);o.prevAll(".postbox:visible").eq(0).before(o),s.focus(),postboxes.updateOrderButtonsProperties(),postboxes.save_order()}else if(s.hasClass("handle-order-lower")){if(n+1===r)return void postboxes.handleOrderBetweenSortables("next",s,o);o.nextAll(".postbox:visible").eq(0).after(o),s.focus(),postboxes.updateOrderButtonsProperties(),postboxes.save_order()}}},handleOrderBetweenSortables:function(e,s,o){var t,a,r=s.closest(".meta-box-sortables").attr("id"),n=[];i(".meta-box-sortables:visible").each(function(){n.push(i(this).attr("id"))}),1!==n.length&&(t=i.inArray(r,n),a=o.detach(),"previous"===e&&i(a).appendTo("#"+n[t-1]),"next"===e&&i(a).prependTo("#"+n[t+1]),postboxes._mark_area(),s.focus(),postboxes.save_order())},showArrangeArrows:function(){i(".postbox-arrange-arrow").attr("aria-disabled","false").removeClass("hidden"),postboxes._mark_area()},hideArrangeArrows:function(){i(".postbox-arrange-arrow").attr("aria-disabled","true").addClass("hidden"),postboxes._mark_area()},updateOrderButtonsProperties:function(){var e=i(".postbox:visible"),s=i(".meta-box-sortables:visible").not(".unused-container").filter(function(e,s){return!(0<e&&0===s.clientHeight)});1!==s.length||1!==e.length?(r.hasClass("screen-options-open")&&i(".postbox-arrange-arrow").removeClass("hidden").attr("aria-disabled","false"),e.first().parent()[0]===s.first()[0]&&e.first().find(".handle-order-higher").attr("aria-disabled","true"),e.last().parent()[0]===s.last()[0]&&e.last().find(".handle-order-lower").attr("aria-disabled","true")):i(".postbox-arrange-arrow").addClass("hidden").attr("aria-disabled","true")},add_postbox_toggles:function(e,s){var o=i(".postbox .hndle, .postbox .handlediv"),t=i(".postbox .postbox-arrange-arrow");this.page=e,this.init(e,s),o.on("click.postboxes",this.handle_click),t.on("click.postboxes",this.handleOrder),i(".postbox .hndle a").on("click",function(e){e.stopPropagation()}),i(".postbox a.dismiss").on("click.postboxes",function(e){var s=i(this).parents(".postbox").attr("id")+"-hide";e.preventDefault(),i("#"+s).prop("checked",!1).triggerHandler("click")}),i(".hide-postbox-tog").on("click.postboxes",function(){var e=i(this),s=e.val(),o=i("#"+s);e.prop("checked")?(o.show(),i.isFunction(postboxes.pbshow)&&postboxes.pbshow(s)):(o.hide(),i.isFunction(postboxes.pbhide)&&postboxes.pbhide(s)),postboxes.save_state(),postboxes._mark_area(),a.trigger("postbox-toggled",o)}),i('.columns-prefs input[type="radio"]').on("click.postboxes",function(){var e=parseInt(i(this).val(),10);e&&(postboxes._pb_edit(e),postboxes.save_order())}),a.on("screen:options:open",function(){r.addClass("screen-options-open"),postboxes.initializeSortable(),postboxes.showArrangeArrows()}).on("screen:options:close",function(){r.removeClass("screen-options-open"),i(".meta-box-sortables").sortable("destroy"),postboxes.hideArrangeArrows()})},initializeSortable:function(){var s=0<a.find("#screen-options-wrap").length;i(".meta-box-sortables").sortable({placeholder:"sortable-placeholder",connectWith:".meta-box-sortables",items:".postbox",handle:".hndle",cursor:"move",delay:r.hasClass("mobile")?200:0,distance:2,tolerance:"pointer",opacity:.65,forcePlaceholderSize:!0,containment:"#wpwrap",helper:function(e,s){return s.clone().find(":input").attr("name",function(e,s){return"sort_"+parseInt(1e5*Math.random(),10).toString()+"_"+s}).end()},start:function(){s||r.addClass("screen-options-open"),i(".meta-box-sortables").sortable("refreshPositions")},stop:function(){var e=i(this);s||r.removeClass("screen-options-open"),e.find("#dashboard_browser_nag").is(":visible")&&"dashboard_browser_nag"!=this.firstChild.id?e.sortable("cancel"):(postboxes._mark_area(),postboxes.save_order())},receive:function(e,s){"dashboard_browser_nag"==s.item[0].id&&i(s.sender).sortable("cancel"),a.trigger("postbox-moved",s.item)}})},init:function(e,s){i.extend(this,s||{}),r.hasClass("mobile")&&(r.on("orientationchange.postboxes",function(){postboxes._pb_change()}),this._pb_change()),this.updateOrderButtonsProperties(),a.on("postbox-toggled",this._mark_area),i(".postbox .handlediv").each(function(){var e=i(this);e.attr("aria-expanded",!e.closest(".postbox").hasClass("closed"))}),a.find("#screen-options-wrap").length||(this.initializeSortable(),this.showArrangeArrows())},save_state:function(){var e,s;"nav-menus"!==postboxes.page&&(e=i(".postbox").filter(".closed").map(function(){return this.id}).get().join(","),s=i(".postbox").filter(":hidden").map(function(){return this.id}).get().join(","),i.post(ajaxurl,{action:"closed-postboxes",closed:e,hidden:s,closedpostboxesnonce:i("#closedpostboxesnonce").val(),page:postboxes.page}))},save_order:function(){var e={action:"meta-box-order",_ajax_nonce:i("#meta-box-order-nonce").val(),page_columns:i(".columns-prefs input:checked").val()||0,page:postboxes.page};i(".meta-box-sortables").each(function(){e["order["+this.id.split("-")[0]+"]"]=i(this).sortable("toArray").join(",")}),i.post(ajaxurl,e,function(e){e.success&&wp.a11y.speak(d("The boxes order has been saved."))})},_mark_area:function(){var t=i(".postbox:visible");i(".meta-box-sortables:visible").each(function(e,s){var o=i(s);if(o.children(".postbox:visible").length)o.removeClass("empty-container unused-container").removeAttr("data-emptystring");else{if(o.addClass("empty-container"),t.length<1)return 0===e?o.attr("data-emptystring",d("Enable screen elements from the Screen Options menu")):o.addClass("unused-container"),!1;o.attr("data-emptystring",d("Drag screen elements here")),t.length<=e?o.addClass("unused-container"):o.removeClass("unused-container")}}),r.hasClass("screen-options-open")&&postboxes.updateOrderButtonsProperties()},_pb_edit:function(e){var s=i(".metabox-holder").get(0);s&&(s.className=s.className.replace(/columns-\d+/,"columns-"+e)),i(document).trigger("postboxes-columnchange")},_pb_change:function(){var e=i('label.columns-prefs-1 input[type="radio"]');switch(window.orientation){case 90:case-90:e.length&&e.is(":checked")||this._pb_edit(2);break;case 0:case 180:i("#poststuff").length?this._pb_edit(1):e.length&&e.is(":checked")||this._pb_edit(2)}},pbshow:!1,pbhide:!1}}(jQuery); |