[Proto-Scripty] Best way to turn an argument into Enumerable if it's not already
Hello, I'm wondering what is the best way to make sure an argument (or any variable for that matter) is an Enumerable (eg an array) and turn it into one if it's not. For the moment I'm using this solution: function myFunc(a) { if(a.size === undefined) a = [a]; ... } How would you do that? --~--~-~--~~~---~--~~ 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] Support for svg element?
Hello all, This was my first post here, but it looks like it has never been actually posted (sorry if I should not post it again). I have a problem with the canvas svg element used by Raphael (raphaeljs.org). I don't know a lot about the way Firefox lets us embed svg elements inside html documents, so I was surprised to find that Element.viewportOffset doesn't work on the svg element, or any other Position methods, while event handlers and several other js things work as usual. Take a look at this test page for Firefox 3.5: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/ TR/html4/strict.dtd html head title/title script type=text/javascript src=http://ajax.googleapis.com/ajax/ libs/prototype/1.6.0.3/prototype.js/script script type=text/javascript Event.observe(window,load, function (e) { var canvas = document.createElementNS(http://www.w3.org/2000/ svg, svg); canvas.setAttribute(width, 512px); canvas.setAttribute(height, 342px); $(container).appendChild(canvas); alert(Element.viewportOffset(canvas)); alert(Element.viewportOffset($(test))); }); /script /head body style=margin:0px div id=container style=padding:10px;margin:20pxdiv id=test/ div/div /body /html container contains both the svg canvas and a test div, but only test is supported by the viewportOffset method. Why can't I get the offset of the canvas element? Is there a fix or a workaround? What is special about the SVGSVGElement? --~--~-~--~~~---~--~~ 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: how can i implement rails' link_to_remote :submit options using Ajax.updater?
On Aug 1, 4:23 pm, serenobs seren...@gmail.com wrote: Hello. %= link_to_remote 'click here', :update='some_div', :url= {:action='some'}, :submit='group' % is what I want to implement using Ajax.updater. To do this I coded ( it is invoked when I clicked some link or button, whatever ) new Ajax.Updater('some_div', url(:action='some'), { parameters: $('group').serialize(true), method: 'get'} ); group div looks like below: div id=group %= radio_button_tag(:myvalue, 1 % %= radio_button_tag(:myvalue, 2 % /div on the controller's 'some' looks like below def some if params[:myvalue] == blah blah end if i use link_to_remote with submit options, it worked properly. but in case of my code using Ajax.updater, params[:myvalue] is not set properly. What's wrong with me? Somebody help me. This is a Prototype/Scriptaculous group, not a Rails one. There might be people here who read Rails, but you will probably get more success if you post the Javascript which is actually received by the browser, rather than the Rails source. Thanks. --~--~-~--~~~---~--~~ 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] ScrollTo effect
I have managed to get this effect to work on a return to top button, but i'm working on a horizontal layout, and was wondering if there is a way to adapt this effect to work horizontally. example, scroll to a div that is located to the left of the current page position I hope this makes sense thanks for the 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 -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Beginners question, trouble with Event.stop in AJAX
Thanks for the help, I just tried replacing Event.stop(e); with return false; in the function but it still submits the form. I would prefer to do it the new way anyway, if you would be able to help me... The first function is called from Event.observe('email-form', 'submit', callProcBasketEmail); which is within a function that is called when the document loads. The question is, where to put the event observe to watch the second form. My first instinct would be to put it in the function which outputs the form EG function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } (line added just after the ajax function has drawn 'password-form' to the screen) But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Thanks in advance, I think once I get over these initial few hurdles of getting to grips with good practices, I will be fine! Ashley Here is the javascript in full: // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); alert(pars); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } On Aug 2, 11:19 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Ashley, In the one that's not working, you're using what's called a DOM0- style handler -- that's where you're attaching the handler the old- fashioned way, by using an attribute on the form element: form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post Event.stop works only for handlers registered with more modern methods like the Event.observe you used with your first form. To correct the problem, I'd recommend using Event.observe to set up the handler for the second form as you did with the first. If there's a reason you can't do that, though, the DOM0 equivalent of Event.stop is to return false from callProcBasketPassword. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 4:35 pm, Ash ashley.kenner...@gmail.com wrote: Hi, I just started my first experiment with AJAX today. Got the basics working, but when I add a tiny bit more complexity I have a problem, Event.stop doesn't work properly for me. I've followed a couple of basic tutorials to submit an e-mail address to a PHP script, the PHP looks up the e-mail address and if it finds it, it shows an input to enter a password. This all works fine except the function with the ajax call to the password PHP script does not stop the form submitting. There is probably something very obvious I am doing wrong so hopefully someone will be able to spot this a mile away! :) The HTML looks like this, once the second form has been displayed form id=email-form action=procBasketEmailNoJS.php method=post input id=email class=texterwide type=text name=email/ input id=email-submit class=button type=submit value=Submit/ /form div id=email-response we have saved details on file for you, please enter your password below to retrieve them br/ form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post input id=password class=texterwide type=text name=password/ input id=password-submit class=button type=submit value=Submit/ /form /div div id=password-response name=password-response/ /div Here is the ajax.js // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } When I step through in Firebug I can see that the password-response div gets filled with the results of the procBasketPassword.php script, but then the page tries to reload where the form is pointing
[Proto-Scripty] Re: Beginners question, trouble with Event.stop in AJAX
Thanks for the help, I just tried replacing Event.stop(e); with return false; in the function but it still submits the form. I would prefer to do it the new way anyway, if you would be able to help me... The first function is called from Event.observe('email-form', 'submit', callProcBasketEmail); which is within a function that is called when the document loads. The question is, where to put the event observe to watch the second form. My first instinct would be to put it in the function which outputs the form EG function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } (line added just after the ajax function has drawn 'password-form' to the screen) But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Thanks in advance, I think once I get over these initial few hurdles of getting to grips with good practices, I will be fine! Ashley Here is the javascript in full: // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); alert(pars); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } On Aug 2, 11:19 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Ashley, In the one that's not working, you're using what's called a DOM0- style handler -- that's where you're attaching the handler the old- fashioned way, by using an attribute on the form element: form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post Event.stop works only for handlers registered with more modern methods like the Event.observe you used with your first form. To correct the problem, I'd recommend using Event.observe to set up the handler for the second form as you did with the first. If there's a reason you can't do that, though, the DOM0 equivalent of Event.stop is to return false from callProcBasketPassword. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 4:35 pm, Ash ashley.kenner...@gmail.com wrote: Hi, I just started my first experiment with AJAX today. Got the basics working, but when I add a tiny bit more complexity I have a problem, Event.stop doesn't work properly for me. I've followed a couple of basic tutorials to submit an e-mail address to a PHP script, the PHP looks up the e-mail address and if it finds it, it shows an input to enter a password. This all works fine except the function with the ajax call to the password PHP script does not stop the form submitting. There is probably something very obvious I am doing wrong so hopefully someone will be able to spot this a mile away! :) The HTML looks like this, once the second form has been displayed form id=email-form action=procBasketEmailNoJS.php method=post input id=email class=texterwide type=text name=email/ input id=email-submit class=button type=submit value=Submit/ /form div id=email-response we have saved details on file for you, please enter your password below to retrieve them br/ form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post input id=password class=texterwide type=text name=password/ input id=password-submit class=button type=submit value=Submit/ /form /div div id=password-response name=password-response/ /div Here is the ajax.js // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } When I step through in Firebug I can see that the password-response div gets filled with the results of the procBasketPassword.php script, but then the page tries to reload where the form is pointing to -
[Proto-Scripty] Re: Beginners question, trouble with Event.stop in AJAX
Is the password-form submit button a return from procBasketEmail.php? if so then you should observe it in the OnSuccess callback. If that isn't correct chalk it up to me checking this moments after awakening. On Mon, Aug 3, 2009 at 6:23 AM, Ashashley.kenner...@gmail.com wrote: Thanks for the help, I just tried replacing Event.stop(e); with return false; in the function but it still submits the form. I would prefer to do it the new way anyway, if you would be able to help me... The first function is called from Event.observe('email-form', 'submit', callProcBasketEmail); which is within a function that is called when the document loads. The question is, where to put the event observe to watch the second form. My first instinct would be to put it in the function which outputs the form EG function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } (line added just after the ajax function has drawn 'password-form' to the screen) But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Thanks in advance, I think once I get over these initial few hurdles of getting to grips with good practices, I will be fine! Ashley Here is the javascript in full: // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); alert(pars); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } On Aug 2, 11:19 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Ashley, In the one that's not working, you're using what's called a DOM0- style handler -- that's where you're attaching the handler the old- fashioned way, by using an attribute on the form element: form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post Event.stop works only for handlers registered with more modern methods like the Event.observe you used with your first form. To correct the problem, I'd recommend using Event.observe to set up the handler for the second form as you did with the first. If there's a reason you can't do that, though, the DOM0 equivalent of Event.stop is to return false from callProcBasketPassword. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 4:35 pm, Ash ashley.kenner...@gmail.com wrote: Hi, I just started my first experiment with AJAX today. Got the basics working, but when I add a tiny bit more complexity I have a problem, Event.stop doesn't work properly for me. I've followed a couple of basic tutorials to submit an e-mail address to a PHP script, the PHP looks up the e-mail address and if it finds it, it shows an input to enter a password. This all works fine except the function with the ajax call to the password PHP script does not stop the form submitting. There is probably something very obvious I am doing wrong so hopefully someone will be able to spot this a mile away! :) The HTML looks like this, once the second form has been displayed form id=email-form action=procBasketEmailNoJS.php method=post input id=email class=texterwide type=text name=email/ input id=email-submit class=button type=submit value=Submit/ /form div id=email-response we have saved details on file for you, please enter your password below to retrieve them br/ form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post input id=password class=texterwide type=text name=password/ input id=password-submit class=button type=submit value=Submit/ /form /div div id=password-response name=password-response/ /div Here is the ajax.js // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); var myAjax = new
[Proto-Scripty] Class.create and this keyword
Hello, I'm trying to use the Class methods to manage my object hierarchy on my current project, but I have some trouble with the this keyword in conjonction with Class.create. Here is a piece of plain-js code using prototypes to get inheritance: var Super1 = function () { this.fu = bar; } var Sub1 = function () { this.baz = bat; this.f = function () { alert(classic:+this.fu+this.baz); }.bind(this); document.observe(click, this.f); }; Sub1.prototype = new Super1(); new Sub1(); Here is my attempt at mimic this with Class.create: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }.bindAsEventListener(this), initialize: function () { document.observe(click, this.f); } }); new Sub2(); But of course it doesn't work, f in bound to window, not the object create by new. The only way I found is: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }, initialize: function () { this.f = this.f.bindAsEventListener(this); document.observe(click, this.f); } }); new Sub2(); But it's really inelegant. How am I supposed to handle this? --~--~-~--~~~---~--~~ 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: Beginners question, trouble with Event.stop in AJAX
If you are using onsubmit you need to do this ... onsibmit=return theCoolFunction(); then you may return false or true on certain things ... As TJ recommended i would stay away from these old style handlers and look at delegating it properly HTH Alex Mcauley http://www.thevacancymarket.com - Original Message - From: Ash ashley.kenner...@gmail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, August 03, 2009 2:23 PM Subject: [Proto-Scripty] Re: Beginners question, trouble with Event.stop in AJAX Thanks for the help, I just tried replacing Event.stop(e); with return false; in the function but it still submits the form. I would prefer to do it the new way anyway, if you would be able to help me... The first function is called from Event.observe('email-form', 'submit', callProcBasketEmail); which is within a function that is called when the document loads. The question is, where to put the event observe to watch the second form. My first instinct would be to put it in the function which outputs the form EG function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } (line added just after the ajax function has drawn 'password-form' to the screen) But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Thanks in advance, I think once I get over these initial few hurdles of getting to grips with good practices, I will be fine! Ashley Here is the javascript in full: // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); alert(pars); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } On Aug 2, 11:19 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Ashley, In the one that's not working, you're using what's called a DOM0- style handler -- that's where you're attaching the handler the old- fashioned way, by using an attribute on the form element: form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post Event.stop works only for handlers registered with more modern methods like the Event.observe you used with your first form. To correct the problem, I'd recommend using Event.observe to set up the handler for the second form as you did with the first. If there's a reason you can't do that, though, the DOM0 equivalent of Event.stop is to return false from callProcBasketPassword. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 4:35 pm, Ash ashley.kenner...@gmail.com wrote: Hi, I just started my first experiment with AJAX today. Got the basics working, but when I add a tiny bit more complexity I have a problem, Event.stop doesn't work properly for me. I've followed a couple of basic tutorials to submit an e-mail address to a PHP script, the PHP looks up the e-mail address and if it finds it, it shows an input to enter a password. This all works fine except the function with the ajax call to the password PHP script does not stop the form submitting. There is probably something very obvious I am doing wrong so hopefully someone will be able to spot this a mile away! :) The HTML looks like this, once the second form has been displayed form id=email-form action=procBasketEmailNoJS.php method=post input id=email class=texterwide type=text name=email/ input id=email-submit class=button type=submit value=Submit/ /form div id=email-response we have saved details on file for you, please enter your password below to retrieve them br/ form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post input id=password class=texterwide type=text name=password/ input id=password-submit class=button type=submit value=Submit/ /form /div div id=password-response name=password-response/ /div Here is the ajax.js // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new
[Proto-Scripty] Re: Will remove() method on top DIV element automatically remove children of that element?
First of all, thank you for a very detailed answer. From that arises one more question: when you say event handlers are not remove do you mean the event handlers that where added dynamically with commands such as Element.observed and window.addEventListener won't be removed, do you also talk about methods that are creates as part of HTML syntax such as a href=# onclick=javascript:DoSomething()? as most of the dynamic content I create is using he Template class of prototype where actions on those objects are taken from links populated as I've described above (using an HTML within the Template). Will these event invocations also provide a problem and need to be tracked? Thank you, On Aug 2, 10:29 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi, Yes, it will, removing an element (via Prototype or directly with Node.removeChild) removes that element and its children. Which is just as well, as the children would have no where to be otherwise. Note that neither Prototype nor the underlying DOM methods will automatically remove event handlers from the removed elements, which can mean that memory remains in use even though the element isn't on the page anymore. You want to track what children you have event handlers on and remove the handlers as well. This is much easier if you're using event delegation to keep the number of handlers to a minimum. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 2, 11:25 pm, Kostil kostia.iva...@gmail.com wrote: Hi All, I am wondering if remove() method executed on top DIV (parent DIV element) will automatically remove the children of this element (as in remove them from the page and memory if appropriate)? Currently, I am doing the following to remove the children: $('topdiv').childElements().each(function(e) { RemoveChildren(e); }); Where RemoveChildren(e) defined as: function RemoveChildren(e) { if (e.childElements().length 0) { e.childElements().each(function(ee) { RemoveChildren(ee); }); } e.remove(); } The method above seems to work slow especially on IE where very visible lag is apparent when executing this type of cleanup. Thank you in advance, --~--~-~--~~~---~--~~ 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: Will remove() method on top DIV element automatically remove children of that element?
onclick will go as its a DOM0 style handler. Anything in the observe (attached as delegation) will not and you will have to remove manauly with stopObserving(); Alex Mcauley http://www.thevacancymarket.com - Original Message - From: Kostil kostia.iva...@gmail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, August 03, 2009 3:09 PM Subject: [Proto-Scripty] Re: Will remove() method on top DIV element automatically remove children of that element? First of all, thank you for a very detailed answer. From that arises one more question: when you say event handlers are not remove do you mean the event handlers that where added dynamically with commands such as Element.observed and window.addEventListener won't be removed, do you also talk about methods that are creates as part of HTML syntax such as a href=# onclick=javascript:DoSomething()? as most of the dynamic content I create is using he Template class of prototype where actions on those objects are taken from links populated as I've described above (using an HTML within the Template). Will these event invocations also provide a problem and need to be tracked? Thank you, On Aug 2, 10:29 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi, Yes, it will, removing an element (via Prototype or directly with Node.removeChild) removes that element and its children. Which is just as well, as the children would have no where to be otherwise. Note that neither Prototype nor the underlying DOM methods will automatically remove event handlers from the removed elements, which can mean that memory remains in use even though the element isn't on the page anymore. You want to track what children you have event handlers on and remove the handlers as well. This is much easier if you're using event delegation to keep the number of handlers to a minimum. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 2, 11:25 pm, Kostil kostia.iva...@gmail.com wrote: Hi All, I am wondering if remove() method executed on top DIV (parent DIV element) will automatically remove the children of this element (as in remove them from the page and memory if appropriate)? Currently, I am doing the following to remove the children: $('topdiv').childElements().each(function(e) { RemoveChildren(e); }); Where RemoveChildren(e) defined as: function RemoveChildren(e) { if (e.childElements().length 0) { e.childElements().each(function(ee) { RemoveChildren(ee); }); } e.remove(); } The method above seems to work slow especially on IE where very visible lag is apparent when executing this type of cleanup. Thank you in advance, --~--~-~--~~~---~--~~ 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: Class.create and this keyword
Your observers need to be bound to the object you want the this keyword tied to. document.observe('click', this.f.bindAsEventListener(this)) See the bottom of this page: http://prototypejs.org/api/event/observe -justin --~--~-~--~~~---~--~~ 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: Masked Input in Prototype
The plugin's code is compliant with not conflicting with the $ function. But in your implementation of this plugin, you'll have to be sure to use jQuery(#maskInput).mask(...); instead of the demo's example code which uses the $ method. -- http://positionabsolute.net On Jul 30, 9:23 am, Celso cels...@gmail.com wrote: Unfortunately I am no expert in prototype. I can not believe that someone has developed a prototype mask! I try to use prototype and jquery together, Works:http://docs.jquery.com/Using_jQuery_with_Other_Libraries But .. the plugin does not works. On 29 jul, 18:27, Alex McAuley webmas...@thecarmarketplace.com wrote: why not just port the jquery one... wont take long ! Alex Mcauleyhttp://www.thevacancymarket.com - Original Message - From: Celso cels...@gmail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Wednesday, July 29, 2009 10:22 PM Subject: [Proto-Scripty] Re: Masked Input in Prototype something like this:http://digitalbush.com/projects/masked-input-plugin On 24 jul, 06:48, Richard Quadling rquadl...@googlemail.com wrote: 2009/7/23 Matt Foster mattfoste...@gmail.com: You must further define your idea of masked input http://www.google.com/search?q=define%3A+masked+inputie=utf-8oe=utf... On Jul 23, 3:58 pm, Celso cels...@gmail.com wrote: Anyone know a masked input in prototype? Thanks, Celso. An inputmask[1] is where you can say enter text in a form like ... AA nn nn nn A You would be able to type 2 letters, 6 numbers and then 1 letter. The case would be forced to upper case and the spacing would be automatic. BO 52 91 91 V for example OR Are you talking about hiding the input? Like input type=password ? Regards, Richard. [1]http://www.google.co.uk/search?q=define:+input+mask -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! ZOPA :http://uk.zopa.com/member/RQuadling --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
You could just use the arguments array. var stuff = $A(arguments).flatten(); -justin --~--~-~--~~~---~--~~ 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: Masked Input in Prototype
Or before the code do this... $jq=jQuery.noConflict(); then anything that you want to use jQuery's $ for just use $jq in its stead. HTH Alex Mcauley http://www.thevacancymarket.com - Original Message - From: Matt Foster mattfoste...@gmail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, August 03, 2009 4:36 PM Subject: [Proto-Scripty] Re: Masked Input in Prototype The plugin's code is compliant with not conflicting with the $ function. But in your implementation of this plugin, you'll have to be sure to use jQuery(#maskInput).mask(...); instead of the demo's example code which uses the $ method. -- http://positionabsolute.net On Jul 30, 9:23 am, Celso cels...@gmail.com wrote: Unfortunately I am no expert in prototype. I can not believe that someone has developed a prototype mask! I try to use prototype and jquery together, Works:http://docs.jquery.com/Using_jQuery_with_Other_Libraries But .. the plugin does not works. On 29 jul, 18:27, Alex McAuley webmas...@thecarmarketplace.com wrote: why not just port the jquery one... wont take long ! Alex Mcauleyhttp://www.thevacancymarket.com - Original Message - From: Celso cels...@gmail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Wednesday, July 29, 2009 10:22 PM Subject: [Proto-Scripty] Re: Masked Input in Prototype something like this:http://digitalbush.com/projects/masked-input-plugin On 24 jul, 06:48, Richard Quadling rquadl...@googlemail.com wrote: 2009/7/23 Matt Foster mattfoste...@gmail.com: You must further define your idea of masked input http://www.google.com/search?q=define%3A+masked+inputie=utf-8oe=utf... On Jul 23, 3:58 pm, Celso cels...@gmail.com wrote: Anyone know a masked input in prototype? Thanks, Celso. An inputmask[1] is where you can say enter text in a form like ... AA nn nn nn A You would be able to type 2 letters, 6 numbers and then 1 letter. The case would be forced to upper case and the spacing would be automatic. BO 52 91 91 V for example OR Are you talking about hiding the input? Like input type=password ? Regards, Richard. [1]http://www.google.co.uk/search?q=define:+input+mask -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! ZOPA :http://uk.zopa.com/member/RQuadling --~--~-~--~~~---~--~~ 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: Beginners question, trouble with Event.stop in AJAX
Hi, But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Right, because this new line: Event.observe('password-form', 'submit', callProcBasketPassword); ...will cause an error, because there is no element with the ID 'password-form' yet. Remember that Ajax calls are *asynchronous* (that's what the A in Ajax stands for). You start the call at the point in your code where you create the Ajax.Updater object, but then your code continues immediately without waiting for the Ajax call to finish. As DJ pointed out, that's what the onSuccess callback is for -- so you can execute code once the Ajx call has successfully completed. So it would look something like this: http://pastie.org/569908 In terms of getting you past these initial hurtles, some recommended reading: http://prototypejs.org/learn/introduction-to-ajax http://proto-scripty.wikidot.com/prototype:how-to-bulletproof-ajax-requests http://prototypejs.org/api/ajax/request http://prototypejs.org/api/ajax/updater HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 3, 2:23 pm, Ash ashley.kenner...@gmail.com wrote: Thanks for the help, I just tried replacing Event.stop(e); with return false; in the function but it still submits the form. I would prefer to do it the new way anyway, if you would be able to help me... The first function is called from Event.observe('email-form', 'submit', callProcBasketEmail); which is within a function that is called when the document loads. The question is, where to put the event observe to watch the second form. My first instinct would be to put it in the function which outputs the form EG function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } (line added just after the ajax function has drawn 'password-form' to the screen) But this stops the whole function from working - where should the observe line be placed to ensure it will work properly? Thanks in advance, I think once I get over these initial few hurdles of getting to grips with good practices, I will be fine! Ashley Here is the javascript in full: // Attach handler to window load event Event.observe(window, 'load', init, false); function init(){ Event.observe('email-form', 'submit', callProcBasketEmail); } function callProcBasketEmail(e) { var pars = Form.serialize('email-form'); var myAjax = new Ajax.Updater('email-response', 'procBasketEmail.php', {method: 'post', parameters: pars}); Event.observe('password-form', 'submit', callProcBasketPassword); Event.stop(e); } function callProcBasketPassword(e) { var pars = Form.serialize('password-form'); alert(pars); var myAjax = new Ajax.Updater('password-response', 'procBasketPassword.php', {method: 'post', parameters: pars}); Event.stop(e); } On Aug 2, 11:19 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi Ashley, In the one that's not working, you're using what's called a DOM0- style handler -- that's where you're attaching the handler the old- fashioned way, by using an attribute on the form element: form id=password-form onsubmit=callProcBasketPassword() action=procBasketPasswordNoJS.php method=post Event.stop works only for handlers registered with more modern methods like the Event.observe you used with your first form. To correct the problem, I'd recommend using Event.observe to set up the handler for the second form as you did with the first. If there's a reason you can't do that, though, the DOM0 equivalent of Event.stop is to return false from callProcBasketPassword. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 1, 4:35 pm, Ash ashley.kenner...@gmail.com wrote: Hi, I just started my first experiment with AJAX today. Got the basics working, but when I add a tiny bit more complexity I have a problem, Event.stop doesn't work properly for me. I've followed a couple of basic tutorials to submit an e-mail address to a PHP script, the PHP looks up the e-mail address and if it finds it, it shows an input to enter a password. This all works fine except the function with the ajax call to the password PHP script does not stop the form submitting. There is probably something very obvious I am doing wrong so hopefully someone will be able to spot this a mile away! :) The HTML looks like this, once the second form has been displayed form id=email-form action=procBasketEmailNoJS.php method=post input id=email class=texterwide type=text name=email/ input id=email-submit class=button type=submit value=Submit/ /form div
[Proto-Scripty] Re: Class.create and this keyword
Hi, thanks for the answer. I want to bind this.f itself, in order to be able to use Event.stopObserving with it. What is the best way to do it? Cédric On Aug 3, 5:32 pm, mr_justin gro...@jperkins.otherinbox.com wrote: Your observers need to be bound to the object you want the this keyword tied to. document.observe('click', this.f.bindAsEventListener(this)) See the bottom of this page:http://prototypejs.org/api/event/observe -justin --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
I'm not sure we're talking about the same thing. I'm not talking about the variable argument, but some variable named a. argument can be passed to $A() because it has the nature of an Array, but I don't know anything about my variable a. So it looks like $A(a) will fail in the case that interests me, ie if a is not an Enumerable and is not something special like argument. To be more clear, I want to be able to call myFunc with those calls : myFunc(1) myFunc(fubar) myFunc([1, fubar]) myFunc($$('div.comment')) myFunc($('wrapper')) etc. On Aug 3, 5:45 pm, mr_justin gro...@jperkins.otherinbox.com wrote: You could just use the arguments array. var stuff = $A(arguments).flatten(); -justin --~--~-~--~~~---~--~~ 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: Class.create and this keyword
Hi, But it's really inelegant. How am I supposed to handle this? Pretty much like that, except I haven't reassigned the property like that. It *should* be fine, you'll create an own property 'f' on the instance (rather than an inherited one from the prototype) that's bound. But it bothers me and I can't give you a good reason for it. :-) I've done that sort of thing before (keep a bound copy around on the instance, if I'm going to reuse it), I've just for some reason always used a different prop name, I guess so I'm not in doubt whether I've bound it. But doing it in the initializer like you have, there wouldn't be any confusion... Also, the odds are pretty high you just want #bind, not #bindAsEventListener.[1] [1] http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 3, 2:39 pm, Cédric bertolini.ced...@gmail.com wrote: Hello, I'm trying to use the Class methods to manage my object hierarchy on my current project, but I have some trouble with the this keyword in conjonction with Class.create. Here is a piece of plain-js code using prototypes to get inheritance: var Super1 = function () { this.fu = bar; } var Sub1 = function () { this.baz = bat; this.f = function () { alert(classic:+this.fu+this.baz); }.bind(this); document.observe(click, this.f);}; Sub1.prototype = new Super1(); new Sub1(); Here is my attempt at mimic this with Class.create: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }.bindAsEventListener(this), initialize: function () { document.observe(click, this.f); }}); new Sub2(); But of course it doesn't work, f in bound to window, not the object create by new. The only way I found is: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }, initialize: function () { this.f = this.f.bindAsEventListener(this); document.observe(click, this.f); }}); new Sub2(); But it's really inelegant. How am I supposed to handle this? --~--~-~--~~~---~--~~ 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: Class.create and this keyword
Thanks. I'll use #bind instead of #bindAsEventListener from now on. Regarding the binding inelegancy, I'm a bit disappointed, but at least it's a good working solution to the problem. I guess Class#addMethods won't be of any help here? --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
Did you try what I suggested? I tested various argument scenarios as you gave in your example and it worked fine. The arguments variable is a magic variable that is an array (a subset of an array really) of all the arguments passed into the function. -justin --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
I tried it with the following implementation : function myFunc(a) { $A(a).each(function (o) { alert(o) }); } It doesn't work, because for $A() to be of any use, I have to use $A (argument), not $A(a), but the fact is, I have several arguments, not just one. I want to treat the first argument as an Enumerable, and the other arguments have different purposes. Here is an actual function: UI.Observer = function (elements, events, handlers) { var elements = (elements elements.size !== undefined ? elements : [elements]); var events = (events events.size !== undefined ? events : [events]); var handlers = (handlers handlers.size !== undefined ? handlers : [handlers]); var handler = null; var pairs = $R(1, events.size()).map(function (i) { if(typeof handlers[i-1] != undefined) handler = handlers[i-1]; if(typeof handler == function) return { event:events[i-1], handler:handler }; }); var operate = function (method) { elements.each(function (element) { pairs.each(function (pair) { if(pair) Event[method](element, pair.event, pair.handler); }); }); }; this.go = operate.curry(observe); this.stop = operate.curry(stopObserving); this.go(); } --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
So, your solution was good, but I can't apply it just like that. It gave me an idea, though: function ensureArray() { return $A(argument).flatten(); } function myFunc(a) { var a = ensureArray(a); } That would the trick, I guess. Except the side effect that a is flatten ()-ed, but in my case it's ok. --~--~-~--~~~---~--~~ 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: Best way to turn an argument into Enumerable if it's not already
but the fact is, I have several arguments, not just one. I want to treat the first argument as an Enumerable, and the I see, that wasn't clear from the beginning. In that case, how about: elements = $A([elements]).flatten(); handlers = $A([handlers]).flatten(); --~--~-~--~~~---~--~~ 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: Class.create and this keyword
Regardless of the JS framework. A closure is necessary for attaching class methods to a particular instance and preserve the instance reference via the this keyword. http://www.javascriptkit.com/javatutors/closures.shtml I thought Function.bind was pretty clean myself, but I guess you've got the sweet tooth for the syntax. -- http://positionabsolute.net On Aug 3, 1:16 pm, Cédric bertolini.ced...@gmail.com wrote: Thanks. I'll use #bind instead of #bindAsEventListener from now on. Regarding the binding inelegancy, I'm a bit disappointed, but at least it's a good working solution to the problem. I guess Class#addMethods won't be of any help here? --~--~-~--~~~---~--~~ 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: Class.create and this keyword
Oops, sorry for the weird formatting... On Mon, Aug 3, 2009 at 6:38 PM, Ryan Gahl ryan.g...@gmail.com wrote: Let me suggest the module pattern - which not inconsequently also enables true private fields and methods (just because it seems you're looking for alternative patterns). Also, since the module pattern allows for true private members, you can just create a helper function at the module level, thus avoiding placing the f function at the instance level. This assumes you probably don't want calling code to create and instance of Sub2 and then just randomly make calls to myInstance.f()... // (if you don't use a globally accessible namespace object to tack your classes onto, then declare the class variable outside of the module function so the reference is visible elsewhere, but I highly recommend just using a namespace object to hold all your classes instead) var Sub2; //as in the note above, only required here if not using a namespace object (function() { //put the handler here, as a helper function, and no need for it to be public because you typically won't want outside code to do someInstance.f(), right? (no more of this it has an underscore so it's private stuff, people :) function f() { alert(Class: + this.fu + this.baz); } Sub2 = Class.create(Super2, { // notice no var since in this example we declared outside the module so it's available outside the module baz: bat, initialize: function () { document.observe(click, f.bind(this)); //just in-line the binding to make it cleaner, unless you need to re-user the bound function, then maybe cache it in a variable } }); })(); new Sub2(); On Mon, Aug 3, 2009 at 12:05 PM, T.J. Crowder t...@crowdersoftware.com wrote: Hi, But it's really inelegant. How am I supposed to handle this? Pretty much like that, except I haven't reassigned the property like that. It *should* be fine, you'll create an own property 'f' on the instance (rather than an inherited one from the prototype) that's bound. But it bothers me and I can't give you a good reason for it. :-) I've done that sort of thing before (keep a bound copy around on the instance, if I'm going to reuse it), I've just for some reason always used a different prop name, I guess so I'm not in doubt whether I've bound it. But doing it in the initializer like you have, there wouldn't be any confusion... Also, the odds are pretty high you just want #bind, not #bindAsEventListener.[1] [1] http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 3, 2:39 pm, Cédric bertolini.ced...@gmail.com wrote: Hello, I'm trying to use the Class methods to manage my object hierarchy on my current project, but I have some trouble with the this keyword in conjonction with Class.create. Here is a piece of plain-js code using prototypes to get inheritance: var Super1 = function () { this.fu = bar; } var Sub1 = function () { this.baz = bat; this.f = function () { alert(classic:+this.fu+this.baz); }.bind(this); document.observe(click, this.f);}; Sub1.prototype = new Super1(); new Sub1(); Here is my attempt at mimic this with Class.create: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }.bindAsEventListener(this), initialize: function () { document.observe(click, this.f); }}); new Sub2(); But of course it doesn't work, f in bound to window, not the object create by new. The only way I found is: var Super2 = Class.create({ fu: bar }); var Sub2 = Class.create(Super2, { baz: bat, f: function () { alert(Class:+this.fu+this.baz); }, initialize: function () { this.f = this.f.bindAsEventListener(this); document.observe(click, this.f); }}); new Sub2(); But it's really inelegant. How am I supposed to handle this? --~--~-~--~~~---~--~~ 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] sw.gallery script help
Hi I'm working on a slideshow script SW Gallery. http://www.wappler.eu/swgallery/ There are no instructions and I have a couple of questions. Is it possible to set it to slide automatically. The demo has to move manually. And can the Carousel be turned off to not display. My slideshow is too narrow for it to look good. I can't seem to figure it out as I don't know the scripting language. Thanks! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---