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,23 @@
1
+ module Browser; class Event
2
+
3
+ class PageTransition < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.PageTransition'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def persisted=(value)
10
+ `#@native.persisted = #{value}`
11
+ end
12
+ end
13
+
14
+ if Browser.supports? 'Event.PageTransition'
15
+ def self.construct(name, desc)
16
+ `new PageTransitionEvent(name, desc)`
17
+ end
18
+ end if supported?
19
+
20
+ alias_native :persisted?, :persisted
21
+ end
22
+
23
+ end; end
@@ -0,0 +1,33 @@
1
+ module Browser; class Event
2
+
3
+ class PopState < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.PopState'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def state=(value)
10
+ `#@native.state = #{value}`
11
+ end
12
+ end
13
+
14
+ if Browser.supports? 'Event.constructor'
15
+ def self.construct(name, desc)
16
+ `new PopStateEvent(#{name}, #{desc})`
17
+ end
18
+ elsif Browser.supports? 'Event.create'
19
+ def self.construct(name, desc)
20
+ %x{
21
+ var event = document.createEvent('PopStateEvent');
22
+ event.initPopStateEvent(name, desc.bubbles, desc.cancelable,
23
+ desc.state);
24
+
25
+ return event;
26
+ }
27
+ end
28
+ end if supported?
29
+
30
+ alias_native :state
31
+ end
32
+
33
+ end; end
@@ -0,0 +1,43 @@
1
+ module Browser; class Event
2
+
3
+ class Progress < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.Progress'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def computable=(value)
10
+ `#@native.computableLength = #{value}`
11
+ end
12
+
13
+ def loaded=(value)
14
+ `#@native.loaded = #{value}`
15
+ end
16
+
17
+ def total=(value)
18
+ `#@native.total = #{value}`
19
+ end
20
+ end
21
+
22
+ if Browser.supports? 'Event.constructor'
23
+ def self.construct(name, desc)
24
+ `new ProgressEvent(#{name}, #{desc})`
25
+ end
26
+ elsif Browser.supports? 'Event.create'
27
+ def self.construct(name, desc)
28
+ %x{
29
+ var event = document.createEvent("ProgressEvent");
30
+ event.initProgressEvent(name, desc.bubbles, desc.cancelable,
31
+ desc.computable, desc.loaded, desc.total);
32
+
33
+ return event;
34
+ }
35
+ end
36
+ end if supported?
37
+
38
+ alias_native :computable?, :computableLength
39
+ alias_native :loaded
40
+ alias_native :total
41
+ end
42
+
43
+ end; end
@@ -0,0 +1,15 @@
1
+ module Browser; class Event
2
+
3
+ class Sensor < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.Sensor'
6
+ end
7
+
8
+ if Browser.supports? 'Event.constructor'
9
+ def self.construct(name, desc)
10
+ `new SensorEvent(#{name}, #{desc})`
11
+ end
12
+ end if supported?
13
+ end
14
+
15
+ end; end
@@ -0,0 +1,43 @@
1
+ module Browser; class Event
2
+
3
+ class Storage < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.Storage'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def key=(value)
10
+ `#@native.key = #{value}`
11
+ end
12
+
13
+ def new=(value)
14
+ `#@native.newValue = #{value}`
15
+ end
16
+
17
+ def old=(value)
18
+ `#@native.oldValue = #{value}`
19
+ end
20
+
21
+ def area=(value)
22
+ `#@native.storageArea = #{value}`
23
+ end
24
+
25
+ def url=(value)
26
+ `#@native.url = #{value}`
27
+ end
28
+ end
29
+
30
+ if Browser.supports? 'Event.constructor'
31
+ def self.construct(name, desc)
32
+ `new StorageEvent(#{name}, #{desc})`
33
+ end
34
+ end if supported?
35
+
36
+ alias_native :key
37
+ alias_native :new, :newValue
38
+ alias_native :old, :oldValue
39
+ alias_native :area, :storageArea
40
+ alias_native :url
41
+ end
42
+
43
+ end; end
@@ -0,0 +1,60 @@
1
+ module Browser; class Event
2
+
3
+ class Touch < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.Touch'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def alt!
10
+ `#@native.altKey = true`
11
+ end
12
+
13
+ def ctrl!
14
+ `#@native.ctrlKey = true`
15
+ end
16
+
17
+ def meta!
18
+ `#@native.metaKey = true`
19
+ end
20
+
21
+ def shift!
22
+ `#@native.shiftKey = true`
23
+ end
24
+ end
25
+
26
+ if Browser.supports? 'Event.constructor'
27
+ def self.construct(name, desc)
28
+ `new TouchEvent(#{name}, #{desc})`
29
+ end
30
+ end if supported?
31
+
32
+ alias_native :alt?, :altKey
33
+ alias_native :ctrl?, :ctrlKey
34
+ alias_native :meta?, :metaKey
35
+ alias_native :shift?, :shiftKey
36
+
37
+ # TODO: implement touches and targetTouches
38
+
39
+ def cancel?
40
+ name.downcase == 'touchcancel'
41
+ end
42
+
43
+ def end?
44
+ name.downcase == 'touchend'
45
+ end
46
+
47
+ def leave?
48
+ name.downcase == 'touchleave'
49
+ end
50
+
51
+ def move?
52
+ name.downcase == 'touchmove'
53
+ end
54
+
55
+ def start?
56
+ name.downcase == 'touchstart'
57
+ end
58
+ end
59
+
60
+ end; end
@@ -0,0 +1,38 @@
1
+ module Browser; class Event
2
+
3
+ class UI < Event
4
+ def self.supported?
5
+ Browser.supports? 'Event.UI'
6
+ end
7
+
8
+ class Definition < Definition
9
+ def detail=(value)
10
+ `#@native.detail = #{value}`
11
+ end
12
+
13
+ def view=(value)
14
+ `#@native.view = #{value}`
15
+ end
16
+ end
17
+
18
+ if Browser.supports? 'Event.constructor'
19
+ def self.construct(name, desc)
20
+ `new UIEvent(#{name}, #{desc})`
21
+ end
22
+ elsif Browser.supports? 'Event.create'
23
+ def self.construct(name, desc)
24
+ %x{
25
+ var event = document.createEvent("UIEvent");
26
+ event.initUIEvent(name, desc.bubbles, desc.cancelable,
27
+ desc.view || window, desc.detail || 0);
28
+
29
+ return event;
30
+ }
31
+ end
32
+ end if supported?
33
+
34
+ alias_native :detail
35
+ alias_native :view
36
+ end
37
+
38
+ end; end
@@ -0,0 +1,49 @@
1
+ module Browser; class Event
2
+
3
+ class Wheel < UI
4
+ def self.supported?
5
+ not $$[:WheelEvent].nil?
6
+ end
7
+
8
+ class Definition < Definition
9
+ def x=(value)
10
+ `#@native.deltaX = #{value}`
11
+ end
12
+
13
+ def y=(value)
14
+ `#@native.deltaY = #{value}`
15
+ end
16
+
17
+ def z=(value)
18
+ `#@native.deltaZ = #{value}`
19
+ end
20
+
21
+ def mode=(value)
22
+ value = case value
23
+ when :pixel then `WheelEvent.DOM_DELTA_PIXEL`
24
+ when :line then `WheelEvent.DOM_DELTA_LINE`
25
+ when :page then `WheelEvent.DOM_DELTA_PAGE`
26
+ end
27
+
28
+ `#@native.deltaMode = #{value}`
29
+ end
30
+ end
31
+
32
+ def self.construct(name, desc)
33
+ `new WheelEvent(#{name}, #{desc})`
34
+ end
35
+
36
+ alias_native :x, :deltaX
37
+ alias_native :y, :deltaY
38
+ alias_native :z, :deltaZ
39
+
40
+ def mode
41
+ case `#@native.deltaMode`
42
+ when `WheelEvent.DOM_DELTA_PIXEL` then :pixel
43
+ when `WheelEvent.DOM_DELTA_LINE` then :line
44
+ when `WheelEvent.DOM_DELTA_PAGE` then :page
45
+ end
46
+ end
47
+ end
48
+
49
+ end; end
@@ -0,0 +1,70 @@
1
+ module Browser
2
+
3
+ # An {EventSource} allows you to receive events from a server in real-time,
4
+ # similar to long-polling but not exactly.
5
+ #
6
+ # @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource
7
+ class EventSource
8
+ def self.supported?
9
+ Browser.supports? :EventSource
10
+ end
11
+
12
+ include Native
13
+ include Event::Target
14
+
15
+ target {|value|
16
+ EventSource.new(value) if Native.is_a?(value, `window.EventSource`)
17
+ }
18
+
19
+ # Create an {EventSource} on the given path.
20
+ #
21
+ # @param path [String] the path to use as source
22
+ # @yield if the block has no parameters it's instance_exec'd, otherwise it's
23
+ # called with self
24
+ def initialize(path, &block)
25
+ if native?(path)
26
+ super(path)
27
+ else
28
+ super(`new window.EventSource(path)`)
29
+ end
30
+
31
+ if block.arity == 0
32
+ instance_exec(&block)
33
+ else
34
+ block.call(self)
35
+ end if block
36
+ end
37
+
38
+ # @!attribute [r] url
39
+ # @return [String] the URL of the event source
40
+ alias_native :url
41
+
42
+ # @!attribute [r] state
43
+ # @return [:connecting, :open, :closed] the state of the event source
44
+ def state
45
+ %x{
46
+ switch (#@native.readyState) {
47
+ case window.EventSource.CONNECTING:
48
+ return "connecting";
49
+
50
+ case window.EventSource.OPEN:
51
+ return "open";
52
+
53
+ case window.EventSource.CLOSED:
54
+ return "closed";
55
+ }
56
+ }
57
+ end
58
+
59
+ # Check if the event source is alive.
60
+ def alive?
61
+ state == :open
62
+ end
63
+
64
+ # Close the event source.
65
+ def close
66
+ `#@native.close()`
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,90 @@
1
+ require 'browser/location'
2
+
3
+ module Browser
4
+
5
+ # {History} allows manipulation of the session history.
6
+ #
7
+ # @see https://developer.mozilla.org/en-US/docs/Web/API/History
8
+ class History
9
+ # Check if HTML5 history is supported.
10
+ def self.supported?
11
+ Browser.supports? 'History'
12
+ end
13
+
14
+ include Native
15
+
16
+ # @!attribute [r] length
17
+ # @return [Integer] how many items are in the history
18
+ alias_native :length
19
+
20
+ # Go back in the history.
21
+ #
22
+ # @param number [Integer] how many items to go back
23
+ def back(number = 1)
24
+ `#@native.go(-number)`
25
+ end
26
+
27
+ # Go forward in the history.
28
+ #
29
+ # @param number [Integer] how many items to go forward
30
+ def forward(number = 1)
31
+ `#@native.go(number)`
32
+ end
33
+
34
+ # Push an item in the history.
35
+ #
36
+ # @param item [String] the item to push in the history
37
+ # @param data [Object] additional state to push
38
+ def push(item, data = nil)
39
+ data = `null` if data.nil?
40
+
41
+ `#@native.pushState(data, null, item)`
42
+ end
43
+
44
+ # Replace the current history item with another.
45
+ #
46
+ # @param item [String] the item to replace with
47
+ # @param data [Object] additional state to replace
48
+ def replace(item, data = nil)
49
+ data = `null` if data.nil?
50
+
51
+ `#@native.replaceState(data, null, item)`
52
+ end
53
+
54
+ # @!attribute [r] current
55
+ # @return [String] the current item
56
+ def current
57
+ $window.location.path
58
+ end
59
+
60
+ # @!attribute [r] state
61
+ # @return [Object] the current state
62
+ if Browser.supports? 'History.state'
63
+ def state
64
+ %x{
65
+ var state = #@native.state;
66
+
67
+ if (state == null) {
68
+ return nil;
69
+ }
70
+ else {
71
+ return state;
72
+ }
73
+ }
74
+ end
75
+ else
76
+ def state
77
+ raise NotImplementedError, 'history state unsupported'
78
+ end
79
+ end
80
+ end
81
+
82
+ class Window
83
+ # @!attribute [r] history
84
+ # @return [History] the history for this window
85
+ def history
86
+ History.new(`#@native.history`) if `#@native.history`
87
+ end
88
+ end
89
+
90
+ end