Skip to content

Commit

Permalink
More linting on select2/*
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-brown committed Oct 22, 2014
1 parent f0e3968 commit 981432e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"bitwise": true,
"eqnull": true,
"globals": {
"define": true
},
Expand Down
49 changes: 25 additions & 24 deletions src/js/select2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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 = $(
Expand Down
4 changes: 2 additions & 2 deletions src/js/select2/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define([
);

return $dropdown;
}
};

return Dropdown;
})
});
2 changes: 1 addition & 1 deletion src/js/select2/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ define([
}

return Options;
})
});
42 changes: 21 additions & 21 deletions src/js/select2/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});
Expand All @@ -65,59 +65,59 @@ 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
});

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;
})
});

0 comments on commit 981432e

Please sign in to comment.