]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/postbox.js
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / js / postbox.js
1 (function($) {
2         postboxes = {
3                 add_postbox_toggles : function(page,args) {
4                         $('.postbox h3, .postbox .handlediv').click( function() {
5                                 $($(this).parent().get(0)).toggleClass('closed');
6                                 postboxes.save_state(page);
7                         } );
8                         $('.postbox h3 a').click( function(e) {
9                                 e.stopPropagation();
10                         } );
11
12                         $('.hide-postbox-tog').click( function() {
13                                 var box = jQuery(this).val();
14                                 if ( jQuery(this).attr('checked') ) {
15                                         jQuery('#' + box).show();
16                                         if ( $.isFunction( postboxes.pbshow ) )
17                                                 postboxes.pbshow( box );
18
19                                 } else {
20                                         jQuery('#' + box).hide();
21                                         if ( $.isFunction( postboxes.pbhide ) )
22                                                 postboxes.pbhide( box );
23
24                                 }
25                                 postboxes.save_state(page);
26                         } );
27
28                         this.expandSidebar();
29                         this.init(page,args);
30                 },
31
32                 expandSidebar : function(doIt) {
33                         if ( doIt || $('#side-sortables > .postbox:visible').length ) {
34                                 if ( ! $('#post-body').hasClass('has-sidebar') ) {
35                                         $('#post-body').addClass('has-sidebar');
36                                         var h = Math.min( $('#post-body').height(), 300 );
37                                         $('#side-sortables').css({'minHeight':h+'px','height':'auto'});
38                                 }
39                         } else {
40                                 $('#post-body').removeClass('has-sidebar');
41                                 $('#side-sortables').css({'minHeight':'0'});
42                                 if ( $.browser.msie && $.browser.version.charAt(0) == 7 )
43                                         $('#side-sortables').css({'height':'0'});
44                         }
45                 },
46
47                 init : function(page, args) {
48                         $.extend( this, args || {} );
49                         $('#wpbody-content').css('overflow','hidden');
50                         $('.meta-box-sortables').sortable( {
51                                 placeholder: 'sortable-placeholder',
52                                 connectWith: [ '.meta-box-sortables' ],
53                                 items: '> .postbox',
54                                 handle: '.hndle',
55                                 distance: 2,
56                                 tolerance: 'pointer',
57                                 toleranceMove: 'tolerance',
58                                 sort: function(e,ui) {
59                                         if ( $(document).width() - e.clientX < 300 ) {
60                                                 if ( ! $('#post-body').hasClass('has-sidebar') ) {
61                                                         var pos = $('#side-sortables').offset();
62
63                                                         $('#side-sortables').append(ui.item)
64                                                         $(ui.placeholder).css({'top':pos.top,'left':pos.left}).width($(ui.item).width())
65                                                         postboxes.expandSidebar(1);
66                                                 }
67                                         }
68                                 },
69                                 stop: function() {
70                                         var postVars = {
71                                                 action: 'meta-box-order',
72                                                 _ajax_nonce: $('#meta-box-order-nonce').val(),
73                                                 page: page
74                                         }
75                                         $('.meta-box-sortables').each( function() {
76                                                 postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
77                                         } );
78                                         $.post( postboxL10n.requestFile, postVars, function() {
79                                                 postboxes.expandSidebar();
80                                         } );
81                                 }
82                         } );
83                 },
84
85                 save_state : function(page) {
86                         var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(',');
87                         var hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
88                         $.post(postboxL10n.requestFile, {
89                                 action: 'closed-postboxes',
90                                 closed: closed,
91                                 hidden: hidden,
92                                 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
93                                 page: page
94                         });
95                         postboxes.expandSidebar();
96                 },
97
98                 /* Callbacks */
99                 pbshow : false,
100
101                 pbhide : false
102         };
103
104 }(jQuery));