Class: Element
- Inherits:
-
Object
- Object
- Element
- Includes:
- Enumerable
- Defined in:
- lib/opal/jquery/element.rb
Overview
Element is a toll-free bridged class that maps to native jQuery instances.
As Element maps to a jQuery object, it can be used to represent 0, 1, or more actual DOM elements. Element exposes a more ruby-esqe interface to jQuery.
Usage
Element instances can be created in a number of ways.
Creating new Elements
A new element can be created using the Element.new method.
el = Element.new(:div)
el.id = "title"
p el
# => #<Element [<div id="title">]>
This is a nicer version of creating a javascript element using
document.createElement
and then wrapping it in a jquery object.
Finding existing elements in dom
Any valid jQuery selector expressions can be used with either Element.find or Element.[].
foos = Element.find('.foo')
# => #<Element [<div class="foo">]>
links = Element['a']
# => #<Element [<a>, <a class="bar">]>
Alternatively, Element.id can be used to find an element by its document id (or nil is returned for no match).
= Element.id 'bar'
# => Element or nil
DOM Content from string
Finally, an Element instance can be created by parsing a string of html content. This will parse multiple elements, like jquery, if string content contains them:
Element.parse '<div id="title">hello world</div>'
# => #<Element [<div id="title">]>
Instance Attribute Summary collapse
-
#selector ⇒ Object
readonly
The original css selector used to create Element.
Class Method Summary collapse
-
.[](selector) ⇒ Element
Find elements by the given css selector.
-
.expose(*methods) ⇒ Object
Expose jQuery plugins to become available in ruby code.
-
.find(selector) ⇒ Element
Find elements by the given css selector.
-
.id(id) ⇒ Element?
Find an element by the given id.
-
.new(tag = 'div') ⇒ Element
Create a new dom element, wrapped as Element instance with the given
tag
name. -
.parse(str) ⇒ Element
Parse a string of html content into an Element instance.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](name) ⇒ Object
-
#[]=(name, value) ⇒ Object
Set the given attribute
attr
on each element in this collection. - #add_class(class_name) ⇒ Object
-
#after(content) ⇒ Object
Inserts the given
content
after each element in this set of elements. -
#animate(params, &block) ⇒ Object
Set css values over time to create animations.
-
#any? ⇒ true, false
Returns
true
if this collection has 1 or more elements,false
otherwise. - #append(content) ⇒ Object (also: #<<)
- #append_to(element) ⇒ Object
- #append_to_body ⇒ Object
- #append_to_head ⇒ Object
-
#at(index) ⇒ Element?
Returns the element at the given index as a new Element instance.
- #attr(*args) ⇒ Object
-
#before(content) ⇒ Object
Insert the given
content
before each element in this set of elements. - #blur ⇒ Object
- #children(selector = nil) ⇒ Object
-
#class_name ⇒ String
Returns the CSS class name of the firt element in self collection.
-
#class_name=(name) ⇒ Object
Sets the CSS class name of every element in self collection to the given string.
- #click ⇒ Object
-
#clone ⇒ Element
Clone all elements inside this collection, and return as a new instance.
- #closest(selector) ⇒ Object
-
#css(name, value = nil) ⇒ Object
Get or set css properties on each element in self collection.
- #data(*args) ⇒ Object
- #detach(selector = nil) ⇒ Object
- #each {|`$(self[i])`| ... } ⇒ Object
-
#effect(name, *args, &block) ⇒ Object
Start a visual effect (e.g. fadeIn, fadeOut, …) passing its name.
-
#empty ⇒ Object
Remove all child nodes from each element in this collection.
- #fade_toggle(duration = 400) ⇒ Object
- #filter(selector) ⇒ Element
- #find(selector) ⇒ Object
- #first ⇒ Object
- #focus ⇒ Object
- #get ⇒ Object
- #has_attribute?(name) ⇒ Boolean
- #has_class?(class_name) ⇒ Object
- #height ⇒ Object
- #height=(value) ⇒ Object
- #hide(duration = 400) ⇒ Object
- #html(content = undefined) ⇒ Object
-
#html=(content) ⇒ Object
Set the html content of each element in this collection to the passed content.
- #id ⇒ Object
- #id=(id) ⇒ Object
- #index(selector_or_element = nil) ⇒ Object
- #inspect ⇒ Object
- #is(selector) ⇒ true, false
- #is?(selector) ⇒ Object
-
#last ⇒ Element
Returns a new Element instance containing the last element in this current set.
-
#length ⇒ Integer
(also: #size)
Returns the number of elements in this collection.
- #method_missing(name, *args, &block) ⇒ Object
- #next(selector = nil) ⇒ Object (also: #succ)
- #not(selector) ⇒ Element
- #off(name, sel, block = nil) ⇒ Object
- #offset ⇒ Object
- #on(name, sel = nil, &block) ⇒ Object
- #one(name, sel = nil, &block) ⇒ Object
- #outer_height(include_margin = false) ⇒ Object
- #outer_width(include_margin = false) ⇒ Object
-
#parent(selector = nil) ⇒ Element
Returns a new Element set with the parents of each element in this collection.
-
#parents(selector = nil) ⇒ Element
Returns a new Element set with all parents of each element in this collection.
- #position ⇒ Object
- #prepend(content) ⇒ Object
- #prev(selector = nil) ⇒ Object
-
#prop(name, value = undefined) ⇒ Object
Get or set the property
name
on each element in collection. - #remove(selector = nil) ⇒ Object
- #remove_attr(attr) ⇒ Object
- #remove_attribute(attr) ⇒ Object
- #remove_class(class_name) ⇒ Object
- #replace_all(target) ⇒ Object
- #replace_with(new_content) ⇒ Object
- #respond_to_missing?(name, _) ⇒ Boolean
- #scroll_left ⇒ Object
- #scroll_left=(value) ⇒ Object
- #scroll_top ⇒ Object
- #scroll_top=(value) ⇒ Object
- #select ⇒ Object
- #serialize ⇒ Object
-
#serialize_array ⇒ Array<Hashes>
Serializes a form into an Array of Hash objects.
- #show(duration = 400) ⇒ Object
- #siblings(selector = nil) ⇒ Object
- #slide_down(duration = 400) ⇒ Object
- #slide_toggle(duration = 400) ⇒ Object
- #slide_up(duration = 400) ⇒ Object
-
#stop ⇒ Object
Stop any currently running animations on element.
- #submit ⇒ Object
- #tag_name ⇒ Object
-
#text(text = nil) ⇒ String
Get or set the text content of each element in this collection.
-
#text=(text) ⇒ Object
Set text content of each element in this collection.
- #to_n ⇒ Object
- #to_s ⇒ Object
- #toggle(duration = 400) ⇒ Object
- #toggle_class ⇒ Object
-
#trigger(event) ⇒ Object
Trigger an event on this element.
- #value ⇒ Object
- #value=(value) ⇒ Object
- #visible? ⇒ Boolean
- #width ⇒ Object
- #width=(value) ⇒ Object
- #wrap(wrapper) ⇒ Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/opal/jquery/element.rb', line 783 def method_missing(name, *args, &block) args << block if block_given? %x{ var method = self[#{name}]; if (typeof(method) === 'function') { return method.apply(self, #{args.to_n}); } else { return #{super}; } } end |
Instance Attribute Details
#selector ⇒ Object (readonly)
Returns The original css selector used to create Element.
137 138 139 |
# File 'lib/opal/jquery/element.rb', line 137 def selector @selector end |
Class Method Details
.[](selector) ⇒ Element
Find elements by the given css selector.
Returns an empty Element if no matching elements.
75 76 77 |
# File 'lib/opal/jquery/element.rb', line 75 def self.[](selector) `$(#{selector})` end |
.expose(*methods) ⇒ Object
Expose jQuery plugins to become available in ruby code. By default, jQuery methods or plugins must be manually exposed as ruby methods. This method simply creates an aliasing ruby method to call the original javascript function.
130 131 132 133 134 |
# File 'lib/opal/jquery/element.rb', line 130 def self.expose(*methods) methods.each do |method| alias_native method end end |
.find(selector) ⇒ Element
Find elements by the given css selector.
Returns an empty Element if no matching elements.
65 66 67 |
# File 'lib/opal/jquery/element.rb', line 65 def self.find(selector) `$(#{selector})` end |
.id(id) ⇒ Element?
Find an element by the given id.
If no matching element, then nil
will be returned. A matching element
becomes the sole element in the returned collection.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/opal/jquery/element.rb', line 86 def self.id(id) %x{ var el = document.getElementById(id); if (!el) { return nil; } return $(el); } end |
Instance Method Details
#==(other) ⇒ Object
768 769 770 |
# File 'lib/opal/jquery/element.rb', line 768 def ==(other) `self.is(other)` end |
#[](name) ⇒ Object
414 415 416 417 418 419 420 |
# File 'lib/opal/jquery/element.rb', line 414 def [](name) %x{ var value = self.attr(name); if(value === undefined) return nil; return value; } end |
#[]=(name, value) ⇒ Object
Set the given attribute attr
on each element in this collection.
425 426 427 428 |
# File 'lib/opal/jquery/element.rb', line 425 def []=(name, value) `return self.removeAttr(name)` if value.nil? `self.attr(name, value)` end |
#add_class(class_name) ⇒ Object
314 |
# File 'lib/opal/jquery/element.rb', line 314 alias_native :add_class, :addClass |
#after(content) ⇒ Object
Inserts the given content
after each element in this set of elements.
This method can accept either another Element, or a string.
145 |
# File 'lib/opal/jquery/element.rb', line 145 alias_native :after |
#animate(params, &block) ⇒ Object
Set css values over time to create animations. The first parameter is a set of css properties and values to animate to. The first parameter also accepts a special :speed value to set animation speed. If a block is given, the block is run as a callback when the animation finishes.
526 527 528 529 530 531 532 533 |
# File 'lib/opal/jquery/element.rb', line 526 def animate(params, &block) speed = params.has_key?(:speed) ? params.delete(:speed) : 400 if block_given? `self.animate(#{params.to_n}, #{speed}, block)` else `self.animate(#{params.to_n}, #{speed})` end end |
#any? ⇒ true, false
Returns true
if this collection has 1 or more elements, false
otherwise.
656 657 658 |
# File 'lib/opal/jquery/element.rb', line 656 def any? `self.length > 0` end |
#append(content) ⇒ Object Also known as: <<
247 |
# File 'lib/opal/jquery/element.rb', line 247 alias_native :append |
#append_to(element) ⇒ Object
317 |
# File 'lib/opal/jquery/element.rb', line 317 alias_native :append_to, :appendTo |
#append_to_body ⇒ Object
451 452 453 |
# File 'lib/opal/jquery/element.rb', line 451 def append_to_body `self.appendTo(document.body)` end |
#append_to_head ⇒ Object
455 456 457 |
# File 'lib/opal/jquery/element.rb', line 455 def append_to_head `self.appendTo(document.head)` end |
#at(index) ⇒ Element?
Returns the element at the given index as a new Element instance.
Negative indexes can be used and are counted from the end. If the
given index is outside the range then nil
is returned.
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/opal/jquery/element.rb', line 465 def at(index) %x{ var length = self.length; if (index < 0) { index += length; } if (index < 0 || index >= length) { return nil; } return $(self[index]); } end |
#attr(*args) ⇒ Object
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/opal/jquery/element.rb', line 430 def attr(*args) %x{ var size = args.length; switch (size) { case 1: var result = self.attr(args[0]); return( (result == null) ? nil : result ); break; case 2: return self.attr(args[0], args[1]); break; default: #{raise ArgumentError, '#attr only accepts 1 or 2 arguments'} } } end |
#before(content) ⇒ Object
Insert the given content
before each element in this set of elements.
The given content
can be either an Element, or a string.
153 |
# File 'lib/opal/jquery/element.rb', line 153 alias_native :before |
#blur ⇒ Object
202 |
# File 'lib/opal/jquery/element.rb', line 202 alias_native :blur |
#children(selector = nil) ⇒ Object
199 |
# File 'lib/opal/jquery/element.rb', line 199 alias_native :children |
#class_name ⇒ String
Returns the CSS class name of the firt element in self collection. If the collection is empty then an empty string is returned. Only the class name of the first element will ever be returned.
486 487 488 489 490 491 |
# File 'lib/opal/jquery/element.rb', line 486 def class_name %x{ var first = self[0]; return (first && first.className) || ""; } end |
#class_name=(name) ⇒ Object
Sets the CSS class name of every element in self collection to the given string. self does not append the class names, it replaces the entire current class name.
498 499 500 501 502 503 504 505 |
# File 'lib/opal/jquery/element.rb', line 498 def class_name=(name) %x{ for (var i = 0, length = self.length; i < length; i++) { self[i].className = name; } } self end |
#click ⇒ Object
355 |
# File 'lib/opal/jquery/element.rb', line 355 alias_native :click |
#clone ⇒ Element
Clone all elements inside this collection, and return as a new instance.
293 |
# File 'lib/opal/jquery/element.rb', line 293 alias_native :clone |
#closest(selector) ⇒ Object
205 |
# File 'lib/opal/jquery/element.rb', line 205 alias_native :closest |
#css(name, value = nil) ⇒ Object
Get or set css properties on each element in self collection. If
only the name
is given, then that css property name is read from
the first element in the collection and returned. If the value
property is also given then the given css property is set to the
given value for each of the elements in self collection. The
property can also be a hash of properties and values.
513 514 515 516 517 518 519 520 |
# File 'lib/opal/jquery/element.rb', line 513 def css(name, value=nil) if value.nil? && name.is_a?(String) return `self.css(name)` else name.is_a?(Hash) ? `self.css(#{name.to_n})` : `self.css(name, value)` end self end |
#data(*args) ⇒ Object
535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/opal/jquery/element.rb', line 535 def data(*args) %x{ var result = self.data.apply(self, args); if ( (typeof(result) === 'object') && !(result instanceof #{JQUERY_CLASS}) ) { result = #{ JSON.from_object `result` }; } return result == null ? nil : result; } end |
#detach(selector = nil) ⇒ Object
208 |
# File 'lib/opal/jquery/element.rb', line 208 alias_native :detach |
#each {|`$(self[i])`| ... } ⇒ Object
565 566 567 568 569 570 |
# File 'lib/opal/jquery/element.rb', line 565 def each `for (var i = 0, length = self.length; i < length; i++) {` yield `$(self[i])` `}` self end |
#effect(name, *args, &block) ⇒ Object
Start a visual effect (e.g. fadeIn, fadeOut, …) passing its name.
Underscored style is automatically converted (e.g. effect(:fade_in)
).
Also accepts additional arguments and a block for the finished callback.
550 551 552 553 554 555 |
# File 'lib/opal/jquery/element.rb', line 550 def effect(name, *args, &block) name = name.gsub(/_\w/) { |match| match[1].upcase } args = args.map { |a| a.to_n if a.respond_to? :to_n }.compact args << `function() { #{block.call if block_given?} }` `self[#{name}].apply(self, #{args})` end |
#empty ⇒ Object
Remove all child nodes from each element in this collection.
298 |
# File 'lib/opal/jquery/element.rb', line 298 alias_native :empty |
#fade_toggle(duration = 400) ⇒ Object
396 |
# File 'lib/opal/jquery/element.rb', line 396 alias_native :fade_toggle, :fadeToggle |
#find(selector) ⇒ Object
214 |
# File 'lib/opal/jquery/element.rb', line 214 alias_native :find |
#first ⇒ Object
572 573 574 |
# File 'lib/opal/jquery/element.rb', line 572 def first `self.length ? self.first() : nil` end |
#focus ⇒ Object
211 |
# File 'lib/opal/jquery/element.rb', line 211 alias_native :focus |
#get ⇒ Object
301 |
# File 'lib/opal/jquery/element.rb', line 301 alias_native :get |
#has_attribute?(name) ⇒ Boolean
447 448 449 |
# File 'lib/opal/jquery/element.rb', line 447 def has_attribute?(name) `self.attr(name) !== undefined` end |
#has_class?(class_name) ⇒ Object
320 |
# File 'lib/opal/jquery/element.rb', line 320 alias_native :has_class?, :hasClass |
#height ⇒ Object
756 757 758 |
# File 'lib/opal/jquery/element.rb', line 756 def height `self.height()` || nil end |
#height=(value) ⇒ Object
399 |
# File 'lib/opal/jquery/element.rb', line 399 alias_native :height=, :height |
#hide(duration = 400) ⇒ Object
190 |
# File 'lib/opal/jquery/element.rb', line 190 alias_native :hide |
#html(content = undefined) ⇒ Object
576 577 578 579 580 581 582 583 584 |
# File 'lib/opal/jquery/element.rb', line 576 def html(content = undefined) %x{ if (content != null) { return self.html(content); } return self.html() || ''; } end |
#html=(content) ⇒ Object
Set the html content of each element in this collection to the passed content. Content can either be a string or another Element.
328 |
# File 'lib/opal/jquery/element.rb', line 328 alias_native :html=, :html |
#id ⇒ Object
586 587 588 589 590 591 |
# File 'lib/opal/jquery/element.rb', line 586 def id %x{ var first = self[0]; return (first && first.id) || ""; } end |
#id=(id) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/opal/jquery/element.rb', line 593 def id=(id) %x{ var first = self[0]; if (first) { first.id = id; } return self; } end |
#index(selector_or_element = nil) ⇒ Object
331 |
# File 'lib/opal/jquery/element.rb', line 331 alias_native :index |
#inspect ⇒ Object
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/opal/jquery/element.rb', line 609 def inspect %x{ if (self[0] === document) return '#<Element [document]>' else if (self[0] === window ) return '#<Element [window]>' var val, el, str, result = []; for (var i = 0, length = self.length; i < length; i++) { el = self[i]; if (!el.tagName) { return '#<Element ['+el.toString()+']'; } str = "<" + el.tagName.toLowerCase(); if (val = el.id) str += (' id="' + val + '"'); if (val = el.className) str += (' class="' + val + '"'); result.push(str + '>'); } return '#<Element [' + result.join(', ') + ']>'; } end |
#is(selector) ⇒ true, false
259 |
# File 'lib/opal/jquery/element.rb', line 259 alias_native :is |
#is?(selector) ⇒ Object
334 |
# File 'lib/opal/jquery/element.rb', line 334 alias_native :is?, :is |
#last ⇒ Element
Returns a new Element instance containing the last element in this current set.
277 |
# File 'lib/opal/jquery/element.rb', line 277 alias_native :last |
#length ⇒ Integer Also known as: size
Returns the number of elements in this collection. May be zero.
648 649 650 |
# File 'lib/opal/jquery/element.rb', line 648 def length `self.length` end |
#next(selector = nil) ⇒ Object Also known as: succ
217 |
# File 'lib/opal/jquery/element.rb', line 217 alias_native :next |
#off(name, sel, block = nil) ⇒ Object
729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'lib/opal/jquery/element.rb', line 729 def off(name, sel, block = nil) %x{ if (sel == null) { return self.off(name); } else if (block === nil) { return self.off(name, sel.$$jqwrap); } else { return self.off(name, sel, block.$$jqwrap); } } end |
#offset ⇒ Object
561 562 563 |
# File 'lib/opal/jquery/element.rb', line 561 def offset Native(`self.offset()`) end |
#on(name, sel = nil, &block) ⇒ Object
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/opal/jquery/element.rb', line 669 def on(name, sel = nil, &block) %x{ var has_args = #{block.arity} !== 0; var wrapper = function() { for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) { args[i] = arguments[i]; } // Use preventDefault as a canary for native events if (has_args && args[0].preventDefault) { args[0] = #{Event.new `args[0]`}; } return block.apply(null, args); }; block.$$jqwrap = wrapper; if (sel == nil) { self.on(name, wrapper); } else { self.on(name, sel, wrapper); } } block end |
#one(name, sel = nil, &block) ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/opal/jquery/element.rb', line 699 def one(name, sel = nil, &block) %x{ var has_args = #{block.arity} !== 0; var wrapper = function() { for(var args = new Array(arguments.length), i = 0, ii = args.length; i < ii; i++) { args[i] = arguments[i]; } // Use preventDefault as a canary for native events if (has_args && args[0].preventDefault) { args[0] = #{Event.new `args[0]`}; } return block.apply(null, args); }; block.$$jqwrap = wrapper; if (sel == nil) { self.one(name, wrapper); } else { self.one(name, sel, wrapper); } } block end |
#outer_height(include_margin = false) ⇒ Object
408 |
# File 'lib/opal/jquery/element.rb', line 408 alias_native :outer_height, :outerHeight |
#outer_width(include_margin = false) ⇒ Object
405 |
# File 'lib/opal/jquery/element.rb', line 405 alias_native :outer_width, :outerWidth |
#parent(selector = nil) ⇒ Element
Returns a new Element set with the parents of each element in this
collection. An optional selector
argument can be used to filter the
results to match the given selector. Result may be empty.
163 |
# File 'lib/opal/jquery/element.rb', line 163 alias_native :parent |
#parents(selector = nil) ⇒ Element
Returns a new Element set with all parents of each element in this
collection. An optional selector
may be provided to filter the
selection. Resulting collection may be empty.
181 |
# File 'lib/opal/jquery/element.rb', line 181 alias_native :parents |
#position ⇒ Object
764 765 766 |
# File 'lib/opal/jquery/element.rb', line 764 def position Native(`self.position()`) end |
#prepend(content) ⇒ Object
252 |
# File 'lib/opal/jquery/element.rb', line 252 alias_native :prepend |
#prev(selector = nil) ⇒ Object
184 |
# File 'lib/opal/jquery/element.rb', line 184 alias_native :prev |
#prop(name, value = undefined) ⇒ Object
Get or set the property name
on each element in collection.
306 307 308 |
# File 'lib/opal/jquery/element.rb', line 306 def prop(*args) Native.call(self, :prop, *args) end |
#remove(selector = nil) ⇒ Object
187 |
# File 'lib/opal/jquery/element.rb', line 187 alias_native :remove |
#remove_attr(attr) ⇒ Object
337 |
# File 'lib/opal/jquery/element.rb', line 337 alias_native :remove_attr, :removeAttr |
#remove_attribute(attr) ⇒ Object
384 |
# File 'lib/opal/jquery/element.rb', line 384 alias_native :remove_attribute, :removeAttr |
#remove_class(class_name) ⇒ Object
340 |
# File 'lib/opal/jquery/element.rb', line 340 alias_native :remove_class, :removeClass |
#replace_all(target) ⇒ Object
343 |
# File 'lib/opal/jquery/element.rb', line 343 alias_native :replace_all, :replaceAll |
#replace_with(new_content) ⇒ Object
346 |
# File 'lib/opal/jquery/element.rb', line 346 alias_native :replace_with, :replaceWith |
#respond_to_missing?(name, _) ⇒ Boolean
772 773 774 775 776 777 778 779 780 781 |
# File 'lib/opal/jquery/element.rb', line 772 def respond_to_missing?(name, _) %x{ var method = self[#{name}]; if (typeof(method) === 'function') { return true; } else { return #{super}; } } end |
#scroll_left ⇒ Object
381 |
# File 'lib/opal/jquery/element.rb', line 381 alias_native :scroll_left, :scrollLeft |
#scroll_left=(value) ⇒ Object
378 |
# File 'lib/opal/jquery/element.rb', line 378 alias_native :scroll_left=, :scrollLeft |
#scroll_top ⇒ Object
375 |
# File 'lib/opal/jquery/element.rb', line 375 alias_native :scroll_top, :scrollTop |
#scroll_top=(value) ⇒ Object
372 |
# File 'lib/opal/jquery/element.rb', line 372 alias_native :scroll_top=, :scrollTop |
#select ⇒ Object
349 |
# File 'lib/opal/jquery/element.rb', line 349 alias_native :select |
#serialize ⇒ Object
255 |
# File 'lib/opal/jquery/element.rb', line 255 alias_native :serialize |
#serialize_array ⇒ Array<Hashes>
Serializes a form into an Array of Hash objects.
746 747 748 |
# File 'lib/opal/jquery/element.rb', line 746 def serialize_array `self.serializeArray()`.map { |e| Hash.new(e) } end |
#show(duration = 400) ⇒ Object
193 |
# File 'lib/opal/jquery/element.rb', line 193 alias_native :show |
#siblings(selector = nil) ⇒ Object
220 |
# File 'lib/opal/jquery/element.rb', line 220 alias_native :siblings |
#slide_down(duration = 400) ⇒ Object
387 |
# File 'lib/opal/jquery/element.rb', line 387 alias_native :slide_down, :slideDown |
#slide_toggle(duration = 400) ⇒ Object
393 |
# File 'lib/opal/jquery/element.rb', line 393 alias_native :slide_toggle, :slideToggle |
#slide_up(duration = 400) ⇒ Object
390 |
# File 'lib/opal/jquery/element.rb', line 390 alias_native :slide_up, :slideUp |
#stop ⇒ Object
Stop any currently running animations on element.
287 |
# File 'lib/opal/jquery/element.rb', line 287 alias_native :stop |
#submit ⇒ Object
352 |
# File 'lib/opal/jquery/element.rb', line 352 alias_native :submit |
#tag_name ⇒ Object
605 606 607 |
# File 'lib/opal/jquery/element.rb', line 605 def tag_name `self.length > 0 ? self[0].tagName.toLowerCase() : #{nil}` end |
#text(text = nil) ⇒ String
Get or set the text content of each element in this collection. Setting the content is provided as a compatibility method for jquery. Instead #text= should be used for setting text content.
If no text
content is provided, then the text content of this element
will be returned.
234 |
# File 'lib/opal/jquery/element.rb', line 234 alias_native :text |
#text=(text) ⇒ Object
Set text content of each element in this collection.
363 |
# File 'lib/opal/jquery/element.rb', line 363 alias_native :text=, :text |
#to_n ⇒ Object
410 411 412 |
# File 'lib/opal/jquery/element.rb', line 410 def to_n self end |
#to_s ⇒ Object
632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/opal/jquery/element.rb', line 632 def to_s %x{ var val, el, result = []; for (var i = 0, length = self.length; i < length; i++) { el = self[i]; result.push(el.outerHTML) } return result.join(', '); } end |
#toggle(duration = 400) ⇒ Object
196 |
# File 'lib/opal/jquery/element.rb', line 196 alias_native :toggle |
#toggle_class ⇒ Object
366 |
# File 'lib/opal/jquery/element.rb', line 366 alias_native :toggle_class, :toggleClass |
#trigger(event) ⇒ Object
Trigger an event on this element. The given event
specifies the event
type.
242 |
# File 'lib/opal/jquery/element.rb', line 242 alias_native :trigger |
#value ⇒ Object
752 753 754 |
# File 'lib/opal/jquery/element.rb', line 752 def value `self.val()` || "" end |
#value=(value) ⇒ Object
369 |
# File 'lib/opal/jquery/element.rb', line 369 alias_native :value=, :val |
#visible? ⇒ Boolean
557 558 559 |
# File 'lib/opal/jquery/element.rb', line 557 def visible? `self.is(':visible')` end |
#width ⇒ Object
760 761 762 |
# File 'lib/opal/jquery/element.rb', line 760 def width `self.width()` || nil end |
#width=(value) ⇒ Object
402 |
# File 'lib/opal/jquery/element.rb', line 402 alias_native :width=, :width |