diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-06 07:02:55 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-06 07:02:55 -0800 |
commit | 44ae88e8e17713cab81a5cf08820e18896615196 (patch) | |
tree | 45ecb24e92cbd8454c67a4840eea8ae579ebe68f /lib/gallery.in_place_edit.js | |
parent | 1faa2492952a54f0b80cce149ae42b59b91039df (diff) | |
parent | 04c10a0720b57bc4b6273ea7127d9880c2c28354 (diff) |
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'lib/gallery.in_place_edit.js')
-rw-r--r-- | lib/gallery.in_place_edit.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gallery.in_place_edit.js b/lib/gallery.in_place_edit.js new file mode 100644 index 00000000..38c4efb1 --- /dev/null +++ b/lib/gallery.in_place_edit.js @@ -0,0 +1,62 @@ +(function($) { + $.widget("ui.gallery_in_place_edit", { + _init: function() { + var self = this; + $(self).data("parent", self.element.parent()); + this.element.click(function(event) { + event.preventDefault(); + self._show(event.currentTarget); + return false; + }); + }, + + _show: function(target) { + var self = this; + var tag_width = $(target).width(); + $(self).data("tag_width", tag_width); + + $.get(self.options.form_url.replace("__ID__", $(target).attr('rel')), function(data) { + var parent = $(target).parent(); + parent.children().hide(); + parent.append(data); + parent.find("form :text") + .width(tag_width) + .focus(); + $(".g-short-form").gallery_short_form(); + parent.find("form .g-cancel").click(function(event) { + parent.find("form").remove(); + parent.children().show(); + event.preventDefault(); + return false; + }); + self._ajaxify_edit(); + }); + + }, + + _ajaxify_edit: function() { + var self = this; + var form = $($(self).data("parent")).find("form"); + $(form).ajaxForm({ + dataType: "json", + success: function(data) { + if (data.result == "success") { + window.location.reload(); + } else { + $(form).replaceWith(data.form); + var width = $(self).data("tag_width"); + $($(self).data("parent")).find("form :text") + .width(width) + .focus(); + $(".g-short-form").gallery_short_form(); + self._ajaxify_edit(); + } + } + }); + } + }); + + $.extend($.ui.gallery_in_place_edit, { + defaults: {} + }); +})(jQuery); |