--- a/jquery.lensy.js Thu May 16 14:13:16 2013 +0900
+++ b/jquery.lensy.js Sat Nov 16 22:57:57 2013 +0900
function Lensy(element, options) {
this.$select = $(element);
this.settings = $.extend({}, $.fn.lensy.defaults, options);
this.$filter = $('<input>')
.addClass(this.settings.filterClass);
this.$filterWrap = $('<div>')
.addClass(this.settings.filterWrapClass)
this.$container = $('<ul>')
.addClass(this.settings.containerClass);
this.$closeButton = $('<a>')
.text(this.settings.closeButtonText)
.addClass(this.settings.closeButtonClass);
.addClass(this.settings.widgetClass)
.insertAfter(this.$select);
.addClass(this.settings.modalClass)
.append(this.$filterWrap)
.append(this.$closeButton)
createItem: function($option) {
var value = $option.val();
var text = $option.text();
.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');
.addClass(this.settings.itemClass)
.html((this.settings.widgetItemFn || this.settings.itemFn)(value, text, $option));
this.$container.find('[data-original-value]').each(function() {
var value = $item.attr('data-original-value');
var values = this.$select.val() || [];
this.$container.find('[data-original-value]').each(function() {
var value = $item.attr('data-original-value');
if (values.indexOf(value) == -1) {
$item.removeClass(self.settings.itemActiveClass);
$item.addClass(self.settings.itemActiveClass);
var $widgetItem = self.createWidgetItem($item);
self.$widget.append($widgetItem);
this.$widget.click($.proxy(this.show, this));
this.$closeButton.click($.proxy(this.hide, this));
// $item in $container gets clicked on
var itemSelected = function() {
var value = $item.attr('data-original-value');
var values = self.$select.val() || [];
if (values.indexOf(value) == -1) {
self.$select.val(values.concat(value));
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() {
$item.on('click', itemSelected);
self.$container.append($item);
this.$select.on('change', $.proxy(this.update, this));
this.$filter.on('change keyup', $.proxy(this.filter, this));
$.fn.lensy = function(options) {
return this.each(function() {
if (!$.data(this, 'lensy')) {
// escape action: close / clean filter
containerClass: 'lensy-container',