Changeset 1069 for trunk/wp-admin/widgets.php
- Timestamp:
- 10/12/07 16:21:15 (9 months ago)
- Files:
-
- trunk/wp-admin/widgets.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/widgets.php
r1005 r1069 6 6 wp_die( __( 'Cheatin’ uh?' )); 7 7 8 wp_enqueue_script( 'scriptaculous-effects' ); 9 wp_enqueue_script( 'scriptaculous-dragdrop' ); 8 wp_enqueue_script('interface'); 10 9 11 10 function wp_widgets_admin_head() { 12 11 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' ); ?> 18 14 <!--[if IE 7]> 19 15 <style type="text/css"> 20 #palette {float:left;}16 #palette { float: <?php echo ( get_bloginfo( 'text_direction' ) == 'rtl' ) ? 'right' : 'left'; ?>; } 21 17 </style> 22 18 <![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 34 21 $cols = array(); 35 22 foreach ( $wp_registered_sidebars as $index => $sidebar ) { … … 37 24 } 38 25 $cols = implode( ', ', $cols ); 39 26 40 27 $widgets = array(); 41 28 foreach ( $wp_registered_widgets as $name => $widget ) { … … 50 37 var controldims = new Array; 51 38 <?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']; ?>; 55 42 <?php endforeach; ?> 56 43 function initWidgets() { 57 44 <?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}); 61 48 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'); 63 50 <?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');} ); 79 53 } 80 54 function resetDroppableHeights() { 81 55 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 }); 95 65 } 96 66 function maxHeight(elm) { … … 98 68 bodyheight = document.body.clientHeight; 99 69 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); 101 85 } 102 86 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'); 113 102 } 114 103 function popControl(elm) { 115 el = $(elm);116 el.style.width = controldims[elm]['width'] + 'px';117 el.style.height = controldims[elm]['height'] + 'px';118 104 var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2; 119 105 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);}; 127 110 popShadow(); 128 111 } 129 112 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); 135 116 } 136 117 function unpopShadow() { 137 new Effect.Opacity('shadow', {to:0.0}); 138 $('shadow').style.display = 'none'; 118 jQuery('#shadow').fadeOut('fast', function() {jQuery('#shadow').hide()}); 139 119 } 140 120 function unpopControl(el) { 141 $(el).className='hidden'; 121 jQuery(el).attr('class','hidden'); 122 jQuery(el).hide(); 142 123 unpopShadow(); 143 124 } 144 125 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, '')); 147 129 <?php endforeach; ?> 148 130 } 149 131 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 }); 150 138 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 }); 173 144 // ]]> 174 145 </script> … … 180 151 function wp_widget_draggable( $name ) { 181 152 global $wp_registered_widgets, $wp_registered_widget_controls; 182 153 183 154 if ( !isset( $wp_registered_widgets[$name] ) ) { 184 155 return; 185 156 } 186 157 187 158 $sanitized_name = sanitize_title( $wp_registered_widgets[$name]['id'] ); 188 159 $link_title = __( 'Configure' ); 189 $popper = ( isset( $wp_registered_widget_controls[$name] ) ) 160 $popper = ( isset( $wp_registered_widget_controls[$name] ) ) 190 161 ? ' <div class="popper" id="' . $sanitized_name . 'popper" title="' . $link_title . '">≡</div>' 191 162 : ''; 192 163 193 164 $output = '<li class="module" id="widgetprefix-%1$s"><span class="handle">%2$s</span></li>'; 194 165 195 166 printf( $output, $sanitized_name, $wp_registered_widgets[$name]['name'] . $popper ); 196 167 } … … 205 176 <div class="wrap"> 206 177 <h2><?php _e( 'No Sidebars Defined' ); ?></h2> 207 178 208 179 <p><?php _e( 'You are seeing this message because the theme you are currently using isn’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> 209 180 </div> 210 181 <?php 211 182 212 183 require_once 'admin-footer.php'; 213 184 exit; … … 222 193 if ( isset( $_POST['action'] ) ) { 223 194 check_admin_referer( 'widgets-save-widget-order' ); 224 195 225 196 switch ( $_POST['action'] ) { 226 197 case 'default' : … … 228 199 wp_set_sidebars_widgets( $sidebars_widgets ); 229 200 break; 230 201 231 202 case 'save_widget_order' : 232 203 $sidebars_widgets = array(); 233 204 234 205 foreach ( $wp_registered_sidebars as $index => $sidebar ) { 235 206 $postindex = $index . 'order'; 236 207 237 208 parse_str( $_POST[$postindex], $order ); 238 209 239 210 $new_order = $order[$index]; 240 211 241 212 if ( is_array( $new_order ) ) { 242 213 foreach ( $new_order as $sanitized_name ) { … … 249 220 } 250 221 } 251 222 252 223 wp_set_sidebars_widgets( $sidebars_widgets ); 253 224 break; … … 261 232 foreach ( $wp_registered_widgets as $name => $widget ) { 262 233 $is_active = false; 263 234 264 235 foreach ( $wp_registered_sidebars as $index => $sidebar ) { 265 236 if ( is_array( $sidebars_widgets[$index] ) && in_array( $name, $sidebars_widgets[$index] ) ) { … … 268 239 } 269 240 } 270 241 271 242 if ( !$is_active ) { 272 243 $inactive_widgets[] = $name; … … 298 269 <div class="wrap"> 299 270 <h2><?php _e( 'Sidebar Arrangement' ); ?></h2> 300 271 301 272 <p><?php _e( 'You can drag and drop widgets onto your sidebar below.' ); ?></p> 302 273 303 274 <form id="sbadmin" method="post" onsubmit="serializeAll();"> 304 275 <p class="submit"> … … 310 281 ?> 311 282 <input type="hidden" id="<?php echo $index; ?>order" name="<?php echo $index; ?>order" value="" /> 312 283 313 284 <div class="dropzone"> 314 285 <h3><?php echo $sidebar['name']; ?></h3> 315 316 <div id="<?php echo $index; ?>placemat t" class="moduleplacemat">286 287 <div id="<?php echo $index; ?>placemat" class="placemat"> 317 288 <span class="handle"> 318 289 <h4><?php _e( 'Default Sidebar' ); ?></h4> … … 320 291 </span> 321 292 </div> 322 293 323 294 <ul id="<?php echo $index; ?>"> 324 295 <?php … … 334 305 } 335 306 ?> 336 337 <br class="clear" /> 338 307 339 308 </div> 340 309 341 310 <div id="palettediv"> 342 311 <h3><?php _e( 'Available Widgets' ); ?></h3> 343 312 344 313 <ul id="palette"> 345 314 <?php … … 348 317 } 349 318 ?> 350 <li id="lastmodule"><span></span></li>351 319 </ul> 352 320 </div> 353 321 354 322 <script type="text/javascript"> 355 323 // <![CDATA[ 324 jQuery(document).ready(function(){ 356 325 <?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 } ?> 361 330 }); 362 <?php } ?>363 331 // ]]> 364 332 </script> 365 333 366 334 <p class="submit"> 367 335 <?php wp_nonce_field( 'widgets-save-widget-order' ); ?> … … 369 337 <input type="submit" value="<?php _e( 'Save Changes »' ); ?>" /> 370 338 </p> 371 339 372 340 <div id="controls"> 373 341 <?php foreach ( $wp_registered_widget_controls as $name => $widget ) { ?> … … 382 350 </div> 383 351 </form> 384 352 385 353 <br class="clear" /> 386 354 </div> 387 355 388 356 <div id="shadow"> </div> 389 357 390 358 <?php do_action( 'sidebar_admin_page' ); ?> 391 359
