web/wp-admin/js/widgets.dev.js
changeset 194 32102edaa81b
parent 136 bde1974c263b
--- a/web/wp-admin/js/widgets.dev.js	Thu Sep 16 15:45:36 2010 +0000
+++ b/web/wp-admin/js/widgets.dev.js	Mon Nov 19 18:26:13 2012 +0100
@@ -4,7 +4,8 @@
 wpWidgets = {
 
 	init : function() {
-		var rem, sidebars = $('div.widgets-sortables');
+		var rem, sidebars = $('div.widgets-sortables'), isRTL = !! ( 'undefined' != typeof isRtl && isRtl ),
+			margin = ( isRtl ? 'marginRight' : 'marginLeft' ), the_id;
 
 		$('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name').click(function(){
 			var c = $(this).siblings('.widgets-sortables'), p = $(this).parent();
@@ -18,10 +19,13 @@
 		});
 
 		$('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name').click(function() {
-			$(this).siblings('.widget-holder').parent().toggleClass('closed');
+			$(this).parent().toggleClass('closed');
 		});
 
-		sidebars.not('#wp_inactive_widgets').each(function(){
+		sidebars.each(function(){
+			if ( $(this).parent().hasClass('inactive') )
+				return true;
+
 			var h = 50, H = $(this).children('.widget').length;
 			h = h + parseInt(H * 48, 10);
 			$(this).css( 'minHeight', h + 'px' );
@@ -29,19 +33,19 @@
 
 		$('a.widget-action').live('click', function(){
 			var css = {}, widget = $(this).closest('div.widget'), inside = widget.children('.widget-inside'), w = parseInt( widget.find('input.widget-width').val(), 10 );
-			
+
 			if ( inside.is(':hidden') ) {
 				if ( w > 250 && inside.closest('div.widgets-sortables').length ) {
 					css['width'] = w + 30 + 'px';
 					if ( inside.closest('div.widget-liquid-right').length )
-						css['marginLeft'] = 235 - w + 'px';
+						css[margin] = 235 - w + 'px';
 					widget.css(css);
 				}
 				wpWidgets.fixLabels(widget);
 				inside.slideDown('fast');
 			} else {
 				inside.slideUp('fast', function() {
-					widget.css({'width':'','marginLeft':''});
+					widget.css({'width':'', margin:''});
 				});
 			}
 			return false;
@@ -76,14 +80,14 @@
 			zIndex: 5,
 			containment: 'document',
 			start: function(e,ui) {
-				wpWidgets.fixWebkit(1);
 				ui.helper.find('div.widget-description').hide();
+				the_id = this.id;
 			},
 			stop: function(e,ui) {
 				if ( rem )
 					$(rem).hide();
+
 				rem = '';
-				wpWidgets.fixWebkit();
 			}
 		});
 
@@ -95,12 +99,11 @@
 			distance: 2,
 			containment: 'document',
 			start: function(e,ui) {
-				wpWidgets.fixWebkit(1);
 				ui.item.children('.widget-inside').hide();
-				ui.item.css({'marginLeft':'','width':''});
+				ui.item.css({margin:'', 'width':''});
 			},
 			stop: function(e,ui) {
-				if ( ui.item.hasClass('ui-draggable') )
+				if ( ui.item.hasClass('ui-draggable') && ui.item.data('draggable') )
 					ui.item.draggable('destroy');
 
 				if ( ui.item.hasClass('deleting') ) {
@@ -111,15 +114,16 @@
 
 				var add = ui.item.find('input.add_new').val(),
 					n = ui.item.find('input.multi_number').val(),
-					id = ui.item.attr('id'),
+					id = the_id,
 					sb = $(this).attr('id');
 
-				ui.item.css({'marginLeft':'','width':''});
-				wpWidgets.fixWebkit();
+				ui.item.css({margin:'', 'width':''});
+				the_id = '';
+
 				if ( add ) {
 					if ( 'multi' == add ) {
 						ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__|%i%/g, n); }) );
-						ui.item.attr( 'id', id.replace(/__i__|%i%/g, n) );
+						ui.item.attr( 'id', id.replace('__i__', n) );
 						n++;
 						$('div#' + id).find('input.multi_number').val(n);
 					} else if ( 'single' == add ) {
@@ -133,9 +137,15 @@
 				}
 				wpWidgets.saveOrder(sb);
 			},
-			receive: function(e,ui) {
-				if ( !$(this).is(':visible') )
-					$(this).sortable('cancel');
+			receive: function(e, ui) {
+				var sender = $(ui.sender);
+
+				if ( !$(this).is(':visible') || this.id.indexOf('orphaned_widgets') != -1 )
+					sender.sortable('cancel');
+
+				if ( sender.attr('id').indexOf('orphaned_widgets') != -1 && !sender.children('.widget').length ) {
+					sender.parents('.orphan-sidebar').slideUp(400, function(){ $(this).remove(); });
+				}
 			}
 		}).sortable('option', 'connectWith', 'div.widgets-sortables').parent().filter('.closed').children('.widgets-sortables').sortable('disable');
 
@@ -175,7 +185,8 @@
 		};
 
 		$('div.widgets-sortables').each( function() {
-			a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
+			if ( $(this).sortable )
+				a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
 		});
 
 		$.post( ajaxurl, a, function() {
@@ -237,31 +248,28 @@
 	},
 
 	appendTitle : function(widget) {
-		var title = $('input[id*="-title"]', widget);
-		if ( title = title.val() ) {
-			title = title.replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;');
-			$(widget).children('.widget-top').children('.widget-title').children()
-				.children('.in-widget-title').html(': ' + title);
-		}
+		var title = $('input[id*="-title"]', widget).val() || '';
+
+		if ( title )
+			title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+
+		$(widget).children('.widget-top').children('.widget-title').children()
+				.children('.in-widget-title').html(title);
+
 	},
 
 	resize : function() {
-		$('div.widgets-sortables').not('#wp_inactive_widgets').each(function(){
+		$('div.widgets-sortables').each(function(){
+			if ( $(this).parent().hasClass('inactive') )
+				return true;
+
 			var h = 50, H = $(this).children('.widget').length;
 			h = h + parseInt(H * 48, 10);
 			$(this).css( 'minHeight', h + 'px' );
 		});
 	},
 
-    fixWebkit : function(n) {
-        n = n ? 'none' : '';
-        $('body').css({
-			WebkitUserSelect: n,
-			KhtmlUserSelect: n
-		});
-    },
-
-    fixLabels : function(widget) {
+	fixLabels : function(widget) {
 		widget.children('.widget-inside').find('label').each(function(){
 			var f = $(this).attr('for');
 			if ( f && f == $('input', this).attr('id') )
@@ -269,9 +277,9 @@
 		});
 	},
 
-    close : function(widget) {
+	close : function(widget) {
 		widget.children('.widget-inside').slideUp('fast', function(){
-			widget.css({'width':'','marginLeft':''});
+			widget.css({'width':'', margin:''});
 		});
 	}
 };