[44] | 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 | p.toggleClass('closed');
|
---|
| 9 | postboxes.save_state(page);
|
---|
| 10 | if ( id ) {
|
---|
| 11 | if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
|
---|
| 12 | postboxes.pbshow(id);
|
---|
| 13 | else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
|
---|
| 14 | postboxes.pbhide(id);
|
---|
| 15 | }
|
---|
| 16 | } );
|
---|
| 17 | $('.postbox h3 a').click( function(e) {
|
---|
| 18 | e.stopPropagation();
|
---|
| 19 | } );
|
---|
| 20 | $('.hide-postbox-tog').click( function() {
|
---|
| 21 | var box = $(this).val();
|
---|
| 22 | if ( $(this).attr('checked') ) {
|
---|
| 23 | $('#' + box).show();
|
---|
| 24 | if ( $.isFunction( postboxes.pbshow ) )
|
---|
| 25 | postboxes.pbshow( box );
|
---|
| 26 | } else {
|
---|
| 27 | $('#' + box).hide();
|
---|
| 28 | if ( $.isFunction( postboxes.pbhide ) )
|
---|
| 29 | postboxes.pbhide( box );
|
---|
| 30 | }
|
---|
| 31 | postboxes.save_state(page);
|
---|
| 32 | } );
|
---|
| 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 | });
|
---|
| 59 |
|
---|
| 60 | function colname(n) {
|
---|
| 61 | switch (n) {
|
---|
| 62 | case 1:
|
---|
| 63 | return 'normal';
|
---|
| 64 | break
|
---|
| 65 | case 2:
|
---|
| 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 | }
|
---|
| 77 | }
|
---|
| 78 | },
|
---|
| 79 |
|
---|
| 80 | init : function(page, args) {
|
---|
| 81 | $.extend( this, args || {} );
|
---|
| 82 | $('#wpbody-content').css('overflow','hidden');
|
---|
| 83 | $('.meta-box-sortables').sortable({
|
---|
| 84 | placeholder: 'sortable-placeholder',
|
---|
| 85 | connectWith: '.meta-box-sortables',
|
---|
| 86 | items: '.postbox',
|
---|
| 87 | handle: '.hndle',
|
---|
| 88 | cursor: 'move',
|
---|
| 89 | distance: 2,
|
---|
| 90 | tolerance: 'pointer',
|
---|
| 91 | forcePlaceholderSize: true,
|
---|
| 92 | helper: 'clone',
|
---|
| 93 | opacity: 0.65,
|
---|
| 94 | start: function(e,ui) {
|
---|
| 95 | $('body').css({
|
---|
| 96 | WebkitUserSelect: 'none',
|
---|
| 97 | KhtmlUserSelect: 'none'
|
---|
| 98 | });
|
---|
| 99 | /*
|
---|
| 100 | if ( $.browser.msie )
|
---|
| 101 | return;
|
---|
| 102 | ui.item.addClass('noclick');
|
---|
| 103 | */
|
---|
| 104 | },
|
---|
| 105 | stop: function(e,ui) {
|
---|
| 106 | postboxes.save_order(page);
|
---|
| 107 | ui.item.parent().removeClass('temp-border');
|
---|
| 108 | $('body').css({
|
---|
| 109 | WebkitUserSelect: '',
|
---|
| 110 | KhtmlUserSelect: ''
|
---|
| 111 | });
|
---|
| 112 | }
|
---|
| 113 | });
|
---|
| 114 | },
|
---|
| 115 |
|
---|
| 116 | save_state : function(page) {
|
---|
| 117 | var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
|
---|
| 118 | hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
|
---|
| 119 | $.post(postboxL10n.requestFile, {
|
---|
| 120 | action: 'closed-postboxes',
|
---|
| 121 | closed: closed,
|
---|
| 122 | hidden: hidden,
|
---|
| 123 | closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
---|
| 124 | page: page
|
---|
| 125 | });
|
---|
| 126 | },
|
---|
| 127 |
|
---|
| 128 | save_order : function(page) {
|
---|
| 129 | var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
|
---|
| 130 | postVars = {
|
---|
| 131 | action: 'meta-box-order',
|
---|
| 132 | _ajax_nonce: $('#meta-box-order-nonce').val(),
|
---|
| 133 | page_columns: page_columns,
|
---|
| 134 | page: page
|
---|
| 135 | }
|
---|
| 136 | $('.meta-box-sortables').each( function() {
|
---|
| 137 | postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
|
---|
| 138 | } );
|
---|
| 139 | $.post( postboxL10n.requestFile, postVars );
|
---|
| 140 | },
|
---|
| 141 |
|
---|
| 142 | /* Callbacks */
|
---|
| 143 | pbshow : false,
|
---|
| 144 |
|
---|
| 145 | pbhide : false
|
---|
| 146 | };
|
---|
| 147 |
|
---|
| 148 | }(jQuery));
|
---|