Browse Source

Templating for selections

Kevin Brown 10 years ago
parent
commit
8b7924fc72

+ 9 - 2
dist/js/select2.amd.full.js

@@ -711,7 +711,9 @@ define('select2/selection/single',[
   };
 
   SingleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   SingleSelection.prototype.selectionContainer = function () {
@@ -788,7 +790,9 @@ define('select2/selection/multiple',[
   };
 
   MultipleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   MultipleSelection.prototype.selectionContainer = function () {
@@ -1625,6 +1629,9 @@ define('select2/defaults',[
       language: ['select2/i18n/en'],
       templateResult: function (result) {
         return result.text;
+      },
+      templateSelection: function (selection) {
+        return selection.text;
       }
     };
   };

+ 9 - 2
dist/js/select2.amd.js

@@ -711,7 +711,9 @@ define('select2/selection/single',[
   };
 
   SingleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   SingleSelection.prototype.selectionContainer = function () {
@@ -788,7 +790,9 @@ define('select2/selection/multiple',[
   };
 
   MultipleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   MultipleSelection.prototype.selectionContainer = function () {
@@ -1625,6 +1629,9 @@ define('select2/defaults',[
       language: ['select2/i18n/en'],
       templateResult: function (result) {
         return result.text;
+      },
+      templateSelection: function (selection) {
+        return selection.text;
       }
     };
   };

+ 9 - 2
dist/js/select2.full.js

@@ -10246,7 +10246,9 @@ define('select2/selection/single',[
   };
 
   SingleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   SingleSelection.prototype.selectionContainer = function () {
@@ -10323,7 +10325,9 @@ define('select2/selection/multiple',[
   };
 
   MultipleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   MultipleSelection.prototype.selectionContainer = function () {
@@ -11160,6 +11164,9 @@ define('select2/defaults',[
       language: ['select2/i18n/en'],
       templateResult: function (result) {
         return result.text;
+      },
+      templateSelection: function (selection) {
+        return selection.text;
       }
     };
   };

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.full.min.js


+ 9 - 2
dist/js/select2.js

@@ -1139,7 +1139,9 @@ define('select2/selection/single',[
   };
 
   SingleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   SingleSelection.prototype.selectionContainer = function () {
@@ -1216,7 +1218,9 @@ define('select2/selection/multiple',[
   };
 
   MultipleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   MultipleSelection.prototype.selectionContainer = function () {
@@ -2053,6 +2057,9 @@ define('select2/defaults',[
       language: ['select2/i18n/en'],
       templateResult: function (result) {
         return result.text;
+      },
+      templateSelection: function (selection) {
+        return selection.text;
       }
     };
   };

File diff suppressed because it is too large
+ 0 - 0
dist/js/select2.min.js


+ 9 - 7
docs/examples.html

@@ -465,13 +465,15 @@ $.fn.select2.amd.require(["select2/core", "select2/utils"], function (Select2, U
     },
     templateResult: function (repo) {
       var markup = '<div class="row">' +
-         '<div class="col-sm-1"><img src="' + repo.owner.avatar_url + '" style="max-width: 100%" /></div>' +
-         '<div class="col-sm-11">' +
-            '<div class="row">' +
-               '<div class="col-sm-6">' + repo.full_name + '</div>' +
-               '<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
-               '<div class="col-sm-3"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
-            '</div>';
+        '<div class="col-sm-1">' +
+          '<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
+        '</div>' +
+        '<div class="col-sm-11">' +
+          '<div class="row">' +
+            '<div class="col-sm-6">' + repo.full_name + '</div>' +
+            '<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
+            '<div class="col-sm-3"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
+          '</div>';
 
       if (repo.description) {
          markup += '<div>' + repo.description + '</div>';

+ 3 - 0
src/js/select2/defaults.js

@@ -116,6 +116,9 @@ define([
       language: ['select2/i18n/en'],
       templateResult: function (result) {
         return result.text;
+      },
+      templateSelection: function (selection) {
+        return selection.text;
       }
     };
   };

+ 3 - 1
src/js/select2/selection/multiple.js

@@ -52,7 +52,9 @@ define([
   };
 
   MultipleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   MultipleSelection.prototype.selectionContainer = function () {

+ 3 - 1
src/js/select2/selection/single.js

@@ -90,7 +90,9 @@ define([
   };
 
   SingleSelection.prototype.display = function (data) {
-    return data.text;
+    var template = this.options.get('templateSelection');
+
+    return template(data);
   };
 
   SingleSelection.prototype.selectionContainer = function () {

Some files were not shown because too many files changed in this diff