From bd616ac46e9bcfec0043013d9f29a44e19a1a3fc Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 5 Dec 2017 18:30:22 +0100 Subject: [PATCH] put template func of chzn select into var and reuse it --- styles/bootstrap/application.js | 53 +++++++++++---------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/styles/bootstrap/application.js b/styles/bootstrap/application.js index c4968940f..65fccac65 100644 --- a/styles/bootstrap/application.js +++ b/styles/bootstrap/application.js @@ -1,3 +1,16 @@ +/* Template function which outputs an option in a chzn-select */ +chzn_template_func = function (state) { + var subtitle = $(state.element).data('subtitle'); + var warning = $(state.element).data('warning'); + var html = ''+state.text+''; + if(subtitle) + html += '
'+subtitle+''; + if(warning) + html += '
'+warning+''; + html += '
'; + var $newstate = $(html); + return $newstate; +}; $(document).ready( function() { /* close popovers when clicking somewhere except in the popover or the * remove icon @@ -27,28 +40,12 @@ $(document).ready( function() { $(".chzn-select").select2({ width: '100%', - templateResult: function (state) { - var subtitle = $(state.element).data('subtitle'); - var html = ''+state.text+''; - if(subtitle) - html += '
'+subtitle+''; - html += '
'; - var $newstate = $(html); - return $newstate; - } + templateResult: chzn_template_func }); $(".chzn-select-deselect").select2({ allowClear:true, width: '100%', - templateResult: function (state) { - var subtitle = $(state.element).data('subtitle'); - var html = ''+state.text+''; - if(subtitle) - html += '
'+subtitle+''; - html += '
'; - var $newstate = $(html); - return $newstate; - } + templateResult: chzn_template_func }); /* change the color and length of the bar graph showing the password @@ -382,15 +379,7 @@ $(document).ready( function() { // $(".chzn-select").chosen(); $(".chzn-select").select2({ width: '100%', - templateResult: function (state) { - var subtitle = $(state.element).data('subtitle'); - var html = ''+state.text+''; - if(subtitle) - html += '
'+subtitle+''; - html += '
'; - var $newstate = $(html); - return $newstate; - } + templateResult: chzn_template_func }); }); }); /* }}} */ @@ -424,15 +413,7 @@ $(document).ready( function() { // $(".chzn-select").chosen(); $(".chzn-select").select2({ width: '100%', - templateResult: function (state) { - var subtitle = $(state.element).data('subtitle'); - var html = ''+state.text+''; - if(subtitle) - html += '
'+subtitle+''; - html += '
'; - var $newstate = $(html); - return $newstate; - } + templateResult: chzn_template_func }); $(".pwd").passStrength({ /* {{{ */ url: "../op/op.Ajax.php",