From beb63a83804e57050a23b3a90ebed93be41b6769 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 6 Nov 2009 23:05:20 -0800 Subject: Clean up the In place edit api: 1) Only allow 1 in place edit to be active at a time (gets around the issue of using an id to identify the form 2) remove the add_ prefix from some of the api methods 3) clean up inconsistent naming --- lib/gallery.in_place_edit.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/gallery.in_place_edit.js') diff --git a/lib/gallery.in_place_edit.js b/lib/gallery.in_place_edit.js index 38c4efb1..4a90581b 100644 --- a/lib/gallery.in_place_edit.js +++ b/lib/gallery.in_place_edit.js @@ -15,6 +15,13 @@ var tag_width = $(target).width(); $(self).data("tag_width", tag_width); + var form = $("#g-inplace-edit-form"); + if (form.length > 0) { + var parent = form.parent(); + form.remove(); + parent.children().show(); + } + $.get(self.options.form_url.replace("__ID__", $(target).attr('rel')), function(data) { var parent = $(target).parent(); parent.children().hide(); -- cgit v1.2.3 From e300ede3d8311bf236594480355f710b39aaa451 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 7 Nov 2009 00:05:49 -0800 Subject: 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. --- lib/gallery.in_place_edit.js | 27 ++++++++++++++++++--------- modules/gallery/css/gallery.css | 2 +- modules/gallery/views/in_place_edit.html.php | 4 ++-- themes/admin_wind/css/screen.css | 2 +- themes/night_wind/css/screen.css | 2 +- themes/wind/css/screen.css | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) (limited to 'lib/gallery.in_place_edit.js') 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(); } } diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css index 18d9a522..3262dee2 100644 --- a/modules/gallery/css/gallery.css +++ b/modules/gallery/css/gallery.css @@ -50,7 +50,7 @@ /* In-place edit ~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#g-inplace-edit-form ul { +#g-in-place-edit-form ul { margin: 0; } diff --git a/modules/gallery/views/in_place_edit.html.php b/modules/gallery/views/in_place_edit.html.php index 64671d57..03cbdc69 100644 --- a/modules/gallery/views/in_place_edit.html.php +++ b/modules/gallery/views/in_place_edit.html.php @@ -1,5 +1,5 @@ - "post", "id" => "g-inplace-edit-form", "class" => "g-short-form"), $hidden) ?> + "post", "id" => "g-in-place-edit-form", "class" => "g-short-form"), $hidden) ?> -
+
diff --git a/themes/admin_wind/css/screen.css b/themes/admin_wind/css/screen.css index 5fe47d76..3342bd83 100644 --- a/themes/admin_wind/css/screen.css +++ b/themes/admin_wind/css/screen.css @@ -383,7 +383,7 @@ th { } /* In-line editing ~~~~~~~~~~~~~~~~~~~~~~ */ -#g-inplace-edit-message { +#g-in-place-edit-message { background-color: #FFF; } diff --git a/themes/night_wind/css/screen.css b/themes/night_wind/css/screen.css index 1d5e5e2b..cd1824d1 100644 --- a/themes/night_wind/css/screen.css +++ b/themes/night_wind/css/screen.css @@ -456,7 +456,7 @@ li.g-error select { } /* In-line editing ~~~~~~~~~~~~~~~~~~~~~~ */ -#g-inplace-edit-message { +#g-in-place-edit-message { background-color: #FFF; } diff --git a/themes/wind/css/screen.css b/themes/wind/css/screen.css index 2ac37fb6..74771e07 100644 --- a/themes/wind/css/screen.css +++ b/themes/wind/css/screen.css @@ -300,7 +300,7 @@ td { } /* In-line editing ~~~~~~~~~~~~~~~~~~~~~~ */ -#g-inplace-edit-message { +#g-in-place-edit-message { background-color: #FFF; } -- cgit v1.2.3