Jack McKalling Posted August 2, 2006 Share Posted August 2, 2006 I am about to use the custom Objects template, to make a script for a default contextmenu override.It should actually become quite cool. There are some questions though, before I begin coding with custom Objects.What is the difference between these ways of supplying method to a property (or event) of an object:myObject.propName=myFunc;myObject.propName="myFunc()";myObject.propName=function myFunc(){...}Or isn't there a difference? Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 There is no difference except the first 2 would have to be defined else where while hte 3 example defines and assigns all in one line.Does the 2nd example really work??? I have never seen it assigned that way before. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 2, 2006 Author Share Posted August 2, 2006 (edited) I don't know, but in case of the property onclick for example (scripts) it would work just as if that function was script to be executed, like in the onclick attribute or other events. Can it work in DOM like this? Edited August 2, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 Generally I use the 1st eaxmple if I do not need to pass any parmamters with it and then useobject.onclick = function(){myFunc(param1,param2)}when I need to pass parameters.I doubt your second example will work it will be considered a string and you cannot assign a string to an event. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 2, 2006 Author Share Posted August 2, 2006 Ah ok.2)And another thing, why is it without those brackets in the first example? Whay is the difference between refering to a function with or without brackets?3)What is the difference between doing this: myObject.prototype.method = function() { ... }myObject.method()And this:function myObject() {this.method = myFunction;}function myFunction() { ... }? Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 none that I know of Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 2, 2006 Author Share Posted August 2, 2006 Thanks for the help :)I will now try to make an object template for a contextmenu object, which can have subobjects (the options) and each one option its own properties, like short description, name, long description (e.g. for the status bar), script, etc.I already have the static html menu working, now I want to create it dynamically by this object So that the user I give this script to, can administrally add nodes in the document and so on.I came to this idea by a fantastic script that beautifully replicates the foldertree model of Windows Explorer. Unfortunately, that script is Dutch, so I can't show it. But take my word for it that it is sublime Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 good idea...using OO javascript will make it easy for you update the control Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 2, 2006 Author Share Posted August 2, 2006 You mean "OOP"? Object Oriented Programming? Not that I know what it is, but I guess that is what I am using now.. My first time, and like it from the beginning. :)The plan is to give this script to friends including forum mates, so they can manage the context menu of their own sites. It should become fully user friendly, with all editable strings and stuff in a main area. Hope to have it done soon Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 actually I did mean OO javascript (Object Oriented JavaScript ) OOP is just a generialization of the Object Oriented concept and doesn't pertain to a specific language Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 2, 2006 Author Share Posted August 2, 2006 Ah okay, I remembered "OOP" from a reaction of justsomeguy somewhere, as a response to a question of mine. I have been considering using OOP (OO Javascript in this case ) for a long while now, but just hadn't the currage to go and try. Even though then I had a reason to begin, I declined because of PHP being a better option in that case. Now, PHP can't be an option, so I started right away :)PHP can do OOP too, with classes. JavaScript doesn't have classes though. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2006 Share Posted August 2, 2006 no it doesn't unforunately, I find it weird doing OOP with javascript, I work with C# everyday and it is fully OOP enabled like C++.Even PHP has some OOP limitations although I they have made many improvements in PHP5...I don't now where it is now compared to say C or C++. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 3, 2006 Share Posted August 3, 2006 PHP can also do OOP another way, I use this ALOT when using mysql. makes it way easier $var->fooso you can take arrays and do that. for example:$array[name] = reportingsjr;echo $array->name;Now thats just an example. not entirely sure if it will in fact work. It should though. This is used widely with classes by doing this: class mysql{public $host;public $user;public $password;public $db;public $connection;public $result; public function connect(){ $this->connection = mysql_connect($this->host, $this->user, $this->pass) or die ("Unable to connect!"); mysql_select_db($this->db) or die ("Unable to select database!"); } public function close(){ mysql_close($this->connection); } public function query($query) { $this->result = mysql_query($query); }}$foo = new mysql;$foo->host = "localhost";$foo->user = "me";$foo->password = "neverguess";$foo->database = "forum";$foo->connect();$foo->query("SELECT * FROM `users` ORDER BY `id`");while($row = mysql_fetch_object($foo->result)){echo "{$row->id} : {$row->name} <br />";}$foo->close(); Thats probably the first ever actual use of a class Ive ever seen lol.Anyways, hope this helped you understand classes and OOP a bit better lol. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 3, 2006 Author Share Posted August 3, 2006 The script is written.But there keep popping up javascript errors, and one of them I couldn't get right...Somewhere, I want to apply two functions to a certain DOM event. But this did not work:...onmouseup=function(){function1();function2();}Actually of course it is different in the script, but I think too complicated to post. Can anyone give me the sollution of this error? No error message come up, but the functions are executed instandly, and the page keeps loading. This applying repeats some times, with different functions. So there are (for the first function name) three different functions, a location reload function, a window print function and a history function. Actually the pageprint dialogbox comes up and the page keeps reloading so the functions are endlesly executed instead of just been applied to an event. Is this clear enough, or should I post the link to this file?This file could be malicious though, becasue of this unwanted infinite loop I can't get rid of. Link to comment Share on other sites More sharing options...
aspnetguy Posted August 3, 2006 Share Posted August 3, 2006 This file could be malicious though, becasue of this unwanted infinite loop I can't get rid of.:)Anyways your simple example should easily work so unless you want to post the code or pm it to me there isn't much more we can do. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 3, 2006 Author Share Posted August 3, 2006 Well, then I post it. But it is partly Dutch, so remind that. Second, it is quite big <html><head><title>My Contextmenu</title><meta name="comment" content="thanks to [url="http://www.dynamicdrive.com/dynamicindex1/contextmenu.htm"]http://www.dynamicdrive.com/....tmenu.htm[/url]" /><style type="text/css">/*<div id="contextmenu"><div class="noitem"><span class="alt">V</span>orige</div><div class="item">Volge<span class="alt">n</span>de</div><div class="hr"> </div><div class="noitem">Ac<span class="alt">h</span>tergrond opslaan als...</div><div class="noitem">Als a<span class="alt">c</span>htergrond gebruiken</div><div class="noitem">Achtergrond <span class="alt">k</span>opiëren</div><div class="noitem">Als b<span class="alt">u</span>reaubladitem instellen...</div><div class="hr"> </div><div class="item"><span class="alt">A</span>lles selecteren</div><div class="noitem"><span class="alt">P</span>lakken</div><div class="hr"> </div><div class="item">Snelkoppeling <span class="alt">m</span>aken</div><div class="item"><span class="alt">T</span>oevoegen aan Favorieten...</div><div class="item"><span class="alt">B</span>ron weergeven</div><div class="hr"> </div><div class="item">C<span class="alt">o</span>dering</div><div class="hr"> </div><div class="item">Af<span class="alt">d</span>rukken</div><div class="item">Vernieu<span class="alt">w</span>en</div><div class="hr"> </div><div class="item">Ei<span class="alt">g</span>enschappen</div></div>*/div#contextmenu { border:solid 1px rgb(157,157,161); background-color:rgb(255,255,255); position:absolute; left:10px; top:10px; width:208px; color:rgb(0,0,0); padding:2px; font-family:Tahoma; font-size:12px;}div.item, div.noitem { border:solid 1px rgb(255,255,255); background-color:rgb(255,255,255); width:100%; color:rgb(0,0,0); padding:0 0 2px 16px; text-decoration:none; cursor:default;}div.hr { border:solid rgb(157,157,161); border-width:1px 0 0; background-color:rgb(255,255,255); width:100%; color:rgb(0,0,0); font-size:0; padding:0; margin:3px 1px 3px;}div.noitem { color:rgb(172,168,153); }span.alt { text-decoration:underline; }</style><script type="text/javascript">var objLocalMenu = new Array;function ContextMenu(strName, numWidth) {this.addOption = addOption;this.buildDOM = buildDOM;this.nodes = new Array;this.id = strName;this.height = 4;this.width = numWidth;this.opened = false;objLocalMenu[this.id] = this;return this;}function addOption(strClass, strText, numAlt, strDesc, strFunc) {var objNode = new menuLayer(strClass, strText, numAlt, strDesc, strFunc);objNode.id = this.id + "_" + this.nodes.length;this.height += (strClass == "hr") ?6 :16;this.nodes[this.nodes.length] = objNode;objLocalMenu[this.id].nodes[objNode.id] = objNode;return objNode;}function menuLayer(strClass, strText, numAlt, strDesc, strFunc) {this.text = strText;this.alt = numAlt;this.desc = strDesc;this.dclass = strClass;this.script = strFunc;}function goHistory(amount) { history.go(amount); }function goPrint() { window.print(); }function goRefresh() { location.reload(); }function CreateMenu1() {var objMenu = new ContextMenu("Background",208);objMenu.addOption("noitem", "Vorige", 0, "Terug naar de vorige pagina", goHistory(-1));objMenu.addOption("item", "Volgende", 5, "Terug naar de volgende pagina", goHistory(1));objMenu.addOption("hr");objMenu.addOption("noitem", "Achtergrond opslaan als...", 2, "");objMenu.addOption("noitem", "Als achtergrond gebruiken", 5, "");objMenu.addOption("noitem", "Achtergrond kopiëren", 12, "");objMenu.addOption("noitem", "Als bureaubladitem instellen...", 5, "");objMenu.addOption("hr");objMenu.addOption("item", "Alles selecteren", 0, "Alle items op deze pagina selecteren");objMenu.addOption("noitem", "Plakken", 0, "De inhoud van het Klembord invoegen op de invoegpositie");objMenu.addOption("hr");objMenu.addOption("item", "Snelkoppeling maken", 14, "");objMenu.addOption("item", "Toevoegen aan Favorieten...", 0, "");objMenu.addOption("item", "Bron weergeven", 0, "Bron (HTML) van deze pagina weergeven");objMenu.addOption("hr");objMenu.addOption("item", "Codering", 1, "");objMenu.addOption("hr");objMenu.addOption("item", "Afdrukken", 2, "", goPrint());objMenu.addOption("item", "Vernieuwen", 7, "De inhoud van het huidige frame vernieuwen", goRefresh());objMenu.addOption("hr");objMenu.addOption("item", "Eigenschappen", 2, "De eigenschappen van de huidige selectie bewerken");return objMenu;}function buildDOM() {var HoverOver = " onmouseover=function(){this.style.borderColor='rgb(178,180,191)';" + "this.style.backgroundColor='rgb(187,183,199)';}";var HoverOut = " onmouseout=function(){this.style.borderColor='rgb(255,255,255)';" + "this.style.backgroundColor='rgb(255,255,255)';}";var objNodesLayer = document.createElement("div");objNodesLayer.setAttribute("id","contextmenu");objNodesLayer.style.display = (this.opened) ?"block" :"none";for (var n=0; n<this.nodes.length; n++) {var Node = this.nodes[n];if (Node.dclass != "hr") {var Char = Node.text.substr(Node.alt,1);var Text = Node.text.replace(Char,"<span class=\"alt\">" + Char + "</span>");var Click = " onmouseup=function(){objLocalMenu[" + this.id + "].nodes[" + this.id + "_" + n + "].script;MenuVerbergen;}";var objNodeLayer = "\n<div class=\"" + Node.dclass + "\"";objNodeLayer += HoverOver + HoverOut + Click + ">" + Text + "</div>"; }else { objNodeLayer = "\n<div class=\"hr\"> </div>"; }objNodesLayer.innerHTML += objNodeLayer; }document.appendChild(objNodesLayer);}function MenuStarten(e) {var rightedge = (document.all) ?document.body.clientWidth-event.clientX :window.innerWidth-e.clientX;var bottomedge = (document.all) ?document.body.clientHeight-event.clientY :window.innerHeight-e.clientY;var Mleft; var Mtop;var Mwidth = 208; var Mheight = 330;if (rightedge < Mwidth)Mleft = (document.all) ?((event.clientX-Mwidth > 0) ?document.body.scrollLeft+event.clientX-Mwidth :document.body.scrollLeft) : ((e.clientX-Mwidth > 0) ?window.pageXOffset+e.clientX-Mwidth :window.pageXOffset)elseMleft = (document.all) ?document.body.scrollLeft+event.clientX :window.pageXOffset+e.clientXif (bottomedge < Mheight)Mtop = (document.all) ?((event.clientY-Mheight > 0) ?document.body.scrollTop+event.clientY-Mheight :document.body.scrollTop) : ((e.clientX-Mheight > 0) ?window.pageYOffset+e.clientY-Mheight :window.pageYOffset)elseMtop = (document.all) ?document.body.scrollTop+event.clientY :window.pageYOffset+e.clientYvar Menu = document.getElementById("contextmenu");Menu.style.left = Mleft; Menu.style.top = Mtop; Menu.style.display = "block";return false; }function CreateMenus() {objMenu = CreateMenu1(); objMenu.buildDOM();}function MenuVerbergen(e) {if (!document.getElementById("contextmenu")) { return; }var menuElement = document.getElementById("contextmenu");if (document.all){ if (event.srcElement != menuElement && event.srcElement.parentNode != menuElement && event.srcElement.parentNode.parentNode != menuElement) { document.body.innerHTML = ""; }}else {if (e.target != menuElement && e.target.parentNode != menuElement && e.target.parentNode.parentNode != menuElement){ document.body.innerHTML = ""; }}return; }CreateMenus();document.oncontextmenu=MenuStarten;document.onmousedown=MenuVerbergen;</script></head><body><p>This is some text. Click with the right mouse button to activate the custom contextmenu.</p></body></html> Link to comment Share on other sites More sharing options...
TwoD Posted August 3, 2006 Share Posted August 3, 2006 And another thing, why is it without those brackets in the first example? Whay is the difference between refering to a function with or without brackets?Just doing myFunc will return a "handle" to the function object without executing the code in it.myFunc() will execute the code and only return what's specificed by the executed return statement in that function.What is the difference between doing this:myObject.prototype.method = function() { ... }...And this:function myObject() {this.method = myFunction;}function myFunction() { ... }Read all about it here: Private Members in JavaScript.The differences might seem small, but they can be used in powerful ways. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 3, 2006 Author Share Posted August 3, 2006 Can you help me with the (quite complicated) code in the codebox above? Please copy it to an empty document in eg. notepad, or it would be troubled to read due to the length. (it got me some time to paste it between the width of this forum though, as the codebox does not wrap)Notice the html that is commented out, that is the example of html that should come out in the end. And it should be exactly the same as the default context menu if it worked Link to comment Share on other sites More sharing options...
TwoD Posted August 3, 2006 Share Posted August 3, 2006 The problem lies on these lines: <html><head><title>My Contextmenu</title><meta name="comment" content="thanks to [url="http://www.dynamicdrive.com/....tmenu.htm""]http://www.dynamicdrive.com/....tmenu.htm"[/url] /><style type="text/css">/*<div id="contextmenu"><div class="noitem"><span class="alt">V</span>orige</div><div class="item">Volge<span class="alt">n</span>de</div><div class="hr"> </div><div class="noitem">Ac<span class="alt">h</span>tergrond opslaan als...</div><div class="noitem">Als a<span class="alt">c</span>htergrond gebruiken</div><div class="noitem">Achtergrond <span class="alt">k</span>opiëren</div><div class="noitem">Als b<span class="alt">u</span>reaubladitem instellen...</div><div class="hr"> </div><div class="item"><span class="alt">A</span>lles selecteren</div><div class="noitem"><span class="alt">P</span>lakken</div><div class="hr"> </div><div class="item">Snelkoppeling <span class="alt">m</span>aken</div><div class="item"><span class="alt">T</span>oevoegen aan Favorieten...</div><div class="item"><span class="alt">B</span>ron weergeven</div><div class="hr"> </div><div class="item">C<span class="alt">o</span>dering</div><div class="hr"> </div><div class="item">Af<span class="alt">d</span>rukken</div><div class="item">Vernieu<span class="alt">w</span>en</div><div class="hr"> </div><div class="item">Ei<span class="alt">g</span>enschappen</div></div>*/div#contextmenu {border:solid 1px rgb(157,157,161);background-color:rgb(255,255,255);position:absolute; left:10px; top:10px;width:208px; color:rgb(0,0,0); padding:2px;font-family:Tahoma; font-size:12px;}div.item, div.noitem {border:solid 1px rgb(255,255,255);background-color:rgb(255,255,255);width:100%; color:rgb(0,0,0);padding:0 0 2px 16px;text-decoration:none; cursor:default;}div.hr {border:solid rgb(157,157,161); border-width:1px 0 0;background-color:rgb(255,255,255);width:100%; color:rgb(0,0,0);font-size:0; padding:0; margin:3px 1px 3px;}div.noitem { color:rgb(172,168,153); }span.alt { text-decoration:underline; }</style><script type="text/javascript">var objLocalMenu = new Array;function ContextMenu(strName, numWidth) {this.addOption = addOption;this.buildDOM = buildDOM;this.nodes = new Array;this.id = strName;this.height = 4;this.width = numWidth;this.opened = false;objLocalMenu[this.id]=new Array()}function addOption(strClass, strText, numAlt, strDesc, Func) {var objNode = new menuLayer(strClass, strText, numAlt, strDesc);objNode.id = this.id + "_" + this.nodes.length;this.height += (strClass == "hr") ?6 :16;this.nodes[this.nodes.length] = objNode;objLocalMenu[this.id][objLocalMenu[this.id].length]=Func||function(){}; // use a default empty function if none is defined.}function menuLayer(strClass, strText, numAlt, strDesc) {this.text = strText;this.alt = numAlt;this.desc = strDesc;this.dclass = strClass;}function goBack(){history.go(-1); }function goForward() {history.go(1); }function goPrint() {window.print(); }function goRefresh() {location.reload(); }function CreateMenu1() {var objMenu = new ContextMenu("Background",208);objMenu.addOption("noitem", "Vorige", 0, "Terug naar de vorige pagina", goBack);objMenu.addOption("item", "Volgende", 5, "Terug naar de volgende pagina", goForward);objMenu.addOption("hr");objMenu.addOption("noitem", "Achtergrond opslaan als...", 2, "");objMenu.addOption("noitem", "Als achtergrond gebruiken", 5, "");objMenu.addOption("noitem", "Achtergrond kopiëren", 12, "");objMenu.addOption("noitem", "Als bureaubladitem instellen...", 5, "");objMenu.addOption("hr");objMenu.addOption("item", "Alles selecteren", 0, "Alle items op deze pagina selecteren");objMenu.addOption("noitem", "Plakken", 0,"De inhoud van het Klembord invoegen op de invoegpositie");objMenu.addOption("hr");objMenu.addOption("item", "Snelkoppeling maken", 14, "");objMenu.addOption("item", "Toevoegen aan Favorieten...", 0, "");objMenu.addOption("item", "Bron weergeven", 0, "Bron (HTML) van deze pagina weergeven");objMenu.addOption("hr");objMenu.addOption("item", "Codering", 1, "");objMenu.addOption("hr");objMenu.addOption("item", "Afdrukken", 2, "", goPrint);objMenu.addOption("item", "Vernieuwen", 7,"De inhoud van het huidige frame vernieuwen", goRefresh);objMenu.addOption("hr");objMenu.addOption("item", "Eigenschappen", 2,"De eigenschappen van de huidige selectie bewerken");return objMenu;}function buildDOM() { var objNodesLayer = document.createElement("div"); objNodesLayer.setAttribute("id","contextmenu"); objNodesLayer.style.display = (this.opened) ?"block" :"none"; var me=this // me is needed to keep a reference to the menu object. // Inside the event handler functions, this will be linked to the element itself. // me will be accessible by the event functions because they are nested in the buildDOM function. for (var n=0; n<this.nodes.length; n++) { var Node = this.nodes[n]; var NodeDiv=document.createElement('div'); if (Node.dclass != "hr") { var Char = Node.text.substr(Node.alt,1); var Text = Node.text.replace(Char,"<span class=\"alt\">" + Char + "</span>"); NodeDiv.innerHTML=Text; NodeDiv.className=Node.dclass; NodeDiv.onmouseup=new Function("objLocalMenu['"+this.id+"']["+n+"]();MenuVerbergen();") NodeDiv.onmouseover=function(){ this.style.borderColor='rgb(178,180,191)'; this.style.backgroundColor='rgb(187,183,199)'; }; NodeDiv.onmouseout=function(){ this.style.borderColor='rgb(255,255,255)'; this.style.backgroundColor='rgb(255,255,255)'; }; } else { NodeDiv.className = "hr"; } objNodesLayer.appendChild(NodeDiv); NodeDiv=null; // Needed to stay away from memory leaks. } document.body.appendChild(objNodesLayer);}function MenuStarten(e) { var rightedge = (document.all)?document.body.clientWidth-event.clientX :window.innerWidth-e.clientX; var bottomedge = (document.all)?document.body.clientHeight-event.clientY :window.innerHeight-e.clientY; var Mleft; var Mtop; var Mwidth = 208; var Mheight = 330; if (rightedge < Mwidth){ Mleft = (document.all)?((event.clientX-Mwidth > 0)?document.body.scrollLeft+event.clientX-Mwidth :document.body.scrollLeft): ((e.clientX-Mwidth > 0)?window.pageXOffset+e.clientX-Mwidth :window.pageXOffset) } else{ Mleft = (document.all) ?document.body.scrollLeft+event.clientX :window.pageXOffset+e.clientX } if (bottomedge < Mheight){ Mtop = (document.all)?((event.clientY-Mheight > 0)?document.body.scrollTop+event.clientY-Mheight :document.body.scrollTop): ((e.clientX-Mheight > 0)?window.pageYOffset+e.clientY-Mheight :window.pageYOffset) } else{ Mtop = (document.all) ?document.body.scrollTop+event.clientY :window.pageYOffset+e.clientY } var Menu = document.getElementById("contextmenu"); Menu.style.left = Mleft; Menu.style.top = Mtop; Menu.style.display = "block"; return false;}function CreateMenus() {var objMenu1 = CreateMenu1(); objMenu1.buildDOM();}function MenuVerbergen(e) { if (!document.getElementById("contextmenu")) { return; } var menuElement = document.getElementById("contextmenu"); if (document.all){ if (event.srcElement != menuElement && event.srcElement.parentNode != menuElement && event.srcElement.parentNode.parentNode != menuElement){ document.body.innerHTML = ""; } } else { if (e.target != menuElement && e.target.parentNode != menuElement&& e.target.parentNode.parentNode != menuElement){ document.body.innerHTML = ""; } } return;}document.oncontextmenu=MenuStarten;document.onmousedown=MenuVerbergen;</script></head><body onload="CreateMenus();"><p>This is some text. Click with the right mouse button to activate the custom contextmenu.</p></body></html> Crappy non-scrolling codeboxes... Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 4, 2006 Author Share Posted August 4, 2006 (edited) Thank you so much! Of cource this document was full of mistakes, and I even knew where to look for the mistakes (I know it had to do something with those two functions in the eventhandler within the buildDOM function). But this is my first time OOP-ing, so that doesn't matter.Indeed it destroys the page, so I see. But the function MenuVerbergen (translated: HideMenu) was about determining if the menu was clicked or not, if not, the menu should dissappear. Well, it was not finished indeed, I forgot to change the document.body.innerHTML. First, I had the static HTML menu that is now commented out and moved to inside the head section. Then this emptying of the innerHTML was enough. Now there is no HTML left to empty except the original html, it should empty not the innerHTML but hide the menu (by changing the "opened" property of the menu root) sorry I forgot to write that piece of code.But what about those errors? I keep getting an error about the lines in the MenuStarten (translated: StartMenu) and that objects are needed or something.[*Important:]I have build this script with the idea in the back of my mind that various menus should be able to be created, one for each part of your page. If someone is the owner of this script, and he created several menus with these functions, the users of the online version of his pages should get different menus with clicking on different things on the page. But I haven't thought out how to determine what the user clicked, and how to open the respective menu then. This is why the objLocalMenu is an array with in the first element the first menu, so it can hold more menus.[*Edit:]Nevermind the codeboxes, now that it does work partially without an infinit loop, use my online document instead:http://dhost.info/profmemberone/Pages/contextmenu.htm Edited August 4, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 4, 2006 Author Share Posted August 4, 2006 *screems*Yahooo it works Thanks for everything!The menu opens correctly at the correct place, it closes when activated (enabled option clicked) or outside the menu is clicked, and opens again if the outside click was a new call to it :)Now, it is now ready yet, no, but I am past the errors. Now I have to make it so, that the correct menu is opened when you click on something. I have to think that out first, I couldn't do that earlier, without the menu actually working which it does right now.Look here: http://dhost.info/profmemberone/Pages/contextmenu.htm Link to comment Share on other sites More sharing options...
TwoD Posted August 4, 2006 Share Posted August 4, 2006 Hmm, I forgot to remove a part there.The me variable is never used so you can remove it and the comment below.I was going to make the event handler in another way first, but it turned out to be easer the way it's now. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 4, 2006 Author Share Posted August 4, 2006 I fixed it. I fixed also some other things, including something about the opening and closing of the menu, I added another argument "Activated". This argument is used to determine (on hiding of the menu) if an option is actually activated, if so, do hide the menu.I have been messing around with IE only commands to simulate the options of the default menu, like select everyting on a page and add to favorites (works nicely). Now, this selecting causes the contextmenu itself also to be selected while it does is part of the page itself, still. I don't want that menu be part of the selection when I choose option All Select, and I don't want the user to be able to select the options at all either. Next, I want (like) to simulate the View Source option. But, after research, I came to the conclusion this option has been taken out of IE6+ (or whatever) due to security. And I am talking about "view-source:url". If there is no way of actually activating the view source command, then I won't add this option to the custom context menu, but isn't there? Can you help me to find these answers, and possibly more commands to execute for the rest of the options? (and how to determine if there is an history item before or after the current document)? Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 5, 2006 Author Share Posted September 5, 2006 I am experiencing some little troubles with my contextmenu concerning browser compatibility.When my friend (vti) opens my page, the custom menu doesn't replace the default menu, they come up simultaniously. Thus, I conclude that something with his browser (same version of same browser I use ) blockes something typically from the script.Can anyone help me why the script is probably not cross-browser, and what would you suggest to make it cross-browser (or whatever that solves this issue) ? Link to comment Share on other sites More sharing options...
Webworldx Posted September 10, 2006 Share Posted September 10, 2006 Without knowing what browser he's using - and what (if any) extensions he has running i'm not sure what we can do for you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now