Giter Club home page Giter Club logo

ngx-image-gallery's Introduction

This project is no longer maintained. Please consider other image galleries.


ngx-image-gallery

Probably the best Angular 4+ modal and inline image gallery. Angular upgrade for ng-image-gallery.

preview

npm npm David preview

Prerequisites

  • Hammerjs (required for swipe)
npm i -S hammerjs lodash

Then import hammerjs into your project (tip: in you main.ts file), e.g:

import 'hammerjs';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
    enableProdMode();
}

document.addEventListener('DOMContentLoaded', () => {
    platformBrowserDynamic().bootstrapModule(AppModule)
        .catch(err => console.log(err));
});

Install

npm install --save @web-aid-kit/ngx-image-gallery

Import

import { NgxImageGalleryModule } from '@web-aid-kit/ngx-image-gallery';

@NgModule({
  ...,
  imports: [
    NgxImageGalleryModule,
    ...
  ]
})
export class AppModule { }

Use

// app.component.html

<ngx-image-gallery 
[images]="images" 
[conf]="conf"
(onOpen)="galleryOpened($event)"
(onClose)="galleryClosed()"
(onImageClicked)="galleryImageClicked($event)"
(onImageChange)="galleryImageChanged($event)"
(onDelete)="deleteImage($event)"
></ngx-image-gallery>

Configure

import { Component, OnInit, ViewChild } from '@angular/core';
import { NgxImageGalleryComponent, GALLERY_IMAGE, GALLERY_CONF } from '@web-aid-kit/ngx-image-gallery';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  // get reference to gallery component
  @ViewChild(NgxImageGalleryComponent) ngxImageGallery: NgxImageGalleryComponent;
  
  // gallery configuration
  conf: GALLERY_CONF = {
    imageOffset: '0px',
    showDeleteControl: false,
    showImageTitle: false,
  };
	
  // gallery images
  images: GALLERY_IMAGE[] = [
    {
      url: "https://images.pexels.com/photos/669013/pexels-photo-669013.jpeg?w=1260", 
      altText: 'woman-in-black-blazer-holding-blue-cup', 
      title: 'woman-in-black-blazer-holding-blue-cup',
      thumbnailUrl: "https://images.pexels.com/photos/669013/pexels-photo-669013.jpeg?w=60"
    },
    {
      url: "https://images.pexels.com/photos/669006/pexels-photo-669006.jpeg?w=1260", 
      altText: 'two-woman-standing-on-the-ground-and-staring-at-the-mountain', 
      extUrl: 'https://www.pexels.com/photo/two-woman-standing-on-the-ground-and-staring-at-the-mountain-669006/',
      thumbnailUrl: "https://images.pexels.com/photos/669006/pexels-photo-669006.jpeg?w=60"
    },
  ];

  constructor(){}

  ngOnInit() {}
	
  // METHODS
  // open gallery
  openGallery(index: number = 0) {
    this.ngxImageGallery.open(index);
  }
	
  // close gallery
  closeGallery() {
    this.ngxImageGallery.close();
  }
	
  // set new active(visible) image in gallery
  newImage(index: number = 0) {
    this.ngxImageGallery.setActiveImage(index);
  }
	
  // next image in gallery
  nextImage(index: number = 0) {
    this.ngxImageGallery.next();
  }
	
  // prev image in gallery
  prevImage(index: number = 0) {
    this.ngxImageGallery.prev();
  }
	
  /**************************************************/
	
  // EVENTS
  // callback on gallery opened
  galleryOpened(index) {
    console.info('Gallery opened at index ', index);
  }

  // callback on gallery closed
  galleryClosed() {
    console.info('Gallery closed.');
  }

  // callback on gallery image clicked
  galleryImageClicked(index) {
    console.info('Gallery image clicked with index ', index);
  }
  
  // callback on gallery image changed
  galleryImageChanged(index) {
    console.info('Gallery image changed to index ', index);
  }

  // callback on user clicked delete button
  deleteImage(index) {
    console.info('Delete image at index ', index);
  }
}

Interfaces

// gallery configuration
export interface GALLERY_CONF {
  imageBorderRadius?: string; // css border radius of image (default 3px)
  imageOffset?: string; // add gap between image and it's container (default 20px)
  imagePointer? :boolean; // show a pointer on image, should be true when handling onImageClick event (default false)
  showDeleteControl?: boolean; // show image delete icon (default false)
  showCloseControl?: boolean; // show gallery close icon (default true)
  showExtUrlControl?: boolean; // show image external url icon (default true)
  showImageTitle?: boolean; // show image title text (default true)
  showThumbnails?: boolean; // show thumbnails (default true)
  closeOnEsc?: boolean; // close gallery on `Esc` button press (default true)
  reactToKeyboard?: boolean; // change image on keyboard arrow press (default true)
  reactToMouseWheel?: boolean; // change image on mouse wheel scroll (default true)
  reactToRightClick?: boolean; // disable right click on gallery (default false)
  thumbnailSize?: number; // thumbnail size (default 30)
  backdropColor?: string; // gallery backdrop (background) color (default rgba(13,13,14,0.85))
  inline?: boolean; // make gallery inline (default false)
  showArrows?: boolean; // show prev / next arrows (default true)
}

// gallery image
export interface GALLERY_IMAGE {
  url: string; // url of the image
  thumbnailUrl?: string; // thumbnail url (recommended), if not present, gallery will use `url` property to get thumbnail image.
  altText?: string; // alt text for image
  title?: string; // title of the image
  extUrl?: string; // external url of image
  extUrlTarget?: string; // external url target e.g. '_blank', '_self' etc.
}

All properties ending with ? are optional.

Make gallery inline

You can make gallery inline like a carousel by setting conf.inline to true but make sure to change conf.backdropColor as well if you need white backdrop color. Also width and height of the gallery can be adjusted by manually applying css styles with !important flag on gallery element.

Dynamic Update

You can update gallery images images and gallery configuration conf anytime you want even when gallery is opened but due to Angular's change detection restrictions you must assign these variable to new value instead of changing internal properties as mentioned below.

// change images
this.images = this.images.concat([...]);

// change conf
this.conf = {...};

ngx-image-gallery's People

Contributors

andresmanuel1 avatar anthonynahas avatar danielcaspers avatar dcarrask avatar jsdelivrbot avatar thatisuday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-image-gallery's Issues

ngx-image-gallery.component.d.ts:24:9 - error TS1086: An accessor cannot be declared in an ambient context.

Hi, I am using this library,

import { NgxImageGalleryComponent, GALLERY_IMAGE, GALLERY_CONF } from "ngx-image-gallery";

I am getting error on terminal::

ERROR in node_modules/ngx-image-gallery/lib/components/ngx-image-gallery/ngx-image-gallery.component.d.ts(24,9): error TS1086: An accessor cannot be declared in an ambient context. node_modules/ngx-image-gallery/lib/components/ngx-image-gallery/ngx-image-gallery.component.d.ts(25,9): error TS1086: An accessor cannot be declared in an ambient context. node_modules/ngx-image-gallery/lib/components/ngx-image-gallery/ngx-image-gallery.component.d.ts(26,9): error TS1086: An accessor cannot be declared in an ambient context. node_modules/ngx-image-gallery/lib/components/ngx-image-gallery/ngx-image-gallery.component.d.ts(27,9): error TS1086: An accessor cannot be declared in an ambient context.

in beforeUpload(UploadMetadata) change the url not effect

Hi, I am trying to add a drifferent request querystring each time.
so i found the beforeUpload( ) fucntion, but is doesn't work.

I view the source code:
image-upload.component.ts -> uploadSingleFile(fileHolder: FileHolder, url = this.url, customForm?: { [name: string]: any })
line 171
this.imageService
.postImage(this.url, fileHolder.file, this.headers, this.partName, customForm, this.withCredentials)

see using [this.url] not the local variable [url]

Allowed Video

Video is not allowed when we tried to render video in the gallery.

Demo and some clarifications

Hi,

This looks really promising, but I'm a little confused about the demo.

I guess the demo is not the same as the one deployed here?

It's not clear how you get reference to this.ngxImageGallery and all the commands are commented out. I can guess it's a ViewChild but those are important details that would be well to put in the demo.

It's also not clear how to use this in any kind of complex multi view or nested route setup since it's a component that needs placing in the root component and direct referencing to work. How would one go about reusing this across the webapp for displaying a gallery regardless from which component I want to do that. It's not a problem for me to setup a service that holds a reference to the component from root but some kind of a provider would be nice to handle these very common scenarios.

Very promising as I said but these either require some explanation in the demo or a general discussion.

Thanks!

Take 100% width

On a phone I obviously set

showArrows: false

but then the arrows are only hidden, and their space is still taken.

How can I get the images to be 100% wide ?

Angular 9 Support

Screenshot from 2020-02-21 15-58-37

`ERROR in node_modules/ngx-image-gallery/index.d.ts:5:22 - error NG6002: Appears in the NgModule.imports , but could not be resolved to an NgModule class

5 export declare class NgxImageGalleryModule{`

popup issue

large image does not opens on first click on second time it opens

Multiple galleries cause arrows to disappear

I am trying to use two galleries to create a lightbox effect. One gallery is inline, the other is not. I have the (onImageClicked) attribute on the inline gallery set to a method that will open the other gallery. In this configuration, the arrows on the inline gallery are not visible, but I can still click them. Also, the close icon is not visible, but is clickable even though I have it set to turn off. The lightbox gallery works fine. Is there a way to fix this?

Please support SSR (server side rendering) - ReferenceError: window is not defined

hi,

i am using the module in my angular v4 app that will be rendered on the server side with nodejs.
Since in NodeJS there is not a window object, document... when i add this module to the app my build crashes!

Error: -->

})(window, document, 'Hammer');
   ^

ReferenceError: window is not defined
    at Object.VERSION

Angular V 4.4.6
Node V 8.9.1

Thank you in advance

Gallery's overlay not always on top

Current behavior

Elements have the possibility to be placed on top of the gallery's overlay.

Expected behavior

The gallery's overlay should always be above all other elements.

Possible solution

Place the overlay at a high level in the DOM.
This behavior is found in the Angular CDK's overlay

Context

The overlay for the gallery is placed at the level it is defined in the DOM. This causes the possibility for other elements to be placed above this overlay. A basic use case I have found is with mat-sidenav/mat-drawer (see demo).

Demo

https://stackblitz.com/edit/ngx-image-gallery-overlay-issue

Dynamically changing the galleryOptions

Hi, is there any way to change the galleryOptions based on some event? In my case I want add the thumbnailActions based on an action, but I am unable to do by updating the model on action. Is there any way to do it dynamically ?

Allow full screen button

It would be great if this library would support full screen mode by clicking a button when the gallery opens (much like clicking F11 on the browser).

Handle errors on images

Is there any way to handle image errors? It would be great if there was an output to tell you, and then you could handle it.
The only error I have is :
Event {isTrusted: true, type: "error", target: img, currentTarget: img, eventPhase: 2, …} on the console.

Adding new images resets the current image index

When modifying the images array (e.g. adding 3 new images to it), the current image index is lost.
While this may be fine - as the array may contain entirely new images unrelated to the previous batch - there is seemingly currently no way of saving the current index then re-applying it, as doing it via setActiveImage right after modifying the array appears to be too early.

No issue. Just a fact

Probably the worst gallery for angular.
30 open issues as old as 3 years and the author asking for maintenance.
Pull requests in queue and -still- linked as a reference in author's home page?
It all sounds like another scam.
Don't hire people just for their presumed portfolio web page. There's a bunch of people who tend to overwhelm their own abilities or simply lie about them.
Better do some deep research.

Scrolling window while hovering gallery

Whenever I hover the mouse cursor over the 'galleria' div element, it seems to disable window scrolling. Is this intentional? I looked around and couldn't see exactly what was causing this behavior.

Regarding popup

First we loading the image list, after click that particular image, then it will open in popup with thumbnail, here we cant able to show image list?

Ability to make the title a part of the displayed image

Currently the title of an image is displayed at the bottom of the screen.
While it can be styled, is difficult to position it relative to the displayed image, e.g. in the bottom right corner.
Having such an option would be very useful.

New npm package?

Hi,

I've seen that the repo maintenance was transferred (?) and that the package is now available in a different npm package name.
@thatisuday can you elaborate on this?
I've seen that this package (2.x) now targets angular 9.
Will it work for 10 and 11?
Is there a way to help maintain it somehow? I'll be happy to assist if possible.

Image not loading when call openGallery

The gallery does not load the first image. When you open it, the loading circuit loads into infinity. I first have to click on a thumb first to load a picture.

Optional stop propogation of mouse events

Hi,
I'm using this great library on my site, but I currently have an issue:
In the following example when clicking the image on the left it should open the galley, which works:
https://israelhiking.osm.org.il/#!/?q=כנסיה%20ביזנטית,%20מועצה%20אזורית%20לכיש
But after that, when interacting with picture to swipe to change it the map below the image moves while it shouldn't (or at least not expected to).
Is there a problem with my site or with this library?

Also the orange line is cut on the top of the screen, not sure why.
Thanks again for a great library!

sanitizing unsafe style value url(SafeValue must use [property]=binding: url('blob:http://localhost:4200/e295517e')

sanitizing unsafe style value url(SafeValue must use [property]=binding: url('blob:http://localhost:4200/e295517e')

@thatisuday @AnthonyNahas
I have problem using images that are just uploaded in the memory. I have tried to sanitize with:
this._images.push({ url: this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(file)), altText: file.name, title: file.name, });

but the url property have to be string and the sanitizer returns SafeUrl. Using only the URL.createObjectURL(file) doesn't work as well.

Angular 5+ support

After install, it warns about @angular/core@^4.0.0 dependency.

[email protected] requires a peer of @angular/core@^4.0.0 but none is installed. You must install peer dependencies yourself.

Error when compiling in AOT compilation

Get the error after compiling to prod.
Angular 8
production build.

ERROR in (1,1): Directive NgxImageGalleryComponent, Property 'onKeyboardInput' is private and only accessible within class 'NgxImageGalleryComponent'. (1,1): Directive NgxImageGalleryComponent, Property 'onWindowResize' is private and only accessible within class 'NgxImageGalleryComponent'.

Make delete icon customizable

At the moment the delete icon is fixed, it's image or color cannot be changed (not in a non-hacky way at least). It would be great if it can be changed to suit the application's theme.

Not working

Hey there,
Component is not working at all, no images are shown and also demo app wont compile.
Be advised that im using latest versions of everything im own project, but your demo app doesnt work at all(with your configs and my configs).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.