Changeset 10291 for trunk/wp-admin/js/postbox.js
- Timestamp:
- 01/02/2009 03:08:58 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/postbox.js
r10019 r10291 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)); 1 (function(a){postboxes={add_postbox_toggles:function(c,b){a(".postbox h3, .postbox .handlediv").click(function(){a(a(this).parent().get(0)).toggleClass("closed");postboxes.save_state(c)});a(".postbox h3 a").click(function(d){d.stopPropagation()});a(".hide-postbox-tog").click(function(){var d=jQuery(this).val();if(jQuery(this).attr("checked")){jQuery("#"+d).show();if(a.isFunction(postboxes.pbshow)){postboxes.pbshow(d)}}else{jQuery("#"+d).hide();if(a.isFunction(postboxes.pbhide)){postboxes.pbhide(d)}}postboxes.save_state(c)});this.expandSidebar();this.init(c,b)},expandSidebar:function(b){if(b||a("#side-sortables > .postbox:visible").length){if(!a("#post-body").hasClass("has-sidebar")){a("#post-body").addClass("has-sidebar");var c=Math.min(a("#post-body").height(),300);a("#side-sortables").css({minHeight:c+"px",height:"auto"})}}else{a("#post-body").removeClass("has-sidebar");a("#side-sortables").css({minHeight:"0"});if(a.browser.msie&&a.browser.version.charAt(0)==7){a("#side-sortables").css({height:"0"})}}},init:function(c,b){a.extend(this,b||{});a("#wpbody-content").css("overflow","hidden");a(".meta-box-sortables").sortable({placeholder:"sortable-placeholder",connectWith:[".meta-box-sortables"],items:"> .postbox",handle:".hndle",distance:2,tolerance:"pointer",toleranceMove:"tolerance",sort:function(f,d){if(a(document).width()-f.clientX<300){if(!a("#post-body").hasClass("has-sidebar")){var g=a("#side-sortables").offset();a("#side-sortables").append(d.item);a(d.placeholder).css({top:g.top,left:g.left}).width(a(d.item).width());postboxes.expandSidebar(1)}}},stop:function(){var d={action:"meta-box-order",_ajax_nonce:a("#meta-box-order-nonce").val(),page:c};a(".meta-box-sortables").each(function(){d["order["+this.id.split("-")[0]+"]"]=a(this).sortable("toArray").join(",")});a.post(postboxL10n.requestFile,d,function(){postboxes.expandSidebar()})}})},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(postboxL10n.requestFile,{action:"closed-postboxes",closed:b,hidden:c,closedpostboxesnonce:jQuery("#closedpostboxesnonce").val(),page:d});postboxes.expandSidebar()},pbshow:false,pbhide:false}}(jQuery));
Note: See TracChangeset
for help on using the changeset viewer.