/* class2context.js creator: Arnau July 2016 version: v0.1 usage: class2context( 'className', "title", [["option1", "functionoption1()"], ["option 2","functionoption2()"]] ); */ /* testing this, not necessary */ var cmCallNum=0; $( document ).ready(function() { $(document).on('contextmenu', function (e) { //e.preventDefault(); /*//testing only console.log('ContextMenus() called, num.' + cmCallNum); cmCallNum++;*/ ContextMenus(); }); $(document).on('click', function (e) { //e.preventDefault(); /*//testing only console.log('ContextMenus() called, num.' + cmCallNum); cmCallNum++;*/ ContextMenus(); }); }); /* MUTATION OBSERVER --detect changes in dom, and re-asign context menus*/ // select the target node //MUTATION DOM var target = document.body; var mutNum=0; var observer = new MutationObserver(function(mutations) { console.log("class2context.js: mutation of dom, num." + mutNum); mutNum++; ContextMenus(); }); // configuration of the observer: var config = { attributes: true, childList: true, characterData: true }; // pass in the target node, as well as the observer options observer.observe(target, config); /* "; aux+=" "; aux+=""; document.getElementById('contextMenus').innerHTML+=aux; //adds the div context menu into the context menus div place } for(var i=0; i