]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/postbox.dev.js
Wordpress 3.2
[autoinstalls/wordpress.git] / wp-admin / js / postbox.dev.js
1 var postboxes;
2 (function($) {
3         postboxes = {
4                 add_postbox_toggles : function(page,args) {
5                         this.init(page,args);
6                         $('.postbox h3, .postbox .handlediv').click( function() {
7                                 var p = $(this).parent('.postbox'), id = p.attr('id');
8                                 if ( 'dashboard_browser_nag' == id )
9                                         return;
10
11                                 p.toggleClass('closed');
12                                 postboxes.save_state(page);
13                                 if ( id ) {
14                                         if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
15                                                 postboxes.pbshow(id);
16                                         else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
17                                                 postboxes.pbhide(id);
18                                 }
19                         } );
20                         $('.postbox h3 a').click( function(e) {
21                                 e.stopPropagation();
22                         } );
23                         $('.postbox a.dismiss').click( function(e) {
24                                 var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
25                                 $( '#' + hide_id ).prop('checked', false).triggerHandler('click');
26                                 return false;
27                         } );
28                         $('.hide-postbox-tog').click( function() {
29                                 var box = $(this).val();
30
31                                 if ( $(this).prop('checked') ) {
32                                         $('#' + box).show();
33                                         if ( $.isFunction( postboxes.pbshow ) )
34                                                 postboxes.pbshow( box );
35                                 } else {
36                                         $('#' + box).hide();
37                                         if ( $.isFunction( postboxes.pbhide ) )
38                                                 postboxes.pbhide( box );
39                                 }
40                                 postboxes.save_state(page);
41                         } );
42                         $('.columns-prefs input[type="radio"]').click(function(){
43                                 var num = $(this).val(), i, el, p = $('#poststuff');
44
45                                 if ( p.length ) { // write pages
46                                         if ( num == 2 ) {
47                                                 p.addClass('has-right-sidebar');
48                                                 $('#side-sortables').addClass('temp-border');
49                                         } else if ( num == 1 ) {
50                                                 p.removeClass('has-right-sidebar');
51                                                 $('#normal-sortables').append($('#side-sortables').children('.postbox'));
52                                         }
53                                 } else { // dashboard
54                                         for ( i = 4; ( i > num && i > 1 ); i-- ) {
55                                                 el = $('#' + colname(i) + '-sortables');
56                                                 $('#' + colname(i-1) + '-sortables').append(el.children('.postbox'));
57                                                 el.parent().hide();
58                                         }
59                                         for ( i = 1; i <= num; i++ ) {
60                                                 el = $('#' + colname(i) + '-sortables');
61                                                 if ( el.parent().is(':hidden') )
62                                                         el.addClass('temp-border').parent().show();
63                                         }
64                                         $('.postbox-container:visible').css('width', 98/num + '%');
65                                 }
66                                 postboxes.save_order(page);
67                         });
68
69                         function colname(n) {
70                                 switch (n) {
71                                         case 1:
72                                                 return 'normal';
73                                                 break
74                                         case 2:
75                                                 return 'side';
76                                                 break
77                                         case 3:
78                                                 return 'column3';
79                                                 break
80                                         case 4:
81                                                 return 'column4';
82                                                 break
83                                         default:
84                                                 return '';
85                                 }
86                         }
87                 },
88
89                 init : function(page, args) {
90                         $.extend( this, args || {} );
91                         $('#wpbody-content').css('overflow','hidden');
92                         $('.meta-box-sortables').sortable({
93                                 placeholder: 'sortable-placeholder',
94                                 connectWith: '.meta-box-sortables',
95                                 items: '.postbox',
96                                 handle: '.hndle',
97                                 cursor: 'move',
98                                 distance: 2,
99                                 tolerance: 'pointer',
100                                 forcePlaceholderSize: true,
101                                 helper: 'clone',
102                                 opacity: 0.65,
103                                 stop: function(e,ui) {
104                                         if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) {
105                                                 $(this).sortable('cancel');
106                                                 return;
107                                         }
108
109                                         postboxes.save_order(page);
110                                         ui.item.parent().removeClass('temp-border');
111                                 },
112                                 receive: function(e,ui) {
113                                         if ( 'dashboard_browser_nag' == ui.item[0].id )
114                                                 $(ui.sender).sortable('cancel');
115                                 }
116                         });
117                 },
118
119                 save_state : function(page) {
120                         var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
121                                 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
122
123                         $.post(ajaxurl, {
124                                 action: 'closed-postboxes',
125                                 closed: closed,
126                                 hidden: hidden,
127                                 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
128                                 page: page
129                         });
130                 },
131
132                 save_order : function(page) {
133                         var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
134
135                         postVars = {
136                                 action: 'meta-box-order',
137                                 _ajax_nonce: $('#meta-box-order-nonce').val(),
138                                 page_columns: page_columns,
139                                 page: page
140                         }
141                         $('.meta-box-sortables').each( function() {
142                                 postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
143                         } );
144                         $.post( ajaxurl, postVars );
145                 },
146
147                 /* Callbacks */
148                 pbshow : false,
149
150                 pbhide : false
151         };
152
153 }(jQuery));