Loading README.md +1 −2 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ Copy the mention folder into your own application, or install the package as a d npm install --save ng2-mentions Add the CSS and JS dependencies your index.html: Add the CSS to your index.html: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="ext/textarea-caret-position.js"></script> Add the `[mention]` directive to your input element: Loading gh-pages/ext/textarea-caret-position.jsdeleted 100644 → 0 +0 −131 Original line number Diff line number Diff line /* From: https://github.com/component/textarea-caret-position */ /* jshint browser: true */ (function () { // The properties that we copy into a mirrored div. // Note that some browsers, such as Firefox, // do not concatenate properties, i.e. padding-top, bottom etc. -> padding, // so we have to do every single property specifically. var properties = [ 'direction', // RTL support 'boxSizing', 'width', // on Chrome and IE, exclude the scrollbar, so the mirror div wraps exactly as the textarea does 'height', 'overflowX', 'overflowY', // copy the scrollbar for IE 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderStyle', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', // https://developer.mozilla.org/en-US/docs/Web/CSS/font 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', // might not make a difference, but better be safe 'letterSpacing', 'wordSpacing', 'tabSize', 'MozTabSize' ]; var isBrowser = (typeof window !== 'undefined'); var isFirefox = (isBrowser && window.mozInnerScreenX != null); function getCaretCoordinates(element, position, options) { if(!isBrowser) { throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser'); } var debug = options && options.debug || false; if (debug) { var el = document.querySelector('#input-textarea-caret-position-mirror-div'); if ( el ) { el.parentNode.removeChild(el); } } // mirrored div var div = document.createElement('div'); div.id = 'input-textarea-caret-position-mirror-div'; document.body.appendChild(div); var style = div.style; var computed = window.getComputedStyle? getComputedStyle(element) : element.currentStyle; // currentStyle for IE < 9 // default textarea styles style.whiteSpace = 'pre-wrap'; if (element.nodeName !== 'INPUT') style.wordWrap = 'break-word'; // only for textarea-s // position off-screen style.position = 'absolute'; // required to return coordinates properly if (!debug) style.visibility = 'hidden'; // not 'display: none' because we want rendering // transfer the element's properties to the div properties.forEach(function (prop) { style[prop] = computed[prop]; }); if (isFirefox) { // Firefox lies about the overflow property for textareas: https://bugzilla.mozilla.org/show_bug.cgi?id=984275 if (element.scrollHeight > parseInt(computed.height)) style.overflowY = 'scroll'; } else { style.overflow = 'hidden'; // for Chrome to not render a scrollbar; IE keeps overflowY = 'scroll' } div.textContent = element.value.substring(0, position); // the second special handling for input type="text" vs textarea: spaces need to be replaced with non-breaking spaces - http://stackoverflow.com/a/13402035/1269037 if (element.nodeName === 'INPUT') div.textContent = div.textContent.replace(/\s/g, '\u00a0'); var span = document.createElement('span'); // Wrapping must be replicated *exactly*, including when a long word gets // onto the next line, with whitespace at the end of the line before (#7). // The *only* reliable way to do that is to copy the *entire* rest of the // textarea's content into the <span> created at the caret position. // for inputs, just '.' would be enough, but why bother? span.textContent = element.value.substring(position) || '.'; // || because a completely empty faux span doesn't render at all div.appendChild(span); var coordinates = { top: span.offsetTop + parseInt(computed['borderTopWidth']), left: span.offsetLeft + parseInt(computed['borderLeftWidth']) }; if (debug) { span.style.backgroundColor = '#aaa'; } else { document.body.removeChild(div); } return coordinates; } if (typeof module != 'undefined' && typeof module.exports != 'undefined') { module.exports = getCaretCoordinates; } else if(isBrowser){ window.getCaretCoordinates = getCaretCoordinates; } }()); index.html +0 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ <!-- 0. Dependancies --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <script src="ext/textarea-caret-position.js"></script> <script src="http://cdn.tinymce.com/4/tinymce.min.js"></script> <!-- 1. Load libraries --> Loading ext/textarea-caret-position.js→mention/caret-coords.ts +7 −11 Original line number Diff line number Diff line /* From: https://github.com/component/textarea-caret-position */ /* jshint browser: true */ (function () { // The properties that we copy into a mirrored div. // Note that some browsers, such as Firefox, // do not concatenate properties, i.e. padding-top, bottom etc. -> padding, Loading Loading @@ -50,9 +48,9 @@ var properties = [ ]; var isBrowser = (typeof window !== 'undefined'); var isFirefox = (isBrowser && window.mozInnerScreenX != null); var isFirefox = (isBrowser && (<any>window).mozInnerScreenX != null); function getCaretCoordinates(element, position, options) { export function getCaretCoordinates(element, position, options=null) { if(!isBrowser) { throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser'); } Loading Loading @@ -122,10 +120,8 @@ function getCaretCoordinates(element, position, options) { return coordinates; } if (typeof module != 'undefined' && typeof module.exports != 'undefined') { module.exports = getCaretCoordinates; } else if(isBrowser){ window.getCaretCoordinates = getCaretCoordinates; } }()); // if (typeof module != 'undefined' && typeof module.exports != 'undefined') { // module.exports = getCaretCoordinates; // } else if(isBrowser){ // window.getCaretCoordinates = getCaretCoordinates; // } mention/mention-list.ts +1 −2 Original line number Diff line number Diff line import {Component, ElementRef, Output, EventEmitter} from 'angular2/core'; import {isInputOrTextAreaElement, getContentEditableCaretCoords} from './mention-utils'; declare var getCaretCoordinates:any; import {getCaretCoordinates} from './caret-coords'; /** * Angular 2 Mentions. Loading Loading
README.md +1 −2 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ Copy the mention folder into your own application, or install the package as a d npm install --save ng2-mentions Add the CSS and JS dependencies your index.html: Add the CSS to your index.html: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="ext/textarea-caret-position.js"></script> Add the `[mention]` directive to your input element: Loading
gh-pages/ext/textarea-caret-position.jsdeleted 100644 → 0 +0 −131 Original line number Diff line number Diff line /* From: https://github.com/component/textarea-caret-position */ /* jshint browser: true */ (function () { // The properties that we copy into a mirrored div. // Note that some browsers, such as Firefox, // do not concatenate properties, i.e. padding-top, bottom etc. -> padding, // so we have to do every single property specifically. var properties = [ 'direction', // RTL support 'boxSizing', 'width', // on Chrome and IE, exclude the scrollbar, so the mirror div wraps exactly as the textarea does 'height', 'overflowX', 'overflowY', // copy the scrollbar for IE 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderStyle', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', // https://developer.mozilla.org/en-US/docs/Web/CSS/font 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', // might not make a difference, but better be safe 'letterSpacing', 'wordSpacing', 'tabSize', 'MozTabSize' ]; var isBrowser = (typeof window !== 'undefined'); var isFirefox = (isBrowser && window.mozInnerScreenX != null); function getCaretCoordinates(element, position, options) { if(!isBrowser) { throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser'); } var debug = options && options.debug || false; if (debug) { var el = document.querySelector('#input-textarea-caret-position-mirror-div'); if ( el ) { el.parentNode.removeChild(el); } } // mirrored div var div = document.createElement('div'); div.id = 'input-textarea-caret-position-mirror-div'; document.body.appendChild(div); var style = div.style; var computed = window.getComputedStyle? getComputedStyle(element) : element.currentStyle; // currentStyle for IE < 9 // default textarea styles style.whiteSpace = 'pre-wrap'; if (element.nodeName !== 'INPUT') style.wordWrap = 'break-word'; // only for textarea-s // position off-screen style.position = 'absolute'; // required to return coordinates properly if (!debug) style.visibility = 'hidden'; // not 'display: none' because we want rendering // transfer the element's properties to the div properties.forEach(function (prop) { style[prop] = computed[prop]; }); if (isFirefox) { // Firefox lies about the overflow property for textareas: https://bugzilla.mozilla.org/show_bug.cgi?id=984275 if (element.scrollHeight > parseInt(computed.height)) style.overflowY = 'scroll'; } else { style.overflow = 'hidden'; // for Chrome to not render a scrollbar; IE keeps overflowY = 'scroll' } div.textContent = element.value.substring(0, position); // the second special handling for input type="text" vs textarea: spaces need to be replaced with non-breaking spaces - http://stackoverflow.com/a/13402035/1269037 if (element.nodeName === 'INPUT') div.textContent = div.textContent.replace(/\s/g, '\u00a0'); var span = document.createElement('span'); // Wrapping must be replicated *exactly*, including when a long word gets // onto the next line, with whitespace at the end of the line before (#7). // The *only* reliable way to do that is to copy the *entire* rest of the // textarea's content into the <span> created at the caret position. // for inputs, just '.' would be enough, but why bother? span.textContent = element.value.substring(position) || '.'; // || because a completely empty faux span doesn't render at all div.appendChild(span); var coordinates = { top: span.offsetTop + parseInt(computed['borderTopWidth']), left: span.offsetLeft + parseInt(computed['borderLeftWidth']) }; if (debug) { span.style.backgroundColor = '#aaa'; } else { document.body.removeChild(div); } return coordinates; } if (typeof module != 'undefined' && typeof module.exports != 'undefined') { module.exports = getCaretCoordinates; } else if(isBrowser){ window.getCaretCoordinates = getCaretCoordinates; } }());
index.html +0 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ <!-- 0. Dependancies --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <script src="ext/textarea-caret-position.js"></script> <script src="http://cdn.tinymce.com/4/tinymce.min.js"></script> <!-- 1. Load libraries --> Loading
ext/textarea-caret-position.js→mention/caret-coords.ts +7 −11 Original line number Diff line number Diff line /* From: https://github.com/component/textarea-caret-position */ /* jshint browser: true */ (function () { // The properties that we copy into a mirrored div. // Note that some browsers, such as Firefox, // do not concatenate properties, i.e. padding-top, bottom etc. -> padding, Loading Loading @@ -50,9 +48,9 @@ var properties = [ ]; var isBrowser = (typeof window !== 'undefined'); var isFirefox = (isBrowser && window.mozInnerScreenX != null); var isFirefox = (isBrowser && (<any>window).mozInnerScreenX != null); function getCaretCoordinates(element, position, options) { export function getCaretCoordinates(element, position, options=null) { if(!isBrowser) { throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser'); } Loading Loading @@ -122,10 +120,8 @@ function getCaretCoordinates(element, position, options) { return coordinates; } if (typeof module != 'undefined' && typeof module.exports != 'undefined') { module.exports = getCaretCoordinates; } else if(isBrowser){ window.getCaretCoordinates = getCaretCoordinates; } }()); // if (typeof module != 'undefined' && typeof module.exports != 'undefined') { // module.exports = getCaretCoordinates; // } else if(isBrowser){ // window.getCaretCoordinates = getCaretCoordinates; // }
mention/mention-list.ts +1 −2 Original line number Diff line number Diff line import {Component, ElementRef, Output, EventEmitter} from 'angular2/core'; import {isInputOrTextAreaElement, getContentEditableCaretCoords} from './mention-utils'; declare var getCaretCoordinates:any; import {getCaretCoordinates} from './caret-coords'; /** * Angular 2 Mentions. Loading