Skip to content

Commit b220836

Browse files
authored
Merge pull request #14 from designjockey/close-icon-color
Close Icon Color: Changes color of X icon based on bg color
2 parents 553cc33 + cb9a23a commit b220836

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

Diff for: lightbox.js

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
import $ from 'jquery';
2+
import tinycolor from 'tinycolor2';
23
import 'style!./sass/lightbox.scss';
34

45
var bgColor,
56
opacity,
67
$blocking = $('<div class="js-blocking" id="lightbox-blocking"></div>'),
78
$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+
`),
936
images = [],
1037
active = false,
1138
loading = false,
@@ -17,7 +44,7 @@ var bgColor,
1744
var LightboxImage = function(src, id) {
1845
this.src = src;
1946
this.id = id;
20-
this.$view = $(template).hide();
47+
this.$view = $template.hide();
2148

2249
var self = this;
2350

@@ -146,6 +173,13 @@ function bind() {
146173
});
147174
}
148175

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+
149183
function init(options) {
150184
var defaults = {
151185
context: document.body,
@@ -158,6 +192,8 @@ function init(options) {
158192
bgColor = config.bgColor;
159193
opacity = config.opacity;
160194

195+
_setCloseIconColor(bgColor);
196+
161197
$context.find('.js-lightbox').each(function(i, el) {
162198
var $img = $(el);
163199
$img.data('img-id', i).addClass('lightbox-link');
@@ -169,7 +205,7 @@ function init(options) {
169205
images[$(this).data('img-id')].render();
170206
});
171207

172-
if (images.length === 1) {
208+
if (images.length === 1) {
173209
single = true;
174210
}
175211
}

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightbox",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "Image lightbox",
55
"main": "lightbox.js",
66
"scripts": {
@@ -17,6 +17,7 @@
1717
},
1818
"homepage": "https://github.com/behance/lightbox#readme",
1919
"dependencies": {
20-
"jquery": "~2.1.1"
20+
"jquery": "~2.1.1",
21+
"tinycolor2": "^1.3.0"
2122
}
2223
}

0 commit comments

Comments
 (0)