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

Ticket #3876 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] Add enumerable method for JavascriptElementProxy

Reported by: rick Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version: 1.0.0
Severity: normal Keywords:
Cc: technoweenie@gmail.com

Description

page.select('#versions li.selected').each do |page, element|
  page.call 'Element.removeClassName', element, 'selected'
end

generates

$$('#versions li.selected').each(function(element)) {
  Element.removeClassName(element, 'selected')
})

Attachments

javascript_element_proxy.3597.diff (1.6 kB) - added by rick on 02/17/06 22:59:54.
enum_proxy.3618.diff (11.3 kB) - added by rick on 02/19/06 07:26:25.
all prototype enums added.
prototype_helpers.diff (16.5 kB) - added by rick on 02/25/06 16:32:47.
prototype_helpers.fixed.diff (16.5 kB) - added by rick on 02/25/06 16:40:29.
fixed issue with chained visual_effects call
prototype_helpers.taketwo.diff (13.5 kB) - added by Rick on 03/03/06 19:23:55.
enabled element function chaining in enumerations

Change History

02/17/06 22:59:54 changed by rick

  • attachment javascript_element_proxy.3597.diff added.

02/17/06 23:03:20 changed by anonymous

  • cc set to technoweenie@gmail.com.

02/19/06 00:31:41 changed by david

  • keywords set to untested.

Looks great! Needs tests, though. Perhaps you could extend it to the other parts of enumerable? Like select, reject, etc.

02/19/06 00:32:00 changed by david

  • keywords changed from untested to unverified.

02/19/06 07:26:25 changed by rick

  • attachment enum_proxy.3618.diff added.

all prototype enums added.

02/19/06 07:33:39 changed by rick

  • keywords deleted.

Done. One odd thing that I'm not totally sure on is the way the enumerable proxy methods set variables. I can't do this because of the way the proxy chains the calls:

page.assign('foo_items', page.select('#list li').collect { |page, element| page << "(element.className == 'foo')" })
}}]

So, I did this instead:

{{{
page.select('#list li').collect('foo_items') { |page, element| page << "(element.className == 'foo')" })
}}]

Anyways, gobs of tests included this time.  I also added tests for the new JSON encoders.
}}}

02/19/06 07:37:54 changed by rick

Preview is my friend...

One odd thing that I'm not totally sure on is the way the enumerable proxy methods set variables. I can't do this because of the way the proxy chains the calls:

page.assign('foo_items', page.select('#list li').collect { |page, element| page << "(element.className == 'foo')" })

So, I did this instead:

page.select('#list li').collect('foo_items') { |page, element| page << "(element.className == 'foo')" })

Anyways, gobs of tests included this time. I also added tests for the new JSON encoders.

02/23/06 06:11:17 changed by david

Is there any way to turn:

page.select('#versions li.selected').each do |page, element|
  page.call 'Element.removeClassName', element, 'selected'
end

into:

page.select('#versions li.selected').each do |page, element|
  element.remove_class_name 'selected'
end

?

02/25/06 16:32:47 changed by rick

  • attachment prototype_helpers.diff added.

02/25/06 16:39:25 changed by rick

Changes:

page.select('#versions li.selected').first.hide
=> Element.hide($$('#versions li.selected).first());

page.select('#versions li.selected').each do |page, element|
  element.remove_class_name 'selected'
end
=> $$('#versions li.selected').each(function(element) { Element.removeClassName(element, 'selected') }

page['foo'].hide
=> Element.hide('foo')

page['foo'].show.visual_effect :highlight
=> Element.show('foo')
=> new Effect.Highlight('foo',{})

02/25/06 16:40:29 changed by rick

  • attachment prototype_helpers.fixed.diff added.

fixed issue with chained visual_effects call

03/03/06 19:23:55 changed by Rick

  • attachment prototype_helpers.taketwo.diff added.

enabled element function chaining in enumerations

03/03/06 19:34:27 changed by david

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

(In [3754]) RJS now does enumerations, baby! (closes #3876) [Rick Olson]