1
0
mirror of synced 2025-02-10 17:19:23 +03:00

More linting on select2/*

This commit is contained in:
Kevin Brown 2014-09-21 16:00:03 -04:00
parent f0e3968989
commit 981432ee89
5 changed files with 50 additions and 48 deletions

View File

@ -1,5 +1,6 @@
{ {
"bitwise": true, "bitwise": true,
"eqnull": true,
"globals": { "globals": {
"define": true "define": true
}, },

View File

@ -8,7 +8,7 @@ define([
options = options || {}; options = options || {};
options.multiple = options.multiple || $element.prop("multiple"); options.multiple = options.multiple || $element.prop('multiple');
this.options = new Options(options); this.options = new Options(options);
@ -27,21 +27,22 @@ define([
this.selection = new this.options.selectionAdapter($element, this.options); this.selection = new this.options.selectionAdapter($element, this.options);
var $selectionContainer = $container.find(".selection"); var $selectionContainer = $container.find('.selection');
var $selection = this.selection.render(); var $selection = this.selection.render();
$selectionContainer.append($selection); $selectionContainer.append($selection);
this.dropdown = new this.options.dropdownAdapter($element, this.options); this.dropdown = new this.options.dropdownAdapter($element, this.options);
var $dropdownContainer = $container.find(".dropdown"); var $dropdownContainer = $container.find('.dropdown');
var $dropdown = this.dropdown.render(); var $dropdown = this.dropdown.render();
$dropdownContainer.append($dropdown); $dropdownContainer.append($dropdown);
this.results = new this.options.resultsAdapter($element, this.options, this.data); this.results = new this.options.resultsAdapter(
$element, this.options, this.data);
var $resultsContainer = $dropdown.find(".results"); var $resultsContainer = $dropdown.find('.results');
var $results = this.results.render(); var $results = this.results.render();
$resultsContainer.append($results); $resultsContainer.append($results);
@ -54,48 +55,48 @@ define([
this.selection.bind(this, $container); this.selection.bind(this, $container);
this.results.bind(this, $container); this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on('change', function () {
self.data.current(function (data) { self.data.current(function (data) {
self.trigger("selection:update", { self.trigger('selection:update', {
data: data data: data
}); });
}); });
}); });
this.selection.on("toggle", function () { this.selection.on('toggle', function () {
self.toggleDropdown(); self.toggleDropdown();
}); });
this.results.on("selected", function (params) { this.results.on('selected', function (params) {
self.trigger("select", params); self.trigger('select', params);
self.trigger("close"); self.trigger('close');
}); });
this.results.on("unselected", function (params) { this.results.on('unselected', function (params) {
self.trigger("unselect", params); self.trigger('unselect', params);
self.trigger("close"); self.trigger('close');
}); });
this.on("open", function () { this.on('open', function () {
$container.addClass("open"); $container.addClass('open');
}); });
this.on("close", function () { this.on('close', function () {
$container.removeClass("open"); $container.removeClass('open');
}); });
// Set the initial state // Set the initial state
this.data.current(function (initialData) { this.data.current(function (initialData) {
self.trigger("selection:update", { self.trigger('selection:update', {
data: initialData data: initialData
}); });
}); });
this.data.query({}, function (data) { this.data.query({}, function (data) {
self.results.trigger("results:all", data); self.results.trigger('results:all', data);
}); });
// Hide the original select // Hide the original select
@ -106,12 +107,12 @@ define([
Utils.Extend(Select2, Utils.Observable); Utils.Extend(Select2, Utils.Observable);
Select2.prototype.toggleDropdown = function () { Select2.prototype.toggleDropdown = function () {
if (this.$container.hasClass("open")) { if (this.$container.hasClass('open')) {
this.trigger("close"); this.trigger('close');
} else { } else {
this.trigger("open"); this.trigger('open');
}
} }
};
Select2.prototype.render = function () { Select2.prototype.render = function () {
var $container = $( var $container = $(

View File

@ -15,7 +15,7 @@ define([
); );
return $dropdown; return $dropdown;
} };
return Dropdown; return Dropdown;
}) });

View File

@ -27,4 +27,4 @@ define([
} }
return Options; return Options;
}) });

View File

@ -44,16 +44,16 @@ define([
this.data.current(function (selected) { this.data.current(function (selected) {
selected = $.map(selected, function (s) { return s.id; }); selected = $.map(selected, function (s) { return s.id; });
self.$results.find(".option.selected").removeClass("selected"); self.$results.find('.option.selected').removeClass('selected');
var $options = self.$results.find(".option"); var $options = self.$results.find('.option');
$options.each(function () { $options.each(function () {
var $option = $(this); var $option = $(this);
var item = $option.data("data"); var item = $option.data('data');
if (selected.indexOf(item.id) > -1) { if (selected.indexOf(item.id) > -1) {
$option.addClass("selected"); $option.addClass('selected');
} }
}); });
}); });
@ -65,43 +65,43 @@ define([
); );
$option.html(data.text); $option.html(data.text);
$option.data("data", data); $option.data('data', data);
return $option; return $option;
} };
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on('results:all', function (data) {
self.clear(); self.clear();
self.append(data); self.append(data);
self.setClasses(); self.setClasses();
}); });
this.on("results:append", function (data) { this.on('results:append', function (data) {
self.append(data); self.append(data);
self.setClasses(); self.setClasses();
}) });
this.$results.on("mouseup", ".option", function (evt) { this.$results.on('mouseup', '.option', function (evt) {
var $this = $(this); var $this = $(this);
var data = $this.data("data"); var data = $this.data('data');
if ($this.hasClass("selected")) { if ($this.hasClass('selected')) {
self.trigger("unselected", { self.trigger('unselected', {
originalEvent: evt, originalEvent: evt,
data: data data: data
}) });
self.setClasses(); self.setClasses();
return; return;
} }
self.trigger("selected", { self.trigger('selected', {
originalEvent: evt, originalEvent: evt,
data: data data: data
}); });
@ -109,15 +109,15 @@ define([
self.setClasses(); self.setClasses();
}); });
this.$results.on("mouseenter", ".option", function (evt) { this.$results.on('mouseenter', '.option', function (evt) {
self.$results.find(".option.highlighted").removeClass("highlighted"); self.$results.find('.option.highlighted').removeClass('highlighted');
$(this).addClass("highlighted"); $(this).addClass('highlighted');
}); });
this.$results.on("mouseleave", ".option", function (evt) { this.$results.on('mouseleave', '.option', function (evt) {
$(this).removeClass("highlighted"); $(this).removeClass('highlighted');
}); });
}; };
return Results; return Results;
}) });