diff options
author | Wu Cheng-Han | 2016-10-12 17:50:01 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-10-12 17:50:01 +0800 |
commit | f3d4b55856e1d7f043831c5d8fcf92bc74395605 (patch) | |
tree | 0c9545dd0f05331ea2eb8885b373bbcc366dae13 /public/vendor | |
parent | 12b7646f247f2325c8d4593480571868b0783612 (diff) |
Fix getCaretPosition in text complete might get undefined position error
Diffstat (limited to 'public/vendor')
-rwxr-xr-x | public/vendor/jquery-textcomplete/jquery.textcomplete.js | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/public/vendor/jquery-textcomplete/jquery.textcomplete.js b/public/vendor/jquery-textcomplete/jquery.textcomplete.js index e1d90d0a..cd2f863d 100755 --- a/public/vendor/jquery-textcomplete/jquery.textcomplete.js +++ b/public/vendor/jquery-textcomplete/jquery.textcomplete.js @@ -863,16 +863,31 @@ if (typeof jQuery === 'undefined') { // // FIXME: Calculate the left top corner of `this.option.appendTo` element. getCaretPosition: function () { - //var position = this._getCaretRelativePosition(); - //var offset = this.$el.offset(); - //var offset = $('.CodeMirror-cursor').offset(); - var position = $('.CodeMirror-cursor').position(); - var menu = $('.cursor-menu .dropdown-menu'); - var offsetLeft = parseFloat(menu.attr('data-offset-left')); - var offsetTop = parseFloat(menu.attr('data-offset-top')); - position.left += offsetLeft; - position.top += offsetTop; - return position; + if ($('.CodeMirror-cursor').length > 0) { + var position = $('.CodeMirror-cursor').position(); + var menu = $('.cursor-menu .dropdown-menu'); + var offsetLeft = parseFloat(menu.attr('data-offset-left')); + var offsetTop = parseFloat(menu.attr('data-offset-top')); + position.left += offsetLeft; + position.top += offsetTop; + return position; + } else { + var position = this._getCaretRelativePosition(); + var offset = this.$el.offset(); + + // Calculate the left top corner of `this.option.appendTo` element. + var $parent = this.option.appendTo; + if ($parent) { + if (!($parent instanceof $)) { $parent = $($parent); } + var parentOffset = $parent.offsetParent().offset(); + offset.top -= parentOffset.top; + offset.left -= parentOffset.left; + } + + position.top += offset.top; + position.left += offset.left; + return position; + } }, // Focus on the element. |