From 58688bde6d1ceaa4d78e416e0701ba39701e1b39 Mon Sep 17 00:00:00 2001
From: Nuno Santos ')
- .appendTo(document.body);
- if (settings.title) {
- $('').text(settings.title).appendTo(menu);
+ // merge them
+ $.extend(settings, menuData);
+
+ // Build popup menu HTML
+ function createMenu(e) {
+ var menu = $('
')
+ .appendTo(document.body);
+ if (settings.title) {
+ $('').text(settings.title).appendTo(menu);
+ }
+ var activeItems = 0;
+ settings.items.forEach(function (item) {
+ if (item.isActive && !item.isActive()) {
+ return;
+ }
+ if (item) {
+ var rowCode = '
');
+ icon.attr('src', item.icon);
+ icon.insertBefore(row.find('.itemTitle'));
+ }
+ row.find('.itemTitle').text(item.label);
+
+ if (item.isEnabled != undefined && !item.isEnabled()) {
+ row.addClass('disabled');
+ } else if (item.action) {
+ row.find('.' + settings.linkClickerClass).click(function () {
+ item.action(e);
+ });
+ }
+ activeItems++;
+ } else {
+ $('').appendTo(menu);
+ }
+ });
+
+ if (activeItems === 0) {
+ menu.remove();
+ return;
+ }
+
+ menu.find('.' + settings.headerClass).text(settings.title);
+ return menu;
}
- if (item.isActive && !item.isActive()) {
- return;
- }
- settings.items.forEach(function(item) {
- if (item) {
- var rowCode = '
';
- // rowCode += '';
- var row = $(rowCode).appendTo(menu);
- if(item.icon){
- var icon = $('
');
- icon.attr('src', item.icon);
- icon.insertBefore(row.find('.itemTitle'));
+
+ // On contextmenu event (right click)
+ this.on('contextmenu', function (e) {
+ if (settings.mandatoryClass && $(e.target).closest('.' + settings.mandatoryClass).length <= 0) {
+ return;
}
- row.find('.itemTitle').text(item.label);
-
- if (item.isEnabled != undefined && !item.isEnabled()) {
- row.addClass('disabled');
- } else if (item.action) {
- row.find('.'+settings.linkClickerClass).click(function () { item.action(e); });
+ var menu = createMenu(e)
+ .show();
+
+ var left = e.pageX + 5, /* nudge to the right, so the pointer is covering the title */
+ top = e.pageY;
+ if (top + menu.height() >= $(window).height()) {
+ top -= menu.height();
+ }
+ if (left + menu.width() >= $(window).width()) {
+ left -= menu.width();
}
- } else {
- $('').appendTo(menu);
- }
- });
- menu.find('.' + settings.headerClass ).text(settings.title);
- return menu;
- }
+ // Create and show menu
+ menu.css({zIndex: 1000001, left: left, top: top})
+ .on('contextmenu', function () {
+ return false;
+ });
- // On contextmenu event (right click)
- this.on('contextmenu', function(e) {
- var menu = createMenu(e)
- .show();
-
- var left = e.pageX + 5, /* nudge to the right, so the pointer is covering the title */
- top = e.pageY;
- if (top + menu.height() >= $(window).height()) {
- top -= menu.height();
- }
- if (left + menu.width() >= $(window).width()) {
- left -= menu.width();
- }
+ // Cover rest of page with invisible div that when clicked will cancel the popup.
+ var bg = $('')
+ .css({left: 0, top: 0, width: '100%', height: '100%', position: 'absolute', zIndex: 1000000})
+ .appendTo(document.body)
+ .on('contextmenu click', function () {
+ // If click or right click anywhere else on page: remove clean up.
+ bg.remove();
+ menu.remove();
+ return false;
+ });
- // Create and show menu
- menu.css({zIndex:1000001, left:left, top:top})
- .on('contextmenu', function() { return false; });
+ // When clicking on a link in menu: clean up (in addition to handlers on link already)
+ menu.find('a').click(function () {
+ bg.remove();
+ menu.remove();
+ });
- // Cover rest of page with invisible div that when clicked will cancel the popup.
- var bg = $('')
- .css({left:0, top:0, width:'100%', height:'100%', position:'absolute', zIndex:1000000})
- .appendTo(document.body)
- .on('contextmenu click', function() {
- // If click or right click anywhere else on page: remove clean up.
- bg.remove();
- menu.remove();
+ // Cancel event, so real browser popup doesn't appear.
return false;
- });
-
- // When clicking on a link in menu: clean up (in addition to handlers on link already)
- menu.find('a').click(function() {
- bg.remove();
- menu.remove();
});
- // Cancel event, so real browser popup doesn't appear.
- return false;
- });
-
- return this;
+ return this;
};