Make WordPress Core

Changeset 5343


Ignore:
Timestamp:
04/29/2007 08:16:26 PM (18 years ago)
Author:
rob1n
Message:

Move widgets' JS into the <head> of widgets.php. Should fix text/rss widget controls. see #4169

Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/wp-admin/widgets.php

    r5324 r5343  
    66wp_enqueue_script( 'scriptaculous-dragdrop' );
    77
    8 wp_register_script( 'widgets-admin', '/wp-admin/widgets.js.php', array( 'scriptaculous-effects', 'scriptaculous-dragdrop' ), '1.0' );
    9 wp_enqueue_script( 'widgets-admin' );
    10 
    118function wp_widgets_admin_head() {
    12     global $wp_registered_sidebars, $wp_registered_widgets;
     9    global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls;
    1310   
    1411    define( 'WP_WIDGETS_WIDTH', 1 + 262 * ( count( $wp_registered_sidebars ) ) );
     
    2017        #sbadmin #zones { width: <?php echo constant( 'WP_WIDGETS_WIDTH' ); ?>px; }
    2118    </style>
    22 <?php if ( ('rtl' == get_bloginfo('text_direction')) ) : ?>
     19<?php
     20    if ( get_bloginfo( 'text_direction' ) == 'rtl' ) {
     21?>
    2322    <link rel="stylesheet" href="widgets-rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    2423<?php
    25     endif;
    26 }
    27 
     24    }
     25   
     26    $cols = array();
     27    foreach ( $wp_registered_sidebars as $index => $sidebar ) {
     28        $cols[] = '\'' . $index . '\'';
     29    }
     30    $cols = implode( ', ', $cols );
     31   
     32    $widgets = array();
     33    foreach ( $wp_registered_widgets as $name => $widget ) {
     34        $widgets[] = '\'' . $widget['id'] . '\'';
     35    }
     36    $widgets = implode( ', ', $widgets );
     37?>
     38<script type="text/javascript">
     39// <![CDATA[
     40    var cols = [<?php echo $cols; ?>];
     41    var widgets = [<?php echo $widgets; ?>];
     42    var controldims = new Array;
     43    <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
     44        controldims['<?php echo $widget['id']; ?>control'] = new Array;
     45        controldims['<?php echo $widget['id']; ?>control']['width'] = <?php echo (int) $widget['width']; ?>;
     46        controldims['<?php echo $widget['id']; ?>control']['height'] = <?php echo (int) $widget['height']; ?>;
     47    <?php endforeach; ?>
     48    function initWidgets() {
     49    <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
     50        $('<?php echo $widget['id']; ?>popper').onclick = function() {popControl('<?php echo $widget['id']; ?>control');};
     51        $('<?php echo $widget['id']; ?>closer').onclick = function() {unpopControl('<?php echo $widget['id']; ?>control');};
     52        new Draggable('<?php echo $widget['id']; ?>control', {revert:false,handle:'controlhandle',starteffect:function(){},endeffect:function(){},change:function(o){dragChange(o);}});
     53        if ( true && window.opera )
     54            $('<?php echo $widget['id']; ?>control').style.border = '1px solid #bbb';
     55    <?php endforeach; ?>
     56        if ( true && window.opera )
     57            $('shadow').style.background = 'transparent';
     58        new Effect.Opacity('shadow', {to:0.0});
     59        widgets.map(function(o) {o='widgetprefix-'+o; Position.absolutize(o); Position.relativize(o);} );
     60        $A(Draggables.drags).map(function(o) {o.startDrag(null); o.finishDrag(null);});
     61        for ( var n in Draggables.drags ) {
     62            if ( Draggables.drags[n].element.id == 'lastmodule' ) {
     63                Draggables.drags[n].destroy();
     64                break;
     65            }
     66        }
     67        resetPaletteHeight();
     68    }
     69    function resetDroppableHeights() {
     70        var max = 6;
     71        cols.map(function(o) {var c = $(o).childNodes.length; if ( c > max ) max = c;} );
     72        var height = 35 * ( max + 1);
     73        cols.map(function(o) {h = (($(o).childNodes.length + 1) * 35); $(o).style.height = (h > 280 ? h : 280) + 'px';} );
     74    }
     75    function resetPaletteHeight() {
     76        var p = $('palette'), pd = $('palettediv'), last = $('lastmodule');
     77        p.appendChild(last);
     78        if ( Draggables.activeDraggable && last.id == Draggables.activeDraggable.element.id )
     79            last = last.previousSibling;
     80        var y1 = Position.cumulativeOffset(last)[1] + last.offsetHeight;
     81        var y2 = Position.cumulativeOffset(pd)[1] + pd.offsetHeight;
     82        var dy = y1 - y2;
     83        pd.style.height = (pd.offsetHeight + dy + 9) + "px";
     84    }
     85    function maxHeight(elm) {
     86        htmlheight = document.body.parentNode.clientHeight;
     87        bodyheight = document.body.clientHeight;
     88        var height = htmlheight > bodyheight ? htmlheight : bodyheight;
     89        $(elm).style.height = height + 'px';
     90    }
     91    function dragChange(o) {
     92        el = o.element ? o.element : $(o);
     93        var p = Position.page(el);
     94        var right = p[0];
     95        var top = p[1];
     96        var left = $('shadow').offsetWidth - (el.offsetWidth + left);
     97        var bottom = $('shadow').offsetHeight - (el.offsetHeight + top);
     98        if ( right < 1 ) el.style.left = 0;
     99        if ( top < 1 ) el.style.top = 0;
     100        if ( left < 1 ) el.style.left = (left + right) + 'px';
     101        if ( bottom < 1 ) el.style.top = (top + bottom) + 'px';
     102    }
     103    function popControl(elm) {
     104        el = $(elm);
     105        el.style.width = controldims[elm]['width'] + 'px';
     106        el.style.height = controldims[elm]['height'] + 'px';
     107        var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2;
     108        var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2;
     109        el.style.position = 'absolute';
     110        el.style.right = '' + x + 'px';
     111        el.style.top = '' + y + 'px';
     112        el.style.zIndex = 1000;
     113        el.className='control';
     114        $('shadow').onclick = function() {unpopControl(elm);};
     115        window.onresize = function(){maxHeight('shadow');dragChange(elm);};
     116        popShadow();
     117    }
     118    function popShadow() {
     119        maxHeight('shadow');
     120        var shadow = $('shadow');
     121        shadow.style.zIndex = 999;
     122        shadow.style.display = 'block';
     123        new Effect.Opacity('shadow', {duration:0.5, from:0.0, to:0.2});
     124    }
     125    function unpopShadow() {
     126        new Effect.Opacity('shadow', {to:0.0});
     127        $('shadow').style.display = 'none';
     128    }
     129    function unpopControl(el) {
     130        $(el).className='hidden';
     131        unpopShadow();
     132    }
     133    function serializeAll() {
     134    <?php foreach ( $wp_registered_sidebars as $index => $sidebar ) : ?>
     135        $('<?php echo $index; ?>order').value = Sortable.serialize('<?php echo $index; ?>');
     136    <?php endforeach; ?>
     137    }
     138    function updateAll() {
     139        resetDroppableHeights();
     140        resetPaletteHeight();
     141        cols.map(function(o){
     142            var pm = $(o+'placematt');
     143            if ( $(o).childNodes.length == 0 ) {
     144                pm.style.display = 'block';
     145                Position.absolutize(o+'placematt');
     146            } else {
     147                pm.style.display = 'none';
     148            }
     149        });
     150    }
     151    function noSelection(event) {
     152        if ( document.selection ) {
     153            var range = document.selection.createRange();
     154            range.collapse(false);
     155            range.select();
     156            return false;
     157        }
     158    }
     159    addLoadEvent(updateAll);
     160    addLoadEvent(initWidgets);
     161    Event.observe(window, 'resize', resetPaletteHeight);
     162// ]]>
     163</script>
     164<?php
     165}
    28166add_action( 'admin_head', 'wp_widgets_admin_head' );
    29167do_action( 'sidebar_admin_setup' );
  • trunk/wp-admin/widgets.php

    r5324 r5343  
    66wp_enqueue_script( 'scriptaculous-dragdrop' );
    77
    8 wp_register_script( 'widgets-admin', '/wp-admin/widgets.js.php', array( 'scriptaculous-effects', 'scriptaculous-dragdrop' ), '1.0' );
    9 wp_enqueue_script( 'widgets-admin' );
    10 
    118function wp_widgets_admin_head() {
    12     global $wp_registered_sidebars, $wp_registered_widgets;
     9    global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls;
    1310   
    1411    define( 'WP_WIDGETS_WIDTH', 1 + 262 * ( count( $wp_registered_sidebars ) ) );
     
    2017        #sbadmin #zones { width: <?php echo constant( 'WP_WIDGETS_WIDTH' ); ?>px; }
    2118    </style>
    22 <?php if ( ('rtl' == get_bloginfo('text_direction')) ) : ?>
     19<?php
     20    if ( get_bloginfo( 'text_direction' ) == 'rtl' ) {
     21?>
    2322    <link rel="stylesheet" href="widgets-rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" />
    2423<?php
    25     endif;
    26 }
    27 
     24    }
     25   
     26    $cols = array();
     27    foreach ( $wp_registered_sidebars as $index => $sidebar ) {
     28        $cols[] = '\'' . $index . '\'';
     29    }
     30    $cols = implode( ', ', $cols );
     31   
     32    $widgets = array();
     33    foreach ( $wp_registered_widgets as $name => $widget ) {
     34        $widgets[] = '\'' . $widget['id'] . '\'';
     35    }
     36    $widgets = implode( ', ', $widgets );
     37?>
     38<script type="text/javascript">
     39// <![CDATA[
     40    var cols = [<?php echo $cols; ?>];
     41    var widgets = [<?php echo $widgets; ?>];
     42    var controldims = new Array;
     43    <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
     44        controldims['<?php echo $widget['id']; ?>control'] = new Array;
     45        controldims['<?php echo $widget['id']; ?>control']['width'] = <?php echo (int) $widget['width']; ?>;
     46        controldims['<?php echo $widget['id']; ?>control']['height'] = <?php echo (int) $widget['height']; ?>;
     47    <?php endforeach; ?>
     48    function initWidgets() {
     49    <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
     50        $('<?php echo $widget['id']; ?>popper').onclick = function() {popControl('<?php echo $widget['id']; ?>control');};
     51        $('<?php echo $widget['id']; ?>closer').onclick = function() {unpopControl('<?php echo $widget['id']; ?>control');};
     52        new Draggable('<?php echo $widget['id']; ?>control', {revert:false,handle:'controlhandle',starteffect:function(){},endeffect:function(){},change:function(o){dragChange(o);}});
     53        if ( true && window.opera )
     54            $('<?php echo $widget['id']; ?>control').style.border = '1px solid #bbb';
     55    <?php endforeach; ?>
     56        if ( true && window.opera )
     57            $('shadow').style.background = 'transparent';
     58        new Effect.Opacity('shadow', {to:0.0});
     59        widgets.map(function(o) {o='widgetprefix-'+o; Position.absolutize(o); Position.relativize(o);} );
     60        $A(Draggables.drags).map(function(o) {o.startDrag(null); o.finishDrag(null);});
     61        for ( var n in Draggables.drags ) {
     62            if ( Draggables.drags[n].element.id == 'lastmodule' ) {
     63                Draggables.drags[n].destroy();
     64                break;
     65            }
     66        }
     67        resetPaletteHeight();
     68    }
     69    function resetDroppableHeights() {
     70        var max = 6;
     71        cols.map(function(o) {var c = $(o).childNodes.length; if ( c > max ) max = c;} );
     72        var height = 35 * ( max + 1);
     73        cols.map(function(o) {h = (($(o).childNodes.length + 1) * 35); $(o).style.height = (h > 280 ? h : 280) + 'px';} );
     74    }
     75    function resetPaletteHeight() {
     76        var p = $('palette'), pd = $('palettediv'), last = $('lastmodule');
     77        p.appendChild(last);
     78        if ( Draggables.activeDraggable && last.id == Draggables.activeDraggable.element.id )
     79            last = last.previousSibling;
     80        var y1 = Position.cumulativeOffset(last)[1] + last.offsetHeight;
     81        var y2 = Position.cumulativeOffset(pd)[1] + pd.offsetHeight;
     82        var dy = y1 - y2;
     83        pd.style.height = (pd.offsetHeight + dy + 9) + "px";
     84    }
     85    function maxHeight(elm) {
     86        htmlheight = document.body.parentNode.clientHeight;
     87        bodyheight = document.body.clientHeight;
     88        var height = htmlheight > bodyheight ? htmlheight : bodyheight;
     89        $(elm).style.height = height + 'px';
     90    }
     91    function dragChange(o) {
     92        el = o.element ? o.element : $(o);
     93        var p = Position.page(el);
     94        var right = p[0];
     95        var top = p[1];
     96        var left = $('shadow').offsetWidth - (el.offsetWidth + left);
     97        var bottom = $('shadow').offsetHeight - (el.offsetHeight + top);
     98        if ( right < 1 ) el.style.left = 0;
     99        if ( top < 1 ) el.style.top = 0;
     100        if ( left < 1 ) el.style.left = (left + right) + 'px';
     101        if ( bottom < 1 ) el.style.top = (top + bottom) + 'px';
     102    }
     103    function popControl(elm) {
     104        el = $(elm);
     105        el.style.width = controldims[elm]['width'] + 'px';
     106        el.style.height = controldims[elm]['height'] + 'px';
     107        var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2;
     108        var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2;
     109        el.style.position = 'absolute';
     110        el.style.right = '' + x + 'px';
     111        el.style.top = '' + y + 'px';
     112        el.style.zIndex = 1000;
     113        el.className='control';
     114        $('shadow').onclick = function() {unpopControl(elm);};
     115        window.onresize = function(){maxHeight('shadow');dragChange(elm);};
     116        popShadow();
     117    }
     118    function popShadow() {
     119        maxHeight('shadow');
     120        var shadow = $('shadow');
     121        shadow.style.zIndex = 999;
     122        shadow.style.display = 'block';
     123        new Effect.Opacity('shadow', {duration:0.5, from:0.0, to:0.2});
     124    }
     125    function unpopShadow() {
     126        new Effect.Opacity('shadow', {to:0.0});
     127        $('shadow').style.display = 'none';
     128    }
     129    function unpopControl(el) {
     130        $(el).className='hidden';
     131        unpopShadow();
     132    }
     133    function serializeAll() {
     134    <?php foreach ( $wp_registered_sidebars as $index => $sidebar ) : ?>
     135        $('<?php echo $index; ?>order').value = Sortable.serialize('<?php echo $index; ?>');
     136    <?php endforeach; ?>
     137    }
     138    function updateAll() {
     139        resetDroppableHeights();
     140        resetPaletteHeight();
     141        cols.map(function(o){
     142            var pm = $(o+'placematt');
     143            if ( $(o).childNodes.length == 0 ) {
     144                pm.style.display = 'block';
     145                Position.absolutize(o+'placematt');
     146            } else {
     147                pm.style.display = 'none';
     148            }
     149        });
     150    }
     151    function noSelection(event) {
     152        if ( document.selection ) {
     153            var range = document.selection.createRange();
     154            range.collapse(false);
     155            range.select();
     156            return false;
     157        }
     158    }
     159    addLoadEvent(updateAll);
     160    addLoadEvent(initWidgets);
     161    Event.observe(window, 'resize', resetPaletteHeight);
     162// ]]>
     163</script>
     164<?php
     165}
    28166add_action( 'admin_head', 'wp_widgets_admin_head' );
    29167do_action( 'sidebar_admin_setup' );
Note: See TracChangeset for help on using the changeset viewer.