/* 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); /* "; // function class2context(classgiv, title, options){ classgiv=JSON.parse(JSON.stringify(classgiv)); if(document.getElementById("context"+classgiv)) { //toastr.success("alreadyExist"); }else{ var aux=""; aux+="