@@ -24,106 +24,106 @@ provides: [Element.Pin]
24
24
*/
25
25
26
26
( function ( ) {
27
- var supportsPositionFixed = false ,
28
- supportTested = false ;
29
-
30
- var testPositionFixed = function ( ) {
31
- var test = new Element ( 'div' ) . setStyles ( {
32
- position : 'fixed' ,
33
- top : 0 ,
34
- right : 0
35
- } ) . inject ( document . body ) ;
36
- supportsPositionFixed = ( test . offsetTop === 0 ) ;
37
- test . dispose ( ) ;
38
- supportTested = true ;
39
- } ;
40
-
41
- Element . implement ( {
42
-
43
- pin : function ( enable , forceScroll ) {
44
- if ( ! supportTested ) testPositionFixed ( ) ;
45
- if ( this . getStyle ( 'display' ) == 'none' ) return this ;
46
-
47
- var pinnedPosition ,
48
- scroll = window . getScroll ( ) ,
49
- parent ,
50
- scrollFixer ;
51
-
52
- if ( enable !== false ) {
53
- pinnedPosition = this . getPosition ( ) ;
54
- if ( ! this . retrieve ( 'pin:_pinned' ) ) {
55
- var currentPosition = {
56
- top : pinnedPosition . y - scroll . y ,
57
- left : pinnedPosition . x - scroll . x ,
58
- margin : '0px' ,
59
- padding : '0px'
27
+ var supportsPositionFixed = false ,
28
+ supportTested = false ;
29
+
30
+ var testPositionFixed = function ( ) {
31
+ var test = new Element ( 'div' ) . setStyles ( {
32
+ position : 'fixed' ,
33
+ top : 0 ,
34
+ right : 0
35
+ } ) . inject ( document . body ) ;
36
+ supportsPositionFixed = ( test . offsetTop === 0 ) ;
37
+ test . dispose ( ) ;
38
+ supportTested = true ;
39
+ } ;
40
+
41
+ Element . implement ( {
42
+
43
+ pin : function ( enable , forceScroll ) {
44
+ if ( ! supportTested ) testPositionFixed ( ) ;
45
+ if ( this . getStyle ( 'display' ) == 'none' ) return this ;
46
+
47
+ var pinnedPosition ,
48
+ scroll = window . getScroll ( ) ,
49
+ parent ,
50
+ scrollFixer ;
51
+
52
+ if ( enable !== false ) {
53
+ pinnedPosition = this . getPosition ( ) ;
54
+ if ( ! this . retrieve ( 'pin:_pinned' ) ) {
55
+ var currentPosition = {
56
+ top : pinnedPosition . y - scroll . y ,
57
+ left : pinnedPosition . x - scroll . x ,
58
+ margin : '0px' ,
59
+ padding : '0px'
60
+ } ;
61
+
62
+ if ( supportsPositionFixed && ! forceScroll ) {
63
+ this . setStyle ( 'position' , 'fixed' ) . setStyles ( currentPosition ) ;
64
+ } else {
65
+
66
+ parent = this . getOffsetParent ( ) ;
67
+ var position = this . getPosition ( parent ) ,
68
+ styles = this . getStyles ( 'left' , 'top' ) ;
69
+
70
+ if ( parent && styles . left == 'auto' || styles . top == 'auto' ) this . setPosition ( position ) ;
71
+ if ( this . getStyle ( 'position' ) == 'static' ) this . setStyle ( 'position' , 'absolute' ) ;
72
+
73
+ position = {
74
+ x : styles . left . toInt ( ) - scroll . x ,
75
+ y : styles . top . toInt ( ) - scroll . y
60
76
} ;
61
77
62
- if ( supportsPositionFixed && ! forceScroll ) {
63
- this . setStyle ( 'position' , 'fixed' ) . setStyles ( currentPosition ) ;
64
- } else {
65
-
66
- parent = this . getOffsetParent ( ) ;
67
- var position = this . getPosition ( parent ) ,
68
- styles = this . getStyles ( 'left' , 'top' ) ;
69
-
70
- if ( parent && styles . left == 'auto' || styles . top == 'auto' ) this . setPosition ( position ) ;
71
- if ( this . getStyle ( 'position' ) == 'static' ) this . setStyle ( 'position' , 'absolute' ) ;
72
-
73
- position = {
74
- x : styles . left . toInt ( ) - scroll . x ,
75
- y : styles . top . toInt ( ) - scroll . y
76
- } ;
77
-
78
- scrollFixer = function ( ) {
79
- if ( ! this . retrieve ( 'pin:_pinned' ) ) return ;
80
- var scroll = window . getScroll ( ) ;
81
- this . setStyles ( {
82
- left : position . x + scroll . x ,
83
- top : position . y + scroll . y
84
- } ) ;
85
- } . bind ( this ) ;
86
-
87
- this . store ( 'pin:_scrollFixer' , scrollFixer ) ;
88
- window . addEvent ( 'scroll' , scrollFixer ) ;
89
- }
90
- this . store ( 'pin:_pinned' , true ) ;
78
+ scrollFixer = function ( ) {
79
+ if ( ! this . retrieve ( 'pin:_pinned' ) ) return ;
80
+ var scroll = window . getScroll ( ) ;
81
+ this . setStyles ( {
82
+ left : position . x + scroll . x ,
83
+ top : position . y + scroll . y
84
+ } ) ;
85
+ } . bind ( this ) ;
86
+
87
+ this . store ( 'pin:_scrollFixer' , scrollFixer ) ;
88
+ window . addEvent ( 'scroll' , scrollFixer ) ;
91
89
}
90
+ this . store ( 'pin:_pinned' , true ) ;
91
+ }
92
92
93
- } else {
94
- if ( ! this . retrieve ( 'pin:_pinned' ) ) return this ;
93
+ } else {
94
+ if ( ! this . retrieve ( 'pin:_pinned' ) ) return this ;
95
95
96
- parent = this . getParent ( ) ;
97
- var offsetParent = ( parent . getComputedStyle ( 'position' ) != 'static' ? parent : parent . getOffsetParent ( ) ) ;
96
+ parent = this . getParent ( ) ;
97
+ var offsetParent = ( parent . getComputedStyle ( 'position' ) != 'static' ? parent : parent . getOffsetParent ( ) ) ;
98
98
99
- pinnedPosition = this . getPosition ( ) ;
99
+ pinnedPosition = this . getPosition ( ) ;
100
100
101
- this . store ( 'pin:_pinned' , false ) ;
102
- scrollFixer = this . retrieve ( 'pin:_scrollFixer' ) ;
103
- if ( ! scrollFixer ) {
104
- this . setStyles ( {
105
- position : 'absolute' ,
106
- top : pinnedPosition . y + scroll . y ,
107
- left : pinnedPosition . x + scroll . x
108
- } ) ;
109
- } else {
110
- this . store ( 'pin:_scrollFixer' , null ) ;
111
- window . removeEvent ( 'scroll' , scrollFixer ) ;
112
- }
113
- this . removeClass ( 'isPinned' ) ;
101
+ this . store ( 'pin:_pinned' , false ) ;
102
+ scrollFixer = this . retrieve ( 'pin:_scrollFixer' ) ;
103
+ if ( ! scrollFixer ) {
104
+ this . setStyles ( {
105
+ position : 'absolute' ,
106
+ top : pinnedPosition . y + scroll . y ,
107
+ left : pinnedPosition . x + scroll . x
108
+ } ) ;
109
+ } else {
110
+ this . store ( 'pin:_scrollFixer' , null ) ;
111
+ window . removeEvent ( 'scroll' , scrollFixer ) ;
114
112
}
115
- return this ;
116
- } ,
113
+ this . removeClass ( 'isPinned' ) ;
114
+ }
115
+ return this ;
116
+ } ,
117
117
118
- unpin : function ( ) {
119
- return this . pin ( false ) ;
120
- } ,
118
+ unpin : function ( ) {
119
+ return this . pin ( false ) ;
120
+ } ,
121
121
122
- togglePin : function ( ) {
123
- return this . pin ( ! this . retrieve ( 'pin:_pinned' ) ) ;
124
- }
122
+ togglePin : function ( ) {
123
+ return this . pin ( ! this . retrieve ( 'pin:_pinned' ) ) ;
124
+ }
125
125
126
- } ) ;
126
+ } ) ;
127
127
128
128
//<1.2compat>
129
129
Element . alias ( 'togglepin' , 'togglePin' ) ;
0 commit comments