Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to replace only the link text by the provided html … #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ var customHtml = '<div style="cursor: pointer; background-color: pink">' +
'<i class="glyphicon glyphicon-ok-sign"></i> Testing Custom </div>';

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");
Expand Down
21 changes: 15 additions & 6 deletions contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,14 +32,20 @@ angular.module('ui.bootstrap.contextMenu', [])

var $a = $('<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)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This curly brace should be moved to previous line for consistency

text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html;
}
else if (typeof item.text !== "undefined")
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This curly brace should be moved to previous line for consistency

text = item.text;
}

Expand Down Expand Up @@ -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))
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This curly brace should be moved to previous line for consistency

text = processTextItem($scope, item, text, event, model, $promises, nestedMenu, $);
}
else if (typeof item.html !== "undefined") {
else if (typeof item.html !== "undefined")
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This curly brace should be moved to previous line for consistency

// leave styling open to dev
text = item.html
text = item.compileHtml ? $compile(angular.element(item.html))($scope) : item.html;
}

$li.append(text);
Expand Down