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

Added basic templating to results

This commit is contained in:
Kevin Brown 2014-11-01 21:57:14 -04:00
parent be4d091451
commit a3fa516761
9 changed files with 69 additions and 18 deletions

View File

@ -264,7 +264,7 @@ define('select2/results',[
.removeAttr('aria-selected');
var $label = $('<strong class="group-label"></strong>');
$label.html(data.text);
this.template(data, $label);
var $children = [];
@ -283,7 +283,7 @@ define('select2/results',[
$option.append($label);
$option.append($childrenContainer);
} else {
$option.html(data.text);
this.template(data, $option);
}
if (data.disabled) {
@ -513,6 +513,12 @@ define('select2/results',[
}
};
Results.prototype.template = function (result, $container) {
var template = this.options.get('templateResult');
$container.html(template(result));
};
return Results;
});
@ -1616,7 +1622,10 @@ define('select2/defaults',[
Defaults.prototype.reset = function () {
this.defaults = {
language: ['select2/i18n/en']
language: ['select2/i18n/en'],
templateResult: function (result) {
return result.text;
}
};
};

View File

@ -264,7 +264,7 @@ define('select2/results',[
.removeAttr('aria-selected');
var $label = $('<strong class="group-label"></strong>');
$label.html(data.text);
this.template(data, $label);
var $children = [];
@ -283,7 +283,7 @@ define('select2/results',[
$option.append($label);
$option.append($childrenContainer);
} else {
$option.html(data.text);
this.template(data, $option);
}
if (data.disabled) {
@ -513,6 +513,12 @@ define('select2/results',[
}
};
Results.prototype.template = function (result, $container) {
var template = this.options.get('templateResult');
$container.html(template(result));
};
return Results;
});
@ -1616,7 +1622,10 @@ define('select2/defaults',[
Defaults.prototype.reset = function () {
this.defaults = {
language: ['select2/i18n/en']
language: ['select2/i18n/en'],
templateResult: function (result) {
return result.text;
}
};
};

View File

@ -9799,7 +9799,7 @@ define('select2/results',[
.removeAttr('aria-selected');
var $label = $('<strong class="group-label"></strong>');
$label.html(data.text);
this.template(data, $label);
var $children = [];
@ -9818,7 +9818,7 @@ define('select2/results',[
$option.append($label);
$option.append($childrenContainer);
} else {
$option.html(data.text);
this.template(data, $option);
}
if (data.disabled) {
@ -10048,6 +10048,12 @@ define('select2/results',[
}
};
Results.prototype.template = function (result, $container) {
var template = this.options.get('templateResult');
$container.html(template(result));
};
return Results;
});
@ -11151,7 +11157,10 @@ define('select2/defaults',[
Defaults.prototype.reset = function () {
this.defaults = {
language: ['select2/i18n/en']
language: ['select2/i18n/en'],
templateResult: function (result) {
return result.text;
}
};
};

File diff suppressed because one or more lines are too long

15
dist/js/select2.js vendored
View File

@ -692,7 +692,7 @@ define('select2/results',[
.removeAttr('aria-selected');
var $label = $('<strong class="group-label"></strong>');
$label.html(data.text);
this.template(data, $label);
var $children = [];
@ -711,7 +711,7 @@ define('select2/results',[
$option.append($label);
$option.append($childrenContainer);
} else {
$option.html(data.text);
this.template(data, $option);
}
if (data.disabled) {
@ -941,6 +941,12 @@ define('select2/results',[
}
};
Results.prototype.template = function (result, $container) {
var template = this.options.get('templateResult');
$container.html(template(result));
};
return Results;
});
@ -2044,7 +2050,10 @@ define('select2/defaults',[
Defaults.prototype.reset = function () {
this.defaults = {
language: ['select2/i18n/en']
language: ['select2/i18n/en'],
templateResult: function (result) {
return result.text;
}
};
};

File diff suppressed because one or more lines are too long

View File

@ -462,6 +462,12 @@ $.fn.select2.amd.require(["select2/core", "select2/utils"], function (Select2, U
return data.items;
},
cache: true
},
templateResult: function (repo) {
return repo.full_name;
},
templateSelection: function (repo) {
return repo.full_name;
}
});

View File

@ -113,7 +113,10 @@ define([
Defaults.prototype.reset = function () {
this.defaults = {
language: ['select2/i18n/en']
language: ['select2/i18n/en'],
templateResult: function (result) {
return result.text;
}
};
};

View File

@ -110,7 +110,7 @@ define([
.removeAttr('aria-selected');
var $label = $('<strong class="group-label"></strong>');
$label.html(data.text);
this.template(data, $label);
var $children = [];
@ -129,7 +129,7 @@ define([
$option.append($label);
$option.append($childrenContainer);
} else {
$option.html(data.text);
this.template(data, $option);
}
if (data.disabled) {
@ -359,5 +359,11 @@ define([
}
};
Results.prototype.template = function (result, $container) {
var template = this.options.get('templateResult');
$container.html(template(result));
};
return Results;
});