2015-12-02 20:03:10 +01:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
2017-05-29 20:03:59 +02:00
|
|
|
/* jshint validthis: true */
|
2015-12-02 20:03:10 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
2017-05-29 20:03:59 +02:00
|
|
|
* sgZoomableImage - Show the image fullscreen when clicking on the image inside the container.
|
2015-12-02 20:03:10 +01:00
|
|
|
* @memberof SOGo.MailerUI
|
|
|
|
* @restrict attribute
|
|
|
|
* @ngInject
|
|
|
|
* @example:
|
|
|
|
|
2017-05-29 20:03:59 +02:00
|
|
|
<div sg-zoomable-image="$index">
|
2015-12-02 20:03:10 +01:00
|
|
|
<md-card>
|
|
|
|
<img src="foo.png">
|
|
|
|
</md-card>
|
|
|
|
</div>
|
|
|
|
*/
|
|
|
|
function sgZoomableImage() {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2017-05-29 20:03:59 +02:00
|
|
|
bindToController: {
|
|
|
|
partIndex: '=sgZoomableImage'
|
|
|
|
},
|
|
|
|
controller: sgZoomableImageController
|
2015-12-02 20:03:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function link(scope, iElement, attrs, ctrl) {
|
|
|
|
var parentNode = iElement.parent(),
|
2017-05-29 20:03:59 +02:00
|
|
|
imgElement, showImage, toggleClass;
|
|
|
|
|
|
|
|
imgElement = iElement.find('img');
|
2015-12-02 20:03:10 +01:00
|
|
|
|
|
|
|
toggleClass = function(event) {
|
|
|
|
if (event.target.tagName == 'IMG')
|
|
|
|
parentNode.toggleClass('sg-zoom');
|
|
|
|
};
|
|
|
|
|
2017-05-29 20:03:59 +02:00
|
|
|
showImage = function(event) {
|
|
|
|
if (event.target.tagName == 'IMG')
|
|
|
|
ctrl.showGallery(event, imgElement[0].src);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (imgElement.length)
|
|
|
|
ctrl.addImage(imgElement[0].src);
|
|
|
|
|
|
|
|
iElement.on('click', showImage);
|
2015-12-02 20:03:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-29 20:03:59 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
sgZoomableImageController.$inject = ['$element', 'ImageGallery'];
|
|
|
|
function sgZoomableImageController($element, ImageGallery) {
|
|
|
|
var $ctrl = this;
|
|
|
|
|
|
|
|
this.$postLink = function() {
|
|
|
|
ImageGallery.registerImage($element);
|
|
|
|
$element.on('click', this.showImage);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.showImage = function($event) {
|
|
|
|
if ($event.target.tagName == 'IMG')
|
|
|
|
ImageGallery.showGallery($event, $ctrl.partIndex);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:03:10 +01:00
|
|
|
angular
|
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.directive('sgZoomableImage', sgZoomableImage);
|
|
|
|
})();
|