- commit
- a9cdc3ba73a39416ccc1f7dbd6b04c7b0e4430ac
- parent
- 1279d6917f019d7e1584bda0e3aa9ddd1e020f67
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-01-02 23:05
refactor
Diffstat
| M | jquery.sticky-kit.coffee | 38 | +++++++++++++++++--------------------- |
1 files changed, 17 insertions, 21 deletions
diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee
@@ -54,11 +54,9 @@ $.fn.stick_in_parent = (opts={}) ->
54 54
55 55 _top = 0
56 56
57 -1 elm.css("position", "relative")
58 -1
59 -1 tick = ->
60 -1 return if detached
-1 57 elm.css "position", "relative"
61 58
-1 59 get_max = ->
62 60 # | +--------------+
63 61 # | | border |
64 62 # original | +--------------+
@@ -84,32 +82,34 @@ $.fn.stick_in_parent = (opts={}) ->
84 82 # | border |
85 83 # +--------------+
86 84
87 -1 fixed_old = fixed
88 -1 bottomed_old = bottomed
89 -1
90 85 padding_bottom = parseInt parent.css("padding-bottom"), 10
91 86 border_bottom = parseInt parent.css("border-bottom-width"), 10
92 -1
93 87 margin_top = parseInt elm.css("margin-top"), 10
94 88
-1 89 return parent.outerHeight() - (elm.outerHeight(true) - margin_top) - padding_bottom - border_bottom
-1 90
-1 91 tick = ->
-1 92 return if detached
-1 93
-1 94 fixed_old = fixed
-1 95 bottomed_old = bottomed
-1 96
-1 97 margin_top = parseInt elm.css("margin-top"), 10
95 98 original_top = top(elm, parent) - _top
96 99
97 -1 _top = top(scrollable, parent) + offset_top + margin_top - original_top
-1 100 _top = top(scrollable, parent) + offset_top + margin_top
98 101 if enable_bottoming
99 -1 old = _top
100 -1 _top = Math.min(_top, parent.outerHeight() - original_top - elm.outerHeight(true) + margin_top - padding_bottom - border_bottom)
101 -1 bottomed = _top != old
102 -1 _top = Math.max(_top, 0)
-1 102 max = get_max()
-1 103 _top = max if bottomed = _top >= max
-1 104 _top = Math.max(_top - original_top, 0)
103 105
104 -1 fixed = _top != 0
-1 106 elm.css "top", _top
105 107
106 -1 if fixed
-1 108 if (fixed = _top != 0)
107 109 elm.addClass(sticky_class)
108 110 else
109 111 elm.removeClass(sticky_class)
110 112
111 -1 elm.css("top", _top)
112 -1
113 113 # trigger events
114 114 if !fixed && fixed_old
115 115 elm.trigger("sticky_kit:unstick")
@@ -137,16 +137,12 @@ $.fn.stick_in_parent = (opts={}) ->
137 137
138 138 elm.css {
139 139 position: ""
140 -1 bottom: ""
141 140 top: ""
142 141 }
143 142
144 -1 parent.css "position", ""
145 -1
146 143 if fixed
147 144 elm.removeClass sticky_class
148 145
149 -1 parent.css "position", "relative"
150 146 win.on "touchmove", tick
151 147 win.on "scroll", tick
152 148 win.on "resize", tick