diamonds 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- 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,194 @@
|
|
1
|
+
require 'promise'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Browser; module Database
|
5
|
+
|
6
|
+
class SQL
|
7
|
+
# Check if the browser supports WebSQL.
|
8
|
+
def self.supported?
|
9
|
+
Browser.supports? 'WebSQL'
|
10
|
+
end
|
11
|
+
|
12
|
+
class Error < StandardError
|
13
|
+
def self.new(error)
|
14
|
+
return super if self != Error
|
15
|
+
|
16
|
+
[Unknown, Database, Version, TooLarge, Quota, Syntax, Constraint, Timeout] \
|
17
|
+
[`error.code`].new(`error.message`)
|
18
|
+
end
|
19
|
+
|
20
|
+
Unknown = Class.new(self)
|
21
|
+
Database = Class.new(self)
|
22
|
+
Version = Class.new(self)
|
23
|
+
TooLarge = Class.new(self)
|
24
|
+
Quota = Class.new(self)
|
25
|
+
Syntax = Class.new(self)
|
26
|
+
Constraint = Class.new(self)
|
27
|
+
Timeout = Class.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
include Native
|
31
|
+
|
32
|
+
# @return [String] the name of the database
|
33
|
+
attr_reader :name
|
34
|
+
|
35
|
+
# @return [String] the description for the database
|
36
|
+
attr_reader :description
|
37
|
+
|
38
|
+
# @return [Integer] the size constraint in bytes
|
39
|
+
attr_reader :size
|
40
|
+
|
41
|
+
# Open a database with the given name and options.
|
42
|
+
#
|
43
|
+
# @param name [String] the name for the database
|
44
|
+
# @param options [Hash] options to open the database
|
45
|
+
#
|
46
|
+
# @option options [String] :description the description for the database
|
47
|
+
# @option options [String] :version ('') the expected version of the database
|
48
|
+
# @option options [Integer] :size (5 * 1024 * 1024) the size constraint in bytes
|
49
|
+
def initialize(name, options = {})
|
50
|
+
@name = name
|
51
|
+
@description = options[:description] || name
|
52
|
+
@version = options[:version] || ''
|
53
|
+
@size = options[:size] || 2 * 1024 * 1024
|
54
|
+
|
55
|
+
super(`window.openDatabase(#{name}, #{@version}, #{@description}, #{@size})`)
|
56
|
+
end
|
57
|
+
|
58
|
+
# @overload version()
|
59
|
+
#
|
60
|
+
# Get the version of the database.
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
#
|
64
|
+
# @overload version(from, to, &block)
|
65
|
+
#
|
66
|
+
# Migrate the database to a new version.
|
67
|
+
#
|
68
|
+
# @param from [String] the version you're migrating from
|
69
|
+
# @param to [String] the version you're migrating to
|
70
|
+
#
|
71
|
+
# @yieldparam transaction [Transaction] the transaction to work with
|
72
|
+
def version(from = nil, to = nil, &block)
|
73
|
+
return `#@native.version` unless block
|
74
|
+
|
75
|
+
`#@native.changeVersion(#{from}, #{to},
|
76
|
+
#{-> t { block.call(Transaction.new(self, t)) }})`
|
77
|
+
end
|
78
|
+
|
79
|
+
# Start a transaction on the database.
|
80
|
+
#
|
81
|
+
# @yieldparam transaction [Transaction] the transaction to work on
|
82
|
+
def transaction(&block)
|
83
|
+
raise ArgumentError, 'no block given' unless block
|
84
|
+
|
85
|
+
`#@native.transaction(#{-> t { block.call(Transaction.new(self, t)) }})`
|
86
|
+
end
|
87
|
+
|
88
|
+
# Allows you to make changes to the database or read data from it.
|
89
|
+
class Transaction
|
90
|
+
include Native
|
91
|
+
|
92
|
+
# @return [Database] the database the transaction has been created from
|
93
|
+
attr_reader :database
|
94
|
+
|
95
|
+
# @private
|
96
|
+
def initialize(database, transaction)
|
97
|
+
@database = database
|
98
|
+
|
99
|
+
super(transaction)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Query the database.
|
103
|
+
#
|
104
|
+
# @param query [String] the SQL query to send
|
105
|
+
# @param parameters [Array] optional bind parameters for the query
|
106
|
+
#
|
107
|
+
# @return [Promise]
|
108
|
+
def query(query, *parameters)
|
109
|
+
promise = Promise.new
|
110
|
+
|
111
|
+
`#@native.executeSql(#{query}, #{parameters},
|
112
|
+
#{-> _, r { promise.resolve(Result.new(self, r)) }},
|
113
|
+
#{-> _, e { promise.reject(Error.new(e)) }})`
|
114
|
+
|
115
|
+
promise
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Represents a row.
|
120
|
+
class Row < OpenStruct
|
121
|
+
# @private
|
122
|
+
def initialize(row)
|
123
|
+
super(Hash.new(row))
|
124
|
+
end
|
125
|
+
|
126
|
+
def inspect
|
127
|
+
"#<SQL::Row: #{Hash.new(@native).inspect}>"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Result
|
132
|
+
include Native
|
133
|
+
|
134
|
+
# @return [Transaction] the transaction the result came from
|
135
|
+
attr_reader :transaction
|
136
|
+
|
137
|
+
# @return [SQL] the database the result came from
|
138
|
+
attr_reader :database
|
139
|
+
|
140
|
+
# @private
|
141
|
+
def initialize(transaction, result)
|
142
|
+
@transaction = transaction
|
143
|
+
@database = transaction.database
|
144
|
+
|
145
|
+
super(result)
|
146
|
+
end
|
147
|
+
|
148
|
+
include Enumerable
|
149
|
+
|
150
|
+
# Get a row from the result.
|
151
|
+
#
|
152
|
+
# @param index [Integer] the index for the row
|
153
|
+
#
|
154
|
+
# @return [Row]
|
155
|
+
def [](index)
|
156
|
+
if index < 0
|
157
|
+
index += length
|
158
|
+
end
|
159
|
+
|
160
|
+
unless index < 0 || index >= length
|
161
|
+
Row.new(`#@native.rows.item(index)`)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Enumerate over the rows.
|
166
|
+
#
|
167
|
+
# @yieldparam row [Row]
|
168
|
+
#
|
169
|
+
# @return [self]
|
170
|
+
def each(&block)
|
171
|
+
return enum_for :each unless block
|
172
|
+
|
173
|
+
%x{
|
174
|
+
for (var i = 0, length = #@native.rows.length; i < length; i++) {
|
175
|
+
#{block.call(self[`i`])};
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
self
|
180
|
+
end
|
181
|
+
|
182
|
+
# @!attribute [r] length
|
183
|
+
# @return [Integer] number of rows in the result
|
184
|
+
def length
|
185
|
+
`#@native.rows.length`
|
186
|
+
end
|
187
|
+
|
188
|
+
# @!attribute [r] affected
|
189
|
+
# @return [Integer] number of affected rows
|
190
|
+
alias_native :affected, :rowsAffected
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end; end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Browser
|
2
|
+
|
3
|
+
# Allows you to delay the call to a function which gets called after the
|
4
|
+
# given time.
|
5
|
+
#
|
6
|
+
# @see https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout
|
7
|
+
class Delay
|
8
|
+
# @!attribute [r] after
|
9
|
+
# @return [Float] the seconds after which the block is called
|
10
|
+
attr_reader :after
|
11
|
+
|
12
|
+
# Create and start a timeout.
|
13
|
+
#
|
14
|
+
# @param window [Window] the window to start the timeout on
|
15
|
+
# @param time [Float] seconds after which the block is called
|
16
|
+
def initialize(window, time, &block)
|
17
|
+
@window = Native.convert(window)
|
18
|
+
@after = time
|
19
|
+
@block = block
|
20
|
+
end
|
21
|
+
|
22
|
+
# Abort the timeout.
|
23
|
+
def abort
|
24
|
+
`#@window.clearTimeout(#@id)`
|
25
|
+
end
|
26
|
+
|
27
|
+
# Start the delay.
|
28
|
+
def start
|
29
|
+
@id = `#@window.setTimeout(#{@block.to_n}, #@after * 1000)`
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Window
|
34
|
+
# Execute a block after the given seconds.
|
35
|
+
#
|
36
|
+
# @param time [Float] the seconds after it gets called
|
37
|
+
#
|
38
|
+
# @return [Delay] the object representing the timeout
|
39
|
+
def after(time, &block)
|
40
|
+
Delay.new(@native, time, &block).tap(&:start)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Execute a block after the given seconds, you have to call [#start] on it
|
44
|
+
# yourself.
|
45
|
+
#
|
46
|
+
# @param time [Float] the seconds after it gets called
|
47
|
+
#
|
48
|
+
# @return [Delay] the object representing the timeout
|
49
|
+
def after!(time, &block)
|
50
|
+
Delay.new(@native, time, &block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
module Kernel
|
57
|
+
# (see Browser::Window#after)
|
58
|
+
def after(time, &block)
|
59
|
+
$window.after(time, &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
# (see Browser::Window#after!)
|
63
|
+
def after!(time, &block)
|
64
|
+
$window.after!(time, &block)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Proc
|
69
|
+
# (see Browser::Window#after)
|
70
|
+
def after(time)
|
71
|
+
$window.after(time, &self)
|
72
|
+
end
|
73
|
+
|
74
|
+
# (see Browser::Window#after!)
|
75
|
+
def after!(time)
|
76
|
+
$window.after!(time, &self)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'browser/dom/node_set'
|
2
|
+
require 'browser/dom/node'
|
3
|
+
require 'browser/dom/attribute'
|
4
|
+
require 'browser/dom/character_data'
|
5
|
+
require 'browser/dom/text'
|
6
|
+
require 'browser/dom/cdata'
|
7
|
+
require 'browser/dom/comment'
|
8
|
+
require 'browser/dom/element'
|
9
|
+
require 'browser/dom/document'
|
10
|
+
require 'browser/dom/document_fragment'
|
11
|
+
require 'browser/dom/builder'
|
12
|
+
require 'browser/dom/mutation_observer'
|
13
|
+
|
14
|
+
module Kernel
|
15
|
+
# Parse an XML string into a DOM usable {Browser::DOM::Document}
|
16
|
+
#
|
17
|
+
# @param what [String] the string to parse
|
18
|
+
# @return [Browser::DOM::Document] the document
|
19
|
+
def XML(what)
|
20
|
+
%x{
|
21
|
+
var doc;
|
22
|
+
|
23
|
+
if (window.DOMParser) {
|
24
|
+
doc = new DOMParser().parseFromString(what, 'text/xml');
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
doc = new ActiveXObject('Microsoft.XMLDOM');
|
28
|
+
doc.async = 'false';
|
29
|
+
doc.loadXML(what);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
DOM(`doc`)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Wrap a native element or create a DOM tree using the {Paggio::HTML} DSL.
|
37
|
+
#
|
38
|
+
# @return [Browser::DOM::Node]
|
39
|
+
def DOM(*args, &block)
|
40
|
+
if block
|
41
|
+
document = args.shift || $document
|
42
|
+
roots = Browser::DOM::Builder.new(document, &block).to_a
|
43
|
+
|
44
|
+
if roots.length == 1
|
45
|
+
roots.first
|
46
|
+
else
|
47
|
+
Browser::DOM::NodeSet.new(roots)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
what = args.shift
|
51
|
+
document = args.shift || $document
|
52
|
+
|
53
|
+
if native?(what)
|
54
|
+
Browser::DOM::Node.new(what)
|
55
|
+
elsif Browser::DOM::Node === what
|
56
|
+
what
|
57
|
+
elsif String === what
|
58
|
+
%x{
|
59
|
+
var doc = #{Native.try_convert(document)}.createElement('div');
|
60
|
+
doc.innerHTML = what;
|
61
|
+
|
62
|
+
return #{DOM(`doc.childNodes.length == 1 ? doc.childNodes[0] : doc`)};
|
63
|
+
}
|
64
|
+
else
|
65
|
+
raise ArgumentError, "argument not DOM convertible"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module Browser
|
72
|
+
|
73
|
+
class Window
|
74
|
+
# Get the {DOM::Document} for this window.
|
75
|
+
#
|
76
|
+
# @return [DOM::Document]
|
77
|
+
def document
|
78
|
+
DOM(`#@native.document`)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
$document = $window.document
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Browser; module DOM
|
2
|
+
|
3
|
+
# Encapsulates an {Element} attribute.
|
4
|
+
class Attribute
|
5
|
+
include Native
|
6
|
+
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String] the name of the attribute
|
9
|
+
alias_native :name
|
10
|
+
|
11
|
+
# @!attribute value
|
12
|
+
# @return [String] the value of the attribute
|
13
|
+
alias_native :value
|
14
|
+
alias_native :value=
|
15
|
+
|
16
|
+
# Returns true if the attribute is an id.
|
17
|
+
if Browser.supports? 'Attr.isId'
|
18
|
+
alias_native :id?, :isId
|
19
|
+
else
|
20
|
+
def id?
|
21
|
+
name == :id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end; end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Temporary fix for a bug in String#scan
|
2
|
+
module Paggio::Utils
|
3
|
+
def self.heredoc(string)
|
4
|
+
string
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Paggio::HTML::Element < BasicObject
|
9
|
+
def on(*args, &block)
|
10
|
+
(@on ||= []) << [args, block]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Browser; module DOM
|
15
|
+
|
16
|
+
class Builder
|
17
|
+
def self.to_h
|
18
|
+
@builders ||= {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.for(klass, &block)
|
22
|
+
if block
|
23
|
+
to_h[klass] = block
|
24
|
+
else
|
25
|
+
to_h[klass]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build(builder, item)
|
30
|
+
to_h.each {|klass, block|
|
31
|
+
if klass === item
|
32
|
+
return block.call(builder, item)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
|
36
|
+
raise ArgumentError, "cannot build unknown item #{item}"
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :document, :element
|
40
|
+
|
41
|
+
def initialize(document, &block)
|
42
|
+
@document = document
|
43
|
+
@builder = Paggio::HTML.new(&block)
|
44
|
+
@roots = @builder.each.map { |e| Builder.build(self, e) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_a
|
48
|
+
@roots
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Builder.for String do |b, item|
|
53
|
+
b.document.create_text(item)
|
54
|
+
end
|
55
|
+
|
56
|
+
Builder.for Paggio::HTML::Element do |b, item|
|
57
|
+
dom = b.document.create_element(`item.name`)
|
58
|
+
|
59
|
+
if Hash === `item.attributes`
|
60
|
+
dom.attributes.merge!(`item.attributes`)
|
61
|
+
end
|
62
|
+
|
63
|
+
`item.class_names`.each {|value|
|
64
|
+
dom.add_class value
|
65
|
+
}
|
66
|
+
|
67
|
+
if on = `item.on || nil`
|
68
|
+
on.each {|args, block|
|
69
|
+
dom.on(*args, &block)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
if inner = `item.inner_html || nil`
|
74
|
+
dom.inner_html = inner
|
75
|
+
else
|
76
|
+
item.each {|child|
|
77
|
+
dom << Builder.build(b, child)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
dom
|
82
|
+
end
|
83
|
+
|
84
|
+
Builder.for DOM::Node do |b, item|
|
85
|
+
item
|
86
|
+
end
|
87
|
+
|
88
|
+
end; end
|