unpoly-rails 0.57.0 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +393 -1
  3. data/Gemfile.lock +5 -2
  4. data/README.md +1 -1
  5. data/README_RAILS.md +1 -1
  6. data/Rakefile +10 -1
  7. data/design/es6.js +32 -0
  8. data/design/ie11.txt +9 -0
  9. data/design/measure_jquery/element_list.js +41 -0
  10. data/design/measure_jquery/up.on_vs_addEventListener.js +56 -0
  11. data/design/todo_jquery.txt +13 -0
  12. data/dist/unpoly-bootstrap3.js +8 -8
  13. data/dist/unpoly-bootstrap3.min.js +1 -1
  14. data/dist/unpoly.css +22 -20
  15. data/dist/unpoly.js +6990 -5336
  16. data/dist/unpoly.min.css +1 -1
  17. data/dist/unpoly.min.js +4 -4
  18. data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +5 -0
  19. data/lib/assets/javascripts/unpoly.coffee +8 -6
  20. data/lib/assets/javascripts/unpoly/browser.coffee.erb +23 -118
  21. data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +36 -0
  22. data/lib/assets/javascripts/unpoly/classes/cache.coffee +4 -4
  23. data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +45 -39
  24. data/lib/assets/javascripts/unpoly/classes/config.coffee +9 -0
  25. data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +18 -27
  26. data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +39 -0
  27. data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +116 -0
  28. data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +8 -8
  29. data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +19 -19
  30. data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +54 -31
  31. data/lib/assets/javascripts/unpoly/classes/{focus_tracker.coffee → focus_follower.coffee} +2 -2
  32. data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +25 -25
  33. data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +4 -11
  34. data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +157 -0
  35. data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +525 -0
  36. data/lib/assets/javascripts/unpoly/classes/record.coffee +8 -2
  37. data/lib/assets/javascripts/unpoly/classes/rect.js +21 -0
  38. data/lib/assets/javascripts/unpoly/classes/request.coffee +41 -35
  39. data/lib/assets/javascripts/unpoly/classes/response.coffee +7 -3
  40. data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +102 -0
  41. data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +67 -0
  42. data/lib/assets/javascripts/unpoly/classes/selector.coffee +60 -0
  43. data/lib/assets/javascripts/unpoly/classes/tether.coffee +105 -0
  44. data/lib/assets/javascripts/unpoly/classes/url_set.coffee +12 -7
  45. data/lib/assets/javascripts/unpoly/element.coffee.erb +1126 -0
  46. data/lib/assets/javascripts/unpoly/event.coffee.erb +437 -0
  47. data/lib/assets/javascripts/unpoly/feedback.coffee +73 -94
  48. data/lib/assets/javascripts/unpoly/form.coffee.erb +188 -181
  49. data/lib/assets/javascripts/unpoly/{dom.coffee.erb → fragment.coffee.erb} +250 -283
  50. data/lib/assets/javascripts/unpoly/framework.coffee +67 -0
  51. data/lib/assets/javascripts/unpoly/history.coffee +29 -28
  52. data/lib/assets/javascripts/unpoly/legacy.coffee +60 -0
  53. data/lib/assets/javascripts/unpoly/link.coffee.erb +127 -119
  54. data/lib/assets/javascripts/unpoly/log.coffee +99 -19
  55. data/lib/assets/javascripts/unpoly/modal.coffee.erb +95 -118
  56. data/lib/assets/javascripts/unpoly/motion.coffee.erb +158 -138
  57. data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
  58. data/lib/assets/javascripts/unpoly/popup.coffee.erb +119 -102
  59. data/lib/assets/javascripts/unpoly/protocol.coffee +11 -15
  60. data/lib/assets/javascripts/unpoly/proxy.coffee +62 -65
  61. data/lib/assets/javascripts/unpoly/radio.coffee +3 -5
  62. data/lib/assets/javascripts/unpoly/rails.coffee +8 -9
  63. data/lib/assets/javascripts/unpoly/syntax.coffee.erb +173 -125
  64. data/lib/assets/javascripts/unpoly/toast.coffee +25 -24
  65. data/lib/assets/javascripts/unpoly/tooltip.coffee +89 -79
  66. data/lib/assets/javascripts/unpoly/util.coffee.erb +579 -1074
  67. data/lib/assets/javascripts/unpoly/{layout.coffee.erb → viewport.coffee.erb} +334 -264
  68. data/lib/assets/stylesheets/unpoly/dom.sass +1 -1
  69. data/lib/assets/stylesheets/unpoly/layout.sass +2 -0
  70. data/lib/assets/stylesheets/unpoly/popup.sass +0 -1
  71. data/lib/assets/stylesheets/unpoly/tooltip.sass +17 -12
  72. data/lib/unpoly/rails/version.rb +1 -1
  73. data/package.json +1 -2
  74. data/spec_app/Gemfile +2 -1
  75. data/spec_app/Gemfile.lock +38 -27
  76. data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
  77. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -2
  78. data/spec_app/app/assets/stylesheets/integration_test.sass +14 -1
  79. data/spec_app/app/controllers/scroll_test_controller.rb +5 -0
  80. data/spec_app/app/views/css_test/modal.erb +6 -6
  81. data/spec_app/app/views/css_test/popup.erb +44 -18
  82. data/spec_app/app/views/css_test/tooltip.erb +23 -4
  83. data/spec_app/app/views/error_test/trigger.erb +1 -1
  84. data/spec_app/app/views/form_test/basics/new.erb +1 -3
  85. data/spec_app/app/views/pages/start.erb +9 -2
  86. data/spec_app/app/views/reveal_test/long1.erb +1 -1
  87. data/spec_app/app/views/reveal_test/long2.erb +1 -1
  88. data/spec_app/app/views/reveal_test/within_document_viewport.erb +24 -0
  89. data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +28 -0
  90. data/spec_app/app/views/scroll_test/long1.erb +30 -0
  91. data/spec_app/config/routes.rb +1 -0
  92. data/spec_app/spec/javascripts/helpers/agent_detector.coffee +3 -0
  93. data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +1 -0
  94. data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +17 -5
  95. data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +1 -1
  96. data/spec_app/spec/javascripts/helpers/fixture.js.coffee +25 -0
  97. data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +1 -0
  98. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -0
  99. data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +1 -1
  100. data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +2 -2
  101. data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +4 -1
  102. data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +3 -0
  103. data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +2 -1
  104. data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +2 -2
  105. data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +18 -11
  106. data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +3 -0
  107. data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +3 -0
  108. data/spec_app/spec/javascripts/helpers/spec_util.coffee +47 -0
  109. data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +3 -0
  110. data/spec_app/spec/javascripts/helpers/to_be_array.coffee +5 -0
  111. data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +6 -2
  112. data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +3 -0
  113. data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +6 -2
  114. data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +8 -0
  115. data/spec_app/spec/javascripts/helpers/to_be_error.coffee +3 -0
  116. data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +3 -0
  117. data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +8 -0
  118. data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +3 -0
  119. data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +3 -0
  120. data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +3 -0
  121. data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +9 -0
  122. data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +3 -0
  123. data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +3 -0
  124. data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +1 -2
  125. data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +7 -0
  126. data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +7 -0
  127. data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +10 -0
  128. data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +10 -0
  129. data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +8 -0
  130. data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +7 -3
  131. data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +3 -0
  132. data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +1 -0
  133. data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +9 -0
  134. data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -21
  135. data/spec_app/spec/javascripts/helpers/to_match_list.coffee +14 -0
  136. data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +3 -0
  137. data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +4 -1
  138. data/spec_app/spec/javascripts/helpers/to_match_url.coffee +1 -0
  139. data/spec_app/spec/javascripts/helpers/trigger.js.coffee +91 -7
  140. data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +3 -0
  141. data/spec_app/spec/javascripts/up/browser_spec.js.coffee +23 -90
  142. data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +3 -0
  143. data/spec_app/spec/javascripts/up/classes/config_spec.coffee +24 -0
  144. data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +45 -0
  145. data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +5 -2
  146. data/spec_app/spec/javascripts/up/classes/params_spec.coffee +557 -0
  147. data/spec_app/spec/javascripts/up/classes/request_spec.coffee +7 -4
  148. data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +51 -0
  149. data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +3 -0
  150. data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +3 -2
  151. data/spec_app/spec/javascripts/up/element_spec.coffee +897 -0
  152. data/spec_app/spec/javascripts/up/event_spec.js.coffee +496 -0
  153. data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +69 -48
  154. data/spec_app/spec/javascripts/up/form_spec.js.coffee +252 -194
  155. data/spec_app/spec/javascripts/up/{dom_spec.js.coffee → fragment_spec.js.coffee} +381 -388
  156. data/spec_app/spec/javascripts/up/history_spec.js.coffee +21 -19
  157. data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +4 -0
  158. data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +27 -0
  159. data/spec_app/spec/javascripts/up/link_spec.js.coffee +163 -160
  160. data/spec_app/spec/javascripts/up/log_spec.js.coffee +85 -12
  161. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +141 -123
  162. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +117 -113
  163. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +60 -77
  164. data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +1 -0
  165. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +85 -78
  166. data/spec_app/spec/javascripts/up/radio_spec.js.coffee +29 -22
  167. data/spec_app/spec/javascripts/up/rails_spec.js.coffee +14 -13
  168. data/spec_app/spec/javascripts/up/spec_spec.js.coffee +9 -0
  169. data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +96 -66
  170. data/spec_app/spec/javascripts/up/toast_spec.js.coffee +37 -0
  171. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +31 -47
  172. data/spec_app/spec/javascripts/up/util_spec.js.coffee +725 -562
  173. data/spec_app/spec/javascripts/up/{layout_spec.js.coffee → viewport_spec.js.coffee} +175 -149
  174. metadata +57 -19
  175. data/lib/assets/javascripts/unpoly-bootstrap3/layout-ext.coffee +0 -5
  176. data/lib/assets/javascripts/unpoly/bus.coffee.erb +0 -518
  177. data/lib/assets/javascripts/unpoly/classes/extract_step.coffee +0 -4
  178. data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +0 -125
  179. data/lib/assets/javascripts/unpoly/params.coffee.erb +0 -522
  180. data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +0 -8
  181. data/spec_app/spec/javascripts/up/bus_spec.js.coffee +0 -210
  182. data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +0 -9
  183. data/spec_app/spec/javascripts/up/params_spec.coffee +0 -768
  184. data/spec_app/vendor/asset-libs/jasmine-fixture-1.3.4/jasmine-fixture.js +0 -433
  185. data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/.bower.json +0 -26
  186. data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/jasmine-jquery.js +0 -838
@@ -1,838 +0,0 @@
1
- /*!
2
- Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
3
-
4
- Version 2.1.1
5
-
6
- https://github.com/velesin/jasmine-jquery
7
-
8
- Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining
11
- a copy of this software and associated documentation files (the
12
- "Software"), to deal in the Software without restriction, including
13
- without limitation the rights to use, copy, modify, merge, publish,
14
- distribute, sublicense, and/or sell copies of the Software, and to
15
- permit persons to whom the Software is furnished to do so, subject to
16
- the following conditions:
17
-
18
- The above copyright notice and this permission notice shall be
19
- included in all copies or substantial portions of the Software.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- */
29
-
30
- (function (root, factory) {
31
- if (typeof module !== 'undefined' && module.exports) {
32
- factory(root, root.jasmine, require('jquery'));
33
- } else {
34
- factory(root, root.jasmine, root.jQuery);
35
- }
36
- }((function() {return this; })(), function (window, jasmine, $) { "use strict";
37
-
38
- jasmine.spiedEventsKey = function (selector, eventName) {
39
- return [$(selector).selector, eventName].toString()
40
- }
41
-
42
- jasmine.getFixtures = function () {
43
- return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
44
- }
45
-
46
- jasmine.getStyleFixtures = function () {
47
- return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
48
- }
49
-
50
- jasmine.Fixtures = function () {
51
- this.containerId = 'jasmine-fixtures'
52
- this.fixturesCache_ = {}
53
- this.fixturesPath = 'spec/javascripts/fixtures'
54
- }
55
-
56
- jasmine.Fixtures.prototype.set = function (html) {
57
- this.cleanUp()
58
- return this.createContainer_(html)
59
- }
60
-
61
- jasmine.Fixtures.prototype.appendSet= function (html) {
62
- this.addToContainer_(html)
63
- }
64
-
65
- jasmine.Fixtures.prototype.preload = function () {
66
- this.read.apply(this, arguments)
67
- }
68
-
69
- jasmine.Fixtures.prototype.load = function () {
70
- this.cleanUp()
71
- this.createContainer_(this.read.apply(this, arguments))
72
- }
73
-
74
- jasmine.Fixtures.prototype.appendLoad = function () {
75
- this.addToContainer_(this.read.apply(this, arguments))
76
- }
77
-
78
- jasmine.Fixtures.prototype.read = function () {
79
- var htmlChunks = []
80
- , fixtureUrls = arguments
81
-
82
- for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
83
- htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
84
- }
85
-
86
- return htmlChunks.join('')
87
- }
88
-
89
- jasmine.Fixtures.prototype.clearCache = function () {
90
- this.fixturesCache_ = {}
91
- }
92
-
93
- jasmine.Fixtures.prototype.cleanUp = function () {
94
- $('#' + this.containerId).remove()
95
- }
96
-
97
- jasmine.Fixtures.prototype.sandbox = function (attributes) {
98
- var attributesToSet = attributes || {}
99
- return $('<div id="sandbox" />').attr(attributesToSet)
100
- }
101
-
102
- jasmine.Fixtures.prototype.createContainer_ = function (html) {
103
- var container = $('<div>')
104
- .attr('id', this.containerId)
105
- .html(html)
106
-
107
- $(document.body).append(container)
108
- return container
109
- }
110
-
111
- jasmine.Fixtures.prototype.addToContainer_ = function (html){
112
- var container = $(document.body).find('#'+this.containerId).append(html)
113
-
114
- if (!container.length) {
115
- this.createContainer_(html)
116
- }
117
- }
118
-
119
- jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) {
120
- if (typeof this.fixturesCache_[url] === 'undefined') {
121
- this.loadFixtureIntoCache_(url)
122
- }
123
- return this.fixturesCache_[url]
124
- }
125
-
126
- jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
127
- var self = this
128
- , url = this.makeFixtureUrl_(relativeUrl)
129
- , htmlText = ''
130
- , request = $.ajax({
131
- async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
132
- cache: false,
133
- url: url,
134
- dataType: 'html',
135
- success: function (data, status, $xhr) {
136
- htmlText = $xhr.responseText
137
- }
138
- }).fail(function ($xhr, status, err) {
139
- throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
140
- })
141
-
142
- var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || [];
143
-
144
- scripts.each(function(){
145
- $.ajax({
146
- async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
147
- cache: false,
148
- dataType: 'script',
149
- url: $(this).attr('src'),
150
- success: function (data, status, $xhr) {
151
- htmlText += '<script>' + $xhr.responseText + '</script>'
152
- },
153
- error: function ($xhr, status, err) {
154
- throw new Error('Script could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
155
- }
156
- });
157
- })
158
-
159
- self.fixturesCache_[relativeUrl] = htmlText;
160
- }
161
-
162
- jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
163
- return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
164
- }
165
-
166
- jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
167
- return this[methodName].apply(this, passedArguments)
168
- }
169
-
170
-
171
- jasmine.StyleFixtures = function () {
172
- this.fixturesCache_ = {}
173
- this.fixturesNodes_ = []
174
- this.fixturesPath = 'spec/javascripts/fixtures'
175
- }
176
-
177
- jasmine.StyleFixtures.prototype.set = function (css) {
178
- this.cleanUp()
179
- this.createStyle_(css)
180
- }
181
-
182
- jasmine.StyleFixtures.prototype.appendSet = function (css) {
183
- this.createStyle_(css)
184
- }
185
-
186
- jasmine.StyleFixtures.prototype.preload = function () {
187
- this.read_.apply(this, arguments)
188
- }
189
-
190
- jasmine.StyleFixtures.prototype.load = function () {
191
- this.cleanUp()
192
- this.createStyle_(this.read_.apply(this, arguments))
193
- }
194
-
195
- jasmine.StyleFixtures.prototype.appendLoad = function () {
196
- this.createStyle_(this.read_.apply(this, arguments))
197
- }
198
-
199
- jasmine.StyleFixtures.prototype.cleanUp = function () {
200
- while(this.fixturesNodes_.length) {
201
- this.fixturesNodes_.pop().remove()
202
- }
203
- }
204
-
205
- jasmine.StyleFixtures.prototype.createStyle_ = function (html) {
206
- var styleText = $('<div></div>').html(html).text()
207
- , style = $('<style>' + styleText + '</style>')
208
-
209
- this.fixturesNodes_.push(style)
210
- $('head').append(style)
211
- }
212
-
213
- jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
214
- jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
215
- jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
216
- jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
217
- jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
218
- jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
219
-
220
- jasmine.getJSONFixtures = function () {
221
- return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
222
- }
223
-
224
- jasmine.JSONFixtures = function () {
225
- this.fixturesCache_ = {}
226
- this.fixturesPath = 'spec/javascripts/fixtures/json'
227
- }
228
-
229
- jasmine.JSONFixtures.prototype.load = function () {
230
- this.read.apply(this, arguments)
231
- return this.fixturesCache_
232
- }
233
-
234
- jasmine.JSONFixtures.prototype.read = function () {
235
- var fixtureUrls = arguments
236
-
237
- for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
238
- this.getFixtureData_(fixtureUrls[urlIndex])
239
- }
240
-
241
- return this.fixturesCache_
242
- }
243
-
244
- jasmine.JSONFixtures.prototype.clearCache = function () {
245
- this.fixturesCache_ = {}
246
- }
247
-
248
- jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
249
- if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
250
- return this.fixturesCache_[url]
251
- }
252
-
253
- jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
254
- var self = this
255
- , url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
256
-
257
- $.ajax({
258
- async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
259
- cache: false,
260
- dataType: 'json',
261
- url: url,
262
- success: function (data) {
263
- self.fixturesCache_[relativeUrl] = data
264
- },
265
- error: function ($xhr, status, err) {
266
- throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
267
- }
268
- })
269
- }
270
-
271
- jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
272
- return this[methodName].apply(this, passedArguments)
273
- }
274
-
275
- jasmine.jQuery = function () {}
276
-
277
- jasmine.jQuery.browserTagCaseIndependentHtml = function (html) {
278
- return $('<div/>').append(html).html()
279
- }
280
-
281
- jasmine.jQuery.elementToString = function (element) {
282
- return $(element).map(function () { return this.outerHTML; }).toArray().join(', ')
283
- }
284
-
285
- var data = {
286
- spiedEvents: {}
287
- , handlers: []
288
- }
289
-
290
- jasmine.jQuery.events = {
291
- spyOn: function (selector, eventName) {
292
- var handler = function (e) {
293
- var calls = (typeof data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] !== 'undefined') ? data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0
294
- data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = {
295
- args: jasmine.util.argsToArray(arguments),
296
- calls: ++calls
297
- }
298
- }
299
-
300
- $(selector).on(eventName, handler)
301
- data.handlers.push(handler)
302
-
303
- return {
304
- selector: selector,
305
- eventName: eventName,
306
- handler: handler,
307
- reset: function (){
308
- delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
309
- },
310
- calls: {
311
- count: function () {
312
- return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
313
- data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0;
314
- },
315
- any: function () {
316
- return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
317
- !!data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : false;
318
- }
319
- }
320
- }
321
- },
322
-
323
- args: function (selector, eventName) {
324
- var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].args
325
-
326
- if (!actualArgs) {
327
- throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
328
- }
329
-
330
- return actualArgs
331
- },
332
-
333
- wasTriggered: function (selector, eventName) {
334
- return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
335
- },
336
-
337
- wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) {
338
- var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1)
339
-
340
- if (Object.prototype.toString.call(expectedArgs) !== '[object Array]')
341
- actualArgs = actualArgs[0]
342
-
343
- return util.equals(actualArgs, expectedArgs, customEqualityTesters)
344
- },
345
-
346
- wasPrevented: function (selector, eventName) {
347
- var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
348
- , args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
349
- , e = args ? args[0] : undefined
350
-
351
- return e && e.isDefaultPrevented()
352
- },
353
-
354
- wasStopped: function (selector, eventName) {
355
- var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
356
- , args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
357
- , e = args ? args[0] : undefined
358
-
359
- return e && e.isPropagationStopped()
360
- },
361
-
362
- cleanUp: function () {
363
- data.spiedEvents = {}
364
- data.handlers = []
365
- }
366
- }
367
-
368
- var hasProperty = function (actualValue, expectedValue) {
369
- if (expectedValue === undefined)
370
- return actualValue !== undefined
371
-
372
- return actualValue === expectedValue
373
- }
374
-
375
- beforeEach(function () {
376
- jasmine.addMatchers({
377
- toHaveClass: function () {
378
- return {
379
- compare: function (actual, className) {
380
- return { pass: $(actual).hasClass(className) }
381
- }
382
- }
383
- },
384
-
385
- toHaveCss: function () {
386
- return {
387
- compare: function (actual, css) {
388
- for (var prop in css){
389
- var value = css[prop]
390
- // see issue #147 on gh
391
- ;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue
392
- if ($(actual).css(prop) !== value) return { pass: false }
393
- }
394
- return { pass: true }
395
- }
396
- }
397
- },
398
-
399
- toBeVisible: function () {
400
- return {
401
- compare: function (actual) {
402
- return { pass: $(actual).is(':visible') }
403
- }
404
- }
405
- },
406
-
407
- toBeHidden: function () {
408
- return {
409
- compare: function (actual) {
410
- return { pass: $(actual).is(':hidden') }
411
- }
412
- }
413
- },
414
-
415
- toBeSelected: function () {
416
- return {
417
- compare: function (actual) {
418
- return { pass: $(actual).is(':selected') }
419
- }
420
- }
421
- },
422
-
423
- toBeChecked: function () {
424
- return {
425
- compare: function (actual) {
426
- return { pass: $(actual).is(':checked') }
427
- }
428
- }
429
- },
430
-
431
- toBeEmpty: function () {
432
- return {
433
- compare: function (actual) {
434
- return { pass: $(actual).is(':empty') }
435
- }
436
- }
437
- },
438
-
439
- toBeInDOM: function () {
440
- return {
441
- compare: function (actual) {
442
- return { pass: $.contains(document.documentElement, $(actual)[0]) }
443
- }
444
- }
445
- },
446
-
447
- toExist: function () {
448
- return {
449
- compare: function (actual) {
450
- return { pass: $(actual).length }
451
- }
452
- }
453
- },
454
-
455
- toHaveLength: function () {
456
- return {
457
- compare: function (actual, length) {
458
- return { pass: $(actual).length === length }
459
- }
460
- }
461
- },
462
-
463
- toHaveAttr: function () {
464
- return {
465
- compare: function (actual, attributeName, expectedAttributeValue) {
466
- return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) }
467
- }
468
- }
469
- },
470
-
471
- toHaveProp: function () {
472
- return {
473
- compare: function (actual, propertyName, expectedPropertyValue) {
474
- return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) }
475
- }
476
- }
477
- },
478
-
479
- toHaveId: function () {
480
- return {
481
- compare: function (actual, id) {
482
- return { pass: $(actual).attr('id') == id }
483
- }
484
- }
485
- },
486
-
487
- toHaveHtml: function () {
488
- return {
489
- compare: function (actual, html) {
490
- return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) }
491
- }
492
- }
493
- },
494
-
495
- toContainHtml: function () {
496
- return {
497
- compare: function (actual, html) {
498
- var actualHtml = $(actual).html()
499
- , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html)
500
-
501
- return { pass: (actualHtml.indexOf(expectedHtml) >= 0) }
502
- }
503
- }
504
- },
505
-
506
- toHaveText: function () {
507
- return {
508
- compare: function (actual, text) {
509
- var actualText = $(actual).text()
510
- var trimmedText = $.trim(actualText)
511
-
512
- if (text && $.isFunction(text.test)) {
513
- return { pass: text.test(actualText) || text.test(trimmedText) }
514
- } else {
515
- return { pass: (actualText == text || trimmedText == text) }
516
- }
517
- }
518
- }
519
- },
520
-
521
- toContainText: function () {
522
- return {
523
- compare: function (actual, text) {
524
- var trimmedText = $.trim($(actual).text())
525
-
526
- if (text && $.isFunction(text.test)) {
527
- return { pass: text.test(trimmedText) }
528
- } else {
529
- return { pass: trimmedText.indexOf(text) != -1 }
530
- }
531
- }
532
- }
533
- },
534
-
535
- toHaveValue: function () {
536
- return {
537
- compare: function (actual, value) {
538
- return { pass: $(actual).val() === value }
539
- }
540
- }
541
- },
542
-
543
- toHaveData: function () {
544
- return {
545
- compare: function (actual, key, expectedValue) {
546
- return { pass: hasProperty($(actual).data(key), expectedValue) }
547
- }
548
- }
549
- },
550
-
551
- toContainElement: function () {
552
- return {
553
- compare: function (actual, selector) {
554
- return { pass: $(actual).find(selector).length }
555
- }
556
- }
557
- },
558
-
559
- toBeMatchedBy: function () {
560
- return {
561
- compare: function (actual, selector) {
562
- return { pass: $(actual).filter(selector).length }
563
- }
564
- }
565
- },
566
-
567
- toBeDisabled: function () {
568
- return {
569
- compare: function (actual, selector) {
570
- return { pass: $(actual).is(':disabled') }
571
- }
572
- }
573
- },
574
-
575
- toBeFocused: function (selector) {
576
- return {
577
- compare: function (actual, selector) {
578
- return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement }
579
- }
580
- }
581
- },
582
-
583
- toHandle: function () {
584
- return {
585
- compare: function (actual, event) {
586
- if ( !actual || actual.length === 0 ) return { pass: false };
587
- var events = $._data($(actual).get(0), "events")
588
-
589
- if (!events || !event || typeof event !== "string") {
590
- return { pass: false }
591
- }
592
-
593
- var namespaces = event.split(".")
594
- , eventType = namespaces.shift()
595
- , sortedNamespaces = namespaces.slice(0).sort()
596
- , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
597
-
598
- if (events[eventType] && namespaces.length) {
599
- for (var i = 0; i < events[eventType].length; i++) {
600
- var namespace = events[eventType][i].namespace
601
-
602
- if (namespaceRegExp.test(namespace))
603
- return { pass: true }
604
- }
605
- } else {
606
- return { pass: (events[eventType] && events[eventType].length > 0) }
607
- }
608
-
609
- return { pass: false }
610
- }
611
- }
612
- },
613
-
614
- toHandleWith: function () {
615
- return {
616
- compare: function (actual, eventName, eventHandler) {
617
- if ( !actual || actual.length === 0 ) return { pass: false };
618
- var normalizedEventName = eventName.split('.')[0]
619
- , stack = $._data($(actual).get(0), "events")[normalizedEventName]
620
-
621
- for (var i = 0; i < stack.length; i++) {
622
- if (stack[i].handler == eventHandler) return { pass: true }
623
- }
624
-
625
- return { pass: false }
626
- }
627
- }
628
- },
629
-
630
- toHaveBeenTriggeredOn: function () {
631
- return {
632
- compare: function (actual, selector) {
633
- var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) }
634
-
635
- result.message = result.pass ?
636
- "Expected event " + $(actual) + " not to have been triggered on " + selector :
637
- "Expected event " + $(actual) + " to have been triggered on " + selector
638
-
639
- return result;
640
- }
641
- }
642
- },
643
-
644
- toHaveBeenTriggered: function (){
645
- return {
646
- compare: function (actual) {
647
- var eventName = actual.eventName
648
- , selector = actual.selector
649
- , result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) }
650
-
651
- result.message = result.pass ?
652
- "Expected event " + eventName + " not to have been triggered on " + selector :
653
- "Expected event " + eventName + " to have been triggered on " + selector
654
-
655
- return result
656
- }
657
- }
658
- },
659
-
660
- toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) {
661
- return {
662
- compare: function (actual, selector, expectedArgs) {
663
- var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual)
664
- , result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) }
665
-
666
- if (wasTriggered) {
667
- var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1]
668
- result.message = result.pass ?
669
- "Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) :
670
- "Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
671
-
672
- } else {
673
- // todo check on this
674
- result.message = result.pass ?
675
- "Expected event " + actual + " not to have been triggered on " + selector :
676
- "Expected event " + actual + " to have been triggered on " + selector
677
- }
678
-
679
- return result
680
- }
681
- }
682
- },
683
-
684
- toHaveBeenPreventedOn: function () {
685
- return {
686
- compare: function (actual, selector) {
687
- var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) }
688
-
689
- result.message = result.pass ?
690
- "Expected event " + actual + " not to have been prevented on " + selector :
691
- "Expected event " + actual + " to have been prevented on " + selector
692
-
693
- return result
694
- }
695
- }
696
- },
697
-
698
- toHaveBeenPrevented: function () {
699
- return {
700
- compare: function (actual) {
701
- var eventName = actual.eventName
702
- , selector = actual.selector
703
- , result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) }
704
-
705
- result.message = result.pass ?
706
- "Expected event " + eventName + " not to have been prevented on " + selector :
707
- "Expected event " + eventName + " to have been prevented on " + selector
708
-
709
- return result
710
- }
711
- }
712
- },
713
-
714
- toHaveBeenStoppedOn: function () {
715
- return {
716
- compare: function (actual, selector) {
717
- var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) }
718
-
719
- result.message = result.pass ?
720
- "Expected event " + actual + " not to have been stopped on " + selector :
721
- "Expected event " + actual + " to have been stopped on " + selector
722
-
723
- return result;
724
- }
725
- }
726
- },
727
-
728
- toHaveBeenStopped: function () {
729
- return {
730
- compare: function (actual) {
731
- var eventName = actual.eventName
732
- , selector = actual.selector
733
- , result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) }
734
-
735
- result.message = result.pass ?
736
- "Expected event " + eventName + " not to have been stopped on " + selector :
737
- "Expected event " + eventName + " to have been stopped on " + selector
738
-
739
- return result
740
- }
741
- }
742
- }
743
- })
744
-
745
- jasmine.getEnv().addCustomEqualityTester(function(a, b) {
746
- if (a && b) {
747
- if (a instanceof $ || jasmine.isDomNode(a)) {
748
- var $a = $(a)
749
-
750
- if (b instanceof $)
751
- return $a.length == b.length && a.is(b)
752
-
753
- return $a.is(b);
754
- }
755
-
756
- if (b instanceof $ || jasmine.isDomNode(b)) {
757
- var $b = $(b)
758
-
759
- if (a instanceof $)
760
- return a.length == $b.length && $b.is(a)
761
-
762
- return $(b).is(a);
763
- }
764
- }
765
- })
766
-
767
- jasmine.getEnv().addCustomEqualityTester(function (a, b) {
768
- if (a instanceof $ && b instanceof $ && a.size() == b.size())
769
- return a.is(b)
770
- })
771
- })
772
-
773
- afterEach(function () {
774
- jasmine.getFixtures().cleanUp()
775
- jasmine.getStyleFixtures().cleanUp()
776
- jasmine.jQuery.events.cleanUp()
777
- })
778
-
779
- window.readFixtures = function () {
780
- return jasmine.getFixtures().proxyCallTo_('read', arguments)
781
- }
782
-
783
- window.preloadFixtures = function () {
784
- jasmine.getFixtures().proxyCallTo_('preload', arguments)
785
- }
786
-
787
- window.loadFixtures = function () {
788
- jasmine.getFixtures().proxyCallTo_('load', arguments)
789
- }
790
-
791
- window.appendLoadFixtures = function () {
792
- jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
793
- }
794
-
795
- window.setFixtures = function (html) {
796
- return jasmine.getFixtures().proxyCallTo_('set', arguments)
797
- }
798
-
799
- window.appendSetFixtures = function () {
800
- jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
801
- }
802
-
803
- window.sandbox = function (attributes) {
804
- return jasmine.getFixtures().sandbox(attributes)
805
- }
806
-
807
- window.spyOnEvent = function (selector, eventName) {
808
- return jasmine.jQuery.events.spyOn(selector, eventName)
809
- }
810
-
811
- window.preloadStyleFixtures = function () {
812
- jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
813
- }
814
-
815
- window.loadStyleFixtures = function () {
816
- jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
817
- }
818
-
819
- window.appendLoadStyleFixtures = function () {
820
- jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
821
- }
822
-
823
- window.setStyleFixtures = function (html) {
824
- jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
825
- }
826
-
827
- window.appendSetStyleFixtures = function (html) {
828
- jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
829
- }
830
-
831
- window.loadJSONFixtures = function () {
832
- return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
833
- }
834
-
835
- window.getJSONFixture = function (url) {
836
- return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
837
- }
838
- }));