From e0e4fa249c297199073bbf6109743efeeb6fac09 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 29 Mar 2016 11:10:35 +0200 Subject: [PATCH] Reuse token field mirror (prevent multiple unclean fields in dom). --- .../javascripts/app/lib/base/bootstrap-tokenfield.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js b/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js index 196cc0d0b..a81c22db1 100755 --- a/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js +++ b/app/assets/javascripts/app/lib/base/bootstrap-tokenfield.js @@ -135,7 +135,7 @@ } // Set up mirror for input auto-sizing - this.$mirror = $(''); + this.$mirror = $(''); this.$input.css('min-width', this.options.minWidth + 'px') $.each([ 'fontFamily', @@ -149,7 +149,12 @@ ], function (i, val) { _self.$mirror[0].style[val] = _self.$input.css(val); }); - this.$mirror.appendTo( 'body' ) + if (!$('.js-tokenfieldMirror').get(0)) { + this.$mirror.appendTo( 'body' ) + } + else { + this.$mirror = $('.js-tokenfieldMirror') + } // Insert tokenfield to HTML this.$wrapper.insertBefore( this.$element )