diff --git a/dist/mentio.js b/dist/mentio.js index 2d81fa5..449ec17 100755 --- a/dist/mentio.js +++ b/dist/mentio.js @@ -575,7 +575,7 @@ angular.module('mentio') range.setStart(elem, offset); range.setEnd(elem, offset); range.collapse(true); - sel.removeAllRanges(); + try{sel.removeAllRanges();}catch(error){} sel.addRange(range); targetElement.focus(); } diff --git a/dist/mentio.min.js b/dist/mentio.min.js index 7f68f17..157b876 100755 --- a/dist/mentio.min.js +++ b/dist/mentio.min.js @@ -1 +1 @@ -"use strict";angular.module("mentio",[]).directive("mentio",function(e,t,n,r){return{restrict:"A",scope:{macros:"=mentioMacros",search:"&mentioSearch",select:"&mentioSelect",items:"=mentioItems",typedTerm:"=mentioTypedTerm",ngModel:"="},controller:function(t,n,i){t.query=function(e,n){var r=t.triggerCharMap[e];r.showMenu(),r.search({term:n}),r.typedTerm=n},t.defaultSearch=function(e){var n=[];angular.forEach(t.items,function(t){t.label.toUpperCase().indexOf(e.term.toUpperCase())>=0&&n.push(t)}),t.localItems=n},t.bridgeSearch=function(e){var n=i.mentioSearch?t.search:t.defaultSearch;n({term:e})},t.defaultSelect=function(e){return t.defaultTriggerChar+e.item.label},t.bridgeSelect=function(e){var n=i.mentioSelect?t.select:t.defaultSelect;return n({item:e})},t.setTriggerText=function(e){t.syncTriggerText&&(t.typedTerm=e)},t.replaceText=function(r,i){var o=t.triggerCharMap[r],a=o.select({item:i});if(e.replaceTriggerText(t.targetElement,t.targetElementPath,t.targetElementSelectedOffset,t.triggerCharSet,a),t.setTriggerText(""),angular.element(t.targetElement).triggerHandler("change"),t.isContentEditable()){t.contentEditableMenuPasted=!0;var c=n(function(){t.contentEditableMenuPasted=!1},100);t.$on("$destroy",function(){n.cancel(c)})}},t.hideAll=function(){for(var e in t.triggerCharMap)t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].hideMenu()},t.getActiveMenuScope=function(){for(var e in t.triggerCharMap)if(t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible)return t.triggerCharMap[e];return null},t.selectActive=function(){for(var e in t.triggerCharMap)t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible&&t.triggerCharMap[e].selectActive()},t.isActive=function(){for(var e in t.triggerCharMap)if(t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible)return!0;return!1},t.isContentEditable=function(){return"INPUT"!==t.targetElement.nodeName&&"TEXTAREA"!==t.targetElement.nodeName},t.replaceMacro=function(r){var i=n(function(){e.replaceMacroText(t.targetElement,t.targetElementPath,t.targetElementSelectedOffset,t.macros,t.macros[r]),angular.element(t.targetElement).triggerHandler("change")},300);t.$on("$destroy",function(){n.cancel(i)})},t.addMenu=function(e){e.parentScope&&t.triggerCharMap.hasOwnProperty(e.triggerChar)||(t.triggerCharMap[e.triggerChar]=e,void 0===t.triggerCharSet&&(t.triggerCharSet=[]),t.triggerCharSet.push(e.triggerChar),e.setParent(t))},t.$on("menuCreated",function(e,n){i.id===n.targetElement&&t.addMenu(n.scope)}),r.on("click",function(){t.isActive()&&t.$apply(function(){t.hideAll()})}),r.on("keydown keypress paste",function(e){var n=t.getActiveMenuScope();n&&(9===e.which&&n.selectActive(),27===e.which&&(e.preventDefault(),n.$apply(function(){n.hideMenu()})),40===e.which&&(e.preventDefault(),n.$apply(function(){n.activateNextItem()})),38===e.which&&(e.preventDefault(),n.$apply(function(){n.activatePreviousItem()})),(13===e.which||32===e.which)&&(e.preventDefault(),n.selectActive()))})},link:function(n,r,i){if(n.triggerCharMap={},i.$set("autocomplete","off"),i.mentioItems){n.localItems=[],n.parentScope=n;var o=i.mentioSearch?' mentio-items="items"':' mentio-items="localItems"';n.defaultTriggerChar=i.mentioTriggerChar?n.$eval(i.mentioTriggerChar):"@";var a='';var c=t(a),l=c(n);r.parent().append(l)}i.mentioTypedTerm&&(n.syncTriggerText=!0),n.$watch("ngModel",function(){if(n.contentEditableMenuPasted)return void(n.contentEditableMenuPasted=!1);var t=e.getTriggerInfo(n.triggerCharSet);if(void 0!==t)n.targetElement=t.mentionSelectedElement,n.targetElementPath=t.mentionSelectedPath,n.targetElementSelectedOffset=t.mentionSelectedOffset,n.setTriggerText(t.mentionText),n.query(t.mentionTriggerChar,t.mentionText);else{n.setTriggerText(""),n.hideAll();var r=e.getMacroMatch(n.macros);void 0!==r&&(n.targetElement=r.macroSelectedElement,n.targetElementPath=r.macroSelectedPath,n.targetElementSelectedOffset=r.macroSelectedOffset,n.replaceMacro(r.macroText))}})}}}).directive("mentioMenu",function(e,t,n,r,i){return{restrict:"E",scope:{search:"&mentioSearch",select:"&mentioSelect",items:"=mentioItems",triggerChar:"=mentioTriggerChar",forElem:"=mentioFor",parentScope:"=mentioParentScope"},templateUrl:function(e,t){return void 0!==t.mentioTemplateUrl?t.mentioTemplateUrl:"mentio-menu.tpl.html"},controller:function(e){e.visible=!1,this.activate=e.activate=function(t){e.activeItem=t},this.isActive=e.isActive=function(t){return e.activeItem===t},this.selectItem=e.selectItem=function(t){e.hideMenu(),e.parentMentio.replaceText(e.triggerChar,t)},e.activateNextItem=function(){var t=e.items.indexOf(e.activeItem);this.activate(e.items[(t+1)%e.items.length])},e.activatePreviousItem=function(){var t=e.items.indexOf(e.activeItem);this.activate(e.items[0===t?e.items.length-1:t-1])},e.selectActive=function(){e.selectItem(e.activeItem)},e.isVisible=function(){return e.visible},e.showMenu=function(){e.visible||(e.requestVisiblePendingSearch=!0)},e.setParent=function(t){e.parentMentio=t}},link:function(o,a){if(a[0].parentNode.removeChild(a[0]),i[0].body.appendChild(a[0]),o.menuElement=a,o.parentScope)o.parentScope.addMenu(o);else{if(!o.forElem)return void n.error("mentio-menu requires a target element in tbe mentio-for attribute");if(!o.triggerChar)return void n.error("mentio-menu requires a trigger char");var c=i[0].querySelector("#"+o.forElem);if(c){var l=angular.element(c),s=l.attr("mentio");void 0!==s?(t.$broadcast("menuCreated",{targetElement:o.forElem,scope:o}),o.targetElement=l):n.error("Error, no mentio directive on target element "+o.forElem)}else n.error("Error, no such element: "+o.forElem)}angular.element(r).bind("resize",function(){if(o.isVisible()){var t=[];t.push(o.triggerChar),e.popUnderMention(t,a)}}),o.$watch("items",function(e){e&&e.length>0?(o.activate(e[0]),!o.visible&&o.requestVisiblePendingSearch&&(o.visible=!0,o.requestVisiblePendingSearch=!1)):o.hideMenu()}),o.$watch("isVisible()",function(t){if(t){var n=[];n.push(o.triggerChar),e.popUnderMention(n,a)}}),o.hideMenu=function(){o.visible=!1,a.css("display","none")}}}}).directive("mentioMenuItem",function(){return{restrict:"A",scope:{item:"=mentioMenuItem"},require:"^mentioMenu",link:function(e,t,n,r){e.$watch(function(){return r.isActive(e.item)},function(e){e?t.addClass("active"):t.removeClass("active")}),t.bind("mouseenter",function(){e.$apply(function(){r.activate(e.item)})}),t.bind("click",function(t){t.preventDefault(),r.selectItem(e.item)})}}}).filter("unsafe",function(e){return function(t){return e.trustAsHtml(t)}}).filter("mentioHighlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n,r){if(n){var i=r?'$&':"$&";return(""+t).replace(new RegExp(e(n),"gi"),i)}return t}}),angular.module("mentio").factory("mentioUtil",function(e,t,n,r){function i(e,t){var n,i=h(e);void 0!==i?(n=a()?S(document.activeElement,i.mentionPosition):v(i.mentionPosition),t.css({top:n.top+"px",left:n.left+"px",position:"absolute",zIndex:100,display:"block"}),r(function(){o(t)},0)):t.css({display:"none"})}function o(t){for(var n,r=20,i=100,o=t[0];void 0===n||0===n.height;)if(n=o.getBoundingClientRect(),0===n.height&&(o=o.childNodes[0],!o.getBoundingClientRect))return;var a=n.top,c=a+n.height;if(0>a)e.scrollTo(0,e.pageYOffset+n.top-r);else if(c>e.innerHeight){var l=e.pageYOffset+n.top-r;l-e.pageYOffset>i&&(l=e.pageYOffset+i);var s=e.pageYOffset-(e.innerHeight-c);s>l&&(s=l),e.scrollTo(0,s)}}function a(){var e=document.activeElement;if(null!==e){var t=e.nodeName;return"INPUT"===t||"TEXTAREA"===t}return!1}function c(e,t,n){for(var r,i=e,o=0;o=0&&i.length+a===o.length){var l=a-1;(0===a||" "===o.charAt(l)||" "===o.charAt(l))&&(c={macroPosition:a,macroText:i,macroSelectedElement:t,macroSelectedPath:r,macroSelectedOffset:n})}}),c)return c}}function g(){var e,t=window.getSelection(),n=t.anchorNode,r=[];if(null!=n){for(var i,o=n.contentEditable;null!==n&&"true"!==o;)i=u(n),r.push(i),n=n.parentNode,null!==n&&(o=n.contentEditable);return r.reverse(),e=t.getRangeAt(0).startOffset,{selected:n,path:r,offset:e}}}function h(e){var t,n,r;if(a())t=document.activeElement;else{var i=g();i&&(t=i.selected,n=i.path,r=i.offset)}var o=p();if(void 0!==o&&null!==o){var c,l=-1;if(e.forEach(function(e){var t=o.lastIndexOf(e);t>l&&(l=t,c=e)}),0===l||/[\xA0\s]/g.test(o.substring(l-1,l))){var s=o.substring(l+1,o.length);if(c=o.substring(l,l+1),!/[\xA0\s]/g.test(s))return{mentionPosition:l,mentionText:s,mentionSelectedElement:t,mentionSelectedPath:n,mentionSelectedOffset:r,mentionTriggerChar:c}}}}function p(){var e;if(a()){var t=document.activeElement;if(void 0!==document.selection){t.focus();var n=document.selection.createRange();e=n.text}else if(void 0!==t.selectionStart){var r=t.selectionStart;e=t.value.substring(0,r)}}else{var i=window.getSelection().anchorNode;if(null!=i){var o=i.textContent,c=window.getSelection().getRangeAt(0).startOffset;c>=0&&(e=o.substring(0,c))}}return e}function v(e){var t,n,r="",i="",o="sel_"+(new Date).getTime()+"_"+Math.random().toString().substr(2);if(document.selection&&document.selection.createRange)n=document.selection.createRange().duplicate(),n.selectStartOffset(e),n.selectEndOffset(e),n.collapse(!1),n.pasteHTML(''+i+""),t=document.getElementById(o);else if(window.getSelection){var a=window.getSelection();n=document.createRange(),n.setStart(a.anchorNode,e),n.setEnd(a.anchorNode,e),n.collapse(!1),t=document.createElement("span"),t.id=o,t.appendChild(document.createTextNode(r)),n.insertNode(t)}var c=t,l={left:0,top:t.offsetHeight};do l.left+=c.offsetLeft,l.top+=c.offsetTop;while(c=c.offsetParent);return t.parentNode.removeChild(t),l}function S(e,t){var n=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"],r=null!==window.mozInnerScreenX,i=document.createElement("div");i.id="input-textarea-caret-position-mirror-div",document.body.appendChild(i);var o=i.style,a=window.getComputedStyle?getComputedStyle(e):e.currentStyle;o.whiteSpace="pre-wrap","INPUT"!==e.nodeName&&(o.wordWrap="break-word"),o.position="absolute",o.visibility="hidden",n.forEach(function(e){o[e]=a[e]}),r?(o.width=parseInt(a.width)-2+"px",e.scrollHeight>parseInt(a.height)&&(o.overflowY="scroll")):o.overflow="hidden",i.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(i.textContent=i.textContent.replace(/\s/g," "));var c=document.createElement("span");c.textContent=e.value.substring(t)||".",i.appendChild(c);var l={top:c.offsetTop+parseInt(a.borderTopWidth)+c.offsetHeight,left:c.offsetLeft+parseInt(a.borderLeftWidth)},s=e;do l.left+=s.offsetLeft,l.top+=s.offsetTop;while(s=s.offsetParent);return document.body.removeChild(i),l}return{popUnderMention:i,replaceMacroText:m,replaceTriggerText:d,getMacroMatch:f,getTriggerInfo:h,selectElement:c,getTextAreaOrInputUnderlinePosition:S,getTextPrecedingCurrentSelection:p,getContentEditableSelectedPath:g,getNodePositionInParent:u,getContentEditableCaretPosition:v,pasteHtml:l,resetSelection:s,scrollIntoView:o}}),angular.module("mentio").run(["$templateCache",function(e){e.put("mentio-menu.tpl.html",'')}]); \ No newline at end of file +"use strict";angular.module("mentio",[]).directive("mentio",function(e,t,n,r){return{restrict:"A",scope:{macros:"=mentioMacros",search:"&mentioSearch",select:"&mentioSelect",items:"=mentioItems",typedTerm:"=mentioTypedTerm",ngModel:"="},controller:function(t,n,i){t.query=function(e,n){var r=t.triggerCharMap[e];r.showMenu(),r.search({term:n}),r.typedTerm=n},t.defaultSearch=function(e){var n=[];angular.forEach(t.items,function(t){t.label.toUpperCase().indexOf(e.term.toUpperCase())>=0&&n.push(t)}),t.localItems=n},t.bridgeSearch=function(e){var n=i.mentioSearch?t.search:t.defaultSearch;n({term:e})},t.defaultSelect=function(e){return t.defaultTriggerChar+e.item.label},t.bridgeSelect=function(e){var n=i.mentioSelect?t.select:t.defaultSelect;return n({item:e})},t.setTriggerText=function(e){t.syncTriggerText&&(t.typedTerm=e)},t.replaceText=function(r,i){var o=t.triggerCharMap[r],a=o.select({item:i});if(e.replaceTriggerText(t.targetElement,t.targetElementPath,t.targetElementSelectedOffset,t.triggerCharSet,a),t.setTriggerText(""),angular.element(t.targetElement).triggerHandler("change"),t.isContentEditable()){t.contentEditableMenuPasted=!0;var c=n(function(){t.contentEditableMenuPasted=!1},100);t.$on("$destroy",function(){n.cancel(c)})}},t.hideAll=function(){for(var e in t.triggerCharMap)t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].hideMenu()},t.getActiveMenuScope=function(){for(var e in t.triggerCharMap)if(t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible)return t.triggerCharMap[e];return null},t.selectActive=function(){for(var e in t.triggerCharMap)t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible&&t.triggerCharMap[e].selectActive()},t.isActive=function(){for(var e in t.triggerCharMap)if(t.triggerCharMap.hasOwnProperty(e)&&t.triggerCharMap[e].visible)return!0;return!1},t.isContentEditable=function(){return"INPUT"!==t.targetElement.nodeName&&"TEXTAREA"!==t.targetElement.nodeName},t.replaceMacro=function(r){var i=n(function(){e.replaceMacroText(t.targetElement,t.targetElementPath,t.targetElementSelectedOffset,t.macros,t.macros[r]),angular.element(t.targetElement).triggerHandler("change")},300);t.$on("$destroy",function(){n.cancel(i)})},t.addMenu=function(e){e.parentScope&&t.triggerCharMap.hasOwnProperty(e.triggerChar)||(t.triggerCharMap[e.triggerChar]=e,void 0===t.triggerCharSet&&(t.triggerCharSet=[]),t.triggerCharSet.push(e.triggerChar),e.setParent(t))},t.$on("menuCreated",function(e,n){i.id===n.targetElement&&t.addMenu(n.scope)}),r.on("click",function(){t.isActive()&&t.$apply(function(){t.hideAll()})}),r.on("keydown keypress paste",function(e){var n=t.getActiveMenuScope();n&&(9===e.which&&n.selectActive(),27===e.which&&(e.preventDefault(),n.$apply(function(){n.hideMenu()})),40===e.which&&(e.preventDefault(),n.$apply(function(){n.activateNextItem()})),38===e.which&&(e.preventDefault(),n.$apply(function(){n.activatePreviousItem()})),(13===e.which||32===e.which)&&(e.preventDefault(),n.selectActive()))})},link:function(n,r,i){if(n.triggerCharMap={},i.$set("autocomplete","off"),i.mentioItems){n.localItems=[],n.parentScope=n;var o=i.mentioSearch?' mentio-items="items"':' mentio-items="localItems"';n.defaultTriggerChar=i.mentioTriggerChar?n.$eval(i.mentioTriggerChar):"@";var a='';var c=t(a),l=c(n);r.parent().append(l)}i.mentioTypedTerm&&(n.syncTriggerText=!0),n.$watch("ngModel",function(){if(n.contentEditableMenuPasted)return void(n.contentEditableMenuPasted=!1);var t=e.getTriggerInfo(n.triggerCharSet);if(void 0!==t)n.targetElement=t.mentionSelectedElement,n.targetElementPath=t.mentionSelectedPath,n.targetElementSelectedOffset=t.mentionSelectedOffset,n.setTriggerText(t.mentionText),n.query(t.mentionTriggerChar,t.mentionText);else{n.setTriggerText(""),n.hideAll();var r=e.getMacroMatch(n.macros);void 0!==r&&(n.targetElement=r.macroSelectedElement,n.targetElementPath=r.macroSelectedPath,n.targetElementSelectedOffset=r.macroSelectedOffset,n.replaceMacro(r.macroText))}})}}}).directive("mentioMenu",function(e,t,n,r,i){return{restrict:"E",scope:{search:"&mentioSearch",select:"&mentioSelect",items:"=mentioItems",triggerChar:"=mentioTriggerChar",forElem:"=mentioFor",parentScope:"=mentioParentScope"},templateUrl:function(e,t){return void 0!==t.mentioTemplateUrl?t.mentioTemplateUrl:"mentio-menu.tpl.html"},controller:function(e){e.visible=!1,this.activate=e.activate=function(t){e.activeItem=t},this.isActive=e.isActive=function(t){return e.activeItem===t},this.selectItem=e.selectItem=function(t){e.hideMenu(),e.parentMentio.replaceText(e.triggerChar,t)},e.activateNextItem=function(){var t=e.items.indexOf(e.activeItem);this.activate(e.items[(t+1)%e.items.length])},e.activatePreviousItem=function(){var t=e.items.indexOf(e.activeItem);this.activate(e.items[0===t?e.items.length-1:t-1])},e.selectActive=function(){e.selectItem(e.activeItem)},e.isVisible=function(){return e.visible},e.showMenu=function(){e.visible||(e.requestVisiblePendingSearch=!0)},e.setParent=function(t){e.parentMentio=t}},link:function(o,a){if(a[0].parentNode.removeChild(a[0]),i[0].body.appendChild(a[0]),o.menuElement=a,o.parentScope)o.parentScope.addMenu(o);else{if(!o.forElem)return void n.error("mentio-menu requires a target element in tbe mentio-for attribute");if(!o.triggerChar)return void n.error("mentio-menu requires a trigger char");var c=i[0].querySelector("#"+o.forElem);if(c){var l=angular.element(c),s=l.attr("mentio");void 0!==s?(t.$broadcast("menuCreated",{targetElement:o.forElem,scope:o}),o.targetElement=l):n.error("Error, no mentio directive on target element "+o.forElem)}else n.error("Error, no such element: "+o.forElem)}angular.element(r).bind("resize",function(){if(o.isVisible()){var t=[];t.push(o.triggerChar),e.popUnderMention(t,a)}}),o.$watch("items",function(e){e&&e.length>0?(o.activate(e[0]),!o.visible&&o.requestVisiblePendingSearch&&(o.visible=!0,o.requestVisiblePendingSearch=!1)):o.hideMenu()}),o.$watch("isVisible()",function(t){if(t){var n=[];n.push(o.triggerChar),e.popUnderMention(n,a)}}),o.hideMenu=function(){o.visible=!1,a.css("display","none")}}}}).directive("mentioMenuItem",function(){return{restrict:"A",scope:{item:"=mentioMenuItem"},require:"^mentioMenu",link:function(e,t,n,r){e.$watch(function(){return r.isActive(e.item)},function(e){e?t.addClass("active"):t.removeClass("active")}),t.bind("mouseenter",function(){e.$apply(function(){r.activate(e.item)})}),t.bind("click",function(t){t.preventDefault(),r.selectItem(e.item)})}}}).filter("unsafe",function(e){return function(t){return e.trustAsHtml(t)}}).filter("mentioHighlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,n,r){if(n){var i=r?'$&':"$&";return(""+t).replace(new RegExp(e(n),"gi"),i)}return t}}),angular.module("mentio").factory("mentioUtil",function(e,t,n,r){function i(e,t){var n,i=h(e);void 0!==i?(n=a()?S(document.activeElement,i.mentionPosition):v(i.mentionPosition),t.css({top:n.top+"px",left:n.left+"px",position:"absolute",zIndex:100,display:"block"}),r(function(){o(t)},0)):t.css({display:"none"})}function o(t){for(var n,r=20,i=100,o=t[0];void 0===n||0===n.height;)if(n=o.getBoundingClientRect(),0===n.height&&(o=o.childNodes[0],!o.getBoundingClientRect))return;var a=n.top,c=a+n.height;if(0>a)e.scrollTo(0,e.pageYOffset+n.top-r);else if(c>e.innerHeight){var l=e.pageYOffset+n.top-r;l-e.pageYOffset>i&&(l=e.pageYOffset+i);var s=e.pageYOffset-(e.innerHeight-c);s>l&&(s=l),e.scrollTo(0,s)}}function a(){var e=document.activeElement;if(null!==e){var t=e.nodeName;return"INPUT"===t||"TEXTAREA"===t}return!1}function c(e,t,n){for(var r,i=e,o=0;o=0&&i.length+a===o.length){var l=a-1;(0===a||" "===o.charAt(l)||" "===o.charAt(l))&&(c={macroPosition:a,macroText:i,macroSelectedElement:t,macroSelectedPath:r,macroSelectedOffset:n})}}),c)return c}}function g(){var e,t=window.getSelection(),n=t.anchorNode,r=[];if(null!=n){for(var i,o=n.contentEditable;null!==n&&"true"!==o;)i=u(n),r.push(i),n=n.parentNode,null!==n&&(o=n.contentEditable);return r.reverse(),e=t.getRangeAt(0).startOffset,{selected:n,path:r,offset:e}}}function h(e){var t,n,r;if(a())t=document.activeElement;else{var i=g();i&&(t=i.selected,n=i.path,r=i.offset)}var o=p();if(void 0!==o&&null!==o){var c,l=-1;if(e.forEach(function(e){var t=o.lastIndexOf(e);t>l&&(l=t,c=e)}),0===l||/[\xA0\s]/g.test(o.substring(l-1,l))){var s=o.substring(l+1,o.length);if(c=o.substring(l,l+1),!/[\xA0\s]/g.test(s))return{mentionPosition:l,mentionText:s,mentionSelectedElement:t,mentionSelectedPath:n,mentionSelectedOffset:r,mentionTriggerChar:c}}}}function p(){var e;if(a()){var t=document.activeElement;if(void 0!==document.selection){t.focus();var n=document.selection.createRange();e=n.text}else if(void 0!==t.selectionStart){var r=t.selectionStart;e=t.value.substring(0,r)}}else{var i=window.getSelection().anchorNode;if(null!=i){var o=i.textContent,c=window.getSelection().getRangeAt(0).startOffset;c>=0&&(e=o.substring(0,c))}}return e}function v(e){var t,n,r="",i="",o="sel_"+(new Date).getTime()+"_"+Math.random().toString().substr(2);if(document.selection&&document.selection.createRange)n=document.selection.createRange().duplicate(),n.selectStartOffset(e),n.selectEndOffset(e),n.collapse(!1),n.pasteHTML(''+i+""),t=document.getElementById(o);else if(window.getSelection){var a=window.getSelection();n=document.createRange(),n.setStart(a.anchorNode,e),n.setEnd(a.anchorNode,e),n.collapse(!1),t=document.createElement("span"),t.id=o,t.appendChild(document.createTextNode(r)),n.insertNode(t)}var c=t,l={left:0,top:t.offsetHeight};do l.left+=c.offsetLeft,l.top+=c.offsetTop;while(c=c.offsetParent);return t.parentNode.removeChild(t),l}function S(e,t){var n=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"],r=null!==window.mozInnerScreenX,i=document.createElement("div");i.id="input-textarea-caret-position-mirror-div",document.body.appendChild(i);var o=i.style,a=window.getComputedStyle?getComputedStyle(e):e.currentStyle;o.whiteSpace="pre-wrap","INPUT"!==e.nodeName&&(o.wordWrap="break-word"),o.position="absolute",o.visibility="hidden",n.forEach(function(e){o[e]=a[e]}),r?(o.width=parseInt(a.width)-2+"px",e.scrollHeight>parseInt(a.height)&&(o.overflowY="scroll")):o.overflow="hidden",i.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(i.textContent=i.textContent.replace(/\s/g," "));var c=document.createElement("span");c.textContent=e.value.substring(t)||".",i.appendChild(c);var l={top:c.offsetTop+parseInt(a.borderTopWidth)+c.offsetHeight,left:c.offsetLeft+parseInt(a.borderLeftWidth)},s=e;do l.left+=s.offsetLeft,l.top+=s.offsetTop;while(s=s.offsetParent);return document.body.removeChild(i),l}return{popUnderMention:i,replaceMacroText:m,replaceTriggerText:d,getMacroMatch:f,getTriggerInfo:h,selectElement:c,getTextAreaOrInputUnderlinePosition:S,getTextPrecedingCurrentSelection:p,getContentEditableSelectedPath:g,getNodePositionInParent:u,getContentEditableCaretPosition:v,pasteHtml:l,resetSelection:s,scrollIntoView:o}}),angular.module("mentio").run(["$templateCache",function(e){e.put("mentio-menu.tpl.html",'')}]); \ No newline at end of file diff --git a/src/mentio.service.js b/src/mentio.service.js index 3730d7f..1ca18cc 100644 --- a/src/mentio.service.js +++ b/src/mentio.service.js @@ -107,7 +107,7 @@ angular.module('mentio') range.setStart(elem, offset); range.setEnd(elem, offset); range.collapse(true); - sel.removeAllRanges(); + try{sel.removeAllRanges();}catch(error){} sel.addRange(range); targetElement.focus(); }