Show
Ignore:
Timestamp:
10/12/07 16:21:15 (9 months ago)
Author:
donncha
Message:

Merge with WP 2.3 - testing use only!
Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/widgets.php

    r1005 r1069  
    66        wp_die( __( 'Cheatin’ uh?' )); 
    77 
    8 wp_enqueue_script( 'scriptaculous-effects' ); 
    9 wp_enqueue_script( 'scriptaculous-dragdrop' ); 
     8wp_enqueue_script('interface'); 
    109 
    1110function wp_widgets_admin_head() { 
    1211        global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls; 
    13          
    14         define( 'WP_WIDGETS_WIDTH', 1 + 262 * ( count( $wp_registered_sidebars ) ) ); 
    15         define( 'WP_WIDGETS_HEIGHT', 35 * ( count( $wp_registered_widgets ) ) ); 
    16 ?> 
    17         <link rel="stylesheet" href="widgets.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 
     12?> 
     13        <?php wp_admin_css( 'css/widgets' ); ?> 
    1814        <!--[if IE 7]> 
    1915        <style type="text/css"> 
    20         #palette {float:left;
     16               #palette { float: <?php echo ( get_bloginfo( 'text_direction' ) == 'rtl' ) ? 'right' : 'left'; ?>;
    2117        </style> 
    2218        <![endif]--> 
    23         <style type="text/css"> 
    24                 .dropzone ul { height: <?php echo constant( 'WP_WIDGETS_HEIGHT' ); ?>px; } 
    25                 #sbadmin #zones { width: <?php echo constant( 'WP_WIDGETS_WIDTH' ); ?>px; } 
    26         </style> 
    27 <?php 
    28         if ( get_bloginfo( 'text_direction' ) == 'rtl' ) {  
    29 ?> 
    30         <link rel="stylesheet" href="widgets-rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 
    31 <?php 
    32         } 
    33          
     19<?php 
     20 
    3421        $cols = array(); 
    3522        foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
     
    3724        } 
    3825        $cols = implode( ', ', $cols ); 
    39          
     26 
    4027        $widgets = array(); 
    4128        foreach ( $wp_registered_widgets as $name => $widget ) { 
     
    5037        var controldims = new Array; 
    5138        <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?> 
    52                 controldims['<?php echo $widget['id']; ?>control'] = new Array; 
    53                 controldims['<?php echo $widget['id']; ?>control']['width'] = <?php echo (int) $widget['width']; ?>; 
    54                 controldims['<?php echo $widget['id']; ?>control']['height'] = <?php echo (int) $widget['height']; ?>; 
     39                controldims['#<?php echo $widget['id']; ?>control'] = new Array; 
     40                controldims['#<?php echo $widget['id']; ?>control']['width'] = <?php echo (int) $widget['width']; ?>; 
     41                controldims['#<?php echo $widget['id']; ?>control']['height'] = <?php echo (int) $widget['height']; ?>; 
    5542        <?php endforeach; ?> 
    5643        function initWidgets() { 
    5744        <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?> 
    58                 $('<?php echo $widget['id']; ?>popper').onclick = function() {popControl('<?php echo $widget['id']; ?>control');}
    59                 $('<?php echo $widget['id']; ?>closer').onclick = function() {unpopControl('<?php echo $widget['id']; ?>control');}
    60                 new Draggable('<?php echo $widget['id']; ?>control', {revert:false,handle:'controlhandle',starteffect:function(){},endeffect:function(){},change:function(o){dragChange(o);}}); 
     45                jQuery('#<?php echo $widget['id']; ?>popper').click(function() {popControl('#<?php echo $widget['id']; ?>control');})
     46                jQuery('#<?php echo $widget['id']; ?>closer').click(function() {unpopControl('#<?php echo $widget['id']; ?>control');})
     47                jQuery('#<?php echo $widget['id']; ?>control').Draggable({handle: '.controlhandle', zIndex: 1000}); 
    6148                if ( true && window.opera ) 
    62                         $('<?php echo $widget['id']; ?>control').style.border = '1px solid #bbb'
     49                        jQuery('#<?php echo $widget['id']; ?>control').css('border','1px solid #bbb')
    6350        <?php endforeach; ?> 
    64                 if ( true && window.opera ) 
    65                         $('shadow').style.background = 'transparent'; 
    66                 new Effect.Opacity('shadow', {to:0.0}); 
    67                 widgets.map(function(o) {o='widgetprefix-'+o; Position.absolutize(o); Position.relativize(o);} ); 
    68                 $A(Draggables.drags).map(function(o) {o.startDrag(null); o.finishDrag(null);}); 
    69                 //for ( var n in Draggables.drags ) { 
    70                 for ( n=0; n<=Draggables.drags.length; n++ ) { 
    71                         if ( parseInt( n ) ) { 
    72                                 if ( Draggables.drags[n].element.id == 'lastmodule' ) { 
    73                                         Draggables.drags[n].destroy(); 
    74                                         break; 
    75                                 } 
    76                         } 
    77                 } 
    78                 resetPaletteHeight(); 
     51                jQuery('#shadow').css('opacity','0'); 
     52                jQuery(widgets).each(function(o) {o='#widgetprefix-'+o; jQuery(o).css('position','relative');} ); 
    7953        } 
    8054        function resetDroppableHeights() { 
    8155                var max = 6; 
    82                 cols.map(function(o) {var c = $(o).childNodes.length; if ( c > max ) max = c;} ); 
    83                 var height = 35 * ( max + 1); 
    84                 cols.map(function(o) {h = (($(o).childNodes.length + 1) * 35); $(o).style.height = (h > 280 ? h : 280) + 'px';} ); 
    85         } 
    86         function resetPaletteHeight() { 
    87                 var p = $('palette'), pd = $('palettediv'), last = $('lastmodule'); 
    88                 p.appendChild(last); 
    89                 if ( Draggables.activeDraggable && last.id == Draggables.activeDraggable.element.id ) 
    90                         last = last.previousSibling; 
    91                 var y1 = Position.cumulativeOffset(last)[1] + last.offsetHeight; 
    92                 var y2 = Position.cumulativeOffset(pd)[1] + pd.offsetHeight; 
    93                 var dy = y1 - y2; 
    94                 pd.style.height = (pd.offsetHeight + dy + 9) + "px"; 
     56                jQuery.map(cols, function(o) { 
     57                        var c = jQuery('#' + o + ' li').length; 
     58                        if ( c > max ) max = c; 
     59                }); 
     60                var maxheight = 35 * ( max + 1); 
     61                jQuery.map(cols, function(o) { 
     62                        height = 0 == jQuery('#' + o + ' li').length ? maxheight - jQuery('#' + o + 'placemat').height() : maxheight; 
     63                        jQuery('#' + o).height(height); 
     64                }); 
    9565        } 
    9666        function maxHeight(elm) { 
     
    9868                bodyheight = document.body.clientHeight; 
    9969                var height = htmlheight > bodyheight ? htmlheight : bodyheight; 
    100                 $(elm).style.height = height + 'px'; 
     70                jQuery(elm).height(height); 
     71        } 
     72        function getViewportDims() { 
     73                var x,y; 
     74                if (self.innerHeight) { // all except Explorer 
     75                        x = self.innerWidth; 
     76                        y = self.innerHeight; 
     77                } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
     78                        x = document.documentElement.clientWidth; 
     79                        y = document.documentElement.clientHeight; 
     80                } else if (document.body) { // other Explorers 
     81                        x = document.body.clientWidth; 
     82                        y = document.body.clientHeight; 
     83                } 
     84                return new Array(x,y); 
    10185        } 
    10286        function dragChange(o) { 
    103                 el = o.element ? o.element : $(o); 
    104                 var p = Position.page(el); 
    105                 var right = p[0]; 
    106                 var top = p[1]; 
    107                 var left = $('shadow').offsetWidth - (el.offsetWidth + right); 
    108                 var bottom = $('shadow').offsetHeight - (el.offsetHeight + top); 
    109                 if ( right < 1 ) el.style.left = 0; 
    110                 if ( top < 1 ) el.style.top = 0; 
    111                 if ( left < 1 ) el.style.left = (left + right) + 'px'; 
    112                 if ( bottom < 1 ) el.style.top = (top + bottom) + 'px'; 
     87                var p = getViewportDims(); 
     88                var screenWidth = p[0]; 
     89                var screenHeight = p[1]; 
     90                var elWidth = parseInt( jQuery(o).css('width') ); 
     91                var elHeight = parseInt( jQuery(o).css('height') ); 
     92                var elLeft = parseInt( jQuery(o).css('left') ); 
     93                var elTop = parseInt( jQuery(o).css('top') ); 
     94                if ( screenWidth < ( parseInt(elLeft) + parseInt(elWidth) ) ) 
     95                        jQuery(o).css('left', ( screenWidth - elWidth ) + 'px' ); 
     96                if ( screenHeight < ( parseInt(elTop) + parseInt(elHeight) ) ) 
     97                        jQuery(o).css('top', ( screenHeight - elHeight ) + 'px' ); 
     98                if ( elLeft < 1 ) 
     99                        jQuery(o).css('left', '1px'); 
     100                if ( elTop < 1 ) 
     101                        jQuery(o).css('top', '1px'); 
    113102        } 
    114103        function popControl(elm) { 
    115                 el = $(elm); 
    116                 el.style.width = controldims[elm]['width'] + 'px'; 
    117                 el.style.height = controldims[elm]['height'] + 'px'; 
    118104                var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2; 
    119105                var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2; 
    120                 el.style.position = 'absolute'; 
    121                 el.style.right = '' + x + 'px'; 
    122                 el.style.top = '' + y + 'px'; 
    123                 el.style.zIndex = 1000; 
    124                 el.className='control'; 
    125                 $('shadow').onclick = function() {unpopControl(elm);}; 
    126             window.onresize = function(){maxHeight('shadow');dragChange(elm);}; 
     106                jQuery(elm).css({display: 'block', width: controldims[elm]['width'] + 'px', height: controldims[elm]['height'] + 'px', position: 'absolute', right: x + 'px', top: y + 'px', zIndex: '1000' }); 
     107                jQuery(elm).attr('class','control'); 
     108                jQuery('#shadow').click(function() {unpopControl(elm);}); 
     109                window.onresize = function(){maxHeight('#shadow');dragChange(elm);}; 
    127110                popShadow(); 
    128111        } 
    129112        function popShadow() { 
    130                 maxHeight('shadow'); 
    131                 var shadow = $('shadow'); 
    132                 shadow.style.zIndex = 999; 
    133                 shadow.style.display = 'block'; 
    134             new Effect.Opacity('shadow', {duration:0.5, from:0.0, to:0.2}); 
     113                maxHeight('#shadow'); 
     114                jQuery('#shadow').css({zIndex: '999', display: 'block'}); 
     115                jQuery('#shadow').fadeTo('fast', 0.2); 
    135116        } 
    136117        function unpopShadow() { 
    137             new Effect.Opacity('shadow', {to:0.0}); 
    138                 $('shadow').style.display = 'none'; 
     118                jQuery('#shadow').fadeOut('fast', function() {jQuery('#shadow').hide()}); 
    139119        } 
    140120        function unpopControl(el) { 
    141                 $(el).className='hidden'; 
     121                jQuery(el).attr('class','hidden'); 
     122                jQuery(el).hide(); 
    142123                unpopShadow(); 
    143124        } 
    144125        function serializeAll() { 
    145         <?php foreach ( $wp_registered_sidebars as $index => $sidebar ) : ?> 
    146                 $('<?php echo $index; ?>order').value = Sortable.serialize('<?php echo $index; ?>'); 
     126        <?php $i = 0; foreach ( $wp_registered_sidebars as $index => $sidebar ) : $i++; ?> 
     127                var serial<?php echo $i ?> = jQuery.SortSerialize('<?php echo $index ?>'); 
     128                jQuery('#<?php echo $index ?>order').attr('value',serial<?php echo $i ?>.hash.replace(/widgetprefix-/g, '')); 
    147129        <?php endforeach; ?> 
    148130        } 
    149131        function updateAll() { 
     132                jQuery.map(cols, function(o) { 
     133                        if ( jQuery('#' + o + ' li').length ) 
     134                                jQuery('#'+o+'placemat span.handle').hide(); 
     135                        else 
     136                                jQuery('#'+o+'placemat span.handle').show(); 
     137                }); 
    150138                resetDroppableHeights(); 
    151                 resetPaletteHeight(); 
    152                 cols.map(function(o){ 
    153                         var pm = $(o+'placematt'); 
    154                         if ( $(o).childNodes.length == 0 ) { 
    155                                 pm.style.display = 'block'; 
    156                                 //Position.absolutize(o+'placematt'); 
    157                         } else { 
    158                                 pm.style.display = 'none'; 
    159                         } 
    160                 }); 
    161         } 
    162         function noSelection(event) { 
    163                 if ( document.selection ) { 
    164                         var range = document.selection.createRange(); 
    165                         range.collapse(false); 
    166                         range.select(); 
    167                         return false; 
    168                 } 
    169         } 
    170         addLoadEvent(updateAll); 
    171         addLoadEvent(initWidgets); 
    172         Event.observe(window, 'resize', resetPaletteHeight); 
     139        } 
     140        jQuery(document).ready( function() { 
     141                updateAll(); 
     142                initWidgets(); 
     143        }); 
    173144// ]]> 
    174145</script> 
     
    180151function wp_widget_draggable( $name ) { 
    181152        global $wp_registered_widgets, $wp_registered_widget_controls; 
    182          
     153 
    183154        if ( !isset( $wp_registered_widgets[$name] ) ) { 
    184155                return; 
    185156        } 
    186          
     157 
    187158        $sanitized_name = sanitize_title( $wp_registered_widgets[$name]['id'] ); 
    188159        $link_title = __( 'Configure' ); 
    189         $popper = ( isset( $wp_registered_widget_controls[$name] ) )  
     160        $popper = ( isset( $wp_registered_widget_controls[$name] ) ) 
    190161                ? ' <div class="popper" id="' . $sanitized_name . 'popper" title="' . $link_title . '">&#8801;</div>' 
    191162                : ''; 
    192          
     163 
    193164        $output = '<li class="module" id="widgetprefix-%1$s"><span class="handle">%2$s</span></li>'; 
    194          
     165 
    195166        printf( $output, $sanitized_name, $wp_registered_widgets[$name]['name'] . $popper ); 
    196167} 
     
    205176        <div class="wrap"> 
    206177                <h2><?php _e( 'No Sidebars Defined' ); ?></h2> 
    207                  
     178 
    208179                <p><?php _e( 'You are seeing this message because the theme you are currently using isn&#8217;t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="http://automattic.com/code/widgets/themes/">follow these instructions</a>.' ); /* TODO: article on codex */; ?></p> 
    209180        </div> 
    210181<?php 
    211          
     182 
    212183        require_once 'admin-footer.php'; 
    213184        exit; 
     
    222193if ( isset( $_POST['action'] ) ) { 
    223194        check_admin_referer( 'widgets-save-widget-order' ); 
    224          
     195 
    225196        switch ( $_POST['action'] ) { 
    226197                case 'default' : 
     
    228199                        wp_set_sidebars_widgets( $sidebars_widgets ); 
    229200                break; 
    230                  
     201 
    231202                case 'save_widget_order' : 
    232203                        $sidebars_widgets = array(); 
    233                          
     204 
    234205                        foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
    235206                                $postindex = $index . 'order'; 
    236                                  
     207 
    237208                                parse_str( $_POST[$postindex], $order ); 
    238                                  
     209 
    239210                                $new_order = $order[$index]; 
    240                                  
     211 
    241212                                if ( is_array( $new_order ) ) { 
    242213                                        foreach ( $new_order as $sanitized_name ) { 
     
    249220                                } 
    250221                        } 
    251                          
     222 
    252223                        wp_set_sidebars_widgets( $sidebars_widgets ); 
    253224                break; 
     
    261232foreach ( $wp_registered_widgets as $name => $widget ) { 
    262233        $is_active = false; 
    263          
     234 
    264235        foreach ( $wp_registered_sidebars as $index => $sidebar ) { 
    265236                if ( is_array( $sidebars_widgets[$index] ) && in_array( $name, $sidebars_widgets[$index] ) ) { 
     
    268239                } 
    269240        } 
    270          
     241 
    271242        if ( !$is_active ) { 
    272243                $inactive_widgets[] = $name; 
     
    298269        <div class="wrap"> 
    299270                <h2><?php _e( 'Sidebar Arrangement' ); ?></h2> 
    300                  
     271 
    301272                <p><?php _e( 'You can drag and drop widgets onto your sidebar below.' ); ?></p> 
    302                  
     273 
    303274                <form id="sbadmin" method="post" onsubmit="serializeAll();"> 
    304275                        <p class="submit"> 
     
    310281                        ?> 
    311282                                <input type="hidden" id="<?php echo $index; ?>order" name="<?php echo $index; ?>order" value="" /> 
    312                                  
     283 
    313284                                <div class="dropzone"> 
    314285                                        <h3><?php echo $sidebar['name']; ?></h3> 
    315                                          
    316                                         <div id="<?php echo $index; ?>placematt" class="module placemat"> 
     286 
     287                                        <div id="<?php echo $index; ?>placemat" class="placemat"> 
    317288                                                <span class="handle"> 
    318289                                                        <h4><?php _e( 'Default Sidebar' ); ?></h4> 
     
    320291                                                </span> 
    321292                                        </div> 
    322                                          
     293 
    323294                                        <ul id="<?php echo $index; ?>"> 
    324295                                        <?php 
     
    334305                                } 
    335306                        ?> 
    336                          
    337                         <br class="clear" /> 
    338                          
     307 
    339308                        </div> 
    340                  
     309 
    341310                        <div id="palettediv"> 
    342311                                <h3><?php _e( 'Available Widgets' ); ?></h3> 
    343                          
     312 
    344313                                <ul id="palette"> 
    345314                                <?php 
     
    348317                                        } 
    349318                                ?> 
    350                                         <li id="lastmodule"><span></span></li> 
    351319                                </ul> 
    352320                        </div> 
    353                  
     321 
    354322                        <script type="text/javascript"> 
    355323                        // <![CDATA[ 
     324                                jQuery(document).ready(function(){ 
    356325                        <?php foreach ( $containers as $container ) { ?> 
    357                                 Sortable.create("<?php echo $container; ?>",
    358                                         dropOnEmpty: true, containment: [<?php echo $c_string; ?>],  
    359                                         handle: 'handle', constraint: false, onUpdate: updateAll,  
    360                                        format: /^widgetprefix-(.*)$/ 
     326                                       jQuery('ul#<?php echo $container; ?>').Sortable(
     327                                               accept: 'module', activeclass: 'activeDraggable', opacity: 0.8, revert: true, onStop: updateAll 
     328                                        }); 
     329                        <?php } ?> 
    361330                                }); 
    362                         <?php } ?> 
    363331                        // ]]> 
    364332                        </script> 
    365                  
     333 
    366334                        <p class="submit"> 
    367335                        <?php wp_nonce_field( 'widgets-save-widget-order' ); ?> 
     
    369337                                <input type="submit" value="<?php _e( 'Save Changes &raquo;' ); ?>" /> 
    370338                        </p> 
    371                  
     339 
    372340                        <div id="controls"> 
    373341                        <?php foreach ( $wp_registered_widget_controls as $name => $widget ) { ?> 
     
    382350                        </div> 
    383351                </form> 
    384                  
     352 
    385353                <br class="clear" /> 
    386354        </div> 
    387          
     355 
    388356        <div id="shadow"> </div> 
    389          
     357 
    390358        <?php do_action( 'sidebar_admin_page' ); ?> 
    391359