[Pkg-javascript-commits] [pdf.js] 92/115: Move link creation logic to src/display/annotation_layer.js
David Prévot
taffit at moszumanska.debian.org
Wed Dec 16 20:03:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit bce3214105dfb78235a2f2277ee32b339c2b1216
Author: Tim van der Meij <timvandermeij at gmail.com>
Date: Tue Dec 8 23:38:32 2015 +0100
Move link creation logic to src/display/annotation_layer.js
Additionally simplify the div creation logic (it needs to happen only
once, so it should not be in the for-loop) and remove/rename variables
for shorter code.
---
src/display/annotation_layer.js | 37 +++++++++++++++++--
web/annotations_layer_builder.js | 77 +++++++++++-----------------------------
web/pdf_page_view.js | 4 +--
3 files changed, 56 insertions(+), 62 deletions(-)
diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js
index 2602f41..eea2878 100644
--- a/src/display/annotation_layer.js
+++ b/src/display/annotation_layer.js
@@ -274,7 +274,29 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
return container;
}
- function getHtmlElementForLinkAnnotation(item, page, viewport) {
+ function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) {
+ function bindLink(link, dest) {
+ link.href = linkService.getDestinationHash(dest);
+ link.onclick = function annotationsLayerBuilderLinksOnclick() {
+ if (dest) {
+ linkService.navigateTo(dest);
+ }
+ return false;
+ };
+ if (dest) {
+ link.className = 'internalLink';
+ }
+ }
+
+ function bindNamedAction(link, action) {
+ link.href = linkService.getAnchorUrl('');
+ link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
+ linkService.executeNamedAction(action);
+ return false;
+ };
+ link.className = 'internalLink';
+ }
+
var container = getContainer(item, page, viewport);
container.className = 'annotLink';
@@ -285,19 +307,28 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
}
+ if (!item.url) {
+ if (item.action) {
+ bindNamedAction(link, item.action);
+ } else {
+ bindLink(link, ('dest' in item) ? item.dest : null);
+ }
+ }
+
container.appendChild(link);
return container;
}
- function getHtmlElement(data, page, viewport) {
+ function getHtmlElement(data, page, viewport, linkService) {
switch (data.annotationType) {
case AnnotationType.WIDGET:
return getHtmlElementForTextWidgetAnnotation(data, page);
case AnnotationType.TEXT:
return getHtmlElementForTextAnnotation(data, page, viewport);
case AnnotationType.LINK:
- return getHtmlElementForLinkAnnotation(data, page, viewport);
+ return getHtmlElementForLinkAnnotation(data, page, viewport,
+ linkService);
default:
throw new Error('Unsupported annotationType: ' + data.annotationType);
}
diff --git a/web/annotations_layer_builder.js b/web/annotations_layer_builder.js
index 5a72873..37e23d8 100644
--- a/web/annotations_layer_builder.js
+++ b/web/annotations_layer_builder.js
@@ -48,47 +48,21 @@ var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
* @param {PageViewport} viewport
* @param {string} intent (default value is 'display')
*/
- setupAnnotations:
- function AnnotationsLayerBuilder_setupAnnotations(viewport, intent) {
- function bindLink(link, dest) {
- link.href = linkService.getDestinationHash(dest);
- link.onclick = function annotationsLayerBuilderLinksOnclick() {
- if (dest) {
- linkService.navigateTo(dest);
- }
- return false;
- };
- if (dest) {
- link.className = 'internalLink';
- }
- }
-
- function bindNamedAction(link, action) {
- link.href = linkService.getAnchorUrl('');
- link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
- linkService.executeNamedAction(action);
- return false;
- };
- link.className = 'internalLink';
- }
-
- var linkService = this.linkService;
- var pdfPage = this.pdfPage;
+ render: function AnnotationsLayerBuilder_render(viewport, intent) {
var self = this;
- var getAnnotationsParams = {
+ var parameters = {
intent: (intent === undefined ? 'display' : intent),
};
- pdfPage.getAnnotations(getAnnotationsParams).then(
- function (annotationsData) {
+ this.pdfPage.getAnnotations(parameters).then(function (annotations) {
viewport = viewport.clone({ dontFlip: true });
var data, element, i, ii;
if (self.div) {
// If an annotationLayer already exists, refresh its children's
- // transformation matrices
- for (i = 0, ii = annotationsData.length; i < ii; i++) {
- data = annotationsData[i];
+ // transformation matrices.
+ for (i = 0, ii = annotations.length; i < ii; i++) {
+ data = annotations[i];
element = self.div.querySelector(
'[data-annotation-id="' + data.id + '"]');
if (element) {
@@ -96,46 +70,35 @@ var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
'matrix(' + viewport.transform.join(',') + ')');
}
}
- // See PDFPageView.reset()
self.div.removeAttribute('hidden');
} else {
- for (i = 0, ii = annotationsData.length; i < ii; i++) {
- data = annotationsData[i];
+ if (annotations.length === 0) {
+ return;
+ }
+
+ self.div = document.createElement('div');
+ self.div.className = 'annotationLayer';
+ self.pageDiv.appendChild(self.div);
+
+ for (i = 0, ii = annotations.length; i < ii; i++) {
+ data = annotations[i];
if (!data || !data.hasHtml) {
continue;
}
- element = PDFJS.AnnotationLayer.getHtmlElement(data, pdfPage,
- viewport);
+ element = PDFJS.AnnotationLayer.getHtmlElement(data, self.pdfPage,
+ viewport,
+ self.linkService);
if (typeof mozL10n !== 'undefined') {
mozL10n.translate(element);
}
-
- if (data.subtype === 'Link' && !data.url) {
- var link = element.getElementsByTagName('a')[0];
- if (link) {
- if (data.action) {
- bindNamedAction(link, data.action);
- } else {
- bindLink(link, ('dest' in data) ? data.dest : null);
- }
- }
- }
-
- if (!self.div) {
- var annotationLayerDiv = document.createElement('div');
- annotationLayerDiv.className = 'annotationLayer';
- self.pageDiv.appendChild(annotationLayerDiv);
- self.div = annotationLayerDiv;
- }
-
self.div.appendChild(element);
}
}
});
},
- hide: function () {
+ hide: function AnnotationsLayerBuilder_hide() {
if (!this.div) {
return;
}
diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index 440b31f..1e1e685 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -275,7 +275,7 @@ var PDFPageView = (function PDFPageViewClosure() {
}
if (redrawAnnotations && this.annotationLayer) {
- this.annotationLayer.setupAnnotations(this.viewport, 'display');
+ this.annotationLayer.render(this.viewport, 'display');
}
},
@@ -507,7 +507,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.annotationLayer = this.annotationsLayerFactory.
createAnnotationsLayerBuilder(div, this.pdfPage);
}
- this.annotationLayer.setupAnnotations(this.viewport, 'display');
+ this.annotationLayer.render(this.viewport, 'display');
}
div.setAttribute('data-loaded', true);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list