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();
});
$('#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' );
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;
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();
}
});
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') ) {
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 ) {
}
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');
};
$('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() {
},
appendTitle : function(widget) {
- var title = $('input[id*="-title"]', widget);
- if ( title = title.val() ) {
- title = title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
- $(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, '<').replace(/>/g, '>');
+
+ $(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') )
});
},
- close : function(widget) {
+ close : function(widget) {
widget.children('.widget-inside').slideUp('fast', function(){
- widget.css({'width':'','marginLeft':''});
+ widget.css({'width':'', margin:''});
});
}
};