2014-11-25 11:00:21 -05:00
|
|
|
define [
|
|
|
|
"base"
|
2014-11-26 11:18:39 -05:00
|
|
|
"ide/pdfng/directives/pdfViewer"
|
2014-11-25 11:00:21 -05:00
|
|
|
], (
|
|
|
|
App
|
2014-11-26 11:18:39 -05:00
|
|
|
pdfViewer
|
2016-07-20 07:58:32 -04:00
|
|
|
|
2014-11-25 11:00:21 -05:00
|
|
|
) ->
|
2015-02-12 06:32:27 -05:00
|
|
|
App.directive "pdfng", ["$timeout", "localStorage", ($timeout, localStorage) ->
|
2014-11-25 11:00:21 -05:00
|
|
|
return {
|
|
|
|
scope: {
|
|
|
|
"pdfSrc": "="
|
|
|
|
"highlights": "="
|
|
|
|
"position": "="
|
|
|
|
"dblClickCallback": "="
|
|
|
|
}
|
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
scope.loading = false
|
2014-11-28 10:08:24 -05:00
|
|
|
scope.pleaseJumpTo = null
|
|
|
|
scope.scale = null
|
2014-11-25 11:00:21 -05:00
|
|
|
initializedPosition = false
|
|
|
|
initializePosition = () ->
|
|
|
|
return if initializedPosition
|
|
|
|
initializedPosition = true
|
|
|
|
|
2015-02-12 06:32:27 -05:00
|
|
|
if (scale = localStorage("pdf.scale"))?
|
2014-11-26 11:18:59 -05:00
|
|
|
scope.scale = { scaleMode: scale.scaleMode, scale: +scale.scale}
|
2014-11-25 11:00:21 -05:00
|
|
|
else
|
|
|
|
scope.scale = { scaleMode: 'scale_mode_fit_width' }
|
|
|
|
|
2015-02-12 06:32:27 -05:00
|
|
|
if (position = localStorage("pdf.position.#{attrs.key}"))
|
2016-06-14 07:32:54 -04:00
|
|
|
scope.position =
|
|
|
|
page: +position.page,
|
|
|
|
offset:
|
|
|
|
"top": +position.offset.top
|
|
|
|
"left": +position.offset.left
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-05 14:40:33 -05:00
|
|
|
scope.$on "$destroy", () =>
|
2015-02-12 06:32:27 -05:00
|
|
|
localStorage "pdf.scale", scope.scale
|
|
|
|
localStorage "pdf.position.#{attrs.key}", scope.position
|
2014-12-05 14:40:33 -05:00
|
|
|
|
2014-11-25 11:00:21 -05:00
|
|
|
$(window).unload () =>
|
2015-02-12 06:32:27 -05:00
|
|
|
localStorage "pdf.scale", scope.scale
|
|
|
|
localStorage "pdf.position.#{attrs.key}", scope.position
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
flashControls = () ->
|
2015-01-23 11:58:53 -05:00
|
|
|
scope.$evalAsync () ->
|
|
|
|
scope.flashControls = true
|
|
|
|
$timeout () ->
|
|
|
|
scope.flashControls = false
|
|
|
|
, 1000
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-05 09:33:06 -05:00
|
|
|
scope.$on 'pdfDoubleClick', (event, e) ->
|
|
|
|
scope.dblClickCallback?(page: e.page - 1, offset: { top: e.y, left: e.x })
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-08 10:32:16 -05:00
|
|
|
scope.$on 'flash-controls', () ->
|
|
|
|
flashControls()
|
|
|
|
|
2014-11-25 11:00:21 -05:00
|
|
|
scope.$watch "pdfSrc", (url) ->
|
|
|
|
if url
|
|
|
|
scope.loading = true
|
2016-07-01 12:00:06 -04:00
|
|
|
scope.loaded = false
|
2016-07-05 08:09:50 -04:00
|
|
|
scope.progress = 1
|
2014-11-25 11:00:21 -05:00
|
|
|
initializePosition()
|
|
|
|
flashControls()
|
2016-07-05 08:11:11 -04:00
|
|
|
|
2014-12-08 12:48:57 -05:00
|
|
|
scope.$on "loaded", () ->
|
2016-07-01 12:00:06 -04:00
|
|
|
scope.loaded = true
|
2015-01-26 08:41:28 -05:00
|
|
|
scope.progress = 100
|
2015-01-23 11:58:53 -05:00
|
|
|
$timeout () ->
|
|
|
|
scope.loading = false
|
|
|
|
delete scope.progress
|
2016-07-01 12:00:06 -04:00
|
|
|
, 500
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
scope.fitToHeight = () ->
|
2014-11-26 11:52:54 -05:00
|
|
|
scale = angular.copy (scope.scale)
|
|
|
|
scale.scaleMode = 'scale_mode_fit_height'
|
|
|
|
scope.scale = scale
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
scope.fitToWidth = () ->
|
2014-11-26 11:52:54 -05:00
|
|
|
scale = angular.copy (scope.scale)
|
|
|
|
scale.scaleMode = 'scale_mode_fit_width'
|
|
|
|
scope.scale = scale
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
scope.zoomIn = () ->
|
2014-11-26 11:52:54 -05:00
|
|
|
scale = angular.copy (scope.scale)
|
|
|
|
scale.scaleMode = 'scale_mode_value'
|
|
|
|
scale.scale = scale.scale * 1.2
|
|
|
|
scope.scale = scale
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
scope.zoomOut = () ->
|
2014-11-26 11:52:54 -05:00
|
|
|
scale = angular.copy (scope.scale)
|
|
|
|
scale.scaleMode = 'scale_mode_value'
|
|
|
|
scale.scale = scale.scale / 1.2
|
|
|
|
scope.scale = scale
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
if attrs.resizeOn?
|
|
|
|
for event in attrs.resizeOn.split(",")
|
|
|
|
scope.$on event, (e) ->
|
2014-12-02 06:42:57 -05:00
|
|
|
#console.log 'got a resize event', event, e
|
2014-12-08 12:00:26 -05:00
|
|
|
|
|
|
|
scope.$on 'progress', (event, progress) ->
|
|
|
|
scope.$apply () ->
|
2016-07-01 12:00:06 -04:00
|
|
|
return if scope.loaded
|
2014-12-08 12:00:26 -05:00
|
|
|
scope.progress = Math.floor(progress.loaded/progress.total*100)
|
2015-01-23 11:58:53 -05:00
|
|
|
scope.progress = 100 if scope.progress > 100
|
|
|
|
scope.progress = 0 if scope.progress < 0
|
|
|
|
|
|
|
|
scope.$on '$destroy', () ->
|
|
|
|
# console.log 'pdfjs destroy event'
|
2014-11-25 11:00:21 -05:00
|
|
|
|
|
|
|
template: """
|
2014-12-05 09:33:06 -05:00
|
|
|
<div data-pdf-viewer class="pdfjs-viewer" pdf-src='pdfSrc' position='position' scale='scale' highlights='highlights' please-jump-to='pleaseJumpTo'></div>
|
2014-11-25 11:00:21 -05:00
|
|
|
<div class="pdfjs-controls" ng-class="{'flash': flashControls }">
|
|
|
|
<div class="btn-group">
|
|
|
|
<a href
|
|
|
|
class="btn btn-info btn-lg"
|
|
|
|
ng-click="fitToWidth()"
|
|
|
|
tooltip="Fit to Width"
|
|
|
|
tooltip-append-to-body="true"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
>
|
|
|
|
<i class="fa fa-fw fa-arrows-h"></i>
|
|
|
|
</a>
|
|
|
|
<a href
|
|
|
|
class="btn btn-info btn-lg"
|
|
|
|
ng-click="fitToHeight()"
|
|
|
|
tooltip="Fit to Height"
|
|
|
|
tooltip-append-to-body="true"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
>
|
|
|
|
<i class="fa fa-fw fa-arrows-v"></i>
|
|
|
|
</a>
|
|
|
|
<a href
|
|
|
|
class="btn btn-info btn-lg"
|
|
|
|
ng-click="zoomIn()"
|
|
|
|
tooltip="Zoom In"
|
|
|
|
tooltip-append-to-body="true"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
>
|
|
|
|
<i class="fa fa-fw fa-search-plus"></i>
|
|
|
|
</a>
|
|
|
|
<a href
|
|
|
|
class="btn btn-info btn-lg"
|
|
|
|
ng-click="zoomOut()"
|
|
|
|
tooltip="Zoom Out"
|
|
|
|
tooltip-append-to-body="true"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
>
|
|
|
|
<i class="fa fa-fw fa-search-minus"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2014-12-08 12:00:26 -05:00
|
|
|
<div class="progress-thin" ng-show="loading">
|
|
|
|
<div class="progress-bar" ng-style="{ 'width': progress + '%' }"></div>
|
|
|
|
</div>
|
2014-11-25 11:00:21 -05:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
]
|