1 var postboxes; |
1 var postboxes; |
|
2 |
2 (function($) { |
3 (function($) { |
3 postboxes = { |
4 postboxes = { |
4 add_postbox_toggles : function(page,args) { |
5 add_postbox_toggles : function(page, args) { |
5 this.init(page,args); |
6 var self = this; |
6 $('.postbox h3, .postbox .handlediv').click( function() { |
7 |
|
8 self.init(page, args); |
|
9 |
|
10 $('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() { |
7 var p = $(this).parent('.postbox'), id = p.attr('id'); |
11 var p = $(this).parent('.postbox'), id = p.attr('id'); |
|
12 |
|
13 if ( 'dashboard_browser_nag' == id ) |
|
14 return; |
|
15 |
8 p.toggleClass('closed'); |
16 p.toggleClass('closed'); |
9 postboxes.save_state(page); |
17 |
|
18 if ( page != 'press-this' ) |
|
19 self.save_state(page); |
|
20 |
10 if ( id ) { |
21 if ( id ) { |
11 if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) ) |
22 if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) ) |
12 postboxes.pbshow(id); |
23 self.pbshow(id); |
13 else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) ) |
24 else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) ) |
14 postboxes.pbhide(id); |
25 self.pbhide(id); |
15 } |
26 } |
16 } ); |
27 }); |
|
28 |
17 $('.postbox h3 a').click( function(e) { |
29 $('.postbox h3 a').click( function(e) { |
18 e.stopPropagation(); |
30 e.stopPropagation(); |
19 } ); |
31 }); |
20 $('.hide-postbox-tog').click( function() { |
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() { |
21 var box = $(this).val(); |
40 var box = $(this).val(); |
22 if ( $(this).attr('checked') ) { |
41 |
|
42 if ( $(this).prop('checked') ) { |
23 $('#' + box).show(); |
43 $('#' + box).show(); |
24 if ( $.isFunction( postboxes.pbshow ) ) |
44 if ( $.isFunction( postboxes.pbshow ) ) |
25 postboxes.pbshow( box ); |
45 self.pbshow( box ); |
26 } else { |
46 } else { |
27 $('#' + box).hide(); |
47 $('#' + box).hide(); |
28 if ( $.isFunction( postboxes.pbhide ) ) |
48 if ( $.isFunction( postboxes.pbhide ) ) |
29 postboxes.pbhide( box ); |
49 self.pbhide( box ); |
30 } |
50 } |
31 postboxes.save_state(page); |
51 self.save_state(page); |
32 } ); |
52 self._mark_area(); |
33 $('.columns-prefs input[type="radio"]').click(function(){ |
|
34 var num = $(this).val(), i, el, p = $('#poststuff'); |
|
35 |
|
36 if ( p.length ) { // write pages |
|
37 if ( num == 2 ) { |
|
38 p.addClass('has-right-sidebar'); |
|
39 $('#side-sortables').addClass('temp-border'); |
|
40 } else if ( num == 1 ) { |
|
41 p.removeClass('has-right-sidebar'); |
|
42 $('#normal-sortables').append($('#side-sortables').children('.postbox')); |
|
43 } |
|
44 } else { // dashboard |
|
45 for ( i = 4; ( i > num && i > 1 ); i-- ) { |
|
46 el = $('#' + colname(i) + '-sortables'); |
|
47 $('#' + colname(i-1) + '-sortables').append(el.children('.postbox')); |
|
48 el.parent().hide(); |
|
49 } |
|
50 for ( i = 1; i <= num; i++ ) { |
|
51 el = $('#' + colname(i) + '-sortables'); |
|
52 if ( el.parent().is(':hidden') ) |
|
53 el.addClass('temp-border').parent().show(); |
|
54 } |
|
55 $('.postbox-container:visible').css('width', 98/num + '%'); |
|
56 } |
|
57 postboxes.save_order(page); |
|
58 }); |
53 }); |
59 |
54 |
60 function colname(n) { |
55 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ |
61 switch (n) { |
56 var n = parseInt($(this).val(), 10); |
62 case 1: |
57 |
63 return 'normal'; |
58 if ( n ) { |
64 break |
59 self._pb_edit(n); |
65 case 2: |
60 self.save_order(page); |
66 return 'side'; |
|
67 break |
|
68 case 3: |
|
69 return 'column3'; |
|
70 break |
|
71 case 4: |
|
72 return 'column4'; |
|
73 break |
|
74 default: |
|
75 return ''; |
|
76 } |
61 } |
77 } |
62 }); |
78 }, |
63 }, |
79 |
64 |
80 init : function(page, args) { |
65 init : function(page, args) { |
|
66 var isMobile = $(document.body).hasClass('mobile'); |
|
67 |
81 $.extend( this, args || {} ); |
68 $.extend( this, args || {} ); |
82 $('#wpbody-content').css('overflow','hidden'); |
69 $('#wpbody-content').css('overflow','hidden'); |
83 $('.meta-box-sortables').sortable({ |
70 $('.meta-box-sortables').sortable({ |
84 placeholder: 'sortable-placeholder', |
71 placeholder: 'sortable-placeholder', |
85 connectWith: '.meta-box-sortables', |
72 connectWith: '.meta-box-sortables', |
86 items: '.postbox', |
73 items: '.postbox', |
87 handle: '.hndle', |
74 handle: '.hndle', |
88 cursor: 'move', |
75 cursor: 'move', |
|
76 delay: ( isMobile ? 200 : 0 ), |
89 distance: 2, |
77 distance: 2, |
90 tolerance: 'pointer', |
78 tolerance: 'pointer', |
91 forcePlaceholderSize: true, |
79 forcePlaceholderSize: true, |
92 helper: 'clone', |
80 helper: 'clone', |
93 opacity: 0.65, |
81 opacity: 0.65, |
94 start: function(e,ui) { |
82 stop: function(e,ui) { |
95 $('body').css({ |
83 if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) { |
96 WebkitUserSelect: 'none', |
84 $(this).sortable('cancel'); |
97 KhtmlUserSelect: 'none' |
|
98 }); |
|
99 /* |
|
100 if ( $.browser.msie ) |
|
101 return; |
85 return; |
102 ui.item.addClass('noclick'); |
86 } |
103 */ |
87 |
|
88 postboxes.save_order(page); |
104 }, |
89 }, |
105 stop: function(e,ui) { |
90 receive: function(e,ui) { |
106 postboxes.save_order(page); |
91 if ( 'dashboard_browser_nag' == ui.item[0].id ) |
107 ui.item.parent().removeClass('temp-border'); |
92 $(ui.sender).sortable('cancel'); |
108 $('body').css({ |
93 |
109 WebkitUserSelect: '', |
94 postboxes._mark_area(); |
110 KhtmlUserSelect: '' |
|
111 }); |
|
112 } |
95 } |
113 }); |
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(); |
114 }, |
104 }, |
115 |
105 |
116 save_state : function(page) { |
106 save_state : function(page) { |
117 var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','), |
107 var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','), |
118 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(','); |
108 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(','); |
|
109 |
119 $.post(ajaxurl, { |
110 $.post(ajaxurl, { |
120 action: 'closed-postboxes', |
111 action: 'closed-postboxes', |
121 closed: closed, |
112 closed: closed, |
122 hidden: hidden, |
113 hidden: hidden, |
123 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |
114 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), |