upjs-rails 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/dist/up-bootstrap.js +13 -0
- data/dist/up-bootstrap.min.js +1 -1
- data/dist/up.js +342 -108
- data/dist/up.min.js +2 -2
- data/lib/assets/javascripts/up-bootstrap/layout-ext.js.coffee +5 -0
- data/lib/assets/javascripts/up-bootstrap/modal-ext.js.coffee +0 -5
- data/lib/assets/javascripts/up-bootstrap/navigation-ext.js.coffee +4 -0
- data/lib/assets/javascripts/up.js.coffee +1 -1
- data/lib/assets/javascripts/up/flow.js.coffee +54 -40
- data/lib/assets/javascripts/up/layout.js.coffee +330 -0
- data/lib/assets/javascripts/up/link.js.coffee +6 -3
- data/lib/assets/javascripts/up/modal.js.coffee +21 -12
- data/lib/assets/javascripts/up/util.js.coffee +35 -9
- data/lib/upjs/rails/version.rb +1 -1
- data/spec_app/spec/javascripts/up/flow_spec.js.coffee +47 -3
- data/spec_app/spec/javascripts/up/layout_spec.js.coffee +240 -0
- data/spec_app/spec/javascripts/up/navigation_spec.js.coffee +0 -1
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +6 -0
- metadata +6 -4
- data/lib/assets/javascripts/up/viewport.js.coffee +0 -174
- data/spec_app/spec/javascripts/up/viewport_spec.js.coffee +0 -122
@@ -102,7 +102,6 @@ describe 'up.navigation', ->
|
|
102
102
|
it 'prefers to mark an enclosing [up-expand] click area', ->
|
103
103
|
$area = affix('div[up-expand] a[href="/foo"][up-target=".main"]')
|
104
104
|
up.ready($area)
|
105
|
-
console.log($area)
|
106
105
|
$link = $area.find('a')
|
107
106
|
affix('.main')
|
108
107
|
$link.click()
|
@@ -72,6 +72,12 @@ describe 'up.util', ->
|
|
72
72
|
expect(object.b).toBe(2)
|
73
73
|
expect(object.c).toBe(3)
|
74
74
|
|
75
|
+
it 'returns the current hash when called without arguments', ->
|
76
|
+
object = up.util.config(a: 1, b: 2)
|
77
|
+
result = object.update()
|
78
|
+
expect(result.a).toBe(1)
|
79
|
+
expect(result.b).toBe(2)
|
80
|
+
|
75
81
|
it 'throws an error when setting a key that was not included in the factory settings', ->
|
76
82
|
object = up.util.config(a: 1)
|
77
83
|
update = -> object.update(b: 2)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,13 +85,16 @@ files:
|
|
85
85
|
- dist/up.min.css
|
86
86
|
- dist/up.min.js
|
87
87
|
- lib/assets/javascripts/up-bootstrap.js.coffee
|
88
|
+
- lib/assets/javascripts/up-bootstrap/layout-ext.js.coffee
|
88
89
|
- lib/assets/javascripts/up-bootstrap/modal-ext.js.coffee
|
90
|
+
- lib/assets/javascripts/up-bootstrap/navigation-ext.js.coffee
|
89
91
|
- lib/assets/javascripts/up.js.coffee
|
90
92
|
- lib/assets/javascripts/up/browser.js.coffee
|
91
93
|
- lib/assets/javascripts/up/bus.js.coffee
|
92
94
|
- lib/assets/javascripts/up/flow.js.coffee
|
93
95
|
- lib/assets/javascripts/up/form.js.coffee
|
94
96
|
- lib/assets/javascripts/up/history.js.coffee
|
97
|
+
- lib/assets/javascripts/up/layout.js.coffee
|
95
98
|
- lib/assets/javascripts/up/link.js.coffee
|
96
99
|
- lib/assets/javascripts/up/magic.js.coffee
|
97
100
|
- lib/assets/javascripts/up/modal.js.coffee
|
@@ -103,7 +106,6 @@ files:
|
|
103
106
|
- lib/assets/javascripts/up/slot.js.coffee
|
104
107
|
- lib/assets/javascripts/up/tooltip.js.coffee
|
105
108
|
- lib/assets/javascripts/up/util.js.coffee
|
106
|
-
- lib/assets/javascripts/up/viewport.js.coffee
|
107
109
|
- lib/assets/stylesheets/up-bootstrap.css.sass
|
108
110
|
- lib/assets/stylesheets/up-bootstrap/modal-ext.css.sass
|
109
111
|
- lib/assets/stylesheets/up.css.sass
|
@@ -210,6 +212,7 @@ files:
|
|
210
212
|
- spec_app/spec/javascripts/up/flow_spec.js.coffee
|
211
213
|
- spec_app/spec/javascripts/up/form_spec.js.coffee
|
212
214
|
- spec_app/spec/javascripts/up/history_spec.js.coffee
|
215
|
+
- spec_app/spec/javascripts/up/layout_spec.js.coffee
|
213
216
|
- spec_app/spec/javascripts/up/link_spec.js.coffee
|
214
217
|
- spec_app/spec/javascripts/up/magic_spec.js.coffee
|
215
218
|
- spec_app/spec/javascripts/up/modal_spec.js.coffee
|
@@ -220,7 +223,6 @@ files:
|
|
220
223
|
- spec_app/spec/javascripts/up/slot_spec.js.coffee
|
221
224
|
- spec_app/spec/javascripts/up/tooltip_spec.js.coffee
|
222
225
|
- spec_app/spec/javascripts/up/util_spec.js.coffee
|
223
|
-
- spec_app/spec/javascripts/up/viewport_spec.js.coffee
|
224
226
|
- spec_app/test/controllers/.keep
|
225
227
|
- spec_app/test/fixtures/.keep
|
226
228
|
- spec_app/test/helpers/.keep
|
@@ -1,174 +0,0 @@
|
|
1
|
-
###*
|
2
|
-
Viewport scrolling
|
3
|
-
==================
|
4
|
-
|
5
|
-
This modules contains functions to scroll the viewport and reveal contained elements.
|
6
|
-
|
7
|
-
By default Up.js will always scroll to an element before updating it.
|
8
|
-
|
9
|
-
The container that will be scrolled is the closest parent of the element that is either:
|
10
|
-
|
11
|
-
- The currently open [modal](/up.modal)
|
12
|
-
- An element with the attribute `[up-viewport]`
|
13
|
-
- The `<body>` element
|
14
|
-
- An element matching the selector you have configured using `up.viewport.defaults({ viewSelector: 'my-custom-selector' })`.
|
15
|
-
|
16
|
-
@class up.viewport
|
17
|
-
###
|
18
|
-
up.viewport = (->
|
19
|
-
|
20
|
-
u = up.util
|
21
|
-
|
22
|
-
###*
|
23
|
-
@method up.viewport.defaults
|
24
|
-
@param {Number} [options.duration]
|
25
|
-
@param {String} [options.easing]
|
26
|
-
@param {String} [options.viewSelector]
|
27
|
-
###
|
28
|
-
config = u.config
|
29
|
-
duration: 0
|
30
|
-
viewSelector: 'body, .up-modal, [up-viewport]'
|
31
|
-
easing: 'swing'
|
32
|
-
|
33
|
-
reset = ->
|
34
|
-
config.reset()
|
35
|
-
|
36
|
-
SCROLL_PROMISE_KEY = 'up-scroll-promise'
|
37
|
-
|
38
|
-
###*
|
39
|
-
@method up.scroll
|
40
|
-
@param {String|Element|jQuery} viewOrSelector
|
41
|
-
@param {Number} scrollPos
|
42
|
-
@param {String}[options.duration]
|
43
|
-
@param {String}[options.easing]
|
44
|
-
@return {Deferred}
|
45
|
-
@protected
|
46
|
-
###
|
47
|
-
scroll = (viewOrSelector, scrollTop, options) ->
|
48
|
-
$view = $(viewOrSelector)
|
49
|
-
options = u.options(options)
|
50
|
-
duration = u.option(options.duration, config.duration)
|
51
|
-
easing = u.option(options.easing, config.easing)
|
52
|
-
|
53
|
-
finishScrolling($view)
|
54
|
-
|
55
|
-
if duration > 0
|
56
|
-
deferred = $.Deferred()
|
57
|
-
|
58
|
-
$view.data(SCROLL_PROMISE_KEY, deferred)
|
59
|
-
deferred.then ->
|
60
|
-
$view.removeData(SCROLL_PROMISE_KEY)
|
61
|
-
# Since we're scrolling using #animate, #finish can be
|
62
|
-
# used to jump to the last frame:
|
63
|
-
# https://api.jquery.com/finish/
|
64
|
-
$view.finish()
|
65
|
-
|
66
|
-
targetProps =
|
67
|
-
scrollTop: scrollTop
|
68
|
-
|
69
|
-
$view.animate targetProps,
|
70
|
-
duration: duration,
|
71
|
-
easing: easing,
|
72
|
-
complete: -> deferred.resolve()
|
73
|
-
|
74
|
-
deferred
|
75
|
-
else
|
76
|
-
$view.scrollTop(scrollTop)
|
77
|
-
u.resolvedDeferred()
|
78
|
-
|
79
|
-
###*
|
80
|
-
@method up.viewport.finishScrolling
|
81
|
-
@private
|
82
|
-
###
|
83
|
-
finishScrolling = (elementOrSelector) ->
|
84
|
-
$(elementOrSelector).each ->
|
85
|
-
if existingScrolling = $(this).data(SCROLL_PROMISE_KEY)
|
86
|
-
existingScrolling.resolve()
|
87
|
-
|
88
|
-
###*
|
89
|
-
@method up.reveal
|
90
|
-
@param {String|Element|jQuery} element
|
91
|
-
@param {String|Element|jQuery} [options.view]
|
92
|
-
@param {Number} [options.duration]
|
93
|
-
@param {String} [options.easing]
|
94
|
-
@return {Deferred}
|
95
|
-
@protected
|
96
|
-
###
|
97
|
-
reveal = (elementOrSelector, options) ->
|
98
|
-
|
99
|
-
options = u.options(options)
|
100
|
-
|
101
|
-
$element = $(elementOrSelector)
|
102
|
-
$view = findView($element, options.view)
|
103
|
-
viewIsBody = $view.is('body')
|
104
|
-
|
105
|
-
viewHeight = if viewIsBody then u.clientSize().height else $view.height()
|
106
|
-
|
107
|
-
originalScrollPos = $view.scrollTop()
|
108
|
-
newScrollPos = originalScrollPos
|
109
|
-
|
110
|
-
# When the scrolled element is not <body> but instead a container
|
111
|
-
# with overflow-y: scroll, $.position returns the position the
|
112
|
-
# the first row of the client area instead of the first row of
|
113
|
-
# the canvas buffer.
|
114
|
-
# http://codepen.io/anon/pen/jPojGE
|
115
|
-
offsetShift = if viewIsBody then 0 else originalScrollPos
|
116
|
-
|
117
|
-
firstVisibleRow = -> newScrollPos
|
118
|
-
lastVisibleRow = -> newScrollPos + viewHeight - 1
|
119
|
-
|
120
|
-
elementDims = u.measure($element, relative: true)
|
121
|
-
firstElementRow = elementDims.top + offsetShift
|
122
|
-
lastElementRow = firstElementRow + elementDims.height - 1
|
123
|
-
|
124
|
-
if lastElementRow > lastVisibleRow()
|
125
|
-
# Try to show the full height of the element
|
126
|
-
newScrollPos += (lastElementRow - lastVisibleRow())
|
127
|
-
|
128
|
-
if firstElementRow < firstVisibleRow()
|
129
|
-
# If the full element does not fit, scroll to the first row
|
130
|
-
newScrollPos = firstElementRow
|
131
|
-
|
132
|
-
if newScrollPos != originalScrollPos
|
133
|
-
scroll($view, newScrollPos, options)
|
134
|
-
else
|
135
|
-
u.resolvedDeferred()
|
136
|
-
|
137
|
-
###*
|
138
|
-
@private
|
139
|
-
@method up.viewport.findView
|
140
|
-
###
|
141
|
-
findView = ($element, viewSelectorOrElement) ->
|
142
|
-
$view = undefined
|
143
|
-
# If someone has handed as a jQuery element, that's the
|
144
|
-
# view period.
|
145
|
-
if u.isJQuery(viewSelectorOrElement)
|
146
|
-
$view = viewSelectorOrElement
|
147
|
-
else
|
148
|
-
# If we have been given
|
149
|
-
viewSelector = u.presence(viewSelectorOrElement) || config.viewSelector
|
150
|
-
$view = $element.closest(viewSelector)
|
151
|
-
|
152
|
-
$view.length or u.error("Could not find view to scroll for %o (tried selectors %o)", $element, viewSelectors)
|
153
|
-
$view
|
154
|
-
|
155
|
-
|
156
|
-
###*
|
157
|
-
Marks this element as a scrolling container.
|
158
|
-
Use this e.g. if your app uses a custom panel layout with fixed positioning
|
159
|
-
instead of scrolling `<body>`.
|
160
|
-
|
161
|
-
@method [up-viewport]
|
162
|
-
###
|
163
|
-
|
164
|
-
up.bus.on 'framework:reset', reset
|
165
|
-
|
166
|
-
reveal: reveal
|
167
|
-
scroll: scroll
|
168
|
-
finishScrolling: finishScrolling
|
169
|
-
defaults: config.update
|
170
|
-
|
171
|
-
)()
|
172
|
-
|
173
|
-
up.scroll = up.viewport.scroll
|
174
|
-
up.reveal = up.viewport.reveal
|
@@ -1,122 +0,0 @@
|
|
1
|
-
describe 'up.viewport', ->
|
2
|
-
|
3
|
-
u = up.util
|
4
|
-
|
5
|
-
describe 'Javascript functions', ->
|
6
|
-
|
7
|
-
describe 'up.reveal', ->
|
8
|
-
|
9
|
-
describe 'when the container is body', ->
|
10
|
-
|
11
|
-
beforeEach ->
|
12
|
-
@restoreMargin = u.temporaryCss($('body'), 'margin-top': 0)
|
13
|
-
|
14
|
-
afterEach ->
|
15
|
-
@$container.remove()
|
16
|
-
@restoreMargin()
|
17
|
-
|
18
|
-
it 'reveals the given element', ->
|
19
|
-
$view = $('body')
|
20
|
-
$view.scrollTop(0)
|
21
|
-
$elements = []
|
22
|
-
@$container = $('<div class="container">').prependTo($view)
|
23
|
-
|
24
|
-
for i in [0..2]
|
25
|
-
$element = $('<div>').css(height: '5000px').text("Child #{i}")
|
26
|
-
$element.appendTo(@$container)
|
27
|
-
$elements.push($element)
|
28
|
-
|
29
|
-
# --------------
|
30
|
-
# [0] 00000..04999
|
31
|
-
# --------------
|
32
|
-
# [1] 05000..09999
|
33
|
-
# [3] 10000..14999
|
34
|
-
expect($view.scrollTop()).toBe(0)
|
35
|
-
|
36
|
-
up.reveal($elements[1], view: $view)
|
37
|
-
# [0] 00000..04999
|
38
|
-
# --------------
|
39
|
-
# [1] 05000..09999
|
40
|
-
# --------------
|
41
|
-
# [3] 10000..14999
|
42
|
-
expect($view.scrollTop()).toBe(5000)
|
43
|
-
|
44
|
-
up.reveal($elements[2], view: $view)
|
45
|
-
# [0] 00000..04999
|
46
|
-
# [1] 05000..09999
|
47
|
-
# --------------
|
48
|
-
# [3] 10000..14999
|
49
|
-
# --------------
|
50
|
-
expect($view.scrollTop()).toBe(10000)
|
51
|
-
|
52
|
-
describe 'when the view is a container with overflow-y: scroll', ->
|
53
|
-
|
54
|
-
it 'reveals the given element', ->
|
55
|
-
$view = affix('div').css
|
56
|
-
'position': 'absolute'
|
57
|
-
'width': '100px'
|
58
|
-
'height': '100px'
|
59
|
-
'overflow-y': 'scroll'
|
60
|
-
$elements = []
|
61
|
-
u.each [0..5], ->
|
62
|
-
$element = $('<div>').css(height: '50px')
|
63
|
-
$element.appendTo($view)
|
64
|
-
$elements.push($element)
|
65
|
-
|
66
|
-
# --------------
|
67
|
-
# [0] 000..049
|
68
|
-
# [1] 050..099
|
69
|
-
# --------------
|
70
|
-
# [2] 100..149
|
71
|
-
# [3] 150..199
|
72
|
-
# [4] 200..249
|
73
|
-
# [5] 250..399
|
74
|
-
expect($view.scrollTop()).toBe(0)
|
75
|
-
|
76
|
-
# See that the view only scrolls down as little as possible
|
77
|
-
# in order to reveal the element
|
78
|
-
up.reveal($elements[3], view: $view)
|
79
|
-
# [0] 000..049
|
80
|
-
# [1] 050..099
|
81
|
-
# --------------
|
82
|
-
# [2] 100..149
|
83
|
-
# [3] 150..199
|
84
|
-
# --------------
|
85
|
-
# [4] 200..249
|
86
|
-
# [5] 250..399
|
87
|
-
expect($view.scrollTop()).toBe(100)
|
88
|
-
|
89
|
-
# See that the view doesn't move if the element
|
90
|
-
# is already revealed
|
91
|
-
up.reveal($elements[2], view: $view)
|
92
|
-
expect($view.scrollTop()).toBe(100)
|
93
|
-
|
94
|
-
# See that the view scrolls as far down as it cans
|
95
|
-
# to show the bottom element
|
96
|
-
up.reveal($elements[5], view: $view)
|
97
|
-
# [0] 000..049
|
98
|
-
# [1] 050..099
|
99
|
-
# [2] 100..149
|
100
|
-
# [3] 150..199
|
101
|
-
# --------------
|
102
|
-
# [4] 200..249
|
103
|
-
# [5] 250..399
|
104
|
-
# --------------
|
105
|
-
expect($view.scrollTop()).toBe(200)
|
106
|
-
|
107
|
-
# See that the view only scrolls up as little as possible
|
108
|
-
# in order to reveal the element
|
109
|
-
up.reveal($elements[1], view: $view)
|
110
|
-
# [0] 000..049
|
111
|
-
# --------------
|
112
|
-
# [1] 050..099
|
113
|
-
# [2] 100..149
|
114
|
-
# --------------
|
115
|
-
# [3] 150..199
|
116
|
-
# [4] 200..249
|
117
|
-
# [5] 250..399
|
118
|
-
expect($view.scrollTop()).toBe(50)
|
119
|
-
|
120
|
-
describe 'up.scroll', ->
|
121
|
-
|
122
|
-
it 'should have tests'
|