diff --git a/build.properties b/build.properties index b4fc623f..73fc8d45 100644 --- a/build.properties +++ b/build.properties @@ -6,7 +6,7 @@ PROJECT: openseadragon BUILD_MAJOR: 0 BUILD_MINOR: 9 -BUILD_ID: 102 +BUILD_ID: 107 BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} diff --git a/openseadragon.js b/openseadragon.js index a15c5860..4164956d 100644 --- a/openseadragon.js +++ b/openseadragon.js @@ -1,7 +1,7 @@ /*globals OpenSeadragon */ /** - * @version OpenSeadragon 0.9.102 + * @version OpenSeadragon 0.9.107 * * @fileOverview *

@@ -5624,7 +5624,7 @@ function processResponse( xhr ){ data = xhr.responseText; } }else if( responseText.match(/\s*[\{\[].*/) ){ - data = eval( responseText ); + data = eval( '('+responseText+')' ); }else{ data = responseText; } @@ -6071,7 +6071,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, { if( !$.isPlainObject(data) ){ - options = configureFromXML( this, data ); + options = configureFromXml( this, data ); }else{ @@ -6201,50 +6201,13 @@ function configureFromXml( tileSource, xmlDoc ){ try { + configuration = { - "ns": root.namespaceURI, - "identifier": root.getElement('identifier').innerHTML, - "width": root.getElement('width').innerHTML, - "height": root.getElement('height').innerHTML, - "scale_factors": null, - "tile_width": root.getElement('tile_width').innerHTML, - "tile_height": root.getElement('tile_height').innerHTML, - "formats": [ "jpg", "png" ], - "quality": [ "native", "grey" ] + "ns": root.namespaceURI }; - scale_factors = root.getElement('scale_factors'); - if( scale_factors ){ - scale_factors = scale_factors.getElementsByTagName('scale_factor'); - configuration.scale_factors = []; - for( i = 0; i < scale_factors.length; i++ ){ - configuration.scale_factors.push( - scale_factors[ i ].innerHTML - ); - } - } + parseXML( root, configuration ); - formats = root.getElement('formats'); - if( formats ){ - formats = formats.getElementsByTagName('format'); - configuration.formats = []; - for( i = 0; i < formats.length; i++ ){ - configuration.formats.push( - formats[ i ].innerHTML - ); - } - } - - qualities = root.getElement('qualities'); - if( qualities ){ - qualities = formats.getElementsByTagName('quality'); - configuration.quality = []; - for( i = 0; i < qualities.length; i++ ){ - configuration.quality.push( - qualities[ i ].innerHTML - ); - } - } return configureFromObject( tileSource, configuration ); @@ -6260,6 +6223,35 @@ function configureFromXml( tileSource, xmlDoc ){ }; +/** + * @private + * @inner + * @function + */ +function parseXML( node, configuration, property ){ + var i, + value; + if( node.nodeType == 3 && property ){//text node + value = node.nodeValue.trim(); + if( value.match(/^\d*$/)){ + value = Number( value ); + } + if( !configuration[ property ] ){ + configuration[ property ] = value; + }else{ + if( !$.isArray( configuration[ property ] ) ){ + configuration[ property ] = [ configuration[ property ] ]; + } + configuration[ property ].push( value ); + } + } else if( node.nodeType == 1 ){ + for( i = 0; i < node.childNodes.length; i++ ){ + parseXML( node.childNodes[ i ], configuration, node.nodeName ); + } + } +} + + /** * @private * @inner @@ -6278,6 +6270,12 @@ function configureFromXml( tileSource, xmlDoc ){ } */ function configureFromObject( tileSource, configuration ){ + //the image_host property is not part of the iiif standard but is included here to + //allow the info.json and info.xml specify a different server to load the + //images from so we can test the implementation. + if( configuration.image_host ){ + configuration.tilesUrl = configuration.image_host; + } return configuration; }; diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index 36ac6f6e..4b4b6111 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -81,7 +81,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, { if( !$.isPlainObject(data) ){ - options = configureFromXML( this, data ); + options = configureFromXml( this, data ); }else{ @@ -211,50 +211,13 @@ function configureFromXml( tileSource, xmlDoc ){ try { + configuration = { - "ns": root.namespaceURI, - "identifier": root.getElement('identifier').innerHTML, - "width": root.getElement('width').innerHTML, - "height": root.getElement('height').innerHTML, - "scale_factors": null, - "tile_width": root.getElement('tile_width').innerHTML, - "tile_height": root.getElement('tile_height').innerHTML, - "formats": [ "jpg", "png" ], - "quality": [ "native", "grey" ] + "ns": root.namespaceURI }; - scale_factors = root.getElement('scale_factors'); - if( scale_factors ){ - scale_factors = scale_factors.getElementsByTagName('scale_factor'); - configuration.scale_factors = []; - for( i = 0; i < scale_factors.length; i++ ){ - configuration.scale_factors.push( - scale_factors[ i ].innerHTML - ); - } - } + parseXML( root, configuration ); - formats = root.getElement('formats'); - if( formats ){ - formats = formats.getElementsByTagName('format'); - configuration.formats = []; - for( i = 0; i < formats.length; i++ ){ - configuration.formats.push( - formats[ i ].innerHTML - ); - } - } - - qualities = root.getElement('qualities'); - if( qualities ){ - qualities = formats.getElementsByTagName('quality'); - configuration.quality = []; - for( i = 0; i < qualities.length; i++ ){ - configuration.quality.push( - qualities[ i ].innerHTML - ); - } - } return configureFromObject( tileSource, configuration ); @@ -270,6 +233,35 @@ function configureFromXml( tileSource, xmlDoc ){ }; +/** + * @private + * @inner + * @function + */ +function parseXML( node, configuration, property ){ + var i, + value; + if( node.nodeType == 3 && property ){//text node + value = node.nodeValue.trim(); + if( value.match(/^\d*$/)){ + value = Number( value ); + } + if( !configuration[ property ] ){ + configuration[ property ] = value; + }else{ + if( !$.isArray( configuration[ property ] ) ){ + configuration[ property ] = [ configuration[ property ] ]; + } + configuration[ property ].push( value ); + } + } else if( node.nodeType == 1 ){ + for( i = 0; i < node.childNodes.length; i++ ){ + parseXML( node.childNodes[ i ], configuration, node.nodeName ); + } + } +} + + /** * @private * @inner @@ -288,6 +280,12 @@ function configureFromXml( tileSource, xmlDoc ){ } */ function configureFromObject( tileSource, configuration ){ + //the image_host property is not part of the iiif standard but is included here to + //allow the info.json and info.xml specify a different server to load the + //images from so we can test the implementation. + if( configuration.image_host ){ + configuration.tilesUrl = configuration.image_host; + } return configuration; }; diff --git a/src/tilesource.js b/src/tilesource.js index a5a5eb99..79d134c6 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -372,7 +372,7 @@ function processResponse( xhr ){ data = xhr.responseText; } }else if( responseText.match(/\s*[\{\[].*/) ){ - data = eval( responseText ); + data = eval( '('+responseText+')' ); }else{ data = responseText; } diff --git a/www/tilesource-iiif.html b/www/tilesource-iiif.html index 6cc19edf..e3d615d5 100644 --- a/www/tilesource-iiif.html +++ b/www/tilesource-iiif.html @@ -53,7 +53,6 @@ OpenSeadragon({ minZoomLevel: 1, defaultZoomLevel: 1, tileSources: [{ - "tilesUrl": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000001", "width": 2617, "height": 3600, @@ -62,7 +61,8 @@ OpenSeadragon({ "tile_height": 256, "formats": [ "jpg", "png" ], "qualities": ["native", "bitonal", "grey", "color"], - "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" + "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1", + "image_host": "http://img.princeton.edu/loris" }...,{ ...//more tile sources @@ -80,7 +80,7 @@ OpenSeadragon({ minZoomLevel: 1, defaultZoomLevel: 1, tileSources: [{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000001", "width": 2617, "height": 3600, @@ -91,7 +91,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000002", "width": 2547, "height": 3600, @@ -102,7 +102,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000003", "width": 2694, "height": 3600, @@ -113,7 +113,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000004", "width": 2717, "height": 3600, @@ -124,7 +124,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000005", "width": 2694, "height": 3600, @@ -135,7 +135,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000006", "width": 2717, "height": 3600, @@ -146,7 +146,7 @@ OpenSeadragon({ "qualities": ["native", "bitonal", "grey", "color"], "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1" },{ - "tilesUrl": "http://img.princeton.edu/loris", + "image_host": "http://img.princeton.edu/loris", "identifier": "pudl0001/4609321/s42/00000007", "width": 2694, "height": 3600, @@ -160,3 +160,90 @@ OpenSeadragon({ }); +
+

XMLHTTPRequest for IIIF info.xml or info.json

+

+ The following example info.json and info.xml documents are non-normative and include + a property image_host which allows the info.json and info.xml + to be hosted from a different server than the images are served from. +

+
+
+
+ Example XMLHTTPRequest for IIIF info ( XML or JSON ) +
+
+ + +
+

+ Below is a sample IIIF info file formatted as XML. +

+
+<?xml version="1.0" encoding="UTF-8"?>
+<info xmlns="http://library.stanford.edu/iiif/image-api/ns/">
+    <identifier>pudl0001/4609321/s42/00000004</identifier>
+    <width>2717</width>
+    <height>3600</height>
+    <scale_factors>
+        <scale_factor>1</scale_factor>
+        <scale_factor>2</scale_factor>
+        <scale_factor>3</scale_factor>
+        <scale_factor>4</scale_factor>
+        <scale_factor>5</scale_factor>
+    </scale_factors>
+    <tile_width>256</tile_width>
+    <tile_height>256</tile_height>
+    <formats>
+        <format>jpg</format>
+        <format>png</format>
+    </formats>
+    <qualities>
+        <quality>native</quality>
+        <quality>bitonal</quality>
+        <quality>grey</quality>
+        <quality>color</quality>
+    </qualities>
+    <profile>http://library.stanford.edu/iiif/image-api/compliance.html#level1</profile>
+    <image_host>http://img.princeton.edu/loris</image_host>
+</info>
+

+ And the equivalent sample IIIF info file formatted as JSON. +

+
+{  
+    "identifier" : "pudl0001/4609321/s42/00000003",
+    "width":        2694,   
+    "height":       3600,   
+    "scale_factors" : [1, 2, 3, 4, 5],   
+    "tile_width" : 256,   
+    "tile_height" : 256,   
+    "formats" : [ "jpg", "png" ],   
+    "qualities" : ["native", "bitonal", "grey", "color"],   
+    "profile" : "http://library.stanford.edu/iiif/image-api/compliance.html#level1",
+    "image_host": "http://img.princeton.edu/loris"
+}
+
+OpenSeadragon({
+    ...
+    tileSources:   [
+        "/openseadragon/examples/images/loris/pudl0001/4609321/s42/00000003/info.json",
+        "/openseadragon/examples/images/loris/pudl0001/4609321/s42/00000004/info.xml"
+    ],
+    ...
+});
+