![]() |
# Class: JavaScriptGenerator [ "README", "AUTHORS", "COPYING", "lib/bivouac/helpers/view/goh/base.rb", "lib/bivouac/helpers/view/goh/form.rb", "lib/bivouac/helpers/view/goh/html.rb", "lib/bivouac/helpers/view/goh/sound.rb", "lib/bivouac/helpers/view/goh/scriptaculous.rb", "lib/bivouac/helpers/view/goh/javascript.rb", nil].each do JavaScriptGenerator.view_html BivouacHelpers.view_html BivouacHelpers::SoundView.view_html BivouacHelpers::ScriptAculoUsView.view_html BivouacHelpers::BaseView.view_html BivouacHelpers::JavaScriptView.view_html BivouacHelpers::HtmlView.view_html BivouacHelpers::FormView.view_html end |

Writes raw JavaScript to the page.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 54
54: def <<(javascript)
55: @source << javascript
56: end
![Permalink to Public Instance method: []](../permalink.gif)
Returns a element reference by finding it through id in the DOM. This element can then be used for further method calls. Examples:
page['blank_slate'] # => $('blank_slate');
page['blank_slate'].show # => $('blank_slate').show();
page['blank_slate'].show('first').up # => $('blank_slate').show('first').up();
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 24
24: def []( id )
25: # JavaScriptElementProxy.new(self, id)
26: end

Displays an alert dialog with the given message.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 59
59: def alert(message)
60: call( "alert", message )
61: end

Assigns the JavaScript variable the given value.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 64
64: def assign( variable, value )
65: record "#{variable} = #{value.inspect}"
66: end

Calls the JavaScript function, optionally with the given arguments.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 104
104: def call(function, *arguments)
105: record "#{function}(#{arguments_for_call(arguments)});\n"
106: end

Executes the content of the block after a delay of seconds. Example:
page.delay(20) do
page.visual_effect :fade, 'notice'
end
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 175
175: def delay(seconds = 1)
176: record "setTimeout(function() {\n\n"
177: yield
178: record "}, #{(seconds * 1000).to_i})"
179: end

Creates a script.aculo.us draggable element. See ActionView::Helpers::ScriptaculousHelper for more information.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 70
70: def draggable( id, options = {} )
71: record @context.draggable_element_js( id, options ) + ";\n"
72: end

Creates a script.aculo.us drop receiving element. See ActionView::Helpers::ScriptaculousHelper for more information.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 76
76: def drop_receiving( id, options = {} )
77: record @context.drop_receiving_element_js( id, options ) + ";\n"
78: end

Hides the visible DOM elements with the given ids.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 81
81: def hide( *ids )
82: loop_on_multiple_args 'Element.hide', ids
83: end

Inserts HTML at the specified position relative to the DOM element identified by the given id.
position may be one of:
| :top: | HTML is inserted inside the element, before the element‘s existing content. |
| :bottom: | HTML is inserted inside the element, after the element‘s existing content. |
| :before: | HTML is inserted immediately preceeding the element. |
| :after: | HTML is inserted immediately following the element. |
data may be a string of HTML to insert.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 98
98: def insert_html(position, id, data)
99: insertion = position.to_s.camelize
100: call "new Insertion.#{insertion}", id, data
101: end

Redirects the browser to the given location.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 109
109: def redirect_to(location)
110: assign 'window.location.href', location
111: end

Removes the DOM elements with the given ids from the page.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 114
114: def remove(*ids)
115: loop_on_multiple_args 'Element.remove', ids
116: end

Replaces the "outer HTML" (i.e., the entire element, not just its contents) of the DOM element with the given id.
data may be a string of HTML to insert. For example:
# Replace the DOM element having ID 'person-45' with the # 'person' partial for the appropriate object. replace 'person-45', render( 'person', :object => @person )
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 139
139: def replace(id, data)
140: call 'Element.replace', id, data
141: end

Replaces the inner HTML of the DOM element with the given id.
data may be a string of HTML to insert
# Replace the HTML of the DOM element having ID 'person-45' with the # 'person' partial for the appropriate object. replace_html 'person-45', render( 'person', :object => @person )
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 126
126: def replace_html(id, data)
127: call 'Element.update', id, data
128: end

Returns a collection reference by finding it through a CSS pattern in the DOM. This collection can then be used for further method calls. Examples:
page.select('p') # => $$('p');
page.select('p.welcome b').first # => $$('p.welcome b').first();
page.select('p.welcome b').first.hide # => $$('p.welcome b').first().hide();
You can also use prototype enumerations with the collection. Observe:
page.select('#items li').each do |value|
value.hide
end
# => $$('#items li').each(function(value) { value.hide(); });
Though you can call the block param anything you want, they are always rendered in the javascript as ‘value, index.’ Other enumerations, like collect() return the last statement:
page.select('#items li').collect('hidden') do |item|
item.hide
end
# => var hidden = $$('#items li').collect(function(value, index) { return value.hide(); });
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 49
49: def select(pattern)
50: # JavaScriptElementCollectionProxy.new(self, pattern)
51: end

Shows hidden DOM elements with the given ids.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 144
144: def show(*ids)
145: loop_on_multiple_args 'Element.show', ids
146: end

Creates a script.aculo.us sortable element. Useful to recreate sortable elements after items get added or deleted.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 150
150: def sortable(id, options = {})
151: record @context.sortable_element_js( id, options ) + ";\n"
152: end

Toggles the visibility of the DOM elements with the given ids.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 161
161: def toggle(*ids)
162: loop_on_multiple_args 'Element.toggle', ids
163: end

Creates a script.aculo.us unsortable element. Useful to recreate unsortable elements after items get added or deleted.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 156
156: def unsortable( id )
157: record @context.unsortable_element_js( id ) + ";\n"
158: end

Starts a script.aculo.us visual effect.
[ show source ]
# File lib/bivouac/helpers/view/goh/javascript.rb, line 166
166: def visual_effect(name, element_id = false, js_options = {})
167: record( @context.visual_effect( name, element_id, js_options ) + ";\n" )
168: end