Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3568 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 1 year ago

[PATCH] Add Behavior object to prototype

Reported by: devslashnull@gmail.com Assigned to: sam@conio.net
Priority: high Milestone:
Component: Prototype Version: 1.0.0
Severity: minor Keywords: behavior prototype IE
Cc: handcoding

Description

Based largely on behavior.js by Ben Nolan, this patch adds a prototype object called Behavior which applies behaviors to page elements using the new Selector prototype object.

This will clean up the generated markup and hopefully provide an easy way to maintain consistent selector-based behavior of page elements, even when RJS and other DOM manipulation adds and removes elements.

Basic documentation of the helper methods is included and contains examples of use, such as this one, which modifies all PDF links to open in a new window:

register_behaviors 'a' =>
  'if (/\.pdf$/i.test(element.href)) element.target = "_blank";'

Thanks to kastner for the idea and for design help, and to Ben Nolan for the original idea.

Attachments

prototype_behavior_object_patch.diff (1.7 kB) - added by devslashnull@gmail.com on 01/22/06 01:51:15.
Patch for the spinoffs directory
prototype_helper_behavior_methods_patch.diff (4.1 kB) - added by devslashnull@gmail.com on 01/22/06 01:51:43.
Patch for the trunk directory
prototype_behavior_object_patch2.diff (1.8 kB) - added by devslashnull@gmail.com on 01/23/06 02:36:12.
Patch for the spinoffs directory, fixes issues with multiple callbacks and allows multiple selectors per behavior
prototype_helper_behavior_methods_patch2.diff (5.6 kB) - added by devslashnull@gmail.com on 01/23/06 02:37:45.
Patch for the trunk directory, allows multiple selectors per behavior and adds more tests

Change History

01/22/06 01:51:15 changed by devslashnull@gmail.com

  • attachment prototype_behavior_object_patch.diff added.

Patch for the spinoffs directory

01/22/06 01:51:43 changed by devslashnull@gmail.com

  • attachment prototype_helper_behavior_methods_patch.diff added.

Patch for the trunk directory

01/22/06 01:52:02 changed by devslashnull@gmail.com

  • keywords set to behavior prototype.

01/22/06 01:56:48 changed by david

  • owner changed from sam to sam@conio.net.

01/22/06 02:15:08 changed by devslashnull@gmail.com

Please note that this has been tested in Safari and Firefox, but not IE. If anyone would like to test it in IE, please do. Seeing as how it's based on prototype and doesn't do anything novel it ought to work fine.

01/22/06 02:19:45 changed by sam

I'd love to include this. Is it OK with Ben Nolan?

01/23/06 02:36:12 changed by devslashnull@gmail.com

  • attachment prototype_behavior_object_patch2.diff added.

Patch for the spinoffs directory, fixes issues with multiple callbacks and allows multiple selectors per behavior

01/23/06 02:37:45 changed by devslashnull@gmail.com

  • attachment prototype_helper_behavior_methods_patch2.diff added.

Patch for the trunk directory, allows multiple selectors per behavior and adds more tests

01/23/06 02:40:35 changed by devslashnull@gmail.com

I just emailed Ben, so he should get back to me via email or post here soon.

01/24/06 00:52:47 changed by bnolan@gmail.com

Fine by me. I'm honoured! :D

02/26/06 08:23:47 changed by anonymous

When will this be included with prototype?

07/24/06 06:47:17 changed by petermichaux@gmail.com

  • keywords changed from behavior prototype to behavior prototype IE.

08/21/06 18:56:24 changed by anonymous

any news on that?

10/02/06 23:53:50 changed by mislav

  • priority changed from normal to high.
  • severity changed from normal to minor.

Too bad that after 3/4 of a year and approval by both Sam and Ben, this isn't applied. I think Behavior fits into Prototype perfectly. Does it need more or better tests?

+1 for applying it to the source

02/28/07 23:12:11 changed by handcoding

  • cc set to handcoding.

05/28/08 15:38:13 changed by kruse

+1 for an inclusion from me as well.

Do note however that an updated version of Bens Behaviour script (with several bugfixes and improvements) is available from http://www.kruse-net.dk/behaviour/.

I would be happy to provide a customized version of Behaviour if needed.

05/28/08 16:41:51 changed by eventualbuddha

  • status changed from new to closed.
  • resolution set to wontfix.

Wow, I totally forgot about this one (I'm devslashnull@gmail.com). I've started using jQuery instead of Prototype, so I have no stake in the outcome of this ticket anymore.

I propose that, if you want to see this go through, you open a new ticket at the new Lighthouse tracker for Rails and provide an updated patch. Until then, so long.