/*global alert*/ /*jshint indent:4*/ if (typeof jQuery !== 'undefined') { (function($, undefined) { $.WordPressAjaxAdmin = function(element, options) { var self = this, block = self.block = $(element); self.options = $.extend({}, $.WordPressAjaxAdmin.defaults, options); block.delegate('.row-actions a, .row-actions-visible a', 'click', function(event) { var link, parent, row, skip; link = self.link = $(this); parent = self.parent = link.closest('span'); row = self.row = parent.closest('tr'); if (self.options.exclude) { skip = false; $.each(parent.attr('class').split(' '), function(i, c) { if ($.inArray(c, self.options.exclude) > -1) { skip = true; } }); } else if (self.options.include) { skip = true; $.each(parent.attr('class').split(' '), function(i, c) { if ($.inArray(c, self.options.include) > -1) { skip = false; } }); } if (skip) { return; } else if (link.attr('target') === '_blank' || parent.length === 0) { return; } else if (!parent.hasClass('view') && $.inArray(parent.attr('class'), self.options.ignore) < 0) { event.preventDefault(); } if (parent.hasClass('edit')) { self.edit(); } else if (parent.hasClass('top') || parent.hasClass('up') || parent.hasClass('down') || parent.hasClass('bottom')) { self.move(); } else if (parent.hasClass('trash')) { self.trash(); } }); block.delegate('a.add', 'click', function(event) { event.preventDefault(); self.link = $(this); self.add(); }); }; $.WordPressAjaxAdmin.defaults = { ignore: [] }; $.WordPressAjaxAdmin.prototype = { add: function() { var options = this.options, link = this.link, parent = link.closest('div'), table = parent.find('table tbody'), first = table.find('tr:first'), inline; $.post(options.ajaxurl, $.extend({}, options.data, { 'action': options.actions.add }), function(response) { inline = $(response.html).insertBefore(first); /* handle save and cancel buttons */ inline.find('a.cancel').click(function(){ first.show(); inline.remove(); }); inline.find('a.save').click(function(){ var waiting = inline.find('img.waiting').show(); inline.find('div.error').remove(); inline.find('form').ajaxSubmit({ data: {'save': true}, dataType: 'json', success: function(response) { if (response.status === 'success') { inline.remove(); table.append(response.html); if (first.hasClass('empty-row')) { first.remove(); } } else { waiting.hide(); var errors = $('
' + response.message + '