Skip to content

Commit

Permalink
fix: add default empty option
Browse files Browse the repository at this point in the history
  • Loading branch information
josetaira committed Oct 8, 2017
1 parent 4a92d4f commit 41aa90f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce) {
}

$li.append(optionText);

return optionText;
};

/**
Expand All @@ -133,7 +135,7 @@ function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce) {
var text = DEFAULT_ITEM_TEXT;
var currItemParam = angular.extend({}, params);
var item = params.item;

currItemParam.nestedMenu = nestedMenu;
currItemParam.enabled = resolveBoolOrFunc(item.enabled || item[2], params);
currItemParam.text = createAndAddOptionText(currItemParam);
Expand Down Expand Up @@ -241,10 +243,7 @@ function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce) {
});
});
} else {
$li.on('click', function ($event) {
$event.preventDefault();
});
$li.addClass('disabled');
setElementDisabled($li);
}
};

Expand Down Expand Up @@ -348,6 +347,13 @@ function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce) {
}
});

if ($ul.children().length === 0) {
var $emptyLi = angular.element('<li>');
setElementDisabled($emptyLi);
$emptyLi.html('<a>empty</a>');
$ul.append($emptyLi);
}

$(document).find('body').append($ul);

doAfterAllPromises(params);
Expand Down Expand Up @@ -546,6 +552,13 @@ function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce) {
$ul.append($li);
}

function setElementDisabled($li) {
$li.on('click', function ($event) {
$event.preventDefault();
});
$li.addClass('disabled');
}

return function ($scope, element, attrs) {
var openMenuEvent = "contextmenu";
if(attrs.contextMenuOn && typeof(attrs.contextMenuOn) === "string"){
Expand Down
5 changes: 3 additions & 2 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ angular.module('app', ['ui.bootstrap.contextMenu'])
text: 'Disabled object-based option',
enabled: function () {
return false;
}
},
},
{
text: function() { return 'Text Using Function'; },
hasBottomDivider: function () {
return $scope.showHiddenOption;
}
},
children: [],
},
{
html: function() { return '<a><b>HTML Using Function</b></a>'; },
Expand Down

0 comments on commit 41aa90f

Please sign in to comment.