| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /* eslint-disable
- max-len,
- no-cond-assign,
- no-return-assign,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS101: Remove unnecessary use of Array.from
- * DS102: Remove unnecessary code created because of implicit returns
- * DS207: Consider shorter variations of null checks
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- import App from '../../../base'
- import './pdfViewer'
- export default App.directive('pdfng', ($timeout, localStorage) => ({
- scope: {
- pdfSrc: '=',
- highlights: '=',
- position: '=',
- dblClickCallback: '='
- },
- link(scope, element, attrs) {
- scope.loading = false
- scope.pleaseJumpTo = null
- scope.scale = null
- let initializedPosition = false
- const initializePosition = function() {
- let position, scale
- if (initializedPosition) {
- return
- }
- initializedPosition = true
- if ((scale = localStorage('pdf.scale')) != null) {
- scope.scale = { scaleMode: scale.scaleMode, scale: +scale.scale }
- } else {
- scope.scale = { scaleMode: 'scale_mode_fit_width' }
- }
- if ((position = localStorage(`pdf.position.${attrs.key}`))) {
- scope.position = {
- page: +position.page,
- offset: {
- top: +position.offset.top,
- left: +position.offset.left
- }
- }
- }
- scope.$on('$destroy', () => {
- localStorage('pdf.scale', scope.scale)
- return localStorage(`pdf.position.${attrs.key}`, scope.position)
- })
- return $(window).unload(() => {
- localStorage('pdf.scale', scope.scale)
- return localStorage(`pdf.position.${attrs.key}`, scope.position)
- })
- }
- const flashControls = () =>
- scope.$evalAsync(function() {
- scope.flashControls = true
- return $timeout(() => (scope.flashControls = false), 1000)
- })
- scope.$on(
- 'pdfDoubleClick',
- (event, e) =>
- typeof scope.dblClickCallback === 'function'
- ? scope.dblClickCallback({
- page: e.page - 1,
- offset: { top: e.y, left: e.x }
- })
- : undefined
- )
- scope.$on('flash-controls', () => flashControls())
- scope.$watch('pdfSrc', function(url) {
- if (url) {
- scope.loading = true
- scope.loaded = false
- scope.progress = 1
- initializePosition()
- return flashControls()
- }
- })
- scope.$on('loaded', function() {
- scope.loaded = true
- scope.progress = 100
- return $timeout(function() {
- scope.loading = false
- return delete scope.progress
- }, 500)
- })
- scope.fitToHeight = function() {
- const scale = angular.copy(scope.scale)
- scale.scaleMode = 'scale_mode_fit_height'
- return (scope.scale = scale)
- }
- scope.fitToWidth = function() {
- const scale = angular.copy(scope.scale)
- scale.scaleMode = 'scale_mode_fit_width'
- return (scope.scale = scale)
- }
- scope.zoomIn = function() {
- const scale = angular.copy(scope.scale)
- scale.scaleMode = 'scale_mode_value'
- scale.scale = scale.scale * 1.2
- return (scope.scale = scale)
- }
- scope.zoomOut = function() {
- const scale = angular.copy(scope.scale)
- scale.scaleMode = 'scale_mode_value'
- scale.scale = scale.scale / 1.2
- return (scope.scale = scale)
- }
- if (attrs.resizeOn != null) {
- for (let event of Array.from(attrs.resizeOn.split(','))) {
- scope.$on(event, function(e) {})
- }
- }
- // console.log 'got a resize event', event, e
- scope.$on('progress', (event, progress) =>
- scope.$apply(function() {
- if (scope.loaded) {
- return
- }
- scope.progress = Math.floor((progress.loaded / progress.total) * 100)
- if (scope.progress > 100) {
- scope.progress = 100
- }
- if (scope.progress < 0) {
- return (scope.progress = 0)
- }
- })
- )
- return scope.$on('$destroy', function() {})
- },
- // console.log 'pdfjs destroy event'
- template: `\
- <div data-pdf-viewer class="pdfjs-viewer" pdf-src='pdfSrc' position='position' scale='scale' highlights='highlights' please-jump-to='pleaseJumpTo'></div>
- <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>
- <div class="progress-thin" ng-show="loading">
- <div class="progress-bar" ng-style="{ 'width': progress + '%' }"></div>
- </div>\
- `
- }))
|