Skip to content

Commit

Permalink
release 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rvera committed Sep 25, 2016
1 parent bf797df commit e2c10a6
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 87 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Image Picker
# Image Picker 0.3.0

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.

Expand All @@ -9,3 +9,17 @@ Just download the latest build and add the corresponding .js and .css to your as
# Examples and doc

Visit http://rvera.github.com/image-picker

# What's new

0.3.0
----
- Enhancements:
- Bower support
- Easier group styling #53 (Thanks @kkalpakloglou!)
- Custom class to elements #44 (Thanks @poikilotherm!)
- Configure alt property for images #68 (Thanks @curtisgibby)
- Pass original events when firing custom events
- Fixed some bugs:
- #49
- #78 (Thanks @rdennis!)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4
0.3.0
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-picker",
"version": "0.2.4",
"version": "0.3.0",
"homepage": "http://rvera.github.com/image-picker",
"authors": [
"Rodrigo Vera"
Expand Down
153 changes: 83 additions & 70 deletions image-picker/image-picker.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Image Picker
// by Rodrigo Vera
//
// Version 0.2.4
// Version 0.3.0
// Full source at https://github.com/rvera/image-picker
// MIT License, https://github.com/rvera/image-picker/blob/master/LICENSE
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.11.0
(function() {
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; };
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; };

jQuery.fn.extend({
imagepicker: function(opts) {
Expand Down Expand Up @@ -45,15 +45,27 @@
};

both_array_are_equal = function(a, b) {
return jQuery(a).not(b).length === 0 && jQuery(b).not(a).length === 0;
var i, j, len, x;
if ((!a || !b) || (a.length !== b.length)) {
return false;
}
a = a.slice(0);
b = b.slice(0);
a.sort();
b.sort();
for (i = j = 0, len = a.length; j < len; i = ++j) {
x = a[i];
if (b[i] !== x) {
return false;
}
}
return true;
};

ImagePicker = (function() {

function ImagePicker(select_element, opts) {
this.opts = opts != null ? opts : {};
this.sync_picker_with_select = __bind(this.sync_picker_with_select, this);

function ImagePicker(select_element, opts1) {
this.opts = opts1 != null ? opts1 : {};
this.sync_picker_with_select = bind(this.sync_picker_with_select, this);
this.select = jQuery(select_element);
this.multiple = this.select.attr("multiple") === "multiple";
if (this.select.data("limit") != null) {
Expand All @@ -63,26 +75,23 @@
}

ImagePicker.prototype.destroy = function() {
var option, _i, _len, _ref;
_ref = this.picker_options;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
var j, len, option, ref;
ref = this.picker_options;
for (j = 0, len = ref.length; j < len; j++) {
option = ref[j];
option.destroy();
}
this.picker.remove();
this.select.unbind("change");
this.select.off("change", this.sync_picker_with_select);
this.select.removeData("picker");
return this.select.show();
};

ImagePicker.prototype.build_and_append_picker = function() {
var _this = this;
if (this.opts.hide_select) {
this.select.hide();
}
this.select.change(function() {
return _this.sync_picker_with_select();
});
this.select.on("change", this.sync_picker_with_select);
if (this.picker != null) {
this.picker.remove();
}
Expand All @@ -92,18 +101,18 @@
};

ImagePicker.prototype.sync_picker_with_select = function() {
var option, _i, _len, _ref, _results;
_ref = this.picker_options;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
var j, len, option, ref, results;
ref = this.picker_options;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
option = ref[j];
if (option.is_selected()) {
_results.push(option.mark_as_selected());
results.push(option.mark_as_selected());
} else {
_results.push(option.unmark_as_selected());
results.push(option.unmark_as_selected());
}
}
return _results;
return results;
};

ImagePicker.prototype.create_picker = function() {
Expand All @@ -114,51 +123,51 @@
};

ImagePicker.prototype.recursively_parse_option_groups = function(scoped_dom, target_container) {
var container, option, option_group, _i, _j, _len, _len1, _ref, _ref1, _results;
_ref = scoped_dom.children("optgroup");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option_group = _ref[_i];
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("<ul></ul>");
container.append(jQuery("<li class='group_title'>" + (option_group.attr("label")) + "</li>"));
target_container.append(jQuery("<li class='group'>").append(container));
this.recursively_parse_option_groups(option_group, container);
}
_ref1 = (function() {
var _k, _len1, _ref1, _results1;
_ref1 = scoped_dom.children("option");
_results1 = [];
for (_k = 0, _len1 = _ref1.length; _k < _len1; _k++) {
option = _ref1[_k];
_results1.push(new ImagePickerOption(option, this, this.opts));
ref1 = (function() {
var l, len1, ref1, results1;
ref1 = scoped_dom.children("option");
results1 = [];
for (l = 0, len1 = ref1.length; l < len1; l++) {
option = ref1[l];
results1.push(new ImagePickerOption(option, this, this.opts));
}
return _results1;
return results1;
}).call(this);
_results = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
option = _ref1[_j];
results = [];
for (k = 0, len1 = ref1.length; k < len1; k++) {
option = ref1[k];
this.picker_options.push(option);
if (!option.has_image()) {
continue;
}
_results.push(target_container.append(option.node));
results.push(target_container.append(option.node));
}
return _results;
return results;
};

ImagePicker.prototype.has_implicit_blanks = function() {
var option;
return ((function() {
var _i, _len, _ref, _results;
_ref = this.picker_options;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
var j, len, ref, results;
ref = this.picker_options;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
option = ref[j];
if (option.is_blank() && !option.has_image()) {
_results.push(option);
results.push(option);
}
}
return _results;
return results;
}).call(this)).length > 0;
};

Expand All @@ -170,12 +179,12 @@
}
};

ImagePicker.prototype.toggle = function(imagepicker_option) {
ImagePicker.prototype.toggle = function(imagepicker_option, original_event) {
var new_values, old_values, selected_value;
old_values = this.selected_values();
selected_value = imagepicker_option.value().toString();
if (this.multiple) {
if (__indexOf.call(this.selected_values(), selected_value) >= 0) {
if (indexOf.call(this.selected_values(), selected_value) >= 0) {
new_values = this.selected_values();
new_values.splice(jQuery.inArray(selected_value, old_values), 1);
this.select.val([]);
Expand All @@ -199,7 +208,7 @@
if (!both_array_are_equal(old_values, this.selected_values())) {
this.select.change();
if (this.opts.changed != null) {
return this.opts.changed.call(this.select, old_values, this.selected_values());
return this.opts.changed.call(this.select, old_values, this.selected_values(), original_event);
}
}
};
Expand All @@ -209,18 +218,16 @@
})();

ImagePickerOption = (function() {

function ImagePickerOption(option_element, picker, opts) {
function ImagePickerOption(option_element, picker, opts1) {
this.picker = picker;
this.opts = opts != null ? opts : {};
this.clicked = __bind(this.clicked, this);

this.opts = opts1 != null ? opts1 : {};
this.clicked = bind(this.clicked, this);
this.option = jQuery(option_element);
this.create_node();
}

ImagePickerOption.prototype.destroy = function() {
return this.node.find(".thumbnail").unbind();
return this.node.find(".thumbnail").off("click", this.clicked);
};

ImagePickerOption.prototype.has_image = function() {
Expand Down Expand Up @@ -261,27 +268,33 @@
}
};

ImagePickerOption.prototype.clicked = function() {
this.picker.toggle(this);
ImagePickerOption.prototype.clicked = function(event) {
this.picker.toggle(this, event);
if (this.opts.clicked != null) {
this.opts.clicked.call(this.picker.select, this);
this.opts.clicked.call(this.picker.select, this, event);
}
if ((this.opts.selected != null) && this.is_selected()) {
return this.opts.selected.call(this.picker.select, this);
return this.opts.selected.call(this.picker.select, this, event);
}
};

ImagePickerOption.prototype.create_node = function() {
var image, thumbnail;
var image, imgAlt, imgClass, thumbnail;
this.node = jQuery("<li/>");
image = jQuery("<img class='image_picker_image'/>");
image.attr("src", this.option.data("img-src"));
thumbnail = jQuery("<div class='thumbnail'>");
thumbnail.click({
option: this
}, function(event) {
return event.data.option.clicked();
});
imgClass = this.option.data("img-class");
if (imgClass) {
this.node.addClass(imgClass);
image.addClass(imgClass);
thumbnail.addClass(imgClass);
}
imgAlt = this.option.data("img-alt");
if (imgAlt) {
image.attr('alt', imgAlt);
}
thumbnail.on("click", this.clicked);
thumbnail.append(image);
if (this.opts.show_label) {
thumbnail.append(jQuery("<p/>").html(this.label()));
Expand Down
2 changes: 1 addition & 1 deletion image-picker/image-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e2c10a6

Please sign in to comment.