1
0
mirror of synced 2024-11-26 14:56:07 +03:00

Visibility of the search can be controlled

This commit is contained in:
Kevin Brown 2014-10-16 19:08:11 -04:00
parent 5b98f690c1
commit 5cf0dbf114
9 changed files with 138 additions and 28 deletions

View File

@ -253,15 +253,15 @@ define('select2/results',[
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on('results:all', function (data) { container.on('results:all', function (params) {
self.clear(); self.clear();
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
this.on('results:append', function (data) { container.on('results:append', function (params) {
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
@ -796,6 +796,7 @@ define('select2/dropdown/search',[
'</span>' '</span>'
); );
this.$searchContainer = $search;
this.$search = $search.find('input'); this.$search = $search.find('input');
$rendered.prepend($search); $rendered.prepend($search);
@ -804,6 +805,8 @@ define('select2/dropdown/search',[
}; };
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this;
decorated.call(this, container, $container); decorated.call(this, container, $container);
this.$search.on('keyup', function () { this.$search.on('keyup', function () {
@ -811,6 +814,22 @@ define('select2/dropdown/search',[
term: $(this).val() term: $(this).val()
}); });
}); });
container.on('results:all', function (params) {
if (params.query.term == null || params.query.term === '') {
var showSearch = self.showSearch(params);
if (showSearch) {
self.$searchContainer.show();
} else {
self.$searchContainer.hide();
}
}
});
};
Search.prototype.showSearch = function (params) {
return true;
}; };
return Search; return Search;
@ -1006,7 +1025,10 @@ define('select2/core',[
this.on('query', function (params) { this.on('query', function (params) {
this.data.query(params, function (data) { this.data.query(params, function (data) {
self.results.trigger('results:all', data); self.trigger('results:all', {
data: data,
query: params
});
}); });
}); });

View File

@ -253,15 +253,15 @@ define('select2/results',[
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on('results:all', function (data) { container.on('results:all', function (params) {
self.clear(); self.clear();
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
this.on('results:append', function (data) { container.on('results:append', function (params) {
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
@ -796,6 +796,7 @@ define('select2/dropdown/search',[
'</span>' '</span>'
); );
this.$searchContainer = $search;
this.$search = $search.find('input'); this.$search = $search.find('input');
$rendered.prepend($search); $rendered.prepend($search);
@ -804,6 +805,8 @@ define('select2/dropdown/search',[
}; };
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this;
decorated.call(this, container, $container); decorated.call(this, container, $container);
this.$search.on('keyup', function () { this.$search.on('keyup', function () {
@ -811,6 +814,22 @@ define('select2/dropdown/search',[
term: $(this).val() term: $(this).val()
}); });
}); });
container.on('results:all', function (params) {
if (params.query.term == null || params.query.term === '') {
var showSearch = self.showSearch(params);
if (showSearch) {
self.$searchContainer.show();
} else {
self.$searchContainer.hide();
}
}
});
};
Search.prototype.showSearch = function (params) {
return true;
}; };
return Search; return Search;
@ -1006,7 +1025,10 @@ define('select2/core',[
this.on('query', function (params) { this.on('query', function (params) {
this.data.query(params, function (data) { this.data.query(params, function (data) {
self.results.trigger('results:all', data); self.trigger('results:all', {
data: data,
query: params
});
}); });
}); });

View File

@ -9791,15 +9791,15 @@ define('select2/results',[
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on('results:all', function (data) { container.on('results:all', function (params) {
self.clear(); self.clear();
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
this.on('results:append', function (data) { container.on('results:append', function (params) {
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
@ -10334,6 +10334,7 @@ define('select2/dropdown/search',[
'</span>' '</span>'
); );
this.$searchContainer = $search;
this.$search = $search.find('input'); this.$search = $search.find('input');
$rendered.prepend($search); $rendered.prepend($search);
@ -10342,6 +10343,8 @@ define('select2/dropdown/search',[
}; };
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this;
decorated.call(this, container, $container); decorated.call(this, container, $container);
this.$search.on('keyup', function () { this.$search.on('keyup', function () {
@ -10349,6 +10352,22 @@ define('select2/dropdown/search',[
term: $(this).val() term: $(this).val()
}); });
}); });
container.on('results:all', function (params) {
if (params.query.term == null || params.query.term === '') {
var showSearch = self.showSearch(params);
if (showSearch) {
self.$searchContainer.show();
} else {
self.$searchContainer.hide();
}
}
});
};
Search.prototype.showSearch = function (params) {
return true;
}; };
return Search; return Search;
@ -10544,7 +10563,10 @@ define('select2/core',[
this.on('query', function (params) { this.on('query', function (params) {
this.data.query(params, function (data) { this.data.query(params, function (data) {
self.results.trigger('results:all', data); self.trigger('results:all', {
data: data,
query: params
});
}); });
}); });

File diff suppressed because one or more lines are too long

32
dist/js/select2.js vendored
View File

@ -682,15 +682,15 @@ define('select2/results',[
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on('results:all', function (data) { container.on('results:all', function (params) {
self.clear(); self.clear();
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
this.on('results:append', function (data) { container.on('results:append', function (params) {
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
@ -1225,6 +1225,7 @@ define('select2/dropdown/search',[
'</span>' '</span>'
); );
this.$searchContainer = $search;
this.$search = $search.find('input'); this.$search = $search.find('input');
$rendered.prepend($search); $rendered.prepend($search);
@ -1233,6 +1234,8 @@ define('select2/dropdown/search',[
}; };
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this;
decorated.call(this, container, $container); decorated.call(this, container, $container);
this.$search.on('keyup', function () { this.$search.on('keyup', function () {
@ -1240,6 +1243,22 @@ define('select2/dropdown/search',[
term: $(this).val() term: $(this).val()
}); });
}); });
container.on('results:all', function (params) {
if (params.query.term == null || params.query.term === '') {
var showSearch = self.showSearch(params);
if (showSearch) {
self.$searchContainer.show();
} else {
self.$searchContainer.hide();
}
}
});
};
Search.prototype.showSearch = function (params) {
return true;
}; };
return Search; return Search;
@ -1435,7 +1454,10 @@ define('select2/core',[
this.on('query', function (params) { this.on('query', function (params) {
this.data.query(params, function (data) { this.data.query(params, function (data) {
self.results.trigger('results:all', data); self.trigger('results:all', {
data: data,
query: params
});
}); });
}); });

File diff suppressed because one or more lines are too long

View File

@ -102,7 +102,10 @@ define([
this.on('query', function (params) { this.on('query', function (params) {
this.data.query(params, function (data) { this.data.query(params, function (data) {
self.results.trigger('results:all', data); self.trigger('results:all', {
data: data,
query: params
});
}); });
}); });

View File

@ -12,6 +12,7 @@ define([
'</span>' '</span>'
); );
this.$searchContainer = $search;
this.$search = $search.find('input'); this.$search = $search.find('input');
$rendered.prepend($search); $rendered.prepend($search);
@ -20,6 +21,8 @@ define([
}; };
Search.prototype.bind = function (decorated, container, $container) { Search.prototype.bind = function (decorated, container, $container) {
var self = this;
decorated.call(this, container, $container); decorated.call(this, container, $container);
this.$search.on('keyup', function () { this.$search.on('keyup', function () {
@ -27,6 +30,22 @@ define([
term: $(this).val() term: $(this).val()
}); });
}); });
container.on('results:all', function (params) {
if (params.query.term == null || params.query.term === '') {
var showSearch = self.showSearch(params);
if (showSearch) {
self.$searchContainer.show();
} else {
self.$searchContainer.hide();
}
}
});
};
Search.prototype.showSearch = function (params) {
return true;
}; };
return Search; return Search;

View File

@ -114,15 +114,15 @@ define([
Results.prototype.bind = function (container, $container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on('results:all', function (data) { container.on('results:all', function (params) {
self.clear(); self.clear();
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });
this.on('results:append', function (data) { container.on('results:append', function (params) {
self.append(data); self.append(params.data);
self.setClasses(); self.setClasses();
}); });