diff --git a/dist/angular-thumbnails.js b/dist/angular-thumbnails.js index 46e9a46..8e793df 100644 --- a/dist/angular-thumbnails.js +++ b/dist/angular-thumbnails.js @@ -104,7 +104,7 @@ return { restrict: "E", scope: { - source: "=", + source: "@", scale: "=", fileType: "@", maxHeight: "@", diff --git a/dist/angular-thumbnails.min.js b/dist/angular-thumbnails.min.js index cbc18a4..528fab2 100644 --- a/dist/angular-thumbnails.min.js +++ b/dist/angular-thumbnails.min.js @@ -1 +1 @@ -!function(){"use strict";function PaginationStatus(currentPage,totalPages){var _currentPage=parseInt(currentPage,10),_totalPages=parseInt(totalPages,10);return this.currentPage=function(){return _currentPage},this.nextPage=function(){_currentPage>=_totalPages||(_currentPage+=1)},this.previousPage=function(){1!==_currentPage&&(_currentPage-=1)},this}function RenderViewport(height,width,scale,rotation){var _height=height,_width=width,_rotation=rotation||0;return this.adjustCanvasDimensions=function(height,width,canvas){var ratio=width/height;height>_height&&(height=_height,width=height*ratio),width>_width&&(width=_width,height=width/ratio),canvas.height=height,canvas.width=width},this.rotateClockwise=function(){_rotation+=90},this.rotateCounterClockwise=function(){_rotation-=90},this.getRotation=function(){return _rotation},this}function PdfRenderer(scope,canvas){var pdfDoc=null,renderPage=function(pagination){pdfDoc.getPage(pagination.currentPage()).then(function(page){var viewport=page.getViewport(parseInt(scope.scale,10)||1,0),targetViewport=new RenderViewport(scope.maxHeight||viewport.height,scope.maxWidth||viewport.width);targetViewport.adjustCanvasDimensions(viewport.height,viewport.width,canvas),page.render({canvasContext:canvas.getContext("2d"),viewport:page.getViewport(canvas.height/viewport.height,targetViewport.getRotation())})})};return this.render=function(){scope.source&&(PDFJS.disableWorker=!0,PDFJS.getDocument(scope.source,null,null,scope.onProgress).then(function(_pdfDoc){pdfDoc=_pdfDoc,scope.$apply(function(){renderPage(new PaginationStatus(scope.pageNum||1,pdfDoc.numPages))})},function(error){console.log(error)}))},this}function VideoRenderer(scope,container,canvas){return this.render=function(){var video=document.createElement("video");video.setAttribute("style","display: none"),video.addEventListener("canplay",function(){new RenderViewport(scope.maxHeight||video.videoHeight,scope.maxWidth||video.videoWidth).adjustCanvasDimensions(video.videoHeight,video.videoWidth,canvas),scope.$apply(function(){canvas.getContext("2d").drawImage(video,0,0,video.videoWidth,video.videoHeight,0,0,canvas.width,canvas.height)})}),container.append(video),video.src=scope.source},this}function ImgRenderer(scope,canvas){return this.render=function(){var img=new Image;img.addEventListener("load",function(){scope.$apply(function(){new RenderViewport(scope.maxHeight||img.height,scope.maxWidth||img.width).adjustCanvasDimensions(img.height,img.width,canvas),canvas.getContext("2d").drawImage(img,0,0,img.width,img.height,0,0,canvas.width,canvas.height)})},!1),img.src=scope.source},this}angular.module("angular-thumbnails",[]).directive("thumbnail",function($window){return{restrict:"E",scope:{source:"=",scale:"=",fileType:"@",maxHeight:"@",maxWidth:"@"},link:function(scope,element,attrs){var canvas=document.createElement("canvas"),renderer=null,renderFunc=function(){renderer&&renderer.render()};element.append(canvas),"pdf"===scope.fileType?renderer=new PdfRenderer(scope,canvas):"image"===scope.fileType?renderer=new ImgRenderer(scope,canvas):"video"===scope.fileType&&(renderer=new VideoRenderer(scope,element,canvas)),scope.$watch("source + fileType + scale + maxHeight + maxWidth",renderFunc)}}})}(); \ No newline at end of file +!function(){"use strict";function PaginationStatus(currentPage,totalPages){var _currentPage=parseInt(currentPage,10),_totalPages=parseInt(totalPages,10);return this.currentPage=function(){return _currentPage},this.nextPage=function(){_currentPage>=_totalPages||(_currentPage+=1)},this.previousPage=function(){1!==_currentPage&&(_currentPage-=1)},this}function RenderViewport(height,width,scale,rotation){var _height=height,_width=width,_rotation=rotation||0;return this.adjustCanvasDimensions=function(height,width,canvas){var ratio=width/height;height>_height&&(height=_height,width=height*ratio),width>_width&&(width=_width,height=width/ratio),canvas.height=height,canvas.width=width},this.rotateClockwise=function(){_rotation+=90},this.rotateCounterClockwise=function(){_rotation-=90},this.getRotation=function(){return _rotation},this}function PdfRenderer(scope,canvas){var pdfDoc=null,renderPage=function(pagination){pdfDoc.getPage(pagination.currentPage()).then(function(page){var viewport=page.getViewport(parseInt(scope.scale,10)||1,0),targetViewport=new RenderViewport(scope.maxHeight||viewport.height,scope.maxWidth||viewport.width);targetViewport.adjustCanvasDimensions(viewport.height,viewport.width,canvas),page.render({canvasContext:canvas.getContext("2d"),viewport:page.getViewport(canvas.height/viewport.height,targetViewport.getRotation())})})};return this.render=function(){scope.source&&(PDFJS.disableWorker=!0,PDFJS.getDocument(scope.source,null,null,scope.onProgress).then(function(_pdfDoc){pdfDoc=_pdfDoc,scope.$apply(function(){renderPage(new PaginationStatus(scope.pageNum||1,pdfDoc.numPages))})},function(error){console.log(error)}))},this}function VideoRenderer(scope,container,canvas){return this.render=function(){var video=document.createElement("video");video.setAttribute("style","display: none"),video.addEventListener("canplay",function(){new RenderViewport(scope.maxHeight||video.videoHeight,scope.maxWidth||video.videoWidth).adjustCanvasDimensions(video.videoHeight,video.videoWidth,canvas),scope.$apply(function(){canvas.getContext("2d").drawImage(video,0,0,video.videoWidth,video.videoHeight,0,0,canvas.width,canvas.height)})}),container.append(video),video.src=scope.source},this}function ImgRenderer(scope,canvas){return this.render=function(){var img=new Image;img.addEventListener("load",function(){scope.$apply(function(){new RenderViewport(scope.maxHeight||img.height,scope.maxWidth||img.width).adjustCanvasDimensions(img.height,img.width,canvas),canvas.getContext("2d").drawImage(img,0,0,img.width,img.height,0,0,canvas.width,canvas.height)})},!1),img.src=scope.source},this}angular.module("angular-thumbnails",[]).directive("thumbnail",function($window){return{restrict:"E",scope:{source:"@",scale:"=",fileType:"@",maxHeight:"@",maxWidth:"@"},link:function(scope,element,attrs){var canvas=document.createElement("canvas"),renderer=null,renderFunc=function(){renderer&&renderer.render()};element.append(canvas),"pdf"===scope.fileType?renderer=new PdfRenderer(scope,canvas):"image"===scope.fileType?renderer=new ImgRenderer(scope,canvas):"video"===scope.fileType&&(renderer=new VideoRenderer(scope,element,canvas)),scope.$watch("source + fileType + scale + maxHeight + maxWidth",renderFunc)}}})}(); \ No newline at end of file diff --git a/src/angular-thumbnails.js b/src/angular-thumbnails.js index 6c41478..63434e7 100644 --- a/src/angular-thumbnails.js +++ b/src/angular-thumbnails.js @@ -167,7 +167,7 @@ return { restrict: 'E', scope: { - 'source': '=', + 'source': '@', 'scale': '=', 'fileType': '@', 'maxHeight': '@',