From 7155adc718b5700c9f86d2387c70ac11c7b9cd2b Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Fri, 6 Feb 2015 20:08:28 -0500 Subject: [PATCH] Split out `formatRepo` and `formatRepoSelection` This splits out the two templating functions that are referenced in the documentation. The two functions were previously available in the source code, but they were not named with the method names that the documentation referred to. This closes https://github.com/select2/select2/issues/2993. --- docs/examples.html | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/docs/examples.html b/docs/examples.html index e9e0edad..50b2b722 100644 --- a/docs/examples.html +++ b/docs/examples.html @@ -923,6 +923,33 @@ $.fn.select2.amd.require( data: data }); + function formatRepo (repo) { + if (repo.loading) return repo.text; + + var markup = '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + repo.full_name + '
' + + '
' + repo.forks_count + '
' + + '
' + repo.stargazers_count + '
' + + '
'; + + if (repo.description) { + markup += '
' + repo.description + '
'; + } + + markup += '
'; + + return markup; + } + + function formatRepoSelection (repo) { + return repo.full_name || repo.text; + } + $ajax.select2({ ajax: { url: "https://api.github.com/search/repositories", @@ -952,31 +979,8 @@ $.fn.select2.amd.require( }, escapeMarkup: function (markup) { return markup; }, minimumInputLength: 1, - templateResult: function (repo) { - if (repo.loading) return repo.text; - - var markup = '
' + - '
' + - '' + - '
' + - '
' + - '
' + - '
' + repo.full_name + '
' + - '
' + repo.forks_count + '
' + - '
' + repo.stargazers_count + '
' + - '
'; - - if (repo.description) { - markup += '
' + repo.description + '
'; - } - - markup += '
'; - - return markup; - }, - templateSelection: function (repo) { - return repo.full_name || repo.text; - } + templateResult: formatRepo, + templateSelection: formatRepoSelection }); $(".js-example-disabled").select2();