├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── angular.json
├── demo
├── app.component.ts
├── app.css
├── app.module.ts
├── img
│ ├── image1-thumb.jpg
│ ├── image1.jpg
│ ├── image2-thumb.jpg
│ ├── image2.jpg
│ ├── image3-thumb.jpg
│ ├── image3.jpg
│ ├── image4-thumb.jpg
│ └── image4.jpg
├── main.ts
└── polyfills.ts
├── index.html
├── karma-main.js
├── karma.conf.js
├── package.json
├── src
├── index.ts
├── lightbox-config.service.ts
├── lightbox-event.service.ts
├── lightbox-overlay.component.spec.ts
├── lightbox-overlay.component.ts
├── lightbox.component.spec.ts
├── lightbox.component.ts
├── lightbox.css
├── lightbox.module.ts
└── lightbox.service.ts
├── tsconfig-demo.json
├── tsconfig.json
├── tslint.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | src/*.map
3 | src/*.js
4 | /compiled
5 | *.map
6 | /img
7 | *.metadata.json
8 | *.log
9 | /dist
10 | *.d.ts
11 | *.ngsummary.json
12 |
13 | .angular
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | dist
2 | demo
3 | node_modules
4 | src
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '10.16.0'
4 | addons:
5 | apt:
6 | packages:
7 | - sshpass
8 | before_script:
9 | - npm install -g yarn
10 | - yarn
11 | script:
12 | - npm test
13 | - npm run build
14 | after_success:
15 | - npm run build
16 | - ssh-keyscan $DOMAIN > ~/.ssh/known_hosts
17 | - sshpass -p "$PASS" rsync -ar --stats --exclude=.git ./ $USER@$DOMAIN:$FOLDER_PATH
18 | branches:
19 | only:
20 | - master
21 | notifications:
22 | email: false
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/themyth92/ngx-lightbox)
2 |
3 | # Ngx-Lightbox
4 |
5 | A [lightbox2](https://github.com/lokesh/lightbox2) implementation port to use with new Angular without the need for jQuery
6 |
7 | ## Version
8 |
9 | - For Angular 5, 6, 7, please use ngx-lightbox 1.x.x. `npm install ngx-lightbox@1.2.0`
10 | - For Angular >= 8, please use ngx-lightbox 2.x.x. `npm install ngx-lightbox@2.0.0`
11 | - For Angular 2, 4, please use [angular2-lightbox](https://github.com/themyth92/angular2-lightbox)
12 |
13 | ## [Demo](https://themyth92.com/project/ngx-lightbox)
14 |
15 | ## Installation
16 |
17 | `npm install --save ngx-lightbox`
18 |
19 | Update your `angular.json`
20 |
21 | ```
22 | {
23 | "styles": [
24 | "./node_modules/ngx-lightbox/lightbox.css",
25 | ...
26 | ],
27 | }
28 | ```
29 |
30 | ## Usage
31 |
32 | ### Module:
33 |
34 | Import `LightboxModule` from `ngx-lightbox`
35 |
36 | ```javascript
37 | import { LightboxModule } from 'ngx-lightbox';
38 |
39 | @NgModule({
40 | imports: [ LightboxModule ]
41 | })
42 | ```
43 |
44 | ### Component
45 |
46 | 1. Markup
47 |
48 | ```html
49 |
50 |
![]()
51 |
52 | ```
53 |
54 | 2. Component method
55 |
56 | ```javascript
57 | import { Lightbox } from 'ngx-lightbox';
58 |
59 | export class AppComponent {
60 | private _album: Array = [];
61 | constructor(private _lightbox: Lightbox) {
62 | for (let i = 1; i <= 4; i++) {
63 | const src = 'demo/img/image' + i + '.jpg';
64 | const caption = 'Image ' + i + ' caption here';
65 | const thumb = 'demo/img/image' + i + '-thumb.jpg';
66 | const album = {
67 | src: src,
68 | caption: caption,
69 | thumb: thumb
70 | };
71 |
72 | this._albums.push(album);
73 | }
74 | }
75 |
76 | open(index: number): void {
77 | // open lightbox
78 | this._lightbox.open(this._albums, index);
79 | }
80 |
81 | close(): void {
82 | // close lightbox programmatically
83 | this._lightbox.close();
84 | }
85 | }
86 |
87 | ```
88 |
89 | Each `object` of `album` array inside your component may contains 3 properties :
90 |
91 | | Properties | Requirement | Description |
92 | | ---------- | ----------- | ------------------------------------------------------------------------------------------------------------------ |
93 | | src | Required | The source image to your thumbnail that you want to with use lightbox when user click on `thumbnail` image |
94 | | caption | Optional | Your caption corresponding with your image |
95 | | thumb | Optional | Source of your thumbnail. It is being used inside your component markup so this properties depends on your naming. |
96 |
97 | 3. Listen to lightbox event
98 |
99 | You can listen to 3 events, which are either **CHANGE_PAGE**, **CLOSE** or **OPEN**.
100 |
101 | ```javascript
102 | import { LightboxEvent, LIGHTBOX_EVENT } from 'ngx-lightbox';
103 | import { Subscription } from 'rxjs';
104 |
105 | export class AppComponent {
106 | private _subscription: Subscription;
107 | constructor(private _lightboxEvent: LightboxEvent) {}
108 | open(index: number): void {
109 | // register your subscription and callback whe open lightbox is fired
110 | this._subscription = this._lightboxEvent.lightboxEvent$
111 | .subscribe(event => this._onReceivedEvent(event));
112 | }
113 |
114 | private _onReceivedEvent(event: any): void {
115 | // remember to unsubscribe the event when lightbox is closed
116 | if (event.id === LIGHTBOX_EVENT.CLOSE) {
117 | // event CLOSED is fired
118 | this._subscription.unsubscribe();
119 | }
120 |
121 | if (event.id === LIGHTBOX_EVENT.OPEN) {
122 | // event OPEN is fired
123 | }
124 |
125 | if (event.id === LIGHTBOX_EVENT.CHANGE_PAGE) {
126 | // event change page is fired
127 | console.log(event.data); // -> image index that lightbox is switched to
128 | }
129 | }
130 | }
131 | ```
132 |
133 | ## Lightbox options
134 |
135 | Available options based on lightbox2 options
136 |
137 | | Properties | Default | Description |
138 | | --------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
139 | | fadeDuration | **0.7** seconds | _duration_ starting when the **src** image is **loaded** to **fully appear** onto screen. |
140 | | resizeDuration | **0.5** seconds | _duration_ starting when Lightbox container **change** its dimension from a _default/previous image_ to the _current image_ when the _current image_ is **loaded**. |
141 | | fitImageInViewPort | **true** | Determine whether lightbox will use the natural image _width/height_ or change the image _width/height_ to fit the view of current window. Change this option to **true** to prevent problem when image too big compare to browser windows. |
142 | | positionFromTop | **20** px | The position of lightbox from the top of window browser |
143 | | showImageNumberLabel | **false** | Determine whether to show the image number to user. The default text shown is `Image IMAGE_NUMBER of ALBUM_LENGTH` |
144 | | alwaysShowNavOnTouchDevices | **false** | Determine whether to show `left/right` arrow to user on Touch devices. |
145 | | wrapAround | **false** | Determine whether to move to the start of the album when user reaches the end of album and vice versa. Set it to **true** to enable this feature. |
146 | | disableKeyboardNav | **false** | Determine whether to disable navigation using keyboard event. |
147 | | disableScrolling | **false** | If **true**, prevent the page from scrolling while Lightbox is open. This works by settings overflow hidden on the body. |
148 | | centerVertically | **false** | If **true**, images will be centered vertically to the screen. |
149 | | albumLabel | "Image %1 of %2" | The text displayed below the caption when viewing an image set. The default text shows the current image number and the total number of images in the set. |
150 | | enableTransition | **true** | Transition animation between images will be disabled if this flag set to **false** |
151 | | showZoom | **false** | Zoom Buttons will be shown if this flag set to **true** |
152 | | showRotate | **false** | Rotate Buttons will be shown if this flag set to **true** |
153 | | showDownloadButton | **false** | Download button will be shown if this flag set to **true** |
154 | | containerElementResolver | () => document.body | Resolves the element that will contain the lightbox |
155 |
156 |
157 | **NOTE**: You can either override default config or during a specific opening window
158 |
159 | 1. Override default config
160 |
161 | ```javascript
162 | import { LightboxConfig } from 'ngx-lightbox';
163 |
164 | export class AppComponent {
165 | constructor(private _lightboxConfig: LightboxConfig) {
166 | // override default config
167 | _lightboxConfig.fadeDuration = 1;
168 | }
169 | }
170 | ```
171 |
172 | 2. Set config in a specific opening window
173 |
174 | ```javascript
175 | import { LightboxConfig, Lightbox } from 'ngx-lightbox';
176 |
177 | export class AppComponent {
178 | constructor(private _lightboxConfig: LightboxConfig, private _lightbox: Lightbox) {}
179 | open(index: number) {
180 | // override the default config on second parameter
181 | this._lightbox.open(this._albums, index, { wrapAround: true, showImageNumberLabel: true });
182 | }
183 | }
184 | ```
185 |
186 | ### Overriding lightbox parent elements
187 |
188 | If you want to use any other parent element than your ``, please override the `containerElementResolver` property of your `LightboxConfig`.
189 | This can be used, e.g. if you are opening the lightbox from within a Shadow DOM based web component.
190 |
191 | ```js
192 | export class MyLightBoxTrigger {
193 | constructor(
194 | private _lightbox: Lightbox,
195 | private _lighboxConfig: LightboxConfig,
196 | ) {
197 | _lighboxConfig.containerElementResolver = (doc: Document) => doc.getElementById('my-lightbox-host');
198 | }
199 |
200 | open(index: number): void {
201 | this._lightbox.open(this.images, index); // will put the lightbox child into e.g.
202 | }
203 | ```
204 |
205 | ## Angular Universal
206 |
207 | This project works with universal out of the box with no additional configuration.
208 |
209 | ## License
210 |
211 | MIT
212 |
213 | ## Donation
214 |
215 | Buy me a beer if you like
216 |
217 | BTC: 1MFx5waJ7Sitn961DaXe3mQXrb7pEoSJct
218 |
219 | ETH: 0x2211F3d683eB1C2d753aD21D9Bd9110729C80B72
220 |
221 | NEO: ARrUrnbq1ogfsoabvCgJ5SHgknhzyUmtuS
222 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "ngx-lightbox": {
7 | "root": ".",
8 | "sourceRoot": ".",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {},
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist",
17 | "index": "index.html",
18 | "main": "demo/main.ts",
19 | "polyfills": "demo/polyfills.ts",
20 | "tsConfig": "tsconfig-demo.json",
21 | "styles": [
22 | "./src/lightbox.css",
23 | "demo/app.css"
24 | ],
25 | "assets": [
26 | { "glob": "**/*", "input": "./demo/img/", "output": "./demo/img/" }
27 | ],
28 | "scripts": []
29 | },
30 | "configurations": {
31 | "production": {
32 | "optimization": true,
33 | "outputHashing": "all",
34 | "sourceMap": true,
35 | "namedChunks": false,
36 | "aot": true,
37 | "extractLicenses": true,
38 | "vendorChunk": false,
39 | "buildOptimizer": true
40 | }
41 | }
42 | },
43 | "serve": {
44 | "builder": "@angular-devkit/build-angular:dev-server",
45 | "options": {
46 | "browserTarget": "ngx-lightbox:build"
47 | },
48 | "configurations": {
49 | "production": {
50 | "browserTarget": "ngx-lightbox:build:production"
51 | }
52 | }
53 | },
54 | "test": {
55 | "builder": "@angular-devkit/build-angular:karma",
56 | "options": {
57 | "main": "src/index.ts",
58 | "tsConfig": "tsconfig.json",
59 | "karmaConfig": "karma.conf.js",
60 | "scripts": []
61 | }
62 | },
63 | "lint": {
64 | "builder": "@angular-devkit/build-angular:tslint",
65 | "options": {
66 | "tsConfig": [
67 | "tsconfig.json"
68 | ],
69 | "exclude": [
70 | "**/node_modules/**"
71 | ]
72 | }
73 | }
74 | }
75 | }
76 | },
77 | "cli": {
78 | "analytics": false
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/demo/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Subscription } from 'rxjs';
2 |
3 | import { Component } from '@angular/core';
4 |
5 | import { IAlbum, IEvent, Lightbox, LIGHTBOX_EVENT, LightboxConfig, LightboxEvent } from '../src';
6 |
7 | @Component({
8 | selector: 'demo',
9 | template: `
10 |
11 |
12 |
![]()
13 |
14 |
15 |
16 |
17 |
![]()
18 |
19 |
20 | `,
21 | host: {
22 | class: 'columns'
23 | }
24 | })
25 | export class AppComponent {
26 | public albums: Array;
27 | private _subscription: Subscription;
28 | constructor(
29 | private _lightbox: Lightbox,
30 | private _lightboxEvent: LightboxEvent,
31 | private _lighboxConfig: LightboxConfig
32 | ) {
33 | this.albums = [];
34 | for (let i = 1; i <= 4; i++) {
35 | const src = 'demo/img/image' + i + '.jpg';
36 | const caption = 'Image ' + i + ' caption here';
37 | const thumb = 'demo/img/image' + i + '-thumb.jpg';
38 | const album = {
39 | src: src,
40 | caption: caption,
41 | thumb: thumb
42 | };
43 |
44 | this.albums.push(album);
45 | }
46 |
47 | // set default config
48 | this._lighboxConfig.fadeDuration = 1;
49 | }
50 |
51 | open(index: number): void {
52 | this._subscription = this._lightboxEvent.lightboxEvent$.subscribe((event: IEvent) => this._onReceivedEvent(event));
53 |
54 | // override the default config
55 | this._lightbox.open(this.albums, index, {
56 | wrapAround: true,
57 | showImageNumberLabel: true,
58 | disableScrolling: true,
59 | showZoom: true,
60 | showRotate: true,
61 | showDownloadButton: true
62 | });
63 | }
64 |
65 | private _onReceivedEvent(event: IEvent): void {
66 | if (event.id === LIGHTBOX_EVENT.CLOSE) {
67 | this._subscription.unsubscribe();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/demo/app.css:
--------------------------------------------------------------------------------
1 | .huge-margin-top {
2 | margin-top: 100vh;
3 | }
4 |
5 | .img-row {
6 | display: inline-block;
7 | }
8 |
9 | .img-frame {
10 | margin: 10px;
11 | border: 5px solid #fff;
12 | cursor: pointer;
13 | -webkit-transition-duration: 0.3s;
14 | transition-duration: 0.3s;
15 | -webkit-transition-property: transform;
16 | transition-property: transform;
17 | }
18 |
19 | .img-frame:hover, .img-frame:focus, .img-frame:active {
20 | -webkit-transform: translateY(-5px);
21 | transform: translateY(-5px);
22 | }
23 |
--------------------------------------------------------------------------------
/demo/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { BrowserModule } from '@angular/platform-browser';
3 |
4 | import { LightboxModule } from '../src';
5 | import { AppComponent } from './app.component';
6 |
7 | @NgModule({
8 | imports: [ BrowserModule, LightboxModule ],
9 | declarations: [ AppComponent ],
10 | bootstrap: [ AppComponent ]
11 | })
12 | export class AppModule { }
13 |
--------------------------------------------------------------------------------
/demo/img/image1-thumb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image1-thumb.jpg
--------------------------------------------------------------------------------
/demo/img/image1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image1.jpg
--------------------------------------------------------------------------------
/demo/img/image2-thumb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image2-thumb.jpg
--------------------------------------------------------------------------------
/demo/img/image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image2.jpg
--------------------------------------------------------------------------------
/demo/img/image3-thumb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image3-thumb.jpg
--------------------------------------------------------------------------------
/demo/img/image3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image3.jpg
--------------------------------------------------------------------------------
/demo/img/image4-thumb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image4-thumb.jpg
--------------------------------------------------------------------------------
/demo/img/image4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/themyth92/ngx-lightbox/07fdc0e6c52fe0e439a23b98c88c2cda7f55a37a/demo/img/image4.jpg
--------------------------------------------------------------------------------
/demo/main.ts:
--------------------------------------------------------------------------------
1 | import { AppModule } from './app.module';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | platformBrowserDynamic().bootstrapModule(AppModule);
5 |
--------------------------------------------------------------------------------
/demo/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/set';
35 |
36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
37 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
38 |
39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */
40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
41 |
42 |
43 | /** Evergreen browsers require these. **/
44 | // import 'core-js/es6/reflect';
45 | // import 'core-js/es7/reflect';
46 |
47 |
48 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/
49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
50 |
51 |
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 |
59 |
60 | /***************************************************************************************************
61 | * APPLICATION IMPORTS
62 | */
63 |
64 | /**
65 | * Date, currency, decimal and percent pipes.
66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
67 | */
68 | // import 'intl'; // Run `npm install --save intl`.
69 | /**
70 | * Need to import at least one locale-data with intl.
71 | */
72 | // import 'intl/locale-data/jsonp/en';
73 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
25 |
36 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/karma-main.js:
--------------------------------------------------------------------------------
1 | Error.stackTraceLimit = Infinity;
2 | require('core-js/es/reflect');
3 | require('zone.js/dist/zone');
4 | require('zone.js/dist/long-stack-trace-zone');
5 | require('zone.js/dist/proxy');
6 | require('zone.js/dist/sync-test');
7 | require('zone.js/dist/jasmine-patch');
8 | require('zone.js/dist/async-test');
9 | require('zone.js/dist/fake-async-test');
10 | require('rxjs');
11 |
12 | const testing = require('@angular/core/testing');
13 | const browser = require('@angular/platform-browser-dynamic/testing');
14 |
15 | testing.TestBed.initTestEnvironment(
16 | browser.BrowserDynamicTestingModule,
17 | browser.platformBrowserDynamicTesting()
18 | );
19 |
20 | const appContext = require.context('./src', true, /\.spec\.ts/);
21 |
22 | appContext.keys().forEach(appContext);
23 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const webpack = require('webpack');
3 |
4 | module.exports = config => {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | files: [
9 | { pattern: './src/img/*.png', watched: false, included: false, served: true, nocache: false },
10 | { pattern: './karma-main.js', watched: false }
11 | ],
12 | reporters: ['dots'],
13 | port: 9876,
14 | colors: true,
15 | logLevel: config.LOG_INFO,
16 | autoWatch: false,
17 | browsers: ['PhantomJS'],
18 | singleRun: true,
19 | browserConsoleLogOptions: {
20 | terminal: true,
21 | level: 'log'
22 | },
23 | plugins: [
24 | require('karma-jasmine'),
25 | require('karma-phantomjs-launcher'),
26 | require('karma-webpack'),
27 | require('karma-sourcemap-loader'),
28 | require('@angular-devkit/build-angular/plugins/karma')
29 | ],
30 | preprocessors: {
31 | './karma-main.js': ['webpack', 'sourcemap']
32 | },
33 | webpack: {
34 | mode: 'development',
35 | stats: 'errors-only',
36 | resolve: {
37 | modules: [
38 | 'node_modules'
39 | ],
40 | extensions: ['.ts', '.js']
41 | },
42 | devtool: 'inline-source-map',
43 | module: {
44 | rules: [
45 | {
46 | test: /\.ts$/,
47 | loader: 'awesome-typescript-loader',
48 | include: [
49 | path.resolve(__dirname, 'src')
50 | ]
51 | }
52 | ]
53 | },
54 | plugins: [
55 | new webpack.ContextReplacementPlugin(
56 | /@angular(\\|\/)core(\\|\/)src/,
57 | path.resolve(__dirname, '../src')
58 | )
59 | ]
60 | },
61 | webpackServer: {
62 | noInfo: true
63 | },
64 | proxies: {
65 | '/src/img/': '/base/src/img/'
66 | }
67 | });
68 | };
69 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngx-lightbox",
3 | "version": "3.0.0",
4 | "description": "A port >= angular5 for lightbox2",
5 | "main": "index.js",
6 | "dependencies": {
7 | "file-saver": "^2.0.5",
8 | "ngx-filesaver": "14.0.0"
9 | },
10 | "devDependencies": {
11 | "@angular-devkit/build-angular": "^14.0.0",
12 | "@angular/cli": "^14.0.0",
13 | "@angular/common": "^14.0.0",
14 | "@angular/compiler": "^14.0.0",
15 | "@angular/compiler-cli": "^14.0.0",
16 | "@angular/core": "^14.0.0",
17 | "@angular/platform-browser": "^14.0.0",
18 | "@angular/platform-browser-dynamic": "^14.0.0",
19 | "@types/file-saver": "^2.0.5",
20 | "@types/jasmine": "^4.3.0",
21 | "copyfiles": "^2.4.1",
22 | "core-js": "^3.25.3",
23 | "del-cli": "^5.0.0",
24 | "jasmine-core": "^4.4.0",
25 | "karma": "^6.4.1",
26 | "karma-jasmine": "^5.1.0",
27 | "karma-phantomjs-launcher": "^1.0.4",
28 | "karma-sourcemap-loader": "^0.3.8",
29 | "karma-webpack": "^5.0.0",
30 | "ngx-lightbox": "^2.6.2",
31 | "phantomjs-prebuilt": "^2.1.16",
32 | "rxjs": "^7.5.7",
33 | "tslint": "^6.1.3",
34 | "typescript": "4.7.4",
35 | "webpack": "^5.74.0",
36 | "zone.js": "^0.11.8"
37 | },
38 | "scripts": {
39 | "start": "./node_modules/.bin/ng serve",
40 | "build": "./node_modules/.bin/ng build",
41 | "test": " ./node_modules/.bin/ng lint && ./node_modules/.bin/ng test",
42 | "lint": "./node_modules/.bin/ng lint",
43 | "prepublishOnly": "./node_modules/.bin/ngc && ./node_modules/.bin/copyfiles -u 1 src/img/* src/*.js src/*.d.ts src/*.js.map src/*.metadata.json src/*.css .",
44 | "postpublish": "./node_modules/.bin/del '*.{service,component,module,spec,ngfactory}.js' '*.{metadata,ngsummary}.json' index.js webpack.config.js '*.{ts,css,map}' '{compiled,img}' 'src/*.{d.ts,ngfactory.ts,js,map,json}'"
45 | },
46 | "repository": {
47 | "type": "git",
48 | "url": "git+https://github.com/themyth92/ngx-lightbox.git"
49 | },
50 | "keywords": [
51 | "lightbox2",
52 | "angularjs",
53 | "directives",
54 | "lightbox2",
55 | "angular",
56 | "directives"
57 | ],
58 | "author": "themyth92",
59 | "license": "MIT",
60 | "bugs": {
61 | "url": "https://github.com/themyth92/ngx-lightbox/issues"
62 | },
63 | "homepage": "https://github.com/themyth92/ngx-lightbox#readme"
64 | }
65 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export { Lightbox } from './lightbox.service';
2 | export { LightboxConfig } from './lightbox-config.service';
3 | export { LightboxEvent, LIGHTBOX_EVENT, IAlbum, IEvent } from './lightbox-event.service';
4 | export { LightboxModule } from './lightbox.module';
5 |
--------------------------------------------------------------------------------
/src/lightbox-config.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 | @Injectable()
4 | export class LightboxConfig {
5 | public fadeDuration: number;
6 | public resizeDuration: number;
7 | public fitImageInViewPort: boolean;
8 | public positionFromTop: number;
9 | public showImageNumberLabel: boolean;
10 | public alwaysShowNavOnTouchDevices: boolean;
11 | public wrapAround: boolean;
12 | public disableKeyboardNav: boolean;
13 | public disableScrolling: boolean;
14 | public centerVertically: boolean;
15 | public enableTransition: boolean;
16 | public albumLabel: string;
17 | public showZoom: boolean;
18 | public showRotate: boolean;
19 | public showDownloadButton: boolean;
20 | public containerElementResolver: (document: any) => HTMLElement;
21 |
22 | constructor() {
23 | this.fadeDuration = 0.7;
24 | this.resizeDuration = 0.5;
25 | this.fitImageInViewPort = true;
26 | this.positionFromTop = 20;
27 | this.showImageNumberLabel = false;
28 | this.alwaysShowNavOnTouchDevices = false;
29 | this.wrapAround = false;
30 | this.disableKeyboardNav = false;
31 | this.disableScrolling = false;
32 | this.centerVertically = false;
33 | this.enableTransition = true;
34 | this.albumLabel = 'Image %1 of %2';
35 | this.showZoom = false;
36 | this.showRotate = false;
37 | this.containerElementResolver = (documentRef) => documentRef.querySelector('body');
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lightbox-event.service.ts:
--------------------------------------------------------------------------------
1 | import { Observable, Subject } from 'rxjs';
2 |
3 | import { Injectable} from '@angular/core';
4 |
5 | export interface IEvent {
6 | id: number;
7 | data?: any;
8 | }
9 |
10 | export interface IAlbum {
11 | src: string;
12 | caption?: string;
13 | thumb: string;
14 | downloadUrl?: string;
15 | }
16 |
17 | export const LIGHTBOX_EVENT = {
18 | CHANGE_PAGE: 1,
19 | CLOSE: 2,
20 | OPEN: 3,
21 | ZOOM_IN: 4,
22 | ZOOM_OUT: 5,
23 | ROTATE_LEFT: 6,
24 | ROTATE_RIGHT: 7
25 | };
26 |
27 | @Injectable()
28 | export class LightboxEvent {
29 | private _lightboxEventSource: Subject