Skip to content

Commit

Permalink
Add an option to compile html string to help user can add html string…
Browse files Browse the repository at this point in the history
… with their custom directives.
  • Loading branch information
hieutranagi47 committed Jul 25, 2018
1 parent 1fd65a8 commit 04a0194
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Every menu option is represented by an Object containing the following propertie
| -------- | ---- | ----------- |
| text | Function/String | A function that returns the string or the actual string itself. Either text or html must be specified |
| html | Function/String | A function or string that returns the html to be used for this menu option. Either text or html must be specified |
| compile | Boolean | To compile html string to use a custom directive in the html string |
| click | Function | The function to be called on click of the option|
| enabled | Function/Boolean | A function returning whether the option is enabled or not, or a boolean |
| displayed | Function/Boolean | A function returning whether the option is displayed or not, or a boolean. If not displayed, no element is created at all and nothing related to the item will be executed (events, functions returning children, etc.) |
Expand Down
13 changes: 9 additions & 4 deletions contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// Triggers right after any context menu is opened
ContextMenuOpened: 'context-menu-opened'
})
.directive('contextMenu', ['$rootScope', 'ContextMenuEvents', '$parse', '$q', 'CustomService', '$sce', '$document', '$window',
function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce, $document, $window) {
.directive('contextMenu', ['$rootScope', 'ContextMenuEvents', '$parse', '$q', 'CustomService', '$sce', '$document', '$window', '$compile',
function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce, $document, $window, $compile) {

var _contextMenus = [];
// Contains the element that was clicked to show the context menu
Expand All @@ -50,8 +50,13 @@
// runs the function that expects a jQuery/jqLite element
optionText = item.html($scope);
} else {
// Assumes that the developer already placed a valid jQuery/jqLite element
optionText = item.html;
// Incase we want to compile html string to initialize their custom directive in html string
if (item.compile) {
optionText = $compile(item.html)($scope);
} else {
// Assumes that the developer already placed a valid jQuery/jqLite element
optionText = item.html;
}
}
} else {

Expand Down

0 comments on commit 04a0194

Please sign in to comment.