annotate public_html/static/js/implab/sticky.js @ 16:e69c970c3ddd default tip

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