1+ <?php
2+ @require ( '../wp-config.php ' );
3+ cache_javascript_headers ();
4+
5+ $ cols = array ();
6+ foreach ( $ wp_registered_sidebars as $ index => $ sidebar ) {
7+ $ cols [] = '\'' . $ index . '\'' ;
8+ }
9+ $ cols = implode ( ', ' , $ cols );
10+
11+ $ widgets = array ();
12+ foreach ( $ wp_registered_widgets as $ name => $ widget ) {
13+ $ widgets [] = '\'' . $ widget ['id ' ] . '\'' ;
14+ }
15+ $ widgets = implode ( ', ' , $ widgets );
16+ ?>
17+ var cols = [<?php echo $ cols ; ?> ];
18+ var widgets = [<?php echo $ widgets ; ?> ];
19+ var controldims = new Array;
20+ <?php foreach ( $ wp_registered_widget_controls as $ name => $ widget ) : ?>
21+ controldims['<?php echo $ widget ['id ' ]; ?> control'] = new Array;
22+ controldims['<?php echo $ widget ['id ' ]; ?> control']['width'] = <?php echo (int ) $ widget ['width ' ]; ?> ;
23+ controldims['<?php echo $ widget ['id ' ]; ?> control']['height'] = <?php echo (int ) $ widget ['height ' ]; ?> ;
24+ <?php endforeach ; ?>
25+ function initWidgets() {
26+ <?php foreach ( $ wp_registered_widget_controls as $ name => $ widget ) : ?>
27+ $('<?php echo $ widget ['id ' ]; ?> popper').onclick = function() {popControl('<?php echo $ widget ['id ' ]; ?> control');};
28+ $('<?php echo $ widget ['id ' ]; ?> closer').onclick = function() {unpopControl('<?php echo $ widget ['id ' ]; ?> control');};
29+ new Draggable('<?php echo $ widget ['id ' ]; ?> control', {revert:false,handle:'controlhandle',starteffect:function(){},endeffect:function(){},change:function(o){dragChange(o);}});
30+ if ( true && window.opera )
31+ $('<?php echo $ widget ['id ' ]; ?> control').style.border = '1px solid #bbb';
32+ <?php endforeach ; ?>
33+ if ( true && window.opera )
34+ $('shadow').style.background = 'transparent';
35+ new Effect.Opacity('shadow', {to:0.0});
36+ widgets.map(function(o) {o='widgetprefix-'+o; Position.absolutize(o); Position.relativize(o);} );
37+ $A(Draggables.drags).map(function(o) {o.startDrag(null); o.finishDrag(null);});
38+ for ( var n in Draggables.drags ) {
39+ if ( Draggables.drags[n].element.id == 'lastmodule' ) {
40+ Draggables.drags[n].destroy();
41+ break;
42+ }
43+ }
44+ resetPaletteHeight();
45+ }
46+ function resetDroppableHeights() {
47+ var max = 6;
48+ cols.map(function(o) {var c = $(o).childNodes.length; if ( c > max ) max = c;} );
49+ var height = 35 * ( max + 1);
50+ cols.map(function(o) {h = (($(o).childNodes.length + 1) * 35); $(o).style.height = (h > 280 ? h : 280) + 'px';} );
51+ }
52+ function resetPaletteHeight() {
53+ var p = $('palette'), pd = $('palettediv'), last = $('lastmodule');
54+ p.appendChild(last);
55+ if ( Draggables.activeDraggable && last.id == Draggables.activeDraggable.element.id )
56+ last = last.previousSibling;
57+ var y1 = Position.cumulativeOffset(last)[1] + last.offsetHeight;
58+ var y2 = Position.cumulativeOffset(pd)[1] + pd.offsetHeight;
59+ var dy = y1 - y2;
60+ pd.style.height = (pd.offsetHeight + dy + 9) + "px";
61+ }
62+ function maxHeight(elm) {
63+ htmlheight = document.body.parentNode.clientHeight;
64+ bodyheight = document.body.clientHeight;
65+ var height = htmlheight > bodyheight ? htmlheight : bodyheight;
66+ $(elm).style.height = height + 'px';
67+ }
68+ function dragChange(o) {
69+ el = o.element ? o.element : $(o);
70+ var p = Position.page(el);
71+ var right = p[0];
72+ var top = p[1];
73+ var left = $('shadow').offsetWidth - (el.offsetWidth + left);
74+ var bottom = $('shadow').offsetHeight - (el.offsetHeight + top);
75+ if ( right < 1 ) el.style.left = 0;
76+ if ( top < 1 ) el.style.top = 0;
77+ if ( left < 1 ) el.style.left = (left + right) + 'px';
78+ if ( bottom < 1 ) el.style.top = (top + bottom) + 'px';
79+ }
80+ function popControl(elm) {
81+ el = $(elm);
82+ el.style.width = controldims[elm]['width'] + 'px';
83+ el.style.height = controldims[elm]['height'] + 'px';
84+ var x = ( document.body.clientWidth - controldims[elm]['width'] ) / 2;
85+ var y = ( document.body.parentNode.clientHeight - controldims[elm]['height'] ) / 2;
86+ el.style.position = 'absolute';
87+ el.style.right = '' + x + 'px';
88+ el.style.top = '' + y + 'px';
89+ el.style.zIndex = 1000;
90+ el.className='control';
91+ $('shadow').onclick = function() {unpopControl(elm);};
92+ window.onresize = function(){maxHeight('shadow');dragChange(elm);};
93+ popShadow();
94+ }
95+ function popShadow() {
96+ maxHeight('shadow');
97+ var shadow = $('shadow');
98+ shadow.style.zIndex = 999;
99+ shadow.style.display = 'block';
100+ new Effect.Opacity('shadow', {duration:0.5, from:0.0, to:0.2});
101+ }
102+ function unpopShadow() {
103+ new Effect.Opacity('shadow', {to:0.0});
104+ $('shadow').style.display = 'none';
105+ }
106+ function unpopControl(el) {
107+ $(el).className='hidden';
108+ unpopShadow();
109+ }
110+ function serializeAll() {
111+ <?php foreach ( $ wp_registered_sidebars as $ index => $ sidebar ) : ?>
112+ $('<?php echo $ index ; ?> order').value = Sortable.serialize('<?php echo $ index ; ?> ');
113+ <?php endforeach ; ?>
114+ }
115+ function updateAll() {
116+ resetDroppableHeights();
117+ resetPaletteHeight();
118+ cols.map(function(o){
119+ var pm = $(o+'placematt');
120+ if ( $(o).childNodes.length == 0 ) {
121+ pm.style.display = 'block';
122+ Position.absolutize(o+'placematt');
123+ } else {
124+ pm.style.display = 'none';
125+ }
126+ });
127+ }
128+ function noSelection(event) {
129+ if ( document.selection ) {
130+ var range = document.selection.createRange();
131+ range.collapse(false);
132+ range.select();
133+ return false;
134+ }
135+ }
136+ addLoadEvent(updateAll);
137+ addLoadEvent(initWidgets);
138+ Event.observe(window, 'resize', resetPaletteHeight);
0 commit comments