diff --git a/image-picker/image-picker.js b/image-picker/image-picker.js
index b61443f..68baeaa 100644
--- a/image-picker/image-picker.js
+++ b/image-picker/image-picker.js
@@ -1,14 +1,13 @@
-// Generated by CoffeeScript 1.12.6
+// Generated by CoffeeScript 2.0.2
(function() {
+ // Image Picker source
+ // by Rodrigo Vera
+
var ImagePicker, ImagePickerOption, both_array_are_equal, sanitized_options,
- bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
- indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+ indexOf = [].indexOf;
jQuery.fn.extend({
- imagepicker: function(opts) {
- if (opts == null) {
- opts = {};
- }
+ imagepicker: function(opts = {}) {
return this.each(function() {
var select;
select = jQuery(this);
@@ -31,6 +30,7 @@
initialized: void 0,
changed: void 0,
clicked: void 0,
+ dblclicked: void 0,
selected: void 0,
limit: void 0,
limit_reached: void 0,
@@ -57,10 +57,10 @@
return true;
};
- ImagePicker = (function() {
- function ImagePicker(select_element, opts1) {
- this.opts = opts1 != null ? opts1 : {};
- this.sync_picker_with_select = bind(this.sync_picker_with_select, this);
+ ImagePicker = class ImagePicker {
+ constructor(select_element, opts1 = {}) {
+ this.sync_picker_with_select = this.sync_picker_with_select.bind(this);
+ this.opts = opts1;
this.select = jQuery(select_element);
this.multiple = this.select.attr("multiple") === "multiple";
if (this.select.data("limit") != null) {
@@ -69,7 +69,7 @@
this.build_and_append_picker();
}
- ImagePicker.prototype.destroy = function() {
+ destroy() {
var j, len, option, ref;
ref = this.picker_options;
for (j = 0, len = ref.length; j < len; j++) {
@@ -80,9 +80,9 @@
this.select.off("change", this.sync_picker_with_select);
this.select.removeData("picker");
return this.select.show();
- };
+ }
- ImagePicker.prototype.build_and_append_picker = function() {
+ build_and_append_picker() {
if (this.opts.hide_select) {
this.select.hide();
}
@@ -93,9 +93,9 @@
this.create_picker();
this.select.after(this.picker);
return this.sync_picker_with_select();
- };
+ }
- ImagePicker.prototype.sync_picker_with_select = function() {
+ sync_picker_with_select() {
var j, len, option, ref, results;
ref = this.picker_options;
results = [];
@@ -108,23 +108,23 @@
}
}
return results;
- };
+ }
- ImagePicker.prototype.create_picker = function() {
+ create_picker() {
this.picker = jQuery("
");
this.picker_options = [];
this.recursively_parse_option_groups(this.select, this.picker);
return this.picker;
- };
+ }
- ImagePicker.prototype.recursively_parse_option_groups = function(scoped_dom, target_container) {
+ recursively_parse_option_groups(scoped_dom, target_container) {
var container, j, k, len, len1, option, option_group, ref, ref1, results;
ref = scoped_dom.children("optgroup");
for (j = 0, len = ref.length; j < len; j++) {
option_group = ref[j];
option_group = jQuery(option_group);
container = jQuery("");
- container.append(jQuery("" + (option_group.attr("label")) + ""));
+ container.append(jQuery(`${option_group.attr("label")}`));
target_container.append(jQuery("").append(container));
this.recursively_parse_option_groups(option_group, container);
}
@@ -148,9 +148,9 @@
results.push(target_container.append(option.node));
}
return results;
- };
+ }
- ImagePicker.prototype.has_implicit_blanks = function() {
+ has_implicit_blanks() {
var option;
return ((function() {
var j, len, ref, results;
@@ -164,17 +164,17 @@
}
return results;
}).call(this)).length > 0;
- };
+ }
- ImagePicker.prototype.selected_values = function() {
+ selected_values() {
if (this.multiple) {
return this.select.val() || [];
} else {
return [this.select.val()];
}
- };
+ }
- ImagePicker.prototype.toggle = function(imagepicker_option, original_event) {
+ toggle(imagepicker_option, original_event) {
var new_values, old_values, selected_value;
old_values = this.selected_values();
selected_value = imagepicker_option.value().toString();
@@ -206,34 +206,34 @@
return this.opts.changed.call(this.select, old_values, this.selected_values(), original_event);
}
}
- };
-
- return ImagePicker;
+ }
- })();
+ };
- ImagePickerOption = (function() {
- function ImagePickerOption(option_element, picker, opts1) {
+ ImagePickerOption = class ImagePickerOption {
+ constructor(option_element, picker, opts1 = {}) {
+ this.clicked = this.clicked.bind(this);
+ this.dblclicked = this.dblclicked.bind(this);
this.picker = picker;
- this.opts = opts1 != null ? opts1 : {};
- this.clicked = bind(this.clicked, this);
+ this.opts = opts1;
this.option = jQuery(option_element);
this.create_node();
}
- ImagePickerOption.prototype.destroy = function() {
- return this.node.find(".thumbnail").off("click", this.clicked);
- };
+ destroy() {
+ this.node.find(".thumbnail").off("click", this.clicked);
+ return this.node.find(".thumbnail").off("dblclick", this.dblclicked);
+ }
- ImagePickerOption.prototype.has_image = function() {
+ has_image() {
return this.option.data("img-src") != null;
- };
+ }
- ImagePickerOption.prototype.is_blank = function() {
+ is_blank() {
return !((this.value() != null) && this.value() !== "");
- };
+ }
- ImagePickerOption.prototype.is_selected = function() {
+ is_selected() {
var select_value;
select_value = this.picker.select.val();
if (this.picker.multiple) {
@@ -241,29 +241,29 @@
} else {
return this.value() === select_value;
}
- };
+ }
- ImagePickerOption.prototype.mark_as_selected = function() {
+ mark_as_selected() {
return this.node.find(".thumbnail").addClass("selected");
- };
+ }
- ImagePickerOption.prototype.unmark_as_selected = function() {
+ unmark_as_selected() {
return this.node.find(".thumbnail").removeClass("selected");
- };
+ }
- ImagePickerOption.prototype.value = function() {
+ value() {
return this.option.val();
- };
+ }
- ImagePickerOption.prototype.label = function() {
+ label() {
if (this.option.data("img-label")) {
return this.option.data("img-label");
} else {
return this.option.text();
}
- };
+ }
- ImagePickerOption.prototype.clicked = function(event) {
+ clicked(event) {
this.picker.toggle(this, event);
if (this.opts.clicked != null) {
this.opts.clicked.call(this.picker.select, this, event);
@@ -271,11 +271,18 @@
if ((this.opts.selected != null) && this.is_selected()) {
return this.opts.selected.call(this.picker.select, this, event);
}
- };
+ }
- ImagePickerOption.prototype.create_node = function() {
+ dblclicked(event) {
+ if (this.opts.dblclicked != null) {
+ return this.opts.dblclicked.call(this.picker.select, this, event);
+ }
+ }
+
+ create_node() {
var image, imgAlt, imgClass, thumbnail;
this.node = jQuery("");
+ // font-awesome support
if (this.option.data("font_awesome")) {
image = jQuery("");
image.attr("class", "fa-fw " + this.option.data("img-src"));
@@ -284,27 +291,28 @@
image.attr("src", this.option.data("img-src"));
}
thumbnail = jQuery("");
+ // Add custom class
imgClass = this.option.data("img-class");
if (imgClass) {
this.node.addClass(imgClass);
image.addClass(imgClass);
thumbnail.addClass(imgClass);
}
+ // Add image alt
imgAlt = this.option.data("img-alt");
if (imgAlt) {
image.attr('alt', imgAlt);
}
thumbnail.on("click", this.clicked);
+ thumbnail.on("dblclick", this.dblclicked);
thumbnail.append(image);
if (this.opts.show_label) {
thumbnail.append(jQuery("
").html(this.label()));
}
this.node.append(thumbnail);
return this.node;
- };
-
- return ImagePickerOption;
+ }
- })();
+ };
}).call(this);
diff --git a/source/coffee/image-picker.coffee b/source/coffee/image-picker.coffee
index 1b08f65..606fbfe 100644
--- a/source/coffee/image-picker.coffee
+++ b/source/coffee/image-picker.coffee
@@ -18,6 +18,7 @@ sanitized_options = (opts) ->
initialized: undefined,
changed: undefined,
clicked: undefined,
+ dblclicked: undefined,
selected: undefined,
limit: undefined,
limit_reached: undefined,
@@ -125,6 +126,7 @@ class ImagePickerOption
destroy: ->
@node.find(".thumbnail").off("click", @clicked)
+ @node.find(".thumbnail").off("dblclick", @dblclicked)
has_image: () ->
@option.data("img-src")?
@@ -159,6 +161,9 @@ class ImagePickerOption
@opts.clicked.call(@picker.select, this, event) if @opts.clicked?
@opts.selected.call(@picker.select, this, event) if @opts.selected? and @is_selected()
+ dblclicked: (event) =>
+ @opts.dblclicked.call(@picker.select, this, event) if @opts.dblclicked?
+
create_node: () ->
@node = jQuery("
")
# font-awesome support
@@ -180,6 +185,7 @@ class ImagePickerOption
if imgAlt
image.attr('alt', imgAlt);
thumbnail.on("click", @clicked)
+ thumbnail.on("dblclick", @dblclicked)
thumbnail.append(image)
thumbnail.append(jQuery("
").html(@label())) if @opts.show_label
@node.append( thumbnail )