textmodule: keep widget in input area width, auto-highlight first

This commit is contained in:
Felix Niklas 2016-02-02 15:41:29 +01:00
parent a0b3559522
commit 78548697eb

View file

@ -27,6 +27,8 @@
this.active = false this.active = false
this.buffer = '' this.buffer = ''
this._width = 380
// check if ce exists // check if ce exists
if ( $.data(element, 'plugin_ce') ) { if ( $.data(element, 'plugin_ce') ) {
this.ce = $.data(element, 'plugin_ce') this.ce = $.data(element, 'plugin_ce')
@ -197,18 +199,29 @@
// create base template // create base template
Plugin.prototype.baseTemplate = function() { Plugin.prototype.baseTemplate = function() {
this.$element.after('<div class="shortcut dropdown"><ul class="dropdown-menu" style="width: 360px; max-height: 200px;"><li><a>-</a></li></ul></div>') this.$element.after('<div class="shortcut dropdown"><ul class="dropdown-menu" style="max-height: 200px;"><li><a>-</a></li></ul></div>')
this.$widget = this.$element.next() this.$widget = this.$element.next()
console.log("element", this.$element);
} }
// set height of widget // set height of widget
Plugin.prototype.movePosition = function() { Plugin.prototype.movePosition = function() {
if (!this._position) return if (!this._position) return
var height = this.$element.height() + 20 var height = this.$element.height() + 2
var widgetHeight = this.$widget.find('ul').height() //+ 60 // + height var widgetHeight = this.$widget.find('ul').height() //+ 60 // + height
var top = -( widgetHeight + height ) + this._position.top var top = -( widgetHeight + height ) + this._position.top
this.$widget.css('top', top) var left = this._position.left - 6
this.$widget.css('left', this._position.left)
// position the element further left if it would break out of the textarea width
if (left + this._width > this.$element.innerWidth()) {
left = this.$element.innerWidth() - this._width
}
this.$widget.css({
top: top,
left: left,
width: this._width
})
} }
// set position of widget // set position of widget
@ -369,7 +382,11 @@
template = template + " (" + App.Utils.htmlEscape(item.keywords) + ")" template = template + " (" + App.Utils.htmlEscape(item.keywords) + ")"
} }
template = template + "</a></li>" template = template + "</a></li>"
this.$widget.find('ul').append(template) var element = $(template)
if (i == 0) {
element.addClass('active')
}
this.$widget.find('ul').append(element)
} }
if ( !result[0] ) { if ( !result[0] ) {
this.$widget.find('ul').append("<li><a href='#'>-</a></li>") this.$widget.find('ul').append("<li><a href='#'>-</a></li>")