summaryrefslogtreecommitdiff
path: root/lib/gallery.common.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gallery.common.js')
-rw-r--r--lib/gallery.common.js101
1 files changed, 71 insertions, 30 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js
index 755218f5..fa11aeb9 100644
--- a/lib/gallery.common.js
+++ b/lib/gallery.common.js
@@ -26,9 +26,9 @@
}
var el = $(this).find(".g-valign");
if (!el.length) {
- $(this).html("<" + container + " class=\"g-valign\">" + $(this).html() +
- "</" + container + ">");
- el = $(this).children(container + ".g-valign");
+ $(this).html("<" + container + " class=\"g-valign\">" + $(this).html() +
+ "</" + container + ">");
+ el = $(this).children(container + ".g-valign");
}
var elh = $(el).height();
var ph = $(this).height();
@@ -133,23 +133,26 @@
$.fn.gallery_context_menu = function() {
if ($(".g-context-menu li").length) {
var hover_target = $(this).find(".g-context-menu");
- if (hover_target.attr("context_menu_initialized")) {
- return;
+ if (hover_target.hasClass("g-context-menu-initialized")) {
+ return;
}
var list = $(hover_target).find("ul");
+
hover_target.find("*").removeAttr('title');
+ hover_target.find(".g-dialog-link").gallery_dialog();
+ hover_target.find(".g-ajax-link").gallery_ajax();
list.hide();
+
hover_target.hover(
function() {
list.stop(true, true).slideDown("fast");
- $(this).find(".g-dialog-link").gallery_dialog();
- $(this).find(".g-ajax-link").gallery_ajax();
},
function() {
list.stop(true, true).slideUp("slow");
}
);
- hover_target.attr("context_menu_initialized", 1);
+
+ hover_target.addClass("g-context-menu-initialized");
}
};
@@ -200,7 +203,7 @@
// Set the input value equal to label text
if (input.val() == "") {
input.val(label.html());
- button.enable(false);
+ button.attr("disabled", true);
}
// Attach event listeners to the input
@@ -209,14 +212,14 @@
if ($(this).val() == label.html()) {
$(this).val("");
}
- button.enable(true);
+ button.attr("disabled", false);
});
input.bind("blur", function(e){
// Reset the input value if it's empty
if ($(this).val() == "") {
$(this).val(label.html());
- button.enable(false);
+ button.attr("disabled", true);
}
});
});
@@ -225,29 +228,67 @@
// Augment jQuery autocomplete to expect the first response line to
// be a <meta> tag that protects against UTF-7 attacks.
$.fn.gallery_autocomplete = function(url, options) {
- // Drop the first response - it should be a meta tag
- options.parse = function(data) {
- var parsed = [];
- var rows = data.split("\n");
- if (rows[0].indexOf("<meta") == -1) {
- throw 'Missing <meta> tag in first line of autocomplete response';
- }
- rows.shift(); // drop <META> tag
- for (var i=0; i < rows.length; i++) {
- var row = $.trim(rows[i]);
- if (row) {
- row = row.split("|");
- parsed[parsed.length] = {
- data: row,
- value: row[0],
- result: row[0]
- };
+ var autocomplete_options = {
+ source: function(request, response) {
+ var split = function(val) {
+ return val.split(/,\s*/);
+ };
+
+ var extract_last = function(term) {
+ return split(term).pop();
+ };
+
+ var ajax_options = {
+ dataType: "json",
+ url: url,
+ success: function(data) {
+ response(data);
+ },
+ data: {
+ term: request.term
+ },
+ dataFilter: function(data, dataType) {
+ // Drop the <meta> tag
+ return data.substring(data.indexOf("\n") + 1);
+ }
+ };
+
+ if ("multiple" in options) {
+ $.extend(ajax_options, {
+ data: {
+ term: extract_last(request.term)
+ }
+ });
}
+
+ $.ajax(ajax_options, response);
}
- return parsed;
};
- $(this).autocomplete(url, options);
+ if ("multiple" in options) {
+ var split = function(val) {
+ return val.split(/,\s*/);
+ };
+ $.extend(autocomplete_options, {
+ focus: function(event, ui) {
+ var terms = split(this.value);
+ terms.pop();
+ terms.push(ui.item.value);
+ this.value = terms.join(", ");
+ return false;
+ },
+ select: function(event, ui) {
+ var terms = split(this.value);
+ terms.pop();
+ terms.push(ui.item.value);
+ terms.push("");
+ this.value = terms.join(", ");
+ return false;
+ }
+ });
+ }
+
+ $(this).autocomplete(autocomplete_options);
};
})(jQuery);