galleria.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var domhandler_1 = require("../dom/domhandler");
  15. var Galleria = /** @class */ (function () {
  16. function Galleria(el) {
  17. this.el = el;
  18. this.panelWidth = 600;
  19. this.panelHeight = 400;
  20. this.frameWidth = 60;
  21. this.frameHeight = 40;
  22. this.activeIndex = 0;
  23. this.showFilmstrip = true;
  24. this.autoPlay = true;
  25. this.transitionInterval = 4000;
  26. this.showCaption = true;
  27. this.effectDuration = 500;
  28. this.onImageClicked = new core_1.EventEmitter();
  29. this.onImageChange = new core_1.EventEmitter();
  30. this.stripLeft = 0;
  31. }
  32. Galleria.prototype.ngAfterViewChecked = function () {
  33. if (this.imagesChanged) {
  34. this.stopSlideshow();
  35. this.render();
  36. this.imagesChanged = false;
  37. }
  38. };
  39. Object.defineProperty(Galleria.prototype, "images", {
  40. get: function () {
  41. return this._images;
  42. },
  43. set: function (value) {
  44. this._images = value;
  45. this.imagesChanged = true;
  46. if (this.initialized) {
  47. this.activeIndex = 0;
  48. }
  49. },
  50. enumerable: true,
  51. configurable: true
  52. });
  53. Galleria.prototype.ngAfterViewInit = function () {
  54. this.container = this.el.nativeElement.children[0];
  55. this.panelWrapper = domhandler_1.DomHandler.findSingle(this.el.nativeElement, 'ul.ui-galleria-panel-wrapper');
  56. this.initialized = true;
  57. if (this.showFilmstrip) {
  58. this.stripWrapper = domhandler_1.DomHandler.findSingle(this.container, 'div.ui-galleria-filmstrip-wrapper');
  59. this.strip = domhandler_1.DomHandler.findSingle(this.stripWrapper, 'ul.ui-galleria-filmstrip');
  60. }
  61. if (this.images && this.images.length) {
  62. this.render();
  63. }
  64. };
  65. Galleria.prototype.render = function () {
  66. this.panels = domhandler_1.DomHandler.find(this.panelWrapper, 'li.ui-galleria-panel');
  67. if (this.showFilmstrip) {
  68. this.frames = domhandler_1.DomHandler.find(this.strip, 'li.ui-galleria-frame');
  69. this.stripWrapper.style.width = domhandler_1.DomHandler.width(this.panelWrapper) - 50 + 'px';
  70. this.stripWrapper.style.height = this.frameHeight + 'px';
  71. }
  72. if (this.showCaption) {
  73. this.caption = domhandler_1.DomHandler.findSingle(this.container, 'div.ui-galleria-caption');
  74. this.caption.style.bottom = this.showFilmstrip ? domhandler_1.DomHandler.getOuterHeight(this.stripWrapper, true) + 'px' : 0 + 'px';
  75. this.caption.style.width = domhandler_1.DomHandler.width(this.panelWrapper) + 'px';
  76. }
  77. if (this.autoPlay) {
  78. this.startSlideshow();
  79. }
  80. this.container.style.visibility = 'visible';
  81. };
  82. Galleria.prototype.startSlideshow = function () {
  83. var _this = this;
  84. this.interval = setInterval(function () {
  85. _this.next();
  86. }, this.transitionInterval);
  87. this.slideshowActive = true;
  88. };
  89. Galleria.prototype.stopSlideshow = function () {
  90. if (this.interval) {
  91. clearInterval(this.interval);
  92. }
  93. this.slideshowActive = false;
  94. };
  95. Galleria.prototype.clickNavRight = function () {
  96. if (this.slideshowActive) {
  97. this.stopSlideshow();
  98. }
  99. this.next();
  100. };
  101. Galleria.prototype.clickNavLeft = function () {
  102. if (this.slideshowActive) {
  103. this.stopSlideshow();
  104. }
  105. this.prev();
  106. };
  107. Galleria.prototype.frameClick = function (frame) {
  108. if (this.slideshowActive) {
  109. this.stopSlideshow();
  110. }
  111. this.select(domhandler_1.DomHandler.index(frame), false);
  112. };
  113. Galleria.prototype.prev = function () {
  114. if (this.activeIndex !== 0) {
  115. this.select(this.activeIndex - 1, true);
  116. }
  117. };
  118. Galleria.prototype.next = function () {
  119. if (this.activeIndex !== (this.panels.length - 1)) {
  120. this.select(this.activeIndex + 1, true);
  121. }
  122. else {
  123. this.select(0, false);
  124. this.stripLeft = 0;
  125. }
  126. };
  127. Galleria.prototype.select = function (index, reposition) {
  128. if (index !== this.activeIndex) {
  129. var oldPanel = this.panels[this.activeIndex], newPanel = this.panels[index];
  130. domhandler_1.DomHandler.fadeIn(newPanel, this.effectDuration);
  131. if (this.showFilmstrip) {
  132. var oldFrame = this.frames[this.activeIndex], newFrame = this.frames[index];
  133. if (reposition === undefined || reposition === true) {
  134. var frameLeft = newFrame.offsetLeft, stepFactor = this.frameWidth + parseInt(getComputedStyle(newFrame)['margin-right'], 10), stripLeft = this.strip.offsetLeft, frameViewportLeft = frameLeft + stripLeft, frameViewportRight = frameViewportLeft + this.frameWidth;
  135. if (frameViewportRight > domhandler_1.DomHandler.width(this.stripWrapper))
  136. this.stripLeft -= stepFactor;
  137. else if (frameViewportLeft < 0)
  138. this.stripLeft += stepFactor;
  139. }
  140. }
  141. this.activeIndex = index;
  142. this.onImageChange.emit({ index: index });
  143. }
  144. };
  145. Galleria.prototype.clickImage = function (event, image, i) {
  146. this.onImageClicked.emit({ originalEvent: event, image: image, index: i });
  147. };
  148. Galleria.prototype.ngOnDestroy = function () {
  149. this.stopSlideshow();
  150. };
  151. __decorate([
  152. core_1.Input(),
  153. __metadata("design:type", Object)
  154. ], Galleria.prototype, "style", void 0);
  155. __decorate([
  156. core_1.Input(),
  157. __metadata("design:type", String)
  158. ], Galleria.prototype, "styleClass", void 0);
  159. __decorate([
  160. core_1.Input(),
  161. __metadata("design:type", Number)
  162. ], Galleria.prototype, "panelWidth", void 0);
  163. __decorate([
  164. core_1.Input(),
  165. __metadata("design:type", Number)
  166. ], Galleria.prototype, "panelHeight", void 0);
  167. __decorate([
  168. core_1.Input(),
  169. __metadata("design:type", Number)
  170. ], Galleria.prototype, "frameWidth", void 0);
  171. __decorate([
  172. core_1.Input(),
  173. __metadata("design:type", Number)
  174. ], Galleria.prototype, "frameHeight", void 0);
  175. __decorate([
  176. core_1.Input(),
  177. __metadata("design:type", Number)
  178. ], Galleria.prototype, "activeIndex", void 0);
  179. __decorate([
  180. core_1.Input(),
  181. __metadata("design:type", Boolean)
  182. ], Galleria.prototype, "showFilmstrip", void 0);
  183. __decorate([
  184. core_1.Input(),
  185. __metadata("design:type", Boolean)
  186. ], Galleria.prototype, "autoPlay", void 0);
  187. __decorate([
  188. core_1.Input(),
  189. __metadata("design:type", Number)
  190. ], Galleria.prototype, "transitionInterval", void 0);
  191. __decorate([
  192. core_1.Input(),
  193. __metadata("design:type", Boolean)
  194. ], Galleria.prototype, "showCaption", void 0);
  195. __decorate([
  196. core_1.Input(),
  197. __metadata("design:type", Number)
  198. ], Galleria.prototype, "effectDuration", void 0);
  199. __decorate([
  200. core_1.Output(),
  201. __metadata("design:type", Object)
  202. ], Galleria.prototype, "onImageClicked", void 0);
  203. __decorate([
  204. core_1.Output(),
  205. __metadata("design:type", Object)
  206. ], Galleria.prototype, "onImageChange", void 0);
  207. __decorate([
  208. core_1.Input(),
  209. __metadata("design:type", Array),
  210. __metadata("design:paramtypes", [Array])
  211. ], Galleria.prototype, "images", null);
  212. Galleria = __decorate([
  213. core_1.Component({
  214. selector: 'p-galleria',
  215. template: "\n <div [ngClass]=\"{'ui-galleria ui-widget ui-widget-content ui-corner-all':true}\" [ngStyle]=\"style\" [class]=\"styleClass\" [style.width.px]=\"panelWidth\">\n <ul class=\"ui-galleria-panel-wrapper\" [style.width.px]=\"panelWidth\" [style.height.px]=\"panelHeight\">\n <li *ngFor=\"let image of images;let i=index\" class=\"ui-galleria-panel\" [ngClass]=\"{'ui-helper-hidden':i!=activeIndex}\"\n [style.width.px]=\"panelWidth\" [style.height.px]=\"panelHeight\" (click)=\"clickImage($event,image,i)\">\n <img class=\"ui-panel-images\" [src]=\"image.source\" [alt]=\"image.alt\" [title]=\"image.title\"/>\n </li>\n </ul>\n <div [ngClass]=\"{'ui-galleria-filmstrip-wrapper':true}\" *ngIf=\"showFilmstrip\">\n <ul class=\"ui-galleria-filmstrip\" style=\"transition:left 1s\" [style.left.px]=\"stripLeft\">\n <li #frame *ngFor=\"let image of images;let i=index\" [ngClass]=\"{'ui-galleria-frame-active':i==activeIndex}\" class=\"ui-galleria-frame\" (click)=\"frameClick(frame)\"\n [style.width.px]=\"frameWidth\" [style.height.px]=\"frameHeight\" [style.transition]=\"'opacity 0.75s ease'\">\n <div class=\"ui-galleria-frame-content\">\n <img [src]=\"image.source\" [alt]=\"image.alt\" [title]=\"image.title\" class=\"ui-galleria-frame-image\"\n [style.width.px]=\"frameWidth\" [style.height.px]=\"frameHeight\">\n </div>\n </li>\n </ul>\n </div>\n <div class=\"ui-galleria-nav-prev pi pi-fw pi-chevron-left\" (click)=\"clickNavLeft()\" [style.bottom.px]=\"frameHeight/2\" *ngIf=\"activeIndex !== 0\"></div>\n <div class=\"ui-galleria-nav-next pi pi-fw pi-chevron-right\" (click)=\"clickNavRight()\" [style.bottom.px]=\"frameHeight/2\"></div>\n <div class=\"ui-galleria-caption\" *ngIf=\"showCaption&&images\" style=\"display:block\">\n <h4>{{images[activeIndex]?.title}}</h4><p>{{images[activeIndex]?.alt}}</p>\n </div>\n </div>\n "
  216. }),
  217. __metadata("design:paramtypes", [core_1.ElementRef])
  218. ], Galleria);
  219. return Galleria;
  220. }());
  221. exports.Galleria = Galleria;
  222. var GalleriaModule = /** @class */ (function () {
  223. function GalleriaModule() {
  224. }
  225. GalleriaModule = __decorate([
  226. core_1.NgModule({
  227. imports: [common_1.CommonModule],
  228. exports: [Galleria],
  229. declarations: [Galleria]
  230. })
  231. ], GalleriaModule);
  232. return GalleriaModule;
  233. }());
  234. exports.GalleriaModule = GalleriaModule;
  235. //# sourceMappingURL=galleria.js.map