Make WordPress Core

Ticket #26002: 26002.diff

File 26002.diff, 6.9 KB (added by dougwollison, 13 years ago)

Initial changes: spacing, braces, equals, keys fixed and globals.

  • src/wp-admin/js/inline-edit-tax.js

     
     1/* global inlineEditL10n:false */
     2/* global ajaxurl:false */
    13
    24(function($) {
    3 inlineEditTax = {
     5        var inlineEditTax = {
    46
    5         init : function() {
    6                 var t = this, row = $('#inline-edit');
     7                init: function() {
     8                        var t = this, row = $( '#inline-edit' );
    79
    8                 t.type = $('#the-list').attr('data-wp-lists').substr(5);
    9                 t.what = '#'+t.type+'-';
     10                        t.type = $( '#the-list' ).attr( 'data-wp-lists' ).substr( 5 );
     11                        t.what = '#' + t.type + '-';
    1012
    11                 $('#the-list').on('click', 'a.editinline', function(){
    12                         inlineEditTax.edit(this);
    13                         return false;
    14                 });
     13                        $( '#the-list' ).on( 'click', 'a.editinline', function() {
     14                                inlineEditTax.edit( this );
     15                                return false;
     16                        });
    1517
    16                 // prepare the edit row
    17                 row.keyup(function(e) { if(e.which == 27) return inlineEditTax.revert(); });
     18                        // prepare the edit row
     19                        row.keyup(function( e ) {
     20                                if ( e.which === 27 ) {
     21                                        return inlineEditTax.revert();
     22                                }
     23                        });
    1824
    19                 $('a.cancel', row).click(function() { return inlineEditTax.revert(); });
    20                 $('a.save', row).click(function() { return inlineEditTax.save(this); });
    21                 $('input, select', row).keydown(function(e) { if(e.which == 13) return inlineEditTax.save(this); });
     25                        $( 'a.cancel', row ).click(function() {
     26                                return inlineEditTax.revert();
     27                        });
     28                        $( 'a.save', row ).click(function() {
     29                                return inlineEditTax.save( this );
     30                        });
     31                        $( 'input, select', row ).keydown(function( e ) {
     32                                if ( e.which === 13 ) {
     33                                        return inlineEditTax.save( this );
     34                                }
     35                        });
    2236
    23                 $('#posts-filter input[type="submit"]').mousedown(function(e){
     37                        $( '#posts-filter input[type="submit"]' ).mousedown(function() {
     38                                t.revert();
     39                        });
     40                },
     41
     42                toggle: function( el ) {
     43                        var t = this;
     44                        $( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el );
     45                },
     46
     47                edit: function( id ) {
     48                        var t = this, editRow, rowData;
    2449                        t.revert();
    25                 });
    26         },
    2750
    28         toggle : function(el) {
    29                 var t = this;
    30                 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
    31         },
     51                        if ( typeof( id ) === 'object' ) {
     52                                id = t.getId( id );
     53                        }
    3254
    33         edit : function(id) {
    34                 var t = this, editRow;
    35                 t.revert();
     55                        editRow = $( '#inline-edit' ).clone( true ), rowData = $( '#inline_' + id );
     56                        $( 'td', editRow ).attr( 'colspan', $( '.widefat:first thead th:visible' ).length );
    3657
    37                 if ( typeof(id) == 'object' )
    38                         id = t.getId(id);
     58                        if ( $( t.what + id ).hasClass( 'alternate' ) ) {
     59                                $( editRow ).addClass( 'alternate' );
     60                        }
    3961
    40                 editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
    41                 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
     62                        $( t.what + id ).hide().after( editRow );
    4263
    43                 if ( $(t.what+id).hasClass('alternate') )
    44                         $(editRow).addClass('alternate');
     64                        $( ':input[name="name"]', editRow ).val( $( '.name', rowData ).text() );
     65                        $( ':input[name="slug"]', editRow ).val( $( '.slug', rowData ).text() );
    4566
    46                 $(t.what+id).hide().after(editRow);
     67                        $( editRow ).attr( 'id', 'edit-' + id ).addClass( 'inline-editor' ).show();
     68                        $( '.ptitle', editRow ).eq(0).focus();
    4769
    48                 $(':input[name="name"]', editRow).val( $('.name', rowData).text() );
    49                 $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() );
     70                        return false;
     71                },
    5072
    51                 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
    52                 $('.ptitle', editRow).eq(0).focus();
     73                save : function( id ) {
     74                        var params, fields, tax = $( 'input[name="taxonomy"]' ).val() || '';
    5375
    54                 return false;
    55         },
     76                        if( typeof( id ) === 'object' ) {
     77                                id = this.getId( id );
     78                        }
    5679
    57         save : function(id) {
    58                 var params, fields, tax = $('input[name="taxonomy"]').val() || '';
     80                        $( 'table.widefat .spinner' ).show();
    5981
    60                 if( typeof(id) == 'object' )
    61                         id = this.getId(id);
     82                        params = {
     83                                action:   'inline-save-tax',
     84                                tax_type: this.type,
     85                                tax_ID:   id,
     86                                taxonomy: tax
     87                        };
    6288
    63                 $('table.widefat .spinner').show();
     89                        fields = $( '#edit-' + id ).find( ':input' ).serialize();
     90                        params = fields + '&' + $.param( params );
    6491
    65                 params = {
    66                         action: 'inline-save-tax',
    67                         tax_type: this.type,
    68                         tax_ID: id,
    69                         taxonomy: tax
    70                 };
     92                        // make ajax request
     93                        $.post( ajaxurl, params,
     94                                function( r ) {
     95                                        var row, new_id;
     96                                        $( 'table.widefat .spinner' ).hide();
    7197
    72                 fields = $('#edit-'+id).find(':input').serialize();
    73                 params = fields + '&' + $.param(params);
     98                                        if ( r ) {
     99                                                if ( -1 !== r.indexOf( '<tr' ) ) {
     100                                                        $( inlineEditTax.what + id ).remove();
     101                                                        new_id = $( r ).attr( 'id' );
    74102
    75                 // make ajax request
    76                 $.post( ajaxurl, params,
    77                         function(r) {
    78                                 var row, new_id;
    79                                 $('table.widefat .spinner').hide();
     103                                                        $( '#edit-' + id ).before( r ).remove();
     104                                                        row = new_id ? $( '#' + new_id ) : $( inlineEditTax.what + id );
     105                                                        row.hide().fadeIn();
     106                                                } else {
     107                                                        $( '#edit-' + id + ' .inline-edit-save .error' ).html( r ).show();
     108                                                }
     109                                        } else {
     110                                                $( '#edit-' + id + ' .inline-edit-save .error' ).html( inlineEditL10n.error ).show();
     111                                        }
    80112
    81                                 if (r) {
    82                                         if ( -1 != r.indexOf('<tr') ) {
    83                                                 $(inlineEditTax.what+id).remove();
    84                                                 new_id = $(r).attr('id');
     113                                        if ( $( row ).prev( 'tr' ).hasClass( 'alternate' ) ) {
     114                                                $( row ).removeClass( 'alternate' );
     115                                        }
     116                                }
     117                        );
     118                        return false;
     119                },
    85120
    86                                                 $('#edit-'+id).before(r).remove();
    87                                                 row = new_id ? $('#'+new_id) : $(inlineEditTax.what+id);
    88                                                 row.hide().fadeIn();
    89                                         } else
    90                                                 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
    91                                 } else
    92                                         $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
     121                revert: function() {
     122                        var id = $( 'table.widefat tr.inline-editor' ).attr( 'id' );
    93123
    94                                 if ($(row).prev('tr').hasClass('alternate'))
    95                                         $(row).removeClass('alternate');
     124                        if ( id ) {
     125                                $( 'table.widefat .spinner' ).hide();
     126                                $( '#' + id ).remove();
     127                                id = id.substr( id.lastIndexOf( '-' ) + 1 );
     128                                $( this.what + id ).show();
    96129                        }
    97                 );
    98                 return false;
    99         },
    100130
    101         revert : function() {
    102                 var id = $('table.widefat tr.inline-editor').attr('id');
     131                        return false;
     132                },
    103133
    104                 if ( id ) {
    105                         $('table.widefat .spinner').hide();
    106                         $('#'+id).remove();
    107                         id = id.substr( id.lastIndexOf('-') + 1 );
    108                         $(this.what+id).show();
     134                getId: function( o ) {
     135                        var id = o.tagName === 'TR' ? o.id : $( o ).parents( 'tr' ).attr( 'id' ), parts = id.split( '-' );
     136                        return parts[ parts.length - 1 ];
    109137                }
     138        };
    110139
    111                 return false;
    112         },
    113 
    114         getId : function(o) {
    115                 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
    116                 return parts[parts.length - 1];
    117         }
    118 };
    119 
    120 $(document).ready(function(){inlineEditTax.init();});
    121 })(jQuery);
     140        $( document ).ready(function() {
     141                inlineEditTax.init();
     142        });
     143})( jQuery );