summaryrefslogtreecommitdiff
path: root/lib/gallery.in_place_edit.js
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
committerAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
commit0733dc37fda27a5ba35f9020edf3c66aa41a95a0 (patch)
tree6877946232f1b01b1c8709054c689f6658cef34f /lib/gallery.in_place_edit.js
parent218493c50be9362d4abed6900a816308fee5d978 (diff)
parent9379308f91a476f790fb8d444536719535c584e4 (diff)
Merge commit 'upstream/master'
Conflicts: modules/gallery/tests/xss_data.txt
Diffstat (limited to 'lib/gallery.in_place_edit.js')
-rw-r--r--lib/gallery.in_place_edit.js78
1 files changed, 78 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..681688e5
--- /dev/null
+++ b/lib/gallery.in_place_edit.js
@@ -0,0 +1,78 @@
+(function($) {
+ $.widget("ui.gallery_in_place_edit", {
+ _init: function() {
+ var self = this;
+ 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);
+
+ var form = $("#g-in-place-edit-form");
+ if (form.length > 0) {
+ self._cancel();
+ }
+
+ $.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) {
+ self._cancel();
+ event.preventDefault();
+ return false;
+ });
+ self._ajaxify_edit();
+ });
+
+ },
+
+ _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 = $("#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");
+ $(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();
+ }
+ }
+ });
+ }
+ });
+
+ $.extend($.ui.gallery_in_place_edit, {
+ defaults: {}
+ });
+})(jQuery);