1
0
mirror of synced 2025-02-09 16:49:24 +03:00

Linted select2/data/* and select2/dropdown/*

This commit is contained in:
Kevin Brown 2014-09-21 16:04:53 -04:00
parent 981432ee89
commit f0b819336a
5 changed files with 39 additions and 41 deletions

View File

@ -1,14 +1,14 @@
define([
"./array",
"../utils",
"jquery"
'./array',
'../utils',
'jquery'
], function (ArrayAdapter, Utils, $) {
function AjaxAdapter ($element, options) {
this.ajaxOptions = options.options.ajax;
this.processResults = this.ajaxOptions.processResults ||
function (results) {
return results
return results;
};
ArrayAdapter.__super__.constructor.call(this, $element, options);
@ -21,14 +21,14 @@ define([
var self = this;
var options = $.extend({
type: "GET",
type: 'GET',
}, this.ajaxOptions);
if (typeof options.url === "function") {
if (typeof options.url === 'function') {
options.url = options.url(params);
}
if (typeof options.data === "function") {
if (typeof options.data === 'function') {
options.data = options.data(params);
}
@ -37,8 +37,6 @@ define([
$request.success(function (data) {
var results = self.processResults(data);
console.log(results)
callback(results);
});
};

View File

@ -1,6 +1,6 @@
define([
"./select",
"../utils"
'./select',
'../utils'
], function (SelectAdapter, Utils) {
function ArrayAdapter ($element, options) {
this.data = options.options.data;
@ -13,7 +13,7 @@ define([
ArrayAdapter.prototype.select = function (data) {
var self = this;
this.$element.find("option").each(function () {
this.$element.find('option').each(function () {
var $option = $(this);
var option = self.item($option);
@ -27,17 +27,17 @@ define([
this.$element.append($option);
ArrayAdapter.__super__.select.call(this, data);
}
};
ArrayAdapter.prototype.option = function (data) {
var $option = $("<option></option>");
var $option = $('<option></option>');
$option.text(data.text);
$option.val(data.id);
$option.data("data", data);
$option.data('data', data);
return $option;
}
};
ArrayAdapter.prototype.query = function (params, callback) {
var matches = [];
@ -52,7 +52,7 @@ define([
});
callback(matches);
}
};
return ArrayAdapter;
});

View File

@ -8,12 +8,12 @@ define([
Utils.Extend(BaseAdapter, Utils.Observable);
BaseAdapter.prototype.current = function (callback) {
throw new Error("The `current` method must be defined in child classes.");
}
throw new Error('The `current` method must be defined in child classes.');
};
BaseAdapter.prototype.query = function (params, callback) {
throw new Error("The `query` method must be defined in child classes.");
}
throw new Error('The `query` method must be defined in child classes.');
};
return BaseAdapter;
});

View File

@ -15,7 +15,7 @@ define([
var data = [];
var self = this;
this.$element.find(":selected").each(function () {
this.$element.find(':selected').each(function () {
var $option = $(this);
var option = self.item($option);
@ -29,7 +29,7 @@ define([
SelectAdapter.prototype.select = function (data) {
var self = this;
if (this.$element.prop("multiple")) {
if (this.$element.prop('multiple')) {
this.current(function (currentData) {
var val = [];
@ -45,20 +45,20 @@ define([
}
self.$element.val(val);
self.$element.trigger("change");
self.$element.trigger('change');
});
} else {
var val = data.id;
this.$element.val(val);
this.$element.trigger("change");
this.$element.trigger('change');
}
};
SelectAdapter.prototype.unselect = function (data) {
var self = this;
if (!this.$element.prop("multiple")) {
if (!this.$element.prop('multiple')) {
return;
}
@ -74,27 +74,27 @@ define([
}
self.$element.val(val);
self.$element.trigger("change");
self.$element.trigger('change');
});
}
};
SelectAdapter.prototype.bind = function (container, $container) {
var self = this;
container.on("select", function (params) {
container.on('select', function (params) {
self.select(params.data);
});
container.on("unselect", function (params) {
container.on('unselect', function (params) {
self.unselect(params.data);
});
}
};
SelectAdapter.prototype.query = function (params, callback) {
var data = [];
var self = this;
this.$element.find("option").each(function () {
this.$element.find('option').each(function () {
var $option = $(this);
var option = self.item($option);
@ -108,7 +108,7 @@ define([
};
SelectAdapter.prototype.item = function ($option) {
var data = $option.data("data");
var data = $option.data('data');
// If the data has already be generated, use it
if (data == null) {
@ -117,14 +117,14 @@ define([
text: $option.html()
};
$option.data("data", data);
$option.data('data', data);
}
return data;
};
SelectAdapter.prototype.matches = function (params, data) {
if ($.trim(params.term) == "") {
if ($.trim(params.term) === '') {
return true;
}
@ -133,7 +133,7 @@ define([
}
return false;
}
};
return SelectAdapter;
});

View File

@ -1,15 +1,15 @@
define([
"../utils"
'../utils'
], function (Utils) {
function Search (decorated, arguments) {
decorated.call(this, arguments);
function Search (decorated, args) {
decorated.call(this, args);
}
Utils.Extend(Search, Utils.Observable);
Search.prototype.bind = function (decorated, arguments) {
Search.prototype.bind = function (decorated, args) {
this.$container = $container;
}
};
return Search;
});