- $widgets = array();
- foreach ( $wp_registered_widgets as $name => $widget ) {
- $widgets[] = '\'' . $widget['id'] . '\'';
- }
- $widgets = implode( ', ', $widgets );
-?>
-<script type="text/javascript">
-// <![CDATA[
- var cols = [<?php echo $cols; ?>];
- var widgets = [<?php echo $widgets; ?>];
- var controldims = new Array;
- <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
- controldims['#<?php echo $widget['id']; ?>control'] = new Array;
- controldims['#<?php echo $widget['id']; ?>control']['width'] = <?php echo (int) $widget['width']; ?>;
- controldims['#<?php echo $widget['id']; ?>control']['height'] = <?php echo (int) $widget['height']; ?>;
- <?php endforeach; ?>
- function initWidgets() {
- <?php foreach ( $wp_registered_widget_controls as $name => $widget ) : ?>
- jQuery('#<?php echo $widget['id']; ?>popper').click(function() {popControl('#<?php echo $widget['id']; ?>control');});
- jQuery('#<?php echo $widget['id']; ?>closer').click(function() {unpopControl('#<?php echo $widget['id']; ?>control');});
- jQuery('#<?php echo $widget['id']; ?>control').Draggable({handle: '.controlhandle', zIndex: 1000});
- if ( true && window.opera )
- jQuery('#<?php echo $widget['id']; ?>control').css('border','1px solid #bbb');
- <?php endforeach; ?>
- jQuery('#shadow').css('opacity','0');
- jQuery(widgets).each(function(o) {o='#widgetprefix-'+o; jQuery(o).css('position','relative');} );
- }
- function resetDroppableHeights() {
- var max = 6;
- jQuery.map(cols, function(o) {
- var c = jQuery('#' + o + ' li').length;
- if ( c > max ) max = c;
- });
- var maxheight = 35 * ( max + 1);
- jQuery.map(cols, function(o) {
- height = 0 == jQuery('#' + o + ' li').length ? maxheight - jQuery('#' + o + 'placemat').height() : maxheight;
- jQuery('#' + o).height(height);
- });
- }
- function maxHeight(elm) {
- htmlheight = document.body.parentNode.clientHeight;
- bodyheight = document.body.clientHeight;
- var height = htmlheight > bodyheight ? htmlheight : bodyheight;
- jQuery(elm).height(height);
- }
- function getViewportDims() {
- var x,y;
- if (self.innerHeight) { // all except Explorer
- x = self.innerWidth;
- y = self.innerHeight;
- } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
- x = document.documentElement.clientWidth;
- y = document.documentElement.clientHeight;
- } else if (document.body) { // other Explorers
- x = document.body.clientWidth;
- y = document.body.clientHeight;
- }
- return new Array(x,y);
- }
- function dragChange(o) {
- var p = getViewportDims();
- var screenWidth = p[0];
- var screenHeight = p[1];
- var elWidth = parseInt( jQuery(o).css('width') );
- var elHeight = parseInt( jQuery(o).css('height') );
- var elLeft = parseInt( jQuery(o).css('left') );
- var elTop = parseInt( jQuery(o).css('top') );
- if ( screenWidth < ( parseInt(elLeft) + parseInt(elWidth) ) )
- jQuery(o).css('left', ( screenWidth - elWidth ) + 'px' );
- if ( screenHeight < ( parseInt(elTop) + parseInt(elHeight) ) )
- jQuery(o).css('top', ( screenHeight - elHeight ) + 'px' );
- if ( elLeft < 1 )
- jQuery(o).css('left', '1px');
- if ( elTop < 1 )
- jQuery(o).css('top', '1px');
- }
- function popControl(elm) {
- var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2;
- var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2;
- 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' });
- jQuery(elm).attr('class','control');
- jQuery('#shadow').click(function() {unpopControl(elm);});
- window.onresize = function(){maxHeight('#shadow');dragChange(elm);};
- popShadow();
- }
- function popShadow() {
- maxHeight('#shadow');
- jQuery('#shadow').css({zIndex: '999', display: 'block'});
- jQuery('#shadow').fadeTo('fast', 0.2);
- }
- function unpopShadow() {
- jQuery('#shadow').fadeOut('fast', function() {jQuery('#shadow').hide()});
- }
- function unpopControl(el) {
- jQuery(el).attr('class','hidden');
- jQuery(el).hide();
- unpopShadow();
- }
- function serializeAll() {
- <?php $i = 0; foreach ( $wp_registered_sidebars as $index => $sidebar ) : $i++; ?>
- var serial<?php echo $i ?> = jQuery.SortSerialize('<?php echo $index ?>');
- jQuery('#<?php echo $index ?>order').attr('value',serial<?php echo $i ?>.hash.replace(/widgetprefix-/g, ''));
- <?php endforeach; ?>
- }
- function updateAll() {
- jQuery.map(cols, function(o) {
- if ( jQuery('#' + o + ' li').length )
- jQuery('#'+o+'placemat span.handle').hide();
- else
- jQuery('#'+o+'placemat span.handle').show();
- });
- resetDroppableHeights();
- }
- jQuery(document).ready( function() {
- updateAll();
- initWidgets();
- });
-// ]]>
-</script>
-<?php