diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-07 00:05:49 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-07 00:05:49 -0800 |
commit | e300ede3d8311bf236594480355f710b39aaa451 (patch) | |
tree | 382d16032be71f7ea280660bbbdac24b77e254f3 /lib/gallery.in_place_edit.js | |
parent | ad8579e11a0860006cecf9312c86c1a2c4e8418a (diff) |
1) Change the name of the form and message to g-in-place-edit-form and g-in-place-edit-message.
2) Make sure the cancel button works and cleans up the dom appropriately.
Diffstat (limited to 'lib/gallery.in_place_edit.js')
-rw-r--r-- | lib/gallery.in_place_edit.js | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/gallery.in_place_edit.js b/lib/gallery.in_place_edit.js index 4a90581b..681688e5 100644 --- a/lib/gallery.in_place_edit.js +++ b/lib/gallery.in_place_edit.js @@ -2,7 +2,6 @@ $.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); @@ -15,11 +14,9 @@ var tag_width = $(target).width(); $(self).data("tag_width", tag_width); - var form = $("#g-inplace-edit-form"); + var form = $("#g-in-place-edit-form"); if (form.length > 0) { - var parent = form.parent(); - form.remove(); - parent.children().show(); + self._cancel(); } $.get(self.options.form_url.replace("__ID__", $(target).attr('rel')), function(data) { @@ -31,8 +28,7 @@ .focus(); $(".g-short-form").gallery_short_form(); parent.find("form .g-cancel").click(function(event) { - parent.find("form").remove(); - parent.children().show(); + self._cancel(); event.preventDefault(); return false; }); @@ -41,21 +37,34 @@ }, + _cancel: function() { + var parent = $("#g-in-place-edit-form").parent(); + $(parent).find("form").remove(); + $(parent).children().show(); + $("#g-in-place-edit-message").remove(); + }, + _ajaxify_edit: function() { var self = this; - var form = $($(self).data("parent")).find("form"); + var form = $("#g-in-place-edit-form"); $(form).ajaxForm({ dataType: "json", success: function(data) { if (data.result == "success") { window.location.reload(); } else { + var parent = $(form).parent(); $(form).replaceWith(data.form); var width = $(self).data("tag_width"); - $($(self).data("parent")).find("form :text") + $(parent).find("form :text") .width(width) .focus(); $(".g-short-form").gallery_short_form(); + $(parent).find("form .g-cancel").click(function(event) { + self._cancel(); + event.preventDefault(); + return false; + }); self._ajaxify_edit(); } } |