]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/inline-edit-tax.js
WordPress 3.8-scripts
[autoinstalls/wordpress.git] / wp-admin / js / inline-edit-tax.js
index d5539cc2b2184e98814a678bd685d29c45700d79..1efacba7a11b5afe1c9df64013614724ffa3f5ba 100644 (file)
@@ -1,86 +1,70 @@
+/* global inlineEditL10n, ajaxurl */
 
+var inlineEditTax;
 (function($) {
 inlineEditTax = {
 
        init : function() {
                var t = this, row = $('#inline-edit');
 
-               t.type = $('#the-list').attr('className').substr(5);
+               t.type = $('#the-list').attr('data-wp-lists').substr(5);
                t.what = '#'+t.type+'-';
 
-               // get all editable rows
-               t.rows = $('tr.iedit');
+               $('#the-list').on('click', 'a.editinline', function(){
+                       inlineEditTax.edit(this);
+                       return false;
+               });
 
                // prepare the edit row
-               row.keyup(function(e) { if(e.which == 27) return inlineEditTax.revert(); });
-
-               $('a.cancel', row).click(function() { return inlineEditTax.revert(); });
-               $('a.save', row).click(function() { return inlineEditTax.save(this); });
-               $('input, select', row).keydown(function(e) { if(e.which == 13) return inlineEditTax.save(this); });
+               row.keyup( function( e ) {
+                       if ( e.which === 27 ) {
+                               return inlineEditTax.revert();
+                       }
+               });
 
-               // add events
-               t.addEvents(t.rows);
+               $( 'a.cancel', row ).click( function() {
+                       return inlineEditTax.revert();
+               });
+               $( 'a.save', row ).click( function() {
+                       return inlineEditTax.save(this);
+               });
+               $( 'input, select', row ).keydown( function( e ) {
+                       if ( e.which === 13 ) {
+                               return inlineEditTax.save( this );
+                       }
+               });
 
-               $('#posts-filter input[type="submit"]').click(function(e){
-                       if ( $('form#posts-filter tr.inline-editor').length > 0 )
-                               t.revert();
+               $( '#posts-filter input[type="submit"]' ).mousedown( function() {
+                       t.revert();
                });
        },
 
        toggle : function(el) {
                var t = this;
-
-               $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
-       },
-
-       addEvents : function(r) {
-               r.each(function() {
-                       $(this).find('a.editinline').click(function() { inlineEditTax.edit(this); return false; });
-                       $(this).find('.hide-if-no-js').removeClass('hide-if-no-js');
-               });
+               $(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el);
        },
 
        edit : function(id) {
-               var t = this;
+               var editRow, rowData,
+                       t = this;
                t.revert();
 
-               if ( typeof(id) == 'object' )
+               if ( typeof(id) === 'object' ) {
                        id = t.getId(id);
+               }
 
-               var editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
+               editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
                $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
 
-               if ( $(t.what+id).hasClass('alternate') )
+               if ( $( t.what + id ).hasClass( 'alternate' ) ) {
                        $(editRow).addClass('alternate');
+               }
 
                $(t.what+id).hide().after(editRow);
 
                $(':input[name="name"]', editRow).val( $('.name', rowData).text() );
                $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() );
 
-               // cat parents
-               var cat_parent = $('.cat_parent', rowData).text();
-               if ( cat_parent != '0' )
-                       $('select[name="parent"]', editRow).val(cat_parent);
-
-               // remove the current parent and children from the parent dropdown
-               var pageOpt = $('select[name="parent"] option[value="'+id+'"]', editRow);
-               if ( pageOpt.length > 0 ) {
-                       var pageLevel = pageOpt[0].className.split('-')[1], nextPage = pageOpt, pageLoop = true;
-                       while ( pageLoop ) {
-                               var nextPage = nextPage.next('option');
-                               if (nextPage.length == 0) break;
-                               var nextLevel = nextPage[0].className.split('-')[1];
-                               if ( nextLevel <= pageLevel ) {
-                                       pageLoop = false;
-                               } else {
-                                       nextPage.remove();
-                                       nextPage = pageOpt;
-                               }
-                       }
-                       pageOpt.remove();
-               }
-
                $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
                $('.ptitle', editRow).eq(0).focus();
 
@@ -88,41 +72,48 @@ inlineEditTax = {
        },
 
        save : function(id) {
-               if( typeof(id) == 'object' )
+               var params, fields, tax = $('input[name="taxonomy"]').val() || '';
+
+               if( typeof(id) === 'object' ) {
                        id = this.getId(id);
+               }
 
-               $('table.widefat .inline-edit-save .waiting').show();
+               $('table.widefat .spinner').show();
 
-               var params = {
+               params = {
                        action: 'inline-save-tax',
                        tax_type: this.type,
-                       tax_ID: id
+                       tax_ID: id,
+                       taxonomy: tax
                };
 
-               var fields = $('#edit-'+id+' :input').fieldSerialize();
+               fields = $('#edit-'+id).find(':input').serialize();
                params = fields + '&' + $.param(params);
 
                // make ajax request
-               $.post('admin-ajax.php', params,
+               $.post( ajaxurl, params,
                        function(r) {
-
-                               $('table.widefat .inline-edit-save .waiting').hide();
+                               var row, new_id;
+                               $('table.widefat .spinner').hide();
 
                                if (r) {
-                                       if ( -1 != r.indexOf('<tr') ) {
+                                       if ( -1 !== r.indexOf( '<tr' ) ) {
                                                $(inlineEditTax.what+id).remove();
-                                               $('#edit-'+id).before(r).remove();
-
-                                               var row = $(inlineEditTax.what+id);
-                                               row.hide();
+                                               new_id = $(r).attr('id');
 
-                                               row.find('.hide-if-no-js').removeClass('hide-if-no-js');
-                                               inlineEditTax.addEvents(row);
-                                               row.fadeIn();
-                                       } else
+                                               $('#edit-'+id).before(r).remove();
+                                               row = new_id ? $('#'+new_id) : $(inlineEditTax.what+id);
+                                               row.hide().fadeIn();
+                                       } else {
                                                $('#edit-'+id+' .inline-edit-save .error').html(r).show();
-                               } else
+                                       }
+                               } else {
                                        $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
+                               }
+
+                               if ( $( row ).prev( 'tr' ).hasClass( 'alternate' ) ) {
+                                       $(row).removeClass('alternate');
+                               }
                        }
                );
                return false;
@@ -132,7 +123,7 @@ inlineEditTax = {
                var id = $('table.widefat tr.inline-editor').attr('id');
 
                if ( id ) {
-                       $('table.widefat .inline-edit-save .waiting').hide();
+                       $('table.widefat .spinner').hide();
                        $('#'+id).remove();
                        id = id.substr( id.lastIndexOf('-') + 1 );
                        $(this.what+id).show();
@@ -142,8 +133,7 @@ inlineEditTax = {
        },
 
        getId : function(o) {
-               var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id');
-               var parts = id.split('-');
+               var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
                return parts[parts.length - 1];
        }
 };