module.exports = function (app) { app.directive("gFotorama", function () { return { restrict: "A", link: function (scope, element, attrs) { element.addClass('fotorama'); var $fotorama = $(element.fotorama()); var fotorama = $fotorama.data('fotorama'); fotorama.setOptions({ width: "100%", maxheight: 500, loop: true, nav: "thumbs" }); //$fotorama.on('fotorama:show', function (e, fotorama, extra) { $fotorama.on('fotorama:error', function (e, fotorama, extra) { console.log('## ' + e.type); console.log('active frame', fotorama.activeFrame); console.log('additional data', extra); }); scope.$watch(attrs.gFotorama, function (value) { console.log(value); fotorama.load(value); }); } } }); app.controller("GalleryPageController", function ($scope, api) { $scope.years = []; var years = [2015, 2014, 2013, 2012, 2011, 2010]; years.forEach(function (year, year_index) { api.gallery.year(year) .success(function (albums) { if(albums.length) { $scope.years[year_index] = { year: year, albums: albums.map(function (album) { var preview = album.content[0]; album.preview_url = preview.content.medium.url; //album.fotorama = album.content.map(productToFotorama); return album; }) }; } }) }); } ); app.controller("AlbumPageController", function ($scope, $http, $routeParams, api) { api.gallery.album( $routeParams.year, $routeParams.course, $routeParams.album ) .success(function (album) { var preview = album.content[0]; album.preview_url = preview.content.medium.url; //album.fotorama = album.content.map(productToFotorama); $scope.album = album; }); }); }; function productToFotorama(product) { //var tpl = '

' + product.author + '

' + product.authorAge + ' лет

'; var $e = $('
'); var $c = $e.find('.album-item div'); $('

').text(product.author).appendTo($c); if(product['authorAge']) { $('

').text(product['authorAge'] + ' лет').appendTo($c); } return { img: product.content["big"].url, thumb: product.content["small"].url, full: product.content["original"].url, //html: $.parseHTML(tpl)[0] html: $e }; }