diff --git a/app/assets/javascripts/app/lib/base/jquery.textmodule.js b/app/assets/javascripts/app/lib/base/jquery.textmodule.js index 3e2a86ee8..d309c0e3c 100644 --- a/app/assets/javascripts/app/lib/base/jquery.textmodule.js +++ b/app/assets/javascripts/app/lib/base/jquery.textmodule.js @@ -54,16 +54,16 @@ // enter if ( e.keyCode === 13 ) { e.preventDefault() - var id = _this.$widget.find('.dropdown-menu li.is-active a').data('id') + var id = _this.$widget.find('.dropdown-menu li.is-active').data('id') // as fallback use hovered element if (!id) { - id = _this.$widget.find('.dropdown-menu li:hover a').data('id') + id = _this.$widget.find('.dropdown-menu li:hover').data('id') } // as fallback first element if (!id) { - id = _this.$widget.find('.dropdown-menu li:first-child a').data('id') + id = _this.$widget.find('.dropdown-menu li:first-child').data('id') } _this.take(id) return @@ -194,6 +194,7 @@ Plugin.prototype.baseTemplate = function() { this.$element.after('') this.$widget = this.$element.next() + this.$widget.on('click', 'li', $.proxy(this.onEntryClick, this)) } // set height of widget @@ -318,6 +319,11 @@ } } + Plugin.prototype.onEntryClick = function(event) { + var id = $(event.target).data('id') + this.take(id) + } + // select text module and insert into text Plugin.prototype.take = function(id) { if (!id) { @@ -364,32 +370,32 @@ return }) + result.reverse() + this.$widget.find('ul').html('') this.log('result', term, result) + + if (!result[0]) { + return this.close() + } + + if (!this.active) { + this.open() + } + for (var i = 0; i < result.length; i++) { var item = result[i] - var template = "
  • " + App.Utils.htmlEscape(item.name) - if (item.keywords) { - template = template + " (" + App.Utils.htmlEscape(item.keywords) + ")" - } - template = template + "
  • " - var element = $(template) - if (i == 0) { + var element = $('
  • ') + element.attr('data-id', item.id) + element.text(App.Utils.htmlEscape(item.name)) + element.addClass('u-clickable u-textTruncate') + if (i == result.length-1) { element.addClass('is-active') } this.$widget.find('ul').append(element) } - // if ( !result[0] ) { - // this.$widget.find('ul').append("
  • -
  • ") - // } - this.$widget.find('ul li').on( - 'click', - function(e) { - e.preventDefault() - var id = $(e.target).data('id') - _this.take(id) - } - ) + + this.$widget.find('ul').scrollTop(9999) this.movePosition() }