Make WordPress Core

Ticket #10021: widgets.diff

File widgets.diff, 28.6 KB (added by Denis-de-Bernardy, 16 years ago)
  • wp-includes/default-widgets.php

     
    873873
    874874        if ( !empty($error) )
    875875                echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
    876 
     876       
     877        global $wp_widget_control_number;
     878        if ( !empty($wp_widget_control_number) ) {
     879                $widget_title_id = 'widget-' . $wp_widget_control_number . '_rss-' . $number . '-title';
     880        } else {
     881                $widget_title_id = 'rss-title-' . $number;
     882        }
     883       
    877884        if ( $inputs['url'] ) :
    878885?>
    879886        <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
    880887        <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
    881888<?php endif; if ( $inputs['title'] ) : ?>
    882         <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
    883         <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
     889        <p><label for="<?php echo $widget_title_id; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
     890        <input class="widefat" id="<?php echo $widget_title_id; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
    884891<?php endif; if ( $inputs['items'] ) : ?>
    885892        <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
    886893        <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
  • wp-includes/widgets.php

     
    119119         * @return string ID attribute for $field_name
    120120         */
    121121        function get_field_id($field_name) {
    122                 return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
     122                global $wp_widget_control_number;
     123                if ( !empty($wp_widget_control_number) ) {
     124                        return 'widget-' . $wp_widget_control_number . '_' . $this->id_base . '-' . $this->number . '-' . $field_name;
     125                } else {
     126                        return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
     127                }
    123128        }
    124129
    125130        // Private Functions. Don't worry about these.
  • wp-admin/includes/widgets.php

     
    7676 */
    7777function wp_list_widget_controls_dynamic_sidebar( $params ) {
    7878        global $wp_registered_widgets;
    79         static $i = 0;
    80         $i++;
     79        global $wp_widget_control_number;
     80        if ( empty($wp_widget_control_number) )
     81                $wp_widget_control_number = 0;
     82        $wp_widget_control_number++;
    8183
    8284        $widget_id = $params[0]['widget_id'];
    8385        $id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id;
    8486        $hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : '';
    8587
    86         $params[0]['before_widget'] = "<div id='widget-${i}_$id' class='widget'$hidden>";
     88        $params[0]['before_widget'] = "<div id='widget-${wp_widget_control_number}_$id' class='widget'$hidden>";
    8789        $params[0]['after_widget'] = "</div>";
    8890        $params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
    8991        $params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
  • wp-admin/js/common.dev.js

     
    22(function($){
    33// sidebar admin menu
    44adminMenu = {
    5 
    65        init : function() {
    7                 $('#adminmenu div.wp-menu-toggle').each( function() {
    8                         if ( $(this).siblings('.wp-submenu').length )
    9                                 $(this).click(function(){ adminMenu.toggle( $(this).siblings('.wp-submenu') ); });
     6                $('.wp-menu-toggle', '#adminmenu')
     7                .each( function() {
     8                        var t = $(this);
     9                        if ( t.siblings('.wp-submenu').length )
     10                                t.click(function(){ adminMenu.toggle( $(this).siblings('.wp-submenu') ); });
    1011                        else
    11                                 $(this).hide();
     12                                t.hide();
    1213                });
    13 
     14                //$.log('wp-menu-toggle');
     15               
    1416                this.favorites();
    15 
    16                 $('a.separator').click(function(){
     17                //$.log('favorites');
     18               
     19                $('.separator', '#adminmenu')
     20                .click(function(){
    1721                        if ( $('body').hasClass('folded') ) {
    1822                                adminMenu.fold(1);
    1923                                deleteUserSetting( 'mfold' );
     
    2327                        }
    2428                        return false;
    2529                });
    26 
     30                //$.log('admin menu - separator');
     31               
    2732                if ( $('body').hasClass('folded') ) {
    2833                        this.fold();
    2934                }
     35                //$.log('admin menu - fold');
     36               
    3037                this.restoreMenuState();
     38                //$.log('admin menu - restore state');
    3139        },
    3240
    3341        restoreMenuState : function() {
    34                 $('#adminmenu li.wp-has-submenu').each(function(i, e) {
     42                $('.wp-has-submenu', '#adminmenu')
     43                .each(function(i, e) {
    3544                        var v = getUserSetting( 'm'+i );
    36                         if ( $(e).hasClass('wp-has-current-submenu') ) return true; // leave the current parent open
     45                        if ( $(e).hasClass('wp-has-current-submenu') )
     46                                return true; // leave the current parent open
    3747
    38                         if ( 'o' == v ) $(e).addClass('wp-menu-open');
    39                         else if ( 'c' == v ) $(e).removeClass('wp-menu-open');
     48                        if ( 'o' == v )
     49                                $(e).addClass('wp-menu-open');
     50                        else if ( 'c' == v )
     51                                $(e).removeClass('wp-menu-open');
    4052                });
    4153        },
    4254
    4355        toggle : function(el) {
     56                el['slideToggle'](150, function() {
     57                        el.css('display','');
     58                }).parent().toggleClass( 'wp-menu-open' );
    4459
    45                 el['slideToggle'](150, function(){el.css('display','');}).parent().toggleClass( 'wp-menu-open' );
    46 
    47                 $('#adminmenu li.wp-has-submenu').each(function(i, e) {
     60                $('.wp-has-submenu', '#adminmenu')
     61                .each(function(i, e) {
    4862                        var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
    4963                        setUserSetting( 'm'+i, v );
    5064                });
     
    5569        fold : function(off) {
    5670                if (off) {
    5771                        $('body').removeClass('folded');
    58                         $('#adminmenu li.wp-has-submenu').unbind();
     72                        $('li.wp-has-submenu', '#adminmenu').unbind();
    5973                } else {
    6074                        $('body').addClass('folded');
    61                         $('#adminmenu li.wp-has-submenu').hoverIntent({
    62                                 over: function(e){
     75                        $('li.wp-has-submenu', '#adminmenu')
     76                        .hoverIntent({
     77                                over: function(e) {
    6378                                        var m, b, h, o, f;
    64                                         m = $(this).find('.wp-submenu');
     79                                        m = $('.wp-submenu', this);
    6580                                        b = m.parent().offset().top + m.height() + 1; // Bottom offset of the menu
    6681                                        h = $('#wpwrap').height(); // Height of the entire page
    6782                                        o = 60 + b - h;
     
    7691                                        }
    7792                                        m.addClass('sub-open');
    7893                                },
    79                                 out: function(){ $(this).find('.wp-submenu').removeClass('sub-open').css({'marginTop':''}); },
     94                                out: function() {
     95                                        $('.wp-submenu', this).removeClass('sub-open').css({'marginTop':''});
     96                                },
    8097                                timeout: 220,
    8198                                sensitivity: 8,
    8299                                interval: 100
    83100                        });
    84 
    85101                }
    86102        },
    87103
    88104        favorites : function() {
    89                 $('#favorite-inside').width($('#favorite-actions').width()-4);
    90                 $('#favorite-toggle, #favorite-inside').bind( 'mouseenter', function(){$('#favorite-inside').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideDown') ) { $('#favorite-inside').slideDown(100); $('#favorite-first').addClass('slide-down'); }}, 200) } );
    91 
    92                 $('#favorite-toggle, #favorite-inside').bind( 'mouseleave', function(){$('#favorite-inside').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideUp') ) { $('#favorite-inside').slideUp(100, function(){ $('#favorite-first').removeClass('slide-down'); } ); }}, 300) } );
     105                $('#favorite-inside').width($('#favorite-actions').width() - 4);
     106               
     107                $('#favorite-toggle, #favorite-inside')
     108                .bind('mouseenter', function() {
     109                        $('#favorite-inside').removeClass('slideUp').addClass('slideDown');
     110                        setTimeout(function() {
     111                                if ( $('#favorite-inside').hasClass('slideDown') ) {
     112                                        $('#favorite-inside').slideDown(100);
     113                                        $('#favorite-first').addClass('slide-down');
     114                                }
     115                        }, 200);
     116                }).bind('mouseleave', function() {
     117                        $('#favorite-inside').removeClass('slideDown').addClass('slideUp');
     118                        setTimeout(function() {
     119                                if ( $('#favorite-inside').hasClass('slideUp') ) {
     120                                        $('#favorite-inside').slideUp(100, function() {
     121                                                $('#favorite-first').removeClass('slide-down');
     122                                        });
     123                                }
     124                        }, 300);
     125                });
    93126        }
    94127};
    95128
    96 $(document).ready(function(){adminMenu.init();});
     129$(document).ready(function(){
     130        //$.log('common.js - start');
     131        adminMenu.init();
     132});
    97133
    98134// show/hide/save table columns
    99135columns = {
    100136        init : function() {
    101                 $('.hide-column-tog').click( function() {
     137                $('.hide-column-tog', '#adv-settings')
     138                .click( function() {
    102139                        var column = $(this).val(), show = $(this).attr('checked');
    103140                        if ( show ) {
    104141                                $('.column-' + column).show();
     
    106143                                $('.column-' + column).hide();
    107144                        }
    108145                        columns.save_manage_columns_state();
    109                 } );
     146                });
     147                //$.log('table columns init');
    110148        },
    111149
    112150        save_manage_columns_state : function() {
    113                 var hidden = $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
     151                var hidden = $('.manage-column').filter(':hidden')
     152                .map(function() { return this.id; })
     153                .get().join(',');
    114154                $.post(ajaxurl, {
    115155                        action: 'hidden-columns',
    116156                        hidden: hidden,
     
    120160        }
    121161}
    122162
    123 $(document).ready(function(){columns.init();});
    124 
     163$(document).ready(function(){
     164        columns.init();
     165});
    125166})(jQuery);
    126167
    127168// stub for doing better warnings
     
    144185        var lastClicked = false, checks, first, last, checked;
    145186
    146187        // pulse
    147         $('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300);
     188        $('div.fade').animate( { backgroundColor: '#ffffe0' }, 300)
     189        .animate( { backgroundColor: '#fffbcc' }, 300)
     190        .animate( { backgroundColor: '#ffffe0' }, 300)
     191        .animate( { backgroundColor: '#fffbcc' }, 300);
     192        //$.log('fade');
    148193
    149194        // Move .updated and .error alert boxes
    150         $('div.wrap h2 ~ div.updated, div.wrap h2 ~ div.error').addClass('below-h2');
    151         $('div.updated, div.error').not('.below-h2').insertAfter('div.wrap h2:first');
     195        $('div.wrap').children('h2:first').nextAll('div.updated, div.error')
     196        .addClass('below-h2');
     197        //$.log('lock div.updated, div.error')
    152198
     199        $('div.updated, div.error').not('.below-h2')
     200        .insertAfter($('div.wrap').children('h2:first'));
     201        //$.log('move div.updated, div.error');
     202
    153203        // show warnings
    154         $('#doaction, #doaction2').click(function(){
     204        $('#doaction, #doaction2').click(function () {
    155205                if ( $('select[name="action"]').val() == 'delete' || $('select[name="action2"]').val() == 'delete' ) {
    156206                        return showNotice.warn();
    157207                }
    158208        });
     209        //$.log('doaction')
    159210
    160211        // screen settings tab
    161         $('#show-settings-link').click(function () {
     212        $('#show-settings-link')
     213        .click(function () {
    162214                if ( ! $('#screen-options-wrap').hasClass('screen-options-open') ) {
    163215                        $('#contextual-help-link-wrap').css('visibility', 'hidden');
    164216                }
    165                 $('#screen-options-wrap').slideToggle('fast', function(){
     217               
     218                $('#screen-options-wrap')
     219                .slideToggle('fast', function(){
    166220                        if ( $(this).hasClass('screen-options-open') ) {
    167                                 $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
     221                                $('#show-settings-link')
     222                                .css({'backgroundImage':'url("images/screen-options-right.gif")'});
     223                               
    168224                                $('#contextual-help-link-wrap').css('visibility', '');
    169225                                $(this).removeClass('screen-options-open');
    170226                        } else {
    171                                 $('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
     227                                $('#show-settings-link')
     228                                .css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
     229                               
    172230                                $(this).addClass('screen-options-open');
    173231                        }
    174232                });
    175233                return false;
    176234        });
    177 
     235        //$.log('show-settings-link')
     236       
    178237        // help tab
    179         $('#contextual-help-link').click(function () {
     238        $('#contextual-help-link')
     239        .click(function () {
    180240                if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') ) {
    181241                        $('#screen-options-link-wrap').css('visibility', 'hidden');
    182242                }
    183                 $('#contextual-help-wrap').slideToggle('fast', function(){
     243               
     244                $('#contextual-help-wrap')
     245                .slideToggle('fast', function() {
    184246                        if ( $(this).hasClass('contextual-help-open') ) {
    185                                 $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
     247                                $('#contextual-help-link')
     248                                .css({'backgroundImage':'url("images/screen-options-right.gif")'});
     249                               
    186250                                $('#screen-options-link-wrap').css('visibility', '');
    187251                                $(this).removeClass('contextual-help-open');
    188252                        } else {
    189                                 $('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
     253                                $('#contextual-help-link')
     254                                .css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
     255                               
    190256                                $(this).addClass('contextual-help-open');
    191257                        }
    192258                });
    193259                return false;
    194260        });
    195         $('#contextual-help-link-wrap, #screen-options-link-wrap').show();
     261        //$.log('contextual-help-link');
     262       
     263        // this one is already taken care of by the hide-if-no-js class
     264        // show() and :hidden are extremely slow on slow rendering engines
     265        // e.g. Opera 9 with a 400kb widgets page gets:
     266        // 6ms -- $('#contextual-help-link-wrap')
     267        // 6071ms -- $('#contextual-help-link-wrap:hidden')
     268        // $('#contextual-help-link-wrap, #screen-options-link-wrap').show();
    196269
    197270        // check all checkboxes
    198         $( 'table:visible tbody .check-column :checkbox' ).click( function(e) {
     271        $('tbody').children().children('.check-column').find(':checkbox')
     272        .click( function(e) {
    199273                if ( 'undefined' == e.shiftKey ) { return true; }
    200274                if ( e.shiftKey ) {
    201275                        if ( !lastClicked ) { return true; }
    202                         checks = $( lastClicked ).parents( 'form:first' ).find( ':checkbox' );
     276                        checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
    203277                        first = checks.index( lastClicked );
    204278                        last = checks.index( this );
    205279                        checked = $(this).attr('checked');
    206280                        if ( 0 < first && 0 < last && first != last ) {
    207281                                checks.slice( first, last ).attr( 'checked', function(){
    208                                         if ( $(this).parents('tr').is(':visible') )
     282                                        if ( $(this).closest('tr').is(':visible') )
    209283                                                return checked ? 'checked' : '';
    210284
    211285                                        return '';
     
    214288                }
    215289                lastClicked = this;
    216290                return true;
    217         } );
    218         $( 'thead :checkbox, tfoot :checkbox' ).click( function(e) {
    219                 var c = $(this).attr('checked'), kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard, toggle = e.shiftKey || kbtoggle;
    220 
    221 
    222                 $(this).parents( 'form:first' ).find( 'table tbody:visible' ).find( '.check-column :checkbox' ).attr( 'checked', function() {
    223                         if ( $(this).parents('tr').is(':hidden') )
     291        });
     292        //$.log('tbody checkboxes');
     293       
     294        $('thead, tfoot').find(':checkbox').click( function(e) {
     295                var c = $(this).attr('checked'),
     296                        kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
     297                        toggle = e.shiftKey || kbtoggle;
     298               
     299                $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
     300                .children().children('.check-column').find(':checkbox')
     301                .attr('checked', function() {
     302                        if ( $(this).closest('tr').is(':hidden') )
    224303                                return '';
    225304                        if ( toggle )
    226305                                return $(this).attr( 'checked' ) ? '' : 'checked';
     
    228307                                return 'checked';
    229308                        return '';
    230309                });
    231                 $(this).parents( 'form:first' ).find( 'table thead:visible, table tfoot:visible').find( '.check-column :checkbox' ).attr( 'checked', function() {
     310               
     311                $(this).closest('table').children('thead,  tfoot').filter(':visible')
     312                .children().children('.check-column').find(':checkbox')
     313                .attr('checked', function() {
    232314                        if ( toggle )
    233315                                return '';
    234316                        else if (c)
     
    236318                        return '';
    237319                });
    238320        });
     321        //$.log('thead, tfoot checkboxes');
     322       
    239323        $('#default-password-nag-no').click( function() {
    240324                setUserSetting('default_password_nag', 'hide');
    241325                $('div.default-password-nag').hide();
    242326                return false;
    243327        });
    244        
    245        
     328        //$.log('password nag');
    246329});
    247330
    248331jQuery(document).ready( function($){
    249         var turboNag = $('.turbo-nag');
     332        var turboNag = $('span.turbo-nag');
    250333
    251334        if ( !turboNag.length || ('undefined' != typeof(google) && google.gears) )
    252335                return;
     
    263346        }
    264347
    265348        turboNag.show();
    266 
    267 });
     349        //$.log('turbo');
     350        //$.log('common.js - stop');
     351});
     352 No newline at end of file
  • wp-admin/js/utils.dev.js

     
    163163                return {};
    164164
    165165        return wpCookies.getHash('wp-settings-' + userSettings.uid) || {};
    166 }
     166}
     167 No newline at end of file
  • wp-admin/js/widgets.dev.js

     
    1 
    21var wpWidgets;
    32(function($) {
    43
    54wpWidgets = {
     5        sortables : null,
     6       
    67        init : function() {
    7         var rem;
    8 
     8                var rem;
     9                //wpWidgets.sortables = $('div.widgets-sortables');
     10               
    911                if ( $('body').hasClass('widgets_access') ) {
    1012                        return;
    1113                }
    12 
    13                 $('#widgets-right div.sidebar-name').click(function(){
    14             var c = $(this).siblings('.widgets-sortables');
    15                         if ( c.is(':visible') ) {
     14                //$.log('check widgets_access');
     15               
     16                var availableWidgets = $('#widget-list').children('.widget');
     17                //$.log('availble widgets - find');
     18               
     19                var droppableSidebar = $('#available-widgets');
     20                //$.log('droppable sidebar - find');
     21               
     22                var sortableSidebars = $('div.widgets-sortables');
     23                //$.log('sortable sidebars - find');
     24               
     25                $('#widgets-right').children('.widgets-holder-wrap').children('.sidebar-name')
     26                //.log('find widgets-right sidebar name')
     27                .click(function(){
     28                        var c = $(this).siblings('.widgets-sortables'), p = $(this).parent();
     29                        if ( !p.hasClass('closed') ) {
    1630                                c.sortable('disable');
    17                                 $(this).parent().addClass('closed');
     31                                p.addClass('closed');
    1832                        } else {
    19                                 $(this).parent().removeClass('closed');
     33                                p.removeClass('closed');
    2034                                c.sortable('enable').sortable('refresh');
    2135                        }
    22         });
    23 
    24         $('#widgets-left div.sidebar-name').click(function(){
    25                         if ( $(this).siblings('.widget-holder').is(':visible') ) {
    26                                 $(this).parent().addClass('closed');
    27                         } else {
    28                                 $(this).parent().removeClass('closed');
    29                         }
    30         });
    31 
    32                 $('#widgets-right .widget, #wp_inactive_widgets .widget').each(function(){
     36                });
     37                //$.log('widgets-right sidebar name');
     38               
     39                $('#widgets-left').children('.widgets-holder-wrap').children('.sidebar-name')
     40                //.log('find widgets-left sidebar name')
     41                .click(function() {
     42                        $(this).siblings('.widget-holder').parent().toggleClass('closed');
     43                });
     44                //$.log('widgets-left sidebar name');
     45               
     46                sortableSidebars.not('#wp_inactive_widgets')
     47                .each(function(){
     48                        var h = 50, H = $(this).children('.widget').length;
     49                        h = h + parseInt(H * 48, 10);
     50                        $(this).css( 'minHeight', h + 'px' );
     51                });
     52                //$.log('sidebars - resize');
     53               
     54                sortableSidebars.children('.widget')
     55                //.log('widgets - find active widgets')
     56                .each(function() {
     57                        wpWidgets.addEvents(this);
     58                })
     59                //.log('widgets - attach events')
     60                .each(function() {
    3361                        wpWidgets.appendTitle(this);
    3462                });
    35 
    36                 this.addEvents();
    37         $('.widget-error').parents('.widget').find('a.widget-action').click();
    38 
    39                 $('#available-widgets').droppable({
    40                         tolerance: 'pointer',
    41                         accept: function(o){
    42                                 return $(o).parent().attr('id') != 'widget-list';
    43                         },
    44                         drop: function(e,ui) {
    45                                 ui.draggable.addClass('deleting');
    46                                 $('#removing-widget').hide().children('span').html('');
    47                         },
    48                         over: function(e,ui) {
    49                                 ui.draggable.addClass('deleting');
    50                                 $('.widget-placeholder').hide();
    51 
    52                                 if ( ui.draggable.hasClass('ui-sortable-helper') )
    53                                         $('#removing-widget').show().children('span').html( ui.draggable.find('.widget-title h4').html() );
    54                         },
    55                         out: function(e,ui) {
    56                                 ui.draggable.removeClass('deleting');
    57                                 $('.widget-placeholder').show();
    58                                 $('#removing-widget').hide().children('span').html('');
    59                         }
    60                 });
    61 
    62                 $('#widget-list .widget').draggable({
    63                         connectToSortable: '.widgets-sortables',
    64                         handle: '.widget-title',
     63                //$.log('widgets - set title');
     64               
     65                availableWidgets.draggable({
     66                        connectToSortable: 'div.widgets-sortables',
     67                        handle: '> .widget-top > .widget-title',
    6568                        distance: 2,
    6669                        helper: 'clone',
    6770                        zIndex: 5,
    6871                        containment: 'document',
    6972                        start: function(e,ui) {
    7073                                wpWidgets.fixWebkit(1);
    71                                 ui.helper.find('.widget-description').hide();
     74                                ui.helper.find('div.widget-description').hide();
    7275                        },
    7376                        stop: function(e,ui) {
    7477                                if ( rem )
     
    7780                                wpWidgets.fixWebkit();
    7881                        }
    7982                });
    80 
    81         $('.widgets-sortables').sortable({
     83                //$.log('available widgets - make draggable');
     84                               
     85                sortableSidebars.sortable({
    8286                        placeholder: 'widget-placeholder',
    83                         connectWith: '.widgets-sortables',
    84                         items: '.widget',
    85                         handle: '.widget-title',
     87                        items: '> .widget',
     88                        handle: '> .widget-top > .widget-title',
    8689                        cursor: 'move',
    8790                        distance: 2,
    8891                        containment: 'document',
    8992                        start: function(e,ui) {
    9093                                wpWidgets.fixWebkit(1);
    91                                 ui.item.find('.widget-inside').hide();
     94                                ui.item.children('.widget-inside').hide();
    9295                                ui.item.css({'marginLeft':'','width':''});
    9396                        },
    9497                        stop: function(e,ui) {
     
    101104                                        return;
    102105                                }
    103106
    104                                 var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).attr('id');
     107                                var add = ui.item.find('input.add_new').val(),
     108                                        n = ui.item.find('input.multi_number').val(),
     109                                        id = ui.item.attr('id'),
     110                                        sb = $(this).attr('id');
    105111
    106112                                ui.item.css({'marginLeft':'','width':''});
    107113                                wpWidgets.fixWebkit();
     
    127133                                if ( !$(this).is(':visible') )
    128134                                        $(this).sortable('cancel');
    129135                        }
    130                 }).not(':visible').sortable('disable');
    131                 wpWidgets.resize();
    132                 wpWidgets.fixLabels();
     136                })
     137                //.log('sortable sidebars - enable sortables')
     138                .sortable('option', 'connectWith', 'div.widgets-sortables')
     139                //.log('sortable sidebars - set connectWith')
     140                .parent().filter('.closed').children('.widgets-sortables')
     141                //.log('sortable sidebars - find hidden')
     142                .sortable('disable');
     143                //$.log('sortable sidebars - disable sortables if hidden');
     144               
     145                droppableSidebar.droppable({
     146                        tolerance: 'pointer',
     147                        accept: function(o){
     148                                return $(o).parent().attr('id') != 'widget-list';
     149                        },
     150                        drop: function(e,ui) {
     151                                ui.draggable.addClass('deleting');
     152                                $('#removing-widget').hide().children('span').html('');
     153                        },
     154                        over: function(e,ui) {
     155                                ui.draggable.addClass('deleting');
     156                                $('div.widget-placeholder').hide();
     157
     158                                if ( ui.draggable.hasClass('ui-sortable-helper') )
     159                                        $('#removing-widget').show().children('span')
     160                                        .html( ui.draggable.find('div.widget-title').children('h4').html() );
     161                        },
     162                        out: function(e,ui) {
     163                                ui.draggable.removeClass('deleting');
     164                                $('div.widget-placeholder').show();
     165                                $('#removing-widget').hide().children('span').html('');
     166                        }
     167                });
     168                //$.log('droppable sidebar - enable droppable');
     169               
     170                $('p.widget-error').closest('div.widget').find('a.widget-action').click();
     171                //$.log('widgets - open if errors');
    133172        },
    134173
    135174        saveOrder : function(sb) {
    136                 if ( sb )
    137                         $('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
     175                if ( sb ) {
     176                        $('#' + sb).closest('div.widgets-holder-wrap').find('img.ajax-feedback')
     177                        .css('visibility', 'visible');
     178                }
    138179
    139180                var a = {
    140181                        action: 'widgets-order',
     
    142183                        sidebars: []
    143184                };
    144185
    145                 $('.widgets-sortables').each( function() {
     186                $('div.widgets-sortables').each( function() {
    146187                        a['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
    147188                });
    148189
    149190                $.post( ajaxurl, a, function() {
    150                         $('.ajax-feedback').css('visibility', 'hidden');
     191                        $('img.ajax-feedback').css('visibility', 'hidden');
    151192                });
     193               
    152194                this.resize();
    153195        },
    154196
    155197        save : function(widget, del, animate, order) {
    156                 var sb = widget.parents('.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
     198                var sb = widget.closest('div.widgets-sortables').attr('id'),
     199                        data = widget.find('form').serialize(),
     200                        a;
    157201                widget = $(widget);
    158202                widget.find('.ajax-feedback').css('visibility', 'visible');
    159203
     
    172216                        var id;
    173217
    174218                        if ( del ) {
    175                                 if ( !$('.widget_number', widget).val() ) {
    176                                         id = $('.widget-id', widget).val();
    177                                         $('#available-widgets .widget-id').each(function(){
     219                                if ( !$('input.widget_number', widget).val() ) {
     220                                        id = $('input.widget-id', widget).val();
     221                                        $('#available-widgets').find('input.widget-id')
     222                                        .each(function(){
    178223                                                if ( $(this).val() == id )
    179                                                         $(this).parents('.widget').show();
     224                                                        $(this).closest('div.widget').show();
    180225                                        });
    181226                                }
    182227
     
    193238                        } else {
    194239                                $('.ajax-feedback').css('visibility', 'hidden');
    195240                                if ( r && r.length > 2 ) {
    196                                         $('.widget-content', widget).html(r);
     241                                        $('div.widget-content', widget).html(r);
    197242                                        wpWidgets.appendTitle(widget);
    198243                                        wpWidgets.fixLabels(widget);
    199244                                }
     
    204249        },
    205250
    206251        appendTitle : function(widget) {
    207                 $('input[type="text"]', widget).each(function(){
    208                         var title;
    209                         if ( this.id.indexOf('title') != -1 ) {
    210                                 title = $(this).val().replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    211                                 if ( title )
    212                                         $('.widget-title .in-widget-title', widget).html(': ' + title);
    213                                 return false;
    214                         }
     252                $('#' + widget.id + '-title').each(function() {
     253                        var title = $(this).val().replace(/<[^<>]+>/g, '')
     254                        .replace(/</g, '&lt;').replace(/>/g, '&gt;');
     255                       
     256                        if ( title )
     257                                $(widget).children('.widget-top')
     258                                .children('.widget-title').children().children('.in-widget-title')
     259                                .html(': ' + title);
    215260                });
    216261        },
    217262
    218263        resize : function() {
    219                 $('.widgets-sortables').not('#wp_inactive_widgets').each(function(){
    220                         var h = 50, H = $('.widget', this).length;
     264                $('div.widgets-sortables').not('#wp_inactive_widgets')
     265                //.log('find resizables')
     266                .each(function(){
     267                        var h = 50, H = $(this).children('.widget').length;
    221268                        h = h + parseInt(H * 48, 10);
    222269                        $(this).css( 'minHeight', h + 'px' );
    223270                });
     
    231278                });
    232279    },
    233280   
    234     fixLabels : function(sc) {
    235                 sc = sc || document;
    236 
    237                 $('.widget-inside label', sc).each(function(){
     281    fixLabels : function(widget) {
     282                widget.children('.widget-inside').find('label').each(function(){
    238283                        var f = $(this).attr('for');
    239284
    240285                        if ( f && f == $('input', this).attr('id') )
     
    243288        },
    244289   
    245290    close : function(widget) {
    246                 widget.find('.widget-inside').slideUp('fast', function(){
     291                widget.children('.widget-inside').slideUp('fast', function(){
    247292                        widget.css({'width':'','marginLeft':''});
    248293                });
    249294        },
    250295
    251296    addEvents : function(sc) {
    252297                sc = sc || document;
     298               
    253299                $('a.widget-action', sc).click(function(){
    254             var w = parseInt( $(this).parents('.widget').find('.widget-width').val(), 10 ), css = {}, inside = $(this).parents('.widget-top').siblings('.widget-inside');
     300                        var css = {},
     301                                widget = $(this).closest('div.widget'),
     302                                inside = widget.children('.widget-inside'),
     303                                w = parseInt( widget.find('input.widget-width').val(), 10 );
     304                       
    255305                        if ( inside.is(':hidden') ) {
    256                                 if ( w > 250 && inside.parents('.widgets-sortables').length ) {
     306                                if ( w > 250 && inside.closest('div.widgets-sortables').length ) {
    257307                                        css['width'] = w + 30 + 'px';
    258                                         if ( inside.parents('.widget-liquid-right').length )
     308                                        if ( inside.closest('div.widget-liquid-right').length )
    259309                                                css['marginLeft'] = 235 - w + 'px';
    260                                         inside.parents('.widget').css(css);
     310                                        widget.css(css);
    261311                                }
     312                                wpWidgets.fixLabels(widget);
    262313                                inside.slideDown('fast');
    263314                        } else {
    264                                 inside.slideUp('fast', function(){ inside.parents('.widget').css({'width':'','marginLeft':''}); });
     315                                inside.slideUp('fast', function() {
     316                                        widget.css({'width':'','marginLeft':''});
     317                                });
    265318                        }
    266             return false;
    267         });
    268         $('.widget-control-save', sc).click(function(){
    269                         wpWidgets.save( $(this).parents('.widget'), 0, 1, 0 );
    270319                        return false;
    271320                });
    272                 $('.widget-control-remove', sc).click(function(){
    273                         wpWidgets.save( $(this).parents('.widget'), 1, 1, 0 );
     321                // todo: optimize this further by using a button tag instead
     322                $('input.widget-control-save', sc).click(function(){
     323                        wpWidgets.save( $(this).closest('div.widget'), 0, 1, 0 );
    274324                        return false;
    275325                });
    276                 $('.widget-control-close', sc).click(function(){
    277                         wpWidgets.close( $(this).parents('.widget') );
     326                $('a.widget-control-remove', sc).click(function(){
     327                        wpWidgets.save( $(this).closest('div.widget'), 1, 1, 0 );
    278328                        return false;
    279329                });
     330                $('a.widget-control-close', sc).click(function(){
     331                        wpWidgets.close( $(this).closest('div.widget') );
     332                        return false;
     333                });
    280334        }
    281335};
    282 $(document).ready(function(){wpWidgets.init();});
     336$(document).ready(function($){
     337        //$.log('widgets.js - start');
     338        wpWidgets.init();
     339        //$.log('widgets.js - done');
     340});
    283341
    284 })(jQuery);
     342})(jQuery);
     343 No newline at end of file