X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/4f9d63e13cd8c6e275797c75b401b074b82937bc..80b7979fccf09a75af3f4c111fa27060ae6dbf85:/wp-admin/js/widgets.dev.js diff --git a/wp-admin/js/widgets.dev.js b/wp-admin/js/widgets.dev.js index 87a0c3c6..8e3a05dd 100644 --- a/wp-admin/js/widgets.dev.js +++ b/wp-admin/js/widgets.dev.js @@ -4,7 +4,8 @@ var wpWidgets; 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 @@ wpWidgets = { }); $('#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' ); @@ -34,14 +38,14 @@ wpWidgets = { 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 @@ wpWidgets = { 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 @@ wpWidgets = { 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 @@ wpWidgets = { 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 = { } 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 @@ wpWidgets = { }; $('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 @@ wpWidgets = { }, appendTitle : function(widget) { - var title = $('input[id*="-title"]', widget); - if ( title = title.val() ) { - title = title.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, '>'); + + $(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 @@ wpWidgets = { }); }, - close : function(widget) { + close : function(widget) { widget.children('.widget-inside').slideUp('fast', function(){ - widget.css({'width':'','marginLeft':''}); + widget.css({'width':'', margin:''}); }); } };