[Proto-Scripty] Re: Is there a way to DRY this up?
Like this?: function filterHandler(evt){this.fire('check:filter');} $('filter').observe('keyup', filterHandler).observe('click',filterHandler).observe('focus', filterHandler).observe('blur', filterHandler); See Observe Documentation: http://www.prototypejs.org/api/event/observe As the Event.Observe function returns the element the event listener is being applied too you can just call 'observe' in tandem. I also created a function named 'filterHandler' that each event listener will call as they all run the same code, this makes it easier if you wish to make a change to the function and removes the (assumed) needless repetition, however if you intend to call different functions with each event listener use the code below: $('filter').observe('keyup', function(evt) {this.fire('check:filter');}).observe('click',function(evt) {this.fire('check:filter');}).observe('focus', function(evt) {this.fire('check:filter');}).observe('blur', function(evt) {this.fire('check:filter');}); Hope this helps, Chris On Dec 23, 7:16 am, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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] Is there a way to DRY this up?
On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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: Behavioral of select option
Hi I think the error might be to do with this section of code: ...).down('input.previous')... this is calling for the first input with a class name of 'previous' within the element with the id of 'paging', what I'm assuming you were trying to do was get the element that comes before the first input in the element with the id of 'paging' if so the following should work: $('paging').down('input').previous().observe('click', _msoS.handlePagingSubmit.bindAsEventListener(_msoS, $F('myselect'))); If not, could you post the entirety of your code including your HTML? Then perhaps I may be of more help. Cheers, Chris On Dec 23, 10:57 am, kstubs kst...@gmail.com wrote: I have a select option, in HTML It is empty like this: select id=myselect name=selectoroption//select After page load I make ajax request and finish loading the selector with additional option(s). So I might have: select id=myselect name=selector option1/option option2/option option3/option /select I have registered an event to handle a submit click for the form and pass the value to the click handler event like this: $('paging').down('input.previous').observe('click', _msoS.handlePagingSubmit.bindAsEventListener(_msoS, $F('myselect'))); The value passed to my click handler for myselect is NULL but indeed the first option is selected. Whats wrong? -- 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: PeriodicalExecuter counter
Hi, Below is a patch to PeriodicalExecuter that should do what your asking, I have Prototype 1.7.min and this patch is untested: var PeriodicalExecuter=Class.create({initialize:function(callback,frequency) {this.callback=callback;this.frequency=frequency;this.currentlyExecuting=false;this.iterations=0;this.registerCallback()},registerCallback:function() {this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000)},execute:function() {this.callback(this)},stop:function(){if(! this.timer)return;clearInterval(this.timer);this.timer=null},onTimerEvent:function() {if(!this.currentlyExecuting) {try{this.currentlyExecuting=true;this.iterations+ +;this.execute();this.currentlyExecuting=false}catch(e) {this.currentlyExecuting=false;throw e); I suggest you make a backup of your current prototype implementation if you have made any other modifications to it. Replace the current PeriodicalExecuter class with the one above. To find out what iteration PE is on just call 'pe.iterations', 'pe' being the variable name of the argument supplied to the callback function. Or to find out from outside of the callback just use 'pe.iterations', in this case 'pe' being the variable name in which the implementation of PeriodicalExecuter is stored. Hope this helps. Cheers, Chris Oh and Merry Christmas. On Dec 18, 11:20 am, JoJo tokyot...@gmail.com wrote: What's the best way to find which iteration the PeriodicalExecutuer is currently on? What I'm trying to do is step through an array slowly (period of 0.5 seconds) and having the ability to stop at an arbitrary time. The PeriodicalExecuter has the ability to stop, but it doesn't have the ability to step sequentially through an array. Or should I not even attempt to use PE's for 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-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] Is there a way to DRY this up?
Good Idea! :D Dunno why I didn't think of that, I used something like that the other day, Doh.. Chris On 23 December 2010 23:02, Richard Quadling rquadl...@gmail.com wrote: On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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.comprototype-scriptaculous%2bunsubscr...@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.
[Proto-Scripty] Re: Behavioral of select option
On Dec 22, 9:57 pm, kstubs kst...@gmail.com wrote: I have a select option, in HTML It is empty like this: select id=myselect name=selectoroption//select After page load I make ajax request and finish loading the selector with additional option(s). So I might have: select id=myselect name=selector option1/option option2/option option3/option /select I have registered an event to handle a submit click for the form and pass the value to the click handler event like this: $('paging').down('input.previous').observe('click', _msoS.handlePagingSubmit.bindAsEventListener(_msoS, $F('myselect'))); The value passed to my click handler for myselect is NULL but indeed the first option is selected. You haven't said how the first option is selected (whether by the user, or by the initial Ajax load); but I think the problem might be that with some browsers if you populate a select by Javascript it is not enough to have one or more of the options 'selected': you need to tell the select explicitly what is selected. -- 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] Is there a way to DRY this up?
Excellent suggestions. Thanks, all! Walter On Dec 23, 2010, at 5:42 AM, Christopher Dyson wrote: Good Idea! :D Dunno why I didn't think of that, I used something like that the other day, Doh.. Chris On 23 December 2010 23:02, Richard Quadling rquadl...@gmail.com wrote: On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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 . -- 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 . -- 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: Is there a way to DRY this up?
@Richard: Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); That creates four identical functions (one for each event). Not necessarily a problem, but... @Walter: How 'bout *really* not repeating yourself: ;-) // In your bag of tricks Element.addMethods({ observeAll: function(element, eventNames, handler) { if (!(element = $(element))) return; eventNames = typeof eventNames === string ? $w(eventNames) : eventNames; eventNames.each(function(eventName) { Event.observe(element, eventName, handler); }); return element; } }); // Then in this specific case: $('filter').observeAll(['keyup', 'click', 'focus', 'blur'], function(evt) { this.fire('check:filter'); }); // Or: $('filter').observeAll('keyup click focus blur', function(evt) { this.fire('check:filter'); }); // Or even: var filter = $('filter'); filter.observeAll( 'keyup click focus blur', Element.fire.curry(filter, 'check:filter')); FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 23, 10:02 am, Richard Quadling rquadl...@gmail.com wrote: On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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: Observe form submit which button clicked?
It can be even simpler than Walter's version, and I'm not aware of any issues with `click` not bubbling: $('theForm').observe('click', function(event) { // Find out if it was a submit button that was clicked var button = event.findElement('input[type=submit]'); if (button) { // Yes, grab its value and do something with it. // In this example, we'll populate a hidden field // with the name q: this.down('input[name=q]').value = button.value; } }); Here's a live example: http://jsbin.com/ukifo3 Works with IE6, IE7, Firefox, Opera, Chrome... FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 22, 9:51 pm, kstubs kst...@gmail.com wrote: OK, just observing click event for the submit button is working fine. -- 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] Re: Is there a way to DRY this up?
As usual, taking it to the space elevator! Thanks so much! Walter On Dec 23, 2010, at 10:21 AM, T.J. Crowder wrote: @Richard: Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); That creates four identical functions (one for each event). Not necessarily a problem, but... @Walter: How 'bout *really* not repeating yourself: ;-) // In your bag of tricks Element.addMethods({ observeAll: function(element, eventNames, handler) { if (!(element = $(element))) return; eventNames = typeof eventNames === string ? $w(eventNames) : eventNames; eventNames.each(function(eventName) { Event.observe(element, eventName, handler); }); return element; } }); // Then in this specific case: $('filter').observeAll(['keyup', 'click', 'focus', 'blur'], function(evt) { this.fire('check:filter'); }); // Or: $('filter').observeAll('keyup click focus blur', function(evt) { this.fire('check:filter'); }); // Or even: var filter = $('filter'); filter.observeAll( 'keyup click focus blur', Element.fire.curry(filter, 'check:filter')); FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 23, 10:02 am, Richard Quadling rquadl...@gmail.com wrote: On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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 . -- 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] element.getStyle('border') does not work
Hello guys I am using the latest version of JS Prototype, 1.7. I have never asked a question about JS Prototype online because I always figured it out somehow or just found another solution. But that's not true this time. In CSS, the border is set on an element like this: #element { border:#00 solid 3px; } Now I try to get the border value in JS Prototype with this code: $('element').getStyle('border'); And this is the return I get in Firebug: (an empty string) I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? 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.
Re: [Proto-Scripty] element.getStyle('border') does not work
reorder the border attributes so they are type, size, color and see if that solves your problem. On Thu, Dec 23, 2010 at 11:53 AM, marbrun marb...@me.com wrote: Hello guys I am using the latest version of JS Prototype, 1.7. I have never asked a question about JS Prototype online because I always figured it out somehow or just found another solution. But that's not true this time. In CSS, the border is set on an element like this: #element { border:#00 solid 3px; } Now I try to get the border value in JS Prototype with this code: $('element').getStyle('border'); And this is the return I get in Firebug: (an empty string) I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? 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.comprototype-scriptaculous%2bunsubscr...@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.
[Proto-Scripty] Re: element.getStyle('border') does not work
I tried that already. Also tried just with getStyle('border-width') but that gives nothing either. Other styles like background-color are returned well. On 23 dec, 18:02, Jane Hunter jane...@gmail.com wrote: reorder the border attributes so they are type, size, color and see if that solves your problem. On Thu, Dec 23, 2010 at 11:53 AM, marbrun marb...@me.com wrote: Hello guys I am using the latest version of JS Prototype, 1.7. I have never asked a question about JS Prototype online because I always figured it out somehow or just found another solution. But that's not true this time. In CSS, the border is set on an element like this: #element { border:#00 solid 3px; } Now I try to get the border value in JS Prototype with this code: $('element').getStyle('border'); And this is the return I get in Firebug: (an empty string) I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? 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.comprototype-scriptaculous%2bunsubscr...@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] Re: Is there a way to DRY this up?
@TJ Yeah. I sort of noticed that. I like the observeAll mechanism. Very reusable. In PHP, I could ... if (!!fn || fn = function(){...}) { fn(); } sort of thing. Basically assign a value to a variable and evaluate the assignment. For closures, this is always true. Could this be done in JS? On 23 December 2010 15:21, T.J. Crowder t...@crowdersoftware.com wrote: @Richard: Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); That creates four identical functions (one for each event). Not necessarily a problem, but... @Walter: How 'bout *really* not repeating yourself: ;-) // In your bag of tricks Element.addMethods({ observeAll: function(element, eventNames, handler) { if (!(element = $(element))) return; eventNames = typeof eventNames === string ? $w(eventNames) : eventNames; eventNames.each(function(eventName) { Event.observe(element, eventName, handler); }); return element; } }); // Then in this specific case: $('filter').observeAll(['keyup', 'click', 'focus', 'blur'], function(evt) { this.fire('check:filter'); }); // Or: $('filter').observeAll('keyup click focus blur', function(evt) { this.fire('check:filter'); }); // Or even: var filter = $('filter'); filter.observeAll( 'keyup click focus blur', Element.fire.curry(filter, 'check:filter')); FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 23, 10:02 am, Richard Quadling rquadl...@gmail.com wrote: On 22 December 2010 18:16, Walter Lee Davis wa...@wdstudio.com wrote: I have a quick filter for hiding list items until only matches show. I want to cover all the various ways that a user might interact with the search field, so I write this lovely: $('filter').observe('keyup', function(evt){ this.fire('check:filter'); }); $('filter').observe('click', function(evt){ this.fire('check:filter'); }); $('filter').observe('focus', function(evt){ this.fire('check:filter'); }); $('filter').observe('blur', function(evt){ this.fire('check:filter'); }); Is there any way to write this more clearly, as in with fewer lines of code? I'm using 1.6.latest, haven't tried the new 1.7 goodies yet. Would that help? Walter -- 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. Maybe something like ... ['keyup', 'click', 'focus', 'blur'].each(function(eventName){ $('filter').observe(eventName, function(evt){ this.fire('check:filter'); }); }); -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- 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] element.getStyle('border') does not work
I just tried this with 1.6 and can report the following: * It works if you define the style inline (in the div's style tag). * It works if you set the attribute using Prototype Element.setStyle * It works for any simple attribute that does not have a composite- shortcut form, like width, no matter where in the CSS hierarchy that value was defined. * For anything that has a composite form, like margin (versus margin- left) the only way to get this to work is to set the property inline or by JavaScript (which I believe does the same thing as inline internally). (But this is not universally true for all attributes -- see below.) If you want to get the border property en toto, then you'll have to do the long-hand or JavaScript assignment. But if you want to reference a border-left-width in your code that is set outside of the style attribute on the tag itself, you will probably have to write your CSS in completely long-hand format: #foo { border-left-width: 2px; border-left-style: solid; border-left-color: #ccc; } I just discovered something else that's fairly alarming -- I defined margin-left: auto; on a div in the page head style tag, then asked for $('thatDiv').getStyle('margin-left') and got back 0px as the value. Doesn't matter where I define it, inline is no different. Firefox 3.latest with Firebug.latest. Walter On Dec 23, 2010, at 11:53 AM, marbrun wrote: I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? -- 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: element.getStyle('border') does not work
Great test! Strange thing are these results: $('test').measure('border'); - undefined $('test').measure('border-box-width') - 210 $('test').measure('width') - 200 #test { width:200px; border:solid 5px #00; } So even with the new measure and getLayout methods in JS Prototype 1.7 you would need to do the math yourself when you just want the border. Is this a bug? On 23 dec, 18:29, Walter Lee Davis wa...@wdstudio.com wrote: I just tried this with 1.6 and can report the following: * It works if you define the style inline (in the div's style tag). * It works if you set the attribute using Prototype Element.setStyle * It works for any simple attribute that does not have a composite- shortcut form, like width, no matter where in the CSS hierarchy that value was defined. * For anything that has a composite form, like margin (versus margin- left) the only way to get this to work is to set the property inline or by JavaScript (which I believe does the same thing as inline internally). (But this is not universally true for all attributes -- see below.) If you want to get the border property en toto, then you'll have to do the long-hand or JavaScript assignment. But if you want to reference a border-left-width in your code that is set outside of the style attribute on the tag itself, you will probably have to write your CSS in completely long-hand format: #foo { border-left-width: 2px; border-left-style: solid; border-left-color: #ccc; } I just discovered something else that's fairly alarming -- I defined margin-left: auto; on a div in the page head style tag, then asked for $('thatDiv').getStyle('margin-left') and got back 0px as the value. Doesn't matter where I define it, inline is no different. Firefox 3.latest with Firebug.latest. Walter On Dec 23, 2010, at 11:53 AM, marbrun wrote: I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? -- 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: element.getStyle('border') does not work
It doesn't seem to be a Prototype-specific thing. `getComputedStyle` is just not giving back that information: http://jsbin.com/uyifa4 Except on Opera. It works on Opera. V. weird. FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 23, 5:10 pm, marbrun marb...@me.com wrote: I tried that already. Also tried just with getStyle('border-width') but that gives nothing either. Other styles like background-color are returned well. On 23 dec, 18:02, Jane Hunter jane...@gmail.com wrote: reorder the border attributes so they are type, size, color and see if that solves your problem. On Thu, Dec 23, 2010 at 11:53 AM, marbrun marb...@me.com wrote: Hello guys I am using the latest version of JS Prototype, 1.7. I have never asked a question about JS Prototype online because I always figured it out somehow or just found another solution. But that's not true this time. In CSS, the border is set on an element like this: #element { border:#00 solid 3px; } Now I try to get the border value in JS Prototype with this code: $('element').getStyle('border'); And this is the return I get in Firebug: (an empty string) I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? 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.comprototype-scriptaculou s%2bunsubscr...@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.
[Proto-Scripty] Re: element.getStyle('border') does not work
Doh! Not all that weird, I'd forgotten that `border-size` is a shorthand property! Works with full names: http://jsbin.com/uyifa4/2 Nice one, Walter! -- T.J. On Dec 23, 5:45 pm, T.J. Crowder t...@crowdersoftware.com wrote: It doesn't seem to be a Prototype-specific thing. `getComputedStyle` is just not giving back that information:http://jsbin.com/uyifa4 Except on Opera. It works on Opera. V. weird. FWIW, -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com On Dec 23, 5:10 pm, marbrun marb...@me.com wrote: I tried that already. Also tried just with getStyle('border-width') but that gives nothing either. Other styles like background-color are returned well. On 23 dec, 18:02, Jane Hunter jane...@gmail.com wrote: reorder the border attributes so they are type, size, color and see if that solves your problem. On Thu, Dec 23, 2010 at 11:53 AM, marbrun marb...@me.com wrote: Hello guys I am using the latest version of JS Prototype, 1.7. I have never asked a question about JS Prototype online because I always figured it out somehow or just found another solution. But that's not true this time. In CSS, the border is set on an element like this: #element { border:#00 solid 3px; } Now I try to get the border value in JS Prototype with this code: $('element').getStyle('border'); And this is the return I get in Firebug: (an empty string) I have simplified all other code, so there nothing else influencing it. I have even tested this in another project using Prototype version 1.6. No result. How can I solve this quite important problem? 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.comprototype-scriptaculou s%2bunsubscr...@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.
[Proto-Scripty] Re: Class.create() and Object.clone() and methods
HI! Great! Thanks! Thomas -- 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] Dilemma: singleton or ordinal object?
Usually we have some fields in a form like date-field. I have a dilemma: in such languages as C# I would create singleton and use one class per many date-fields to display calendar. I dont know is it possible (how to create singleton class and how create ordinary class with static methods and fields) and expediently to make singleton calendar class or have on ordinary calendar object per date-field? Help me please -- 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: Behavioral of select option
Chris, the selector is valid, I have an input with a class=previous within a form container id=paging Colin, after the select option list is dynamically constructed I set the first item in the list like this: pagePageSelector.options.selectedIndex = (currentpage - 1); I've stepped through the code at this point and there is no issue here, currentpage has value and -1 this value is 0 or greater. After additional study I have learned that there was conflicting events on document:load that meant certain assigned event handler bindings invalid. I have moved these binding scripts into later event handled scripts. Thanks for the help. Issue solved. Karl.. -- 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: Observe form submit which button clicked?
T.J., Duhh! Thanks for pointing out the obvious. I was stuck on observing submit. Now, I've tested your page in Chrome and FF, but doesn't seem to be working, instead I am taken straight to Google. -- 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.