1
1
import $ from 'jquery' ;
2
+ import tinycolor from 'tinycolor2' ;
2
3
import 'style!./sass/lightbox.scss' ;
3
4
4
5
var bgColor ,
5
6
opacity ,
6
7
$blocking = $ ( '<div class="js-blocking" id="lightbox-blocking"></div>' ) ,
7
8
$body = $ ( document . body ) ,
8
- template = '<div class="js-lightbox-wrap" id="lightbox-wrap"> <div class="js-lightbox-inner-wrap" id="lightbox-inner-wrap"> <div class="js-img-wrap" id="lightbox-img-wrap"> <div class="control prev js-control js-prev"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="60" height="60" viewBox="0 0 60 60" xml:space="preserve"><circle class="lightbox-icon-bg" cx="30" cy="30" r="30"/><path class="lightbox-icon-arrow" d="M28.6 30l7.9-7.9c0.5-0.5 0.7-1.1 0.7-1.7s-0.2-1.2-0.7-1.7c-0.9-0.9-2.5-0.9-3.4 0l-9.6 9.6c-0.5 0.5-0.7 1.1-0.7 1.7s0.2 1.2 0.7 1.7l9.6 9.6c0.9 0.9 2.5 0.9 3.4 0 0.5-0.5 0.7-1.1 0.7-1.7 0-0.6-0.2-1.2-0.7-1.7L28.6 30z"/></svg> </div> <div class="control next js-control js-next"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="60" height="60" viewBox="0 0 60 60" xml:space="preserve"><circle class="lightbox-icon-bg" cx="30" cy="30" r="30"/><path class="lightbox-icon-arrow" d="M31.4 30l-7.9 7.9c-0.5 0.5-0.7 1.1-0.7 1.7 0 0.6 0.2 1.2 0.7 1.7 0.9 0.9 2.5 0.9 3.4 0l9.6-9.6c0.5-0.5 0.7-1.1 0.7-1.7s-0.2-1.2-0.7-1.7l-9.6-9.6c-0.9-0.9-2.5-0.9-3.4 0 -0.5 0.5-0.7 1.1-0.7 1.7 0 0.6 0.2 1.2 0.7 1.7L31.4 30z"/></svg> </div> <div class="control close js-control js-close"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" viewBox="0 0 26 26" preserveAspectRatio="xMidYMid meet"> <rect x="-3.4" y="11" transform="matrix(0.7071 0.7071 -0.7071 0.7071 13 -5.3848)" class="st0" width="32.7" height="4" /> <rect x="-3.4" y="11" transform="matrix(0.7071 -0.7071 0.7071 0.7071 -5.3848 13)" class="st0" width="32.7" height="4" /> </svg> </div> <img/></div> </div> </div>' ,
9
+ $template = $ ( `
10
+ <div class="js-lightbox-wrap" id="lightbox-wrap">
11
+ <div class="js-lightbox-inner-wrap" id="lightbox-inner-wrap">
12
+ <div class="js-img-wrap" id="lightbox-img-wrap">
13
+ <div class="control prev js-control js-prev">
14
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="60" height="60" viewBox="0 0 60 60" xml:space="preserve">
15
+ <circle class="lightbox-icon-bg" cx="30" cy="30" r="30"/>
16
+ <path class="lightbox-icon-arrow" d="M28.6 30l7.9-7.9c0.5-0.5 0.7-1.1 0.7-1.7s-0.2-1.2-0.7-1.7c-0.9-0.9-2.5-0.9-3.4 0l-9.6 9.6c-0.5 0.5-0.7 1.1-0.7 1.7s0.2 1.2 0.7 1.7l9.6 9.6c0.9 0.9 2.5 0.9 3.4 0 0.5-0.5 0.7-1.1 0.7-1.7 0-0.6-0.2-1.2-0.7-1.7L28.6 30z"/>
17
+ </svg>
18
+ </div>
19
+ <div class="control next js-control js-next">
20
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" width="60" height="60" viewBox="0 0 60 60" xml:space="preserve">
21
+ <circle class="lightbox-icon-bg" cx="30" cy="30" r="30"/>
22
+ <path class="lightbox-icon-arrow" d="M31.4 30l-7.9 7.9c-0.5 0.5-0.7 1.1-0.7 1.7 0 0.6 0.2 1.2 0.7 1.7 0.9 0.9 2.5 0.9 3.4 0l9.6-9.6c0.5-0.5 0.7-1.1 0.7-1.7s-0.2-1.2-0.7-1.7l-9.6-9.6c-0.9-0.9-2.5-0.9-3.4 0 -0.5 0.5-0.7 1.1-0.7 1.7 0 0.6 0.2 1.2 0.7 1.7L31.4 30z"/>
23
+ </svg>
24
+ </div>
25
+ <div class="control close js-control js-close">
26
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0" y="0" viewBox="0 0 26 26" preserveAspectRatio="xMidYMid meet">
27
+ <rect x="-3.4" y="11" transform="matrix(0.7071 0.7071 -0.7071 0.7071 13 -5.3848)" class="st0" width="32.7" height="4" />
28
+ <rect x="-3.4" y="11" transform="matrix(0.7071 -0.7071 0.7071 0.7071 -5.3848 13)" class="st0" width="32.7" height="4" />
29
+ </svg>
30
+ </div>
31
+ <img/>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ ` ) ,
9
36
images = [ ] ,
10
37
active = false ,
11
38
loading = false ,
@@ -17,7 +44,7 @@ var bgColor,
17
44
var LightboxImage = function ( src , id ) {
18
45
this . src = src ;
19
46
this . id = id ;
20
- this . $view = $ ( template ) . hide ( ) ;
47
+ this . $view = $template . hide ( ) ;
21
48
22
49
var self = this ;
23
50
@@ -146,6 +173,13 @@ function bind() {
146
173
} ) ;
147
174
}
148
175
176
+ function _setCloseIconColor ( bgColor ) {
177
+ var tinyBgColor = tinycolor ( bgColor ) ;
178
+ var closeIconColor = tinyBgColor . isLight ( ) ? '#000' : '#FFF' ;
179
+
180
+ $template . find ( '.js-close svg' ) . attr ( 'fill' , closeIconColor ) ;
181
+ }
182
+
149
183
function init ( options ) {
150
184
var defaults = {
151
185
context : document . body ,
@@ -158,6 +192,8 @@ function init(options) {
158
192
bgColor = config . bgColor ;
159
193
opacity = config . opacity ;
160
194
195
+ _setCloseIconColor ( bgColor ) ;
196
+
161
197
$context . find ( '.js-lightbox' ) . each ( function ( i , el ) {
162
198
var $img = $ ( el ) ;
163
199
$img . data ( 'img-id' , i ) . addClass ( 'lightbox-link' ) ;
@@ -169,7 +205,7 @@ function init(options) {
169
205
images [ $ ( this ) . data ( 'img-id' ) ] . render ( ) ;
170
206
} ) ;
171
207
172
- if ( images . length === 1 ) {
208
+ if ( images . length === 1 ) {
173
209
single = true ;
174
210
}
175
211
}
0 commit comments