Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions dist/mentio.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,11 @@ angular.module('mentio', [])
};
}],

link: function (scope, element) {
element[0].parentNode.removeChild(element[0]);
$document[0].body.appendChild(element[0]);
link: function (scope, element, attrs) {
if (attrs.mentioApplyElement === undefined) {
element[0].parentNode.removeChild(element[0]);
$document[0].body.appendChild(element[0]);
}
scope.menuElement = element; // for testing

if (scope.parentScope) {
Expand Down Expand Up @@ -606,7 +608,7 @@ angular.module('mentio', [])
scope.adjustScroll = function (direction) {
var menuEl = element[0];
var menuItemsList = menuEl.querySelector('ul');
var menuItem = (menuEl.querySelector('[mentio-menu-item].active') ||
var menuItem = (menuEl.querySelector('[mentio-menu-item].active') ||
menuEl.querySelector('[data-mentio-menu-item].active'));

if (scope.isFirstItemActive()) {
Expand Down Expand Up @@ -694,9 +696,9 @@ angular.module('mentio')

if (selectedElementIsTextAreaOrInput(ctx)) {
coordinates = getTextAreaOrInputUnderlinePosition(ctx, getDocument(ctx).activeElement,
mentionInfo.mentionPosition);
mentionInfo.mentionPosition, selectionEl);
} else {
coordinates = getContentEditableCaretPosition(ctx, mentionInfo.mentionPosition);
coordinates = getContentEditableCaretPosition(ctx, mentionInfo.mentionPosition, selectionEl);
}

// Move the button into place.
Expand Down Expand Up @@ -856,7 +858,7 @@ angular.module('mentio')
}

// public
function replaceTriggerText (ctx, targetElement, path, offset, triggerCharSet,
function replaceTriggerText (ctx, targetElement, path, offset, triggerCharSet,
text, requireLeadingSpace, hasTrailingSpace) {
resetSelection(ctx, targetElement, path, offset);

Expand Down Expand Up @@ -979,7 +981,7 @@ angular.module('mentio')
// public
function getTriggerInfo (ctx, triggerCharSet, requireLeadingSpace, menuAlreadyActive, hasTrailingSpace) {
/*jshint maxcomplexity:11 */
// yes this function needs refactoring
// yes this function needs refactoring
var selected, path, offset;
if (selectedElementIsTextAreaOrInput(ctx)) {
selected = getDocument(ctx).activeElement;
Expand Down Expand Up @@ -1008,7 +1010,7 @@ angular.module('mentio')
(
mostRecentTriggerCharPos === 0 ||
!requireLeadingSpace ||
/[\xA0\s]/g.test
/[([\-\xA0\s]/g.test
(
effectiveRange.substring(
mostRecentTriggerCharPos - 1,
Expand All @@ -1030,7 +1032,7 @@ angular.module('mentio')
if (hasTrailingSpace) {
currentTriggerSnippet = currentTriggerSnippet.trim();
}
if (!leadingSpace && (menuAlreadyActive || !(/[\xA0\s]/g.test(currentTriggerSnippet)))) {
if (!leadingSpace) {
return {
mentionPosition: mostRecentTriggerCharPos,
mentionText: currentTriggerSnippet,
Expand Down Expand Up @@ -1080,7 +1082,7 @@ angular.module('mentio')
return text;
}

function getContentEditableCaretPosition (ctx, selectedNodePosition) {
function getContentEditableCaretPosition (ctx, selectedNodePosition, selectionEl) {
var markerTextChar = '\ufeff';
var markerEl, markerId = 'sel_' + new Date().getTime() + '_' + Math.random().toString().substr(2);

Expand All @@ -1107,7 +1109,12 @@ angular.module('mentio')
top: markerEl.offsetHeight
};

localToGlobalCoordinates(ctx, markerEl, coordinates);
if (selectionEl[0].parentNode === document.body) {
localToGlobalCoordinates(ctx, markerEl, coordinates);
} else {
coordinates.left += markerEl.offsetLeft;
coordinates.top += markerEl.offsetTop;
}

markerEl.parentNode.removeChild(markerEl);
return coordinates;
Expand All @@ -1124,7 +1131,7 @@ angular.module('mentio')
obj = iframe;
iframe = null;
}
}
}
obj = element;
iframe = ctx ? ctx.iframe : null;
while(obj !== getDocument().body) {
Expand All @@ -1139,10 +1146,10 @@ angular.module('mentio')
obj = iframe;
iframe = null;
}
}
}
}

function getTextAreaOrInputUnderlinePosition (ctx, element, position) {
function getTextAreaOrInputUnderlinePosition (ctx, element, position, selectionEl) {
var properties = [
'direction',
'boxSizing',
Expand Down Expand Up @@ -1220,7 +1227,12 @@ angular.module('mentio')
left: span.offsetLeft + parseInt(computed.borderLeftWidth)
};

localToGlobalCoordinates(ctx, element, coordinates);
if (selectionEl[0].parentNode === document.body) {
localToGlobalCoordinates(ctx, element, coordinates);
} else {
coordinates.left += element.offsetLeft;
coordinates.top += element.offsetTop;
}

getDocument(ctx).body.removeChild(div);

Expand Down Expand Up @@ -1251,4 +1263,4 @@ angular.module('mentio')
};
}]);

angular.module("mentio").run(["$templateCache", function($templateCache) {$templateCache.put("mentio-menu.tpl.html","<style>\n.scrollable-menu {\n height: auto;\n max-height: 300px;\n overflow: auto;\n}\n\n.menu-highlighted {\n font-weight: bold;\n}\n</style>\n<ul class=\"dropdown-menu scrollable-menu\" style=\"display:block\">\n <li mentio-menu-item=\"item\" ng-repeat=\"item in items track by $index\">\n <a class=\"text-primary\" ng-bind-html=\"item.label | mentioHighlight:typedTerm:\'menu-highlighted\' | unsafe\"></a>\n </li>\n</ul>");}]);
angular.module("mentio").run(["$templateCache", function($templateCache) {$templateCache.put("mentio-menu.tpl.html","<style>\r\n.scrollable-menu {\r\n height: auto;\r\n max-height: 300px;\r\n overflow: auto;\r\n}\r\n\r\n.menu-highlighted {\r\n font-weight: bold;\r\n}\r\n</style>\r\n<ul class=\"dropdown-menu scrollable-menu\" style=\"display:block\">\r\n <li mentio-menu-item=\"item\" ng-repeat=\"item in items track by $index\">\r\n <a class=\"text-primary\" ng-bind-html=\"item.label | mentioHighlight:typedTerm:\'menu-highlighted\' | unsafe\"></a>\r\n </li>\r\n</ul>");}]);
Loading