7
7
else if ( typeof define == 'function' && typeof define . amd == 'object' ) define ( definition ) ;
8
8
else root [ 'Multiple' ] = definition ( ) ;
9
9
} ( this , function ( ) {
10
- "use strict"
10
+ "use strict"
11
11
12
- // http://stackoverflow.com/a/4819886/1221082
13
- var isMobile = 'ontouchstart' in window || navigator . maxTouchPoints ;
14
- // http://stackoverflow.com/a/12625907/1221082
15
- var isWebkit = 'WebkitAppearance' in document . documentElement . style ;
12
+ // http://stackoverflow.com/a/4819886/1221082
13
+ var isMobile = 'ontouchstart' in window || navigator . maxTouchPoints ;
14
+ // http://stackoverflow.com/a/12625907/1221082
15
+ var isWebkit = 'WebkitAppearance' in document . documentElement . style ;
16
16
17
- // Force webkit repaint on resize
18
- isWebkit && window . addEventListener ( 'resize' , function ( e ) {
19
- document . body . style . visibility = 'hidden' ;
20
- e = document . body . offsetHeight ;
21
- document . body . style . visibility = '' ;
22
- } ) ;
17
+ // Force webkit repaint on resize
18
+ isWebkit && window . addEventListener ( 'resize' , function ( e ) {
19
+ document . body . style . visibility = 'hidden' ;
20
+ e = document . body . offsetHeight ;
21
+ document . body . style . visibility = '' ;
22
+ } ) ;
23
23
24
- var Multiple = function ( options ) {
25
- if ( ! ( this instanceof Multiple ) ) return new Multiple ( options ) ;
24
+ var Multiple = function ( options ) {
25
+ if ( ! ( this instanceof Multiple ) ) return new Multiple ( options ) ;
26
26
27
- [ 'selector' , 'background' , 'affectText' , 'opacity' ] . forEach ( function ( option ) {
28
- this [ option ] = options [ option ] ;
29
- } . bind ( this ) ) ;
27
+ [ 'selector' , 'background' , 'affectText' , 'opacity' ] . forEach ( function ( option ) {
28
+ this [ option ] = options [ option ] ;
29
+ } . bind ( this ) ) ;
30
30
31
- this . className = 'multiple-' + ( isMobile ? 'mobile' : 'desktop' ) + ( this . affectText ? '-text' : '' ) ;
32
- this . update ( this . background ) ;
33
- }
31
+ this . className = 'multiple-' + ( isMobile ? 'mobile' : 'desktop' ) + ( this . affectText ? '-text' : '' ) ;
32
+ this . update ( this . background ) ;
33
+ }
34
34
35
- Multiple . prototype = {
36
- constructor : Multiple ,
37
- each : function ( select , callback , nodes ) {
38
- Array . prototype . slice . call ( nodes ? select : document . querySelectorAll ( select ) ) . forEach ( callback . bind ( this ) ) ;
39
- } ,
40
- // #f95 or #ff9955 or rgb(255,153,85) -> rgba(255,102,0,0.666)
41
- setOpacity : function ( styles ) {
42
- return styles . replace ( / # \b ( [ a - f \d ] { 3 } | [ a - f \d ] { 6 } ) \b / gi, function ( full , hex ) {
43
- var rgb = hex . match ( new RegExp ( '(.{' + hex . length / 3 + '})' , 'g' ) ) . map ( function ( l ) { return parseInt ( hex . length % 2 ? l + l : l , 16 ) } ) ;
44
- return 'rgb(' + rgb . join ( ',' ) + ')' ;
45
- } ) . replace ( / r g b \( ( .[ ^ \) ] * ) \) / gi, function ( full , rgb ) {
46
- var min , a = ( 255 - ( min = Math . min . apply ( Math , ( rgb = rgb . split ( ',' ) ) ) ) ) / 255 ,
47
- rgba = this . opacity === true
48
- ? rgb . map ( function ( channel ) { return 0 | ( channel - min ) / a } ) . concat ( ( 0 | 1000 * a ) / 1000 )
49
- : rgb . concat ( this . opacity ) ;
50
- return 'rgba(' + rgba . join ( ',' ) + ')' ;
51
- } . bind ( this ) ) ;
52
- } ,
53
- // linear-gradient(#fff, #000) -> -webkit-*, -moz-*, -ms-*, -o-*
54
- setVendors : function ( styles , textMode ) {
55
- var result = textMode ? [ ] : [ styles ] ;
56
- if ( / - g r a d i e n t \( / i. test ( styles ) || textMode ) [ 'webkit' , 'moz' , 'ms' , 'o' ] . forEach ( function ( vendor , i ) {
57
- if ( textMode && i ) return ;
58
- result . unshift ( ( textMode ? '-webkit-linear-gradient(transparent,transparent),' : '' ) + styles . replace ( / ( [ ^ , \s ] * - g r a d i e n t \( ) / gi, '-' + vendor + '-$1' ) ) ;
59
- } ) ;
60
- return result ;
61
- } ,
62
- setStyles : function ( selector , styles , textMode ) {
63
- if ( this . opacity ) styles = this . setOpacity ( styles ) ;
64
- this . styleTag . innerHTML = selector + '{background-image:' + this . setVendors ( styles , textMode ) . join ( ';\nbackground-image:' ) + '}' ;
65
- } ,
66
- renderTag : function ( className ) {
67
- var tag = document . createElement ( 'div' ) ;
68
- tag . className = className ;
69
- return tag ;
70
- } ,
71
- update : function ( styles ) {
72
- this . each ( this . selector , function ( elem ) {
73
- if ( elem . getAttribute ( 'data-multiple' ) ) return ;
74
- if ( ! isMobile || this . affectText ) return elem . classList . add ( this . className ) ;
35
+ Multiple . prototype = {
36
+ constructor : Multiple ,
37
+ each : function ( select , callback , nodes ) {
38
+ Array . prototype . slice . call ( nodes ? select : document . querySelectorAll ( select ) ) . forEach ( callback . bind ( this ) ) ;
39
+ } ,
40
+ // #f95 or #ff9955 or rgb(255,153,85) -> rgba(255,102,0,0.666)
41
+ setOpacity : function ( styles ) {
42
+ return styles . replace ( / # \b ( [ a - f \d ] { 3 } | [ a - f \d ] { 6 } ) \b / gi, function ( full , hex ) {
43
+ var rgb = hex . match ( new RegExp ( '(.{' + hex . length / 3 + '})' , 'g' ) ) . map ( function ( l ) { return parseInt ( hex . length % 2 ? l + l : l , 16 ) } ) ;
44
+ return 'rgb(' + rgb . join ( ',' ) + ')' ;
45
+ } ) . replace ( / r g b \( ( .[ ^ \) ] * ) \) / gi, function ( full , rgb ) {
46
+ var min , a = ( 255 - ( min = Math . min . apply ( Math , ( rgb = rgb . split ( ',' ) ) ) ) ) / 255 ,
47
+ rgba = this . opacity === true
48
+ ? rgb . map ( function ( channel ) { return 0 | ( channel - min ) / a } ) . concat ( ( 0 | 1000 * a ) / 1000 )
49
+ : rgb . concat ( this . opacity ) ;
50
+ return 'rgba(' + rgba . join ( ',' ) + ')' ;
51
+ } . bind ( this ) ) ;
52
+ } ,
53
+ // linear-gradient(#fff, #000) -> -webkit-*, -moz-*, -ms-*, -o-*
54
+ setVendors : function ( styles , textMode ) {
55
+ var result = textMode ? [ ] : [ styles ] ;
56
+ if ( / - g r a d i e n t \( / i. test ( styles ) || textMode ) [ 'webkit' , 'moz' , 'ms' , 'o' ] . forEach ( function ( vendor , i ) {
57
+ if ( textMode && i ) return ;
58
+ result . unshift ( ( textMode ? '-webkit-linear-gradient(transparent,transparent),' : '' ) + styles . replace ( / ( [ ^ , \s ] * - g r a d i e n t \( ) / gi, '-' + vendor + '-$1' ) ) ;
59
+ } ) ;
60
+ return result ;
61
+ } ,
62
+ setStyles : function ( selector , styles , textMode ) {
63
+ if ( this . opacity ) styles = this . setOpacity ( styles ) ;
64
+ this . styleTag . innerHTML = selector + '{background-image:' + this . setVendors ( styles , textMode ) . join ( ';\nbackground-image:' ) + '}' ;
65
+ } ,
66
+ renderTag : function ( className ) {
67
+ var tag = document . createElement ( 'div' ) ;
68
+ tag . className = className ;
69
+ return tag ;
70
+ } ,
71
+ update : function ( styles ) {
72
+ this . each ( this . selector , function ( elem ) {
73
+ if ( elem . getAttribute ( 'data-multiple' ) ) return ;
74
+ if ( ! isMobile || this . affectText ) return elem . classList . add ( this . className ) ;
75
75
76
- var wrapperTag = this . renderTag ( this . className + '-wrapper' ) ,
77
- contentTag = this . renderTag ( this . className + '-content' ) ;
78
- this . each ( elem . childNodes , function ( child ) { contentTag . appendChild ( child ) } , true ) ;
79
- elem . appendChild ( wrapperTag ) ;
80
- wrapperTag . appendChild ( this . renderTag ( this . className ) ) ;
81
- wrapperTag . appendChild ( contentTag ) ;
82
- elem . setAttribute ( 'data-multiple' , true ) ;
83
- } ) ;
76
+ var wrapperTag = this . renderTag ( this . className + '-wrapper' ) ,
77
+ contentTag = this . renderTag ( this . className + '-content' ) ;
78
+ this . each ( elem . childNodes , function ( child ) { contentTag . appendChild ( child ) } , true ) ;
79
+ elem . appendChild ( wrapperTag ) ;
80
+ wrapperTag . appendChild ( this . renderTag ( this . className ) ) ;
81
+ wrapperTag . appendChild ( contentTag ) ;
82
+ elem . setAttribute ( 'data-multiple' , true ) ;
83
+ } ) ;
84
84
85
- if ( ! styles ) return ;
86
- if ( ! this . styleTag ) document . head . appendChild ( this . styleTag = document . createElement ( 'style' ) ) ;
87
- if ( ! isMobile || ! this . affectText ) this . setStyles ( this . selector + ( isMobile ? ' ' : '' ) + '.' + this . className + ( isMobile ? ':before' : '' ) , styles , this . affectText ) ;
88
- if ( this . affectText ) this . styleTag . innerHTML += this . selector + '.' + this . className + '{color:' + this . affectText + '}' ;
89
- } ,
90
- destroy : function ( ) {
91
- this . styleTag . parentNode && this . styleTag . parentNode . removeChild ( this . styleTag ) && delete this . styleTag ;
92
- this . each ( this . selector , function ( elem ) {
93
- elem . classList . remove ( this . className ) ;
94
- elem . removeAttribute ( 'data-multiple' ) ;
85
+ if ( ! styles ) return ;
86
+ if ( ! this . styleTag ) document . head . appendChild ( this . styleTag = document . createElement ( 'style' ) ) ;
87
+ if ( ! isMobile || ! this . affectText ) this . setStyles ( this . selector + ( isMobile ? ' ' : '' ) + '.' + this . className + ( isMobile ? ':before' : '' ) , styles , this . affectText ) ;
88
+ if ( this . affectText ) this . styleTag . innerHTML += this . selector + '.' + this . className + '{color:' + this . affectText + '}' ;
89
+ } ,
90
+ destroy : function ( ) {
91
+ this . styleTag . parentNode && this . styleTag . parentNode . removeChild ( this . styleTag ) && delete this . styleTag ;
92
+ this . each ( this . selector , function ( elem ) {
93
+ elem . classList . remove ( this . className ) ;
94
+ elem . removeAttribute ( 'data-multiple' ) ;
95
95
96
- if ( ! isMobile || this . affectText ) return ;
97
- this . each ( elem . children [ 0 ] . children [ 1 ] . childNodes , function ( child ) { elem . appendChild ( child ) } , true ) ;
98
- elem . removeChild ( elem . children [ 0 ] ) ;
99
- } ) ;
100
- }
101
- }
96
+ if ( ! isMobile || this . affectText ) return ;
97
+ this . each ( elem . children [ 0 ] . children [ 1 ] . childNodes , function ( child ) { elem . appendChild ( child ) } , true ) ;
98
+ elem . removeChild ( elem . children [ 0 ] ) ;
99
+ } ) ;
100
+ }
101
+ }
102
102
103
- return Multiple ;
103
+ return Multiple ;
104
104
} ) ) ;
0 commit comments