@@ -10,18 +10,19 @@ DV._.extend(DV.Schema.helpers, {
1010 var doc = this . viewer . schema . document ;
1111 var pagesHTML = this . constructPages ( ) ;
1212 var description = ( doc . description ) ? doc . description : null ;
13- var storyURL = doc . resources . related_article ;
13+ var storyURL = doc . resources . related_article ;
14+ var options = this . viewer . options ;
1415
1516 var headerHTML = JST . header ( {
16- options : this . viewer . options ,
17+ options : options ,
1718 id : doc . id ,
1819 story_url : storyURL ,
1920 title : doc . title || ''
2021 } ) ;
21- var footerHTML = JST . footer ( { options : this . viewer . options } ) ;
22+ var footerHTML = JST . footer ( { options : { } } ) ;
2223
2324 var pdfURL = doc . resources . pdf ;
24- pdfURL = pdfURL && this . viewer . options . pdf !== false ? '<a target="_blank" href="' + pdfURL + '">Original Document (PDF) »</a>' : '' ;
25+ pdfURL = pdfURL && options . pdf !== false ? '<a target="_blank" href="' + pdfURL + '">Original Document (PDF) »</a>' : '' ;
2526
2627 var contribs = doc . contributor && doc . contributor_organization &&
2728 ( '' + doc . contributor + ', ' + doc . contributor_organization ) ;
@@ -30,7 +31,7 @@ DV._.extend(DV.Schema.helpers, {
3031 var printNotesURL = ( showAnnotations ) && doc . resources . print_annotations ;
3132
3233 var viewerOptions = {
33- options : this . viewer . options ,
34+ options : options ,
3435 pages : pagesHTML ,
3536 header : headerHTML ,
3637 footer : footerHTML ,
@@ -39,21 +40,43 @@ DV._.extend(DV.Schema.helpers, {
3940 story_url : storyURL ,
4041 print_notes_url : printNotesURL ,
4142 descriptionContainer : JST . descriptionContainer ( { description : description } ) ,
42- autoZoom : this . viewer . options . zoom == 'auto' ,
43+ autoZoom : options . zoom == 'auto' ,
4344 mini : false
4445 } ;
4546
46- var width = this . viewer . options . width ;
47- var height = this . viewer . options . height ;
48- if ( width && height ) {
47+ if ( options . responsive ) {
48+ if ( ! options . height ) {
49+ var winHeight = DV . jQuery ( window ) . height ( ) ;
50+ var toSubtract = options . responsiveOffset == null ? this . viewer . helpers . RESPONSIVE_DEFAULT_OFFSET : options . responsiveOffset ;
51+ options . height = winHeight - toSubtract ;
52+ }
53+ }
54+
55+ var width = options . width ;
56+ var height = options . height ;
57+ if ( width && height && ! options . responsive ) {
4958 if ( width < 500 ) {
50- this . viewer . options . mini = true ;
59+ options . mini = true ;
5160 viewerOptions . mini = true ;
5261 }
53- DV . jQuery ( this . viewer . options . container ) . css ( {
62+ DV . jQuery ( options . container ) . css ( {
63+ position : 'relative' ,
64+ width : options . width ,
65+ height : options . height
66+ } ) ;
67+ }
68+
69+ if ( options . responsive ) {
70+ var container = DV . jQuery ( options . container ) ;
71+ this . viewer . options . sidebarVisible = ( container . width ( ) - 2 ) >= this . viewer . helpers . RESPONSIVE_MIN_SIDEBAR_WIDTH ;
72+ container . css ( {
5473 position : 'relative' ,
55- width : this . viewer . options . width ,
56- height : this . viewer . options . height
74+ height : options . height
75+ } ) ;
76+
77+ var viewer = this . viewer ;
78+ DV . jQuery ( window ) . resize ( function ( ) {
79+ viewer . helpers . responsiveRedraw ( ) ;
5780 } ) ;
5881 }
5982
@@ -174,22 +197,21 @@ DV._.extend(DV.Schema.helpers, {
174197 // Hide the overflow of the body, unless we're positioned.
175198 var containerEl = DV . jQuery ( this . viewer . options . container ) ;
176199 var position = containerEl . css ( 'position' ) ;
177- if ( position != 'relative' && position != 'absolute' && ! this . viewer . options . fixedSize ) {
200+ if ( position != 'relative' && position != 'absolute' && ! this . viewer . options . fixedSize && ! this . viewer . options . responsive ) {
178201 DV . jQuery ( "html, body" ) . css ( { overflow : 'hidden' } ) ;
179202 // Hide the border, if we're a full-screen viewer in the body tag.
180203 if ( containerEl . offset ( ) . top == 0 ) {
181204 this . viewer . elements . viewer . css ( { border : 0 } ) ;
182205 }
183206 }
207+ this . viewer . helpers . _prevWidth = this . viewer . elements . viewer . width ( ) ;
184208
185209 // Hide and show navigation flags:
186210 var showAnnotations = this . showAnnotations ( ) ;
187211 var showPages = this . models . document . totalPages > 1 ;
188212 var showSearch = ( this . viewer . options . search !== false ) &&
189213 ( this . viewer . options . text !== false ) &&
190214 ( ! this . viewer . options . width || this . viewer . options . width >= 540 ) ;
191- var noFooter = ( ! showAnnotations && ! showPages && ! showSearch && ! this . viewer . options . sidebar ) ;
192-
193215
194216 // Hide annotations, if there are none:
195217 var $annotationsView = this . viewer . $ ( '.DV-annotationView' ) ;
@@ -224,35 +246,24 @@ DV._.extend(DV.Schema.helpers, {
224246 // Remove and re-render the nav controls.
225247 // Don't show the nav controls if there's no sidebar, and it's a one-page doc.
226248 this . viewer . $ ( '.DV-navControls' ) . remove ( ) ;
227- if ( showPages || this . viewer . options . sidebar ) {
249+ if ( showPages || this . viewer . options . sidebarVisible ) {
228250 var navControls = JST . navControls ( {
229251 totalPages : this . viewer . schema . data . totalPages ,
230252 totalAnnotations : this . viewer . schema . data . totalAnnotations
231253 } ) ;
232254 this . viewer . $ ( '.DV-navControlsContainer' ) . html ( navControls ) ;
233255 }
234256
235- this . viewer . $ ( '.DV-fullscreenControl' ) . remove ( ) ;
236257 if ( this . viewer . schema . document . canonicalURL ) {
237258 var fullscreenControl = JST . fullscreenControl ( { } ) ;
238- if ( noFooter ) {
239- this . viewer . $ ( '.DV-collapsibleControls' ) . prepend ( fullscreenControl ) ;
240- this . elements . viewer . addClass ( 'DV-hideFooter' ) ;
241- } else {
242- this . viewer . $ ( '.DV-fullscreenContainer' ) . html ( fullscreenControl ) ;
243- }
259+ this . viewer . $ ( '.DV-fullscreenContainer' ) . html ( fullscreenControl ) ;
244260 }
245261
246- if ( this . viewer . options . sidebar ) {
247- this . viewer . $ ( '.DV-sidebar' ) . show ( ) ;
248- }
249-
250- // Check if the zoom is showing, and if not, shorten the width of search
251- DV . _ . defer ( DV . _ . bind ( function ( ) {
252- if ( ( this . elements . viewer . width ( ) <= 700 ) && ( showAnnotations || showPages || showSearch ) ) {
253- this . viewer . $ ( '.DV-controls' ) . addClass ( 'DV-narrowControls' ) ;
254- }
255- } , this ) ) ;
262+ var v = this . viewer . elements . viewer ;
263+ v . toggleClass ( 'DV-hideSidebar' , ! this . viewer . options . sidebarVisible ) ;
264+ v . toggleClass ( 'DV-mini' , ! this . viewer . options . sidebarVisible ) ;
265+ v . toggleClass ( 'DV-supermini' , this . viewer . elements . viewer . width ( ) < 500 ) ;
266+ v . toggleClass ( 'DV-hideFooter' , this . viewer . options . sidebarVisible ) ;
256267
257268 // Set the currentPage element reference.
258269 this . elements . currentPage = this . viewer . $ ( 'span.DV-currentPage' ) ;
0 commit comments