From 9a13ff5ea4bdc1c3880d2ef43031ec3596f9b57e Mon Sep 17 00:00:00 2001 From: Dieter Geerts Date: Mon, 2 May 2016 15:46:16 +0200 Subject: [PATCH 1/3] Added possibility to replace only the link text by the provided html + added compile option, to support translations. --- README.md | 4 +++- contextMenu.js | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a4d2ad..7b80c56 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,9 @@ var customHtml = '
' + ' Testing Custom
'; var customItem = { - html: customHtml, + html: customHtml, + compileHtml: true, // Defaults false, for compiling translations. + replaceTextByHtml: true, // Defaults false, for using the html in the link instead of completely replace it. enabled: function() {return true}, click: function ($itemScope, $event, value) { alert("custom html"); diff --git a/contextMenu.js b/contextMenu.js index 8a46c15..da962a4 100644 --- a/contextMenu.js +++ b/contextMenu.js @@ -10,7 +10,7 @@ angular.module('ui.bootstrap.contextMenu', []) } }) -.directive('contextMenu', ["$parse", "$q", "CustomService", "$sce", function ($parse, $q, custom, $sce) { +.directive('contextMenu', ["$parse", "$q", "CustomService", "$sce", "$compile", function ($parse, $q, custom, $sce, $compile) { var contextMenus = []; var $currentContextMenu = null; @@ -32,14 +32,20 @@ angular.module('ui.bootstrap.contextMenu', []) var $a = $(''); $a.css("padding-right", "8px"); - $a.attr({ tabindex: '-1', href: '#' }); + $a.attr({tabindex: '-1', href: '#'}); if (typeof item[0] === 'string') { text = item[0]; } else if (typeof item[0] === "function") { text = item[0].call($scope, $scope, event, model); - } else if (typeof item.text !== "undefined") { + } + else if (typeof item.html !== "undefined" && item.replaceTextByHtml) + { + text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html; + } + else if (typeof item.text !== "undefined") + { text = item.text; } @@ -71,12 +77,15 @@ angular.module('ui.bootstrap.contextMenu', []) // if first item is a string, then text should be the string. var text = defaultItemText; - if (typeof item[0] === 'function' || typeof item[0] === 'string' || typeof item.text !== "undefined") { + if (typeof item[0] === 'function' || typeof item[0] === 'string' || typeof item.text !== "undefined" + || (typeof item.html !== "undefined" && item.replaceTextByHtml)) + { text = processTextItem($scope, item, text, event, model, $promises, nestedMenu, $); } - else if (typeof item.html !== "undefined") { + else if (typeof item.html !== "undefined") + { // leave styling open to dev - text = item.html + text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html; } $li.append(text); From 3de5ab99e54ee84da535774450e279d1ae0a0c08 Mon Sep 17 00:00:00 2001 From: Dieter Geerts Date: Tue, 3 May 2016 10:31:55 +0200 Subject: [PATCH 2/3] Changed curly braces to JavaScript styling as requested. --- contextMenu.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/contextMenu.js b/contextMenu.js index da962a4..fda42b7 100644 --- a/contextMenu.js +++ b/contextMenu.js @@ -36,16 +36,11 @@ angular.module('ui.bootstrap.contextMenu', []) if (typeof item[0] === 'string') { text = item[0]; - } - else if (typeof item[0] === "function") { + } else if (typeof item[0] === "function") { text = item[0].call($scope, $scope, event, model); - } - else if (typeof item.html !== "undefined" && item.replaceTextByHtml) - { + } else if (typeof item.html !== "undefined" && item.replaceTextByHtml) { text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html; - } - else if (typeof item.text !== "undefined") - { + } else if (typeof item.text !== "undefined") { text = item.text; } @@ -78,12 +73,9 @@ angular.module('ui.bootstrap.contextMenu', []) var text = defaultItemText; if (typeof item[0] === 'function' || typeof item[0] === 'string' || typeof item.text !== "undefined" - || (typeof item.html !== "undefined" && item.replaceTextByHtml)) - { + || (typeof item.html !== "undefined" && item.replaceTextByHtml)) { text = processTextItem($scope, item, text, event, model, $promises, nestedMenu, $); - } - else if (typeof item.html !== "undefined") - { + } else if (typeof item.html !== "undefined") { // leave styling open to dev text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html; } From 45b44e8484dc2f05a725597cc39aa8bc3ae9850c Mon Sep 17 00:00:00 2001 From: Dieter Geerts Date: Tue, 24 May 2016 13:14:57 +0200 Subject: [PATCH 3/3] Fixed position for scrolling pages (pun intended). --- contextMenu.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contextMenu.js b/contextMenu.js index fda42b7..4eab65b 100644 --- a/contextMenu.js +++ b/contextMenu.js @@ -136,7 +136,7 @@ angular.module('ui.bootstrap.contextMenu', []) $ul.css({ display: 'block', - position: 'absolute', + position: 'fixed', left: leftCoordinate + 'px', top: topCoordinate + 'px' }); @@ -221,7 +221,7 @@ angular.module('ui.bootstrap.contextMenu', []) $ul.attr({ 'role': 'menu' }); $ul.css({ display: 'block', - position: 'absolute', + position: 'fixed', left: event.pageX + 'px', top: event.pageY + 'px', "z-index": 10000 @@ -250,7 +250,7 @@ angular.module('ui.bootstrap.contextMenu', []) $contextMenu.css({ width: '100%', height: height + 'px', - position: 'absolute', + position: 'fixed', top: 0, left: 0, zIndex: 9999