6
|
1 define([ 'dojo/on', 'dojo/dom-geometry', 'dojo/dom-style' ], function(on, g,
|
|
2 css) {
|
|
3
|
12
|
4 /**
|
|
5 * @param [Dom|string]
|
|
6 * stiker element to become a sticker
|
|
7 */
|
6
|
8 return function(sticker, options) {
|
|
9 var dh, pos;
|
|
10
|
12
|
11 var pos = g.position(sticker, true);
|
|
12 var clientWidth = g.position(document.body).w;
|
|
13 var stickRight = options ? options.stick == 'right' : false;
|
6
|
14
|
12
|
15 var origPos = css.get(sticker, stickRight ? 'right' : 'left');
|
|
16
|
|
17 var fixPos = (stickRight ? clientWidth - pos.w - pos.x : pos.x) + 'px';
|
6
|
18
|
12
|
19 var dhcalc = function() {
|
|
20 if (options && options.along) {
|
|
21 var along = g.position(options.along, true);
|
|
22 dh = along.y + along.h - pos.h - pos.y;
|
|
23 if (options.alongContent)
|
|
24 // respect bottom padding and border
|
|
25 dh -= g.getPadExtents(options.along).t
|
|
26 + g.getBorderExtents(options.along).t;
|
|
27 } else {
|
|
28 dh = window.scrollMaxY - pos.h - pos.y;
|
|
29 }
|
|
30 };
|
6
|
31
|
|
32 var fixed = false;
|
12
|
33
|
6
|
34 var stfn = function() {
|
12
|
35 if (!options || !options.along)
|
6
|
36 dh = window.scrollMaxY - pos.h - pos.y;
|
|
37
|
|
38 if (window.scrollY >= pos.y && window.scrollY <= pos.y + dh) {
|
|
39 if (!fixed) {
|
12
|
40 if (stickRight)
|
|
41 css.set(sticker, {
|
|
42 top : 0,
|
|
43 right : fixPos,
|
|
44 position : 'fixed'
|
|
45 });
|
|
46 else
|
|
47 css.set(sticker, {
|
|
48 top : 0,
|
|
49 left : fixPos,
|
|
50 position : 'fixed'
|
|
51 });
|
6
|
52 fixed = true;
|
|
53 }
|
|
54 } else {
|
|
55 if (fixed) {
|
|
56 fixed = false;
|
12
|
57
|
|
58 if (stickRight)
|
|
59 css.set(sticker, {
|
|
60 position : 'relative',
|
|
61 right : origPos
|
|
62 });
|
|
63 else
|
|
64 css.set(sticker, {
|
|
65 position : 'relative',
|
|
66 left : origPos
|
|
67 });
|
6
|
68
|
|
69 if (window.scrollY < pos.y) {
|
12
|
70 css.set(sticker, {
|
|
71 top : 'auto'
|
|
72 });
|
6
|
73 } else {
|
12
|
74 css.set(sticker, {
|
|
75 top : dh + 'px'
|
|
76 });
|
6
|
77 }
|
|
78 }
|
|
79 }
|
|
80 };
|
12
|
81
|
|
82 dhcalc();
|
6
|
83 stfn();
|
|
84
|
12
|
85 on(window, 'scroll', stfn);
|
|
86 on(window, 'resize', dhcalc);
|
6
|
87 };
|
|
88 }); |