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



[Proto-Scripty] Re: Stack overflow... ???

2010-10-17 Thread T.J. Crowder
Hi,

 ...data-picker is a real
 attribute?? or you just add it for easy use with the $('*[data-
 picker]') selector??

I made it up for use with the selector. Technically, custom (made-up)
attributes are invalid in HTML4, but in practice browsers just ignore
them (but do preserve them and give them to getAttribute/
readAttribute), although validators like the W3C's[1] flag them up (of
course, that's their job). As of HTML5, custom attributes are
explicitly allowed if they start with the prefix data-. So you can
have your own attributes if you like -- data-foo, data-bar, data-
my-nifty-thing, etc.

[1] http://validator.w3.org

HTH,

-- T.J. :-)

On Oct 15, 5:00 pm, ncubica ncub...@gmail.com wrote:
 [off-topic] Hi TJ I just saw in your jsbin code the attribute span
 data-picker='colors=blue'Blue/span data-picker is a real
 attribute?? or you just add it for easy use with the $('*[data-
 picker]') selector??

 thanks in advance
 nahum

 On Oct 14, 10:35 am, T.J. Crowder t...@crowdersoftware.com wrote:



  Hi,

   Thanks also for the short version of your setSelect()...

  Glad that helped!

   ...I tried in vain to do
   that for a full day... another example of how the prototype documentation
   really sucks!

  Okay, granted it's a bit 
  terse:http://api.prototypejs.org/dom/form/element/setvalue/

  ...but I wouldn't have said it sucked. Regardless, I know from
  experience that they're very happy indeed to accept documentation
  patches to improve things...

  -- T.J. ;-)

  On Oct 14, 1:42 pm, Phil Petree phil.pet...@gmail.com wrote:

   Thanks TJ!

   I had fixed the Stack Overflow problem around 6a this morning... I would
   share what the problem was but then I'd have to kill my self! LOL

   Thanks also for the short version of your setSelect(), I tried in vain to 
   do
   that for a full day... another example of how the prototype documentation
   really sucks!  It should have been a 2 minute find/do.

   Not gonna worry about the click handler because there are only 8 onclicks 
   on
   that page and I doubt a user will use more than 1 or 2 of them... if they
   even realize those images work that way... just an easter egg is all it 
   is.

   On Thu, Oct 14, 2010 at 7:33 AM, T.J. Crowder 
   t...@crowdersoftware.comwrote:

Hi,

I'm not 100% sure what you're trying to do with all of those templates
and that selector (the selector is invalid, looks like maybe you're
trying to use a template in it, but it's all one big quoted string,
so...). However, I _think_ you're trying to replicate the Prototype
`Element#setValue` function. If I'm reading right, your `setSelect`
could read like this:

function setSelect(selID, strValue) {
 $(selID).setValue(strValue);
}

Live example:http://jsbin.com/aboyo

Perhaps off-topic, but I wouldn't have all of those onclicks if you
can avoid it:
   http://jsbin.com/aboyo/2

You can condense that a bit:
   http://jsbin.com/aboyo/3

HTH, apologies if I've gotten the wrong end of the stick.
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Oct 14, 1:54 am, Phil Petree phil.pet...@gmail.com wrote:
 Hey All!

 In my html doc I have a series of images... one for aol, yahoo, gmail,
 facebook etc. and each image in written like this:
 img src='images/aol.png' border='0' onclick='setSelect(thSelect,
 aol);'/

 In my javascript file I have setSelect defined like this:
 function setSelect(strID, strValue)
 {
   var selectIDTemplate = new Template('#{matchID}');
   var selectTemplate = new Template('#{matchString}');
   var selectThis = {matchID: strID};
   var selectID = {matchString: strValue };
   $$('select#selectIDTemplate.evaluate(selectID)
option').each(function(o){
     if(o.value == selectTemplate.evaluate(selectThis)){o.selected =
 true;$break;}
   });

 }

 When I click on an image I get a Stack Overflow on line 29 error.  
 This
is
 with prototype.js 1.6.1

 Any ideas? Suggestions?

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

[Proto-Scripty] Re: Scalable Drag Drop (without noticeable lag)

2010-10-17 Thread T.J. Crowder
Hi,

 Not much I can do about that i
 guess. just letting you know I didn't write it that way.

What I usually do is post it inline in the message (as you did), and
*also* post it to Pastie.org and provide a link. Pastie preserves the
formatting correctly. (I've never quite understood the truly bizarre
and arbitrary way Google adds linebreaks to code...)

FWIW,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Oct 15, 7:08 pm, Scott counterstre...@gmail.com wrote:
 When copying and pasting the html from my post, there are some extra
 line breaks or wrapping happening. Not much I can do about that i
 guess. just letting you know I didn't write it that way.

-- 
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] Toggle checkboxes???

2010-10-17 Thread Phil Petree
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.

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.



Re: [Proto-Scripty] Toggle checkboxes???

2010-10-17 Thread Jarkko Laine
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???

2010-10-17 Thread Phil Petree
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).

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.comprototype-scriptaculous%2bunsubscr...@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.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] Toggle checkboxes???

2010-10-17 Thread Jarkko Laine

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.