/** * Created by NICK on 15/10/13. * email:nick121212@126.com * qq:289412378 * copyright NICK */ import ref = require('ref'); import common = require('common/common/controller/base_material_controller'); import popup = require('common/common/controller/popup_material_controller'); export class LightboxProvider extends common.BaseController { public static _name:string = "lightbox"; public static provider:Array = [()=> { var provider:angular.IServiceProvider = { $get: ['$rootScope', '$mdDialog', ($rootScope, $mdDialog)=> { function showImage(index, images, $event) { var dialogOptions:ng.material.IDialogOptions = {}; dialogOptions.controller = 'LightboxController'; dialogOptions.controllerAs = 'lightboxCtl'; dialogOptions.template = "\n" + " \n" + //" \n" + //" \n" + //" \n" + " \n" + "\n" + "
\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "
\n" + "
"; dialogOptions.targetEvent = $event; dialogOptions.clickOutsideToClose = true; dialogOptions.resolve = { 'images': ()=> { return images; }, 'index': ()=> { return index || 0; } }; $mdDialog.show(dialogOptions); } return { showImage: showImage }; }] }; return provider; }]; } export class LightboxController extends popup.PopupController { public static $inject = ['$rootScope', '$scope', '$q', '$mdToast', '$mdDialog', 'images', 'index']; public static _name = 'LightboxController'; private images:Array; private index:number; constructor() { super(arguments); } prev() { if (this.index == 0) { this.index = this.images.length - 1; return; } this.index--; } next() { if (this.index == this.images.length - 1) { this.index = 0; return; } this.index++; } } export class LightboxDirective extends common.BaseController { public static _name:string = "lightbox"; public static directive:Array = ['$rootScope', 'lightbox', ($rootScope, lightbox) => { var directive:ng.IDirective = { require: '^?ngModel', scope: true, replace: true, }; directive.link = ($scope, $element, $attrs, $ctrl)=> { $rootScope.$on('showImages', function (event, data) { lightbox.showImage(data.index, data.images, data.$event); }); }; return directive; }]; }