2011-12-06 07:50:25 +04:00
|
|
|
/**
|
2012-01-25 23:14:02 +04:00
|
|
|
* @version OpenSeadragon @VERSION@
|
2011-12-06 07:50:25 +04:00
|
|
|
*
|
2012-01-25 23:14:02 +04:00
|
|
|
* @fileOverview
|
|
|
|
* <h2>
|
|
|
|
* <strong>
|
|
|
|
* OpenSeadragon - Javascript Deep Zooming
|
|
|
|
* </strong>
|
|
|
|
* </h2>
|
|
|
|
* <p>
|
|
|
|
* OpenSeadragon is provides an html interface for creating
|
|
|
|
* deep zoom user interfaces. The simplest examples include deep
|
|
|
|
* zoom for large resolution images, and complex examples include
|
|
|
|
* zoomable map interfaces driven by SVG files.
|
|
|
|
* </p>
|
|
|
|
*
|
2012-04-11 01:02:24 +04:00
|
|
|
* @author <br/>(c) 2011, 2012 Christopher Thatcher
|
2012-01-25 23:14:02 +04:00
|
|
|
* @author <br/>(c) 2010 OpenSeadragon Team
|
|
|
|
* @author <br/>(c) 2010 CodePlex Foundation
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* <strong>Original license preserved below: </strong><br/>
|
|
|
|
* <pre>
|
2011-12-06 07:50:25 +04:00
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* License: New BSD License (BSD)
|
|
|
|
* Copyright (c) 2010, OpenSeadragon
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of OpenSeadragon nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2012-04-11 01:02:24 +04:00
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
* </pre>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* <strong> Work done by Chris Thatcher adds an MIT license </strong><br/>
|
|
|
|
* <pre>
|
2011-12-06 07:50:25 +04:00
|
|
|
* ----------------------------------------------------------------------------
|
2012-04-11 01:02:24 +04:00
|
|
|
* (c) Christopher Thatcher 2011, 2012. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed with the MIT License
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
* ---------------------------------------------------------------------------
|
2012-01-25 23:14:02 +04:00
|
|
|
* </pre>
|
|
|
|
* </p>
|
2011-12-06 07:50:25 +04:00
|
|
|
**/
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-03-01 17:38:15 +04:00
|
|
|
* The root namespace for OpenSeadragon, this function also serves as a single
|
|
|
|
* point of instantiation for an {@link OpenSeadragon.Viewer}, including all
|
|
|
|
* combinations of out-of-the-box configurable features. All utility methods
|
|
|
|
* and classes are defined on or below this namespace.
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
* @function
|
2012-01-25 23:14:02 +04:00
|
|
|
* @name OpenSeadragon
|
|
|
|
* @exports $ as OpenSeadragon
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Object} options All required and optional settings for instantiating
|
|
|
|
* a new instance of an OpenSeadragon image viewer.
|
|
|
|
*
|
|
|
|
* @param {String} options.xmlPath
|
|
|
|
* DEPRECATED. A relative path to load a DZI file from the server.
|
|
|
|
* Prefer the newer options.tileSources.
|
|
|
|
*
|
|
|
|
* @param {Array|String|Function|Object[]|Array[]|String[]|Function[]} options.tileSources
|
|
|
|
* As an Array, the tileSource can hold either be all Objects or mixed
|
|
|
|
* types of Arrays of Objects, String, Function. When a value is a String,
|
|
|
|
* the tileSource is used to create a {@link OpenSeadragon.DziTileSource}.
|
|
|
|
* When a value is a Function, the function is used to create a new
|
|
|
|
* {@link OpenSeadragon.TileSource} whose abstract method
|
|
|
|
* getUrl( level, x, y ) is implemented by the function. Finally, when it
|
|
|
|
* is an Array of objects, it is used to create a
|
|
|
|
* {@link OpenSeadragon.LegacyTileSource}.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [options.debugMode=true]
|
|
|
|
* Currently does nothing. TODO: provide an in-screen panel providing event
|
|
|
|
* detail feedback.
|
|
|
|
*
|
|
|
|
* @param {Number} [options.animationTime=1.5]
|
|
|
|
* Specifies the animation duration per each {@link OpenSeadragon.Spring}
|
|
|
|
* which occur when the image is dragged or zoomed.
|
|
|
|
*
|
|
|
|
* @param {Number} [options.blendTime=0.5]
|
|
|
|
* Specifies the duration of animation as higher or lower level tiles are
|
|
|
|
* replacing the existing tile.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [options.alwaysBlend=false]
|
|
|
|
* Forces the tile to always blend. By default the tiles skip blending
|
|
|
|
* when the blendTime is surpassed and the current animation frame would
|
|
|
|
* not complete the blend.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [options.autoHideControls=true]
|
|
|
|
* If the user stops interacting with the viewport, fade the navigation
|
|
|
|
* controls. Useful for presentation since the controls are by default
|
|
|
|
* floated on top of the image the user is viewing.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [options.immediateRender=false]
|
2012-03-07 07:20:00 +04:00
|
|
|
* Render the best closest level first, ignoring the lowering levels which
|
|
|
|
* provide the effect of very blurry to sharp. It is recommended to change
|
|
|
|
* setting to true for mobile devices.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Boolean} [options.wrapHorizontal=false]
|
2012-03-07 07:20:00 +04:00
|
|
|
* Set to true to force the image to wrap horizontally within the viewport.
|
|
|
|
* Useful for maps or images representing the surface of a sphere or cylinder.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Boolean} [options.wrapVertical=false]
|
2012-03-07 07:20:00 +04:00
|
|
|
* Set to true to force the image to wrap vertically within the viewport.
|
|
|
|
* Useful for maps or images representing the surface of a sphere or cylinder.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Number} [options.minZoomImageRatio=0.8]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The minimum percentage ( expressed as a number between 0 and 1 ) of
|
|
|
|
* the viewport height or width at which the zoom out will be constrained.
|
|
|
|
* Setting it to 0, for example will allow you to zoom out infinitly.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.maxZoomPixelRatio=2]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The maximum ratio to allow a zoom-in to affect the highest level pixel
|
|
|
|
* ratio. This can be set to Infinity to allow 'infinite' zooming into the
|
|
|
|
* image though it is less effective visually if the HTML5 Canvas is not
|
|
|
|
* availble on the viewing device.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Number} [options.visibilityRatio=0.5]
|
|
|
|
* The percentage ( as a number from 0 to 1 ) of the source image which
|
|
|
|
* must be kept within the viewport. If the image is dragged beyond that
|
|
|
|
* limit, it will 'bounce' back until the minimum visibility ration is
|
|
|
|
* achieved. Setting this to 0 and wrapHorizontal ( or wrapVertical ) to
|
|
|
|
* true will provide the effect of an infinitely scrolling viewport.
|
|
|
|
*
|
|
|
|
* @param {Number} [options.springStiffness=5.0]
|
2012-03-07 07:20:00 +04:00
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.imageLoaderLimit=0]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The maximum number of image requests to make concurrently. By default
|
|
|
|
* it is set to 0 allowing the browser to make the maximum number of
|
|
|
|
* image requests in parallel as allowed by the browsers policy.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.clickTimeThreshold=200]
|
2012-03-07 07:20:00 +04:00
|
|
|
* If multiple mouse clicks occurs within less than this number of
|
|
|
|
* milliseconds, treat them as a single click.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.clickDistThreshold=5]
|
2012-03-07 07:20:00 +04:00
|
|
|
* If a mouse or touch drag occurs and the distance to the starting drag
|
|
|
|
* point is less than this many pixels, ignore the drag event.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.zoomPerClick=2.0]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The "zoom distance" per mouse click or touch tap.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.zoomPerScroll=1.2]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The "zoom distance" per mouse scroll or touch pinch.
|
|
|
|
*
|
2012-03-01 17:38:15 +04:00
|
|
|
* @param {Number} [options.zoomPerSecond=2.0]
|
2012-03-07 07:20:00 +04:00
|
|
|
* The number of seconds to animate a single zoom event over.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Boolean} [options.showNavigationControl=true]
|
2012-03-07 07:20:00 +04:00
|
|
|
* Set to false to prevent the appearance of the default navigation controls.
|
2012-03-01 17:38:15 +04:00
|
|
|
*
|
|
|
|
* @param {Number} [options.controlsFadeDelay=2000]
|
|
|
|
* The number of milliseconds to wait once the user has stopped interacting
|
|
|
|
* with the interface before begining to fade the controls. Assumes
|
|
|
|
* showNavigationControl and autoHideControls are both true.
|
|
|
|
*
|
|
|
|
* @param {Number} [options.controlsFadeLength=1500]
|
|
|
|
* The number of milliseconds to animate the controls fading out.
|
|
|
|
*
|
|
|
|
* @param {Number} [options.maxImageCacheCount=100]
|
|
|
|
* The max number of images we should keep in memory (per drawer).
|
|
|
|
*
|
|
|
|
* @param {Number} [options.minPixelRatio=0.5]
|
|
|
|
* The higher the minPixelRatio, the lower the quality of the image that
|
|
|
|
* is considered sufficient to stop rendering a given zoom level. For
|
|
|
|
* example, if you are targeting mobile devices with less bandwith you may
|
|
|
|
* try setting this to 1.5 or higher.
|
|
|
|
*
|
|
|
|
* @param {Boolean} [options.mouseNavEnabled=true]
|
|
|
|
* Is the user able to interact with the image via mouse or touch. Default
|
|
|
|
* interactions include draging the image in a plane, and zooming in toward
|
|
|
|
* and away from the image.
|
|
|
|
*
|
2012-04-03 11:08:27 +04:00
|
|
|
* @param {Boolean} [options.preserveViewport=false]
|
|
|
|
* If the viewer has been configured with a sequence of tile sources, then
|
|
|
|
* normally navigating to through each image resets the viewport to 'home'
|
|
|
|
* position. If preserveViewport is set to true, then the viewport position
|
|
|
|
* is preserved when navigating between images in the sequence.
|
|
|
|
*
|
2012-09-28 22:02:22 +04:00
|
|
|
* @param {String} [options.prefixUrl='/images/']
|
2012-09-28 22:03:45 +04:00
|
|
|
* Prepends the prefixUrl to navImages paths, which is very useful
|
2012-03-01 17:38:15 +04:00
|
|
|
* since the default paths are rarely useful for production
|
|
|
|
* environments.
|
|
|
|
*
|
|
|
|
* @param {Object} [options.navImages=]
|
|
|
|
* An object with a property for each button or other built-in navigation
|
|
|
|
* control, eg the current 'zoomIn', 'zoomOut', 'home', and 'fullpage'.
|
|
|
|
* Each of those in turn provides an image path for each state of the botton
|
|
|
|
* or navigation control, eg 'REST', 'GROUP', 'HOVER', 'PRESS'. Finally the
|
|
|
|
* image paths, by default assume there is a folder on the servers root path
|
|
|
|
* called '/images', eg '/images/zoomin_rest.png'. If you need to adjust
|
|
|
|
* these paths, prefer setting the option.prefixUrl rather than overriding
|
|
|
|
* every image path directly through this setting.
|
|
|
|
*
|
|
|
|
* @returns {OpenSeadragon.Viewer}
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-03-01 17:38:15 +04:00
|
|
|
OpenSeadragon = window.OpenSeadragon || function( options ){
|
|
|
|
|
|
|
|
return new OpenSeadragon.Viewer( options );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Taken from jquery 1.6.1
|
|
|
|
* [[Class]] -> type pairs
|
|
|
|
* @private
|
|
|
|
*/
|
2011-12-07 05:26:06 +04:00
|
|
|
var class2type = {
|
|
|
|
'[object Boolean]': 'boolean',
|
|
|
|
'[object Number]': 'number',
|
|
|
|
'[object String]': 'string',
|
|
|
|
'[object Function]': 'function',
|
|
|
|
'[object Array]': 'array',
|
|
|
|
'[object Date]': 'date',
|
|
|
|
'[object RegExp]': 'regexp',
|
|
|
|
'[object Object]': 'object'
|
|
|
|
},
|
|
|
|
// Save a reference to some core methods
|
2011-12-08 06:10:13 +04:00
|
|
|
toString = Object.prototype.toString,
|
|
|
|
hasOwn = Object.prototype.hasOwnProperty,
|
|
|
|
push = Array.prototype.push,
|
|
|
|
slice = Array.prototype.slice,
|
|
|
|
trim = String.prototype.trim,
|
|
|
|
indexOf = Array.prototype.indexOf;
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-02-28 19:01:45 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.isFunction
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
|
|
|
*/
|
|
|
|
$.isFunction = function( obj ) {
|
|
|
|
return $.type(obj) === "function";
|
|
|
|
};
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.isArray
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
|
|
|
*/
|
|
|
|
$.isArray = Array.isArray || function( obj ) {
|
|
|
|
return $.type(obj) === "array";
|
|
|
|
};
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* A crude way of determining if an object is a window.
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.isWindow
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
|
|
|
*/
|
|
|
|
$.isWindow = function( obj ) {
|
|
|
|
return obj && typeof obj === "object" && "setInterval" in obj;
|
|
|
|
};
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.type
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
|
|
|
*/
|
|
|
|
$.type = function( obj ) {
|
|
|
|
return obj == null ?
|
|
|
|
String( obj ) :
|
|
|
|
class2type[ toString.call(obj) ] || "object";
|
|
|
|
};
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.isPlainObject
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
|
|
|
*/
|
|
|
|
$.isPlainObject = function( obj ) {
|
|
|
|
// Must be an Object.
|
|
|
|
// Because of IE, we also have to check the presence of the constructor property.
|
|
|
|
// Make sure that DOM nodes and window objects don't pass through, as well
|
|
|
|
if ( !obj || OpenSeadragon.type(obj) !== "object" || obj.nodeType || $.isWindow( obj ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
// Not own constructor property must be Object
|
|
|
|
if ( obj.constructor &&
|
|
|
|
!hasOwn.call(obj, "constructor") &&
|
|
|
|
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
|
|
|
|
return false;
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
// Own properties are enumerated firstly, so to speed up,
|
|
|
|
// if last one is own, then all properties are own.
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
var key;
|
|
|
|
for ( key in obj ) {}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
return key === undefined || hasOwn.call( obj, key );
|
|
|
|
};
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-03-01 17:38:15 +04:00
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @name $.isEmptyObject
|
|
|
|
* @function
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-03-01 17:38:15 +04:00
|
|
|
$.isEmptyObject = function( obj ) {
|
|
|
|
for ( var name in obj ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This closure defines all static methods available to the OpenSeadragon
|
|
|
|
* namespace. Many, if not most, are taked directly from jQuery for use
|
|
|
|
* to simplify and reduce common programming patterns. More static methods
|
|
|
|
* from jQuery may eventually make their way into this though we are
|
|
|
|
* attempting to avoid substaintial plagarism or the more explicit dependency
|
|
|
|
* on jQuery only because OpenSeadragon is a broadly useful code base and
|
|
|
|
* would be made less broad by requiring jQuery fully.
|
|
|
|
*
|
|
|
|
* Some static methods have also been refactored from the original OpenSeadragon
|
|
|
|
* project.
|
|
|
|
*/
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-03-01 17:38:15 +04:00
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @see <a href='http://www.jquery.com/'>jQuery</a>
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-07 05:26:06 +04:00
|
|
|
$.extend = function() {
|
2012-01-25 23:14:02 +04:00
|
|
|
var options,
|
|
|
|
name,
|
|
|
|
src,
|
|
|
|
copy,
|
|
|
|
copyIsArray,
|
|
|
|
clone,
|
|
|
|
target = arguments[ 0 ] || {},
|
|
|
|
length = arguments.length,
|
|
|
|
deep = false,
|
|
|
|
i = 1;
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
// Handle a deep copy situation
|
|
|
|
if ( typeof target === "boolean" ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
deep = target;
|
|
|
|
target = arguments[ 1 ] || {};
|
2011-12-07 05:26:06 +04:00
|
|
|
// skip the boolean and the target
|
|
|
|
i = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( typeof target !== "object" && !OpenSeadragon.isFunction( target ) ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
target = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// extend jQuery itself if only one argument is passed
|
|
|
|
if ( length === i ) {
|
|
|
|
target = this;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; i < length; i++ ) {
|
|
|
|
// Only deal with non-null/undefined values
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( ( options = arguments[ i ] ) != null ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
// Extend the base object
|
|
|
|
for ( name in options ) {
|
|
|
|
src = target[ name ];
|
|
|
|
copy = options[ name ];
|
|
|
|
|
|
|
|
// Prevent never-ending loop
|
|
|
|
if ( target === copy ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recurse if we're merging plain objects or arrays
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( deep && copy && ( OpenSeadragon.isPlainObject( copy ) || ( copyIsArray = OpenSeadragon.isArray( copy ) ) ) ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
if ( copyIsArray ) {
|
|
|
|
copyIsArray = false;
|
2012-01-25 23:14:02 +04:00
|
|
|
clone = src && OpenSeadragon.isArray( src ) ? src : [];
|
2011-12-07 05:26:06 +04:00
|
|
|
|
|
|
|
} else {
|
2012-01-25 23:14:02 +04:00
|
|
|
clone = src && OpenSeadragon.isPlainObject( src ) ? src : {};
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Never move original objects, clone them
|
|
|
|
target[ name ] = OpenSeadragon.extend( deep, clone, copy );
|
|
|
|
|
|
|
|
// Don't bring in undefined values
|
|
|
|
} else if ( copy !== undefined ) {
|
|
|
|
target[ name ] = copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the modified object
|
|
|
|
return target;
|
|
|
|
};
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
$.extend( $, {
|
|
|
|
/**
|
|
|
|
* These are the default values for the optional settings documented
|
|
|
|
* in the {@link OpenSeadragon} constructor detail.
|
|
|
|
* @name $.DEFAULT_SETTINGS
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
DEFAULT_SETTINGS: {
|
2012-04-03 11:08:27 +04:00
|
|
|
//DATA SOURCE DETAILS
|
|
|
|
xmlPath: null,
|
|
|
|
tileSources: null,
|
|
|
|
tileHost: null,
|
|
|
|
|
|
|
|
//INTERFACE FEATURES
|
|
|
|
animationTime: 1.5,
|
2012-06-05 15:52:00 +04:00
|
|
|
blendTime: 0.1,
|
2012-04-03 11:08:27 +04:00
|
|
|
alwaysBlend: false,
|
|
|
|
autoHideControls: true,
|
|
|
|
immediateRender: false,
|
|
|
|
wrapHorizontal: false,
|
|
|
|
wrapVertical: false,
|
|
|
|
panHorizontal: true,
|
|
|
|
panVertical: true,
|
2013-01-24 08:00:11 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
visibilityRatio: 0.5,
|
|
|
|
springStiffness: 5.0,
|
2012-08-29 22:46:34 +04:00
|
|
|
clickTimeThreshold: 300,
|
2012-04-03 11:08:27 +04:00
|
|
|
clickDistThreshold: 5,
|
|
|
|
zoomPerClick: 2.0,
|
|
|
|
zoomPerScroll: 1.2,
|
|
|
|
zoomPerSecond: 2.0,
|
2013-01-24 08:00:11 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
showNavigationControl: true,
|
2012-04-11 01:02:24 +04:00
|
|
|
showSequenceControl: true,
|
2012-04-03 11:08:27 +04:00
|
|
|
controlsFadeDelay: 2000,
|
|
|
|
controlsFadeLength: 1500,
|
|
|
|
mouseNavEnabled: true,
|
2013-01-24 08:00:11 +04:00
|
|
|
preserveViewport: false,
|
|
|
|
defaultZoomLevel: 0,
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
showNavigator: true, //promoted to default in 0.9.64
|
2012-04-03 11:08:27 +04:00
|
|
|
navigatorElement: null,
|
|
|
|
navigatorHeight: null,
|
|
|
|
navigatorWidth: null,
|
|
|
|
navigatorPosition: null,
|
2012-09-07 16:55:19 +04:00
|
|
|
navigatorSizeRatio: 0.2,
|
2012-06-05 15:52:00 +04:00
|
|
|
|
2012-08-29 22:46:34 +04:00
|
|
|
showReferenceStrip: false,
|
|
|
|
referenceStripScroll: 'horizontal',
|
|
|
|
referenceStripElement: null,
|
|
|
|
referenceStripHeight: null,
|
|
|
|
referenceStripWidth: null,
|
|
|
|
referenceStripPosition: 'BOTTOM_LEFT',
|
2012-09-07 16:55:19 +04:00
|
|
|
referenceStripSizeRatio: 0.2,
|
2012-08-29 22:46:34 +04:00
|
|
|
|
|
|
|
//COLLECTION VISUALIZATION SETTINGS
|
2013-01-24 08:00:11 +04:00
|
|
|
collectionRows: 3, //or columns depending on layout
|
|
|
|
collectionLayout: 'horizontal', //vertical
|
|
|
|
collectionMode: false,
|
|
|
|
collectionTileSize: 800,
|
2012-08-29 22:46:34 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
//EVENT RELATED CALLBACKS
|
|
|
|
onPageChange: null,
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//PERFORMANCE SETTINGS
|
|
|
|
minPixelRatio: 0.5,
|
|
|
|
imageLoaderLimit: 0,
|
|
|
|
maxImageCacheCount: 200,
|
2012-04-11 01:02:24 +04:00
|
|
|
minZoomImageRatio: 0.8,
|
2012-04-03 11:08:27 +04:00
|
|
|
maxZoomPixelRatio: 2,
|
|
|
|
|
|
|
|
//INTERFACE RESOURCE SETTINGS
|
2012-09-28 22:02:22 +04:00
|
|
|
prefixUrl: "/images/",
|
2012-03-01 17:38:15 +04:00
|
|
|
navImages: {
|
|
|
|
zoomIn: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'zoomin_rest.png',
|
|
|
|
GROUP: 'zoomin_grouphover.png',
|
|
|
|
HOVER: 'zoomin_hover.png',
|
|
|
|
DOWN: 'zoomin_pressed.png'
|
2012-03-01 17:38:15 +04:00
|
|
|
},
|
|
|
|
zoomOut: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'zoomout_rest.png',
|
|
|
|
GROUP: 'zoomout_grouphover.png',
|
|
|
|
HOVER: 'zoomout_hover.png',
|
|
|
|
DOWN: 'zoomout_pressed.png'
|
2012-03-01 17:38:15 +04:00
|
|
|
},
|
|
|
|
home: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'home_rest.png',
|
|
|
|
GROUP: 'home_grouphover.png',
|
|
|
|
HOVER: 'home_hover.png',
|
|
|
|
DOWN: 'home_pressed.png'
|
2012-03-01 17:38:15 +04:00
|
|
|
},
|
|
|
|
fullpage: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'fullpage_rest.png',
|
|
|
|
GROUP: 'fullpage_grouphover.png',
|
|
|
|
HOVER: 'fullpage_hover.png',
|
|
|
|
DOWN: 'fullpage_pressed.png'
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
previous: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'previous_rest.png',
|
|
|
|
GROUP: 'previous_grouphover.png',
|
|
|
|
HOVER: 'previous_hover.png',
|
|
|
|
DOWN: 'previous_pressed.png'
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
next: {
|
2012-09-28 22:02:22 +04:00
|
|
|
REST: 'next_rest.png',
|
|
|
|
GROUP: 'next_grouphover.png',
|
|
|
|
HOVER: 'next_hover.png',
|
|
|
|
DOWN: 'next_pressed.png'
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2013-01-24 08:00:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
//DEVELOPER SETTINGS
|
|
|
|
debugMode: false,
|
|
|
|
debugGridColor: '#437AB2'
|
2012-03-01 17:38:15 +04:00
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* TODO: get rid of this. I can't see how it's required at all. Looks
|
|
|
|
* like an early legacy code artifact.
|
|
|
|
* @static
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
SIGNAL: "----seadragon----",
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
/**
|
|
|
|
* Invokes the the method as if it where a method belonging to the object.
|
|
|
|
* @name $.delegate
|
|
|
|
* @function
|
|
|
|
* @param {Object} object
|
|
|
|
* @param {Function} method
|
|
|
|
*/
|
|
|
|
delegate: function( object, method ) {
|
|
|
|
return function() {
|
|
|
|
if ( arguments === undefined )
|
|
|
|
arguments = [];
|
|
|
|
return method.apply( object, arguments );
|
|
|
|
};
|
|
|
|
},
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An enumeration of Browser vendors including UNKNOWN, IE, FIREFOX,
|
|
|
|
* SAFARI, CHROME, and OPERA.
|
|
|
|
* @name $.BROWSERS
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
BROWSERS: {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
IE: 1,
|
|
|
|
FIREFOX: 2,
|
|
|
|
SAFARI: 3,
|
|
|
|
CHROME: 4,
|
|
|
|
OPERA: 5
|
|
|
|
},
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Returns a DOM Element for the given id or element.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getElement
|
|
|
|
* @param {String|Element} element Accepts an id or element.
|
|
|
|
* @returns {Element} The element with the given id, null, or the element itself.
|
|
|
|
*/
|
2012-01-19 05:15:54 +04:00
|
|
|
getElement: function( element ) {
|
2012-02-10 07:16:09 +04:00
|
|
|
if ( typeof ( element ) == "string" ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
element = document.getElementById( element );
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Determines the position of the upper-left corner of the element.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getElementPosition
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Element|String} element - the elemenet we want the position for.
|
|
|
|
* @returns {Point} - the position of the upper left corner of the element.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getElementPosition: function( element ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
var result = new $.Point(),
|
|
|
|
isFixed,
|
|
|
|
offsetParent;
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
isFixed = $.getElementStyle( element ).position == "fixed";
|
2012-02-01 00:59:09 +04:00
|
|
|
offsetParent = getOffsetParent( element, isFixed );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
while ( offsetParent ) {
|
|
|
|
|
|
|
|
result.x += element.offsetLeft;
|
|
|
|
result.y += element.offsetTop;
|
|
|
|
|
|
|
|
if ( isFixed ) {
|
|
|
|
result = result.plus( $.getPageScroll() );
|
|
|
|
}
|
|
|
|
|
|
|
|
element = offsetParent;
|
|
|
|
isFixed = $.getElementStyle( element ).position == "fixed";
|
2012-02-01 00:59:09 +04:00
|
|
|
offsetParent = getOffsetParent( element, isFixed );
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Determines the height and width of the given element.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getElementSize
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @returns {Point}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getElementSize: function( element ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
return new $.Point(
|
|
|
|
element.clientWidth,
|
|
|
|
element.clientHeight
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Returns the CSSStyle object for the given element.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getElementStyle
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @returns {CSSStyle}
|
|
|
|
*/
|
2012-04-11 01:02:24 +04:00
|
|
|
getElementStyle:
|
|
|
|
document.documentElement.currentStyle ?
|
|
|
|
function( element ) {
|
|
|
|
element = $.getElement( element );
|
2012-01-18 03:30:41 +04:00
|
|
|
return element.currentStyle;
|
2012-04-11 01:02:24 +04:00
|
|
|
} :
|
|
|
|
function( element ) {
|
|
|
|
element = $.getElement( element );
|
2012-01-18 03:30:41 +04:00
|
|
|
return window.getComputedStyle( element, "" );
|
2012-04-11 01:02:24 +04:00
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Gets the latest event, really only useful internally since its
|
|
|
|
* specific to IE behavior. TODO: Deprecate this from the api and
|
|
|
|
* use it internally.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getEvent
|
|
|
|
* @param {Event} [event]
|
|
|
|
* @returns {Event}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getEvent: function( event ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
if( event ){
|
|
|
|
$.getEvent = function( event ){
|
|
|
|
return event;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
$.getEvent = function( event ){
|
|
|
|
return window.event;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return $.getEvent( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Gets the position of the mouse on the screen for a given event.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getMousePosition
|
|
|
|
* @param {Event} [event]
|
|
|
|
* @returns {Point}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getMousePosition: function( event ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( typeof( event.pageX ) == "number" ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getMousePosition = function( event ){
|
|
|
|
var result = new $.Point();
|
|
|
|
|
|
|
|
event = $.getEvent( event );
|
|
|
|
result.x = event.pageX;
|
|
|
|
result.y = event.pageY;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( typeof( event.clientX ) == "number" ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getMousePosition = function( event ){
|
|
|
|
var result = new $.Point();
|
|
|
|
|
|
|
|
event = $.getEvent( event );
|
|
|
|
result.x =
|
|
|
|
event.clientX +
|
|
|
|
document.body.scrollLeft +
|
|
|
|
document.documentElement.scrollLeft;
|
|
|
|
result.y =
|
|
|
|
event.clientY +
|
|
|
|
document.body.scrollTop +
|
|
|
|
document.documentElement.scrollTop;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unknown event mouse position, no known technique."
|
|
|
|
);
|
|
|
|
}
|
2012-01-18 08:13:29 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
return $.getMousePosition( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Determines the pages current scroll position.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getPageScroll
|
|
|
|
* @returns {Point}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getPageScroll: function() {
|
2012-04-11 01:02:24 +04:00
|
|
|
var docElement = document.documentElement || {},
|
|
|
|
body = document.body || {};
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
if ( typeof( window.pageXOffset ) == "number" ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getPageScroll = function(){
|
|
|
|
return new $.Point(
|
|
|
|
window.pageXOffset,
|
|
|
|
window.pageYOffset
|
|
|
|
);
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( body.scrollLeft || body.scrollTop ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getPageScroll = function(){
|
|
|
|
return new $.Point(
|
|
|
|
document.body.scrollLeft,
|
|
|
|
document.body.scrollTop
|
|
|
|
);
|
|
|
|
};
|
2012-02-02 01:56:04 +04:00
|
|
|
} else if ( docElement.scrollLeft || docElement.scrollTop ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getPageScroll = function(){
|
|
|
|
return new $.Point(
|
|
|
|
document.documentElement.scrollLeft,
|
|
|
|
document.documentElement.scrollTop
|
|
|
|
);
|
|
|
|
};
|
2012-04-12 21:20:24 +04:00
|
|
|
} else {
|
|
|
|
$.getPageScroll = function(){
|
|
|
|
return new $.Point(0,0);
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
return $.getPageScroll();
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Determines the size of the browsers window.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getWindowSize
|
|
|
|
* @returns {Point}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getWindowSize: function() {
|
2012-04-11 01:02:24 +04:00
|
|
|
var docElement = document.documentElement || {},
|
2012-01-18 03:30:41 +04:00
|
|
|
body = document.body || {};
|
|
|
|
|
|
|
|
if ( typeof( window.innerWidth ) == 'number' ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getWindowSize = function(){
|
|
|
|
return new $.Point(
|
|
|
|
window.innerWidth,
|
|
|
|
window.innerHeight
|
|
|
|
);
|
|
|
|
}
|
2012-02-02 01:56:04 +04:00
|
|
|
} else if ( docElement.clientWidth || docElement.clientHeight ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getWindowSize = function(){
|
|
|
|
return new $.Point(
|
|
|
|
document.documentElement.clientWidth,
|
|
|
|
document.documentElement.clientHeight
|
|
|
|
);
|
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( body.clientWidth || body.clientHeight ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.getWindowSize = function(){
|
|
|
|
return new $.Point(
|
|
|
|
document.body.clientWidth,
|
|
|
|
document.body.clientHeight
|
|
|
|
);
|
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
} else {
|
|
|
|
throw new Error("Unknown window size, no known technique.");
|
|
|
|
}
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
return $.getWindowSize();
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Wraps the given element in a nest of divs so that the element can
|
|
|
|
* be easily centered.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.makeCenteredNode
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @returns {Element}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
makeCenteredNode: function( element ) {
|
|
|
|
|
|
|
|
var div = $.makeNeutralElement( "div" ),
|
|
|
|
html = [],
|
|
|
|
innerDiv,
|
|
|
|
innerDivs;
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
//TODO: I dont understand the use of # inside the style attributes
|
|
|
|
// below. Invetigate the results of the constructed html in
|
|
|
|
// the browser and clean up the mark-up to make this clearer.
|
|
|
|
html.push('<div style="display:table; height:100%; width:100%;');
|
|
|
|
html.push('border:none; margin:0px; padding:0px;'); // neutralizing
|
|
|
|
html.push('#position:relative; overflow:hidden; text-align:left;">');
|
|
|
|
html.push('<div style="#position:absolute; #top:50%; width:100%; ');
|
|
|
|
html.push('border:none; margin:0px; padding:0px;'); // neutralizing
|
|
|
|
html.push('display:table-cell; vertical-align:middle;">');
|
|
|
|
html.push('<div style="#position:relative; #top:-50%; width:100%; ');
|
|
|
|
html.push('border:none; margin:0px; padding:0px;'); // neutralizing
|
|
|
|
html.push('text-align:center;"></div></div></div>');
|
|
|
|
|
|
|
|
div.innerHTML = html.join( '' );
|
|
|
|
div = div.firstChild;
|
|
|
|
|
|
|
|
innerDiv = div;
|
|
|
|
innerDivs = div.getElementsByTagName( "div" );
|
|
|
|
while ( innerDivs.length > 0 ) {
|
|
|
|
innerDiv = innerDivs[ 0 ];
|
|
|
|
innerDivs = innerDiv.getElementsByTagName( "div" );
|
|
|
|
}
|
|
|
|
|
|
|
|
innerDiv.appendChild( element );
|
|
|
|
|
|
|
|
return div;
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Creates an easily positionable element of the given type that therefor
|
|
|
|
* serves as an excellent container element.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.makeNeutralElement
|
|
|
|
* @param {String} tagName
|
|
|
|
* @returns {Element}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
makeNeutralElement: function( tagName ) {
|
|
|
|
var element = document.createElement( tagName ),
|
|
|
|
style = element.style;
|
|
|
|
|
|
|
|
style.background = "transparent none";
|
|
|
|
style.border = "none";
|
|
|
|
style.margin = "0px";
|
|
|
|
style.padding = "0px";
|
|
|
|
style.position = "static";
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Ensures an image is loaded correctly to support alpha transparency.
|
|
|
|
* Generally only IE has issues doing this correctly for formats like
|
|
|
|
* png.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.makeTransparentImage
|
|
|
|
* @param {String} src
|
|
|
|
* @returns {Element}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
makeTransparentImage: function( src ) {
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
$.makeTransparentImage = function( src ){
|
|
|
|
var img = $.makeNeutralElement( "img" );
|
|
|
|
|
|
|
|
img.src = src;
|
|
|
|
|
|
|
|
return img;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE && $.Browser.version < 7 ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
$.makeTransparentImage = function( src ){
|
|
|
|
var img = $.makeNeutralElement( "img" ),
|
|
|
|
element = null;
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
element = $.makeNeutralElement("span");
|
|
|
|
element.style.display = "inline-block";
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
img.onload = function() {
|
|
|
|
element.style.width = element.style.width || img.width + "px";
|
|
|
|
element.style.height = element.style.height || img.height + "px";
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
img.onload = null;
|
|
|
|
img = null; // to prevent memory leaks in IE
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
img.src = src;
|
|
|
|
element.style.filter =
|
|
|
|
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
|
|
|
|
src +
|
|
|
|
"', sizingMethod='scale')";
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
return element;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $.makeTransparentImage( src );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Sets the opacity of the specified element.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.setElementOpacity
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @param {Number} opacity
|
|
|
|
* @param {Boolean} [usesAlpha]
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
setElementOpacity: function( element, opacity, usesAlpha ) {
|
|
|
|
|
|
|
|
var previousFilter,
|
|
|
|
ieOpacity,
|
|
|
|
ieFilter;
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( usesAlpha && !$.Browser.alpha ) {
|
|
|
|
opacity = Math.round( opacity );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( opacity < 1 ) {
|
|
|
|
element.style.opacity = opacity;
|
|
|
|
} else {
|
|
|
|
element.style.opacity = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( opacity == 1 ) {
|
|
|
|
prevFilter = element.style.filter || "";
|
|
|
|
element.style.filter = prevFilter.replace(/alpha\(.*?\)/g, "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ieOpacity = Math.round( 100 * opacity );
|
|
|
|
ieFilter = " alpha(opacity=" + ieOpacity + ") ";
|
|
|
|
|
|
|
|
//TODO: find out why this uses a try/catch instead of a predetermined
|
|
|
|
// routine or at least an if/elseif/else
|
|
|
|
try {
|
|
|
|
if ( element.filters && element.filters.alpha ) {
|
|
|
|
element.filters.alpha.opacity = ieOpacity;
|
|
|
|
} else {
|
|
|
|
element.style.filter += ieFilter;
|
|
|
|
}
|
|
|
|
} catch ( e ) {
|
|
|
|
element.style.filter += ieFilter;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Adds an event listener for the given element, eventName and handler.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.addEvent
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @param {String} eventName
|
|
|
|
* @param {Function} handler
|
|
|
|
* @param {Boolean} [useCapture]
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
addEvent: function( element, eventName, handler, useCapture ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
//TODO: Why do this if/else on every method call instead of just
|
|
|
|
// defining this function once based on the same logic
|
|
|
|
if ( element.addEventListener ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.addEvent = function( element, eventName, handler, useCapture ){
|
|
|
|
element = $.getElement( element );
|
|
|
|
element.addEventListener( eventName, handler, useCapture );
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( element.attachEvent ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.addEvent = function( element, eventName, handler, useCapture ){
|
|
|
|
element = $.getElement( element );
|
|
|
|
element.attachEvent( "on" + eventName, handler );
|
|
|
|
if ( useCapture && element.setCapture ) {
|
|
|
|
element.setCapture();
|
|
|
|
}
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unable to attach event handler, no known technique."
|
|
|
|
);
|
|
|
|
}
|
2012-04-11 01:02:24 +04:00
|
|
|
|
|
|
|
return $.addEvent( element, eventName, handler, useCapture );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Remove a given event listener for the given element, event type and
|
|
|
|
* handler.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.removeEvent
|
|
|
|
* @param {Element|String} element
|
|
|
|
* @param {String} eventName
|
|
|
|
* @param {Function} handler
|
|
|
|
* @param {Boolean} [useCapture]
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
removeEvent: function( element, eventName, handler, useCapture ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
//TODO: Why do this if/else on every method call instead of just
|
|
|
|
// defining this function once based on the same logic
|
|
|
|
if ( element.removeEventListener ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.removeEvent = function( element, eventName, handler, useCapture ) {
|
|
|
|
element = $.getElement( element );
|
|
|
|
element.removeEventListener( eventName, handler, useCapture );
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( element.detachEvent ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.removeEvent = function( element, eventName, handler, useCapture ) {
|
|
|
|
element = $.getElement( element );
|
|
|
|
element.detachEvent("on" + eventName, handler);
|
|
|
|
if ( useCapture && element.releaseCapture ) {
|
|
|
|
element.releaseCapture();
|
|
|
|
}
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unable to detach event handler, no known technique."
|
|
|
|
);
|
|
|
|
}
|
2012-04-11 01:02:24 +04:00
|
|
|
return $.removeEvent( element, eventName, handler, useCapture );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Cancels the default browser behavior had the event propagated all
|
|
|
|
* the way up the DOM to the window object.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.cancelEvent
|
|
|
|
* @param {Event} [event]
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
cancelEvent: function( event ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
event = $.getEvent( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
if ( event.preventDefault ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.cancelEvent = function( event ){
|
|
|
|
// W3C for preventing default
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$.cancelEvent = function( event ){
|
|
|
|
event = $.getEvent( event );
|
|
|
|
// legacy for preventing default
|
|
|
|
event.cancel = true;
|
|
|
|
// IE for preventing default
|
|
|
|
event.returnValue = false;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2012-04-11 01:02:24 +04:00
|
|
|
$.cancelEvent( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Stops the propagation of the event up the DOM.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.stopEvent
|
|
|
|
* @param {Event} [event]
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
stopEvent: function( event ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
event = $.getEvent( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
if ( event.stopPropagation ) {
|
|
|
|
// W3C for stopping propagation
|
|
|
|
$.stopEvent = function( event ){
|
|
|
|
event.stopPropagation();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// IE for stopping propagation
|
|
|
|
$.stopEvent = function( event ){
|
|
|
|
event = $.getEvent( event );
|
|
|
|
event.cancelBubble = true;
|
|
|
|
};
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
$.stopEvent( event );
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Similar to OpenSeadragon.delegate, but it does not immediately call
|
|
|
|
* the method on the object, returning a function which can be called
|
|
|
|
* repeatedly to delegate the method. It also allows additonal arguments
|
|
|
|
* to be passed during construction which will be added during each
|
|
|
|
* invocation, and each invocation can add additional arguments as well.
|
|
|
|
*
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.createCallback
|
|
|
|
* @param {Object} object
|
|
|
|
* @param {Function} method
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param [args] any additional arguments are passed as arguments to the
|
|
|
|
* created callback
|
2012-01-25 23:14:02 +04:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
createCallback: function( object, method ) {
|
|
|
|
//TODO: This pattern is painful to use and debug. It's much cleaner
|
|
|
|
// to use pinning plus anonymous functions. Get rid of this
|
|
|
|
// pattern!
|
|
|
|
var initialArgs = [],
|
|
|
|
i;
|
|
|
|
for ( i = 2; i < arguments.length; i++ ) {
|
|
|
|
initialArgs.push( arguments[ i ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
var args = initialArgs.concat( [] ),
|
|
|
|
i;
|
|
|
|
for ( i = 0; i < arguments.length; i++ ) {
|
|
|
|
args.push( arguments[ i ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return method.apply( object, args );
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* Retreives the value of a url parameter from the window.location string.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getUrlParameter
|
|
|
|
* @param {String} key
|
|
|
|
* @returns {String} The value of the url parameter or null if no param matches.
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
getUrlParameter: function( key ) {
|
|
|
|
var value = URLPARAMS[ key ];
|
|
|
|
return value ? value : null;
|
|
|
|
},
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
createAjaxRequest: function(){
|
|
|
|
var request;
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
if ( window.ActiveXObject ) {
|
|
|
|
//TODO: very bad...Why check every time using try/catch when
|
|
|
|
// we could determine once at startup which activeX object
|
|
|
|
// was supported. This will have significant impact on
|
2012-06-05 15:52:00 +04:00
|
|
|
// performance for IE Browsers DONE
|
2012-01-18 03:30:41 +04:00
|
|
|
for ( i = 0; i < ACTIVEX.length; i++ ) {
|
|
|
|
try {
|
|
|
|
request = new ActiveXObject( ACTIVEX[ i ] );
|
2012-04-11 01:02:24 +04:00
|
|
|
$.createAjaxRequest = function( ){
|
|
|
|
return new ActiveXObject( ACTIVEX[ i ] );
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( window.XMLHttpRequest ) {
|
2012-04-11 01:02:24 +04:00
|
|
|
$.createAjaxRequest = function( ){
|
|
|
|
return new XMLHttpRequest();
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
request = new XMLHttpRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !request ) {
|
|
|
|
throw new Error( "Browser doesn't support XMLHttpRequest." );
|
|
|
|
}
|
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Makes an AJAX request.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.makeAjaxRequest
|
|
|
|
* @param {String} url - the url to request
|
|
|
|
* @param {Function} [callback] - a function to call when complete
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
makeAjaxRequest: function( url, callback ) {
|
2012-06-05 15:52:00 +04:00
|
|
|
|
|
|
|
var async = true,
|
2012-04-11 01:02:24 +04:00
|
|
|
request = $.createAjaxRequest(),
|
|
|
|
actual,
|
2012-06-05 15:52:00 +04:00
|
|
|
options,
|
2012-04-11 01:02:24 +04:00
|
|
|
i;
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
|
|
|
|
if( $.isPlainObject( url ) ){
|
|
|
|
options.async = options.async || async;
|
|
|
|
}else{
|
|
|
|
options = {
|
|
|
|
url: url,
|
|
|
|
async: $.isFunction( callback ),
|
|
|
|
success: callback,
|
|
|
|
error: null
|
2012-04-11 01:02:24 +04:00
|
|
|
};
|
2012-06-05 15:52:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( options.async ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
/** @ignore */
|
2012-01-18 03:30:41 +04:00
|
|
|
request.onreadystatechange = function() {
|
|
|
|
if ( request.readyState == 4) {
|
|
|
|
request.onreadystatechange = new function() { };
|
2012-06-05 15:52:00 +04:00
|
|
|
options.success( request );
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-06-05 15:52:00 +04:00
|
|
|
request.open( "GET", options.url, options.async );
|
2012-01-18 03:30:41 +04:00
|
|
|
request.send( null );
|
|
|
|
} catch (e) {
|
2012-02-01 00:59:09 +04:00
|
|
|
$.console.log(
|
2012-01-24 07:48:45 +04:00
|
|
|
"%s while making AJAX request: %s",
|
|
|
|
e.name,
|
|
|
|
e.message
|
|
|
|
);
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
request.onreadystatechange = null;
|
|
|
|
request = null;
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
if ( options.error && $.isFunction( options.error ) ) {
|
|
|
|
options.error( request );
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
if( !options.async && $.isFunction( options.success ) ){
|
|
|
|
options.success( request );
|
|
|
|
}
|
|
|
|
|
|
|
|
return options.async ? null : request;
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
2012-04-11 01:02:24 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.jsonp
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.url
|
|
|
|
* @param {Function} options.callback
|
|
|
|
* @param {String} [options.param='callback'] The name of the url parameter
|
2012-03-07 07:20:00 +04:00
|
|
|
* to request the jsonp provider with.
|
2012-04-11 01:02:24 +04:00
|
|
|
* @param {String} [options.callbackName=] The name of the callback to
|
2012-03-07 07:20:00 +04:00
|
|
|
* request the jsonp provider with.
|
|
|
|
*/
|
|
|
|
jsonp: function( options ){
|
|
|
|
var script,
|
|
|
|
url = options.url,
|
|
|
|
head = document.head ||
|
|
|
|
document.getElementsByTagName( "head" )[ 0 ] ||
|
|
|
|
document.documentElement,
|
|
|
|
jsonpCallback = options.callbackName || 'openseadragon' + (+new Date()),
|
|
|
|
previous = window[ jsonpCallback ],
|
|
|
|
replace = "$1" + jsonpCallback + "$2",
|
|
|
|
callbackParam = options.param || 'callback',
|
|
|
|
callback = options.callback;
|
|
|
|
|
|
|
|
url = url.replace( /(\=)\?(&|$)|\?\?/i, replace );
|
|
|
|
// Add callback manually
|
|
|
|
url += (/\?/.test( url ) ? "&" : "?") + callbackParam + "=" + jsonpCallback;
|
|
|
|
|
|
|
|
// Install callback
|
|
|
|
window[ jsonpCallback ] = function( response ) {
|
|
|
|
if ( !previous ){
|
2012-04-12 21:20:24 +04:00
|
|
|
try{
|
|
|
|
delete window[ jsonpCallback ];
|
|
|
|
}catch(e){
|
|
|
|
//swallow
|
|
|
|
}
|
2012-03-07 07:20:00 +04:00
|
|
|
} else {
|
|
|
|
window[ jsonpCallback ] = previous;
|
|
|
|
}
|
|
|
|
if( callback && $.isFunction( callback ) ){
|
|
|
|
callback( response );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
script = document.createElement( "script" );
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
//TODO: having an issue with async info requests
|
|
|
|
if( undefined !== options.async || false !== options.async ){
|
|
|
|
script.async = "async";
|
|
|
|
}
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
if ( options.scriptCharset ) {
|
|
|
|
script.charset = options.scriptCharset;
|
|
|
|
}
|
|
|
|
|
|
|
|
script.src = url;
|
|
|
|
|
|
|
|
// Attach handlers for all browsers
|
|
|
|
script.onload = script.onreadystatechange = function( _, isAbort ) {
|
|
|
|
|
|
|
|
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
|
|
|
|
|
|
|
// Handle memory leak in IE
|
|
|
|
script.onload = script.onreadystatechange = null;
|
|
|
|
|
|
|
|
// Remove the script
|
|
|
|
if ( head && script.parentNode ) {
|
|
|
|
head.removeChild( script );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dereference the script
|
|
|
|
script = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
|
|
|
|
// This arises when a base node is used (#2709 and #4378).
|
|
|
|
head.insertBefore( script, head.firstChild );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-06-05 15:52:00 +04:00
|
|
|
* Loads a Deep Zoom Image description from a url, XML string or JSON string
|
|
|
|
* and provides a callback hook for the resulting Document
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
2012-02-01 00:59:09 +04:00
|
|
|
* @name OpenSeadragon.createFromDZI
|
|
|
|
* @param {String} xmlUrl
|
|
|
|
* @param {String} xmlString
|
|
|
|
* @param {Function} callback
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
createFromDZI: function( dzi, callback, tileHost ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
var async = typeof ( callback ) == "function",
|
2012-06-05 15:52:00 +04:00
|
|
|
dziUrl = (
|
|
|
|
dzi.substring(0,1) != '<' &&
|
|
|
|
dzi.substring(0,1) != '{'
|
|
|
|
) ? dzi : null,
|
|
|
|
dziString = dziUrl ? null : dzi,
|
2012-02-01 00:59:09 +04:00
|
|
|
error = null,
|
|
|
|
urlParts,
|
|
|
|
filename,
|
|
|
|
lastDot,
|
2012-04-12 21:20:24 +04:00
|
|
|
tilesUrl,
|
|
|
|
callbackName;
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
if( tileHost ){
|
|
|
|
|
|
|
|
tilesUrl = tileHost + "/_files/";
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
} else if( dziUrl ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
urlParts = dziUrl.split( '/' );
|
2012-02-01 00:59:09 +04:00
|
|
|
filename = urlParts[ urlParts.length - 1 ];
|
2012-06-05 15:52:00 +04:00
|
|
|
if( filename.match(/_dzi\.js$/) ){
|
|
|
|
//for jsonp dzi specification, the '_dzi' needs to be removed
|
|
|
|
//from the filename to be consistent with the spec
|
|
|
|
filename = filename.replace('_dzi.js', '.js');
|
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
lastDot = filename.lastIndexOf( '.' );
|
|
|
|
|
|
|
|
if ( lastDot > -1 ) {
|
|
|
|
urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot );
|
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tilesUrl = urlParts.join( '/' ) + "_files/";
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function finish( func, obj ) {
|
|
|
|
try {
|
|
|
|
return func( obj, tilesUrl );
|
|
|
|
} catch ( e ) {
|
|
|
|
if ( async ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( async ) {
|
2012-06-05 15:52:00 +04:00
|
|
|
if ( dziString ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
window.setTimeout( function() {
|
2012-06-05 15:52:00 +04:00
|
|
|
var source = finish( processDZIXml, $.parseXml( xmlString ) );
|
2012-02-01 00:59:09 +04:00
|
|
|
// call after finish sets error
|
|
|
|
callback( source, error );
|
|
|
|
}, 1);
|
|
|
|
} else {
|
2012-06-05 15:52:00 +04:00
|
|
|
if( dziUrl.match(/_dzi\.js$/) ){
|
|
|
|
callbackName = dziUrl.split( '/' ).pop().replace('.js','');
|
2012-04-12 21:20:24 +04:00
|
|
|
$.jsonp({
|
2012-06-05 15:52:00 +04:00
|
|
|
url: dziUrl,
|
2012-04-12 21:20:24 +04:00
|
|
|
callbackName: callbackName,
|
|
|
|
callback: function( imageData ){
|
|
|
|
var source = finish( processDZIJSON, imageData.Image );
|
|
|
|
callback( source );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2012-06-05 15:52:00 +04:00
|
|
|
$.makeAjaxRequest( dziUrl, function( xhr ) {
|
2012-04-12 21:20:24 +04:00
|
|
|
var source = finish( processDZIResponse, xhr );
|
|
|
|
// call after finish sets error
|
|
|
|
callback( source, error );
|
|
|
|
});
|
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return null;
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
if ( dziString ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
return finish(
|
|
|
|
processDZIXml,
|
2012-06-05 15:52:00 +04:00
|
|
|
$.parseXml( dziString )
|
2012-02-01 00:59:09 +04:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return finish(
|
|
|
|
processDZIResponse,
|
2012-06-05 15:52:00 +04:00
|
|
|
$.makeAjaxRequest( dziUrl )
|
2012-02-01 00:59:09 +04:00
|
|
|
);
|
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses an XML string into a DOM Document.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.parseXml
|
|
|
|
* @param {String} string
|
|
|
|
* @returns {Document}
|
|
|
|
*/
|
|
|
|
parseXml: function( string ) {
|
|
|
|
//TODO: yet another example where we can determine the correct
|
|
|
|
// implementation once at start-up instead of everytime we use
|
|
|
|
// the function. DONE.
|
|
|
|
if ( window.ActiveXObject ) {
|
|
|
|
|
|
|
|
$.parseXml = function( string ){
|
|
|
|
var xmlDoc = null,
|
|
|
|
parser;
|
|
|
|
|
|
|
|
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
|
|
|
|
xmlDoc.async = false;
|
|
|
|
xmlDoc.loadXML( string );
|
|
|
|
return xmlDoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
} else if ( window.DOMParser ) {
|
|
|
|
|
|
|
|
$.parseXml = function( string ){
|
|
|
|
var xmlDoc = null,
|
|
|
|
parser;
|
|
|
|
|
|
|
|
parser = new DOMParser();
|
|
|
|
xmlDoc = parser.parseFromString( string, "text/xml" );
|
|
|
|
return xmlDoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new Error( "Browser doesn't support XML DOM." );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.parseXml( string );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports whether the image format is supported for tiling in this
|
|
|
|
* version.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.imageFormatSupported
|
|
|
|
* @param {String} [extension]
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
imageFormatSupported: function( extension ) {
|
|
|
|
extension = extension ? extension : "";
|
|
|
|
return !!FILEFORMATS[ extension.toLowerCase() ];
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
});
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current browser vendor, version, and related information regarding
|
|
|
|
* detected features. Features include <br/>
|
|
|
|
* <strong>'alpha'</strong> - Does the browser support image alpha
|
|
|
|
* transparency.<br/>
|
|
|
|
* @name $.Browser
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
$.Browser = {
|
|
|
|
vendor: $.BROWSERS.UNKNOWN,
|
|
|
|
version: 0,
|
|
|
|
alpha: true
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var ACTIVEX = [
|
|
|
|
"Msxml2.XMLHTTP",
|
|
|
|
"Msxml3.XMLHTTP",
|
|
|
|
"Microsoft.XMLHTTP"
|
|
|
|
],
|
|
|
|
FILEFORMATS = {
|
|
|
|
"bmp": false,
|
|
|
|
"jpeg": true,
|
|
|
|
"jpg": true,
|
|
|
|
"png": true,
|
|
|
|
"tif": false,
|
|
|
|
"wdp": false
|
|
|
|
},
|
|
|
|
URLPARAMS = {};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
//A small auto-executing routine to determine the browser vendor,
|
|
|
|
//version and supporting feature sets.
|
|
|
|
var app = navigator.appName,
|
|
|
|
ver = navigator.appVersion,
|
|
|
|
ua = navigator.userAgent;
|
|
|
|
|
|
|
|
//console.error( 'appName: ' + navigator.appName );
|
|
|
|
//console.error( 'appVersion: ' + navigator.appVersion );
|
|
|
|
//console.error( 'userAgent: ' + navigator.userAgent );
|
|
|
|
|
|
|
|
switch( navigator.appName ){
|
|
|
|
case "Microsoft Internet Explorer":
|
|
|
|
if( !!window.attachEvent &&
|
|
|
|
!!window.ActiveXObject ) {
|
|
|
|
|
|
|
|
$.Browser.vendor = $.BROWSERS.IE;
|
|
|
|
$.Browser.version = parseFloat(
|
|
|
|
ua.substring(
|
|
|
|
ua.indexOf( "MSIE" ) + 5,
|
|
|
|
ua.indexOf( ";", ua.indexOf( "MSIE" ) ) )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Netscape":
|
|
|
|
if( !!window.addEventListener ){
|
|
|
|
if ( ua.indexOf( "Firefox" ) >= 0 ) {
|
|
|
|
$.Browser.vendor = $.BROWSERS.FIREFOX;
|
|
|
|
$.Browser.version = parseFloat(
|
|
|
|
ua.substring( ua.indexOf( "Firefox" ) + 8 )
|
|
|
|
);
|
|
|
|
} else if ( ua.indexOf( "Safari" ) >= 0 ) {
|
|
|
|
$.Browser.vendor = ua.indexOf( "Chrome" ) >= 0 ?
|
|
|
|
$.BROWSERS.CHROME :
|
|
|
|
$.BROWSERS.SAFARI;
|
|
|
|
$.Browser.version = parseFloat(
|
|
|
|
ua.substring(
|
|
|
|
ua.substring( 0, ua.indexOf( "Safari" ) ).lastIndexOf( "/" ) + 1,
|
|
|
|
ua.indexOf( "Safari" )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Opera":
|
|
|
|
$.Browser.vendor = $.BROWSERS.OPERA;
|
|
|
|
$.Browser.version = parseFloat( ver );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore '?' portion of query string
|
|
|
|
var query = window.location.search.substring( 1 ),
|
|
|
|
parts = query.split('&'),
|
|
|
|
part,
|
|
|
|
sep,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = 0; i < parts.length; i++ ) {
|
|
|
|
part = parts[ i ];
|
|
|
|
sep = part.indexOf( '=' );
|
|
|
|
|
|
|
|
if ( sep > 0 ) {
|
|
|
|
URLPARAMS[ part.substring( 0, sep ) ] =
|
|
|
|
decodeURIComponent( part.substring( sep + 1 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//determine if this browser supports image alpha transparency
|
|
|
|
$.Browser.alpha = !(
|
2012-04-11 01:02:24 +04:00
|
|
|
(
|
|
|
|
$.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
$.Browser.version < 9
|
|
|
|
) || (
|
2012-03-01 17:38:15 +04:00
|
|
|
$.Browser.vendor == $.BROWSERS.CHROME &&
|
|
|
|
$.Browser.version < 2
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
//TODO: $.console is often used inside a try/catch block which generally
|
|
|
|
// prevents allowings errors to occur with detection until a debugger
|
|
|
|
// is attached. Although I've been guilty of the same anti-pattern
|
|
|
|
// I eventually was convinced that errors should naturally propogate in
|
|
|
|
// all but the most special cases.
|
|
|
|
/**
|
|
|
|
* A convenient alias for console when available, and a simple null
|
|
|
|
* function when console is unavailable.
|
|
|
|
* @static
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
var nullfunction = function( msg ){
|
|
|
|
//document.location.hash = msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.console = window.console || {
|
|
|
|
log: nullfunction,
|
|
|
|
debug: nullfunction,
|
|
|
|
info: nullfunction,
|
|
|
|
warn: nullfunction,
|
|
|
|
error: nullfunction
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Element} element
|
|
|
|
* @param {Boolean} [isFixed]
|
|
|
|
* @returns {Element}
|
|
|
|
*/
|
|
|
|
function getOffsetParent( element, isFixed ) {
|
|
|
|
if ( isFixed && element != document.body ) {
|
|
|
|
return document.body;
|
|
|
|
} else {
|
|
|
|
return element.offsetParent;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {XMLHttpRequest} xhr
|
|
|
|
* @param {String} tilesUrl
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
function processDZIResponse( xhr, tilesUrl ) {
|
|
|
|
var status,
|
|
|
|
statusText,
|
|
|
|
doc = null;
|
|
|
|
|
|
|
|
if ( !xhr ) {
|
|
|
|
throw new Error( $.getString( "Errors.Security" ) );
|
|
|
|
} else if ( xhr.status !== 200 && xhr.status !== 0 ) {
|
|
|
|
status = xhr.status;
|
|
|
|
statusText = ( status == 404 ) ?
|
|
|
|
"Not Found" :
|
|
|
|
xhr.statusText;
|
|
|
|
throw new Error( $.getString( "Errors.Status", status, statusText ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( xhr.responseXML && xhr.responseXML.documentElement ) {
|
|
|
|
doc = xhr.responseXML;
|
|
|
|
} else if ( xhr.responseText ) {
|
2012-06-05 15:52:00 +04:00
|
|
|
doc = $.parseXml( xhr.responseText );
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return processDZIXml( doc, tilesUrl );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Document} xmlDoc
|
|
|
|
* @param {String} tilesUrl
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
function processDZIXml( xmlDoc, tilesUrl ) {
|
|
|
|
|
|
|
|
if ( !xmlDoc || !xmlDoc.documentElement ) {
|
|
|
|
throw new Error( $.getString( "Errors.Xml" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
var root = xmlDoc.documentElement,
|
|
|
|
rootName = root.tagName;
|
|
|
|
|
|
|
|
if ( rootName == "Image" ) {
|
|
|
|
try {
|
|
|
|
return processDZI( root, tilesUrl );
|
|
|
|
} catch ( e ) {
|
|
|
|
throw (e instanceof Error) ?
|
|
|
|
e :
|
|
|
|
new Error( $.getString("Errors.Dzi") );
|
|
|
|
}
|
|
|
|
} else if ( rootName == "Collection" ) {
|
|
|
|
throw new Error( $.getString( "Errors.Dzc" ) );
|
|
|
|
} else if ( rootName == "Error" ) {
|
|
|
|
return processDZIError( root );
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error( $.getString( "Errors.Dzi" ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Element} imageNode
|
|
|
|
* @param {String} tilesUrl
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
function processDZI( imageNode, tilesUrl ) {
|
|
|
|
var fileFormat = imageNode.getAttribute( "Format" ),
|
|
|
|
sizeNode = imageNode.getElementsByTagName( "Size" )[ 0 ],
|
|
|
|
dispRectNodes = imageNode.getElementsByTagName( "DisplayRect" ),
|
|
|
|
width = parseInt( sizeNode.getAttribute( "Width" ) ),
|
|
|
|
height = parseInt( sizeNode.getAttribute( "Height" ) ),
|
|
|
|
tileSize = parseInt( imageNode.getAttribute( "TileSize" ) ),
|
|
|
|
tileOverlap = parseInt( imageNode.getAttribute( "Overlap" ) ),
|
|
|
|
dispRects = [],
|
|
|
|
dispRectNode,
|
|
|
|
rectNode,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( !imageFormatSupported( fileFormat ) ) {
|
|
|
|
throw new Error(
|
|
|
|
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < dispRectNodes.length; i++ ) {
|
|
|
|
dispRectNode = dispRectNodes[ i ];
|
|
|
|
rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ];
|
|
|
|
|
|
|
|
dispRects.push( new $.DisplayRect(
|
|
|
|
parseInt( rectNode.getAttribute( "X" ) ),
|
|
|
|
parseInt( rectNode.getAttribute( "Y" ) ),
|
|
|
|
parseInt( rectNode.getAttribute( "Width" ) ),
|
|
|
|
parseInt( rectNode.getAttribute( "Height" ) ),
|
|
|
|
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
|
|
|
|
parseInt( dispRectNode.getAttribute( "MaxLevel" ) )
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return new $.DziTileSource(
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
tileSize,
|
|
|
|
tileOverlap,
|
|
|
|
tilesUrl,
|
|
|
|
fileFormat,
|
|
|
|
dispRects
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2012-04-12 21:20:24 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Element} imageNode
|
|
|
|
* @param {String} tilesUrl
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-04-12 21:20:24 +04:00
|
|
|
*/
|
|
|
|
function processDZIJSON( imageData, tilesUrl ) {
|
|
|
|
var fileFormat = imageData.Format,
|
|
|
|
sizeData = imageData.Size,
|
|
|
|
dispRectData = imageData.DisplayRect || [],
|
|
|
|
width = parseInt( sizeData.Width ),
|
|
|
|
height = parseInt( sizeData.Height ),
|
|
|
|
tileSize = parseInt( imageData.TileSize ),
|
|
|
|
tileOverlap = parseInt( imageData.Overlap ),
|
|
|
|
dispRects = [],
|
|
|
|
rectData,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( !imageFormatSupported( fileFormat ) ) {
|
|
|
|
throw new Error(
|
|
|
|
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0; i < dispRectData.length; i++ ) {
|
|
|
|
rectData = dispRectData[ i ].Rect;
|
|
|
|
|
|
|
|
dispRects.push( new $.DisplayRect(
|
|
|
|
parseInt( rectData.X ),
|
|
|
|
parseInt( rectData.Y ),
|
|
|
|
parseInt( rectData.Width ),
|
|
|
|
parseInt( rectData.Height ),
|
|
|
|
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
|
|
|
|
parseInt( rectData.MaxLevel )
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return new $.DziTileSource(
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
tileSize,
|
|
|
|
tileOverlap,
|
|
|
|
tilesUrl,
|
|
|
|
fileFormat,
|
|
|
|
dispRects
|
|
|
|
);
|
|
|
|
};
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Document} errorNode
|
|
|
|
* @throws {Error}
|
2012-06-05 15:52:00 +04:00
|
|
|
* @deprecated
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
function processDZIError( errorNode ) {
|
|
|
|
var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
|
|
|
|
message = messageNode.firstChild.nodeValue;
|
|
|
|
|
|
|
|
throw new Error(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|