Skip to content

Commit 3b5220a

Browse files
committed
Bug fixes and improvements
1 parent dce930a commit 3b5220a

11 files changed

+226
-1943
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ Thumbs.db
2121
/dist/js/glightboxTest.min.js
2222
/dist/js/glightboxTest.js
2323
/src/js/glightboxTest.js
24+
sitepsd.psd
25+
package-lock.json

README.md

+38-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
## GLightbox
22

3-
Glightbox is a pure javascript lightbox. It can display images, videos with optional autoplay for youtube, vimeo and even self hosted videos with JWPlayer support
3+
Glightbox is a pure javascript lightbox. It can display images, iframes, inline content and videos with optional autoplay for youtube, vimeo and even self hosted videos with JWPlayer support
44

55
## Demo
6-
You can check the live demo [clicking here](http://glightbox.mcstudios.com.mx/)
6+
You can check the live demo [clicking here](https://glightbox.mcstudios.com.mx/)
77

8-
## Installation
8+
## Usage
99

10-
To start using glightbox simply add the css and the script to your site.
10+
```bash
11+
$ npm install glightbox
12+
# OR
13+
$ bower install glightbox
14+
```
15+
16+
```javascript
17+
import GLightbox from 'glightbox'
18+
```
19+
20+
Or manually download and link `glightbox.min.js` in your HTML:
1121

1222
```
1323
<link rel="stylesheet" href="dist/css/glightbox.css">
@@ -29,12 +39,30 @@ GLightbox was tested in the following browsers.
2939
It will work in any browser that supports css Flexbox
3040

3141
## Changelog
32-
- 1.0.5 Fixed open and close effect not taking a custom animation, also added none as a new option to disable open, close and slide animations. Added new options (touchNavigation, keyboardNavigation, closeOnOutsideClick) to enable or disable user interaction. Fixed an error when calling the destroy method and no videos were present in the slider.
33-
- 1.0.4 Improved the open method so it can be called without duplicating the structure and events, also the original node is passed to events like beforeSlideChange, afterSlideChange, etc.
34-
- 1.0.3 Added option moreLength to control the number of characters in the description for mobile devices
35-
- 1.0.2 Fixed instance not returned and unable to call public methods
36-
- 1.0.1 Fixed large images not displayed correctly
37-
- 1.0.0 Initial release
42+
### 1.0.6
43+
- Fixed afterSlideLoad only triggered one time for all the slides
44+
- Fixed a small space between the image and description when is set to top or bottom
45+
- New: Now you can set individual width and height for each slide with inlines or iframes.
46+
- New: Now you can set individual source types for each slide ('type': 'image' | 'iframe' | 'video' | 'inline' | 'external).
47+
- New: Published on npm
48+
- New: Published on bower
49+
### 1.0.5
50+
- Fixed open and close effect not taking a custom animation
51+
- New: Added none as a new option to disable open, close and slide animations
52+
- New: Added new options (touchNavigation, keyboardNavigation, closeOnOutsideClick) to enable or disable user interaction
53+
- Fixed an error when calling the destroy method and no videos were present in the slider
54+
### 1.0.4
55+
- Improved the open method so it can be called without duplicating the structure and events
56+
- New: The original node is passed to events like beforeSlideChange, afterSlideChange, etc.
57+
### 1.0.3
58+
- New: Added option moreLength to control the number of characters in the description for mobile devices
59+
### 1.0.2
60+
- Fixed instance not returned and unable to call public methods
61+
### 1.0.1
62+
- Fixed large images not displayed correctly
63+
64+
### 1.0.0
65+
- Initial release
3866

3967
## Todo
4068
- [ ] Improve github description with more documentation and examples

bower.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "glightbox",
3+
"description": "JavaScript animation engine",
4+
"main": "dist/js/glightbox.min.js",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/mcstudios/glightbox"
8+
},
9+
"keywords": [
10+
"lightbox",
11+
"javascript",
12+
"gallery",
13+
"popup"
14+
],
15+
"authors": [
16+
"MC Studios <[email protected]>"
17+
],
18+
"license": "MIT",
19+
"homepage": "https://glightbox.mcstudios.com.mx",
20+
"ignore": [
21+
"**/.*",
22+
"node_modules",
23+
"bower_components",
24+
"*.psd",
25+
"demo",
26+
"test",
27+
"tests"
28+
]
29+
}

dist/css/glightbox.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@
9393

9494
.glightbox-container .ginner-container.desc-bottom,
9595
.glightbox-container .ginner-container.desc-top {
96-
display: inline-block;
96+
-webkit-box-orient: vertical;
97+
-webkit-box-direction: normal;
98+
-ms-flex-direction: column;
99+
flex-direction: column;
97100
}
98101

99102
.glightbox-container .ginner-container.desc-left,

dist/css/glightbox.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/glightbox.js

+44-36
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
};
4545

4646
/**
47-
* GLightbox v1.0.5
47+
* GLightbox v1.0.6
4848
* Awesome pure javascript lightbox
4949
* made by mcstudios.com.mx
5050
*/
@@ -286,7 +286,6 @@
286286

287287
var thisArg = arguments[2];
288288

289-
var tstst = onElement;
290289
var element = onElement || [];
291290
if (utils.isString(element)) {
292291
element = document.querySelectorAll(element);
@@ -484,24 +483,28 @@
484483
*/
485484
var getSlideData = function getSlideData() {
486485
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
487-
488-
if (element === null) return false;
489-
490-
var url = '';
491-
var config = element.getAttribute('data-glightbox');
492-
var type = element.nodeName.toLowerCase();
493-
if (type === 'a') url = element.href;
494-
if (type === 'img') url = element.src;
486+
var settings = arguments[1];
495487

496488
var data = {
497-
href: url,
489+
href: '',
498490
title: '',
499491
description: '',
500492
descPosition: 'bottom',
501493
effect: '',
502494
node: element
503495
};
504496

497+
if (utils.isObject(element) && !utils.isNode(element)) {
498+
return extend(data, element);
499+
}
500+
501+
var url = '';
502+
var config = element.getAttribute('data-glightbox');
503+
var type = element.nodeName.toLowerCase();
504+
if (type === 'a') url = element.href;
505+
if (type === 'img') url = element.src;
506+
507+
data.href = url;
505508
var sourceType = getSourceType(url);
506509
data = extend(data, sourceType);
507510

@@ -539,6 +542,16 @@
539542
if (nodeDesc) {
540543
data.description = nodeDesc.innerHTML;
541544
}
545+
546+
data.sourcetype = data.hasOwnProperty('type') ? data.type : data.sourcetype;
547+
data.type = data.sourcetype;
548+
549+
var defaultWith = data.sourcetype == 'video' ? settings.videosWidth : settings.width;
550+
var defaultHeight = data.sourcetype == 'video' ? settings.videosHeight : settings.height;
551+
552+
data.width = utils.has(data, 'width') ? data.width : defaultWith;
553+
data.height = utils.has(data, 'height') ? data.height : defaultHeight;
554+
542555
return data;
543556
};
544557

@@ -565,17 +578,19 @@
565578
this.settings.beforeSlideLoad(slide, data);
566579
}
567580

568-
var type = data.sourcetype;
581+
var type = data.type;
569582
var position = data.descPosition;
570583
var slideMedia = slide.querySelector('.gslide-media');
571584
var slideTitle = slide.querySelector('.gslide-title');
572585
var slideText = slide.querySelector('.gslide-desc');
573586
var slideDesc = slide.querySelector('.gslide-description');
574587
var finalCallback = callback;
575588

576-
if (callback && utils.isFunction(this.settings.afterSlideLoad)) {
589+
if (utils.isFunction(this.settings.afterSlideLoad)) {
577590
finalCallback = function finalCallback() {
578-
callback();
591+
if (utils.isFunction(callback)) {
592+
callback();
593+
}
579594
_this.settings.afterSlideLoad(slide, data);
580595
};
581596
}
@@ -614,7 +629,7 @@
614629
}
615630

616631
if (type === 'external') {
617-
var iframe = createIframe(data.href, this.settings.width, this.settings.height, finalCallback);
632+
var iframe = createIframe(data.href, data.width, data.height, finalCallback);
618633
slideMedia.appendChild(iframe);
619634
return;
620635
}
@@ -652,6 +667,7 @@
652667
var source = data.source;
653668
var video_id = 'gvideo' + data.index;
654669
var slideMedia = slide.querySelector('.gslide-media');
670+
655671
var url = data.href;
656672
var protocol = location.protocol.replace(':', '');
657673

@@ -664,7 +680,7 @@
664680
var vimeo_id = /vimeo.*\/(\d+)/i.exec(url);
665681
var params = parseUrlParams(this.settings.vimeo.params);
666682
var video_url = protocol + '://player.vimeo.com/video/' + vimeo_id[1] + '?' + params;
667-
var iframe = createIframe(video_url, this.settings.videosWidth, this.settings.videosHeight, callback);
683+
var iframe = createIframe(video_url, data.width, data.height, callback);
668684
iframe.id = video_id;
669685
iframe.className = 'vimeo-video gvideo';
670686

@@ -687,7 +703,7 @@
687703
var yparams = parseUrlParams(youtube_params);
688704
var youtube_id = getYoutubeID(url);
689705
var _video_url = protocol + '://www.youtube.com/embed/' + youtube_id + '?' + yparams;
690-
var _iframe = createIframe(_video_url, this.settings.videosWidth, this.settings.videosHeight, callback);
706+
var _iframe = createIframe(_video_url, data.width, data.height, callback);
691707
_iframe.id = video_id;
692708
_iframe.className = 'youtube-video gvideo';
693709

@@ -708,7 +724,7 @@
708724

709725
if (source == 'local') {
710726
var _html = '<video id="' + video_id + '" ';
711-
_html += 'style="background:#000; width: ' + this.settings.width + 'px; height: ' + this.settings.height + 'px;" ';
727+
_html += 'style="background:#000; width: ' + data.width + 'px; height: ' + data.height + 'px;" ';
712728
_html += 'preload="metadata" ';
713729
_html += 'x-webkit-airplay="allow" ';
714730
_html += 'webkit-playsinline="" ';
@@ -908,8 +924,8 @@
908924
var div = document.getElementById(data.inlined.replace('#', ''));
909925
if (div) {
910926
var cloned = div.cloneNode(true);
911-
cloned.style.height = this.settings.height + 'px';
912-
cloned.style.maxWidth = this.settings.width + 'px';
927+
cloned.style.height = data.height + 'px';
928+
cloned.style.maxWidth = data.width + 'px';
913929
addClass(cloned, 'ginlined-content');
914930
slideMedia.appendChild(cloned);
915931

@@ -1048,10 +1064,6 @@
10481064
activeSlideMedia = activeSlide.querySelector('.gslide-media');
10491065
activeSlideDesc = activeSlide.querySelector('.gslide-description');
10501066

1051-
/*if (e.targetTouches[0].target.className.indexOf('gslide-video') !== -1) {
1052-
playVideo(e.targetTouches[0])
1053-
}*/
1054-
10551067
index = _this4.index;
10561068
endCoords = e.targetTouches[0];
10571069
startCoords.pageX = e.targetTouches[0].pageX;
@@ -1061,15 +1073,6 @@
10611073
}
10621074
});
10631075

1064-
/*function playVideo(e) {
1065-
addClass(e.target, 'playing')
1066-
let element = e.target
1067-
let iframe = element.querySelector('.gvideo')
1068-
var e = document.createEvent('TouchEvent');
1069-
e.initEvent('touchstart', true, true);
1070-
iframe.dispatchEvent(e);
1071-
}*/
1072-
10731076
this.events['gestureStart'] = addEvent('gesturestart', {
10741077
onElement: body,
10751078
withCallback: function withCallback(e, target) {
@@ -1340,7 +1343,7 @@
13401343
}, {
13411344
key: 'open',
13421345
value: function open() {
1343-
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1346+
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
13441347

13451348
this.elements = this.getElements(element);
13461349
if (this.elements.length == 0) return false;
@@ -1422,7 +1425,7 @@
14221425
} else {
14231426
// If not loaded add the slide content
14241427
show(this.loader);
1425-
var slide_data = getSlideData(this.elements[index]);
1428+
var slide_data = getSlideData(this.elements[index], this.settings);
14261429
slide_data.index = index;
14271430
setSlideContent.apply(this, [slide, slide_data, function () {
14281431
hide(_this6.loader);
@@ -1460,7 +1463,7 @@
14601463
return false;
14611464
}
14621465

1463-
var slide_data = getSlideData(this.elements[index]);
1466+
var slide_data = getSlideData(this.elements[index], this.settings);
14641467
slide_data.index = index;
14651468
var type = slide_data.sourcetype;
14661469
if (type == 'video' || type == 'external') {
@@ -1657,6 +1660,11 @@
16571660
return false;
16581661
}
16591662
}
1663+
}, {
1664+
key: 'setElements',
1665+
value: function setElements(elements) {
1666+
this.settings.elements = elements;
1667+
}
16601668
}, {
16611669
key: 'getElements',
16621670
value: function getElements() {

0 commit comments

Comments
 (0)