diff --git a/.jshintrc b/.jshintrc index f0d9966b5e..026666ad5f 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,5 +1,6 @@ { "bitwise": true, + "eqnull": true, "globals": { "define": true }, diff --git a/src/js/select2/core.js b/src/js/select2/core.js index e389db0774..681847ed6a 100644 --- a/src/js/select2/core.js +++ b/src/js/select2/core.js @@ -8,7 +8,7 @@ define([ options = options || {}; - options.multiple = options.multiple || $element.prop("multiple"); + options.multiple = options.multiple || $element.prop('multiple'); this.options = new Options(options); @@ -27,21 +27,22 @@ define([ this.selection = new this.options.selectionAdapter($element, this.options); - var $selectionContainer = $container.find(".selection"); + var $selectionContainer = $container.find('.selection'); var $selection = this.selection.render(); $selectionContainer.append($selection); this.dropdown = new this.options.dropdownAdapter($element, this.options); - var $dropdownContainer = $container.find(".dropdown"); + var $dropdownContainer = $container.find('.dropdown'); var $dropdown = this.dropdown.render(); $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(); $resultsContainer.append($results); @@ -54,48 +55,48 @@ define([ this.selection.bind(this, $container); this.results.bind(this, $container); - this.$element.on("change", function () { + this.$element.on('change', function () { self.data.current(function (data) { - self.trigger("selection:update", { + self.trigger('selection:update', { data: data }); }); }); - this.selection.on("toggle", function () { + this.selection.on('toggle', function () { self.toggleDropdown(); }); - this.results.on("selected", function (params) { - self.trigger("select", params); + this.results.on('selected', function (params) { + self.trigger('select', params); - self.trigger("close"); + self.trigger('close'); }); - this.results.on("unselected", function (params) { - self.trigger("unselect", params); + this.results.on('unselected', function (params) { + self.trigger('unselect', params); - self.trigger("close"); + self.trigger('close'); }); - this.on("open", function () { - $container.addClass("open"); + this.on('open', function () { + $container.addClass('open'); }); - this.on("close", function () { - $container.removeClass("open"); + this.on('close', function () { + $container.removeClass('open'); }); // Set the initial state this.data.current(function (initialData) { - self.trigger("selection:update", { + self.trigger('selection:update', { data: initialData }); }); this.data.query({}, function (data) { - self.results.trigger("results:all", data); + self.results.trigger('results:all', data); }); // Hide the original select @@ -106,12 +107,12 @@ define([ Utils.Extend(Select2, Utils.Observable); Select2.prototype.toggleDropdown = function () { - if (this.$container.hasClass("open")) { - this.trigger("close"); + if (this.$container.hasClass('open')) { + this.trigger('close'); } else { - this.trigger("open"); + this.trigger('open'); } - } + }; Select2.prototype.render = function () { var $container = $( diff --git a/src/js/select2/dropdown.js b/src/js/select2/dropdown.js index 9897f7d1d5..75ce39af40 100644 --- a/src/js/select2/dropdown.js +++ b/src/js/select2/dropdown.js @@ -15,7 +15,7 @@ define([ ); return $dropdown; - } + }; return Dropdown; -}) +}); diff --git a/src/js/select2/options.js b/src/js/select2/options.js index 4cfb485809..249f7de719 100644 --- a/src/js/select2/options.js +++ b/src/js/select2/options.js @@ -27,4 +27,4 @@ define([ } return Options; -}) +}); diff --git a/src/js/select2/results.js b/src/js/select2/results.js index b25747d4ac..7c81cef473 100644 --- a/src/js/select2/results.js +++ b/src/js/select2/results.js @@ -44,16 +44,16 @@ define([ this.data.current(function (selected) { 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 () { var $option = $(this); - var item = $option.data("data"); + var item = $option.data('data'); if (selected.indexOf(item.id) > -1) { - $option.addClass("selected"); + $option.addClass('selected'); } }); }); @@ -65,43 +65,43 @@ define([ ); $option.html(data.text); - $option.data("data", data); + $option.data('data', data); return $option; - } + }; Results.prototype.bind = function (container, $container) { var self = this; - this.on("results:all", function (data) { + this.on('results:all', function (data) { self.clear(); self.append(data); self.setClasses(); }); - this.on("results:append", function (data) { + this.on('results:append', function (data) { self.append(data); self.setClasses(); - }) + }); - this.$results.on("mouseup", ".option", function (evt) { + this.$results.on('mouseup', '.option', function (evt) { var $this = $(this); - var data = $this.data("data"); - if ($this.hasClass("selected")) { - self.trigger("unselected", { + var data = $this.data('data'); + if ($this.hasClass('selected')) { + self.trigger('unselected', { originalEvent: evt, data: data - }) + }); self.setClasses(); return; } - self.trigger("selected", { + self.trigger('selected', { originalEvent: evt, data: data }); @@ -109,15 +109,15 @@ define([ self.setClasses(); }); - this.$results.on("mouseenter", ".option", function (evt) { - self.$results.find(".option.highlighted").removeClass("highlighted"); - $(this).addClass("highlighted"); + this.$results.on('mouseenter', '.option', function (evt) { + self.$results.find('.option.highlighted').removeClass('highlighted'); + $(this).addClass('highlighted'); }); - this.$results.on("mouseleave", ".option", function (evt) { - $(this).removeClass("highlighted"); + this.$results.on('mouseleave', '.option', function (evt) { + $(this).removeClass('highlighted'); }); }; return Results; -}) +});