From cb9a23a03c7a027627bb0a1b96997a50d7a6fa75 Mon Sep 17 00:00:00 2001 From: Ritesh Manchanda Date: Wed, 15 Jun 2016 15:42:54 -0400 Subject: [PATCH] Close Icon Color: Changes color of X icon based on bg color --- lightbox.js | 42 +++++++++++++++++++++++++++++++++++++++--- package.json | 5 +++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lightbox.js b/lightbox.js index 6830939..76a6ef0 100644 --- a/lightbox.js +++ b/lightbox.js @@ -1,11 +1,38 @@ import $ from 'jquery'; +import tinycolor from 'tinycolor2'; import 'style!./sass/lightbox.scss'; var bgColor, opacity, $blocking = $(''), $body = $(document.body), - template = '', + $template = $(` + + `), images = [], active = false, loading = false, @@ -17,7 +44,7 @@ var bgColor, var LightboxImage = function(src, id) { this.src = src; this.id = id; - this.$view = $(template).hide(); + this.$view = $template.hide(); var self = this; @@ -146,6 +173,13 @@ function bind() { }); } +function _setCloseIconColor(bgColor) { + var tinyBgColor = tinycolor(bgColor); + var closeIconColor = tinyBgColor.isLight() ? '#000' : '#FFF'; + + $template.find('.js-close svg').attr('fill', closeIconColor); +} + function init(options) { var defaults = { context: document.body, @@ -158,6 +192,8 @@ function init(options) { bgColor = config.bgColor; opacity = config.opacity; + _setCloseIconColor(bgColor); + $context.find('.js-lightbox').each(function(i, el) { var $img = $(el); $img.data('img-id', i).addClass('lightbox-link'); @@ -169,7 +205,7 @@ function init(options) { images[$(this).data('img-id')].render(); }); -if (images.length === 1) { + if (images.length === 1) { single = true; } } diff --git a/package.json b/package.json index 7b0e0ec..1da8aa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lightbox", - "version": "3.0.0", + "version": "3.1.0", "description": "Image lightbox", "main": "lightbox.js", "scripts": { @@ -17,6 +17,7 @@ }, "homepage": "https://github.com/behance/lightbox#readme", "dependencies": { - "jquery": "~2.1.1" + "jquery": "~2.1.1", + "tinycolor2": "^1.3.0" } }