diamonds 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +36 -0
  3. data/lib/diamonds.rb +74 -0
  4. data/lib/diamonds/Gemfile +28 -0
  5. data/lib/diamonds/README.md +254 -0
  6. data/lib/diamonds/Rakefile +5 -0
  7. data/lib/diamonds/apps/application.rb +15 -0
  8. data/lib/diamonds/apps/library.rb +321 -0
  9. data/lib/diamonds/apps/user_app.rb +5 -0
  10. data/lib/diamonds/config.ru +98 -0
  11. data/lib/diamonds/db/mysiteDB Back.sqlite3 +0 -0
  12. data/lib/diamonds/db/mysiteDB.sqlite3 +0 -0
  13. data/lib/diamonds/gems/auto_launch_browser.rb +22 -0
  14. data/lib/diamonds/gems/io.rb +146 -0
  15. data/lib/diamonds/gems/ruby_to_js.rb +173 -0
  16. data/lib/diamonds/gems/server_utils.rb +96 -0
  17. data/lib/diamonds/lib/opal-browser.rb +1 -0
  18. data/lib/diamonds/lib/opal/browser.rb +4 -0
  19. data/lib/diamonds/opal-browser.gemspec +21 -0
  20. data/lib/diamonds/opal/browser.rb +11 -0
  21. data/lib/diamonds/opal/browser/animation_frame.rb +111 -0
  22. data/lib/diamonds/opal/browser/canvas.rb +321 -0
  23. data/lib/diamonds/opal/browser/canvas/data.rb +63 -0
  24. data/lib/diamonds/opal/browser/canvas/gradient.rb +27 -0
  25. data/lib/diamonds/opal/browser/canvas/style.rb +113 -0
  26. data/lib/diamonds/opal/browser/canvas/text.rb +45 -0
  27. data/lib/diamonds/opal/browser/console.rb +103 -0
  28. data/lib/diamonds/opal/browser/cookies.rb +133 -0
  29. data/lib/diamonds/opal/browser/css.rb +24 -0
  30. data/lib/diamonds/opal/browser/css/declaration.rb +83 -0
  31. data/lib/diamonds/opal/browser/css/rule.rb +48 -0
  32. data/lib/diamonds/opal/browser/css/rule/style.rb +16 -0
  33. data/lib/diamonds/opal/browser/css/style_sheet.rb +83 -0
  34. data/lib/diamonds/opal/browser/css/unit.rb +188 -0
  35. data/lib/diamonds/opal/browser/database/sql.rb +194 -0
  36. data/lib/diamonds/opal/browser/delay.rb +78 -0
  37. data/lib/diamonds/opal/browser/dom.rb +84 -0
  38. data/lib/diamonds/opal/browser/dom/attribute.rb +26 -0
  39. data/lib/diamonds/opal/browser/dom/builder.rb +88 -0
  40. data/lib/diamonds/opal/browser/dom/cdata.rb +9 -0
  41. data/lib/diamonds/opal/browser/dom/character_data.rb +73 -0
  42. data/lib/diamonds/opal/browser/dom/comment.rb +9 -0
  43. data/lib/diamonds/opal/browser/dom/document.rb +149 -0
  44. data/lib/diamonds/opal/browser/dom/document_fragment.rb +7 -0
  45. data/lib/diamonds/opal/browser/dom/element.rb +474 -0
  46. data/lib/diamonds/opal/browser/dom/element/attributes.rb +87 -0
  47. data/lib/diamonds/opal/browser/dom/element/data.rb +67 -0
  48. data/lib/diamonds/opal/browser/dom/element/image.rb +23 -0
  49. data/lib/diamonds/opal/browser/dom/element/input.rb +28 -0
  50. data/lib/diamonds/opal/browser/dom/element/offset.rb +89 -0
  51. data/lib/diamonds/opal/browser/dom/element/position.rb +46 -0
  52. data/lib/diamonds/opal/browser/dom/element/scroll.rb +136 -0
  53. data/lib/diamonds/opal/browser/dom/element/select.rb +36 -0
  54. data/lib/diamonds/opal/browser/dom/element/size.rb +34 -0
  55. data/lib/diamonds/opal/browser/dom/element/template.rb +9 -0
  56. data/lib/diamonds/opal/browser/dom/element/textarea.rb +24 -0
  57. data/lib/diamonds/opal/browser/dom/mutation_observer.rb +178 -0
  58. data/lib/diamonds/opal/browser/dom/node.rb +464 -0
  59. data/lib/diamonds/opal/browser/dom/node_set.rb +110 -0
  60. data/lib/diamonds/opal/browser/dom/text.rb +36 -0
  61. data/lib/diamonds/opal/browser/effects.rb +50 -0
  62. data/lib/diamonds/opal/browser/event.rb +253 -0
  63. data/lib/diamonds/opal/browser/event/animation.rb +38 -0
  64. data/lib/diamonds/opal/browser/event/audio_processing.rb +33 -0
  65. data/lib/diamonds/opal/browser/event/base.rb +430 -0
  66. data/lib/diamonds/opal/browser/event/before_unload.rb +15 -0
  67. data/lib/diamonds/opal/browser/event/clipboard.rb +28 -0
  68. data/lib/diamonds/opal/browser/event/close.rb +47 -0
  69. data/lib/diamonds/opal/browser/event/composition.rb +50 -0
  70. data/lib/diamonds/opal/browser/event/custom.rb +65 -0
  71. data/lib/diamonds/opal/browser/event/device_light.rb +23 -0
  72. data/lib/diamonds/opal/browser/event/device_motion.rb +51 -0
  73. data/lib/diamonds/opal/browser/event/device_orientation.rb +48 -0
  74. data/lib/diamonds/opal/browser/event/device_proximity.rb +33 -0
  75. data/lib/diamonds/opal/browser/event/drag.rb +119 -0
  76. data/lib/diamonds/opal/browser/event/focus.rb +39 -0
  77. data/lib/diamonds/opal/browser/event/gamepad.rb +60 -0
  78. data/lib/diamonds/opal/browser/event/hash_change.rb +28 -0
  79. data/lib/diamonds/opal/browser/event/keyboard.rb +115 -0
  80. data/lib/diamonds/opal/browser/event/message.rb +70 -0
  81. data/lib/diamonds/opal/browser/event/mouse.rb +254 -0
  82. data/lib/diamonds/opal/browser/event/page_transition.rb +23 -0
  83. data/lib/diamonds/opal/browser/event/pop_state.rb +33 -0
  84. data/lib/diamonds/opal/browser/event/progress.rb +43 -0
  85. data/lib/diamonds/opal/browser/event/sensor.rb +15 -0
  86. data/lib/diamonds/opal/browser/event/storage.rb +43 -0
  87. data/lib/diamonds/opal/browser/event/touch.rb +60 -0
  88. data/lib/diamonds/opal/browser/event/ui.rb +38 -0
  89. data/lib/diamonds/opal/browser/event/wheel.rb +49 -0
  90. data/lib/diamonds/opal/browser/event_source.rb +70 -0
  91. data/lib/diamonds/opal/browser/history.rb +90 -0
  92. data/lib/diamonds/opal/browser/http.rb +169 -0
  93. data/lib/diamonds/opal/browser/http/binary.rb +58 -0
  94. data/lib/diamonds/opal/browser/http/headers.rb +109 -0
  95. data/lib/diamonds/opal/browser/http/request.rb +344 -0
  96. data/lib/diamonds/opal/browser/http/response.rb +115 -0
  97. data/lib/diamonds/opal/browser/immediate.rb +163 -0
  98. data/lib/diamonds/opal/browser/interval.rb +111 -0
  99. data/lib/diamonds/opal/browser/location.rb +87 -0
  100. data/lib/diamonds/opal/browser/navigator.rb +173 -0
  101. data/lib/diamonds/opal/browser/screen.rb +66 -0
  102. data/lib/diamonds/opal/browser/socket.rb +123 -0
  103. data/lib/diamonds/opal/browser/storage.rb +252 -0
  104. data/lib/diamonds/opal/browser/support.rb +287 -0
  105. data/lib/diamonds/opal/browser/utils.rb +74 -0
  106. data/lib/diamonds/opal/browser/version.rb +3 -0
  107. data/lib/diamonds/opal/browser/window.rb +120 -0
  108. data/lib/diamonds/opal/browser/window/scroll.rb +59 -0
  109. data/lib/diamonds/opal/browser/window/size.rb +59 -0
  110. data/lib/diamonds/opal/browser/window/view.rb +36 -0
  111. data/lib/diamonds/opal/opal-browser.rb +1 -0
  112. data/lib/diamonds/public/__OPAL_SOURCE_MAPS__/application.map +0 -0
  113. data/lib/diamonds/public/javascripts/font-awesome/HELP-US-OUT.txt +7 -0
  114. data/lib/diamonds/public/javascripts/font-awesome/css/font-awesome.css +2026 -0
  115. data/lib/diamonds/public/javascripts/font-awesome/css/font-awesome.min.css +1 -0
  116. data/lib/diamonds/public/javascripts/font-awesome/fonts/FontAwesome.otf +0 -0
  117. data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  118. data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.svg +640 -0
  119. data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  120. data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  121. data/lib/diamonds/public/javascripts/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  122. data/lib/diamonds/public/javascripts/font-awesome/less/animated.less +34 -0
  123. data/lib/diamonds/public/javascripts/font-awesome/less/bordered-pulled.less +25 -0
  124. data/lib/diamonds/public/javascripts/font-awesome/less/core.less +12 -0
  125. data/lib/diamonds/public/javascripts/font-awesome/less/fixed-width.less +6 -0
  126. data/lib/diamonds/public/javascripts/font-awesome/less/font-awesome.less +17 -0
  127. data/lib/diamonds/public/javascripts/font-awesome/less/icons.less +677 -0
  128. data/lib/diamonds/public/javascripts/font-awesome/less/larger.less +13 -0
  129. data/lib/diamonds/public/javascripts/font-awesome/less/list.less +19 -0
  130. data/lib/diamonds/public/javascripts/font-awesome/less/mixins.less +26 -0
  131. data/lib/diamonds/public/javascripts/font-awesome/less/path.less +15 -0
  132. data/lib/diamonds/public/javascripts/font-awesome/less/rotated-flipped.less +20 -0
  133. data/lib/diamonds/public/javascripts/font-awesome/less/stacked.less +20 -0
  134. data/lib/diamonds/public/javascripts/font-awesome/less/variables.less +688 -0
  135. data/lib/diamonds/public/javascripts/font-awesome/scss/_animated.scss +34 -0
  136. data/lib/diamonds/public/javascripts/font-awesome/scss/_bordered-pulled.scss +25 -0
  137. data/lib/diamonds/public/javascripts/font-awesome/scss/_core.scss +12 -0
  138. data/lib/diamonds/public/javascripts/font-awesome/scss/_fixed-width.scss +6 -0
  139. data/lib/diamonds/public/javascripts/font-awesome/scss/_icons.scss +677 -0
  140. data/lib/diamonds/public/javascripts/font-awesome/scss/_larger.scss +13 -0
  141. data/lib/diamonds/public/javascripts/font-awesome/scss/_list.scss +19 -0
  142. data/lib/diamonds/public/javascripts/font-awesome/scss/_mixins.scss +26 -0
  143. data/lib/diamonds/public/javascripts/font-awesome/scss/_path.scss +15 -0
  144. data/lib/diamonds/public/javascripts/font-awesome/scss/_rotated-flipped.scss +20 -0
  145. data/lib/diamonds/public/javascripts/font-awesome/scss/_stacked.scss +20 -0
  146. data/lib/diamonds/public/javascripts/font-awesome/scss/_variables.scss +688 -0
  147. data/lib/diamonds/public/javascripts/font-awesome/scss/font-awesome.scss +17 -0
  148. data/lib/diamonds/public/javascripts/jquery-2.1.4.min.js +4 -0
  149. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  150. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  151. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_flat_10_000000_40x100.png +0 -0
  152. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  153. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  154. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  155. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  156. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  157. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  158. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_222222_256x240.png +0 -0
  159. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_228ef1_256x240.png +0 -0
  160. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ef8c08_256x240.png +0 -0
  161. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ffd27a_256x240.png +0 -0
  162. data/lib/diamonds/public/javascripts/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  163. data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.min.css +7 -0
  164. data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.min.js +13 -0
  165. data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.structure.min.css +5 -0
  166. data/lib/diamonds/public/javascripts/jquery-ui/jquery-ui.theme.min.css +5 -0
  167. data/lib/diamonds/public/javascripts/jquery.js +4 -0
  168. data/lib/diamonds/public/javascripts/jquery.ui.touch-punch.min.js +11 -0
  169. 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
  170. data/lib/diamonds/public/javascripts/standalone.js +2316 -0
  171. data/lib/diamonds/public/javascripts/standalone.min.js +1 -0
  172. data/lib/diamonds/public/javascripts/wysiwyg-editor.min.css +1 -0
  173. data/lib/diamonds/public/javascripts/wysiwyg-editor.min.js +1 -0
  174. data/lib/diamonds/public/javascripts/wysiwyg.min.js +1 -0
  175. data/lib/diamonds/user_app/main.rb +45 -0
  176. data/lib/diamonds/version.rb +3 -0
  177. data/lib/diamonds/views/index.erb +35 -0
  178. data/lib/diamonds/views/javascripts/jeezs_editor.js.erb +365 -0
  179. data/lib/diamonds/views/stylesheets/main.css.erb +244 -0
  180. metadata +490 -0
@@ -0,0 +1,287 @@
1
+ # The engine the browser is running on.
2
+ #
3
+ # Keep in mind it uses the user agent to know, so it's not reliable in case of
4
+ # spoofing.
5
+ BROWSER_ENGINE = `/MSIE|WebKit|Presto|Gecko/.exec(navigator.userAgent)[0]`.downcase rescue :unknown
6
+
7
+ module Browser
8
+ # @private
9
+ @support = `{}`
10
+
11
+ # Check if the browser supports the given feature.
12
+ def self.supports?(feature)
13
+ if defined?(`#@support[#{feature}]`)
14
+ return `#@support[#{feature}]`
15
+ end
16
+
17
+ support = case feature
18
+ when 'MutationObserver'
19
+ defined?(`window.MutationObserver`)
20
+
21
+ when 'WebSocket'
22
+ defined?(`window.WebSocket`)
23
+
24
+ when 'EventSource'
25
+ defined?(`window.EventSource`)
26
+
27
+ when 'XHR'
28
+ defined?(`window.XMLHttpRequest`)
29
+
30
+ when 'ActiveX'
31
+ defined?(`window.ActiveXObject`)
32
+
33
+ when 'WebSQL'
34
+ defined?(`window.openDatabase`)
35
+
36
+ when 'Query.css'
37
+ defined?(`document.querySelectorAll`)
38
+
39
+ when 'Query.xpath'
40
+ defined?(`document.evaluate`)
41
+
42
+ when 'Storage.local'
43
+ defined?(`window.localStorage`)
44
+
45
+ when 'Storage.global'
46
+ defined?(`window.globalStorage`)
47
+
48
+ when 'Storage.session'
49
+ defined?(`window.sessionStorage`)
50
+
51
+ when 'Immediate'
52
+ defined?(`window.setImmediate`)
53
+
54
+ when 'Immediate (Internet Explorer)'
55
+ defined?(`window.msSetImmediate`)
56
+
57
+ when 'Immediate (Firefox)'
58
+ defined?(`window.mozSetImmediate`)
59
+
60
+ when 'Immediate (Opera)'
61
+ defined?(`window.oSetImmediate`)
62
+
63
+ when 'Immediate (Chrome)', 'setImmediate (Safari)'
64
+ defined?(`window.webkitSetImmediate`)
65
+
66
+ when 'CSS.computed'
67
+ defined?(`window.getComputedStyle`)
68
+
69
+ when 'CSS.current'
70
+ defined?(`document.documentElement.currentStyle`)
71
+
72
+ when 'Window.send'
73
+ defined?(`window.postMessage`)
74
+
75
+ when 'Window.send (Asynchronous)'
76
+ if defined?(`window.postMessage`) && !defined?(`window.importScripts`)
77
+ %x{
78
+ var ok = true,
79
+ old = window.onmessage;
80
+
81
+ window.onmessage = function() { ok = false; };
82
+ window.postMessage("", "*")
83
+ window.onmessage = old;
84
+
85
+ return ok;
86
+ }
87
+ end
88
+
89
+ when 'Window.send (Synchronous)'
90
+ !supports?('Window.send (Asynchronous)')
91
+
92
+ when 'Window.innerSize'
93
+ defined?(`window.innerHeight`)
94
+
95
+ when 'Window.outerSize'
96
+ defined?(`window.outerHeight`)
97
+
98
+ when 'Window.scroll'
99
+ defined?(`document.documentElement.scrollLeft`)
100
+
101
+ when 'Window.pageOffset'
102
+ defined?(`window.pageXOffset`)
103
+
104
+ when 'Attr.isId'
105
+ %x{
106
+ var div = document.createElement('div');
107
+ div.setAttribute('id', 'xxxxxxxxxxxxx');
108
+
109
+ return typeof(div.attributes['id'].isId) !== "undefined";
110
+ }
111
+
112
+ when 'Element.addBehavior'
113
+ defined?(`document.documentElement.addBehavior`)
114
+
115
+ when 'Element.className'
116
+ %x{
117
+ var div = document.createElement("div");
118
+ div.setAttribute('className', 'x');
119
+
120
+ return div.className === 'x';
121
+ }
122
+
123
+ when 'Element.class'
124
+ %x{
125
+ var div = document.createElement("div");
126
+ div.setAttribute('class', 'x');
127
+
128
+ return div.className === 'x';
129
+ }
130
+
131
+ when 'Element.for'
132
+ %x{
133
+ var label = document.createElement("label");
134
+ label.setAttribute('for', 'x');
135
+
136
+ return label.htmlFor === 'x';
137
+ }
138
+
139
+ when 'Element.htmlFor'
140
+ %x{
141
+ var label = document.createElement("label");
142
+ label.setAttribute('htmlFor', 'x');
143
+
144
+ return label.htmlFor === 'x';
145
+ }
146
+
147
+ when 'Element.clientSize'
148
+ defined?(`document.documentElement.clientHeight`)
149
+
150
+ when 'Element.scroll'
151
+ defined?(`document.documentElement.scrollLeft`)
152
+
153
+ when 'Element.textContent'
154
+ defined?(`document.documentElement.textContent`)
155
+
156
+ when 'Element.innerText'
157
+ defined?(`document.documentElement.innerText`)
158
+
159
+ when 'Element.matches'
160
+ defined?(`document.documentElement.matches`)
161
+
162
+ when 'Element.matches (Internet Explorer)'
163
+ defined?(`document.documentElement.msMatchesSelector`)
164
+
165
+ when 'Element.matches (Firefox)'
166
+ defined?(`document.documentElement.mozMatchesSelector`)
167
+
168
+ when 'Element.matches (Opera)'
169
+ defined?(`document.documentElement.oMatchesSelector`)
170
+
171
+ when 'Element.matches (Chrome)', 'Element.matches (Safari)'
172
+ defined?(`document.documentElement.webkitMatchesSelector`)
173
+
174
+ when 'Element.getBoundingClientRect'
175
+ defined?(`document.documentElement.getBoundingClientRect`)
176
+
177
+ when 'Event.readystatechange'
178
+ `"onreadystatechange" in window.document.createElement("script")`
179
+
180
+ when 'Event.constructor'
181
+ begin
182
+ `new MouseEvent("click")`
183
+
184
+ true
185
+ rescue
186
+ false
187
+ end
188
+
189
+ when 'Event.create'
190
+ defined?(`document.createEvent`)
191
+
192
+ when 'Event.createObject'
193
+ defined?(`document.createEventObject`)
194
+
195
+ when 'Event.addListener'
196
+ defined?(`document.addEventListener`)
197
+
198
+ when 'Event.attach'
199
+ defined?(`document.attachEvent`)
200
+
201
+ when 'Event.removeListener'
202
+ defined?(`document.removeEventListener`)
203
+
204
+ when 'Event.detach'
205
+ defined?(`document.detachEvent`)
206
+
207
+ when 'Event.dispatch'
208
+ defined?(`document.dispatchEvent`)
209
+
210
+ when 'Event.fire'
211
+ defined?(`document.fireEvent`)
212
+
213
+ when /^Event\.([A-Z].*?)$/
214
+ `(#{$1} + "Event") in window`
215
+
216
+ when 'Document.view'
217
+ defined?(`document.defaultView`)
218
+
219
+ when 'Document.window'
220
+ defined?(`document.parentWindow`)
221
+
222
+ when 'History'
223
+ defined?(`window.history.pushState`)
224
+
225
+ when 'History.state'
226
+ defined?(`window.history.state`)
227
+
228
+ when 'Animation.request'
229
+ defined?(`window.requestAnimationFrame`)
230
+
231
+ when 'Animation.request (Internet Explorer)'
232
+ defined?(`window.msRequestAnimationFrame`)
233
+
234
+ when 'Animation.request (Firefox)'
235
+ defined?(`window.mozRequestAnimationFrame`)
236
+
237
+ when 'Animation.request (Opera)'
238
+ defined?(`window.oRequestAnimationFrame`)
239
+
240
+ when 'Animation.request (Chrome)', 'Animation.request (Safari)'
241
+ defined?(`window.webkitRequestAnimationFrame`)
242
+
243
+ when 'Animation.cancel'
244
+ defined?(`window.cancelAnimationFrame`)
245
+
246
+ when 'Animation.cancel (Internet Explorer)'
247
+ defined?(`window.msCancelAnimationFrame`)
248
+
249
+ when 'Animation.cancel (Firefox)'
250
+ defined?(`window.mozCancelAnimationFrame`)
251
+
252
+ when 'Animation.cancel (Opera)'
253
+ defined?(`window.oCancelAnimationFrame`)
254
+
255
+ when 'Animation.cancel (Chrome)', 'Animation.cancel (Safari)'
256
+ defined?(`window.webkitCancelAnimationFrame`)
257
+
258
+ when 'Animation.cancelRequest'
259
+ defined?(`window.cancelRequestAnimationFrame`)
260
+
261
+ when 'Animation.cancelRequest (Internet Explorer)'
262
+ defined?(`window.msCancelRequestAnimationFrame`)
263
+
264
+ when 'Animation.cancelRequest (Firefox)'
265
+ defined?(`window.mozCancelRequestAnimationFrame`)
266
+
267
+ when 'Animation.cancelRequest (Opera)'
268
+ defined?(`window.oCancelRequestAnimationFrame`)
269
+
270
+ when 'Animation.cancelRequest (Chrome)', 'Animation.cancelRequest (Safari)'
271
+ defined?(`window.webkitCancelRequestAnimationFrame`)
272
+ end
273
+
274
+ `#@support[#{feature}] = #{support}`
275
+ end
276
+
277
+ # Check if the given polyfill is loaded.
278
+ def self.loaded?(name)
279
+ case name
280
+ when 'Sizzle'
281
+ defined?(`window.Sizzle`)
282
+
283
+ when 'wicked-good-xpath'
284
+ defined?(`window.wgxpath`)
285
+ end
286
+ end
287
+ end
@@ -0,0 +1,74 @@
1
+ module Browser
2
+ Size = Struct.new(:width, :height)
3
+ Position = Struct.new(:x, :y)
4
+ end
5
+
6
+ class Object
7
+ # Encode as URI.
8
+ #
9
+ # @return [String] the {Object#to_s} encoded for usage as URI
10
+ def encode_uri
11
+ to_s.encode_uri
12
+ end
13
+
14
+ # Encode as URI component.
15
+ #
16
+ # @return [String] the {Object#to_s} encoded for usage as URI component
17
+ def encode_uri_component
18
+ to_s.encode_uri_component
19
+ end
20
+ end
21
+
22
+ class String
23
+ # Encode as URI component.
24
+ #
25
+ # @return [String] the string encoded for usage as URI component
26
+ def encode_uri_component
27
+ `encodeURIComponent(self)`
28
+ end
29
+
30
+ # Encode as URI.
31
+ #
32
+ # @return [String] the string encoded as URI
33
+ def encode_uri
34
+ `encodeURI(self)`
35
+ end
36
+
37
+ # Decode as URI component.
38
+ #
39
+ # @return [String] the string decoded as URI component
40
+ def decode_uri_component
41
+ `decodeURIComponent(self)`
42
+ end
43
+
44
+ # Decode as URI.
45
+ #
46
+ # @return [String] the string decoded as URI
47
+ def decode_uri
48
+ `decodeURI(self)`
49
+ end
50
+ end
51
+
52
+ class Hash
53
+ # Decode an URL encoded form to a {Hash}.
54
+ #
55
+ # @param string [String] the URL encoded form
56
+ #
57
+ # @return [Hash]
58
+ def self.decode_uri(string)
59
+ self[string.split(?&).map {|part|
60
+ name, value = part.split(?=)
61
+
62
+ [name.decode_uri_component, value.decode_uri_component]
63
+ }]
64
+ end
65
+
66
+ # Encode the Hash to an URL form.
67
+ #
68
+ # @return [String] the URL encoded form
69
+ def encode_uri
70
+ map {|name, value|
71
+ "#{name.to_s.encode_uri_component}=#{value.to_s.encode_uri_component}"
72
+ }.join(?&)
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Browser
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,120 @@
1
+ require 'browser/window/view'
2
+ require 'browser/window/size'
3
+ require 'browser/window/scroll'
4
+
5
+ module Browser
6
+
7
+ # Wrapper class for the `window` object, an instance of it gets
8
+ # set to `$window`.
9
+ class Window
10
+ def self.open(url, options)
11
+ name = options.delete(:name)
12
+ features = options.map {|key, value|
13
+ value = case value
14
+ when true then :yes
15
+ when false then :no
16
+ else value
17
+ end
18
+
19
+ "#{key}=#{value}"
20
+ }.join(?,)
21
+
22
+ %x{
23
+ var win = window.open(#{url}, #{name}, #{features});
24
+
25
+ if (win == null) {
26
+ return nil;
27
+ }
28
+
29
+ return #{new(`win`)};
30
+ }
31
+ end
32
+
33
+ include Native
34
+ include Event::Target
35
+
36
+ target {|value|
37
+ $window if `#{value} == window`
38
+ }
39
+
40
+ # Alert the passed string.
41
+ def alert(value)
42
+ `#@native.alert(value)`
43
+
44
+ value
45
+ end
46
+
47
+ # Display a prompt dialog with the passed string as text.
48
+ def prompt(value)
49
+ `#@native.prompt(value) || nil`
50
+ end
51
+
52
+ # Display a confirmation dialog with the passed string as text.
53
+ def confirm(value)
54
+ `#@native.confirm(value) || false`
55
+ end
56
+
57
+ # Get the {View} for the window.
58
+ #
59
+ # @return [View]
60
+ def view
61
+ View.new(self)
62
+ end
63
+
64
+ # Get the {Size} for this window.
65
+ #
66
+ # @return [Size]
67
+ def size
68
+ Size.new(self)
69
+ end
70
+
71
+ # Get the {Scroll} for this window.
72
+ #
73
+ # @return [Scroll]
74
+ def scroll
75
+ Scroll.new(self)
76
+ end
77
+
78
+ if Browser.supports? 'Window.send'
79
+ def send(message, options = {})
80
+ `#@native.postMessage(#{message}, #{options[:to] || '*'})`
81
+ end
82
+ else
83
+ # Send a message to the window.
84
+ #
85
+ # @param message [String] the message
86
+ # @param options [Hash] optional `to: target`
87
+ def send(message, options = {})
88
+ raise NotImplementedError, 'message sending unsupported'
89
+ end
90
+ end
91
+
92
+ def close
93
+ %x{
94
+ return (window.open('', '_self', '') && window.close()) ||
95
+ (window.opener = null && window.close()) ||
96
+ (window.opener = '' && window.close());
97
+ }
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ $window = Browser::Window.new(`window`)
104
+
105
+ module Kernel
106
+ # (see Browser::Window#alert)
107
+ def alert(value)
108
+ $window.alert(value)
109
+ end
110
+
111
+ # (see Browser::Window#prompt)
112
+ def prompt(value)
113
+ $window.prompt(value)
114
+ end
115
+
116
+ # (see Browser::Window#confirm)
117
+ def confirm(value)
118
+ $window.confirm(value)
119
+ end
120
+ end