diamonds 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +36 -0
- data/lib/diamonds.rb +74 -0
- data/lib/diamonds/Gemfile +28 -0
- data/lib/diamonds/README.md +254 -0
- data/lib/diamonds/Rakefile +5 -0
- data/lib/diamonds/apps/application.rb +15 -0
- data/lib/diamonds/apps/library.rb +321 -0
- data/lib/diamonds/apps/user_app.rb +5 -0
- data/lib/diamonds/config.ru +98 -0
- data/lib/diamonds/db/mysiteDB Back.sqlite3 +0 -0
- data/lib/diamonds/db/mysiteDB.sqlite3 +0 -0
- data/lib/diamonds/gems/auto_launch_browser.rb +22 -0
- data/lib/diamonds/gems/io.rb +146 -0
- data/lib/diamonds/gems/ruby_to_js.rb +173 -0
- data/lib/diamonds/gems/server_utils.rb +96 -0
- data/lib/diamonds/lib/opal-browser.rb +1 -0
- data/lib/diamonds/lib/opal/browser.rb +4 -0
- data/lib/diamonds/opal-browser.gemspec +21 -0
- data/lib/diamonds/opal/browser.rb +11 -0
- data/lib/diamonds/opal/browser/animation_frame.rb +111 -0
- data/lib/diamonds/opal/browser/canvas.rb +321 -0
- data/lib/diamonds/opal/browser/canvas/data.rb +63 -0
- data/lib/diamonds/opal/browser/canvas/gradient.rb +27 -0
- data/lib/diamonds/opal/browser/canvas/style.rb +113 -0
- data/lib/diamonds/opal/browser/canvas/text.rb +45 -0
- data/lib/diamonds/opal/browser/console.rb +103 -0
- data/lib/diamonds/opal/browser/cookies.rb +133 -0
- data/lib/diamonds/opal/browser/css.rb +24 -0
- data/lib/diamonds/opal/browser/css/declaration.rb +83 -0
- data/lib/diamonds/opal/browser/css/rule.rb +48 -0
- data/lib/diamonds/opal/browser/css/rule/style.rb +16 -0
- data/lib/diamonds/opal/browser/css/style_sheet.rb +83 -0
- data/lib/diamonds/opal/browser/css/unit.rb +188 -0
- data/lib/diamonds/opal/browser/database/sql.rb +194 -0
- data/lib/diamonds/opal/browser/delay.rb +78 -0
- data/lib/diamonds/opal/browser/dom.rb +84 -0
- data/lib/diamonds/opal/browser/dom/attribute.rb +26 -0
- data/lib/diamonds/opal/browser/dom/builder.rb +88 -0
- data/lib/diamonds/opal/browser/dom/cdata.rb +9 -0
- data/lib/diamonds/opal/browser/dom/character_data.rb +73 -0
- data/lib/diamonds/opal/browser/dom/comment.rb +9 -0
- data/lib/diamonds/opal/browser/dom/document.rb +149 -0
- data/lib/diamonds/opal/browser/dom/document_fragment.rb +7 -0
- data/lib/diamonds/opal/browser/dom/element.rb +474 -0
- data/lib/diamonds/opal/browser/dom/element/attributes.rb +87 -0
- data/lib/diamonds/opal/browser/dom/element/data.rb +67 -0
- data/lib/diamonds/opal/browser/dom/element/image.rb +23 -0
- data/lib/diamonds/opal/browser/dom/element/input.rb +28 -0
- data/lib/diamonds/opal/browser/dom/element/offset.rb +89 -0
- data/lib/diamonds/opal/browser/dom/element/position.rb +46 -0
- data/lib/diamonds/opal/browser/dom/element/scroll.rb +136 -0
- data/lib/diamonds/opal/browser/dom/element/select.rb +36 -0
- data/lib/diamonds/opal/browser/dom/element/size.rb +34 -0
- data/lib/diamonds/opal/browser/dom/element/template.rb +9 -0
- data/lib/diamonds/opal/browser/dom/element/textarea.rb +24 -0
- data/lib/diamonds/opal/browser/dom/mutation_observer.rb +178 -0
- data/lib/diamonds/opal/browser/dom/node.rb +464 -0
- data/lib/diamonds/opal/browser/dom/node_set.rb +110 -0
- data/lib/diamonds/opal/browser/dom/text.rb +36 -0
- data/lib/diamonds/opal/browser/effects.rb +50 -0
- data/lib/diamonds/opal/browser/event.rb +253 -0
- data/lib/diamonds/opal/browser/event/animation.rb +38 -0
- data/lib/diamonds/opal/browser/event/audio_processing.rb +33 -0
- data/lib/diamonds/opal/browser/event/base.rb +430 -0
- data/lib/diamonds/opal/browser/event/before_unload.rb +15 -0
- data/lib/diamonds/opal/browser/event/clipboard.rb +28 -0
- data/lib/diamonds/opal/browser/event/close.rb +47 -0
- data/lib/diamonds/opal/browser/event/composition.rb +50 -0
- data/lib/diamonds/opal/browser/event/custom.rb +65 -0
- data/lib/diamonds/opal/browser/event/device_light.rb +23 -0
- data/lib/diamonds/opal/browser/event/device_motion.rb +51 -0
- data/lib/diamonds/opal/browser/event/device_orientation.rb +48 -0
- data/lib/diamonds/opal/browser/event/device_proximity.rb +33 -0
- data/lib/diamonds/opal/browser/event/drag.rb +119 -0
- data/lib/diamonds/opal/browser/event/focus.rb +39 -0
- data/lib/diamonds/opal/browser/event/gamepad.rb +60 -0
- data/lib/diamonds/opal/browser/event/hash_change.rb +28 -0
- data/lib/diamonds/opal/browser/event/keyboard.rb +115 -0
- data/lib/diamonds/opal/browser/event/message.rb +70 -0
- data/lib/diamonds/opal/browser/event/mouse.rb +254 -0
- data/lib/diamonds/opal/browser/event/page_transition.rb +23 -0
- data/lib/diamonds/opal/browser/event/pop_state.rb +33 -0
- data/lib/diamonds/opal/browser/event/progress.rb +43 -0
- data/lib/diamonds/opal/browser/event/sensor.rb +15 -0
- data/lib/diamonds/opal/browser/event/storage.rb +43 -0
- data/lib/diamonds/opal/browser/event/touch.rb +60 -0
- data/lib/diamonds/opal/browser/event/ui.rb +38 -0
- data/lib/diamonds/opal/browser/event/wheel.rb +49 -0
- data/lib/diamonds/opal/browser/event_source.rb +70 -0
- data/lib/diamonds/opal/browser/history.rb +90 -0
- data/lib/diamonds/opal/browser/http.rb +169 -0
- data/lib/diamonds/opal/browser/http/binary.rb +58 -0
- data/lib/diamonds/opal/browser/http/headers.rb +109 -0
- data/lib/diamonds/opal/browser/http/request.rb +344 -0
- data/lib/diamonds/opal/browser/http/response.rb +115 -0
- data/lib/diamonds/opal/browser/immediate.rb +163 -0
- data/lib/diamonds/opal/browser/interval.rb +111 -0
- data/lib/diamonds/opal/browser/location.rb +87 -0
- data/lib/diamonds/opal/browser/navigator.rb +173 -0
- data/lib/diamonds/opal/browser/screen.rb +66 -0
- data/lib/diamonds/opal/browser/socket.rb +123 -0
- data/lib/diamonds/opal/browser/storage.rb +252 -0
- data/lib/diamonds/opal/browser/support.rb +287 -0
- data/lib/diamonds/opal/browser/utils.rb +74 -0
- data/lib/diamonds/opal/browser/version.rb +3 -0
- data/lib/diamonds/opal/browser/window.rb +120 -0
- data/lib/diamonds/opal/browser/window/scroll.rb +59 -0
- data/lib/diamonds/opal/browser/window/size.rb +59 -0
- data/lib/diamonds/opal/browser/window/view.rb +36 -0
- data/lib/diamonds/opal/opal-browser.rb +1 -0
- data/lib/diamonds/public/__OPAL_SOURCE_MAPS__/application.map +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/HELP-US-OUT.txt +7 -0
- data/lib/diamonds/public/javascripts/font-awesome/css/font-awesome.css +2026 -0
- data/lib/diamonds/public/javascripts/font-awesome/css/font-awesome.min.css +1 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/FontAwesome.otf +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.eot +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.svg +640 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.woff +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/animated.less +34 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/bordered-pulled.less +25 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/core.less +12 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/fixed-width.less +6 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/font-awesome.less +17 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/icons.less +677 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/larger.less +13 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/list.less +19 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/mixins.less +26 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/path.less +15 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/rotated-flipped.less +20 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/stacked.less +20 -0
- data/lib/diamonds/public/javascripts/font-awesome/less/variables.less +688 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_animated.scss +34 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_bordered-pulled.scss +25 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_core.scss +12 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_fixed-width.scss +6 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_icons.scss +677 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_larger.scss +13 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_list.scss +19 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_mixins.scss +26 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_path.scss +15 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_rotated-flipped.scss +20 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_stacked.scss +20 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/_variables.scss +688 -0
- data/lib/diamonds/public/javascripts/font-awesome/scss/font-awesome.scss +17 -0
- data/lib/diamonds/public/javascripts/jquery-2.1.4.min.js +4 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_222222_256x240.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_228ef1_256x240.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ef8c08_256x240.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ffd27a_256x240.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
- data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.min.css +7 -0
- data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.min.js +13 -0
- data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.structure.min.css +5 -0
- data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.theme.min.css +5 -0
- data/lib/diamonds/public/javascripts/jquery.js +4 -0
- data/lib/diamonds/public/javascripts/jquery.ui.touch-punch.min.js +11 -0
- data/lib/diamonds/public/javascripts/ne pas utiliser version en retard jeezs_editor.js b/data/lib/diamonds/public/javascripts/ne pas utiliser version en retard → jeezs_editor.js +0 -0
- data/lib/diamonds/public/javascripts/standalone.js +2316 -0
- data/lib/diamonds/public/javascripts/standalone.min.js +1 -0
- data/lib/diamonds/public/javascripts/wysiwyg-editor.min.css +1 -0
- data/lib/diamonds/public/javascripts/wysiwyg-editor.min.js +1 -0
- data/lib/diamonds/public/javascripts/wysiwyg.min.js +1 -0
- data/lib/diamonds/user_app/main.rb +45 -0
- data/lib/diamonds/version.rb +3 -0
- data/lib/diamonds/views/index.erb +35 -0
- data/lib/diamonds/views/javascripts/jeezs_editor.js.erb +365 -0
- data/lib/diamonds/views/stylesheets/main.css.erb +244 -0
- metadata +490 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Browser; module DOM
|
|
2
|
+
|
|
3
|
+
class CharacterData < Node
|
|
4
|
+
# Append data to the node.
|
|
5
|
+
#
|
|
6
|
+
# @param string [String] the data to add
|
|
7
|
+
#
|
|
8
|
+
# @return [self]
|
|
9
|
+
def append(string)
|
|
10
|
+
`#@native.appendData(string)`
|
|
11
|
+
|
|
12
|
+
self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @!attribute [r] data
|
|
16
|
+
# @return [String] the data of the node
|
|
17
|
+
def data
|
|
18
|
+
`#@native.data`
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Delete data from the node.
|
|
22
|
+
#
|
|
23
|
+
# @param count [Integer] how much data to delete
|
|
24
|
+
# @param offset [Integer] the offset to start at
|
|
25
|
+
#
|
|
26
|
+
# @return [self]
|
|
27
|
+
def delete(count, offset = 0)
|
|
28
|
+
`#@native.deleteData(offset, count)`
|
|
29
|
+
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Insert data in the node.
|
|
34
|
+
#
|
|
35
|
+
# @param string [String] the data to insert
|
|
36
|
+
# @param offset [Integer] the offset to start at
|
|
37
|
+
#
|
|
38
|
+
# @return [self]
|
|
39
|
+
def insert(string, offset = 0)
|
|
40
|
+
`#@native.insertData(offset, string)`
|
|
41
|
+
|
|
42
|
+
self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @!attribute [r] length
|
|
46
|
+
# @return [Integer] the length of the node
|
|
47
|
+
alias_native :length
|
|
48
|
+
|
|
49
|
+
# Replace data in the node.
|
|
50
|
+
#
|
|
51
|
+
# @param string [String] the data to replace with
|
|
52
|
+
# @param offset [Integer] the offset to start at
|
|
53
|
+
# @param count [Integer] how much data to replace
|
|
54
|
+
#
|
|
55
|
+
# @return [self]
|
|
56
|
+
def replace(string, offset = 0, count = `#@native.length`)
|
|
57
|
+
`#@native.replaceData(offset, count, string)`
|
|
58
|
+
|
|
59
|
+
self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Get a substring of the data.
|
|
63
|
+
#
|
|
64
|
+
# @param count [Integer] how much data to lice
|
|
65
|
+
# @param offset [Integer] the offset to start at
|
|
66
|
+
#
|
|
67
|
+
# @return [String] the substring
|
|
68
|
+
def substring(count, offset = 0)
|
|
69
|
+
`#@native.substringData(offset, count)`
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end; end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
module Browser; module DOM
|
|
2
|
+
|
|
3
|
+
class Document < Element
|
|
4
|
+
# Get the first element matching the given ID, CSS selector or XPath.
|
|
5
|
+
#
|
|
6
|
+
# @param what [String] ID, CSS selector or XPath
|
|
7
|
+
#
|
|
8
|
+
# @return [Element?] the first matching element
|
|
9
|
+
def [](what)
|
|
10
|
+
%x{
|
|
11
|
+
var result = #@native.getElementById(what);
|
|
12
|
+
|
|
13
|
+
if (result) {
|
|
14
|
+
return #{DOM(`result`)};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
css(what).first || xpath(what).first
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias at []
|
|
22
|
+
|
|
23
|
+
# @!attribute [r] body
|
|
24
|
+
# @return [Element?] the body element of the document
|
|
25
|
+
def body
|
|
26
|
+
DOM(`#@native.body`)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Create a new element for the document.
|
|
30
|
+
#
|
|
31
|
+
# @param name [String] the node name
|
|
32
|
+
# @param options [Hash] optional `:namespace` name
|
|
33
|
+
#
|
|
34
|
+
# @return [Element]
|
|
35
|
+
def create_element(name, options = {})
|
|
36
|
+
if ns = options[:namespace]
|
|
37
|
+
DOM(`#@native.createElementNS(#{ns}, #{name})`)
|
|
38
|
+
else
|
|
39
|
+
DOM(`#@native.createElement(name)`)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Create a new text node for the document.
|
|
44
|
+
#
|
|
45
|
+
# @param content [String] the text content
|
|
46
|
+
#
|
|
47
|
+
# @return [Text]
|
|
48
|
+
def create_text(content)
|
|
49
|
+
DOM(`#@native.createTextNode(#{content})`)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def document
|
|
53
|
+
self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @!attribute [r] head
|
|
57
|
+
# @return [Element?] the head element of the document
|
|
58
|
+
def head
|
|
59
|
+
DOM(`#@native.getElementsByTagName("head")[0]`)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def inspect
|
|
63
|
+
"#<DOM::Document>"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if Browser.supports? 'Event.addListener'
|
|
67
|
+
def ready(&block)
|
|
68
|
+
raise ArgumentError, 'no block given' unless block
|
|
69
|
+
|
|
70
|
+
return block.call if ready?
|
|
71
|
+
|
|
72
|
+
on 'dom:load' do |e|
|
|
73
|
+
e.off
|
|
74
|
+
|
|
75
|
+
block.call
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
elsif Browser.supports? 'Event.attach'
|
|
79
|
+
def ready(&block)
|
|
80
|
+
raise ArgumentError, 'no block given' unless block
|
|
81
|
+
|
|
82
|
+
return block.call if ready?
|
|
83
|
+
|
|
84
|
+
on 'ready:state:change' do |e|
|
|
85
|
+
if ready?
|
|
86
|
+
e.off
|
|
87
|
+
|
|
88
|
+
block.call
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
else
|
|
93
|
+
# Wait for the document to be ready and call the block.
|
|
94
|
+
def ready(&block)
|
|
95
|
+
raise NotImplementedError, 'document ready unsupported'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Check if the document is ready.
|
|
100
|
+
def ready?
|
|
101
|
+
`#@native.readyState === "complete"`
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# @!attribute root
|
|
105
|
+
# @return [Element?] the root element of the document
|
|
106
|
+
def root
|
|
107
|
+
DOM(`#@native.documentElement`)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def root=(element)
|
|
111
|
+
`#@native.documentElement = #{Native.convert(element)}`
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# @!attribute [r] style_sheets
|
|
115
|
+
# @return [Array<CSS::StyleSheet>] the style sheets for the document
|
|
116
|
+
def style_sheets
|
|
117
|
+
Native::Array.new(`#@native.styleSheets`) {|e|
|
|
118
|
+
CSS::StyleSheet.new(e)
|
|
119
|
+
}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @!attribute title
|
|
123
|
+
# @return [String] the document title
|
|
124
|
+
def title
|
|
125
|
+
`#@native.title`
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def title=(value)
|
|
129
|
+
`#@native.title = value`
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
if Browser.supports? 'Document.view'
|
|
133
|
+
def window
|
|
134
|
+
Window.new(`#@native.defaultView`)
|
|
135
|
+
end
|
|
136
|
+
elsif Browser.supports? 'Document.window'
|
|
137
|
+
def window
|
|
138
|
+
Window.new(`#@native.parentWindow`)
|
|
139
|
+
end
|
|
140
|
+
else
|
|
141
|
+
# @!attribute [r] window
|
|
142
|
+
# @return [Window] the window for the document
|
|
143
|
+
def window
|
|
144
|
+
raise NotImplementedError, 'window from document unsupported'
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end; end
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
require 'browser/dom/element/attributes'
|
|
2
|
+
require 'browser/dom/element/data'
|
|
3
|
+
require 'browser/dom/element/position'
|
|
4
|
+
require 'browser/dom/element/offset'
|
|
5
|
+
require 'browser/dom/element/scroll'
|
|
6
|
+
require 'browser/dom/element/size'
|
|
7
|
+
|
|
8
|
+
require 'browser/dom/element/input'
|
|
9
|
+
require 'browser/dom/element/select'
|
|
10
|
+
require 'browser/dom/element/image'
|
|
11
|
+
require 'browser/dom/element/template'
|
|
12
|
+
require 'browser/dom/element/textarea'
|
|
13
|
+
|
|
14
|
+
module Browser; module DOM
|
|
15
|
+
|
|
16
|
+
class Element < Node
|
|
17
|
+
def self.create(*args)
|
|
18
|
+
$document.create_element(*args)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.new(node)
|
|
22
|
+
if self == Element
|
|
23
|
+
name = `node.nodeName`.capitalize
|
|
24
|
+
|
|
25
|
+
if Element.constants.include?(name)
|
|
26
|
+
Element.const_get(name).new(node)
|
|
27
|
+
else
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
include Event::Target
|
|
36
|
+
|
|
37
|
+
target {|value|
|
|
38
|
+
DOM(value) rescue nil
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if Browser.supports? 'Element.matches'
|
|
42
|
+
def =~(selector)
|
|
43
|
+
`#@native.matches(#{selector})`
|
|
44
|
+
end
|
|
45
|
+
elsif Browser.supports? 'Element.matches (Opera)'
|
|
46
|
+
def =~(selector)
|
|
47
|
+
`#@native.oMatchesSelector(#{selector})`
|
|
48
|
+
end
|
|
49
|
+
elsif Browser.supports? 'Element.matches (Internet Explorer)'
|
|
50
|
+
def =~(selector)
|
|
51
|
+
`#@native.msMatchesSelector(#{selector})`
|
|
52
|
+
end
|
|
53
|
+
elsif Browser.supports? 'Element.matches (Firefox)'
|
|
54
|
+
def =~(selector)
|
|
55
|
+
`#@native.mozMatchesSelector(#{selector})`
|
|
56
|
+
end
|
|
57
|
+
elsif Browser.supports? 'Element.matches (Chrome)'
|
|
58
|
+
def =~(selector)
|
|
59
|
+
`#@native.webkitMatchesSelector(#{selector})`
|
|
60
|
+
end
|
|
61
|
+
elsif Browser.loaded? 'Sizzle'
|
|
62
|
+
def =~(selector)
|
|
63
|
+
`Sizzle.matchesSelector(#@native, #{selector})`
|
|
64
|
+
end
|
|
65
|
+
else
|
|
66
|
+
# Check whether the element matches the given selector.
|
|
67
|
+
#
|
|
68
|
+
# @param selector [String] the CSS selector
|
|
69
|
+
def =~(selector)
|
|
70
|
+
raise NotImplementedError, 'selector matching unsupported'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Query for children with the given XPpaths.
|
|
75
|
+
#
|
|
76
|
+
# @param paths [Array<String>] the XPaths to look for
|
|
77
|
+
#
|
|
78
|
+
# @return [NodeSet]
|
|
79
|
+
def /(*paths)
|
|
80
|
+
NodeSet[paths.map { |path| xpath(path) }]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Get the attribute with the given name.
|
|
84
|
+
#
|
|
85
|
+
# @param name [String] the attribute name
|
|
86
|
+
# @param options [Hash] options for the attribute
|
|
87
|
+
#
|
|
88
|
+
# @option options [String] :namespace the namespace for the attribute
|
|
89
|
+
#
|
|
90
|
+
# @return [String?]
|
|
91
|
+
def [](name, options = {})
|
|
92
|
+
attributes.get(name, options)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Set the attribute with the given name and value.
|
|
96
|
+
#
|
|
97
|
+
# @param name [String] the attribute name
|
|
98
|
+
# @param value [Object] the attribute value
|
|
99
|
+
# @param options [Hash] the options for the attribute
|
|
100
|
+
#
|
|
101
|
+
# @option options [String] :namespace the namespace for the attribute
|
|
102
|
+
def []=(name, value, options = {})
|
|
103
|
+
attributes.set(name, value, options)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Add class names to the element.
|
|
107
|
+
#
|
|
108
|
+
# @param names [Array<String>] class names to add
|
|
109
|
+
#
|
|
110
|
+
# @return [self]
|
|
111
|
+
def add_class(*names)
|
|
112
|
+
classes = class_names + names
|
|
113
|
+
|
|
114
|
+
unless classes.empty?
|
|
115
|
+
`#@native.className = #{classes.uniq.join ' '}`
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
self
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Get the first node that matches the given CSS selector or XPath.
|
|
122
|
+
#
|
|
123
|
+
# @param path_or_selector [String] an XPath or CSS selector
|
|
124
|
+
#
|
|
125
|
+
# @return [Node?]
|
|
126
|
+
def at(path_or_selector)
|
|
127
|
+
xpath(path_or_selector).first || css(path_or_selector).first
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Get the first node matching the given CSS selectors.
|
|
131
|
+
#
|
|
132
|
+
# @param rules [Array<String>] the CSS selectors to match with
|
|
133
|
+
#
|
|
134
|
+
# @return [Node?]
|
|
135
|
+
def at_css(*rules)
|
|
136
|
+
result = nil
|
|
137
|
+
|
|
138
|
+
rules.each {|rule|
|
|
139
|
+
if result = css(rule).first
|
|
140
|
+
break
|
|
141
|
+
end
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
result
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Get the first node matching the given XPath.
|
|
148
|
+
#
|
|
149
|
+
# @param paths [Array<String>] the XPath to match with
|
|
150
|
+
#
|
|
151
|
+
# @return [Node?]
|
|
152
|
+
def at_xpath(*paths)
|
|
153
|
+
result = nil
|
|
154
|
+
|
|
155
|
+
paths.each {|path|
|
|
156
|
+
if result = xpath(path).first
|
|
157
|
+
break
|
|
158
|
+
end
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
result
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
alias attr []
|
|
165
|
+
|
|
166
|
+
alias attribute []
|
|
167
|
+
|
|
168
|
+
# @!attribute [r] attributes
|
|
169
|
+
# @return [Attributes] the attributes for the element
|
|
170
|
+
def attributes(options = {})
|
|
171
|
+
Attributes.new(self, options)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# @!attribute [r] attribute_nodes
|
|
175
|
+
# @return [NodeSet] the attribute nodes for the element
|
|
176
|
+
def attribute_nodes
|
|
177
|
+
NodeSet[Native::Array.new(`#@native.attributes`, get: :item)]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# @!attribute [r] class_name
|
|
181
|
+
# @return [String] all the element class names
|
|
182
|
+
alias_native :class_name, :className
|
|
183
|
+
|
|
184
|
+
# @!attribute [r] class_names
|
|
185
|
+
# @return [Array<String>] all the element class names
|
|
186
|
+
def class_names
|
|
187
|
+
`#@native.className`.split(/\s+/).reject(&:empty?)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
if Browser.supports? 'Query.css'
|
|
191
|
+
def css(path)
|
|
192
|
+
NodeSet[Native::Array.new(`#@native.querySelectorAll(path)`)]
|
|
193
|
+
rescue
|
|
194
|
+
NodeSet[]
|
|
195
|
+
end
|
|
196
|
+
elsif Browser.loaded? 'Sizzle'
|
|
197
|
+
def css(path)
|
|
198
|
+
NodeSet[`Sizzle(path, #@native)`]
|
|
199
|
+
rescue
|
|
200
|
+
NodeSet[]
|
|
201
|
+
end
|
|
202
|
+
else
|
|
203
|
+
# Query for children matching the given CSS selector.
|
|
204
|
+
#
|
|
205
|
+
# @param selector [String] the CSS selector
|
|
206
|
+
#
|
|
207
|
+
# @return [NodeSet]
|
|
208
|
+
def css(selector)
|
|
209
|
+
raise NotImplementedError, 'query by CSS selector unsupported'
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# @overload data()
|
|
214
|
+
#
|
|
215
|
+
# Return the data for the element.
|
|
216
|
+
#
|
|
217
|
+
# @return [Data]
|
|
218
|
+
#
|
|
219
|
+
# @overload data(hash)
|
|
220
|
+
#
|
|
221
|
+
# Set data on the element.
|
|
222
|
+
#
|
|
223
|
+
# @param hash [Hash] the data to set
|
|
224
|
+
#
|
|
225
|
+
# @return [self]
|
|
226
|
+
def data(value = nil)
|
|
227
|
+
data = Data.new(self)
|
|
228
|
+
|
|
229
|
+
return data unless value
|
|
230
|
+
|
|
231
|
+
if Hash === value
|
|
232
|
+
data.assign(value)
|
|
233
|
+
else
|
|
234
|
+
raise ArgumentError, 'unknown data type'
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
self
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
alias get_attribute []
|
|
241
|
+
|
|
242
|
+
alias get []
|
|
243
|
+
|
|
244
|
+
# @!attribute height
|
|
245
|
+
# @return [Integer] the height of the element
|
|
246
|
+
def height
|
|
247
|
+
size.height
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def height=(value)
|
|
251
|
+
size.height = value
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# @!attribute id
|
|
255
|
+
# @return [String?] the ID of the element
|
|
256
|
+
def id
|
|
257
|
+
%x{
|
|
258
|
+
var id = #@native.id;
|
|
259
|
+
|
|
260
|
+
if (id === "") {
|
|
261
|
+
return nil;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return id;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def id=(value)
|
|
270
|
+
`#@native.id = #{value.to_s}`
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Set the inner DOM of the element using the {Builder}.
|
|
274
|
+
def inner_dom(&block)
|
|
275
|
+
clear
|
|
276
|
+
|
|
277
|
+
# FIXME: when block passing is fixed
|
|
278
|
+
doc = document
|
|
279
|
+
|
|
280
|
+
self << Builder.new(doc, self, &block).to_a
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Set the inner DOM with the given node.
|
|
284
|
+
#
|
|
285
|
+
# (see #append_child)
|
|
286
|
+
def inner_dom=(node)
|
|
287
|
+
clear
|
|
288
|
+
|
|
289
|
+
self << node
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def inspect
|
|
293
|
+
inspect = name.downcase
|
|
294
|
+
|
|
295
|
+
if id
|
|
296
|
+
inspect += '.' + id + '!'
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
unless class_names.empty?
|
|
300
|
+
inspect += '.' + class_names.join('.')
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
"#<DOM::Element: #{inspect}>"
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# @!attribute offset
|
|
307
|
+
# @return [Offset] the offset of the element
|
|
308
|
+
def offset(*values)
|
|
309
|
+
off = Offset.new(self)
|
|
310
|
+
|
|
311
|
+
unless values.empty?
|
|
312
|
+
off.set(*values)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
off
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def offset=(value)
|
|
319
|
+
offset.set(*value)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# @!attribute [r] position
|
|
323
|
+
# @return [Position] the position of the element
|
|
324
|
+
def position
|
|
325
|
+
Position.new(self)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# @!attribute [r] scroll
|
|
329
|
+
# @return [Scroll] the scrolling for the element
|
|
330
|
+
def scroll
|
|
331
|
+
Scroll.new(self)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Search for all the children matching the given XPaths or CSS selectors.
|
|
335
|
+
#
|
|
336
|
+
# @param selectors [Array<String>] mixed list of XPaths and CSS selectors
|
|
337
|
+
#
|
|
338
|
+
# @return [NodeSet]
|
|
339
|
+
def search(*selectors)
|
|
340
|
+
NodeSet.new selectors.map {|selector|
|
|
341
|
+
xpath(selector).to_a.concat(css(selector).to_a)
|
|
342
|
+
}.flatten.uniq
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
alias set []=
|
|
346
|
+
|
|
347
|
+
alias set_attribute []=
|
|
348
|
+
|
|
349
|
+
# @overload style()
|
|
350
|
+
#
|
|
351
|
+
# Return the style for the element.
|
|
352
|
+
#
|
|
353
|
+
# @return [CSS::Declaration]
|
|
354
|
+
#
|
|
355
|
+
# @overload style(data)
|
|
356
|
+
#
|
|
357
|
+
# Set the CSS style as string or set of values.
|
|
358
|
+
#
|
|
359
|
+
# @param data [String, Hash] the new style
|
|
360
|
+
#
|
|
361
|
+
# @return [self]
|
|
362
|
+
#
|
|
363
|
+
# @overload style(&block)
|
|
364
|
+
#
|
|
365
|
+
# Set the CSS style from a CSS builder DSL.
|
|
366
|
+
#
|
|
367
|
+
# @return [self]
|
|
368
|
+
def style(data = nil, &block)
|
|
369
|
+
style = CSS::Declaration.new(`#@native.style`)
|
|
370
|
+
|
|
371
|
+
return style unless data || block
|
|
372
|
+
|
|
373
|
+
if String === data
|
|
374
|
+
style.replace(data)
|
|
375
|
+
elsif Hash === data
|
|
376
|
+
style.assign(data)
|
|
377
|
+
elsif block
|
|
378
|
+
style.apply(&block)
|
|
379
|
+
else
|
|
380
|
+
raise ArgumentError, 'unknown data type'
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
self
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
if Browser.supports? 'CSS.computed'
|
|
387
|
+
def style!
|
|
388
|
+
CSS::Declaration.new(`#{window.to_n}.getComputedStyle(#@native, null)`)
|
|
389
|
+
end
|
|
390
|
+
elsif Browser.supports? 'CSS.current'
|
|
391
|
+
def style!
|
|
392
|
+
CSS::Declaration.new(`#@native.currentStyle`)
|
|
393
|
+
end
|
|
394
|
+
else
|
|
395
|
+
# @!attribute [r] style!
|
|
396
|
+
# @return [CSS::Declaration] get the computed style for the element
|
|
397
|
+
def style!
|
|
398
|
+
raise NotImplementedError, 'computed style unsupported'
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# Remove an attribute from the element.
|
|
403
|
+
#
|
|
404
|
+
# @param name [String] the attribute name
|
|
405
|
+
def remove_attribute(name)
|
|
406
|
+
`#@native.removeAttribute(name)`
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# Remove class names from the element.
|
|
410
|
+
#
|
|
411
|
+
# @param names [Array<String>] class names to remove
|
|
412
|
+
#
|
|
413
|
+
# @return [self]
|
|
414
|
+
def remove_class(*names)
|
|
415
|
+
classes = class_names - names
|
|
416
|
+
|
|
417
|
+
if classes.empty?
|
|
418
|
+
`#@native.removeAttribute('class')`
|
|
419
|
+
else
|
|
420
|
+
`#@native.className = #{classes.join ' '}`
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
self
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
# @!attribute [r] size
|
|
427
|
+
# @return [Size] the size of the element
|
|
428
|
+
def size(*inc)
|
|
429
|
+
Size.new(self, *inc)
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
# @!attribute width
|
|
433
|
+
# @return [Integer] the width of the element
|
|
434
|
+
def width
|
|
435
|
+
size.width
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
def width=(value)
|
|
439
|
+
size.width = value
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
# @!attribute [r] window
|
|
443
|
+
# @return [Window] the window for the element
|
|
444
|
+
def window
|
|
445
|
+
document.window
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
if Browser.supports?('Query.xpath') || Browser.loaded?('wicked-good-xpath')
|
|
449
|
+
if Browser.loaded? 'wicked-good-xpath'
|
|
450
|
+
`wgxpath.install()`
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def xpath(path)
|
|
454
|
+
NodeSet[Native::Array.new(
|
|
455
|
+
`(#@native.ownerDocument || #@native).evaluate(path,
|
|
456
|
+
#@native, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)`,
|
|
457
|
+
get: :snapshotItem,
|
|
458
|
+
length: :snapshotLength)]
|
|
459
|
+
rescue
|
|
460
|
+
NodeSet[]
|
|
461
|
+
end
|
|
462
|
+
else
|
|
463
|
+
# Query for children matching the given XPath.
|
|
464
|
+
#
|
|
465
|
+
# @param path [String] the XPath
|
|
466
|
+
#
|
|
467
|
+
# @return [NodeSet]
|
|
468
|
+
def xpath(path)
|
|
469
|
+
raise NotImplementedError, 'query by XPath unsupported'
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
end; end
|