Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named actions implementation #3557

Merged
merged 1 commit into from
Aug 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
}
data.url = url;
data.dest = action.get('D');
} else if (linkType === 'Named') {
data.action = action.get('N').name;
} else {
TODO('unrecognized link type: ' + linkType);
}
Expand Down
52 changes: 51 additions & 1 deletion web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,52 @@ var PageView = function pageView(container, id, scale,
link.className = 'internalLink';
}

function bindNamedAction(link, action) {
link.onclick = function pageViewSetupNamedActionOnClick() {
// See PDF reference, table 8.45 - Named action
switch (action) {
case 'GoToPage':
document.getElementById('pageNumber').focus();
break;

case 'GoBack':
PDFHistory.back();
break;

case 'GoForward':
PDFHistory.forward();
break;

case 'Find':
if (!PDFView.supportsIntegratedFind) {
PDFFindBar.toggle();
}
break;

case 'NextPage':
PDFView.page++;
break;

case 'PrevPage':
PDFView.page--;
break;

case 'LastPage':
PDFView.page = PDFView.pages.length;
break;

case 'FirstPage':
PDFView.page = 1;
break;

default:
break; // No action according to spec
}
return false;
};
link.className = 'internalLink';
}

pdfPage.getAnnotations().then(function(annotationsData) {
viewport = viewport.clone({ dontFlip: true });
for (var i = 0; i < annotationsData.length; i++) {
Expand Down Expand Up @@ -1646,7 +1692,11 @@ var PageView = function pageView(container, id, scale,
CustomStyle.setProp('transformOrigin', element, transformOriginStr);

if (data.subtype === 'Link' && !data.url) {
bindLink(element, ('dest' in data) ? data.dest : null);
if (data.action) {
bindNamedAction(element, data.action);
} else {
bindLink(element, ('dest' in data) ? data.dest : null);
}
}

annotationsDiv.appendChild(element);
Expand Down