JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.js"></script>
<div ng-app="testApp" ng-controller="ListController">
<div> <strong>Gold: </strong>
{{player.gold}}</div>
<div class="list-group"> <a href="#" class="list-group-item" ng-repeat="item in items" context-menu="menuOptions">
<span class="badge">{{item.cost}}</span>
{{item.name}}
</a>
</div>
</div>
CSS
body > div, body > div > div {
padding: 10px;
}
JavaScript
var app = angular.module('testApp', []);
app.controller('ListController', ['$scope',
function ($scope) {
$scope.player = {
gold: 100
};
$scope.items = [{
name: 'Small Health Potion',
cost: 4
}, {
name: 'Small Mana Potion',
cost: 5
}, {
name: 'Iron Short Sword',
cost: 12
}];
$scope.menuOptions = [{
name: 'Buy',
iconClass: 'glyphicon glyphicon-ok-circle',
onClick: function ($itemScope) {
$scope.player.gold -= $itemScope.item.cost;
}
}, {
name: 'Without Icon',
iconClass: null,
onClick: function ($itemScope) {
$scope.player.gold -= $itemScope.item.cost;
}
},
null, {
name: 'Sell',
iconClass: 'glyphicon glyphicon-pencil',
onClick: function ($itemScope) {
$scope.player.gold += $itemScope.item.cost;
}
}];
}]);
// Inline for demo purposes.
app.directive('contextMenu', function ($parse) {
var renderContextMenu = function ($scope, event, options) {
if (!$) {
var $ = angular.element;
}
$(event.currentTarget).addClass('context');
var $contextMenu = $('<div>');
$contextMenu.addClass('dropdown clearfix');
var $ul = $('<ul>');
$ul.addClass('dropdown-menu');
$ul.attr({
'role': 'menu'
});
$ul.css({
display: 'block',
position: 'absolute',
left: event.pageX + 'px',
top: event.pageY + 'px'
});
angular.forEach(options, function (item, i) {
var $li = $('<li>');
if (item === null) {
$li.addClass('divider');
} else {
$a = $('<a>');
$a.attr({
tabindex: '-1',
href: '#'
});
if (item['iconClass'] !== undefined && item['iconClass'] !== null...