1
0
mirror of synced 2024-11-22 13:06:08 +03:00

Small changes in preparation for more adapters

This commit is contained in:
Kevin Brown 2014-08-30 19:32:29 -04:00
parent d57f8b2203
commit 3e05e32eda
9 changed files with 105 additions and 40 deletions

View File

@ -245,10 +245,17 @@ define('select2/data/select',[
};
SelectAdapter.prototype.item = function ($option) {
var data = {
id: $option.val(),
text: $option.html()
};
var data = $option.data("data");
// If the data has already be generated, use it
if (data == null) {
data = {
id: $option.val(),
text: $option.html()
};
$option.data("data", data);
}
return data;
};
@ -356,7 +363,7 @@ define('select2/results',[
self.setClasses();
})
this.$results.on("click", ".option", function (evt) {
this.$results.on("mouseup", ".option", function (evt) {
var $this = $(this);
var data = $this.data("data");
@ -441,7 +448,7 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
this.$selection.on('click', function (evt) {
this.$selection.on('mousedown', function (evt) {
self.trigger("toggle", {
originalEvent: evt
});
@ -561,7 +568,7 @@ define('select2/options',[
function Options (options) {
this.options = options;
this.dataAdapter = SelectData;
this.dataAdapter = options.dataAdapter || SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
@ -660,12 +667,18 @@ define('select2/core',[
// Set the initial state
this.data.current(function (initialData) {
self.selection.update(initialData);
self.trigger("selection:update", {
data: initialData
});
});
this.data.query({}, function (data) {
self.results.trigger("results:all", data);
});
// Hide the original select
$element.hide();
};
Utils.Extend(Select2, Utils.Observable);

View File

@ -245,10 +245,17 @@ define('select2/data/select',[
};
SelectAdapter.prototype.item = function ($option) {
var data = {
id: $option.val(),
text: $option.html()
};
var data = $option.data("data");
// If the data has already be generated, use it
if (data == null) {
data = {
id: $option.val(),
text: $option.html()
};
$option.data("data", data);
}
return data;
};
@ -356,7 +363,7 @@ define('select2/results',[
self.setClasses();
})
this.$results.on("click", ".option", function (evt) {
this.$results.on("mouseup", ".option", function (evt) {
var $this = $(this);
var data = $this.data("data");
@ -441,7 +448,7 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
this.$selection.on('click', function (evt) {
this.$selection.on('mousedown', function (evt) {
self.trigger("toggle", {
originalEvent: evt
});
@ -561,7 +568,7 @@ define('select2/options',[
function Options (options) {
this.options = options;
this.dataAdapter = SelectData;
this.dataAdapter = options.dataAdapter || SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
@ -660,12 +667,18 @@ define('select2/core',[
// Set the initial state
this.data.current(function (initialData) {
self.selection.update(initialData);
self.trigger("selection:update", {
data: initialData
});
});
this.data.query({}, function (data) {
self.results.trigger("results:all", data);
});
// Hide the original select
$element.hide();
};
Utils.Extend(Select2, Utils.Observable);

View File

@ -9782,10 +9782,17 @@ define('select2/data/select',[
};
SelectAdapter.prototype.item = function ($option) {
var data = {
id: $option.val(),
text: $option.html()
};
var data = $option.data("data");
// If the data has already be generated, use it
if (data == null) {
data = {
id: $option.val(),
text: $option.html()
};
$option.data("data", data);
}
return data;
};
@ -9893,7 +9900,7 @@ define('select2/results',[
self.setClasses();
})
this.$results.on("click", ".option", function (evt) {
this.$results.on("mouseup", ".option", function (evt) {
var $this = $(this);
var data = $this.data("data");
@ -9978,7 +9985,7 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
this.$selection.on('click', function (evt) {
this.$selection.on('mousedown', function (evt) {
self.trigger("toggle", {
originalEvent: evt
});
@ -10098,7 +10105,7 @@ define('select2/options',[
function Options (options) {
this.options = options;
this.dataAdapter = SelectData;
this.dataAdapter = options.dataAdapter || SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
@ -10197,12 +10204,18 @@ define('select2/core',[
// Set the initial state
this.data.current(function (initialData) {
self.selection.update(initialData);
self.trigger("selection:update", {
data: initialData
});
});
this.data.query({}, function (data) {
self.results.trigger("results:all", data);
});
// Hide the original select
$element.hide();
};
Utils.Extend(Select2, Utils.Observable);

29
dist/js/select2.js vendored
View File

@ -673,10 +673,17 @@ define('select2/data/select',[
};
SelectAdapter.prototype.item = function ($option) {
var data = {
id: $option.val(),
text: $option.html()
};
var data = $option.data("data");
// If the data has already be generated, use it
if (data == null) {
data = {
id: $option.val(),
text: $option.html()
};
$option.data("data", data);
}
return data;
};
@ -784,7 +791,7 @@ define('select2/results',[
self.setClasses();
})
this.$results.on("click", ".option", function (evt) {
this.$results.on("mouseup", ".option", function (evt) {
var $this = $(this);
var data = $this.data("data");
@ -869,7 +876,7 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
this.$selection.on('click', function (evt) {
this.$selection.on('mousedown', function (evt) {
self.trigger("toggle", {
originalEvent: evt
});
@ -989,7 +996,7 @@ define('select2/options',[
function Options (options) {
this.options = options;
this.dataAdapter = SelectData;
this.dataAdapter = options.dataAdapter || SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
@ -1088,12 +1095,18 @@ define('select2/core',[
// Set the initial state
this.data.current(function (initialData) {
self.selection.update(initialData);
self.trigger("selection:update", {
data: initialData
});
});
this.data.query({}, function (data) {
self.results.trigger("results:all", data);
});
// Hide the original select
$element.hide();
};
Utils.Extend(Select2, Utils.Observable);

View File

@ -80,12 +80,18 @@ define([
// Set the initial state
this.data.current(function (initialData) {
self.selection.update(initialData);
self.trigger("selection:update", {
data: initialData
});
});
this.data.query({}, function (data) {
self.results.trigger("results:all", data);
});
// Hide the original select
$element.hide();
};
Utils.Extend(Select2, Utils.Observable);

View File

@ -107,10 +107,17 @@ define([
};
SelectAdapter.prototype.item = function ($option) {
var data = {
id: $option.val(),
text: $option.html()
};
var data = $option.data("data");
// If the data has already be generated, use it
if (data == null) {
data = {
id: $option.val(),
text: $option.html()
};
$option.data("data", data);
}
return data;
};

View File

@ -9,7 +9,7 @@ define([
function Options (options) {
this.options = options;
this.dataAdapter = SelectData;
this.dataAdapter = options.dataAdapter || SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;

View File

@ -86,7 +86,7 @@ define([
self.setClasses();
})
this.$results.on("click", ".option", function (evt) {
this.$results.on("mouseup", ".option", function (evt) {
var $this = $(this);
var data = $this.data("data");

View File

@ -25,7 +25,7 @@ define([
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
this.$selection.on('click', function (evt) {
this.$selection.on('mousedown', function (evt) {
self.trigger("toggle", {
originalEvent: evt
});