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,36 @@
|
|
|
1
|
+
module Browser; module DOM; class Element < Node
|
|
2
|
+
|
|
3
|
+
class Select < Element
|
|
4
|
+
def value
|
|
5
|
+
%x{
|
|
6
|
+
if (#@native.value == "") {
|
|
7
|
+
return nil;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return #@native.value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def labels
|
|
16
|
+
NodeSet[Native::Array.new(`#@native.labels`)]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def options
|
|
20
|
+
NodeSet[Native::Array.new(`#@native.options`)]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def option
|
|
24
|
+
DOM(`#@native.options[#@native.selectedIndex]`)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def index
|
|
28
|
+
`#@native.selectedIndex`
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
alias_native :multiple?, :multiple
|
|
32
|
+
alias_native :required?, :required
|
|
33
|
+
alias_native :length
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end; end; end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Browser; module DOM; class Element < Node
|
|
2
|
+
|
|
3
|
+
class Size
|
|
4
|
+
attr_reader :element
|
|
5
|
+
|
|
6
|
+
# @private
|
|
7
|
+
def initialize(element, *inc)
|
|
8
|
+
@element = element
|
|
9
|
+
@native = element.to_n
|
|
10
|
+
@include = inc
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @!attribute width
|
|
14
|
+
# @return [Integer] the element width
|
|
15
|
+
def width
|
|
16
|
+
`#@native.offsetWidth`
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def width=(value)
|
|
20
|
+
@element.style[:width] = value
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @!attribute height
|
|
24
|
+
# @return [Integer] the element height
|
|
25
|
+
def height
|
|
26
|
+
`#@native.offsetHeight`
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def height=(value)
|
|
30
|
+
@element.style[:height] = value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end; end; end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Browser; module DOM; class Element < Node
|
|
2
|
+
|
|
3
|
+
class Textarea < Element
|
|
4
|
+
def value
|
|
5
|
+
%x{
|
|
6
|
+
if (#@native.value == "") {
|
|
7
|
+
return nil;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return #@native.value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def value=(value)
|
|
16
|
+
`#@native.value = #{value}`
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def clear
|
|
20
|
+
`#@native.value = ''`
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end; end; end
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
module Browser; module DOM
|
|
2
|
+
|
|
3
|
+
# A {MutationObserver} is a performant way to observe changes in the DOM,
|
|
4
|
+
# either on the tree, the attributes or data.
|
|
5
|
+
#
|
|
6
|
+
# @see https://developer.mozilla.org/en/docs/Web/API/MutationObserver
|
|
7
|
+
class MutationObserver
|
|
8
|
+
def self.supported?
|
|
9
|
+
Browser.supports? :MutationObserver
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
include Native
|
|
13
|
+
|
|
14
|
+
# Encapsulates a recorded change.
|
|
15
|
+
class Record
|
|
16
|
+
include Native
|
|
17
|
+
|
|
18
|
+
# @!attribute [r] type
|
|
19
|
+
# @return [:attributes, :tree, :cdata] the type of the recorded change
|
|
20
|
+
def type
|
|
21
|
+
case `#@native.type`
|
|
22
|
+
when :attributes then :attribute
|
|
23
|
+
when :childList then :tree
|
|
24
|
+
when :characterData then :cdata
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns true if the change happened on attributes.
|
|
29
|
+
def attribute?
|
|
30
|
+
type == :attribute
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns true if the change happened on the tree.
|
|
34
|
+
def tree?
|
|
35
|
+
type == :tree
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns true if the change happened in a CDATA section.
|
|
39
|
+
def cdata?
|
|
40
|
+
type == :cdata
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @!attribute [r] added
|
|
44
|
+
# @return [NodeSet] the added nodes
|
|
45
|
+
def added
|
|
46
|
+
array = if `#@native.addedNodes != null`
|
|
47
|
+
Native::Array.new(`#@native.addedNodes`)
|
|
48
|
+
else
|
|
49
|
+
[]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
NodeSet[array]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @!attribute [r] removed
|
|
56
|
+
# @return [NodeSet] the removed nodes
|
|
57
|
+
def removed
|
|
58
|
+
array = if `#@native.removedNodes != null`
|
|
59
|
+
Native::Array.new(`#@native.removedNodes`)
|
|
60
|
+
else
|
|
61
|
+
[]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
NodeSet[array]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @!attribute [r] target
|
|
68
|
+
# @return [Node] the node the mutation affected
|
|
69
|
+
def target
|
|
70
|
+
DOM(`#@native.target`)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @!attribute [r] old
|
|
74
|
+
# @return [String] the old value
|
|
75
|
+
alias_native :old, :oldValue
|
|
76
|
+
|
|
77
|
+
# @!attribute [r] name
|
|
78
|
+
# @return [String] the name of the attribute
|
|
79
|
+
alias_native :name, :attributeName
|
|
80
|
+
|
|
81
|
+
# @!attribute [r] namespace
|
|
82
|
+
# @return [String] the namespace of the attribute
|
|
83
|
+
alias_native :namespace, :attributeNamespace
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Create a new MutationObserver with the given block.
|
|
87
|
+
#
|
|
88
|
+
# @yieldparam records [Array<Record>] the recorded changes
|
|
89
|
+
def initialize(&block)
|
|
90
|
+
%x{
|
|
91
|
+
var func = function(records) {
|
|
92
|
+
return #{block.call(`records`.map { |r| Browser::DOM::MutationObserver::Record.new(r) })};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
super(`new window.MutationObserver(func)`)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Observe the given target with the given options.
|
|
100
|
+
#
|
|
101
|
+
# The supported options are:
|
|
102
|
+
#
|
|
103
|
+
# + **children** - whether to observe changes on the children
|
|
104
|
+
# of the target or not
|
|
105
|
+
# + **tree** - whether to observe changes on the whole subtree
|
|
106
|
+
# or not
|
|
107
|
+
# + **attributes** - whether to observe changes to attributes or not,
|
|
108
|
+
# if the value is `:old` the old value will be saved
|
|
109
|
+
# + **cdata** - whether to observe changes to CDATA sections or not,
|
|
110
|
+
# if the value is `:old` the old value will be saved
|
|
111
|
+
# + **filter** - array of attribute names to observe
|
|
112
|
+
#
|
|
113
|
+
# @param target [DOM::Node, native] the node to observe
|
|
114
|
+
# @param options [Hash?] the options
|
|
115
|
+
def observe(target, options = nil)
|
|
116
|
+
unless options
|
|
117
|
+
options = {
|
|
118
|
+
children: true,
|
|
119
|
+
tree: true,
|
|
120
|
+
attributes: :old,
|
|
121
|
+
cdata: :old
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
`#@native.observe(#{Native.convert(target)}, #{convert(options)})`
|
|
126
|
+
|
|
127
|
+
self
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Empty the observer queue and return its contents.
|
|
131
|
+
#
|
|
132
|
+
# @return [Array<Record>]
|
|
133
|
+
def take
|
|
134
|
+
`#@native.takeRecords()`.map { |r| Record.new(r) }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Disconnect the observer, thus stopping observing any changes.
|
|
138
|
+
def disconnect
|
|
139
|
+
`#@native.disconnect()`
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
private
|
|
143
|
+
def convert(hash)
|
|
144
|
+
options = Native(`{}`)
|
|
145
|
+
|
|
146
|
+
if hash[:children]
|
|
147
|
+
options[:childList] = true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
if hash[:tree]
|
|
151
|
+
options[:subtree] = true
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
if attrs = hash[:attributes]
|
|
155
|
+
options[:attributes] = true
|
|
156
|
+
|
|
157
|
+
if attrs == :old
|
|
158
|
+
options[:attributeOldValue] = true
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
if filter = hash[:filter]
|
|
163
|
+
options[:attributeFilter] = filter
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
if cdata = hash[:cdata]
|
|
167
|
+
options[:characterData] = true
|
|
168
|
+
|
|
169
|
+
if cdata == :old
|
|
170
|
+
options[:characterDataOldValue] = true
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
options.to_n
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
end; end
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
module Browser; module DOM
|
|
2
|
+
|
|
3
|
+
# Abstract class for all DOM node types.
|
|
4
|
+
#
|
|
5
|
+
# @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
6
|
+
class Node
|
|
7
|
+
include Native
|
|
8
|
+
|
|
9
|
+
ELEMENT_NODE = 1
|
|
10
|
+
ATTRIBUTE_NODE = 2
|
|
11
|
+
TEXT_NODE = 3
|
|
12
|
+
CDATA_SECTION_NODE = 4
|
|
13
|
+
ENTITY_REFERENCE_NOCE = 5
|
|
14
|
+
ENTITY_NODE = 6
|
|
15
|
+
PROCESSING_INSTRUCTION_NODE = 7
|
|
16
|
+
COMMENT_NODE = 8
|
|
17
|
+
DOCUMENT_NODE = 9
|
|
18
|
+
DOCUMENT_TYPE_NODE = 10
|
|
19
|
+
DOCUMENT_FRAGMENT_NODE = 11
|
|
20
|
+
NOTATION_NODE = 12
|
|
21
|
+
|
|
22
|
+
# Wrap a native DOM node.
|
|
23
|
+
#
|
|
24
|
+
# @param value [native] the native DOM node
|
|
25
|
+
#
|
|
26
|
+
# @return [Node]
|
|
27
|
+
def self.new(value)
|
|
28
|
+
if self == Node
|
|
29
|
+
@classes ||= [nil, Element, Attribute, Text, CDATA, nil, nil, nil, Comment, Document, nil, DocumentFragment]
|
|
30
|
+
|
|
31
|
+
if klass = @classes[`value.nodeType`]
|
|
32
|
+
klass.new(value)
|
|
33
|
+
else
|
|
34
|
+
raise ArgumentError, 'cannot instantiate a non derived Node object'
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
super
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Return true of the other element is the same underlying DOM node.
|
|
42
|
+
#
|
|
43
|
+
# @return [Boolean]
|
|
44
|
+
def ==(other)
|
|
45
|
+
`#@native === #{Native.convert(other)}`
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Append a child to the node.
|
|
49
|
+
#
|
|
50
|
+
# When passing a {String} a text node will be created.
|
|
51
|
+
#
|
|
52
|
+
# When passing an Object that responds to #each, every yielded element
|
|
53
|
+
# will be added following the same logic.
|
|
54
|
+
#
|
|
55
|
+
# @param node [String, Node, #each, #to_n] the node to append
|
|
56
|
+
#
|
|
57
|
+
# @return [self]
|
|
58
|
+
def <<(node)
|
|
59
|
+
if Opal.respond_to? node, :each
|
|
60
|
+
node.each { |n| self << n }
|
|
61
|
+
return self
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
unless native?(node)
|
|
65
|
+
if String === node
|
|
66
|
+
node = `#@native.ownerDocument.createTextNode(node)`
|
|
67
|
+
else
|
|
68
|
+
node = Native.convert(node)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
`#@native.appendChild(node)`
|
|
73
|
+
|
|
74
|
+
self
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def >>(node)
|
|
78
|
+
if Opal.respond_to? node, :each
|
|
79
|
+
node.each { |n| self >> n }
|
|
80
|
+
return self
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
unless native?(node)
|
|
84
|
+
if String === node
|
|
85
|
+
node = `#@native.ownerDocument.createTextNode(node)`
|
|
86
|
+
else
|
|
87
|
+
node = Native.convert(node)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
if `#@native.firstChild == null`
|
|
92
|
+
`#@native.appendChild(node)`
|
|
93
|
+
else
|
|
94
|
+
`#@native.insertBefore(node, #@native.firstChild)`
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
self
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def add_child(node = nil, &block)
|
|
101
|
+
unless node
|
|
102
|
+
node = DOM(&block)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
self << node
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Add the passed node after this one.
|
|
109
|
+
#
|
|
110
|
+
# When passing a {String} a text node will be created.
|
|
111
|
+
#
|
|
112
|
+
# @param node [String, Node, #to_n] the node to add
|
|
113
|
+
def add_next_sibling(node = nil, &block)
|
|
114
|
+
unless node
|
|
115
|
+
node = DOM(&block)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
unless native?(node)
|
|
119
|
+
if String === node
|
|
120
|
+
node = `#@native.ownerDocument.createTextNode(node)`
|
|
121
|
+
else
|
|
122
|
+
node = Native.convert(node)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
`#@native.parentNode.insertBefore(node, #@native.nextSibling)`
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Add the passed node before this one.
|
|
130
|
+
#
|
|
131
|
+
# When passing a {String} a text node will be created.
|
|
132
|
+
#
|
|
133
|
+
# @param node [String, Node, #to_n] the node to add
|
|
134
|
+
def add_previous_sibling(node = nil, &block)
|
|
135
|
+
unless node
|
|
136
|
+
node = DOM(&block)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
unless native?(node)
|
|
140
|
+
if String === node
|
|
141
|
+
node = `#@native.ownerDocument.createTextNode(node)`
|
|
142
|
+
else
|
|
143
|
+
node = Native.convert(node)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
`#@native.parentNode.insertBefore(node, #@native)`
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
alias after add_next_sibling
|
|
151
|
+
|
|
152
|
+
# Append the node to the passed one.
|
|
153
|
+
#
|
|
154
|
+
# @param node [Node] the node to append to
|
|
155
|
+
def append_to(node)
|
|
156
|
+
node << self
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Get an array of ancestors.
|
|
160
|
+
#
|
|
161
|
+
# Passing a selector will select the ancestors matching it.
|
|
162
|
+
#
|
|
163
|
+
# @param expression [String] the selector to use as filter
|
|
164
|
+
#
|
|
165
|
+
# @return [NodeSet]
|
|
166
|
+
def ancestors(expression = nil)
|
|
167
|
+
return NodeSet[] unless parent
|
|
168
|
+
|
|
169
|
+
parents = [parent]
|
|
170
|
+
|
|
171
|
+
while parent = parents.last.parent
|
|
172
|
+
parents << parent
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if Document === parents.last
|
|
176
|
+
parents.pop
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
if expression
|
|
180
|
+
parents.select! { |p| p =~ expression }
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
NodeSet.new(parents)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
alias before add_previous_sibling
|
|
187
|
+
|
|
188
|
+
# Remove the node from its parent.
|
|
189
|
+
def remove
|
|
190
|
+
parent.remove_child(self) if parent
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Remove all the children of the node.
|
|
194
|
+
def clear
|
|
195
|
+
children.remove
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# @!attribute content
|
|
199
|
+
# @return [String] the inner text content of the node
|
|
200
|
+
if Browser.supports? 'Element.textContent'
|
|
201
|
+
def content
|
|
202
|
+
`#@native.textContent`
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def content=(value)
|
|
206
|
+
`#@native.textContent = #{value}`
|
|
207
|
+
end
|
|
208
|
+
elsif Browser.supports? 'Element.innerText'
|
|
209
|
+
def content
|
|
210
|
+
`#@native.innerText`
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def content=(value)
|
|
214
|
+
`#@native.innerText = #{value}`
|
|
215
|
+
end
|
|
216
|
+
else
|
|
217
|
+
def content
|
|
218
|
+
raise NotImplementedError, 'node text content unsupported'
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def content=(value)
|
|
222
|
+
raise NotImplementedError, 'node text content unsupported'
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def blank?
|
|
227
|
+
raise NotImplementedError
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Return true if the node is a CDATA section.
|
|
231
|
+
def cdata?
|
|
232
|
+
node_type == CDATA_SECTION_NODE
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# @!attribute [r] child
|
|
236
|
+
# @return [Node?] the first child of the node
|
|
237
|
+
def child
|
|
238
|
+
children.first
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# @!attribute children
|
|
242
|
+
# @return [NodeSet] the children of the node
|
|
243
|
+
def children
|
|
244
|
+
NodeSet[Native::Array.new(`#@native.childNodes`)]
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def children=(node)
|
|
248
|
+
raise NotImplementedError
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Return true if the node is a comment.
|
|
252
|
+
def comment?
|
|
253
|
+
node_type == COMMENT_NODE
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# @!attribute [r] document
|
|
257
|
+
# @return [Document?] the document the node is attached to
|
|
258
|
+
def document
|
|
259
|
+
DOM(`#@native.ownerDocument`) if defined?(`#@native.ownerDocument`)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Return true if the node is a document.
|
|
263
|
+
def document?
|
|
264
|
+
node_type == DOCUMENT_NODE
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Return true if the node is an element.
|
|
268
|
+
def elem?
|
|
269
|
+
node_type == ELEMENT_NODE
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
alias element? elem?
|
|
273
|
+
|
|
274
|
+
# @!attribute [r] element_children
|
|
275
|
+
# @return [NodeSet] all the children which are elements
|
|
276
|
+
def element_children
|
|
277
|
+
children.select(&:element?)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
alias elements element_children
|
|
281
|
+
|
|
282
|
+
# @!attribute [r] first_element_child
|
|
283
|
+
# @return [Element?] the first element child
|
|
284
|
+
def first_element_child
|
|
285
|
+
element_children.first
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# Return true if the node is a document fragment.
|
|
289
|
+
def fragment?
|
|
290
|
+
node_type == DOCUMENT_FRAGMENT_NODE
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# @!attribute inner_html
|
|
294
|
+
# @return [String] the inner HTML of the node
|
|
295
|
+
def inner_html
|
|
296
|
+
`#@native.innerHTML`
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def inner_html=(value)
|
|
300
|
+
`#@native.innerHTML = #{value}`
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
alias inner_text content
|
|
304
|
+
alias inner_text= content=
|
|
305
|
+
|
|
306
|
+
# @!attribute [r] last_element_child
|
|
307
|
+
# @return [Element?] the last element child
|
|
308
|
+
def last_element_child
|
|
309
|
+
element_children.last
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# @!attribute name
|
|
313
|
+
# @return [String] the name of the node
|
|
314
|
+
def name
|
|
315
|
+
`#@native.nodeName || nil`
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def name=(value)
|
|
319
|
+
`#@native.nodeName = #{value.to_s}`
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# @!attribute [r] namespace
|
|
323
|
+
# @return [String] the namespace of the node
|
|
324
|
+
def namespace
|
|
325
|
+
`#@native.namespaceURI || nil`
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# @!attribute next
|
|
329
|
+
# @return [Node?] the next sibling of the node
|
|
330
|
+
def next
|
|
331
|
+
DOM(`#@native.nextSibling`) if `#@native.nextSibling != null`
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
alias next= add_next_sibling
|
|
335
|
+
|
|
336
|
+
# @!attribute [r] next_element
|
|
337
|
+
# @return [Element?] the next element sibling of the node
|
|
338
|
+
def next_element
|
|
339
|
+
current = self.next
|
|
340
|
+
|
|
341
|
+
while current && !current.element?
|
|
342
|
+
current = current.next
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
current
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
alias next_sibling next
|
|
349
|
+
|
|
350
|
+
alias node_name name
|
|
351
|
+
|
|
352
|
+
alias node_name= name=
|
|
353
|
+
|
|
354
|
+
# @!attribute [r] node_type
|
|
355
|
+
# @return [Symbol] the type of the node
|
|
356
|
+
def node_type
|
|
357
|
+
`#@native.nodeType`
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
# @!attribute parent
|
|
361
|
+
# @return [Element?] the parent of the node
|
|
362
|
+
def parent
|
|
363
|
+
DOM(`#@native.parentNode`) if `#@native.parentNode != null`
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def parent=(node)
|
|
367
|
+
`#@native.parentNode = #{Native.convert(node)}`
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def parse(text, options = {})
|
|
371
|
+
raise NotImplementedError
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def path
|
|
375
|
+
raise NotImplementedError
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# Prepend the node to the passed one.
|
|
379
|
+
#
|
|
380
|
+
# @param node [Node] the node to prepend to
|
|
381
|
+
def prepend_to(node)
|
|
382
|
+
node >> self
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
# @!attribute previous
|
|
386
|
+
# @return [Node?] the previous sibling of the node
|
|
387
|
+
def previous
|
|
388
|
+
DOM(`#@native.previousSibling`) if `#@native.previousSibling != null`
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
alias previous= add_previous_sibling
|
|
392
|
+
|
|
393
|
+
# @!attribute [r] previous_element
|
|
394
|
+
# @return [Element?] the previous element sibling of the node
|
|
395
|
+
def previous_element
|
|
396
|
+
current = self.previous
|
|
397
|
+
|
|
398
|
+
while current && !current.element?
|
|
399
|
+
current = current.previous
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
current
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
alias previous_sibling previous
|
|
406
|
+
|
|
407
|
+
# Remove the given node from the children of this node.
|
|
408
|
+
def remove_child(node)
|
|
409
|
+
`#@native.removeChild(#{Native.try_convert(node)})`
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
# Replace the node with the given one.
|
|
413
|
+
#
|
|
414
|
+
# @todo implement for NodeSet
|
|
415
|
+
#
|
|
416
|
+
# @param node [Node] the node to replace with
|
|
417
|
+
# @return [Node] the passed node
|
|
418
|
+
def replace(node)
|
|
419
|
+
unless native?(node)
|
|
420
|
+
if String === node
|
|
421
|
+
node = `#@native.ownerDocument.createTextNode(node)`
|
|
422
|
+
else
|
|
423
|
+
node = Native.convert(node)
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
`#@native.parentNode.replaceChild(node, #@native)`
|
|
428
|
+
|
|
429
|
+
node
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
alias replace_with replace
|
|
433
|
+
|
|
434
|
+
alias text content
|
|
435
|
+
alias text= content=
|
|
436
|
+
|
|
437
|
+
# Return true if the node is a text node.
|
|
438
|
+
def text?
|
|
439
|
+
node_type == TEXT_NODE
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def traverse(&block)
|
|
443
|
+
raise NotImplementedError
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
alias type node_type
|
|
447
|
+
|
|
448
|
+
# @!attribute value
|
|
449
|
+
# @return [String] the value of the node
|
|
450
|
+
def value
|
|
451
|
+
`#@native.nodeValue || nil`
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
def value=(value)
|
|
455
|
+
`#@native.nodeValue = value`
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
# @private
|
|
459
|
+
def inspect
|
|
460
|
+
"#<DOM::Node: #{name}>"
|
|
461
|
+
end
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
end; end
|