diff --git a/src/Orchard.Web/Modules/Orchard.Tokens/Scripts/orchard-tokens-admin.js b/src/Orchard.Web/Modules/Orchard.Tokens/Scripts/orchard-tokens-admin.js
index 11e70cfdb..e357cd218 100644
--- a/src/Orchard.Web/Modules/Orchard.Tokens/Scripts/orchard-tokens-admin.js
+++ b/src/Orchard.Web/Modules/Orchard.Tokens/Scripts/orchard-tokens-admin.js
@@ -25,15 +25,27 @@
}
});
-jQuery(function ($) {
+jQuery.fn.extend({
+ tokenized : function () {
+ return $(this).each(function () {
+ var _this = $(this);
- // provide autocomplete behavior to tokenized inputs
- // tokensUrl is initialized from the view
- $.get(tokensUrl, function (data) {
- $('.tokenized')
- .autocomplete({
+ // add an icon to tokenized inputs
+ _this.wrap('');
+ var popup = $('
')
+ _this.parent().prepend(popup);
+
+ // show the full list of tokens when the icon is clicked
+ popup.children('.tokenized-popup').click(function () {
+ var input = $(this).parent().next();
+ // pass empty string as value to search for, displaying all results
+ input.autocomplete("search", "");
+ input.focus();
+ });
+
+ $(this).autocomplete({
minLength: 0,
- source: data,
+ source: $.tokens,
select: function (event, ui) {
$(this).insertAtCaret(ui.item.value);
return false;
@@ -50,18 +62,18 @@ jQuery(function ($) {
.appendTo(ul);
};
});
- });
+ });
+ },
+});
- // add an icon to tokenized inputs
- $('.tokenized').wrap('');
+$(function() {
- $('.token-wrapper').prepend('');
+ $.tokens = {};
- // show the full list of tokens when the icon is clicked
- $('.tokenized-popup').click(function () {
- var input = $(this).parent().next();
- // pass empty string as value to search for, displaying all results
- input.autocomplete("search", "");
- input.focus();
+ // provide autocomplete behavior to tokenized inputs
+ // tokensUrl is initialized from the view
+ $.get(tokensUrl, function (data) {
+ $.tokens = data;
+ $('.tokenized').tokenized();
});
});