Skip to content

Commit

Permalink
Merge pull request documentcloud#3 from ashaw/master
Browse files Browse the repository at this point in the history
Annotations Options
  • Loading branch information
jashkenas committed Sep 28, 2011
2 parents 8c904d8 + fa1610d commit 13da25d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
12 changes: 12 additions & 0 deletions public/javascripts/DV/controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ DV.Api.prototype = {
this.viewer.pageSet.reflowPages();
}
},

getAnnotationsBySortOrder : function() {
return this.viewer.models.annotations.sortAnnotations();
},

getAnnotationsByPageIndex : function(idx) {
return this.viewer.models.annotations.getAnnotations(idx);
},

getAnnotation : function(aid) {
return this.viewer.models.annotations.getAnnotation(aid);
},

// Add a new annotation to the document, prefilled to any extent.
addAnnotation : function(anno) {
Expand Down
21 changes: 14 additions & 7 deletions public/javascripts/DV/helpers/construction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Renders the navigation sidebar for chapters and annotations.
_.extend(DV.Schema.helpers, {
showAnnotations : function() {
if (this.viewer.options.showAnnotations === false) return false;
return _.any(this.models.annotations.byId);
},

renderViewer: function(){
var doc = this.viewer.schema.document;
var pagesHTML = this.constructPages();
Expand All @@ -17,7 +22,7 @@ _.extend(DV.Schema.helpers, {
var pdfURL = doc.resources.pdf;
pdfURL = pdfURL && this.viewer.options.pdf !== false ? '<a target="_blank" href="' + pdfURL + '">Original Document (PDF) &raquo;</a>' : '';

var showAnnotations = _.any(this.models.annotations.byId);
var showAnnotations = this.showAnnotations();
var printNotesURL = (showAnnotations) && doc.resources.print_annotations;

var viewerOptions = {
Expand Down Expand Up @@ -101,10 +106,12 @@ _.extend(DV.Schema.helpers, {
};
/* ---------------------------------------------------- end the nav helper methods */

for(var i = 0,len = this.models.document.totalPages; i < len;i++){
if(this.viewer.schema.data.annotationsByPage[i]){
nav[i] = createNavAnnotations(i);
notes[i] = nav[i];
if (this.showAnnotations()) {
for(var i = 0,len = this.models.document.totalPages; i < len;i++){
if(this.viewer.schema.data.annotationsByPage[i]){
nav[i] = createNavAnnotations(i);
notes[i] = nav[i];
}
}
}

Expand Down Expand Up @@ -149,7 +156,7 @@ _.extend(DV.Schema.helpers, {
chaptersContainer = null;
},

// Hide or show all of the comoponents on the page that may or may not be
// Hide or show all of the components on the page that may or may not be
// present, depending on what the document provides.
renderComponents : function() {
// Hide the overflow of the body, unless we're positioned.
Expand All @@ -164,7 +171,7 @@ _.extend(DV.Schema.helpers, {
}

// Hide and show navigation flags:
var showAnnotations = _.any(this.models.annotations.byId);
var showAnnotations = this.showAnnotations();
var showPages = this.models.document.totalPages > 1;
var showSearch = (this.viewer.options.search !== false) &&
(this.viewer.options.text !== false) &&
Expand Down
2 changes: 2 additions & 0 deletions public/javascripts/DV/models/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ DV.model.Annotations.prototype = {

// Renders each annotation into it's HTML format.
renderAnnotations: function(){
if (this.viewer.options.showAnnotations === false) return;

for (var i=0; i<this.bySortOrder.length; i++) {
var anno = this.bySortOrder[i];
anno.of = _.indexOf(this.byPage[anno.page - 1], anno);
Expand Down

0 comments on commit 13da25d

Please sign in to comment.