[Proto-Scripty] Re: Using a prototype function in dynamic content.
$(div).update(thereturn); That did the trick! It's true that I don't make as much use of prototype as I could or should. Most of the js/ajax on the site is written from scratch (way back when I was learning how to use ajax). I added prototype later on to do some of the 'bells and whistles' stuff. I will certainly take the time to read the api as I'm sure there are all sorts of things it could help with on the site. Many thanks, Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Hi, if (http_request.readyState == 4) { if (http_request.status == 200) { document.getElementById('load').innerHTML = ; You're not using Ajax.Request[1] or Ajax.Updater[2]? This is my onSuccess handler, how do I apply evalScripts? DJ and I are talking about a Prototye onSuccess handler for one of the two features above. document.getElementById(div).innerHTML = thereturn; Your code is setting the innerHTML property directly. If you just change that line to use Element#update instead, #update will handle eval'ing the scripts for you: $(div).update(thereturn); Altenately, keep setting innerHTML directly (although #update does some very handy things for you) and then after doing that, call String#evalScripts() directly: document.getElementById(div).innerHTML = thereturn; thereturn.evalScripts(); String#evalScripts is a method Prototype adds to the String prototype and so it's available on all strings. Details here.[4] Looking at your quoted code, you're not making much use of Prototype at all -- not even the $() function! (So much more compact than document.getElementById.) I suggest taking an hour to read through the API docs[5] front-to-back to get an idea of what's on offer. It literally takes an hour and saves you no end of time in the long run. May also be worth reading through some stuff on the unofficial wiki [6]. [1] http://prototypejs.org/api/ajax/request [2] http://prototypejs.org/api/ajax/updater [3] http://prototypejs.org/api/element/update [4] http://prototypejs.org/api/string/evalScripts [5] http://prototypejs.org/api [6] http://proto-scripty.wikidot.com/ HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 4, 1:22 am, Drum csteph2...@gmail.com wrote: if you need to do it yourself, you'd use String#evalScripts on the responseText member of the Ajax.Response passed into your onSuccess handler. Sorry, I still don't understand. This is my onSuccess handler, how do I apply evalScripts? if (http_request.readyState == 4) { if (http_request.status == 200) { document.getElementById('load').innerHTML = ; var thereturn = http_request.responseText; document.getElementById(div).innerHTML = thereturn; } else { alert(error); } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
if you need to do it yourself, you'd use String#evalScripts on the responseText member of the Ajax.Response passed into your onSuccess handler. Sorry, I still don't understand. This is my onSuccess handler, how do I apply evalScripts? if (http_request.readyState == 4) { if (http_request.status == 200) { document.getElementById('load').innerHTML = ; var thereturn = http_request.responseText; document.getElementById(div).innerHTML = thereturn; } else { alert(error); } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Hi, I wasn't talking about String#evalScripts function, I was talking about the evalScripts *option* on Ajax.Updater: http://prototypejs.org/api/ajax/updater If you're not using Ajax.Updater, if you're doing the update yourself, Element#update[1] will eval the scripts for you as part of its processing. But if you need to do it yourself, you'd use String#evalScripts on the responseText member of the Ajax.Response passed into your onSuccess handler. [1] http://prototypejs.org/api/element/update HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 7:26 pm, Drum csteph2...@gmail.com wrote: Ah, now, that's interesting. I did try to use evalScripts, but I couldn't find any clear examples of how or where to apply it. I tried putting it in the places it seemed logical, but without effect. So, ok, I have an HTML page includes an onclick to fetch some content which will include scripts. The JS functions to handle this are in an external file. Do I put the evalScripts() in onclick=getStuff(param, param).evalScipts(); or do I apply it to the returned text before putting it in innerHTML like var thereturn = http_request.responseText.evalScripts(); document.getElementById(div).innerHTML = thereturn; I tried both, but couldn't get either to work. C On 31 July, 11:13, T.J. Crowder t...@crowdersoftware.com wrote: Hi, You're using the evalScripts option in your ajax call? Can you produce a small, self-contained example[1]? [1]http://proto-scripty.wikidot.com/self-contained-test-page -- T.J. :-) On Jul 31, 1:22 am, Drum csteph2...@gmail.com wrote: P.S. I tried with both delete eds[id]; and eds[id] = undefined. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Ah, now, that's interesting. I did try to use evalScripts, but I couldn't find any clear examples of how or where to apply it. I tried putting it in the places it seemed logical, but without effect. So, ok, I have an HTML page includes an onclick to fetch some content which will include scripts. The JS functions to handle this are in an external file. Do I put the evalScripts() in onclick=getStuff(param, param).evalScipts(); or do I apply it to the returned text before putting it in innerHTML like var thereturn = http_request.responseText.evalScripts(); document.getElementById(div).innerHTML = thereturn; I tried both, but couldn't get either to work. C On 31 July, 11:13, T.J. Crowder t...@crowdersoftware.com wrote: Hi, You're using the evalScripts option in your ajax call? Can you produce a small, self-contained example[1]? [1]http://proto-scripty.wikidot.com/self-contained-test-page -- T.J. :-) On Jul 31, 1:22 am, Drum csteph2...@gmail.com wrote: P.S. I tried with both delete eds[id]; and eds[id] = undefined. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Hi, You're using the evalScripts option in your ajax call? Can you produce a small, self-contained example[1]? [1] http://proto-scripty.wikidot.com/self-contained-test-page -- T.J. :-) On Jul 31, 1:22 am, Drum csteph2...@gmail.com wrote: P.S. I tried with both delete eds[id]; and eds[id] = undefined. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Ok, thanks. I think I understand the reasoning here, but I can't get my actual example to work. This is the script as it appears in the initially loaded page and also as it is in the html snippets bought in by ajax. div id=kwdisp0101some keyword/div script if(editor0101){ editor0101.dispose(); editor0101 = undefined; } var editor0101; editor0101 = new Ajax.InPlaceEditor('kwdisp0101','./addkw.php',{size: 17,callback: function(form, value) { return 'oldwd=some %20keywordidx=section-idmyparam=' + escape(value)}});\n; /script The 0101 is an example, I do this for each keyword in the list and derive the numbers from some php code, net will be 0102, 0103 0201 0202 c. This goes for both the editor var name in the js, and for the dic id in the HTML. Have I missed or misunderstood something? (it's been a long day...) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Hi, Really close. :-) But you're running afoul of how eval handles the var statement. (If you'd just left the var statement out entirely, it probably would have worked thanks to the horror of implicit globals [1], but you'd be cluttering up the window namespace something fierce.) Also, you're repeating a lot of code. Instead, I'd suggest declaring a hash of editors on your main page (not the stuff loaded dynamically) and a function for adding or replacing one; and may as well wrap those up into just the one global symbol: In your main script: * * * * var ipeManager = { editors: {}, addOrReplaceEditor: function(id, url, size, paramstr) { var eds; eds = this.editors; if (eds[id]) { eds[id].dispose(); eds[id] = undefined; // Or: delete eds[id]; } eds[id] = new Ajax.InPlaceEditor( id, url, { size: size, callback: function(form, value) { return paramstr + escape(value); } } ); } }; * * * * Then the dynamic stuff can be much simpler: * * * * div id=kwdisp0101some keyword/div script ipeManager.addOrReplaceEditor( kwdisp0101, './addkw.php', 17, 'oldwd=some%20keywordidx=section-idmyparam=' ); /script * * * * [1] http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jul 30, 5:51 pm, Drum csteph2...@gmail.com wrote: Ok, thanks. I think I understand the reasoning here, but I can't get my actual example to work. This is the script as it appears in the initially loaded page and also as it is in the html snippets bought in by ajax. div id=kwdisp0101some keyword/div script if(editor0101){ editor0101.dispose(); editor0101 = undefined;} var editor0101; editor0101 = new Ajax.InPlaceEditor('kwdisp0101','./addkw.php',{size: 17,callback: function(form, value) { return 'oldwd=some %20keywordidx=section-idmyparam=' + escape(value)}});\n; /script The 0101 is an example, I do this for each keyword in the list and derive the numbers from some php code, net will be 0102, 0103 0201 0202 c. This goes for both the editor var name in the js, and for the dic id in the HTML. Have I missed or misunderstood something? (it's been a long day...) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Sorry, but it's still not working for me. I have my main page as it initially loads with this in the HEAD script language=javascript type=text/javascript var ipeManager = { editors: {}, addOrReplaceEditor: function(id, url, size, paramstr){ var eds; eds = this.editors; if (eds[id]) { eds[id].dispose(); delete eds[id]; // Or: eds[id] = undefined; } eds[id] = new Ajax.InPlaceEditor(id,url,{size: size,callback: function(form, value) {return paramstr + escape(value);}}); } }; /script Then, in the body of the document is the keyword list: div id=kwdisp0101A keyword/div ...a bunch of other stuff... script ipeManager.addOrReplaceEditor('kwdisp0101','./addkw.php', 17,'oldwd=A%20keywordidx=subject-idmyparam='); /script div id=kwdisp0102Another keyword/div ...a bunch of other stuff... script ipeManager.addOrReplaceEditor('kwdisp0102','./addkw.php', 17,'oldwd=A%20keywordidx=subject-idmyparam='); /script div id=kwdisp0103Yet another keyword/div ...a bunch of other stuff... script ipeManager.addOrReplaceEditor('kwdisp0103','./addkw.php', 17,'oldwd=Yet%20another%20keywordidx=subject-idmyparam='); /script The content called in by ajax is basically a copy of the keyword list, and has exactly the same structure and IDs as the list above. On loading the initial page it works fine, but when the ajax content has replaced the original list, it no longer works. No Firebug errors, no nothing. Did I miss something out? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Using a prototype function in dynamic content.
Hi, If you replace an element, even if the replacement has the same ID as the original, you will have toinitialize a new InPlaceEditor. It grabs a reference to the element instance, which is different for the replacement than for the original. It would be best to *also* remove the InPlaceEditor for the previous version of the element, so as to free up memory. So, say you have this div: div id='content' ... p id='editme'Blah blah blah/p ... /div And you put an editor on the paragraph: new Ajax.InPlaceEditor('editme', url); If you replace it: $('div').update('p id=editmenew content/p'); ...then the previous paragraph element ceases to exist, and there's nothing to indicate that the new element has an InPlaceEditor. Instead, remember a reference to the editor when first setting it up: var editor; ... editor = new Ajax.InPlaceEditor('editme', url); ...and then destroy it and recreate it when updating: if (editor) { editor.dispose(); editor = undefined; } $('div').update('p id=editmenew content/p'); editor = new Ajax.InPlaceEditor('editme', url); That's all inline code, you'll probably want to put some structure around it, but you get the idea. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jul 26, 2:25 pm, Drum csteph2...@gmail.com wrote: I have a page which include a list of user entered keywords on which I want to be able to use Ajax.InPlaceEditor. It works fine when the initial page loads, The initial list is in the initial HTML and includes the calls to the editor. When, however, the div with the list and calls to the editor has been written using innerHTML = responseText, it does not work. I get no errors in Firebug, but the javascript is not running. Any help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---