Download:
child 8:216800922816
parent 6:d98a02185a99
7:94520aac0370
Anton Shestakov <engored@ya.ru>, Sat, 16 Nov 2013 22:57:57 +0900
Trailing spaces.

1 файлов изменено, 29 вставок(+), 29 удалений(-) [+]
jquery.lensy.js file | annotate | diff | comparison | revisions
--- a/jquery.lensy.js Thu May 16 14:13:16 2013 +0900
+++ b/jquery.lensy.js Sat Nov 16 22:57:57 2013 +0900
@@ -1,35 +1,35 @@
(function($) {
"use strict";
-
+
function Lensy(element, options) {
this.$select = $(element);
this.settings = $.extend({}, $.fn.lensy.defaults, options);
-
+
this.build();
this.bindEvents();
}
-
+
Lensy.prototype = {
build: function() {
this.$filter = $('<input>')
.attr('type', 'text')
.addClass(this.settings.filterClass);
-
+
this.$filterWrap = $('<div>')
.addClass(this.settings.filterWrapClass)
.append(this.$filter);
this.$container = $('<ul>')
.addClass(this.settings.containerClass);
-
+
this.$closeButton = $('<a>')
.text(this.settings.closeButtonText)
.addClass(this.settings.closeButtonClass);
-
+
this.$widget = $('<ul>')
.addClass(this.settings.widgetClass)
.insertAfter(this.$select);
-
+
this.$modal = $('<div>')
.addClass(this.settings.modalClass)
.append(this.$filterWrap)
@@ -37,19 +37,19 @@
.append(this.$closeButton)
.appendTo('body')
.hide();
-
+
this.$select.hide();
},
-
+
show: function() {
this.$modal.show();
this.$filter.focus();
},
-
+
hide: function() {
this.$modal.hide();
},
-
+
createItem: function($option) {
var value = $option.val();
var text = $option.text();
@@ -61,7 +61,7 @@
.data('$option', $option)
.html(this.settings.itemFn(value, text, $option));
},
-
+
createWidgetItem: function($item) {
var value = $item.attr('data-original-value');
var text = $item.attr('data-original-text');
@@ -71,10 +71,10 @@
.addClass(this.settings.itemClass)
.html((this.settings.widgetItemFn || this.settings.itemFn)(value, text, $option));
},
-
+
filter: function() {
var self = this;
-
+
this.$container.find('[data-original-value]').each(function() {
var $item = $(this);
var value = $item.attr('data-original-value');
@@ -86,49 +86,49 @@
}
});
},
-
+
update: function() {
var self = this;
var values = this.$select.val() || [];
-
+
this.$widget.empty();
this.$container.find('[data-original-value]').each(function() {
var $item = $(this);
var value = $item.attr('data-original-value');
-
+
if (values.indexOf(value) == -1) {
$item.removeClass(self.settings.itemActiveClass);
} else {
$item.addClass(self.settings.itemActiveClass);
-
+
var $widgetItem = self.createWidgetItem($item);
self.$widget.append($widgetItem);
}
});
},
-
+
bindEvents: function() {
var self = this;
-
+
this.$widget.click($.proxy(this.show, this));
-
+
this.$closeButton.click($.proxy(this.hide, this));
-
+
// $item in $container gets clicked on
var itemSelected = function() {
var $item = $(this);
var value = $item.attr('data-original-value');
var values = self.$select.val() || [];
-
+
if (values.indexOf(value) == -1) {
self.$select.val(values.concat(value));
} else {
self.$select.val($.grep(values, function(v) { return v != value; }));
}
-
+
self.$select.trigger('change');
};
-
+
// $container is populated with $items
this.$select.find('option').each(function() {
var $option = $(this);
@@ -136,14 +136,14 @@
$item.on('click', itemSelected);
self.$container.append($item);
});
-
+
this.$select.on('change', $.proxy(this.update, this));
this.update();
-
+
this.$filter.on('change keyup', $.proxy(this.filter, this));
}
};
-
+
$.fn.lensy = function(options) {
return this.each(function() {
if (!$.data(this, 'lensy')) {
@@ -151,7 +151,7 @@
}
});
};
-
+
$.fn.lensy.defaults = {
// escape action: close / clean filter
containerClass: 'lensy-container',