Merge pull request #1414 from sharelatex/as-fix-pdf-link-referrer

Fix links in PDF to have noreferrer

GitOrigin-RevId: fa14e552b0d4947781c88ce22fc70696b04cf8a4
This commit is contained in:
Timothée Alby 2019-01-17 15:55:41 +01:00 committed by sharelatex
parent 837302327e
commit 7d5f3537df

View file

@ -1,30 +1,11 @@
/* eslint-disable
max-len,
no-return-assign,
no-undef,
no-unreachable,
*/
// 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
* DS205: Consider reworking code to avoid use of IIFEs
* DS206: Consider reworking classes to avoid initClass
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base'], App =>
// App = angular.module 'pdfAnnotations', []
App.factory('pdfAnnotations', [
function() {
let pdfAnnotations
return (pdfAnnotations = (function() {
pdfAnnotations = class pdfAnnotations {
static initClass() {
this.EXTERNAL_LINK_TARGET = '_blank'
}
/* global PDFJS */
define(['base'], App => {
const EXTERNAL_LINK_TARGET = '_blank'
const REL_NOOPENER = 'noreferrer noopener'
App.factory('pdfAnnotations', function() {
class pdfAnnotations {
constructor(options) {
this.annotationsLayerDiv = options.annotations
this.viewport = options.viewport
@ -32,28 +13,24 @@ define(['base'], App =>
}
setAnnotations(annotations) {
return (() => {
const result = []
for (let annotation of Array.from(annotations)) {
for (let annotation of annotations) {
switch (annotation.subtype) {
case 'Link':
result.push(this.addLink(annotation))
break
case 'Text':
continue
break
default:
result.push(undefined)
}
}
return result
})()
}
addLink(link) {
const element = this.buildLinkElementFromRect(link.rect)
this.setLinkTarget(element, link)
return this.annotationsLayerDiv.appendChild(element)
this.annotationsLayerDiv.appendChild(element)
}
buildLinkElementFromRect(rect) {
@ -70,18 +47,17 @@ define(['base'], App =>
setLinkTarget(element, link) {
if (link.url) {
element.href = link.url
return (element.target = this.EXTERNAL_LINK_TARGET)
element.target = EXTERNAL_LINK_TARGET
element.rel = REL_NOOPENER
} else if (link.dest) {
element.href = `#${link.dest}`
return (element.onclick = e => {
element.onclick = () => {
this.navigateFn(link)
return false
})
}
}
}
pdfAnnotations.initClass()
}
return pdfAnnotations
})())
}
]))
})
})