[Proto-Scripty] Re: Is there a way to DRY this up?

2010-12-23 Thread Neaox
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.



[Proto-Scripty] Re: Behavioral of select option

2010-12-23 Thread Neaox
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

2010-12-23 Thread Neaox
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.



[Proto-Scripty] Locking an Event Listener/Observe

2010-10-17 Thread Neaox
Hi,

I am wanting the ability to lock an event as I register it so that is
can't be removed or unregistered for example

  Event.Observe('element_id', 'click', function_name, true);

The last parameter being a boolean value for locking the event or not,
which would be false by default.

Once a event has been registered locked then it cannot be removed via
the following methods:

  Event.stopObserving('element_id', 'click');

or

  Event.stopObserving('element_id');

UNLESS

  Event.stopObserving('element_id', 'click', NULL, true);

or

  Event.stopObserving('element_id', NULL, NULL, true);

The last parameter being a boolean value stating if you wish to remove
locked listeners, this would be false by default.

You would also be able to remove the locked event via the following:

Event.stopObserving('element_id', 'click', function_name);

I think it would also be a good idea to add another parameter to the
event.observe:

  Event.Observe('element_id', 'click', function_name, true,
true);

This one also being a boolean value (false by default) indicating that
the event listener should be hard locked meaning that it can ONLY be
unregistered by fully referencing it (cannot by unregistered via any
methods above, except last one):

 Event.stopObserving('element_id', 'click', function_name);

I have tried to create something like this myself but I can't get my
head around the caching etc, could some awsome person create a patch
to perfrom this or at least point me in the right direction?

Cheers

-- 
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.