Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal-jquery
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2cbba95aeb31
Choose a base ref
...
head repository: opal/opal-jquery
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d1e607b270e5
Choose a head ref
  • 6 commits
  • 1 file changed
  • 1 contributor

Commits on May 18, 2015

  1. Add Element#is?

    elia committed May 18, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    269c81a View commit details
  2. Add Element#index

    elia committed May 18, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    b4b59c1 View commit details
  3. Add Element#serialize_array

    elia committed May 18, 2015
    Copy the full SHA
    1f2268a View commit details
  4. Add Element#one

    elia committed May 18, 2015
    Copy the full SHA
    72b8287 View commit details
  5. Add Element#submit

    elia committed May 18, 2015
    Copy the full SHA
    d232b4f View commit details
  6. jQuery.fn.attr returns undefined for missing attrs

    Attributes with empty values give "" which is of course considered falsy by JS.
    elia committed May 18, 2015
    Copy the full SHA
    d1e607b View commit details
Showing with 43 additions and 2 deletions.
  1. +43 −2 lib/opal/jquery/element.rb
45 changes: 43 additions & 2 deletions lib/opal/jquery/element.rb
Original file line number Diff line number Diff line change
@@ -325,12 +325,21 @@ def self.expose(*methods)
# @param content [String, Element]
alias_native :html=, :html

# @!method index(selector_or_element = nil)
alias_native :index

# @!method is?(selector)
alias_native :is?, :is

# @!method remove_attr(attr)
alias_native :remove_attr, :removeAttr

# @!method remove_class(class_name)
alias_native :remove_class, :removeClass

# @!method submit()
alias_native :submit

# @!method text=(text)
#
# Set text content of each element in this collection.
@@ -389,7 +398,11 @@ def to_n
end

def [](name)
`self.attr(name) || nil`
%x{
var value = self.attr(name);
if(value === undefined) return nil;
return value;
}
end

def attr(name, value=nil)
@@ -401,7 +414,7 @@ def attr(name, value=nil)
end

def has_attribute?(name)
`!!self.attr(name)`
`self.attr(name) !== undefined`
end

def append_to_body
@@ -640,6 +653,29 @@ def on(name, sel = nil, &block)
block
end

def one(name, sel = nil, &block)
%x{
var wrapper = function(evt) {
if (evt.preventDefault) {
evt = #{Event.new `evt`};
}
return block.apply(null, arguments);
};
block._jq_wrap = wrapper;
if (sel == nil) {
self.one(name, wrapper);
}
else {
self.one(name, sel, wrapper);
}
}

block
end

def off(name, sel, block = nil)
%x{
if (sel == null) {
@@ -654,6 +690,11 @@ def off(name, sel, block = nil)
}
end

# returns an Array of Hashes
def serialize_array
`self.serializeArray()`.map { |e| Hash.new(e) }
end

alias size length

def value