Created
July 5, 2012 17:59
-
-
Save elia/3055246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Kernel | |
| def p *args | |
| `console.log.apply(console, args)` | |
| end | |
| end | |
| class Array | |
| def -(other) | |
| reject { |i| other.include? i } | |
| end | |
| end | |
| class Element | |
| def up selector | |
| parent = `#{jquery}.parents(#{selector})[0] || nil` | |
| Element.new(parent) if parent | |
| end | |
| def down selector | |
| child = `#{jquery}.find(#{selector})[0] || nil` | |
| Element.new(child) if child | |
| end | |
| def [] name | |
| `#{jquery}.attr(#{name})` | |
| end | |
| def data name | |
| `#{jquery}.data(#{name}) || nil` | |
| end | |
| def jquery | |
| @jquery ||= `$(#{@el})` | |
| end | |
| def visible? | |
| `#{jquery}.is(':visible')` | |
| end | |
| attr_reader :el | |
| alias to_s inspect | |
| def class_names | |
| class_name.strip.split(/\s+/) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment