1 var postboxes;(function(a){postboxes={add_postbox_toggles:function(d,c){var b=this;b.init(d,c);a(".postbox h3, .postbox .handlediv").bind("click.postboxes",function(){var e=a(this).parent(".postbox"),f=e.attr("id");if("dashboard_browser_nag"==f){return}e.toggleClass("closed");if(d!="press-this"){b.save_state(d)}if(f){if(!e.hasClass("closed")&&a.isFunction(postboxes.pbshow)){b.pbshow(f)}else{if(e.hasClass("closed")&&a.isFunction(postboxes.pbhide)){b.pbhide(f)}}}});a(".postbox h3 a").click(function(f){f.stopPropagation()});a(".postbox a.dismiss").bind("click.postboxes",function(g){var f=a(this).parents(".postbox").attr("id")+"-hide";a("#"+f).prop("checked",false).triggerHandler("click");return false});a(".hide-postbox-tog").bind("click.postboxes",function(){var e=a(this).val();if(a(this).prop("checked")){a("#"+e).show();if(a.isFunction(postboxes.pbshow)){b.pbshow(e)}}else{a("#"+e).hide();if(a.isFunction(postboxes.pbhide)){b.pbhide(e)}}b.save_state(d);b._mark_area()});a('.columns-prefs input[type="radio"]').bind("click.postboxes",function(){var e=parseInt(a(this).val(),10);if(e){b._pb_edit(e);b.save_order(d)}})},init:function(d,c){var b=a(document.body).hasClass("mobile");a.extend(this,c||{});a("#wpbody-content").css("overflow","hidden");a(".meta-box-sortables").sortable({placeholder:"sortable-placeholder",connectWith:".meta-box-sortables",items:".postbox",handle:".hndle",cursor:"move",delay:(b?200:0),distance:2,tolerance:"pointer",forcePlaceholderSize:true,helper:"clone",opacity:0.65,stop:function(g,f){if(a(this).find("#dashboard_browser_nag").is(":visible")&&"dashboard_browser_nag"!=this.firstChild.id){a(this).sortable("cancel");return}postboxes.save_order(d)},receive:function(g,f){if("dashboard_browser_nag"==f.item[0].id){a(f.sender).sortable("cancel")}postboxes._mark_area()}});if(b){a(document.body).bind("orientationchange.postboxes",function(){postboxes._pb_change()});this._pb_change()}this._mark_area()},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)},_mark_area:function(){var c=a("div.postbox:visible").length,b=a("#post-body #side-sortables");a("#dashboard-widgets .meta-box-sortables:visible").each(function(f,e){var d=a(this);if(c==1||d.children(".postbox:visible").length){d.removeClass("empty-container")}else{d.addClass("empty-container")}});if(b.length){if(b.children(".postbox:visible").length){b.removeClass("empty-container")}else{if(a("#postbox-container-1").css("width")=="280px"){b.addClass("empty-container")}}}},_pb_edit:function(c){var b=a(".metabox-holder").get(0);b.className=b.className.replace(/columns-\d+/,"columns-"+c)},_pb_change:function(){switch(window.orientation){case 90:case -90:this._pb_edit(2);break;case 0:case 180:if(a("#poststuff").length){this._pb_edit(1)}else{this._pb_edit(2)}break}},pbshow:false,pbhide:false}}(jQuery)); |
1 var postboxes; |
|
2 |
|
3 (function($) { |
|
4 postboxes = { |
|
5 add_postbox_toggles : function(page, args) { |
|
6 var self = this; |
|
7 |
|
8 self.init(page, args); |
|
9 |
|
10 $('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() { |
|
11 var p = $(this).parent('.postbox'), id = p.attr('id'); |
|
12 |
|
13 if ( 'dashboard_browser_nag' == id ) |
|
14 return; |
|
15 |
|
16 p.toggleClass('closed'); |
|
17 |
|
18 if ( page != 'press-this' ) |
|
19 self.save_state(page); |
|
20 |
|
21 if ( id ) { |
|
22 if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) ) |
|
23 self.pbshow(id); |
|
24 else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) ) |
|
25 self.pbhide(id); |
|
26 } |
|
27 }); |
|
28 |
|
29 $('.postbox h3 a').click( function(e) { |
|
30 e.stopPropagation(); |
|
31 }); |
|
32 |
|
33 $('.postbox a.dismiss').bind('click.postboxes', function(e) { |
|
34 var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; |
|
35 $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); |
|
36 return false; |
|
37 }); |
|
38 |
|
39 $('.hide-postbox-tog').bind('click.postboxes', function() { |
|
40 var box = $(this).val(); |
|
41 |
|
42 if ( $(this).prop('checked') ) { |
|
43 $('#' + box).show(); |
|
44 if ( $.isFunction( postboxes.pbshow ) ) |
|
45 self.pbshow( box ); |
|
46 } else { |
|
47 $('#' + box).hide(); |
|
48 if ( $.isFunction( postboxes.pbhide ) ) |
|
49 self.pbhide( box ); |
|
50 } |
|
51 self.save_state(page); |
|
52 self._mark_area(); |
|
53 }); |
|
54 |
|
55 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ |
|
56 var n = parseInt($(this).val(), 10); |
|
57 |
|
58 if ( n ) { |
|
59 self._pb_edit(n); |
|
60 self.save_order(page); |
|
61 } |
|
62 }); |
|
63 }, |
|
64 |
|
65 init : function(page, args) { |
|
66 var isMobile = $(document.body).hasClass('mobile'); |
|
67 |
|
68 $.extend( this, args || {} ); |
|
69 $('#wpbody-content').css('overflow','hidden'); |
|
70 $('.meta-box-sortables').sortable({ |
|
71 placeholder: 'sortable-placeholder', |
|
72 connectWith: '.meta-box-sortables', |
|
73 items: '.postbox', |
|
74 handle: '.hndle', |
|
75 cursor: 'move', |
|
76 delay: ( isMobile ? 200 : 0 ), |
|
77 distance: 2, |
|
78 tolerance: 'pointer', |
|
79 forcePlaceholderSize: true, |
|
80 helper: 'clone', |
|
81 opacity: 0.65, |
|
82 stop: function(e,ui) { |
|
83 if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) { |
|
84 $(this).sortable('cancel'); |
|
85 return; |
|
86 } |
|
87 |
|
88 postboxes.save_order(page); |
|
89 }, |
|
90 receive: function(e,ui) { |
|
91 if ( 'dashboard_browser_nag' == ui.item[0].id ) |
|
92 $(ui.sender).sortable('cancel'); |
|
93 |
|
94 postboxes._mark_area(); |
|
95 } |
|
96 }); |
|
97 |
|
98 if ( isMobile ) { |
|
99 $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); }); |
|
100 this._pb_change(); |
|
101 } |
|
102 |
|
103 this._mark_area(); |
|
104 }, |
|
105 |
|
106 save_state : function(page) { |
|
107 var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','), |
|
108 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(','); |
|
109 |
|
110 $.post(ajaxurl, { |
|
111 action: 'closed-postboxes', |
|
112 closed: closed, |
|
113 hidden: hidden, |
|
114 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |
|
115 page: page |
|
116 }); |
|
117 }, |
|
118 |
|
119 save_order : function(page) { |
|
120 var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; |
|
121 |
|
122 postVars = { |
|
123 action: 'meta-box-order', |
|
124 _ajax_nonce: $('#meta-box-order-nonce').val(), |
|
125 page_columns: page_columns, |
|
126 page: page |
|
127 } |
|
128 $('.meta-box-sortables').each( function() { |
|
129 postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(','); |
|
130 } ); |
|
131 $.post( ajaxurl, postVars ); |
|
132 }, |
|
133 |
|
134 _mark_area : function() { |
|
135 var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); |
|
136 |
|
137 $('#dashboard-widgets .meta-box-sortables:visible').each(function(n, el){ |
|
138 var t = $(this); |
|
139 |
|
140 if ( visible == 1 || t.children('.postbox:visible').length ) |
|
141 t.removeClass('empty-container'); |
|
142 else |
|
143 t.addClass('empty-container'); |
|
144 }); |
|
145 |
|
146 if ( side.length ) { |
|
147 if ( side.children('.postbox:visible').length ) |
|
148 side.removeClass('empty-container'); |
|
149 else if ( $('#postbox-container-1').css('width') == '280px' ) |
|
150 side.addClass('empty-container'); |
|
151 } |
|
152 }, |
|
153 |
|
154 _pb_edit : function(n) { |
|
155 var el = $('.metabox-holder').get(0); |
|
156 el.className = el.className.replace(/columns-\d+/, 'columns-' + n); |
|
157 }, |
|
158 |
|
159 _pb_change : function() { |
|
160 var check = $( 'label.columns-prefs-1 input[type="radio"]' ); |
|
161 |
|
162 switch ( window.orientation ) { |
|
163 case 90: |
|
164 case -90: |
|
165 if ( !check.length || !check.is(':checked') ) |
|
166 this._pb_edit(2); |
|
167 break; |
|
168 case 0: |
|
169 case 180: |
|
170 if ( $('#poststuff').length ) { |
|
171 this._pb_edit(1); |
|
172 } else { |
|
173 if ( !check.length || !check.is(':checked') ) |
|
174 this._pb_edit(2); |
|
175 } |
|
176 break; |
|
177 } |
|
178 }, |
|
179 |
|
180 /* Callbacks */ |
|
181 pbshow : false, |
|
182 |
|
183 pbhide : false |
|
184 }; |
|
185 |
|
186 }(jQuery)); |