Fixed some IE issues.
This commit is contained in:
parent
235303d831
commit
43588554fd
2 changed files with 35 additions and 49 deletions
|
@ -132,11 +132,7 @@
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
newLine = "<br></br>"
|
||||||
newLine = "<br>"
|
|
||||||
if ( this.options.mode === 'textonly' ) {
|
|
||||||
newLine = "\n"
|
|
||||||
}
|
|
||||||
if (document.selection) {
|
if (document.selection) {
|
||||||
var range = document.selection.createRange()
|
var range = document.selection.createRange()
|
||||||
newLine = "<br/>" // ie is not supporting \n :(
|
newLine = "<br/>" // ie is not supporting \n :(
|
||||||
|
@ -154,7 +150,14 @@
|
||||||
// just paste text
|
// just paste text
|
||||||
if ( this.options.mode === 'textonly' ) {
|
if ( this.options.mode === 'textonly' ) {
|
||||||
this.$element.on('paste', $.proxy(function (e) {
|
this.$element.on('paste', $.proxy(function (e) {
|
||||||
var text = (e.originalEvent || e).clipboardData.getData('text/plain')
|
e.preventDefault()
|
||||||
|
var text
|
||||||
|
if (window.clipboardData) { // IE
|
||||||
|
text = window.clipboardData.getData('Text')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text = (e.originalEvent || e).clipboardData.getData('text/plain')
|
||||||
|
}
|
||||||
var overlimit = false
|
var overlimit = false
|
||||||
if (text) {
|
if (text) {
|
||||||
|
|
||||||
|
@ -177,8 +180,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert new text
|
// insert new text
|
||||||
e.preventDefault()
|
if (document.selection) { // IE
|
||||||
document.execCommand('inserttext', false, text)
|
var range = document.selection.createRange()
|
||||||
|
range.pasteHTML(text)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.execCommand('inserttext', false, text)
|
||||||
|
}
|
||||||
this.maxLengthOk( overlimit )
|
this.maxLengthOk( overlimit )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +251,7 @@
|
||||||
if ( length > this.options.maxlength ) {
|
if ( length > this.options.maxlength ) {
|
||||||
|
|
||||||
// try to set error on framework form
|
// try to set error on framework form
|
||||||
parent = this.$element.parent().parent()
|
var parent = this.$element.parent().parent()
|
||||||
if ( parent.hasClass('controls') ) {
|
if ( parent.hasClass('controls') ) {
|
||||||
parent.addClass('has-error')
|
parent.addClass('has-error')
|
||||||
setTimeout($.proxy(function(){
|
setTimeout($.proxy(function(){
|
||||||
|
@ -302,7 +310,7 @@
|
||||||
|
|
||||||
// strip html signes if multi line exists
|
// strip html signes if multi line exists
|
||||||
if ( this.options.multiline ) {
|
if ( this.options.multiline ) {
|
||||||
text = this.$element.html()
|
var text = this.$element.html()
|
||||||
text = text.replace(/<br>/g, "\n") // new line as br
|
text = text.replace(/<br>/g, "\n") // new line as br
|
||||||
text = text.replace(/<div>/g, "\n") // in some caes, new line als div
|
text = text.replace(/<div>/g, "\n") // in some caes, new line als div
|
||||||
text = $("<div>" + text + "</div>").text().trim()
|
text = $("<div>" + text + "</div>").text().trim()
|
||||||
|
|
|
@ -45,13 +45,11 @@
|
||||||
|
|
||||||
// navigate through widget
|
// navigate through widget
|
||||||
if ( this.isActive() ) {
|
if ( this.isActive() ) {
|
||||||
console.log('WIDGET IS OPEN', e.keyCode)
|
|
||||||
|
|
||||||
// enter
|
// enter
|
||||||
if ( e.keyCode === 13 ) {
|
if ( e.keyCode === 13 ) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
var id = this.$widget.find('.dropdown-menu li.active a').data('id')
|
var id = this.$widget.find('.dropdown-menu li.active a').data('id')
|
||||||
console.log('ID', id)
|
|
||||||
this.take(id)
|
this.take(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +87,6 @@
|
||||||
if ( next[0] ) {
|
if ( next[0] ) {
|
||||||
top = next.addClass('active').position().top
|
top = next.addClass('active').position().top
|
||||||
}
|
}
|
||||||
console.log('scrollTop', top, top-30)
|
|
||||||
this.$widget.find('.dropdown-menu').scrollTop( top );
|
this.$widget.find('.dropdown-menu').scrollTop( top );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,9 +102,10 @@
|
||||||
if ( this.buffer === '::' ) {
|
if ( this.buffer === '::' ) {
|
||||||
this.close()
|
this.close()
|
||||||
}
|
}
|
||||||
this.buffer = this.buffer.substr( 0, this.buffer.length-1 )
|
var length = this.buffer.length
|
||||||
console.log('BS', this.buffer)
|
this.buffer = this.buffer.substr( 0, length-1 )
|
||||||
this.result( this.buffer.substr(2,this.buffer.length) )
|
console.log('BS backspace', this.buffer)
|
||||||
|
this.result( this.buffer.substr( 2, length-1 ) )
|
||||||
}
|
}
|
||||||
}, this ))
|
}, this ))
|
||||||
|
|
||||||
|
@ -122,18 +120,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter :
|
// enter :
|
||||||
if ( e.keyCode === 58 ) {
|
if ( String.fromCharCode(e.which) === ':' ) {
|
||||||
this.buffer = this.buffer + ':'
|
this.buffer = this.buffer + ':'
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.buffer && this.buffer.substr(0,2) === '::' ) {
|
if ( this.buffer && this.buffer.substr(0,2) === '::' ) {
|
||||||
|
|
||||||
|
|
||||||
var sign = String.fromCharCode(e.which)
|
var sign = String.fromCharCode(e.which)
|
||||||
if ( e.keyCode !== 58 ) {
|
if ( sign && sign !== ':' && e.which != 8 ) { // 8 == backspace
|
||||||
this.buffer = this.buffer + sign
|
this.buffer = this.buffer + sign
|
||||||
|
//console.log('BUFF ADD', sign, this.buffer, sign.length, e.which)
|
||||||
}
|
}
|
||||||
console.log('BUFF HINT', this.buffer, this.buffer.length, e.which)
|
console.log('BUFF HINT', this.buffer, this.buffer.length, e.which, String.fromCharCode(e.which))
|
||||||
|
|
||||||
this.result( this.buffer.substr(2,this.buffer.length) )
|
this.result( this.buffer.substr(2,this.buffer.length) )
|
||||||
|
|
||||||
|
@ -161,37 +159,16 @@
|
||||||
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="width: 360px; max-height: 200px;"><li><a>-</a></li></ul></div>')
|
||||||
this.$widget = this.$element.next()
|
this.$widget = this.$element.next()
|
||||||
this.updatePosition()
|
|
||||||
}
|
|
||||||
|
|
||||||
// get cursor position
|
|
||||||
Plugin.prototype.getCaretPosition = function() {
|
|
||||||
// not needed on IE
|
|
||||||
if (document.selection) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
document.execCommand('insertHTML', false, '<span id="hidden"></span>')
|
|
||||||
}
|
|
||||||
var hiddenNode = document.getElementById('hidden');
|
|
||||||
if (!hiddenNode) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
var position = $(hiddenNode).position()
|
|
||||||
hiddenNode.parentNode.removeChild(hiddenNode)
|
|
||||||
return position
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update widget position
|
// update widget position
|
||||||
Plugin.prototype.updatePosition = function() {
|
Plugin.prototype.updatePosition = function() {
|
||||||
this.$widget.find('.dropdown-menu').scrollTop( 300 );
|
this.$widget.find('.dropdown-menu').scrollTop( 300 );
|
||||||
var position = this.getCaretPosition()
|
if ( !this.$element.is(':visible') ) return
|
||||||
var heightTextarea = this.$element.height()
|
var position = this.$element.caret('position');
|
||||||
var widgetHeight = this.$widget.find('ul').height() + 40
|
if (!position) return
|
||||||
console.log('position', position)
|
var widgetHeight = this.$widget.find('ul').height() + 85
|
||||||
console.log('heightTextarea', heightTextarea)
|
this.$widget.css('top', position.top - widgetHeight)
|
||||||
console.log('widgetHeight', widgetHeight)
|
|
||||||
this.$widget.css('top', position.top - heightTextarea - widgetHeight)
|
|
||||||
if ( !this.isActive() ) {
|
if ( !this.isActive() ) {
|
||||||
this.$widget.css('left', position.left)
|
this.$widget.css('left', position.left)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +209,7 @@
|
||||||
if ( item.id == id ) {
|
if ( item.id == id ) {
|
||||||
var content = item.content + "\n"
|
var content = item.content + "\n"
|
||||||
this.cutInput()
|
this.cutInput()
|
||||||
if (document.selection) {
|
if (document.selection) { // IE
|
||||||
var range = document.selection.createRange()
|
var range = document.selection.createRange()
|
||||||
range.pasteHTML(content)
|
range.pasteHTML(content)
|
||||||
}
|
}
|
||||||
|
@ -249,6 +226,7 @@
|
||||||
// cut out search string from text
|
// cut out search string from text
|
||||||
Plugin.prototype.cutInput = function() {
|
Plugin.prototype.cutInput = function() {
|
||||||
if (!this.buffer) return
|
if (!this.buffer) return
|
||||||
|
if (!this.$element.text()) return
|
||||||
var sel = window.getSelection()
|
var sel = window.getSelection()
|
||||||
if ( !sel || sel.rangeCount < 1) {
|
if ( !sel || sel.rangeCount < 1) {
|
||||||
this.buffer = ''
|
this.buffer = ''
|
||||||
|
@ -266,7 +244,7 @@
|
||||||
Plugin.prototype.result = function(term) {
|
Plugin.prototype.result = function(term) {
|
||||||
|
|
||||||
var result = _.filter( this.collection, function(item) {
|
var result = _.filter( this.collection, function(item) {
|
||||||
reg = new RegExp( term, 'i' )
|
var reg = new RegExp( term, 'i' )
|
||||||
if ( item.name && item.name.match( reg ) ) {
|
if ( item.name && item.name.match( reg ) ) {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
@ -280,7 +258,7 @@
|
||||||
console.log('result', term, result)
|
console.log('result', term, result)
|
||||||
for (var i = 0; i < result.length; i++) {
|
for (var i = 0; i < result.length; i++) {
|
||||||
var item = result[i]
|
var item = result[i]
|
||||||
template = "<li><a href=\"#\" class=\"u-textTruncate\" data-id=" + item.id + ">" + item.name
|
var template = "<li><a href=\"#\" class=\"u-textTruncate\" data-id=" + item.id + ">" + item.name
|
||||||
if (item.keywords) {
|
if (item.keywords) {
|
||||||
template = template + " (" + item.keywords + ")"
|
template = template + " (" + item.keywords + ")"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue