[Proto-Scripty] Re: Ajax - multiple messages on the same connection?
On tiistaina 4. tammikuuta 2011 at 18.22, Phil Petree wrote: There was some discussion of this for html 6 then for awile it looked like they were gonna drop it and then it came back. Latest doc is here: http://dev.w3.org/html5/eventsource/ But dont expect support anytime soon... Isn't this basically what WebSockets [1] are meant for? Check out e.g. Socket.io [2], Faye [3] and Pusher App [4]. //jarkko [1] http://dev.w3.org/html5/websockets/ [2] http://socket.io/ [3] http://faye.jcoglan.com/ [4] http://pusherapp.com/ On Mon, Jan 3, 2011 at 10:22 AM, sol solmy...@gmail.com wrote: Hi, We are using Prototype Ajax on the client side, consuming messages from a Comet server. We were wondering whether it's possible to keep a connection alive, and pass multiple messages on the same connection (for Server push)? It's something in the lines of: - Client opens an Ajax.request - The server sends a reply message; the client consumes it (onsuccess) - Now usually, the HTTP connection would be closed; if the client expects more messages, it should open a new request and a new connection. - But we'd like to keep the connection alive for a while (on both client and server), so that if the server discovers new data (say 5 minutes later) it can push a new message on the same connection, and hopefully trigger another callback on the client ('onsuccess'). Of course this requires a way of telling when 1 message ends, and another begins... we were hoping this can be done based on some separator (perhaps multipart format?), or content-length. Is this supported on Prototype Ajax? 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-scriptacul...@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. -- 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-scriptacul...@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. -- 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-scriptacul...@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.
Re: [Proto-Scripty] Toggle checkboxes???
Hi Phil, On 17.10.2010, at 18.15, Phil Petree wrote: OK, I have a form where the first row of the first colum is a checkbox designed to toggle the checked/unchecked state of all the other checkboxes in the form (select all/select none). Problem is, the state of the checkbox with the onclick state is not getting changed. The rest of the check boxes are toggling based on their current state and I want to tie them to the master checkbox and I'm just not getting this to work. Your HTML code is invalid in a few ways. From a quick glimpse, you have divs inside tr's and the form element as a direct descendant of table. The latter especially causes some trouble. At least Safari automatically closes the form element and thus the checkboxes won't fall within the form. Thus your code below can't possibly work. Here's a quick script that seemed to work (at least in Safari console) with your example page: $('toggle_all').observe('click', function(ev) { var self = this; $$('input[type=checkbox]').without(this).each(function(el) { el.checked = self.checked; }); }); You probably want to modify the selector to be more precise and maybe make the whole function more generic, though. //jarkko A sample page is here: http://www.neighborhoodwatchalerts.com/invite/checkboxes.php The code is this: function toggleCheckBoxes(formName) { // toggle Check Boxes using Prototype Library var form = $(formName); var i = form.getElements('checkbox'); var chkState = ($F('toggle_all') == on) ? true : false; // alert(chkState = +chkState); // show the current state i.each(function(item, chkState) { //item.checked = chkState; // set all checkboxes to the masters state //if (chkState == false) // turn all checkboxes off if (item.checked) { item.checked=false; } else { item.checked=true; } } ); return true; } Any thoughts or suggestions? TJ, you have have any other shortcuts tucked away? Thanks, Pete -- 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-scriptacul...@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. -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- 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-scriptacul...@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.
Re: [Proto-Scripty] Toggle checkboxes???
On 17.10.2010, at 20.52, Phil Petree wrote: Thanks Jarkko! That was the perfect solution... I moved it into the real form and worked flawlessly. Much appreciated. Side note: You are saying the form needs to come before the table so that the table resides inside the form? I never knew that... never knew there was any difference in the order (or that there should be any difference). A table element can only have table-related elements as direct descendants: http://www.w3.org/TR/2010/WD-html-markup-20100624/table.html#table In the same vein, a tr element can only have td's or th's as its children: http://www.w3.org/TR/2010/WD-html-markup-20100624/tr.html#tr //jarkko On Sun, Oct 17, 2010 at 1:22 PM, Jarkko Laine jarks...@gmail.com wrote: Hi Phil, On 17.10.2010, at 18.15, Phil Petree wrote: OK, I have a form where the first row of the first colum is a checkbox designed to toggle the checked/unchecked state of all the other checkboxes in the form (select all/select none). Problem is, the state of the checkbox with the onclick state is not getting changed. The rest of the check boxes are toggling based on their current state and I want to tie them to the master checkbox and I'm just not getting this to work. Your HTML code is invalid in a few ways. From a quick glimpse, you have divs inside tr's and the form element as a direct descendant of table. The latter especially causes some trouble. At least Safari automatically closes the form element and thus the checkboxes won't fall within the form. Thus your code below can't possibly work. Here's a quick script that seemed to work (at least in Safari console) with your example page: $('toggle_all').observe('click', function(ev) { var self = this; $$('input[type=checkbox]').without(this).each(function(el) { el.checked = self.checked; }); }); You probably want to modify the selector to be more precise and maybe make the whole function more generic, though. //jarkko A sample page is here: http://www.neighborhoodwatchalerts.com/invite/checkboxes.php The code is this: function toggleCheckBoxes(formName) { // toggle Check Boxes using Prototype Library var form = $(formName); var i = form.getElements('checkbox'); var chkState = ($F('toggle_all') == on) ? true : false; // alert(chkState = +chkState); // show the current state i.each(function(item, chkState) { //item.checked = chkState; // set all checkboxes to the masters state //if (chkState == false) // turn all checkboxes off if (item.checked) { item.checked=false; } else { item.checked=true; } } ); return true; } Any thoughts or suggestions? TJ, you have have any other shortcuts tucked away? Thanks, Pete -- 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-scriptacul...@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. -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- 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-scriptacul...@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. -- 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-scriptacul...@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. -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- 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-scriptacul...@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.
Re: [Proto-Scripty] Returning an array of results from an operation on an array.
On 17.9.2010, at 15.03, Richard Quadling wrote: Hi. How do I do something like this (just an example) ... [1,2,3].each(function(val){return val * val;}); such that the result is ... [1,4,9] [1,2,3].map(function(i){ return i * i }); // http://api.prototypejs.org/language/enumerable/prototype/collect/ Note that invoke is a shorthand for map except that it calls a method for each of the items: ['hello', 'world'].invoke('toUpperCase'); // http://api.prototypejs.org/language/enumerable/prototype/invoke/ // - ['HELLO', 'WORLD'] Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- 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-scriptacul...@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.
Re: [Proto-Scripty] replace body onload= with event.observe? ... can't figure it out
On 9.6.2010, at 17.08, fernan wrote: Hi! I need to be able to i) read a cookie when the page loads, and ii) save data into the cookie when the page unloads (i.e. when the user clicks and navigates to another page, within the same site or to a different site). I have working code (in a catalyst web application) using body onload=readCookie(); onunload=saveCookie();. However, we want to move this code out of the body element, so we can only use it in some pages (the body tag is added by a global template for the site). So I started playing around with prototype's event.observe ... and can't get it to work. I just cooked a minimal test page to check what the problem might be, and can't figure out what I'm doing wrong. I'd appreciate any help or direction ... The following worked fine for me (both Safari and FF): script type=text/javascript language=JavaScript document.observe('dom:loaded', function() { $('div1').toggle() }); /script Otherwise, what T.J. said. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -- 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-scriptacul...@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: Prototype Selector Speed
On 21.9.2009, at 11.04, T.J. Crowder wrote: Hi, Is there any plans in the future to improve on prototype's speed? Yes. The core team are working on integrating the Sizzle selector engine[1] (which is what the latest version of jQuery uses). (This is more of a challenge than it sounds; switching selector engines touches a lot of things besides just the $$ and Element#select methods.) I *think* that's slated for the next release, but don't quote me. Sam just tweeted [1] that they're using it already on Highrise, so I'd guess it's pretty much in a working condition. //jarkko [1] http://twitter.com/sstephenson/status/439058 -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi --~--~-~--~~~---~--~~ 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: Each Not Working with getElementsByTagName
On 1.12.2008, at 23.14, laurin1 wrote: var $aCSS = document.getElementsByTagName('style'); $aCSS.each(function($sEle){ alert('test'); }); I can make this work with $$, and if I use document.getElementsByTagName('style')[0], I can access each one individually. So why can't I use each()? Because HTMLCollection (which getElementsByTagName returns) doesn't mix in Enumerable, where each comes from. The question is, why would you use getElementsByTagName? //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: testing whether all elements in a div have a certain class
On 31.10.2008, at 21.25, Gabriel Gilini wrote: I'm thinking $$(eval('#container_'+boxID+' span')); Don't know if it's the right thing to do though. Why would you want to eval that string? Matt, could you elaborate a bit more? $$('#container_'+boxID+' span'); actually looks to be fine. What are you getting with it and what are you expecting? //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: obtrusive even handlers not working in generated content
On 29.10.2008, at 16.26, Jonathan Rosenberg wrote: I'm still quite new to Prototype, but I think you're missing some quotes in your code below. What you have now is var para = new Element('p', {'class':'button',onclick:'alert(hello);'}).update(Alert You?); Shouldn't it be var para = new Element('p', {'class':'button',onclick:'\'alert(hello);\''}).update(Alert You?); var al = function() {alert(Hello); } var para = new Element('p', {class: 'button'}).update(Alert you?); para.observe('click', al); Doesn't this work in ie (after you add the paragraph to the DOM)? //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: How to retrieve dynamic element in prototype
self-promotion type=shameless I'm also dealing with event delegation in my RailsConf Europe presentation [1] and PeepCode eBook Unobtrusive Prototype [2], just out of beta. /self-promotion //jarkko [1] http://www.slideshare.net/supervillain/accessible-ajax-on-rails-presentation/ [2] https://peepcode.com/products/unobtrusive-prototype-js On 16.10.2008, at 15.34, Nick Stakenburg wrote: T.J., here's a link for you on event delegation http://mislav.caboo.se/js/handling-events-on-elements/ -- Nick On 16 okt, 14:04, T.J. Crowder [EMAIL PROTECTED] wrote: Again, a much simpler, more performant solution to this issue is to use event delegation. VERY good point, I've updated the tip to mention that. Need to find some good links about event delegation and/or source a How To for it for the wiki. I'll ping Christophe, given that he's just done a talk on the subject! -- T.J. :-) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~--- -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi smime.p7s Description: S/MIME cryptographic signature
[Proto-Scripty] Re: Coming from jquery (be gentle)
I'll throw in a Low Pro [1] version as well: Event.addBehavior({ 'ul.bopCategories .bopCategoryDetails' : function() { this.hide(); }, 'ul.bopCategories li h3:click' : function(e) { elm = e.element(); elm.next('div.bopCategoryDetails').toggle(); elm.toggleClassName('expanded'); } }); The first function will pre-hide the details. Remove it if it's not something you want to happen. //jarkko [1] http://jlaine.net/2007/8/3/from-rails-ajax-helpers-to-low-pro-part-i On 3.10.2008, at 12.37, T.J. Crowder wrote: Actually, let me revise that: function toggleContent(evt) { var elm; elm = evt.element(); elm.next('div.bopCategoryDetails').toggle(); elm.toggleClassName('expanded'); } function initPage() { $$(ul.bopCategories li h3).each(function (elm) { elm.observe('click', toggleContent); }); } Event.observe(document, 'dom:loaded', initPage); The dom:loaded event is fired when the DOM is ready (before window.onload, usually). -- T.J. Crowder tj / crowder software / com -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi smime.p7s Description: S/MIME cryptographic signature