Added text module selection by click.

This commit is contained in:
Martin Edenhofer 2014-10-02 18:07:21 +02:00
parent 53f034eb5f
commit ce7d2e22f8

View file

@ -148,7 +148,11 @@
}, this)).on('focus', $.proxy(function (e) { }, this)).on('focus', $.proxy(function (e) {
this.close() this.close()
}, this)).on('blur', $.proxy(function (e) { }, this)).on('blur', $.proxy(function (e) {
// delay, to get click on text module before widget is closed
a = $.proxy(function() {
this.close() this.close()
}, this)
setTimeout(a, 600);
}, this)) }, this))
}; };
@ -232,15 +236,17 @@
// cut out search string from text // cut out search string from text
Plugin.prototype.cutInput = function() { Plugin.prototype.cutInput = function() {
if (!this.buffer) { if (!this.buffer) return
var sel = window.getSelection()
if ( !sel || sel.rangeCount < 1) {
this.buffer = ''
return return
} }
var sel = window.getSelection(); var range = sel.getRangeAt(0)
var range = sel.getRangeAt(0); var clone = range.cloneRange()
var clone = range.cloneRange(); clone.setStart(range.startContainer, range.startOffset - this.buffer.length)
clone.setStart(range.startContainer, range.startOffset - this.buffer.length); clone.setEnd(range.startContainer, range.startOffset)
clone.setEnd(range.startContainer, range.startOffset); clone.deleteContents()
clone.deleteContents();
this.buffer = '' this.buffer = ''
} }
@ -274,12 +280,11 @@
} }
this.$widget.find('ul li').on( this.$widget.find('ul li').on(
'click', 'click',
function(e) { $.proxy(function(e) {
console.log(31231)
e.preventDefault() e.preventDefault()
var id = $(e.target).data('id') var id = $(e.target).data('id')
console.log('99', id) this.take(id)
} }, this)
) )
this.updatePosition() this.updatePosition()
} }