2011-12-06 07:50:25 +04:00
|
|
|
/**
|
2012-04-03 11:08:27 +04:00
|
|
|
* @version OpenSeadragon 0.9.40
|
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>
|
|
|
|
*
|
|
|
|
* @author <br/>(c) 2011 Christopher Thatcher
|
|
|
|
* @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-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-03-01 17:38:15 +04:00
|
|
|
* @param {String} [options.prefixUrl='']
|
|
|
|
* Appends the prefixUrl to navImages paths, which is very useful
|
|
|
|
* 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 03:29:00 +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
|
|
|
|
2011-12-17 03:29:16 +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
|
|
|
|
debugMode: true,
|
|
|
|
animationTime: 1.5,
|
|
|
|
blendTime: 0.5,
|
|
|
|
alwaysBlend: false,
|
|
|
|
autoHideControls: true,
|
|
|
|
immediateRender: false,
|
|
|
|
wrapHorizontal: false,
|
|
|
|
wrapVertical: false,
|
|
|
|
panHorizontal: true,
|
|
|
|
panVertical: true,
|
|
|
|
visibilityRatio: 0.5,
|
|
|
|
springStiffness: 5.0,
|
|
|
|
clickTimeThreshold: 200,
|
|
|
|
clickDistThreshold: 5,
|
|
|
|
zoomPerClick: 2.0,
|
|
|
|
zoomPerScroll: 1.2,
|
|
|
|
zoomPerSecond: 2.0,
|
|
|
|
showNavigationControl: true,
|
|
|
|
controlsFadeDelay: 2000,
|
|
|
|
controlsFadeLength: 1500,
|
|
|
|
mouseNavEnabled: true,
|
|
|
|
showNavigator: false,
|
|
|
|
navigatorElement: null,
|
|
|
|
navigatorHeight: null,
|
|
|
|
navigatorWidth: null,
|
|
|
|
navigatorPosition: null,
|
|
|
|
navigatorSizeRatio: 0.25,
|
|
|
|
preserveViewport: false,
|
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,
|
|
|
|
minZoomImageRatio: 0.9,
|
|
|
|
maxZoomPixelRatio: 2,
|
|
|
|
|
|
|
|
//INTERFACE RESOURCE SETTINGS
|
|
|
|
prefixUrl: null,
|
2012-03-01 17:38:15 +04:00
|
|
|
navImages: {
|
|
|
|
zoomIn: {
|
|
|
|
REST: '/images/zoomin_rest.png',
|
|
|
|
GROUP: '/images/zoomin_grouphover.png',
|
|
|
|
HOVER: '/images/zoomin_hover.png',
|
|
|
|
DOWN: '/images/zoomin_pressed.png'
|
|
|
|
},
|
|
|
|
zoomOut: {
|
|
|
|
REST: '/images/zoomout_rest.png',
|
|
|
|
GROUP: '/images/zoomout_grouphover.png',
|
|
|
|
HOVER: '/images/zoomout_hover.png',
|
|
|
|
DOWN: '/images/zoomout_pressed.png'
|
|
|
|
},
|
|
|
|
home: {
|
|
|
|
REST: '/images/home_rest.png',
|
|
|
|
GROUP: '/images/home_grouphover.png',
|
|
|
|
HOVER: '/images/home_hover.png',
|
|
|
|
DOWN: '/images/home_pressed.png'
|
|
|
|
},
|
|
|
|
fullpage: {
|
|
|
|
REST: '/images/fullpage_rest.png',
|
|
|
|
GROUP: '/images/fullpage_grouphover.png',
|
|
|
|
HOVER: '/images/fullpage_hover.png',
|
|
|
|
DOWN: '/images/fullpage_pressed.png'
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
previous: {
|
|
|
|
REST: '/images/previous_rest.png',
|
|
|
|
GROUP: '/images/previous_grouphover.png',
|
|
|
|
HOVER: '/images/previous_hover.png',
|
|
|
|
DOWN: '/images/previous_pressed.png'
|
|
|
|
},
|
|
|
|
next: {
|
|
|
|
REST: '/images/next_rest.png',
|
|
|
|
GROUP: '/images/next_grouphover.png',
|
|
|
|
HOVER: '/images/next_hover.png',
|
|
|
|
DOWN: '/images/next_pressed.png'
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 17:38:15 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +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----",
|
2011-12-06 07:50:25 +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
|
|
|
|
},
|
|
|
|
|
2011-12-06 07:50:25 +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;
|
|
|
|
},
|
2011-12-06 07:50:25 +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 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;
|
2011-12-06 07:50:25 +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 );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
while ( offsetParent ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
result.x += element.offsetLeft;
|
|
|
|
result.y += element.offsetTop;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( isFixed ) {
|
|
|
|
result = result.plus( $.getPageScroll() );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
element = offsetParent;
|
|
|
|
isFixed = $.getElementStyle( element ).position == "fixed";
|
2012-02-01 00:59:09 +04:00
|
|
|
offsetParent = getOffsetParent( element, isFixed );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return result;
|
|
|
|
},
|
2011-12-06 07:50:25 +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 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 );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return new $.Point(
|
|
|
|
element.clientWidth,
|
|
|
|
element.clientHeight
|
|
|
|
);
|
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* 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-01-18 03:30:41 +04:00
|
|
|
getElementStyle: function( element ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( element.currentStyle ) {
|
|
|
|
return element.currentStyle;
|
|
|
|
} else if ( window.getComputedStyle ) {
|
|
|
|
return window.getComputedStyle( element, "" );
|
|
|
|
} else {
|
|
|
|
throw new Error( "Unknown element style, no known technique." );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +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 ) {
|
|
|
|
return event ? event : window.event;
|
|
|
|
},
|
2011-12-06 07:50:25 +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 ) {
|
|
|
|
var result = new $.Point();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
event = $.getEvent( event );
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( typeof( event.pageX ) == "number" ) {
|
|
|
|
result.x = event.pageX;
|
|
|
|
result.y = event.pageY;
|
|
|
|
} else if ( typeof( event.clientX ) == "number" ) {
|
|
|
|
result.x =
|
|
|
|
event.clientX +
|
|
|
|
document.body.scrollLeft +
|
|
|
|
document.documentElement.scrollLeft;
|
|
|
|
result.y =
|
|
|
|
event.clientY +
|
|
|
|
document.body.scrollTop +
|
|
|
|
document.documentElement.scrollTop;
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unknown event mouse position, no known technique."
|
|
|
|
);
|
|
|
|
}
|
2012-01-18 08:13:29 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return result;
|
|
|
|
},
|
2011-12-06 07:50:25 +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() {
|
|
|
|
var result = new $.Point(),
|
2012-02-02 01:56:04 +04:00
|
|
|
docElement = document.documentElement || {},
|
2012-01-18 03:30:41 +04:00
|
|
|
body = document.body || {};
|
|
|
|
|
|
|
|
if ( typeof( window.pageXOffset ) == "number" ) {
|
|
|
|
result.x = window.pageXOffset;
|
|
|
|
result.y = window.pageYOffset;
|
|
|
|
} else if ( body.scrollLeft || body.scrollTop ) {
|
|
|
|
result.x = body.scrollLeft;
|
|
|
|
result.y = body.scrollTop;
|
2012-02-02 01:56:04 +04:00
|
|
|
} else if ( docElement.scrollLeft || docElement.scrollTop ) {
|
|
|
|
result.x = docElement.scrollLeft;
|
|
|
|
result.y = docElement.scrollTop;
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return result;
|
|
|
|
},
|
2011-12-06 07:50:25 +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() {
|
|
|
|
var result = new $.Point(),
|
2012-02-02 01:56:04 +04:00
|
|
|
docElement = document.documentElement || {},
|
2012-01-18 03:30:41 +04:00
|
|
|
body = document.body || {};
|
|
|
|
|
|
|
|
if ( typeof( window.innerWidth ) == 'number' ) {
|
|
|
|
result.x = window.innerWidth;
|
|
|
|
result.y = window.innerHeight;
|
2012-02-02 01:56:04 +04:00
|
|
|
} else if ( docElement.clientWidth || docElement.clientHeight ) {
|
|
|
|
result.x = docElement.clientWidth;
|
|
|
|
result.y = docElement.clientHeight;
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( body.clientWidth || body.clientHeight ) {
|
|
|
|
result.x = body.clientWidth;
|
|
|
|
result.y = body.clientHeight;
|
|
|
|
} else {
|
|
|
|
throw new Error("Unknown window size, no known technique.");
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return result;
|
|
|
|
},
|
2011-12-06 07:50:25 +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" );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
innerDiv.appendChild( element );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return div;
|
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* 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;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
style.background = "transparent none";
|
|
|
|
style.border = "none";
|
|
|
|
style.margin = "0px";
|
|
|
|
style.padding = "0px";
|
|
|
|
style.position = "static";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return element;
|
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* 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 ) {
|
|
|
|
var img = $.makeNeutralElement( "img" ),
|
|
|
|
element = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
$.Browser.version < 7 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
element = $.makeNeutralElement("span");
|
|
|
|
element.style.display = "inline-block";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
img.onload = function() {
|
|
|
|
element.style.width = element.style.width || img.width + "px";
|
|
|
|
element.style.height = element.style.height || img.height + "px";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
img.onload = null;
|
|
|
|
img = null; // to prevent memory leaks in IE
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
img.src = src;
|
|
|
|
element.style.filter =
|
|
|
|
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
|
|
|
|
src +
|
|
|
|
"', sizingMethod='scale')";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
} else {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
element = img;
|
|
|
|
element.src = src;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return element;
|
|
|
|
},
|
2011-12-06 07:50:25 +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 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var previousFilter,
|
|
|
|
ieOpacity,
|
|
|
|
ieFilter;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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 );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( opacity < 1 ) {
|
|
|
|
element.style.opacity = opacity;
|
|
|
|
} else {
|
|
|
|
element.style.opacity = "";
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( opacity == 1 ) {
|
|
|
|
prevFilter = element.style.filter || "";
|
|
|
|
element.style.filter = prevFilter.replace(/alpha\(.*?\)/g, "");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
ieOpacity = Math.round( 100 * opacity );
|
|
|
|
ieFilter = " alpha(opacity=" + ieOpacity + ") ";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
//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;
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* 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 ) {
|
|
|
|
element.addEventListener( eventName, handler, useCapture );
|
|
|
|
} else if ( element.attachEvent ) {
|
|
|
|
element.attachEvent( "on" + eventName, handler );
|
|
|
|
if ( useCapture && element.setCapture ) {
|
|
|
|
element.setCapture();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unable to attach event handler, no known technique."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 07:50:25 +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 ) {
|
|
|
|
element.removeEventListener( eventName, handler, useCapture );
|
|
|
|
} else if ( element.detachEvent ) {
|
|
|
|
element.detachEvent("on" + eventName, handler);
|
|
|
|
if ( useCapture && element.releaseCapture ) {
|
|
|
|
element.releaseCapture();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Unable to detach event handler, no known technique."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 07:50:25 +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 );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( event.preventDefault ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
// W3C for preventing default
|
|
|
|
event.preventDefault();
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
// legacy for preventing default
|
|
|
|
event.cancel = true;
|
|
|
|
// IE for preventing default
|
|
|
|
event.returnValue = false;
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +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 );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( event.stopPropagation ) {
|
|
|
|
event.stopPropagation(); // W3C for stopping propagation
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
event.cancelBubble = true; // IE for stopping propagation
|
|
|
|
},
|
2011-12-06 07:50:25 +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 ] );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return function() {
|
|
|
|
var args = initialArgs.concat( [] ),
|
|
|
|
i;
|
|
|
|
for ( i = 0; i < arguments.length; i++ ) {
|
|
|
|
args.push( arguments[ i ] );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return method.apply( object, args );
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* 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;
|
|
|
|
},
|
2011-12-06 07:50:25 +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
|
|
|
* Makes an AJAX request.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.makeAjaxRequest
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {String} url - the url to request
|
|
|
|
* @param {Function} [callback] - a function to call when complete
|
|
|
|
* @throws {Error}
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
makeAjaxRequest: function( url, callback ) {
|
|
|
|
var async = typeof( callback ) == "function",
|
|
|
|
request = null,
|
|
|
|
actual,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( async ) {
|
|
|
|
actual = callback;
|
|
|
|
callback = function() {
|
|
|
|
window.setTimeout(
|
|
|
|
$.createCallback( null, actual, request ),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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
|
|
|
|
// performance for IE Browsers
|
|
|
|
for ( i = 0; i < ACTIVEX.length; i++ ) {
|
|
|
|
try {
|
|
|
|
request = new ActiveXObject( ACTIVEX[ i ] );
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( window.XMLHttpRequest ) {
|
|
|
|
request = new XMLHttpRequest();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( !request ) {
|
|
|
|
throw new Error( "Browser doesn't support XMLHttpRequest." );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( 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() { };
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
try {
|
|
|
|
request.open( "GET", url, async );
|
|
|
|
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
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
request.onreadystatechange = null;
|
|
|
|
request = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( async ) {
|
|
|
|
callback();
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return async ? null : request;
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
/**
|
|
|
|
* Taken from jQuery 1.6.1
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.url
|
|
|
|
* @param {Function} options.callback
|
|
|
|
* @param {String} [options.param='callback'] The name of the url parameter
|
|
|
|
* to request the jsonp provider with.
|
|
|
|
* @param {String} [options.callbackName=] The name of the callback to
|
|
|
|
* 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 ){
|
|
|
|
delete window[ jsonpCallback ];
|
|
|
|
} else {
|
|
|
|
window[ jsonpCallback ] = previous;
|
|
|
|
}
|
|
|
|
if( callback && $.isFunction( callback ) ){
|
|
|
|
callback( response );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
script = document.createElement( "script" );
|
|
|
|
|
|
|
|
script.async = "async";
|
|
|
|
|
|
|
|
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-02-01 00:59:09 +04:00
|
|
|
* Loads a Deep Zoom Image description from a url or XML 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-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",
|
|
|
|
xmlUrl = dzi.substring(0,1) != '<' ? dzi : null,
|
|
|
|
xmlString = xmlUrl ? null : dzi,
|
|
|
|
error = null,
|
|
|
|
urlParts,
|
|
|
|
filename,
|
|
|
|
lastDot,
|
|
|
|
tilesUrl;
|
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
if( tileHost ){
|
|
|
|
|
|
|
|
tilesUrl = tileHost + "/_files/";
|
|
|
|
|
|
|
|
} else if( xmlUrl ) {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
urlParts = xmlUrl.split( '/' );
|
|
|
|
filename = urlParts[ urlParts.length - 1 ];
|
|
|
|
lastDot = filename.lastIndexOf( '.' );
|
|
|
|
|
|
|
|
if ( lastDot > -1 ) {
|
|
|
|
urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot );
|
|
|
|
}
|
2011-12-06 07:50:25 +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
|
|
|
}
|
2011-12-06 07:50:25 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( async ) {
|
|
|
|
if ( xmlString ) {
|
|
|
|
window.setTimeout( function() {
|
|
|
|
var source = finish( processDZIXml, parseXml( xmlString ) );
|
|
|
|
// call after finish sets error
|
|
|
|
callback( source, error );
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
$.makeAjaxRequest( xmlUrl, function( xhr ) {
|
|
|
|
var source = finish( processDZIResponse, xhr );
|
|
|
|
// call after finish sets error
|
|
|
|
callback( source, error );
|
|
|
|
});
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return null;
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( xmlString ) {
|
|
|
|
return finish(
|
|
|
|
processDZIXml,
|
|
|
|
parseXml( xmlString )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return finish(
|
|
|
|
processDZIResponse,
|
|
|
|
$.makeAjaxRequest( xmlUrl )
|
|
|
|
);
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
});
|
2011-12-06 07:50:25 +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 = !(
|
|
|
|
$.Browser.vendor == $.BROWSERS.IE || (
|
|
|
|
$.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
|
|
|
|
*/
|
|
|
|
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 ) {
|
|
|
|
doc = parseXml( xhr.responseText );
|
|
|
|
}
|
|
|
|
|
|
|
|
return processDZIXml( doc, tilesUrl );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Document} xmlDoc
|
|
|
|
* @param {String} tilesUrl
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {Document} errorNode
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
function processDZIError( errorNode ) {
|
|
|
|
var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
|
|
|
|
message = messageNode.firstChild.nodeValue;
|
|
|
|
|
|
|
|
throw new Error(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports whether the image format is supported for tiling in this
|
|
|
|
* version.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @param {String} [extension]
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
function imageFormatSupported( extension ) {
|
|
|
|
extension = extension ? extension : "";
|
|
|
|
return !!FILEFORMATS[ extension.toLowerCase() ];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses an XML string into a DOM Document.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.parseXml
|
|
|
|
* @param {String} string
|
|
|
|
* @returns {Document}
|
|
|
|
*/
|
|
|
|
function parseXml( string ) {
|
|
|
|
//TODO: yet another example where we can determine the correct
|
|
|
|
// implementation once at start-up instead of everytime we use
|
|
|
|
// the function.
|
|
|
|
var xmlDoc = null,
|
|
|
|
parser;
|
|
|
|
|
|
|
|
if ( window.ActiveXObject ) {
|
|
|
|
|
|
|
|
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
|
|
|
|
xmlDoc.async = false;
|
|
|
|
xmlDoc.loadXML( string );
|
|
|
|
|
|
|
|
} else if ( window.DOMParser ) {
|
|
|
|
|
|
|
|
parser = new DOMParser();
|
|
|
|
xmlDoc = parser.parseFromString( string, "text/xml" );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new Error( "Browser doesn't support XML DOM." );
|
|
|
|
}
|
|
|
|
|
|
|
|
return xmlDoc;
|
|
|
|
};
|
2012-01-18 03:30:41 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
(function($){
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-15 23:50:27 +04:00
|
|
|
* For use by classes which want to support custom, non-browser events.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
$.EventHandler = function() {
|
|
|
|
this.events = {};
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
$.EventHandler.prototype = {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* Add an event handler for a given event.
|
|
|
|
* @function
|
|
|
|
* @param {String} eventName - Name of event to register.
|
|
|
|
* @param {Function} handler - Function to call when event is triggered.
|
|
|
|
*/
|
|
|
|
addHandler: function( eventName, handler ) {
|
|
|
|
var events = this.events[ eventName ];
|
2012-01-25 23:14:02 +04:00
|
|
|
if( !events ){
|
2012-02-15 23:50:27 +04:00
|
|
|
this.events[ eventName ] = events = [];
|
2012-01-25 23:14:02 +04:00
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
if( handler && $.isFunction( handler ) ){
|
|
|
|
events[ events.length ] = handler;
|
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* Remove a specific event handler for a given event.
|
|
|
|
* @function
|
|
|
|
* @param {String} eventName - Name of event for which the handler is to be removed.
|
|
|
|
* @param {Function} handler - Function to be removed.
|
|
|
|
*/
|
|
|
|
removeHandler: function( eventName, handler ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
//Start Thatcher - unneccessary indirection. Also, because events were
|
|
|
|
// - not actually being removed, we need to add the code
|
|
|
|
// - to do the removal ourselves. TODO
|
2012-02-15 23:50:27 +04:00
|
|
|
var events = this.events[ eventName ];
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( !events ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//End Thatcher
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* Retrive the list of all handlers registered for a given event.
|
|
|
|
* @function
|
|
|
|
* @param {String} eventName - Name of event to get handlers for.
|
|
|
|
*/
|
|
|
|
getHandler: function( eventName ) {
|
|
|
|
var events = this.events[ eventName ];
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( !events || !events.length ){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
events = events.length === 1 ?
|
|
|
|
[ events[ 0 ] ] :
|
|
|
|
Array.apply( null, events );
|
|
|
|
return function( source, args ) {
|
|
|
|
var i,
|
|
|
|
length = events.length;
|
|
|
|
for ( i = 0; i < length; i++ ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
if( events[ i ] ){
|
|
|
|
events[ i ]( source, args );
|
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
};
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* Trigger an event, optionally passing additional information.
|
|
|
|
* @function
|
|
|
|
* @param {String} eventName - Name of event to register.
|
|
|
|
* @param {Function} handler - Function to call when event is triggered.
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
raiseEvent: function( eventName, eventArgs ) {
|
|
|
|
var handler = this.getHandler( eventName );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( handler ) {
|
|
|
|
if ( !eventArgs ) {
|
|
|
|
eventArgs = new Object();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
|
|
|
|
handler( this, eventArgs );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
// is any button currently being pressed while mouse events occur
|
|
|
|
var IS_BUTTON_DOWN = false,
|
|
|
|
// is any tracker currently capturing?
|
|
|
|
IS_CAPTURING = false,
|
|
|
|
// dictionary from hash to MouseTracker
|
|
|
|
ACTIVE = {},
|
|
|
|
// list of trackers interested in capture
|
|
|
|
CAPTURING = [],
|
|
|
|
// dictionary from hash to private properties
|
|
|
|
THIS = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* The MouseTracker allows other classes to set handlers for common mouse
|
|
|
|
* events on a specific element like, 'enter', 'exit', 'press', 'release',
|
|
|
|
* 'scroll', 'click', and 'drag'.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-03 04:12:45 +04:00
|
|
|
* @param {Object} options
|
|
|
|
* Allows configurable properties to be entirely specified by passing
|
|
|
|
* an options object to the constructor. The constructor also supports
|
|
|
|
* the original positional arguments 'elements', 'clickTimeThreshold',
|
|
|
|
* and 'clickDistThreshold' in that order.
|
|
|
|
* @param {Element|String} options.element
|
|
|
|
* A reference to an element or an element id for which the mouse
|
|
|
|
* events will be monitored.
|
|
|
|
* @param {Number} options.clickTimeThreshold
|
|
|
|
* The number of milliseconds within which mutliple mouse clicks
|
|
|
|
* will be treated as a single event.
|
|
|
|
* @param {Number} options.clickDistThreshold
|
|
|
|
* The distance between mouse click within multiple mouse clicks
|
|
|
|
* will be treated as a single event.
|
|
|
|
* @param {Function} options.enterHandler
|
|
|
|
* An optional handler for mouse enter.
|
|
|
|
* @param {Function} options.exitHandler
|
|
|
|
* An optional handler for mouse exit.
|
|
|
|
* @param {Function} options.pressHandler
|
|
|
|
* An optional handler for mouse press.
|
|
|
|
* @param {Function} options.releaseHandler
|
|
|
|
* An optional handler for mouse release.
|
|
|
|
* @param {Function} options.scrollHandler
|
|
|
|
* An optional handler for mouse scroll.
|
|
|
|
* @param {Function} options.clickHandler
|
|
|
|
* An optional handler for mouse click.
|
|
|
|
* @param {Function} options.dragHandler
|
|
|
|
* An optional handler for mouse drag.
|
|
|
|
* @property {Number} hash
|
|
|
|
* An unique hash for this tracker.
|
|
|
|
* @property {Element} element
|
|
|
|
* The element for which mouse event are being monitored.
|
|
|
|
* @property {Number} clickTimeThreshold
|
|
|
|
* The number of milliseconds within which mutliple mouse clicks
|
|
|
|
* will be treated as a single event.
|
|
|
|
* @property {Number} clickDistThreshold
|
|
|
|
* The distance between mouse click within multiple mouse clicks
|
|
|
|
* will be treated as a single event.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
$.MouseTracker = function ( options ) {
|
|
|
|
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
if( !$.isPlainObject( options ) ){
|
|
|
|
options = {
|
|
|
|
element: args[ 0 ],
|
|
|
|
clickTimeThreshold: args[ 1 ],
|
|
|
|
clickDistThreshold: args[ 2 ]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hash = Math.random();
|
|
|
|
this.element = $.getElement( options.element );
|
|
|
|
this.clickTimeThreshold = options.clickTimeThreshold;
|
|
|
|
this.clickDistThreshold = options.clickDistThreshold;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
this.enterHandler = options.enterHandler || null;
|
|
|
|
this.exitHandler = options.exitHandler || null;
|
|
|
|
this.pressHandler = options.pressHandler || null;
|
|
|
|
this.releaseHandler = options.releaseHandler || null;
|
|
|
|
this.scrollHandler = options.scrollHandler || null;
|
|
|
|
this.clickHandler = options.clickHandler || null;
|
|
|
|
this.dragHandler = options.dragHandler || null;
|
2012-03-16 19:36:28 +04:00
|
|
|
this.keyHandler = options.keyHandler || null;
|
|
|
|
this.focusHandler = options.focusHandler || null;
|
|
|
|
this.blurHandler = options.blurHandler || null;
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
//Store private properties in a scope sealed hash map
|
|
|
|
var _this = this;
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @property {Boolean} tracking
|
|
|
|
* Are we currently tracking mouse events.
|
|
|
|
* @property {Boolean} capturing
|
|
|
|
* Are we curruently capturing mouse events.
|
|
|
|
* @property {Boolean} buttonDown
|
|
|
|
* True if the left mouse button is currently being pressed and was
|
|
|
|
* initiated inside the tracked element, otherwise false.
|
|
|
|
* @property {Boolean} insideElement
|
|
|
|
* Are we currently inside the screen area of the tracked element.
|
|
|
|
* @property {OpenSeadragon.Point} lastPoint
|
|
|
|
* Position of last mouse down/move
|
|
|
|
* @property {Number} lastMouseDownTime
|
|
|
|
* Time of last mouse down.
|
|
|
|
* @property {OpenSeadragon.Point} lastMouseDownPoint
|
|
|
|
* Position of last mouse down
|
|
|
|
*/
|
|
|
|
THIS[ this.hash ] = {
|
2012-02-10 07:16:09 +04:00
|
|
|
"mouseover": function( event ){ onMouseOver( _this, event ); },
|
|
|
|
"mouseout": function( event ){ onMouseOut( _this, event ); },
|
|
|
|
"mousedown": function( event ){ onMouseDown( _this, event ); },
|
|
|
|
"mouseup": function( event ){ onMouseUp( _this, event ); },
|
|
|
|
"click": function( event ){ onMouseClick( _this, event ); },
|
|
|
|
"DOMMouseScroll": function( event ){ onMouseWheelSpin( _this, event ); },
|
|
|
|
"mousewheel": function( event ){ onMouseWheelSpin( _this, event ); },
|
|
|
|
"mouseupie": function( event ){ onMouseUpIE( _this, event ); },
|
|
|
|
"mousemoveie": function( event ){ onMouseMoveIE( _this, event ); },
|
|
|
|
"mouseupwindow": function( event ){ onMouseUpWindow( _this, event ); },
|
|
|
|
"mousemove": function( event ){ onMouseMove( _this, event ); },
|
|
|
|
"touchstart": function( event ){ onTouchStart( _this, event ); },
|
|
|
|
"touchmove": function( event ){ onTouchMove( _this, event ); },
|
|
|
|
"touchend": function( event ){ onTouchEnd( _this, event ); },
|
2012-03-16 19:36:28 +04:00
|
|
|
"keypress": function( event ){ onKeyPress( _this, event ); },
|
|
|
|
"focus": function( event ){ onFocus( _this, event ); },
|
|
|
|
"blur": function( event ){ onBlur( _this, event ); },
|
2012-02-10 07:16:09 +04:00
|
|
|
tracking: false,
|
|
|
|
capturing: false,
|
|
|
|
buttonDown: false,
|
|
|
|
insideElement: false,
|
|
|
|
lastPoint: null,
|
|
|
|
lastMouseDownTime: null,
|
|
|
|
lastMouseDownPoint: null,
|
|
|
|
lastPinchDelta: 0
|
2012-02-02 01:56:04 +04:00
|
|
|
};
|
2011-12-14 05:04:38 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
};
|
2011-12-14 05:04:38 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
$.MouseTracker.prototype = {
|
|
|
|
|
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Are we currently tracking events on this element.
|
|
|
|
* @deprecated Just use this.tracking
|
|
|
|
* @function
|
|
|
|
* @returns {Boolean} Are we currently tracking events on this element.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
|
|
|
isTracking: function () {
|
2012-02-03 04:12:45 +04:00
|
|
|
return THIS[ this.hash ].tracking;
|
2012-02-02 01:56:04 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Enable or disable whether or not we are tracking events on this element.
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} track True to start tracking, false to stop tracking.
|
|
|
|
* @returns {OpenSeadragon.MouseTracker} Chainable.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
|
|
|
setTracking: function ( track ) {
|
|
|
|
if ( track ) {
|
2012-02-03 04:12:45 +04:00
|
|
|
startTracking( this );
|
2011-12-14 05:04:38 +04:00
|
|
|
} else {
|
2012-02-03 04:12:45 +04:00
|
|
|
stopTracking( this );
|
2011-12-14 05:04:38 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
//chain
|
|
|
|
return this;
|
2012-02-02 01:56:04 +04:00
|
|
|
},
|
2012-02-03 04:12:45 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {Boolean} buttonDown
|
|
|
|
* True if the left mouse button is currently being pressed and was
|
|
|
|
* initiated inside the tracked element, otherwise false.
|
|
|
|
* @param {Boolean} buttonDownAny
|
|
|
|
* Was the button down anywhere in the screen during the event.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
enterHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {Boolean} buttonDown
|
|
|
|
* True if the left mouse button is currently being pressed and was
|
|
|
|
* initiated inside the tracked element, otherwise false.
|
|
|
|
* @param {Boolean} buttonDownAny
|
|
|
|
* Was the button down anywhere in the screen during the event.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
exitHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
pressHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {Boolean} buttonDown
|
|
|
|
* True if the left mouse button is currently being pressed and was
|
|
|
|
* initiated inside the tracked element, otherwise false.
|
|
|
|
* @param {Boolean} insideElementRelease
|
|
|
|
* Was the mouse still inside the tracked element when the button
|
|
|
|
* was released.
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
releaseHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {Number} scroll
|
|
|
|
* The scroll delta for the event.
|
|
|
|
* @param {Boolean} shift
|
|
|
|
* Was the shift key being pressed during this event?
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
scrollHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {Boolean} quick
|
|
|
|
* True only if the clickDistThreshold and clickDeltaThreshold are
|
|
|
|
* both pased. Useful for ignoring events.
|
|
|
|
* @param {Boolean} shift
|
|
|
|
* Was the shift key being pressed during this event?
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-02-03 04:12:45 +04:00
|
|
|
clickHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {OpenSeadragon.Point} position
|
|
|
|
* The poistion of the event on the screen.
|
|
|
|
* @param {OpenSeadragon.Point} delta
|
|
|
|
* The x,y components of the difference between start drag and
|
|
|
|
* end drag. Usefule for ignoring or weighting the events.
|
|
|
|
* @param {Boolean} shift
|
|
|
|
* Was the shift key being pressed during this event?
|
2012-02-02 01:56:04 +04:00
|
|
|
*/
|
2012-03-16 19:36:28 +04:00
|
|
|
dragHandler: function(){},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
/**
|
|
|
|
* Implement or assign implmentation to these handlers during or after
|
|
|
|
* calling the constructor.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.MouseTracker} tracker
|
|
|
|
* A reference to the tracker instance.
|
|
|
|
* @param {Number} keyCode
|
|
|
|
* The key code that was pressed.
|
|
|
|
* @param {Boolean} shift
|
|
|
|
* Was the shift key being pressed during this event?
|
|
|
|
*/
|
|
|
|
keyHandler: function(){},
|
|
|
|
|
|
|
|
focusHandler: function(){},
|
|
|
|
|
|
|
|
blurHandler: function(){}
|
2012-02-03 04:12:45 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* Starts tracking mouse events on this element.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function startTracking( tracker ) {
|
|
|
|
var events = [
|
2012-02-10 07:16:09 +04:00
|
|
|
"mouseover", "mouseout", "mousedown", "mouseup",
|
|
|
|
"click",
|
|
|
|
"DOMMouseScroll", "mousewheel",
|
2012-03-16 19:36:28 +04:00
|
|
|
"touchstart", "touchmove", "touchend",
|
|
|
|
"keypress",
|
|
|
|
"focus", "blur"
|
2012-02-03 04:12:45 +04:00
|
|
|
],
|
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
event,
|
|
|
|
i;
|
2012-02-02 01:56:04 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( !delegate.tracking ) {
|
|
|
|
for( i = 0; i < events.length; i++ ){
|
|
|
|
event = events[ i ];
|
|
|
|
$.addEvent(
|
|
|
|
tracker.element,
|
|
|
|
event,
|
|
|
|
delegate[ event ],
|
|
|
|
false
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.tracking = true;
|
|
|
|
ACTIVE[ tracker.hash ] = tracker;
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* Stops tracking mouse events on this element.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function stopTracking( tracker ) {
|
|
|
|
var events = [
|
2012-02-10 07:16:09 +04:00
|
|
|
"mouseover", "mouseout", "mousedown", "mouseup",
|
|
|
|
"click",
|
|
|
|
"DOMMouseScroll", "mousewheel",
|
2012-03-16 19:36:28 +04:00
|
|
|
"touchstart", "touchmove", "touchend",
|
|
|
|
"keypress",
|
|
|
|
"focus", "blur"
|
2012-02-03 04:12:45 +04:00
|
|
|
],
|
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
event,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( delegate.tracking ) {
|
|
|
|
for( i = 0; i < events.length; i++ ){
|
|
|
|
event = events[ i ];
|
|
|
|
$.removeEvent(
|
|
|
|
tracker.element,
|
|
|
|
event,
|
|
|
|
delegate[ event ],
|
|
|
|
false
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
releaseMouse( tracker );
|
|
|
|
delegate.tracking = false;
|
|
|
|
delete ACTIVE[ tracker.hash ];
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function hasMouse( tracker ) {
|
|
|
|
return THIS[ tracker.hash ].insideElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begin capturing mouse events on this element.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function captureMouse( tracker ) {
|
|
|
|
var delegate = THIS[ tracker.hash ];
|
|
|
|
if ( !delegate.capturing ) {
|
|
|
|
|
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.removeEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseup" ],
|
|
|
|
false
|
|
|
|
);
|
|
|
|
$.addEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseupie" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$.addEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mousemove",
|
|
|
|
delegate[ "mousemoveie" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$.addEvent(
|
|
|
|
window,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseupwindow" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$.addEvent(
|
|
|
|
window,
|
|
|
|
"mousemove",
|
|
|
|
delegate[ "mousemove" ],
|
|
|
|
true
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.capturing = true;
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop capturing mouse events on this element.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function releaseMouse( tracker ) {
|
|
|
|
var delegate = THIS[ tracker.hash ];
|
|
|
|
if ( delegate.capturing ) {
|
|
|
|
|
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.removeEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mousemove",
|
|
|
|
delegate[ "mousemoveie" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$.removeEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseupie" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$.addEvent(
|
|
|
|
tracker.element,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseup" ],
|
|
|
|
false
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$.removeEvent(
|
|
|
|
window,
|
|
|
|
"mousemove",
|
|
|
|
delegate[ "mousemove" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$.removeEvent(
|
|
|
|
window,
|
|
|
|
"mouseup",
|
|
|
|
delegate[ "mouseupwindow" ],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
delegate.capturing = false;
|
|
|
|
}
|
|
|
|
};
|
2012-02-02 01:56:04 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function triggerOthers( tracker, handler, event ) {
|
|
|
|
var otherHash;
|
|
|
|
for ( otherHash in ACTIVE ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
if ( ACTIVE.hasOwnProperty( otherHash ) && tracker.hash != otherHash ) {
|
2012-02-03 04:12:45 +04:00
|
|
|
handler( ACTIVE[ otherHash ], event );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onFocus( tracker, event ){
|
2012-03-20 03:03:58 +04:00
|
|
|
//console.log( "focus %s", event );
|
2012-04-03 11:08:27 +04:00
|
|
|
var propagate;
|
2012-03-16 19:36:28 +04:00
|
|
|
if ( tracker.focusHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.focusHandler(
|
2012-03-16 19:36:28 +04:00
|
|
|
tracker,
|
|
|
|
event
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing key handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onBlur( tracker, event ){
|
2012-03-20 03:03:58 +04:00
|
|
|
//console.log( "blur %s", event );
|
2012-04-03 11:08:27 +04:00
|
|
|
var propagate;
|
2012-03-16 19:36:28 +04:00
|
|
|
if ( tracker.blurHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.blurHandler(
|
2012-03-16 19:36:28 +04:00
|
|
|
tracker,
|
|
|
|
event
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing key handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onKeyPress( tracker, event ){
|
2012-03-21 05:58:23 +04:00
|
|
|
//console.log( "keypress %s %s %s %s %s", event.keyCode, event.charCode, event.ctrlKey, event.shiftKey, event.altKey );
|
2012-03-20 23:30:29 +04:00
|
|
|
var propagate;
|
2012-03-16 19:36:28 +04:00
|
|
|
if ( tracker.keyHandler ) {
|
|
|
|
try {
|
2012-03-20 23:30:29 +04:00
|
|
|
propagate = tracker.keyHandler(
|
2012-03-16 19:36:28 +04:00
|
|
|
tracker,
|
2012-03-21 05:58:23 +04:00
|
|
|
event.keyCode ? event.keyCode : event.charCode,
|
|
|
|
event.shiftKey
|
2012-03-16 19:36:28 +04:00
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
2012-03-20 23:30:29 +04:00
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing key handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseOver( tracker, event ) {
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
var event = $.getEvent( event ),
|
2012-04-03 11:08:27 +04:00
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
propagate;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
delegate.capturing &&
|
|
|
|
!isChild( event.srcElement, tracker.element ) ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
triggerOthers( tracker, onMouseOver, event );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
var to = event.target ?
|
|
|
|
event.target :
|
|
|
|
event.srcElement,
|
|
|
|
from = event.relatedTarget ?
|
|
|
|
event.relatedTarget :
|
|
|
|
event.fromElement;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( !isChild( tracker.element, to ) ||
|
|
|
|
isChild( tracker.element, from ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.insideElement = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.enterHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.enterHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
delegate.buttonDown,
|
|
|
|
IS_BUTTON_DOWN
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing enter handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseOut( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
2012-04-03 11:08:27 +04:00
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
propagate;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE &&
|
|
|
|
delegate.capturing &&
|
|
|
|
!isChild( event.srcElement, tracker.element ) ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
triggerOthers( tracker, onMouseOut, event );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
var from = event.target ?
|
|
|
|
event.target :
|
|
|
|
event.srcElement,
|
|
|
|
to = event.relatedTarget ?
|
|
|
|
event.relatedTarget :
|
|
|
|
event.toElement;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( !isChild( tracker.element, from ) ||
|
|
|
|
isChild( tracker.element, to ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.insideElement = false;
|
2012-02-02 01:56:04 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.exitHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.exitHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
delegate.buttonDown,
|
|
|
|
IS_BUTTON_DOWN
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing exit handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseDown( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
2012-04-03 11:08:27 +04:00
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
propagate;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( event.button == 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.buttonDown = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.lastPoint = getMouseAbsolute( event );
|
|
|
|
delegate.lastMouseDownPoint = delegate.lastPoint;
|
|
|
|
delegate.lastMouseDownTime = +new Date();
|
|
|
|
|
|
|
|
if ( tracker.pressHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.pressHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element )
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch (e) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing press handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.pressHandler || tracker.dragHandler ) {
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( !( $.Browser.vendor == $.BROWSERS.IE ) || !IS_CAPTURING ) {
|
|
|
|
captureMouse( tracker );
|
|
|
|
IS_CAPTURING = true;
|
|
|
|
// reset to empty & add us
|
|
|
|
CAPTURING = [ tracker ];
|
|
|
|
} else if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
// add us to the list
|
|
|
|
CAPTURING.push( tracker );
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onTouchStart( tracker, event ) {
|
|
|
|
var touchA,
|
|
|
|
touchB;
|
|
|
|
|
|
|
|
if( event.touches.length == 1 &&
|
|
|
|
event.targetTouches.length == 1 &&
|
|
|
|
event.changedTouches.length == 1 ){
|
|
|
|
|
|
|
|
THIS[ tracker.hash ].lastTouch = event.touches[ 0 ];
|
|
|
|
onMouseOver( tracker, event.changedTouches[ 0 ] );
|
|
|
|
onMouseDown( tracker, event.touches[ 0 ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( event.touches.length == 2 ){
|
|
|
|
|
|
|
|
touchA = getMouseAbsolute( event.touches[ 0 ] );
|
|
|
|
touchB = getMouseAbsolute( event.touches[ 1 ] );
|
|
|
|
THIS[ tracker.hash ].lastPinchDelta =
|
|
|
|
Math.abs( touchA.x - touchB.x ) +
|
|
|
|
Math.abs( touchA.y - touchB.y );
|
|
|
|
//$.console.debug("pinch start : "+THIS[ tracker.hash ].lastPinchDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseUp( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
//were we inside the tracked element when we were pressed
|
|
|
|
insideElementPress = delegate.buttonDown,
|
|
|
|
//are we still inside the tracked element when we released
|
2012-04-03 11:08:27 +04:00
|
|
|
insideElementRelease = delegate.insideElement,
|
|
|
|
propagate;
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
if ( event.button == 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
delegate.buttonDown = false;
|
2012-02-02 01:56:04 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.releaseHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.releaseHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
insideElementPress,
|
|
|
|
insideElementRelease
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch (e) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing release handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( insideElementPress && insideElementRelease ) {
|
|
|
|
handleMouseClick( tracker, event );
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onTouchEnd( tracker, event ) {
|
|
|
|
|
|
|
|
if( event.touches.length == 0 &&
|
|
|
|
event.targetTouches.length == 0 &&
|
|
|
|
event.changedTouches.length == 1 ){
|
|
|
|
|
|
|
|
THIS[ tracker.hash ].lastTouch = null;
|
|
|
|
onMouseUp( tracker, event.changedTouches[ 0 ] );
|
|
|
|
onMouseOut( tracker, event.changedTouches[ 0 ] );
|
|
|
|
}
|
|
|
|
if( event.touches.length + event.changedTouches.length == 2 ){
|
|
|
|
THIS[ tracker.hash ].lastPinchDelta = null;
|
|
|
|
//$.console.debug("pinch end");
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* Only triggered once by the deepest element that initially received
|
|
|
|
* the mouse down event. We want to make sure THIS event doesn't bubble.
|
|
|
|
* Instead, we want to trigger the elements that initially received the
|
|
|
|
* mouse down event (including this one) only if the mouse is no longer
|
|
|
|
* inside them. Then, we want to release capture, and emulate a regular
|
|
|
|
* mouseup on the event that this event was meant for.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseUpIE( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
|
|
|
othertracker,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( event.button == 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
for ( i = 0; i < CAPTURING.length; i++ ) {
|
|
|
|
othertracker = CAPTURING[ i ];
|
|
|
|
if ( !hasMouse( othertracker ) ) {
|
|
|
|
onMouseUp( othertracker, event );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
releaseMouse( tracker );
|
|
|
|
IS_CAPTURING = false;
|
|
|
|
event.srcElement.fireEvent(
|
|
|
|
"on" + event.type,
|
|
|
|
document.createEventObject( event )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
$.stopEvent( event );
|
|
|
|
};
|
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* Only triggered in W3C browsers by elements within which the mouse was
|
|
|
|
* initially pressed, since they are now listening to the window for
|
|
|
|
* mouseup during the capture phase. We shouldn't handle the mouseup
|
|
|
|
* here if the mouse is still inside this element, since the regular
|
|
|
|
* mouseup handler will still fire.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseUpWindow( tracker, event ) {
|
|
|
|
if ( ! THIS[ tracker.hash ].insideElement ) {
|
|
|
|
onMouseUp( tracker, event );
|
|
|
|
}
|
|
|
|
releaseMouse( tracker );
|
|
|
|
};
|
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseClick( tracker, event ) {
|
|
|
|
if ( tracker.clickHandler ) {
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseWheelSpin( tracker, event ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
var nDelta = 0,
|
|
|
|
propagate;
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
if ( !event ) { // For IE, access the global (window) event object
|
|
|
|
event = window.event;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( event.wheelDelta ) { // IE and Opera
|
|
|
|
nDelta = event.wheelDelta;
|
|
|
|
if ( window.opera ) { // Opera has the values reversed
|
|
|
|
nDelta = -nDelta;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} else if (event.detail) { // Mozilla FireFox
|
|
|
|
nDelta = -event.detail;
|
|
|
|
}
|
2012-02-10 07:16:09 +04:00
|
|
|
//The nDelta variable is gated to provide smooth z-index scrolling
|
|
|
|
//since the mouse wheel allows for substantial deltas meant for rapid
|
|
|
|
//y-index scrolling.
|
2012-02-03 04:12:45 +04:00
|
|
|
nDelta = nDelta > 0 ? 1 : -1;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.scrollHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.scrollHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
nDelta,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch (e) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing scroll handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function handleMouseClick( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
2012-04-03 11:08:27 +04:00
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
propagate;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( event.button == 2 ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
var time = +new Date() - delegate.lastMouseDownTime,
|
|
|
|
point = getMouseAbsolute( event ),
|
|
|
|
distance = delegate.lastMouseDownPoint.distanceTo( point ),
|
|
|
|
quick = time <= tracker.clickTimeThreshold &&
|
|
|
|
distance <= tracker.clickDistThreshold;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
if ( tracker.clickHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.clickHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
quick,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing click handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseMove( tracker, event ) {
|
|
|
|
var event = $.getEvent( event ),
|
|
|
|
delegate = THIS[ tracker.hash ],
|
|
|
|
point = getMouseAbsolute( event ),
|
2012-04-03 11:08:27 +04:00
|
|
|
delta = point.minus( delegate.lastPoint ),
|
|
|
|
propagate;
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
delegate.lastPoint = point;
|
|
|
|
|
|
|
|
if ( tracker.dragHandler ) {
|
|
|
|
try {
|
2012-04-03 11:08:27 +04:00
|
|
|
propagate = tracker.dragHandler(
|
2012-02-03 04:12:45 +04:00
|
|
|
tracker,
|
|
|
|
getMouseRelative( event, tracker.element ),
|
|
|
|
delta,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2012-04-03 11:08:27 +04:00
|
|
|
if( propagate === false ){
|
|
|
|
$.cancelEvent( event );
|
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
} catch (e) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing drag handler: %s",
|
|
|
|
e.name,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
}
|
2012-02-03 04:12:45 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onTouchMove( tracker, event ) {
|
|
|
|
var touchA,
|
|
|
|
touchB,
|
|
|
|
pinchDelta;
|
|
|
|
|
|
|
|
if( event.touches.length === 1 &&
|
|
|
|
event.targetTouches.length === 1 &&
|
|
|
|
event.changedTouches.length === 1 &&
|
|
|
|
THIS[ tracker.hash ].lastTouch === event.touches[ 0 ]){
|
|
|
|
|
|
|
|
onMouseMove( tracker, event.touches[ 0 ] );
|
|
|
|
|
|
|
|
} else if ( event.touches.length === 2 ){
|
|
|
|
|
|
|
|
touchA = getMouseAbsolute( event.touches[ 0 ] );
|
|
|
|
touchB = getMouseAbsolute( event.touches[ 1 ] );
|
|
|
|
pinchDelta =
|
|
|
|
Math.abs( touchA.x - touchB.x ) +
|
|
|
|
Math.abs( touchA.y - touchB.y );
|
|
|
|
|
|
|
|
//TODO: make the 75px pinch threshold configurable
|
|
|
|
if( Math.abs( THIS[ tracker.hash ].lastPinchDelta - pinchDelta ) > 75 ){
|
|
|
|
//$.console.debug( "pinch delta : " + pinchDelta + " | previous : " + THIS[ tracker.hash ].lastPinchDelta);
|
|
|
|
|
|
|
|
onMouseWheelSpin( tracker, {
|
|
|
|
shift: false,
|
|
|
|
pageX: ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX ) / 2,
|
|
|
|
pageY: ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY ) / 2,
|
|
|
|
detail:(
|
|
|
|
THIS[ tracker.hash ].lastPinchDelta > pinchDelta
|
|
|
|
) ? 1 : -1
|
|
|
|
});
|
|
|
|
|
|
|
|
THIS[ tracker.hash ].lastPinchDelta = pinchDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
/**
|
|
|
|
* Only triggered once by the deepest element that initially received
|
|
|
|
* the mouse down event. Since no other element has captured the mouse,
|
|
|
|
* we want to trigger the elements that initially received the mouse
|
|
|
|
* down event (including this one). The the param tracker isn't used
|
|
|
|
* but for consistency with the other event handlers we include it.
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
|
|
|
function onMouseMoveIE( tracker, event ) {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < CAPTURING.length; i++ ) {
|
|
|
|
onMouseMove( CAPTURING[ i ], event );
|
|
|
|
}
|
|
|
|
|
|
|
|
$.stopEvent( event );
|
2011-12-14 05:04:38 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
2012-02-03 04:12:45 +04:00
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-14 05:04:38 +04:00
|
|
|
function getMouseAbsolute( event ) {
|
2012-02-02 01:56:04 +04:00
|
|
|
return $.getMousePosition( event );
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2012-02-02 01:56:04 +04:00
|
|
|
function getMouseRelative( event, element ) {
|
|
|
|
var mouse = $.getMousePosition( event ),
|
|
|
|
offset = $.getElementPosition( element );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
return mouse.minus( offset );
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
/**
|
2012-01-25 23:14:02 +04:00
|
|
|
* @private
|
2012-02-01 06:01:37 +04:00
|
|
|
* @inner
|
2012-02-02 01:56:04 +04:00
|
|
|
* Returns true if elementB is a child node of elementA, or if they're equal.
|
2011-12-14 05:04:38 +04:00
|
|
|
*/
|
2012-02-02 01:56:04 +04:00
|
|
|
function isChild( elementA, elementB ) {
|
2011-12-14 05:04:38 +04:00
|
|
|
var body = document.body;
|
2012-02-02 01:56:04 +04:00
|
|
|
while ( elementB && elementA != elementB && body != elementB ) {
|
2011-12-14 05:04:38 +04:00
|
|
|
try {
|
2012-02-02 01:56:04 +04:00
|
|
|
elementB = elementB.parentNode;
|
2011-12-14 05:04:38 +04:00
|
|
|
} catch (e) {
|
|
|
|
return false;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-14 05:04:38 +04:00
|
|
|
}
|
2012-02-02 01:56:04 +04:00
|
|
|
return elementA == elementB;
|
|
|
|
};
|
2011-12-14 05:04:38 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-14 05:04:38 +04:00
|
|
|
function onGlobalMouseDown() {
|
2012-02-03 04:12:45 +04:00
|
|
|
IS_BUTTON_DOWN = true;
|
2012-02-02 01:56:04 +04:00
|
|
|
};
|
2011-12-14 05:04:38 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
*/
|
2011-12-14 05:04:38 +04:00
|
|
|
function onGlobalMouseUp() {
|
2012-02-03 04:12:45 +04:00
|
|
|
IS_BUTTON_DOWN = false;
|
2012-02-02 01:56:04 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
(function () {
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.addEvent( document, "mousedown", onGlobalMouseDown, false );
|
|
|
|
$.addEvent( document, "mouseup", onGlobalMouseUp, false );
|
2011-12-14 05:04:38 +04:00
|
|
|
} else {
|
2012-02-02 01:56:04 +04:00
|
|
|
$.addEvent( window, "mousedown", onGlobalMouseDown, true );
|
|
|
|
$.addEvent( window, "mouseup", onGlobalMouseUp, true );
|
2011-12-14 05:04:38 +04:00
|
|
|
}
|
|
|
|
})();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* An enumeration of supported locations where controls can be anchored,
|
|
|
|
* including NONE, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, and BOTTOM_LEFT.
|
|
|
|
* The anchoring is always relative to the container
|
|
|
|
* @static
|
|
|
|
*/
|
2011-12-14 02:57:40 +04:00
|
|
|
$.ControlAnchor = {
|
|
|
|
NONE: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP_RIGHT: 2,
|
|
|
|
BOTTOM_RIGHT: 3,
|
|
|
|
BOTTOM_LEFT: 4
|
|
|
|
};
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* A Control represents any interface element which is meant to allow the user
|
|
|
|
* to interact with the zoomable interface. Any control can be anchored to any
|
|
|
|
* element.
|
|
|
|
* @class
|
2012-02-01 06:01:37 +04:00
|
|
|
* @param {Element} element - the contol element to be anchored in the container.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {OpenSeadragon.ControlAnchor} anchor - the location to anchor at.
|
|
|
|
* @param {Element} container - the element to control will be anchored too.
|
|
|
|
*
|
2012-02-01 06:01:37 +04:00
|
|
|
* @property {Element} element - the element providing the user interface with
|
2012-01-25 23:14:02 +04:00
|
|
|
* some type of control. Eg a zoom-in button
|
|
|
|
* @property {OpenSeadragon.ControlAnchor} anchor - the position of the control
|
|
|
|
* relative to the container.
|
|
|
|
* @property {Element} container - the element within with the control is
|
|
|
|
* positioned.
|
|
|
|
* @property {Element} wrapper - a nuetral element surrounding the control
|
|
|
|
* element.
|
|
|
|
*/
|
2012-02-01 06:01:37 +04:00
|
|
|
$.Control = function ( element, anchor, container ) {
|
|
|
|
this.element = element;
|
2012-01-24 07:48:45 +04:00
|
|
|
this.anchor = anchor;
|
|
|
|
this.container = container;
|
|
|
|
this.wrapper = $.makeNeutralElement( "span" );
|
2011-12-06 07:50:25 +04:00
|
|
|
this.wrapper.style.display = "inline-block";
|
2012-02-01 06:01:37 +04:00
|
|
|
this.wrapper.appendChild( this.element );
|
2011-12-14 02:57:40 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( this.anchor == $.ControlAnchor.NONE ) {
|
2011-12-14 02:57:40 +04:00
|
|
|
// IE6 fix
|
|
|
|
this.wrapper.style.width = this.wrapper.style.height = "100%";
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:57:40 +04:00
|
|
|
if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
|
|
|
|
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.insertBefore(
|
|
|
|
this.wrapper,
|
|
|
|
this.container.firstChild
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.appendChild( this.wrapper );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Control.prototype = {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Removes the control from the container.
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
destroy: function() {
|
2012-02-01 06:01:37 +04:00
|
|
|
this.wrapper.removeChild( this.element );
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.removeChild( this.wrapper );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Determines if the control is currently visible.
|
|
|
|
* @function
|
|
|
|
* @return {Boolean} true if currenly visible, false otherwise.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
isVisible: function() {
|
|
|
|
return this.wrapper.style.display != "none";
|
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Toggles the visibility of the control.
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} visible - true to make visible, false to hide.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setVisible: function( visible ) {
|
|
|
|
this.wrapper.style.display = visible ?
|
|
|
|
"inline-block" :
|
|
|
|
"none";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Sets the opacity level for the control.
|
|
|
|
* @function
|
|
|
|
* @param {Number} opactiy - a value between 1 and 0 inclusively.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setOpacity: function( opacity ) {
|
2012-02-01 06:01:37 +04:00
|
|
|
if ( this.element[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.setElementOpacity( this.element, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 07:48:45 +04:00
|
|
|
$.setElementOpacity( this.wrapper, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
2012-03-09 20:04:28 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
//id hash for private properties;
|
|
|
|
var THIS = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
$.ControlDock = function( options ){
|
|
|
|
var layouts = [ 'topleft', 'topright', 'bottomright', 'bottomleft'],
|
|
|
|
layout,
|
|
|
|
i;
|
|
|
|
|
|
|
|
$.extend( true, this, {
|
|
|
|
id: 'controldock-'+(+new Date())+'-'+Math.floor(Math.random()*1000000),
|
2012-03-16 19:36:28 +04:00
|
|
|
container: $.makeNeutralElement('form'),
|
2012-03-09 20:04:28 +04:00
|
|
|
controls: []
|
|
|
|
}, options );
|
|
|
|
|
|
|
|
if( this.element ){
|
|
|
|
this.element = $.getElement( this.element );
|
|
|
|
this.element.appendChild( this.container );
|
|
|
|
this.element.style.position = 'relative';
|
|
|
|
this.container.style.width = '100%';
|
|
|
|
this.container.style.height = '100%';
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < layouts.length; i++ ){
|
|
|
|
layout = layouts[ i ];
|
|
|
|
this.controls[ layout ] = $.makeNeutralElement( "div" );
|
|
|
|
this.controls[ layout ].style.position = 'absolute';
|
|
|
|
if ( layout.match( 'left' ) ){
|
|
|
|
this.controls[ layout ].style.left = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'right' ) ){
|
|
|
|
this.controls[ layout ].style.right = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'top' ) ){
|
|
|
|
this.controls[ layout ].style.top = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'bottom' ) ){
|
|
|
|
this.controls[ layout ].style.bottom = '0px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.appendChild( this.controls.topleft );
|
|
|
|
this.container.appendChild( this.controls.topright );
|
|
|
|
this.container.appendChild( this.controls.bottomright );
|
|
|
|
this.container.appendChild( this.controls.bottomleft );
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ControlDock.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
addControl: function ( element, anchor ) {
|
|
|
|
var element = $.getElement( element ),
|
|
|
|
div = null;
|
|
|
|
|
|
|
|
if ( getControlIndex( this, element ) >= 0 ) {
|
|
|
|
return; // they're trying to add a duplicate control
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( anchor ) {
|
|
|
|
case $.ControlAnchor.TOP_RIGHT:
|
|
|
|
div = this.controls.topright;
|
|
|
|
element.style.position = "relative";
|
|
|
|
element.style.marginRight = "4px";
|
|
|
|
element.style.marginTop = "4px";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_RIGHT:
|
|
|
|
div = this.controls.bottomright;
|
|
|
|
element.style.position = "relative";
|
|
|
|
element.style.marginRight = "4px";
|
|
|
|
element.style.marginBottom = "4px";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_LEFT:
|
|
|
|
div = this.controls.bottomleft;
|
|
|
|
element.style.position = "relative";
|
|
|
|
element.style.marginLeft = "4px";
|
|
|
|
element.style.marginBottom = "4px";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.TOP_LEFT:
|
|
|
|
div = this.controls.topleft;
|
|
|
|
element.style.position = "relative";
|
|
|
|
element.style.marginLeft = "4px";
|
|
|
|
element.style.marginTop = "4px";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.NONE:
|
|
|
|
default:
|
|
|
|
div = this.container;
|
|
|
|
element.style.margin = "0px";
|
|
|
|
element.style.padding = "0px";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.controls.push(
|
|
|
|
new $.Control( element, anchor, div )
|
|
|
|
);
|
|
|
|
element.style.display = "inline-block";
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
|
|
|
removeControl: function ( element ) {
|
|
|
|
var element = $.getElement( element ),
|
|
|
|
i = getControlIndex( this, element );
|
|
|
|
|
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.controls[ i ].destroy();
|
|
|
|
this.controls.splice( i, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
|
|
|
clearControls: function () {
|
|
|
|
while ( this.controls.length > 0 ) {
|
|
|
|
this.controls.pop().destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
areControlsEnabled: function () {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( this.controls[ i ].isVisible() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
|
|
|
setControlsEnabled: function( enabled ) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
this.controls[ i ].setVisible( enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utility methods
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function getControlIndex( dock, element ) {
|
|
|
|
var controls = dock.controls,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = controls.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( controls[ i ].element == element ) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
2012-02-27 15:56:29 +04:00
|
|
|
|
|
|
|
// dictionary from hash to private properties
|
2012-03-20 10:44:31 +04:00
|
|
|
var THIS = {},
|
|
|
|
// We keep a list of viewers so we can 'wake-up' each viewer on
|
|
|
|
// a page after toggling between fullpage modes
|
|
|
|
VIEWERS = {};
|
2012-02-27 15:56:29 +04:00
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
/**
|
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* The main point of entry into creating a zoomable image on the page.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* We have provided an idiomatic javascript constructor which takes
|
|
|
|
* a single object, but still support the legacy positional arguments.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* The options below are given in order that they appeared in the constructor
|
|
|
|
* as arguments and we translate a positional call into an idiomatic call.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* @class
|
|
|
|
* @extends OpenSeadragon.EventHandler
|
2012-03-09 20:04:28 +04:00
|
|
|
* @extends OpenSeadragon.ControlDock
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.element Id of Element to attach to,
|
|
|
|
* @param {String} options.xmlPath Xpath ( TODO: not sure! ),
|
|
|
|
* @param {String} options.prefixUrl Url used to prepend to paths, eg button
|
|
|
|
* images, etc.
|
|
|
|
* @param {Seadragon.Controls[]} options.controls Array of Seadragon.Controls,
|
|
|
|
* @param {Seadragon.Overlays[]} options.overlays Array of Seadragon.Overlays,
|
|
|
|
* @param {Seadragon.Controls[]} options.overlayControls An Array of ( TODO:
|
|
|
|
* not sure! )
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
$.Viewer = function( options ) {
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
var args = arguments,
|
2011-12-08 06:10:13 +04:00
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//backward compatibility for positional args while prefering more
|
|
|
|
//idiomatic javascript options object as the only argument
|
2012-02-28 03:29:00 +04:00
|
|
|
if( !$.isPlainObject( options ) ){
|
2011-12-07 05:26:06 +04:00
|
|
|
options = {
|
|
|
|
id: args[ 0 ],
|
|
|
|
xmlPath: args.length > 1 ? args[ 1 ] : undefined,
|
|
|
|
prefixUrl: args.length > 2 ? args[ 2 ] : undefined,
|
|
|
|
controls: args.length > 3 ? args[ 3 ] : undefined,
|
|
|
|
overlays: args.length > 4 ? args[ 4 ] : undefined,
|
2012-03-01 17:38:15 +04:00
|
|
|
overlayControls: args.length > 5 ? args[ 5 ] : undefined
|
2011-12-07 05:26:06 +04:00
|
|
|
};
|
|
|
|
}
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
//options.config and the general config argument are deprecated
|
|
|
|
//in favor of the more direct specification of optional settings
|
|
|
|
//being pass directly on the options object
|
|
|
|
if ( options.config ){
|
|
|
|
$.extend( true, options, options.config );
|
|
|
|
delete options.config;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Public properties
|
2011-12-07 05:26:06 +04:00
|
|
|
//Allow the options object to override global defaults
|
|
|
|
$.extend( true, this, {
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//internal state and dom identifiers
|
|
|
|
id: options.id,
|
|
|
|
hash: options.id,
|
|
|
|
|
|
|
|
//dom nodes
|
|
|
|
element: null,
|
|
|
|
canvas: null,
|
|
|
|
container: null,
|
|
|
|
|
|
|
|
//TODO: not sure how to best describe these
|
|
|
|
overlays: [],
|
|
|
|
overlayControls:[],
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//private state properties
|
2012-04-03 11:08:27 +04:00
|
|
|
previousBody: [],
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
//This was originally initialized in the constructor and so could never
|
|
|
|
//have anything in it. now it can because we allow it to be specified
|
|
|
|
//in the options and is only empty by default if not specified. Also
|
|
|
|
//this array was returned from get_controls which I find confusing
|
|
|
|
//since this object has a controls property which is treated in other
|
|
|
|
//functions like clearControls. I'm removing the accessors.
|
2012-03-01 17:38:15 +04:00
|
|
|
customControls: [],
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//These are originally not part options but declared as members
|
|
|
|
//in initialize. Its still considered idiomatic to put them here
|
|
|
|
source: null,
|
|
|
|
drawer: null,
|
|
|
|
viewport: null,
|
2012-03-07 07:20:00 +04:00
|
|
|
navigator: null,
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
//UI image resources
|
|
|
|
//TODO: rename navImages to uiImages
|
|
|
|
navImages: null,
|
|
|
|
|
|
|
|
//interface button controls
|
|
|
|
buttons: null,
|
|
|
|
|
|
|
|
//TODO: this is defunct so safely remove it
|
2012-03-01 17:38:15 +04:00
|
|
|
profiler: null
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
}, $.DEFAULT_SETTINGS, options );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Private state properties
|
|
|
|
THIS[ this.hash ] = {
|
|
|
|
"fsBoundsDelta": new $.Point( 1, 1 ),
|
|
|
|
"prevContainerSize": null,
|
|
|
|
"lastOpenStartTime": 0,
|
|
|
|
"lastOpenEndTime": 0,
|
|
|
|
"animating": false,
|
|
|
|
"forceRedraw": false,
|
|
|
|
"mouseInside": false,
|
|
|
|
"group": null,
|
|
|
|
// whether we should be continuously zooming
|
|
|
|
"zooming": false,
|
|
|
|
// how much we should be continuously zooming by
|
|
|
|
"zoomFactor": null,
|
|
|
|
"lastZoomTime": null,
|
|
|
|
// did we decide this viewer has a sequence of tile sources
|
|
|
|
"sequenced": false,
|
|
|
|
"sequence": 0
|
|
|
|
};
|
|
|
|
|
|
|
|
//Inherit some behaviors and properties
|
2012-03-09 20:04:28 +04:00
|
|
|
$.EventHandler.call( this );
|
|
|
|
$.ControlDock.call( this, options );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Deal with tile sources
|
|
|
|
var initialTileSource,
|
|
|
|
customTileSource;
|
|
|
|
|
|
|
|
if ( this.xmlPath ){
|
|
|
|
//Deprecated option. Now it is preferred to use the tileSources option
|
|
|
|
this.tileSources = [ this.xmlPath ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.tileSources ){
|
|
|
|
//tileSources is a complex option...
|
|
|
|
//It can be a string, object, function, or an array of any of these.
|
|
|
|
// - A String implies a DZI
|
|
|
|
// - An Srray of Objects implies a simple image
|
|
|
|
// - A Function implies a custom tile source callback
|
|
|
|
// - An Array that is not an Array of simple Objects implies a sequence
|
|
|
|
// of tile sources which can be any of the above
|
|
|
|
if( $.isArray( this.tileSources ) ){
|
|
|
|
if( $.isPlainObject( this.tileSources[ 0 ] ) ){
|
|
|
|
//This is a non-sequenced legacy tile source
|
|
|
|
initialTileSource = this.tileSources;
|
|
|
|
} else {
|
|
|
|
//Sequenced tile source
|
|
|
|
initialTileSource = this.tileSources[ 0 ];
|
|
|
|
THIS[ this.hash ].sequenced = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
initialTileSource = this.tileSources;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.openTileSource( initialTileSource );
|
|
|
|
}
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
this.element = this.element || document.getElementById( this.id );
|
2012-01-24 17:03:50 +04:00
|
|
|
this.canvas = $.makeNeutralElement( "div" );
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
(function( canvas ){
|
|
|
|
canvas.width = "100%";
|
|
|
|
canvas.height = "100%";
|
|
|
|
canvas.overflow = "hidden";
|
|
|
|
canvas.position = "absolute";
|
|
|
|
canvas.top = "0px";
|
|
|
|
canvas.left = "0px";
|
|
|
|
}( this.canvas.style ));
|
|
|
|
|
|
|
|
(function( container ){
|
|
|
|
container.width = "100%";
|
|
|
|
container.height = "100%";
|
|
|
|
container.position = "relative";
|
|
|
|
container.left = "0px";
|
|
|
|
container.top = "0px";
|
|
|
|
container.textAlign = "left"; // needed to protect against
|
|
|
|
}( this.container.style ));
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.container.insertBefore( this.canvas, this.container.firstChild );
|
2012-03-09 20:04:28 +04:00
|
|
|
this.element.appendChild( this.container );
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
//Used for toggling between fullscreen and default container size
|
2012-02-27 15:56:29 +04:00
|
|
|
//TODO: these can be closure private and shared across Viewer
|
|
|
|
// instances.
|
2012-01-24 17:03:50 +04:00
|
|
|
this.bodyWidth = document.body.style.width;
|
|
|
|
this.bodyHeight = document.body.style.height;
|
|
|
|
this.bodyOverflow = document.body.style.overflow;
|
|
|
|
this.docOverflow = document.documentElement.style.overflow;
|
2012-02-27 15:56:29 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
this.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.canvas,
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-03 04:12:45 +04:00
|
|
|
clickHandler: $.delegate( this, onCanvasClick ),
|
|
|
|
dragHandler: $.delegate( this, onCanvasDrag ),
|
|
|
|
releaseHandler: $.delegate( this, onCanvasRelease ),
|
|
|
|
scrollHandler: $.delegate( this, onCanvasScroll )
|
2012-03-07 07:20:00 +04:00
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // default state
|
2012-02-03 04:12:45 +04:00
|
|
|
|
|
|
|
this.outerTracker = new $.MouseTracker({
|
|
|
|
element: this.container,
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-03 04:12:45 +04:00
|
|
|
enterHandler: $.delegate( this, onContainerEnter ),
|
|
|
|
exitHandler: $.delegate( this, onContainerExit ),
|
|
|
|
releaseHandler: $.delegate( this, onContainerRelease )
|
2012-03-07 07:20:00 +04:00
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // always tracking
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-02-28 19:01:45 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-01-24 17:03:50 +04:00
|
|
|
var beginZoomingInHandler = $.delegate( this, beginZoomingIn ),
|
|
|
|
endZoomingHandler = $.delegate( this, endZooming ),
|
|
|
|
doSingleZoomInHandler = $.delegate( this, doSingleZoomIn ),
|
|
|
|
beginZoomingOutHandler = $.delegate( this, beginZoomingOut ),
|
|
|
|
doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ),
|
|
|
|
onHomeHandler = $.delegate( this, onHome ),
|
|
|
|
onFullPageHandler = $.delegate( this, onFullPage ),
|
2012-03-16 19:36:28 +04:00
|
|
|
onFocusHandler = $.delegate( this, onFocus ),
|
|
|
|
onBlurHandler = $.delegate( this, onBlur ),
|
2012-04-03 11:08:27 +04:00
|
|
|
onNextHandler = $.delegate( this, onNext ),
|
|
|
|
onPreviousHandler = $.delegate( this, onPrevious ),
|
|
|
|
navImages = this.navImages,
|
|
|
|
buttons = [];
|
2012-03-20 03:03:58 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
|
|
|
if( this.showNavigationControl ){
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
buttons.push( this.zoomInButton = new $.Button({
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomIn" ),
|
2012-03-01 17:38:15 +04:00
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.zoomIn.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.zoomIn.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.zoomIn.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.zoomIn.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onPress: beginZoomingInHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomInHandler,
|
|
|
|
onEnter: beginZoomingInHandler,
|
2012-03-16 19:36:28 +04:00
|
|
|
onExit: endZoomingHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
2012-04-03 11:08:27 +04:00
|
|
|
}));
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
buttons.push( this.zoomOutButton = new $.Button({
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomOut" ),
|
2012-03-01 17:38:15 +04:00
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.zoomOut.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.zoomOut.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.zoomOut.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.zoomOut.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onPress: beginZoomingOutHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomOutHandler,
|
|
|
|
onEnter: beginZoomingOutHandler,
|
2012-03-16 19:36:28 +04:00
|
|
|
onExit: endZoomingHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
2012-04-03 11:08:27 +04:00
|
|
|
}));
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
buttons.push( this.homeButton = new $.Button({
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.Home" ),
|
2012-03-01 17:38:15 +04:00
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.home.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.home.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.home.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.home.DOWN ),
|
2012-03-16 19:36:28 +04:00
|
|
|
onRelease: onHomeHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
2012-04-03 11:08:27 +04:00
|
|
|
}));
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
buttons.push( this.fullPageButton = new $.Button({
|
2012-03-01 17:38:15 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.FullPage" ),
|
2012-03-01 17:38:15 +04:00
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.fullpage.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.fullpage.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.fullpage.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.fullpage.DOWN ),
|
2012-03-16 19:36:28 +04:00
|
|
|
onRelease: onFullPageHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
2012-04-03 11:08:27 +04:00
|
|
|
}));
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
if( THIS[ this.hash ].sequenced ){
|
|
|
|
|
|
|
|
buttons.push( this.previousButton = new $.Button({
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
tooltip: $.getString( "Tooltips.PreviousPage" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.previous.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.previous.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.previous.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.previous.DOWN ),
|
|
|
|
onRelease: onPreviousHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
|
|
|
buttons.push( this.nextButton = new $.Button({
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
tooltip: $.getString( "Tooltips.NextPage" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.next.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.next.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.next.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.next.DOWN ),
|
|
|
|
onRelease: onNextHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.previousButton.disable();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.buttons = new $.ButtonGroup({
|
|
|
|
buttons: buttons,
|
2012-03-09 20:04:28 +04:00
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-04-03 11:08:27 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold
|
2012-03-09 20:04:28 +04:00
|
|
|
});
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
this.navControl = this.buttons.element;
|
|
|
|
this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade
|
|
|
|
this.addHandler( 'open', $.delegate( this, lightUp ) );
|
|
|
|
|
|
|
|
if( this.toolbar ){
|
|
|
|
this.toolbar = new $.ControlDock({ element: this.toolbar });
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.addControl( this.navControl, $.ControlAnchor.TOP_LEFT );
|
2012-03-09 20:04:28 +04:00
|
|
|
}else{
|
|
|
|
this.addControl( this.navControl, $.ControlAnchor.BOTTOM_RIGHT );
|
|
|
|
}
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
for ( i = 0; i < this.customControls.length; i++ ) {
|
|
|
|
this.addControl(
|
|
|
|
this.customControls[ i ].id,
|
|
|
|
this.customControls[ i ].anchor
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
window.setTimeout( function(){
|
|
|
|
beginControlsAutoHide( _this );
|
|
|
|
}, 1 ); // initial fade out
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
$.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isOpen
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
isOpen: function () {
|
|
|
|
return !!this.source;
|
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* If the string is xml is simply parsed and opened, otherwise the string
|
|
|
|
* is treated as an URL and an xml document is requested via ajax, parsed
|
|
|
|
* and then opened in the viewer.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openDzi
|
|
|
|
* @param {String} dzi and xml string or the url to a DZI xml document.
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
openDzi: function ( dzi ) {
|
2011-12-13 07:40:02 +04:00
|
|
|
var _this = this;
|
2012-02-01 00:59:09 +04:00
|
|
|
$.createFromDZI(
|
|
|
|
dzi,
|
2011-12-13 07:40:02 +04:00
|
|
|
function( source ){
|
|
|
|
_this.open( source );
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
this.tileHost
|
2011-12-08 06:10:13 +04:00
|
|
|
);
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openTileSource
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-13 07:40:02 +04:00
|
|
|
openTileSource: function ( tileSource ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
var _this = this,
|
|
|
|
customTileSource;
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
if ( $.type( tileSource ) == 'string') {
|
|
|
|
//Standard DZI format
|
|
|
|
_this.openDzi( tileSource );
|
|
|
|
} else if ( $.isArray( tileSource ) ){
|
|
|
|
//Legacy image pyramid
|
|
|
|
_this.open( new $.LegacyTileSource( tileSource ) );
|
|
|
|
} else if ( $.isPlainObject( tileSource ) && $.isFunction( tileSource.getTileUrl ) ){
|
|
|
|
//Custom tile source
|
|
|
|
customTileSource = new $.TileSource(
|
|
|
|
tileSource.width,
|
|
|
|
tileSource.height,
|
|
|
|
tileSource.tileSize,
|
|
|
|
tileSource.tileOverlap,
|
|
|
|
tileSource.minLevel,
|
|
|
|
tileSource.maxLevel
|
|
|
|
);
|
|
|
|
customTileSource.getTileUrl = tileSource.getTileUrl;
|
|
|
|
_this.open( customTileSource );
|
|
|
|
} else {
|
|
|
|
//can assume it's already a tile source implementation
|
|
|
|
_this.open( tileSource );
|
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.open
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-13 07:40:02 +04:00
|
|
|
open: function( source ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
var _this = this,
|
|
|
|
overlay,
|
|
|
|
i;
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
if ( this.source ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
this.close( );
|
2011-12-13 07:40:02 +04:00
|
|
|
}
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
// to ignore earlier opens
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastOpenStartTime = +new Date();
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
window.setTimeout( function () {
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ _this.hash ].lastOpenStartTime > THIS[ _this.hash ].lastOpenEndTime ) {
|
|
|
|
THIS[ _this.hash ].setMessage( $.getString( "Messages.Loading" ) );
|
2011-12-13 07:40:02 +04:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastOpenEndTime = +new Date();
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getElementSize( this.container );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
if( source ){
|
|
|
|
this.source = source;
|
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.viewport = this.viewport ? this.viewport : new $.Viewport({
|
2012-03-01 17:38:15 +04:00
|
|
|
containerSize: THIS[ this.hash ].prevContainerSize,
|
|
|
|
contentSize: this.source.dimensions,
|
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime,
|
|
|
|
minZoomImageRatio: this.minZoomImageRatio,
|
|
|
|
maxZoomPixelRatio: this.maxZoomPixelRatio,
|
|
|
|
visibilityRatio: this.visibilityRatio,
|
|
|
|
wrapHorizontal: this.wrapHorizontal,
|
|
|
|
wrapVertical: this.wrapVertical
|
2012-02-28 03:29:00 +04:00
|
|
|
});
|
2012-04-03 11:08:27 +04:00
|
|
|
if( this.preserveVewport ){
|
|
|
|
this.viewport.resetContentSize( this.source.dimensions );
|
|
|
|
}
|
2012-02-28 03:29:00 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
this.drawer = new $.Drawer({
|
|
|
|
source: this.source,
|
|
|
|
viewport: this.viewport,
|
|
|
|
element: this.canvas,
|
2012-03-16 19:36:28 +04:00
|
|
|
overlays: this.overlays,
|
2012-03-01 17:38:15 +04:00
|
|
|
maxImageCacheCount: this.maxImageCacheCount,
|
|
|
|
imageLoaderLimit: this.imageLoaderLimit,
|
|
|
|
minZoomImageRatio: this.minZoomImageRatio,
|
|
|
|
wrapHorizontal: this.wrapHorizontal,
|
|
|
|
wrapVertical: this.wrapVertical,
|
|
|
|
immediateRender: this.immediateRender,
|
|
|
|
blendTime: this.blendTime,
|
|
|
|
alwaysBlend: this.alwaysBlend,
|
|
|
|
minPixelRatio: this.minPixelRatio
|
|
|
|
});
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Instantiate a navigator if configured
|
|
|
|
if ( this.showNavigator && ! this.navigator ){
|
|
|
|
this.navigator = new $.Navigator({
|
|
|
|
id: this.navigatorElement,
|
|
|
|
position: this.navigatorPosition,
|
|
|
|
sizeRatio: this.navigatorSizeRatio,
|
|
|
|
height: this.navigatorHeight,
|
|
|
|
width: this.navigatorWidth,
|
|
|
|
tileSources: this.tileSources,
|
|
|
|
tileHost: this.tileHost,
|
|
|
|
prefixUrl: this.prefixUrl,
|
|
|
|
overlays: this.overlays,
|
|
|
|
viewer: this
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
//this.profiler = new $.Profiler();
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].animating = false;
|
|
|
|
THIS[ this.hash ].forceRedraw = true;
|
2011-12-23 05:47:21 +04:00
|
|
|
scheduleUpdate( this, updateMulti );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
//Assuming you had programatically created a bunch of overlays
|
|
|
|
//and added them via configuration
|
2012-01-24 17:03:50 +04:00
|
|
|
for ( i = 0; i < this.overlayControls.length; i++ ) {
|
|
|
|
|
|
|
|
overlay = this.overlayControls[ i ];
|
|
|
|
|
|
|
|
if ( overlay.point != null ) {
|
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Point(
|
|
|
|
overlay.point.X,
|
|
|
|
overlay.point.Y
|
|
|
|
),
|
|
|
|
$.OverlayPlacement.TOP_LEFT
|
|
|
|
);
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
} else {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Rect(
|
|
|
|
overlay.rect.Point.X,
|
|
|
|
overlay.rect.Point.Y,
|
|
|
|
overlay.rect.Width,
|
|
|
|
overlay.rect.Height
|
|
|
|
),
|
|
|
|
overlay.placement
|
|
|
|
);
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
VIEWERS[ this.hash ] = this;
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "open" );
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( this.navigator ){
|
|
|
|
this.navigator.open( source );
|
|
|
|
}
|
|
|
|
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-13 07:40:02 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.close
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
close: function ( ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
this.source = null;
|
|
|
|
this.drawer = null;
|
2012-04-03 11:08:27 +04:00
|
|
|
this.viewport = this.preserveViewport ? this.viewport : null;
|
2012-01-25 23:14:02 +04:00
|
|
|
//this.profiler = null;
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-03-16 19:36:28 +04:00
|
|
|
|
|
|
|
VIEWERS[ this.hash ] = null;
|
|
|
|
delete VIEWERS[ this.hash ];
|
|
|
|
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isMouseNavEnabled
|
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isMouseNavEnabled: function () {
|
|
|
|
return this.innerTracker.isTracking();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.setMouseNavEnabled
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
setMouseNavEnabled: function( enabled ){
|
|
|
|
this.innerTracker.setTracking( enabled );
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isDashboardEnabled
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-20 03:03:58 +04:00
|
|
|
areControlsEnabled: function () {
|
|
|
|
return this.controls.length && this.controls[ i ].isVisibile();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.setDashboardEnabled
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-20 03:03:58 +04:00
|
|
|
setControlsEnabled: function( enabled ) {
|
|
|
|
if( enabled ){
|
|
|
|
abortControlsAutoHide( this );
|
|
|
|
} else {
|
|
|
|
beginControlsAutoHide( this );
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isFullPage
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isFullPage: function () {
|
|
|
|
return this.container.parentNode == document.body;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2012-02-10 07:16:09 +04:00
|
|
|
* Toggle full page mode.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.setFullPage
|
2012-02-10 07:16:09 +04:00
|
|
|
* @param {Boolean} fullPage
|
|
|
|
* If true, enter full page mode. If false, exit full page mode.
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-08 06:10:13 +04:00
|
|
|
setFullPage: function( fullPage ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
var body = document.body,
|
|
|
|
bodyStyle = body.style,
|
|
|
|
docStyle = document.documentElement.style,
|
|
|
|
containerStyle = this.container.style,
|
|
|
|
canvasStyle = this.canvas.style,
|
2011-12-08 06:10:13 +04:00
|
|
|
oldBounds,
|
2012-02-10 07:16:09 +04:00
|
|
|
newBounds,
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer,
|
|
|
|
hash,
|
2012-02-10 07:16:09 +04:00
|
|
|
nodes,
|
|
|
|
i;
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
//dont bother modifying the DOM if we are already in full page mode.
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( fullPage == this.isFullPage() ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
if ( fullPage ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
this.bodyOverflow = bodyStyle.overflow;
|
|
|
|
this.docOverflow = docStyle.overflow;
|
2011-12-08 06:10:13 +04:00
|
|
|
bodyStyle.overflow = "hidden";
|
|
|
|
docStyle.overflow = "hidden";
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.bodyWidth = bodyStyle.width;
|
|
|
|
this.bodyHeight = bodyStyle.height;
|
2011-12-08 06:10:13 +04:00
|
|
|
bodyStyle.width = "100%";
|
|
|
|
bodyStyle.height = "100%";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
canvasStyle.backgroundColor = "black";
|
2011-12-08 06:10:13 +04:00
|
|
|
canvasStyle.color = "white";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
containerStyle.position = "fixed";
|
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
//when entering full screen on the ipad it wasnt sufficient to leave
|
|
|
|
//the body intact as only only the top half of the screen would
|
|
|
|
//respond to touch events on the canvas, while the bottom half treated
|
|
|
|
//them as touch events on the document body. Thus we remove and store
|
|
|
|
//the bodies elements and replace them when we leave full screen.
|
|
|
|
this.previousBody = [];
|
2012-03-09 20:04:28 +04:00
|
|
|
nodes = body.childNodes.length;
|
2012-02-10 07:16:09 +04:00
|
|
|
for ( i = 0; i < nodes; i ++ ){
|
2012-03-09 20:04:28 +04:00
|
|
|
this.previousBody.push( body.childNodes[ 0 ] );
|
|
|
|
body.removeChild( body.childNodes[ 0 ] );
|
2012-02-10 07:16:09 +04:00
|
|
|
}
|
2012-03-09 20:04:28 +04:00
|
|
|
|
|
|
|
//If we've got a toolbar, we need to enable the user to use css to
|
|
|
|
//preserve it in fullpage mode
|
|
|
|
if( this.toolbar && this.toolbar.element ){
|
|
|
|
//save a reference to the parent so we can put it back
|
|
|
|
//in the long run we need a better strategy
|
|
|
|
this.toolbar.parentNode = this.toolbar.element.parentNode;
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.nextSibling = this.toolbar.element.nextSibling;
|
2012-03-09 20:04:28 +04:00
|
|
|
body.appendChild( this.toolbar.element );
|
|
|
|
|
|
|
|
//Make sure the user has some ability to style the toolbar based
|
|
|
|
//on the mode
|
|
|
|
this.toolbar.element.setAttribute(
|
|
|
|
'class',
|
|
|
|
this.toolbar.element.className +" fullpage"
|
|
|
|
);
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.element.style.position = 'fixed';
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
this.container.style.top = $.getElementSize(
|
|
|
|
this.toolbar.element
|
|
|
|
).y + 'px';
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
body.appendChild( this.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getWindowSize();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
// mouse will be inside container now
|
2011-12-13 02:22:01 +04:00
|
|
|
$.delegate( this, onContainerEnter )();
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
bodyStyle.overflow = this.bodyOverflow;
|
|
|
|
docStyle.overflow = this.docOverflow;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
bodyStyle.width = this.bodyWidth;
|
|
|
|
bodyStyle.height = this.bodyHeight;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
canvasStyle.backgroundColor = "";
|
2011-12-08 06:10:13 +04:00
|
|
|
canvasStyle.color = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
containerStyle.position = "relative";
|
2011-12-08 06:10:13 +04:00
|
|
|
containerStyle.zIndex = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
//If we've got a toolbar, we need to enable the user to use css to
|
|
|
|
//reset it to its original state
|
|
|
|
if( this.toolbar && this.toolbar.element ){
|
|
|
|
body.removeChild( this.toolbar.element );
|
|
|
|
|
|
|
|
//Make sure the user has some ability to style the toolbar based
|
|
|
|
//on the mode
|
|
|
|
this.toolbar.element.setAttribute(
|
|
|
|
'class',
|
|
|
|
this.toolbar.element.className.replace('fullpage','')
|
|
|
|
);
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.element.style.position = 'relative';
|
2012-03-10 06:44:14 +04:00
|
|
|
this.toolbar.parentNode.insertBefore(
|
|
|
|
this.toolbar.element,
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.nextSibling
|
2012-03-10 06:44:14 +04:00
|
|
|
);
|
|
|
|
delete this.toolbar.parentNode;
|
2012-03-16 19:36:28 +04:00
|
|
|
delete this.toolbar.nextSibling;
|
|
|
|
|
|
|
|
this.container.style.top = 'auto';
|
2012-03-09 20:04:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
body.removeChild( this.container );
|
2012-02-10 07:16:09 +04:00
|
|
|
nodes = this.previousBody.length;
|
|
|
|
for ( i = 0; i < nodes; i++ ){
|
2012-03-09 20:04:28 +04:00
|
|
|
body.appendChild( this.previousBody.shift() );
|
2012-02-10 07:16:09 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
this.element.appendChild( this.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getElementSize( this.element );
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
// mouse will likely be outside now
|
2011-12-13 02:22:01 +04:00
|
|
|
$.delegate( this, onContainerExit )();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
if ( this.viewport ) {
|
|
|
|
oldBounds = this.viewport.getBounds();
|
2012-02-27 15:56:29 +04:00
|
|
|
this.viewport.resize( THIS[ this.hash ].prevContainerSize );
|
2011-12-08 06:10:13 +04:00
|
|
|
newBounds = this.viewport.getBounds();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
if ( fullPage ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].fsBoundsDelta = new $.Point(
|
2011-12-08 06:10:13 +04:00
|
|
|
newBounds.width / oldBounds.width,
|
|
|
|
newBounds.height / oldBounds.height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
this.viewport.update();
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
Math.max(
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].fsBoundsDelta.x,
|
|
|
|
THIS[ this.hash ].fsBoundsDelta.y
|
2011-12-08 06:10:13 +04:00
|
|
|
),
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2012-03-16 19:36:28 +04:00
|
|
|
//Ensures that if multiple viewers are on a page, the viewers that
|
|
|
|
//were hidden during fullpage are 'reopened'
|
|
|
|
for( hash in VIEWERS ){
|
|
|
|
viewer = VIEWERS[ hash ];
|
|
|
|
if( viewer !== this && viewer != this.navigator ){
|
|
|
|
viewer.open( viewer.source );
|
2012-04-03 11:08:27 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.open( viewer.source );
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].forceRedraw = true;
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "resize", this );
|
2011-12-23 05:36:17 +04:00
|
|
|
updateOnce( this );
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isVisible
|
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isVisible: function () {
|
|
|
|
return this.container.style.visibility != "hidden";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.setVisible
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-08 06:10:13 +04:00
|
|
|
setVisible: function( visible ){
|
|
|
|
this.container.style.visibility = visible ? "" : "hidden";
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
});
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Schedulers provide the general engine for animation
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
|
|
|
|
var currentTime,
|
|
|
|
targetTime,
|
|
|
|
deltaTime;
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ viewer.hash ].animating ) {
|
2011-12-23 05:47:21 +04:00
|
|
|
return window.setTimeout( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
}, 1 );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
currentTime = +new Date();
|
|
|
|
prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime;
|
2012-01-24 17:03:50 +04:00
|
|
|
// 60 frames per second is ideal
|
|
|
|
targetTime = prevUpdateTime + 1000 / 60;
|
|
|
|
deltaTime = Math.max( 1, targetTime - currentTime );
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
return window.setTimeout( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
}, deltaTime );
|
2011-12-08 06:10:13 +04:00
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//provides a sequence in the fade animation
|
|
|
|
function scheduleControlsFade( viewer ) {
|
|
|
|
window.setTimeout( function(){
|
|
|
|
updateControlsFade( viewer );
|
|
|
|
}, 20);
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//initiates an animation to hide the controls
|
|
|
|
function beginControlsAutoHide( viewer ) {
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !viewer.autoHideControls ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
viewer.controlsShouldFade = true;
|
|
|
|
viewer.controlsFadeBeginTime =
|
2012-01-24 17:03:50 +04:00
|
|
|
+new Date() +
|
2012-03-01 17:38:15 +04:00
|
|
|
viewer.controlsFadeDelay;
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
window.setTimeout( function(){
|
|
|
|
scheduleControlsFade( viewer );
|
2012-03-01 17:38:15 +04:00
|
|
|
}, viewer.controlsFadeDelay );
|
2011-12-08 06:10:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//determines if fade animation is done or continues the animation
|
|
|
|
function updateControlsFade( viewer ) {
|
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
opacity,
|
|
|
|
i;
|
|
|
|
if ( viewer.controlsShouldFade ) {
|
|
|
|
currentTime = new Date().getTime();
|
|
|
|
deltaTime = currentTime - viewer.controlsFadeBeginTime;
|
2012-03-01 17:38:15 +04:00
|
|
|
opacity = 1.0 - deltaTime / viewer.controlsFadeLength;
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
opacity = Math.min( 1.0, opacity );
|
|
|
|
opacity = Math.max( 0.0, opacity );
|
|
|
|
|
2011-12-13 02:22:01 +04:00
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i--) {
|
|
|
|
viewer.controls[ i ].setOpacity( opacity );
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( opacity > 0 ) {
|
|
|
|
// fade again
|
|
|
|
scheduleControlsFade( viewer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//stop the fade animation on the controls and show them
|
|
|
|
function abortControlsAutoHide( viewer ) {
|
|
|
|
var i;
|
|
|
|
viewer.controlsShouldFade = false;
|
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
viewer.controls[ i ].setOpacity( 1.0 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default view event handlers.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-03-16 19:36:28 +04:00
|
|
|
function onFocus(){
|
|
|
|
abortControlsAutoHide( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
function onBlur(){
|
|
|
|
beginControlsAutoHide( this );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasClick( tracker, position, quick, shift ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var zoomPreClick,
|
|
|
|
factor;
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport && quick ) { // ignore clicks where mouse moved
|
2012-03-01 17:38:15 +04:00
|
|
|
zoomPerClick = this.zoomPerClick;
|
2011-12-08 06:10:13 +04:00
|
|
|
factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
this.viewport.pointFromPixel( position, true )
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasDrag( tracker, position, delta, shift ) {
|
|
|
|
if ( this.viewport ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
if( !this.panHorizontal ){
|
|
|
|
delta.x = 0;
|
|
|
|
}
|
|
|
|
if( !this.panVertical ){
|
|
|
|
delta.y = 0;
|
|
|
|
}
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.panBy(
|
|
|
|
this.viewport.deltaPointsFromPixels(
|
|
|
|
delta.negate()
|
|
|
|
)
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( insideElementPress && this.viewport ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasScroll( tracker, position, scroll, shift ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var factor;
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-03-01 17:38:15 +04:00
|
|
|
factor = Math.pow( this.zoomPerScroll, scroll );
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
this.viewport.pointFromPixel( position, true )
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
//cancels event
|
|
|
|
return false;
|
2011-12-08 06:10:13 +04:00
|
|
|
};
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerExit( tracker, position, buttonDownElement, buttonDownAny ) {
|
|
|
|
if ( !buttonDownElement ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = false;
|
|
|
|
if ( !THIS[ this.hash ].animating ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( !insideElementRelease ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = false;
|
|
|
|
if ( !THIS[ this.hash ].animating ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = true;
|
2011-12-08 06:10:13 +04:00
|
|
|
abortControlsAutoHide( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Page update routines ( aka Views - for future reference )
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-23 05:47:21 +04:00
|
|
|
|
|
|
|
function updateMulti( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
var beginTime;
|
|
|
|
|
|
|
|
if ( !viewer.source ) {
|
2011-12-23 05:47:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
beginTime = +new Date();
|
2011-12-23 05:47:21 +04:00
|
|
|
updateOnce( viewer );
|
|
|
|
scheduleUpdate( viewer, arguments.callee, beginTime );
|
|
|
|
};
|
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
function updateOnce( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
var containerSize,
|
|
|
|
animated;
|
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
if ( !viewer.source ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
//viewer.profiler.beginUpdate();
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
containerSize = $.getElementSize( viewer.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
// maintain image position
|
|
|
|
viewer.viewport.resize( containerSize, true );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].prevContainerSize = containerSize;
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "resize" );
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
animated = viewer.viewport.update();
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !THIS[ viewer.hash ].animating && animated ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animationstart" );
|
|
|
|
abortControlsAutoHide( viewer );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
if ( animated ) {
|
|
|
|
viewer.drawer.update();
|
2012-03-07 07:20:00 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.update( viewer.viewport );
|
|
|
|
}
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animation" );
|
2012-02-27 15:56:29 +04:00
|
|
|
} else if ( THIS[ viewer.hash ].forceRedraw || viewer.drawer.needsUpdate() ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.drawer.update();
|
2012-03-07 07:20:00 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.update( viewer.viewport );
|
|
|
|
}
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].forceRedraw = false;
|
2011-12-28 03:20:45 +04:00
|
|
|
}
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ viewer.hash ].animating && !animated ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animationfinish" );
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !THIS[ viewer.hash ].mouseInside ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
beginControlsAutoHide( viewer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].animating = animated;
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
//viewer.profiler.endUpdate();
|
2011-12-23 05:36:17 +04:00
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function resolveUrl( prefix, url ) {
|
|
|
|
return prefix ? prefix + url : url;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function beginZoomingIn() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
2012-03-01 17:38:15 +04:00
|
|
|
THIS[ this.hash ].zoomFactor = this.zoomPerSecond;
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
2012-04-03 11:08:27 +04:00
|
|
|
};
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function beginZoomingOut() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
2012-03-01 17:38:15 +04:00
|
|
|
THIS[ this.hash ].zoomFactor = 1.0 / this.zoomPerSecond;
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
2012-04-03 11:08:27 +04:00
|
|
|
};
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function endZooming() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2012-04-03 11:08:27 +04:00
|
|
|
};
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function scheduleZoom( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
window.setTimeout( $.delegate( viewer, doZoom ), 10 );
|
2012-04-03 11:08:27 +04:00
|
|
|
};
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function doZoom() {
|
2012-01-24 17:03:50 +04:00
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
adjustFactor;
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ this.hash ].zooming && this.viewport) {
|
2012-01-24 17:03:50 +04:00
|
|
|
currentTime = +new Date();
|
2012-02-27 15:56:29 +04:00
|
|
|
deltaTime = currentTime - THIS[ this.hash ].lastZoomTime;
|
|
|
|
adjustedFactor = Math.pow( THIS[ this.hash ].zoomFactor, deltaTime / 1000 );
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy( adjustedFactor );
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.applyConstraints();
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = currentTime;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function doSingleZoomIn() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.zoomBy(
|
2012-03-01 17:38:15 +04:00
|
|
|
this.zoomPerClick / 1.0
|
2011-12-23 05:08:06 +04:00
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function doSingleZoomOut() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.zoomBy(
|
2012-03-01 17:38:15 +04:00
|
|
|
1.0 / this.zoomPerClick
|
2011-12-23 05:08:06 +04:00
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function lightUp() {
|
2012-01-24 17:03:50 +04:00
|
|
|
this.buttons.emulateEnter();
|
|
|
|
this.buttons.emulateExit();
|
2011-12-23 05:08:06 +04:00
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function onHome() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.goHome();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function onFullPage() {
|
|
|
|
this.setFullPage( !this.isFullPage() );
|
2012-01-24 17:03:50 +04:00
|
|
|
// correct for no mouseout event on change
|
2012-03-20 03:03:58 +04:00
|
|
|
this.buttons.emulateExit();
|
|
|
|
this.fullPageButton.element.focus();
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
function onPrevious(){
|
|
|
|
var previous = THIS[ this.hash ].sequence - 1,
|
|
|
|
preserveVewport = true;
|
|
|
|
if( previous >= 0 ){
|
|
|
|
|
|
|
|
THIS[ this.hash ].sequence = previous;
|
|
|
|
|
|
|
|
if( 0 === previous ){
|
|
|
|
//Disable previous button
|
|
|
|
this.previousButton.disable();
|
|
|
|
}
|
|
|
|
if( this.tileSources.length > 0 ){
|
|
|
|
//Enable next button
|
|
|
|
this.nextButton.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.openTileSource( this.tileSources[ previous ] );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function onNext(){
|
|
|
|
var next = THIS[ this.hash ].sequence + 1,
|
|
|
|
preserveVewport = true;
|
|
|
|
if( this.tileSources.length > next ){
|
|
|
|
|
|
|
|
THIS[ this.hash ].sequence = next;
|
|
|
|
|
|
|
|
if( ( this.tileSources.length - 1 ) === next ){
|
|
|
|
//Disable next button
|
|
|
|
this.nextButton.disable();
|
|
|
|
}
|
|
|
|
if( next > 0 ){
|
|
|
|
//Enable previous button
|
|
|
|
this.previousButton.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.openTileSource( this.tileSources[ next ] );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
2012-03-07 07:20:00 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.viewerId
|
|
|
|
*/
|
|
|
|
$.Navigator = function( options ){
|
|
|
|
|
|
|
|
var _this = this,
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer = options.viewer,
|
|
|
|
viewerSize = $.getElementSize( viewer.element );
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
//We may need to create a new element and id if they did not
|
|
|
|
//provide the id for the existing element
|
|
|
|
if( !options.id ){
|
2012-03-16 19:36:28 +04:00
|
|
|
options.id = 'navigator-' + (+new Date());
|
|
|
|
this.element = $.makeNeutralElement( "div" );
|
|
|
|
this.element.id = options.id;
|
|
|
|
this.element.className = 'navigator';
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
options = $.extend( true, {
|
2012-03-20 03:03:58 +04:00
|
|
|
navigatorSizeRatio: $.DEFAULT_SETTINGS.navigatorSizeRatio
|
2012-03-09 20:04:28 +04:00
|
|
|
}, options, {
|
2012-03-07 07:20:00 +04:00
|
|
|
element: this.element,
|
|
|
|
//These need to be overridden to prevent recursion since
|
|
|
|
//the navigator is a viewer and a viewer has a navigator
|
|
|
|
showNavigator: false,
|
|
|
|
mouseNavEnabled: false,
|
2012-03-09 20:04:28 +04:00
|
|
|
showNavigationControl: false
|
2012-03-07 07:20:00 +04:00
|
|
|
});
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
options.minPixelRatio = Math.min(
|
|
|
|
options.navigatorSizeRatio * $.DEFAULT_SETTINGS.minPixelRatio,
|
|
|
|
$.DEFAULT_SETTINGS.minPixelRatio
|
|
|
|
);
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
(function( style ){
|
|
|
|
style.marginTop = '0px';
|
|
|
|
style.marginRight = '0px';
|
|
|
|
style.marginBottom = '0px';
|
|
|
|
style.marginLeft = '0px';
|
|
|
|
style.border = '2px solid #555';
|
|
|
|
style.background = '#000';
|
|
|
|
style.opacity = 0.8;
|
|
|
|
style.overflow = 'hidden';
|
|
|
|
}( this.element.style ));
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
this.displayRegion = $.makeNeutralElement( "textarea" );
|
|
|
|
this.displayRegion.id = this.element.id + '-displayregion';
|
|
|
|
this.displayRegion.className = 'displayregion';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
(function( style ){
|
|
|
|
style.position = 'relative';
|
|
|
|
style.top = '0px';
|
|
|
|
style.left = '0px';
|
2012-03-21 05:58:23 +04:00
|
|
|
style.fontSize = '0px';
|
|
|
|
style.border = '2px solid #900';
|
2012-03-20 23:00:25 +04:00
|
|
|
//TODO: IE doesnt like this property being set
|
2012-03-21 05:58:23 +04:00
|
|
|
try{ style.outline = '2px auto #900'; }catch(e){/*ignore*/}
|
2012-03-07 07:20:00 +04:00
|
|
|
style.background = 'transparent';
|
2012-03-20 10:26:34 +04:00
|
|
|
style.float = 'left'; //Webkit
|
|
|
|
style.cssFloat = 'left'; //Firefox
|
2012-03-20 23:30:29 +04:00
|
|
|
style.styleFloat = 'left'; //IE
|
2012-03-07 07:20:00 +04:00
|
|
|
style.zIndex = 999999999;
|
2012-04-03 11:08:27 +04:00
|
|
|
style.cursor = 'default';
|
2012-03-07 07:20:00 +04:00
|
|
|
}( this.displayRegion.style ));
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.element.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.element,
|
|
|
|
scrollHandler: function(){
|
|
|
|
//dont scroll the page up and down if the user is scrolling
|
|
|
|
//in the navigator
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}).setTracking( true );
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
this.displayRegion.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.displayRegion,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-04-03 11:08:27 +04:00
|
|
|
clickHandler: $.delegate( this, onCanvasClick ),
|
|
|
|
dragHandler: $.delegate( this, onCanvasDrag ),
|
|
|
|
releaseHandler: $.delegate( this, onCanvasRelease ),
|
|
|
|
scrollHandler: $.delegate( this, onCanvasScroll ),
|
2012-03-20 03:03:58 +04:00
|
|
|
focusHandler: function(){
|
2012-04-03 11:08:27 +04:00
|
|
|
var point = $.getElementPosition( _this.viewer.element );
|
|
|
|
|
|
|
|
window.scrollTo( 0, point.y );
|
|
|
|
|
2012-03-20 03:03:58 +04:00
|
|
|
_this.viewer.setControlsEnabled( true );
|
|
|
|
(function( style ){
|
2012-03-21 05:58:23 +04:00
|
|
|
style.border = '2px solid #437AB2';
|
2012-03-20 03:03:58 +04:00
|
|
|
style.outline = '2px auto #437AB2';
|
|
|
|
}( this.element.style ));
|
|
|
|
|
|
|
|
},
|
|
|
|
blurHandler: function(){
|
|
|
|
_this.viewer.setControlsEnabled( false );
|
|
|
|
(function( style ){
|
2012-03-21 05:58:23 +04:00
|
|
|
style.border = '2px solid #900';
|
2012-03-20 03:03:58 +04:00
|
|
|
style.outline = '2px auto #900';
|
|
|
|
}( this.element.style ));
|
|
|
|
},
|
2012-03-21 05:58:23 +04:00
|
|
|
keyHandler: function(tracker, keyCode, shiftKey){
|
2012-03-20 03:03:58 +04:00
|
|
|
//console.log( keyCode );
|
|
|
|
switch( keyCode ){
|
2012-03-21 05:58:23 +04:00
|
|
|
case 61://=|+
|
|
|
|
_this.viewer.viewport.zoomBy(1.1);
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-21 05:58:23 +04:00
|
|
|
return false;
|
|
|
|
case 45://-|_
|
|
|
|
_this.viewer.viewport.zoomBy(0.9);
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-21 05:58:23 +04:00
|
|
|
return false;
|
|
|
|
case 48://0|)
|
|
|
|
_this.viewer.viewport.goHome();
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-21 05:58:23 +04:00
|
|
|
return false;
|
2012-03-20 03:03:58 +04:00
|
|
|
case 119://w
|
2012-03-21 05:58:23 +04:00
|
|
|
case 87://W
|
2012-03-20 23:30:29 +04:00
|
|
|
case 38://up arrow
|
2012-03-21 05:58:23 +04:00
|
|
|
shiftKey ?
|
|
|
|
_this.viewer.viewport.zoomBy(1.1):
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(0, -0.05));
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-20 23:30:29 +04:00
|
|
|
return false;
|
2012-03-20 03:03:58 +04:00
|
|
|
case 115://s
|
2012-03-21 05:58:23 +04:00
|
|
|
case 83://S
|
2012-03-20 23:30:29 +04:00
|
|
|
case 40://down arrow
|
2012-03-21 05:58:23 +04:00
|
|
|
shiftKey ?
|
|
|
|
_this.viewer.viewport.zoomBy(0.9):
|
|
|
|
_this.viewer.viewport.panBy(new $.Point(0, 0.05));
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-20 23:30:29 +04:00
|
|
|
return false;
|
2012-03-20 03:03:58 +04:00
|
|
|
case 97://a
|
2012-03-20 23:30:29 +04:00
|
|
|
case 37://left arrow
|
2012-03-20 23:00:25 +04:00
|
|
|
_this.viewer.viewport.panBy(new $.Point(-0.05, 0));
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-20 23:30:29 +04:00
|
|
|
return false;
|
2012-03-20 03:03:58 +04:00
|
|
|
case 100://d
|
2012-03-20 23:30:29 +04:00
|
|
|
case 39://right arrow
|
2012-03-20 23:00:25 +04:00
|
|
|
_this.viewer.viewport.panBy(new $.Point(0.05, 0));
|
2012-04-03 11:08:27 +04:00
|
|
|
_this.viewer.viewport.applyConstraints();
|
2012-03-20 23:30:29 +04:00
|
|
|
return false;
|
2012-03-20 03:03:58 +04:00
|
|
|
default:
|
|
|
|
//console.log( 'navigator keycode %s', keyCode );
|
2012-03-20 23:30:29 +04:00
|
|
|
return true;
|
2012-03-20 03:03:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).setTracking( true ); // default state
|
|
|
|
|
|
|
|
/*this.displayRegion.outerTracker = new $.MouseTracker({
|
|
|
|
element: this.container,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
enterHandler: $.delegate( this, onContainerEnter ),
|
|
|
|
exitHandler: $.delegate( this, onContainerExit ),
|
|
|
|
releaseHandler: $.delegate( this, onContainerRelease )
|
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // always tracking*/
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
this.element.appendChild( this.displayRegion );
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer.addControl(
|
|
|
|
this.element,
|
|
|
|
$.ControlAnchor.TOP_RIGHT
|
|
|
|
);
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
if( options.width && options.height ){
|
|
|
|
this.element.style.width = options.width + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
this.element.style.height = options.height + 'px';
|
|
|
|
} else {
|
2012-03-20 03:03:58 +04:00
|
|
|
this.element.style.width = ( viewerSize.x * options.navigatorSizeRatio ) + 'px';
|
|
|
|
this.element.style.height = ( viewerSize.y * options.navigatorSizeRatio ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
}
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
$.Viewer.apply( this, [ options ] );
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
|
|
|
|
|
|
|
|
update: function( viewport ){
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
var bounds,
|
|
|
|
topleft,
|
|
|
|
bottomright;
|
|
|
|
|
|
|
|
if( viewport && this.viewport ){
|
|
|
|
bounds = viewport.getBounds( true );
|
|
|
|
topleft = this.viewport.pixelFromPoint( bounds.getTopLeft() );
|
2012-03-07 07:20:00 +04:00
|
|
|
bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight() );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//update style for navigator-box
|
|
|
|
(function(style){
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
style.top = topleft.y + 'px';
|
|
|
|
style.left = topleft.x + 'px';
|
|
|
|
style.width = ( Math.abs( topleft.x - bottomright.x ) - 3 ) + 'px';
|
|
|
|
style.height = ( Math.abs( topleft.y - bottomright.y ) - 3 ) + 'px';
|
2012-03-07 07:20:00 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
}( this.displayRegion.style ));
|
|
|
|
}
|
2012-03-07 07:20:00 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
function onCanvasClick( tracker, position, quick, shift ) {
|
|
|
|
this.displayRegion.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function onCanvasDrag( tracker, position, delta, shift ) {
|
|
|
|
if ( this.viewer.viewport ) {
|
|
|
|
if( !this.panHorizontal ){
|
|
|
|
delta.x = 0;
|
|
|
|
}
|
|
|
|
if( !this.panVertical ){
|
|
|
|
delta.y = 0;
|
|
|
|
}
|
|
|
|
this.viewer.viewport.panBy(
|
|
|
|
this.viewport.deltaPointsFromPixels(
|
|
|
|
delta
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( insideElementPress && this.viewer.viewport ) {
|
|
|
|
this.viewer.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onCanvasScroll( tracker, position, scroll, shift ) {
|
|
|
|
var factor;
|
|
|
|
if ( this.viewer.viewport ) {
|
|
|
|
factor = Math.pow( this.zoomPerScroll, scroll );
|
|
|
|
this.viewer.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
//this.viewport.pointFromPixel( position, true )
|
|
|
|
this.viewport.getCenter()
|
|
|
|
);
|
|
|
|
this.viewer.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
//cancels event
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-07 07:20:00 +04:00
|
|
|
}( OpenSeadragon ));
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
//TODO: I guess this is where the i18n needs to be reimplemented. I'll look
|
|
|
|
// into existing patterns for i18n in javascript but i think that mimicking
|
|
|
|
// pythons gettext might be a reasonable approach.
|
2012-01-24 07:48:45 +04:00
|
|
|
var I18N = {
|
2011-12-06 07:50:25 +04:00
|
|
|
Errors: {
|
2012-04-03 11:08:27 +04:00
|
|
|
Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" +
|
|
|
|
"Please try using IE 7 or Firefox 3.\n",
|
|
|
|
Dzc: "Sorry, we don't support Deep Zoom Collections!",
|
|
|
|
Dzi: "Hmm, this doesn't appear to be a valid Deep Zoom Image.",
|
|
|
|
Xml: "Hmm, this doesn't appear to be a valid Deep Zoom Image.",
|
|
|
|
Empty: "You asked us to open nothing, so we did just that.",
|
|
|
|
ImageFormat: "Sorry, we don't support {0}-based Deep Zoom Images.",
|
|
|
|
Security: "It looks like a security restriction stopped us from " +
|
|
|
|
"loading this Deep Zoom Image.",
|
|
|
|
Status: "This space unintentionally left blank ({0} {1}).",
|
|
|
|
Unknown: "Whoops, something inexplicably went wrong. Sorry!"
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
Messages: {
|
2012-04-03 11:08:27 +04:00
|
|
|
Loading: "Loading..."
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
Tooltips: {
|
2012-04-03 11:08:27 +04:00
|
|
|
FullPage: "Toggle full page",
|
|
|
|
Home: "Go home",
|
|
|
|
ZoomIn: "Zoom in",
|
|
|
|
ZoomOut: "Zoom out",
|
|
|
|
NextPage: "Next page",
|
|
|
|
PreviousPage: "Previous page"
|
2012-01-24 07:48:45 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.getString
|
|
|
|
* @param {String} property
|
|
|
|
*/
|
2012-01-12 03:22:13 +04:00
|
|
|
getString: function( prop ) {
|
|
|
|
|
|
|
|
var props = prop.split('.'),
|
2012-04-03 11:08:27 +04:00
|
|
|
string = null,
|
2012-01-12 03:22:13 +04:00
|
|
|
args = arguments,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = 0; i < props.length; i++ ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
// in case not a subproperty
|
|
|
|
string = I18N[ props[ i ] ] || {};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( typeof( string ) != "string" ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
string = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return string.replace(/\{\d+\}/g, function(capture) {
|
2012-01-12 03:22:13 +04:00
|
|
|
var i = parseInt( capture.match( /\d+/ ) ) + 1;
|
|
|
|
return i < args.length ?
|
|
|
|
args[ i ] :
|
|
|
|
"";
|
2011-12-06 07:50:25 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.setString
|
|
|
|
* @param {String} property
|
|
|
|
* @param {*} value
|
|
|
|
*/
|
2012-01-12 03:22:13 +04:00
|
|
|
setString: function( prop, value ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
var props = prop.split('.'),
|
|
|
|
container = $.Strings,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = 0; i < props.length - 1; i++ ) {
|
|
|
|
if ( !container[ props[ i ] ] ) {
|
|
|
|
container[ props[ i ] ] = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-12 03:22:13 +04:00
|
|
|
container = container[ props[ i ] ];
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
container[ props[ i ] ] = value;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* A Point is really used as a 2-dimensional vector, equally useful for
|
|
|
|
* representing a point on a plane, or the height and width of a plane
|
|
|
|
* not requiring any other frame of reference.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} [x] The vector component 'x'. Defaults to the origin at 0.
|
|
|
|
* @param {Number} [y] The vector component 'y'. Defaults to the origin at 0.
|
|
|
|
* @property {Number} [x] The vector component 'x'.
|
|
|
|
* @property {Number} [y] The vector component 'y'.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.Point = function( x, y ) {
|
|
|
|
this.x = typeof ( x ) == "number" ? x : 0;
|
|
|
|
this.y = typeof ( y ) == "number" ? y : 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Point.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
plus: function( point ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x + point.x,
|
|
|
|
this.y + point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
minus: function( point ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x - point.x,
|
|
|
|
this.y - point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
times: function( factor ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x * factor,
|
|
|
|
this.y * factor
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
divide: function( factor ) {
|
|
|
|
return new $.Point(
|
|
|
|
this.x / factor,
|
|
|
|
this.y / factor
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
negate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
return new $.Point( -this.x, -this.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
distanceTo: function( point ) {
|
|
|
|
return Math.sqrt(
|
|
|
|
Math.pow( this.x - point.x, 2 ) +
|
|
|
|
Math.pow( this.y - point.y, 2 )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
apply: function( func ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( func( this.x ), func( this.y ) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
equals: function( point ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
return (
|
|
|
|
point instanceof $.Point
|
|
|
|
) && (
|
|
|
|
this.x === point.x
|
|
|
|
) && (
|
|
|
|
this.y === point.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Add another Point to this point and return a new Point.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} point The point to add vector components.
|
|
|
|
* @returns {OpenSeadragon.Point} A new point representing the sum of the
|
|
|
|
* vector components
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
toString: function() {
|
|
|
|
return "(" + this.x + "," + this.y + ")";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} width
|
|
|
|
* @param {Number} height
|
|
|
|
* @param {Number} tileSize
|
|
|
|
* @param {Number} tileOverlap
|
|
|
|
* @param {Number} minLevel
|
|
|
|
* @param {Number} maxLevel
|
|
|
|
* @property {Number} aspectRatio
|
|
|
|
* @property {Number} dimensions
|
|
|
|
* @property {Number} tileSize
|
|
|
|
* @property {Number} tileOverlap
|
|
|
|
* @property {Number} minLevel
|
|
|
|
* @property {Number} maxLevel
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.aspectRatio = width / height;
|
2012-01-24 07:48:45 +04:00
|
|
|
this.dimensions = new $.Point( width, height );
|
|
|
|
this.tileSize = tileSize ? tileSize : 0;
|
|
|
|
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
|
|
|
this.minLevel = minLevel ? minLevel : 0;
|
|
|
|
this.maxLevel = maxLevel ? maxLevel :
|
2012-01-18 03:30:41 +04:00
|
|
|
Math.ceil(
|
|
|
|
Math.log( Math.max( width, height ) ) /
|
|
|
|
Math.log( 2 )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.TileSource.prototype = {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getLevelScale: function( level ) {
|
|
|
|
return 1 / ( 1 << ( this.maxLevel - level ) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getNumTiles: function( level ) {
|
|
|
|
var scale = this.getLevelScale( level ),
|
|
|
|
x = Math.ceil( scale * this.dimensions.x / this.tileSize ),
|
|
|
|
y = Math.ceil( scale * this.dimensions.y / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( x, y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getPixelRatio: function( level ) {
|
|
|
|
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
rx = 1.0 / imageSizeScaled.x,
|
|
|
|
ry = 1.0 / imageSizeScaled.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
return new $.Point(rx, ry);
|
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileAtPoint: function( level, point ) {
|
|
|
|
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level ) ),
|
|
|
|
tx = Math.floor( pixel.x / this.tileSize ),
|
|
|
|
ty = Math.floor( pixel.y / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Point( tx, ty );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileBounds: function( level, x, y ) {
|
|
|
|
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
px = ( x === 0 ) ? 0 : this.tileSize * x - this.tileOverlap,
|
|
|
|
py = ( y === 0 ) ? 0 : this.tileSize * y - this.tileOverlap,
|
|
|
|
sx = this.tileSize + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
|
|
|
sy = this.tileSize + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
|
|
|
scale = 1.0 / dimensionsScaled.x;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
sx = Math.min( sx, dimensionsScaled.x - px );
|
|
|
|
sy = Math.min( sy, dimensionsScaled.y - py );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* This method is not implemented by this class other than to throw an Error
|
|
|
|
* announcing you have to implement it. Because of the variety of tile
|
|
|
|
* server technologies, and various specifications for building image
|
|
|
|
* pyramids, this method is here to allow easy integration.
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
getTileUrl: function( level, x, y ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
throw new Error( "Method not implemented." );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2011-12-14 02:40:52 +04:00
|
|
|
tileExists: function( level, x, y ) {
|
|
|
|
var numTiles = this.getNumTiles( level );
|
|
|
|
return level >= this.minLevel &&
|
|
|
|
level <= this.maxLevel &&
|
|
|
|
x >= 0 &&
|
|
|
|
y >= 0 &&
|
|
|
|
x < numTiles.x &&
|
|
|
|
y < numTiles.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @extends OpenSeadragon.TileSource
|
|
|
|
* @param {Number} width
|
|
|
|
* @param {Number} height
|
|
|
|
* @param {Number} tileSize
|
|
|
|
* @param {Number} tileOverlap
|
|
|
|
* @param {String} tilesUrl
|
|
|
|
* @param {String} fileFormat
|
|
|
|
* @param {OpenSeadragon.DisplayRect[]} displayRects
|
|
|
|
* @property {String} tilesUrl
|
|
|
|
* @property {String} fileFormat
|
|
|
|
* @property {OpenSeadragon.DisplayRect[]} displayRects
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) {
|
|
|
|
var i,
|
|
|
|
rect,
|
|
|
|
level;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
$.TileSource.call( this, width, height, tileSize, tileOverlap, null, null );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
this._levelRects = {};
|
|
|
|
this.tilesUrl = tilesUrl;
|
|
|
|
this.fileFormat = fileFormat;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.displayRects = displayRects;
|
2011-12-14 03:34:12 +04:00
|
|
|
|
|
|
|
if ( this.displayRects ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
for ( i = this.displayRects.length - 1; i >= 0; i-- ) {
|
|
|
|
rect = this.displayRects[ i ];
|
|
|
|
for ( level = rect.minLevel; level <= rect.maxLevel; level++ ) {
|
|
|
|
if ( !this._levelRects[ level ] ) {
|
|
|
|
this._levelRects[ level ] = [];
|
2011-12-14 03:29:25 +04:00
|
|
|
}
|
2012-01-24 07:48:45 +04:00
|
|
|
this._levelRects[ level ].push( rect );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-14 03:34:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.DziTileSource.prototype.getTileUrl
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
getTileUrl: function( level, x, y ) {
|
|
|
|
return [ this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat ].join( '' );
|
2011-12-14 03:29:25 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.DziTileSource.prototype.tileExists
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
tileExists: function( level, x, y ) {
|
|
|
|
var rects = this._levelRects[ level ],
|
|
|
|
rect,
|
|
|
|
scale,
|
|
|
|
xMin,
|
|
|
|
yMin,
|
|
|
|
xMax,
|
|
|
|
yMax,
|
|
|
|
i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( !rects || !rects.length ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
for ( i = rects.length - 1; i >= 0; i-- ) {
|
|
|
|
rect = rects[ i ];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( level < rect.minLevel || level > rect.maxLevel ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
scale = this.getLevelScale( level );
|
|
|
|
xMin = rect.x * scale;
|
|
|
|
yMin = rect.y * scale;
|
|
|
|
xMax = xMin + rect.width * scale;
|
|
|
|
yMax = yMin + rect.height * scale;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
xMin = Math.floor( xMin / this.tileSize );
|
|
|
|
yMin = Math.floor( yMin / this.tileSize );
|
|
|
|
xMax = Math.ceil( xMax / this.tileSize );
|
|
|
|
yMax = Math.ceil( yMax / this.tileSize );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( xMin <= x && x < xMax && yMin <= y && y < yMax ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-23 08:02:54 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The LegacyTileSource allows simple, traditional image pyramids to be loaded
|
|
|
|
* into an OpenSeadragon Viewer. Basically, this translates to the historically
|
|
|
|
* common practice of starting with a 'master' image, maybe a tiff for example,
|
|
|
|
* and generating a set of 'service' images like one or more thumbnails, a medium
|
|
|
|
* resolution image and a high resolution image in standard web formats like
|
|
|
|
* png or jpg.
|
|
|
|
* @class
|
|
|
|
* @param {Array} files An array of file descriptions, each is an object with
|
|
|
|
* a 'url', a 'width', and a 'height'. Overriding classes can expect more
|
|
|
|
* properties but these properties are sufficient for this implementation.
|
|
|
|
* Additionally, the files are required to be listed in order from
|
|
|
|
* smallest to largest.
|
|
|
|
* @property {Number} aspectRatio
|
|
|
|
* @property {Number} dimensions
|
|
|
|
* @property {Number} tileSize
|
|
|
|
* @property {Number} tileOverlap
|
|
|
|
* @property {Number} minLevel
|
|
|
|
* @property {Number} maxLevel
|
|
|
|
* @property {Array} files
|
|
|
|
*/
|
2012-02-27 15:56:29 +04:00
|
|
|
$.LegacyTileSource = function( files ) {
|
2012-02-23 08:02:54 +04:00
|
|
|
var width = files[ files.length - 1 ].width,
|
|
|
|
height = files[ files.length - 1 ].height;
|
|
|
|
|
|
|
|
$.TileSource.apply( this, [
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
Math.max( height, width ), //tileSize
|
|
|
|
0, //overlap
|
|
|
|
0, //mimLevel
|
|
|
|
files.length - 1 //maxLevel
|
|
|
|
] );
|
|
|
|
|
|
|
|
this.files = files;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.LegacyTileSource.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getLevelScale: function( level ) {
|
|
|
|
var levelScale = NaN;
|
|
|
|
if ( level >= this.minLevel && level <= this.maxLevel ){
|
|
|
|
levelScale =
|
2012-04-03 11:08:27 +04:00
|
|
|
this.files[ level ].width /
|
|
|
|
this.files[ this.maxLevel ].width;
|
2012-02-23 08:02:54 +04:00
|
|
|
}
|
|
|
|
return levelScale;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getNumTiles: function( level ) {
|
|
|
|
var scale = this.getLevelScale( level );
|
|
|
|
if ( scale ){
|
|
|
|
return new $.Point( 1, 1 );
|
|
|
|
} else {
|
|
|
|
return new $.Point( 0, 0 );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getPixelRatio: function( level ) {
|
|
|
|
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
rx = 1.0 / imageSizeScaled.x,
|
|
|
|
ry = 1.0 / imageSizeScaled.y;
|
|
|
|
|
|
|
|
return new $.Point(rx, ry);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
*/
|
|
|
|
getTileAtPoint: function( level, point ) {
|
|
|
|
return new $.Point( 0, 0 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
|
|
|
getTileBounds: function( level, x, y ) {
|
|
|
|
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
|
|
|
px = ( x === 0 ) ? 0 : this.files[ level ].width,
|
|
|
|
py = ( y === 0 ) ? 0 : this.files[ level ].height,
|
|
|
|
sx = this.files[ level ].width,
|
|
|
|
sy = this.files[ level ].height,
|
2012-04-03 11:08:27 +04:00
|
|
|
scale = 1.0 / ( this.width >= this.height ?
|
|
|
|
dimensionsScaled.y :
|
|
|
|
dimensionsScaled.x
|
2012-02-23 08:02:54 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
sx = Math.min( sx, dimensionsScaled.x - px );
|
|
|
|
sy = Math.min( sy, dimensionsScaled.y - py );
|
|
|
|
|
|
|
|
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is not implemented by this class other than to throw an Error
|
|
|
|
* announcing you have to implement it. Because of the variety of tile
|
|
|
|
* server technologies, and various specifications for building image
|
|
|
|
* pyramids, this method is here to allow easy integration.
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
getTileUrl: function( level, x, y ) {
|
|
|
|
var url = null;
|
|
|
|
if( level >= this.minLevel && level <= this.maxLevel ){
|
|
|
|
url = this.files[ level ].url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
|
|
|
tileExists: function( level, x, y ) {
|
|
|
|
var numTiles = this.getNumTiles( level );
|
|
|
|
return level >= this.minLevel &&
|
|
|
|
level <= this.maxLevel &&
|
|
|
|
x >= 0 &&
|
|
|
|
y >= 0 &&
|
|
|
|
x < numTiles.x &&
|
|
|
|
y < numTiles.y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* An enumeration of button states including, REST, GROUP, HOVER, and DOWN
|
|
|
|
* @static
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
$.ButtonState = {
|
|
|
|
REST: 0,
|
|
|
|
GROUP: 1,
|
|
|
|
HOVER: 2,
|
|
|
|
DOWN: 3
|
|
|
|
};
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Manages events, hover states for individual buttons, tool-tips, as well
|
|
|
|
* as fading the bottons out when the user has not interacted with them
|
|
|
|
* for a specified period.
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @extends OpenSeadragon.EventHandler
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {Object} options
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {String} options.tooltip Provides context help for the button we the
|
|
|
|
* user hovers over it.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {String} options.srcRest URL of image to use in 'rest' state
|
|
|
|
* @param {String} options.srcGroup URL of image to use in 'up' state
|
|
|
|
* @param {String} options.srcHover URL of image to use in 'hover' state
|
|
|
|
* @param {String} options.srcDown URL of image to use in 'domn' state
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Element} [options.element] Element to use as a container for the
|
|
|
|
* button.
|
|
|
|
* @property {String} tooltip Provides context help for the button we the
|
|
|
|
* user hovers over it.
|
|
|
|
* @property {String} srcRest URL of image to use in 'rest' state
|
|
|
|
* @property {String} srcGroup URL of image to use in 'up' state
|
|
|
|
* @property {String} srcHover URL of image to use in 'hover' state
|
|
|
|
* @property {String} srcDown URL of image to use in 'domn' state
|
2012-02-28 03:29:00 +04:00
|
|
|
* @property {Object} config Configurable settings for this button. DEPRECATED.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {Element} [element] Element to use as a container for the
|
|
|
|
* button.
|
|
|
|
* @property {Number} fadeDelay How long to wait before fading
|
|
|
|
* @property {Number} fadeLength How long should it take to fade the button.
|
|
|
|
* @property {Number} fadeBeginTime When the button last began to fade.
|
|
|
|
* @property {Boolean} shouldFade Whether this button should fade after user
|
|
|
|
* stops interacting with the viewport.
|
|
|
|
this.fadeDelay = 0; // begin fading immediately
|
|
|
|
this.fadeLength = 2000; // fade over a period of 2 seconds
|
|
|
|
this.fadeBeginTime = null;
|
|
|
|
this.shouldFade = false;
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-15 02:40:22 +04:00
|
|
|
$.Button = function( options ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-20 16:39:02 +04:00
|
|
|
var _this = this;
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
$.EventHandler.call( this );
|
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
$.extend( true, this, {
|
|
|
|
|
|
|
|
tooltip: null,
|
|
|
|
srcRest: null,
|
|
|
|
srcGroup: null,
|
|
|
|
srcHover: null,
|
|
|
|
srcDown: null,
|
|
|
|
clickTimeThreshold: $.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold,
|
|
|
|
// begin fading immediately
|
|
|
|
fadeDelay: 0,
|
|
|
|
// fade over a period of 2 seconds
|
|
|
|
fadeLength: 2000,
|
|
|
|
onPress: null,
|
|
|
|
onRelease: null,
|
|
|
|
onClick: null,
|
|
|
|
onEnter: null,
|
2012-03-16 19:36:28 +04:00
|
|
|
onExit: null,
|
|
|
|
onFocus: null,
|
|
|
|
onBlur: null
|
2012-02-28 03:29:00 +04:00
|
|
|
|
|
|
|
}, options );
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2011-12-17 02:56:38 +04:00
|
|
|
//TODO: make button elements accessible by making them a-tags
|
|
|
|
// maybe even consider basing them on the element and adding
|
|
|
|
// methods jquery-style.
|
2012-03-16 19:36:28 +04:00
|
|
|
this.element = options.element || $.makeNeutralElement( "button" );
|
2012-02-28 03:29:00 +04:00
|
|
|
this.element.href = '#';
|
2011-12-15 03:22:02 +04:00
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
this.addHandler( "onPress", this.onPress );
|
|
|
|
this.addHandler( "onRelease", this.onRelease );
|
|
|
|
this.addHandler( "onClick", this.onClick );
|
|
|
|
this.addHandler( "onEnter", this.onEnter );
|
|
|
|
this.addHandler( "onExit", this.onExit );
|
2012-03-16 19:36:28 +04:00
|
|
|
this.addHandler( "onFocus", this.onFocus );
|
|
|
|
this.addHandler( "onBlur", this.onBlur );
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.currentState = $.ButtonState.GROUP;
|
2012-02-28 03:29:00 +04:00
|
|
|
this.imgRest = $.makeTransparentImage( this.srcRest );
|
|
|
|
this.imgGroup = $.makeTransparentImage( this.srcGroup );
|
|
|
|
this.imgHover = $.makeTransparentImage( this.srcHover );
|
|
|
|
this.imgDown = $.makeTransparentImage( this.srcDown );
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.fadeBeginTime = null;
|
|
|
|
this.shouldFade = false;
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.element.style.display = "inline-block";
|
2011-12-17 02:56:38 +04:00
|
|
|
this.element.style.position = "relative";
|
2011-12-17 03:29:16 +04:00
|
|
|
this.element.title = this.tooltip;
|
|
|
|
|
|
|
|
this.element.appendChild( this.imgRest );
|
|
|
|
this.element.appendChild( this.imgGroup );
|
|
|
|
this.element.appendChild( this.imgHover );
|
|
|
|
this.element.appendChild( this.imgDown );
|
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
this.imgGroup.style.position =
|
|
|
|
this.imgHover.style.position =
|
|
|
|
this.imgDown.style.position =
|
|
|
|
"absolute";
|
|
|
|
|
|
|
|
this.imgGroup.style.top =
|
|
|
|
this.imgHover.style.top =
|
|
|
|
this.imgDown.style.top =
|
|
|
|
"0px";
|
|
|
|
|
|
|
|
this.imgGroup.style.left =
|
|
|
|
this.imgHover.style.left =
|
|
|
|
this.imgDown.style.left =
|
|
|
|
"0px";
|
|
|
|
|
|
|
|
this.imgHover.style.visibility =
|
|
|
|
this.imgDown.style.visibility =
|
|
|
|
"hidden";
|
|
|
|
|
|
|
|
if ( $.Browser.vendor == $.BROWSERS.FIREFOX && $.Browser.version < 3 ){
|
|
|
|
this.imgGroup.style.top =
|
|
|
|
this.imgHover.style.top =
|
|
|
|
this.imgDown.style.top =
|
|
|
|
"";
|
2011-12-15 02:40:22 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
this.tracker = new $.MouseTracker({
|
|
|
|
|
|
|
|
element: this.element,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
enterHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
|
|
|
|
if ( buttonDownElement ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
|
|
|
_this.raiseEvent( "onEnter", _this );
|
|
|
|
} else if ( !buttonDownAny ) {
|
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
focusHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
|
|
|
|
this.enterHandler( tracker, position, buttonDownElement, buttonDownAny );
|
|
|
|
_this.raiseEvent( "onFocus", _this );
|
|
|
|
},
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
exitHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
2012-02-01 06:01:37 +04:00
|
|
|
if ( buttonDownElement ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
_this.raiseEvent( "onExit", _this );
|
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
blurHandler: function( tracker, position, buttonDownElement, buttonDownAny ) {
|
|
|
|
this.exitHandler( tracker, position, buttonDownElement, buttonDownAny );
|
|
|
|
_this.raiseEvent( "onBlur", _this );
|
|
|
|
},
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
pressHandler: function( tracker, position ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
2011-12-20 16:44:33 +04:00
|
|
|
_this.raiseEvent( "onPress", _this );
|
2011-12-20 16:39:02 +04:00
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( insideElementPress && insideElementRelease ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.HOVER );
|
2011-12-20 16:44:33 +04:00
|
|
|
_this.raiseEvent( "onRelease", _this );
|
2012-02-01 06:01:37 +04:00
|
|
|
} else if ( insideElementPress ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
|
|
|
} else {
|
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
clickHandler: function( tracker, position, quick, shift ) {
|
2011-12-20 16:39:02 +04:00
|
|
|
if ( quick ) {
|
|
|
|
_this.raiseEvent("onClick", _this);
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
keyHandler: function( tracker, key ){
|
2012-03-20 23:30:29 +04:00
|
|
|
//console.log( "%s : handling key %s!", _this.tooltip, key);
|
|
|
|
if( 13 === key ){
|
|
|
|
_this.raiseEvent( "onClick", _this );
|
|
|
|
_this.raiseEvent( "onRelease", _this );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-12-20 16:39:02 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
}).setTracking( true );
|
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
outTo( this, $.ButtonState.REST );
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Determine what this function is intended to do and if it's actually
|
|
|
|
* useful as an API point.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Button.prototype.notifyGroupEnter
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
notifyGroupEnter: function() {
|
2011-12-17 03:29:16 +04:00
|
|
|
inTo( this, $.ButtonState.GROUP );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Determine what this function is intended to do and if it's actually
|
|
|
|
* useful as an API point.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Button.prototype.notifyGroupExit
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
notifyGroupExit: function() {
|
2011-12-17 03:29:16 +04:00
|
|
|
outTo( this, $.ButtonState.REST );
|
2012-04-03 11:08:27 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
disable: function(){
|
|
|
|
this.notifyGroupExit();
|
|
|
|
this.element.disabled = true;
|
|
|
|
$.setElementOpacity( this.element, 0.2, true );
|
|
|
|
},
|
|
|
|
|
|
|
|
enable: function(){
|
|
|
|
this.element.disabled = false;
|
|
|
|
$.setElementOpacity( this.element, 1.0, true );
|
|
|
|
this.notifyGroupEnter();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
function scheduleFade( button ) {
|
|
|
|
window.setTimeout(function(){
|
|
|
|
updateFade( button );
|
|
|
|
}, 20 );
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateFade( button ) {
|
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
opacity;
|
|
|
|
|
|
|
|
if ( button.shouldFade ) {
|
|
|
|
currentTime = +new Date();
|
2012-02-28 17:07:56 +04:00
|
|
|
deltaTime = currentTime - button.fadeBeginTime;
|
|
|
|
opacity = 1.0 - deltaTime / button.fadeLength;
|
2011-12-17 03:29:16 +04:00
|
|
|
opacity = Math.min( 1.0, opacity );
|
|
|
|
opacity = Math.max( 0.0, opacity );
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.setElementOpacity( button.imgGroup, opacity, true );
|
2011-12-17 03:29:16 +04:00
|
|
|
if ( opacity > 0 ) {
|
|
|
|
// fade again
|
|
|
|
scheduleFade( button );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function beginFading( button ) {
|
|
|
|
button.shouldFade = true;
|
2012-02-28 17:07:56 +04:00
|
|
|
button.fadeBeginTime = +new Date() + button.fadeDelay;
|
2012-01-24 07:48:45 +04:00
|
|
|
window.setTimeout( function(){
|
2011-12-17 03:29:16 +04:00
|
|
|
scheduleFade( button );
|
|
|
|
}, button.fadeDelay );
|
|
|
|
};
|
|
|
|
|
|
|
|
function stopFading( button ) {
|
|
|
|
button.shouldFade = false;
|
2012-01-18 03:30:41 +04:00
|
|
|
$.setElementOpacity( button.imgGroup, 1.0, true );
|
2011-12-17 03:29:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function inTo( button, newState ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( button.element.disabled ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( newState >= $.ButtonState.GROUP &&
|
|
|
|
button.currentState == $.ButtonState.REST ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
stopFading( button );
|
|
|
|
button.currentState = $.ButtonState.GROUP;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( newState >= $.ButtonState.HOVER &&
|
|
|
|
button.currentState == $.ButtonState.GROUP ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
button.imgHover.style.visibility = "";
|
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( newState >= $.ButtonState.DOWN &&
|
|
|
|
button.currentState == $.ButtonState.HOVER ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
button.imgDown.style.visibility = "";
|
|
|
|
button.currentState = $.ButtonState.DOWN;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function outTo( button, newState ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if( button.element.disabled ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( newState <= $.ButtonState.HOVER &&
|
|
|
|
button.currentState == $.ButtonState.DOWN ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
button.imgDown.style.visibility = "hidden";
|
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( newState <= $.ButtonState.GROUP &&
|
|
|
|
button.currentState == $.ButtonState.HOVER ) {
|
2011-12-20 16:44:33 +04:00
|
|
|
button.imgHover.style.visibility = "hidden";
|
|
|
|
button.currentState = $.ButtonState.GROUP;
|
2011-12-17 03:29:16 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
if ( newState <= $.ButtonState.REST &&
|
2012-01-24 07:48:45 +04:00
|
|
|
button.currentState == $.ButtonState.GROUP ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
beginFading( button );
|
2011-12-17 03:29:16 +04:00
|
|
|
button.currentState = $.ButtonState.REST;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
2011-12-06 23:48:20 +04:00
|
|
|
/**
|
|
|
|
* Manages events on groups of buttons.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @class
|
|
|
|
* @param {Object} options - a dictionary of settings applied against the entire
|
|
|
|
* group of buttons
|
|
|
|
* @param {Array} options.buttons Array of buttons
|
|
|
|
* @param {Element} [options.group] Element to use as the container,
|
|
|
|
* @param {Object} options.config Object with Viewer settings ( TODO: is
|
|
|
|
* this actually used anywhere? )
|
|
|
|
* @param {Function} [options.enter] Function callback for when the mouse
|
|
|
|
* enters group
|
|
|
|
* @param {Function} [options.exit] Function callback for when mouse leaves
|
|
|
|
* the group
|
|
|
|
* @param {Function} [options.release] Function callback for when mouse is
|
|
|
|
* released
|
|
|
|
* @property {Array} buttons - An array containing the buttons themselves.
|
|
|
|
* @property {Element} element - The shared container for the buttons.
|
|
|
|
* @property {Object} config - Configurable settings for the group of buttons.
|
|
|
|
* @property {OpenSeadragon.MouseTracker} tracker - Tracks mouse events accross
|
|
|
|
* the group of buttons.
|
2011-12-06 23:48:20 +04:00
|
|
|
**/
|
|
|
|
$.ButtonGroup = function( options ) {
|
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
$.extend( true, this, {
|
2012-03-09 20:04:28 +04:00
|
|
|
buttons: [],
|
2012-02-28 17:07:56 +04:00
|
|
|
clickTimeThreshold: $.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: $.DEFAULT_SETTINGS.clickDistThreshold
|
|
|
|
}, options );
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
// copy the botton elements
|
|
|
|
var buttons = this.buttons.concat([]),
|
|
|
|
_this = this,
|
|
|
|
i;
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
this.element = options.group || $.makeNeutralElement( "fieldgroup" );
|
|
|
|
this.label = $.makeNeutralElement( "label" );
|
|
|
|
//TODO: support labels for ButtonGroups
|
|
|
|
//this.label.innerHTML = "test";
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.element.style.display = "inline-block";
|
2012-03-16 19:36:28 +04:00
|
|
|
this.element.appendChild( this.label );
|
2011-12-06 23:48:20 +04:00
|
|
|
for ( i = 0; i < buttons.length; i++ ) {
|
2011-12-17 02:56:38 +04:00
|
|
|
this.element.appendChild( buttons[ i ].element );
|
2011-12-06 23:48:20 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker = new $.MouseTracker({
|
|
|
|
element: this.element,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
enterHandler: function() {
|
|
|
|
var i;
|
2011-12-06 23:48:20 +04:00
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
2012-02-28 17:07:56 +04:00
|
|
|
_this.buttons[ i ].notifyGroupEnter();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
},
|
|
|
|
exitHandler: function() {
|
|
|
|
var i,
|
|
|
|
buttonDownElement = arguments.length > 2 ?
|
|
|
|
arguments[ 2 ] :
|
|
|
|
null;
|
|
|
|
if ( !buttonDownElement ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
releaseHandler: function() {
|
|
|
|
var i,
|
|
|
|
insideElementRelease = arguments.length > 3 ?
|
|
|
|
arguments[ 3 ] :
|
|
|
|
null;
|
|
|
|
if ( !insideElementRelease ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
}).setTracking( true );
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ButtonGroup.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Figure out why this is used on the public API and if a more useful
|
|
|
|
* api can be created.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.ButtonGroup.prototype.emulateEnter
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateEnter: function() {
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker.enterHandler();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* TODO: Figure out why this is used on the public API and if a more useful
|
|
|
|
* api can be created.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.ButtonGroup.prototype.emulateExit
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateExit: function() {
|
2012-02-28 17:07:56 +04:00
|
|
|
this.tracker.exitHandler();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
}( OpenSeadragon ));
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* A Rectangle really represents a 2x2 matrix where each row represents a
|
|
|
|
* 2 dimensional vector component, the first is (x,y) and the second is
|
|
|
|
* (width, height). The latter component implies the equation of a simple
|
|
|
|
* plane.
|
|
|
|
*
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} x The vector component 'x'.
|
|
|
|
* @param {Number} y The vector component 'y'.
|
|
|
|
* @param {Number} width The vector component 'height'.
|
|
|
|
* @param {Number} height The vector component 'width'.
|
|
|
|
* @property {Number} x The vector component 'x'.
|
|
|
|
* @property {Number} y The vector component 'y'.
|
|
|
|
* @property {Number} width The vector component 'width'.
|
|
|
|
* @property {Number} height The vector component 'height'.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-30 03:16:51 +04:00
|
|
|
$.Rect = function( x, y, width, height ) {
|
|
|
|
this.x = typeof ( x ) == "number" ? x : 0;
|
|
|
|
this.y = typeof ( y ) == "number" ? y : 0;
|
|
|
|
this.width = typeof ( width ) == "number" ? width : 0;
|
|
|
|
this.height = typeof ( height ) == "number" ? height : 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Rect.prototype = {
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The aspect ratio is simply the ratio of width to height.
|
|
|
|
* @function
|
|
|
|
* @returns {Number} The ratio of width to height.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getAspectRatio: function() {
|
|
|
|
return this.width / this.height;
|
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Provides the coordinates of the upper-left corner of the rectanglea s a
|
|
|
|
* point.
|
|
|
|
* @function
|
|
|
|
* @returns {OpenSeadragon.Point} The coordinate of the upper-left corner of
|
|
|
|
* the rectangle.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getTopLeft: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point( this.x, this.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Provides the coordinates of the bottom-right corner of the rectangle as a
|
|
|
|
* point.
|
|
|
|
* @function
|
|
|
|
* @returns {OpenSeadragon.Point} The coordinate of the bottom-right corner of
|
|
|
|
* the rectangle.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getBottomRight: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point(
|
|
|
|
this.x + this.width,
|
|
|
|
this.y + this.height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Computes the center of the rectangle.
|
|
|
|
* @function
|
|
|
|
* @returns {OpenSeadragon.Point} The center of the rectangle as represnted
|
|
|
|
* as represented by a 2-dimensional vector (x,y)
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getCenter: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point(
|
|
|
|
this.x + this.width / 2.0,
|
|
|
|
this.y + this.height / 2.0
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Returns the width and height component as a vector OpenSeadragon.Point
|
|
|
|
* @function
|
|
|
|
* @returns {OpenSeadragon.Point} The 2 dimensional vector represnting the
|
|
|
|
* the width and height of the rectangle.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getSize: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return new $.Point( this.width, this.height );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Determines if two Rectanlges have equivalent components.
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Rect} rectangle The Rectangle to compare to.
|
|
|
|
* @return {Boolean} 'true' if all components are equal, otherwise 'false'.
|
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
equals: function( other ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
return ( other instanceof $.Rect ) &&
|
2011-12-30 03:16:51 +04:00
|
|
|
( this.x === other.x ) &&
|
|
|
|
( this.y === other.y ) &&
|
|
|
|
( this.width === other.width ) &&
|
|
|
|
( this.height === other.height );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Provides a string representation of the retangle which is useful for
|
|
|
|
* debugging.
|
|
|
|
* @function
|
|
|
|
* @returns {String} A string representation of the rectangle.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
toString: function() {
|
2011-12-30 03:16:51 +04:00
|
|
|
return "[" +
|
|
|
|
this.x + "," +
|
|
|
|
this.y + "," +
|
|
|
|
this.width + "x" +
|
|
|
|
this.height +
|
|
|
|
"]";
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 00:59:09 +04:00
|
|
|
* A display rectanlge is very similar to the OpenSeadragon.Rect but adds two
|
|
|
|
* fields, 'minLevel' and 'maxLevel' which denote the supported zoom levels
|
|
|
|
* for this rectangle.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @extends OpenSeadragon.Rect
|
|
|
|
* @param {Number} x The vector component 'x'.
|
|
|
|
* @param {Number} y The vector component 'y'.
|
|
|
|
* @param {Number} width The vector component 'height'.
|
|
|
|
* @param {Number} height The vector component 'width'.
|
|
|
|
* @param {Number} minLevel The lowest zoom level supported.
|
|
|
|
* @param {Number} maxLevel The highest zoom level supported.
|
|
|
|
* @property {Number} minLevel The lowest zoom level supported.
|
|
|
|
* @property {Number} maxLevel The highest zoom level supported.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-18 03:30:41 +04:00
|
|
|
$.DisplayRect = function( x, y, width, height, minLevel, maxLevel ) {
|
|
|
|
$.Rect.apply( this, [ x, y, width, height ] );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
this.minLevel = minLevel;
|
|
|
|
this.maxLevel = maxLevel;
|
|
|
|
}
|
2012-01-24 07:48:45 +04:00
|
|
|
|
|
|
|
$.extend( $.DisplayRect.prototype, $.Rect.prototype );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
2012-02-15 23:50:27 +04:00
|
|
|
* @param {Object} options - Spring configuration settings.
|
|
|
|
* @param {Number} options.initial - Initial value of spring, default to 0 so
|
|
|
|
* spring is not in motion initally by default.
|
|
|
|
* @param {Number} options.springStiffness - Spring stiffness.
|
|
|
|
* @param {Number} options.animationTime - Animation duration per spring.
|
|
|
|
*
|
|
|
|
* @property {Number} initial - Initial value of spring, default to 0 so
|
|
|
|
* spring is not in motion initally by default.
|
|
|
|
* @property {Number} springStiffness - Spring stiffness.
|
|
|
|
* @property {Number} animationTime - Animation duration per spring.
|
|
|
|
* @property {Object} current
|
|
|
|
* @property {Number} start
|
|
|
|
* @property {Number} target
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-30 03:16:51 +04:00
|
|
|
$.Spring = function( options ) {
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
if( typeof( options ) != 'object' ){
|
|
|
|
//allows backward compatible use of ( initialValue, config ) as
|
|
|
|
//constructor parameters
|
|
|
|
options = {
|
|
|
|
initial: args.length && typeof ( args[ 0 ] ) == "number" ?
|
|
|
|
args[ 0 ] :
|
|
|
|
0,
|
|
|
|
springStiffness: args.length > 1 ?
|
|
|
|
args[ 1 ].springStiffness :
|
|
|
|
5.0,
|
|
|
|
animationTime: args.length > 1 ?
|
|
|
|
args[ 1 ].animationTime :
|
2012-03-20 23:00:25 +04:00
|
|
|
1.5
|
2011-12-30 03:16:51 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-01-04 02:44:52 +04:00
|
|
|
$.extend( true, this, options);
|
2011-12-30 03:16:51 +04:00
|
|
|
|
|
|
|
|
2012-01-04 02:54:20 +04:00
|
|
|
this.current = {
|
2012-01-05 03:14:20 +04:00
|
|
|
value: typeof ( this.initial ) == "number" ?
|
2012-01-04 02:54:20 +04:00
|
|
|
this.initial :
|
|
|
|
0,
|
|
|
|
time: new Date().getTime() // always work in milliseconds
|
2012-01-05 03:14:20 +04:00
|
|
|
};
|
2012-01-04 02:54:20 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.start = {
|
|
|
|
value: this.current.value,
|
|
|
|
time: this.current.time
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.target = {
|
|
|
|
value: this.current.value,
|
|
|
|
time: this.current.time
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Spring.prototype = {
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} target
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
resetTo: function( target ) {
|
|
|
|
this.target.value = target;
|
|
|
|
this.target.time = this.current.time;
|
|
|
|
this.start.value = this.target.value;
|
|
|
|
this.start.time = this.target.time;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} target
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
springTo: function( target ) {
|
|
|
|
this.start.value = this.current.value;
|
|
|
|
this.start.time = this.current.time;
|
|
|
|
this.target.value = target;
|
|
|
|
this.target.time = this.start.time + 1000 * this.animationTime;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} delta
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
shiftBy: function( delta ) {
|
|
|
|
this.start.value += delta;
|
|
|
|
this.target.value += delta;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
update: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.current.time = new Date().getTime();
|
|
|
|
this.current.value = (this.current.time >= this.target.time) ?
|
|
|
|
this.target.value :
|
|
|
|
this.start.value +
|
|
|
|
( this.target.value - this.start.value ) *
|
2012-01-04 02:44:52 +04:00
|
|
|
transform(
|
|
|
|
this.springStiffness,
|
2012-01-05 03:14:20 +04:00
|
|
|
( this.current.time - this.start.time ) /
|
|
|
|
( this.target.time - this.start.time )
|
2012-01-04 02:44:52 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2011-12-30 03:16:51 +04:00
|
|
|
function transform( stiffness, x ) {
|
|
|
|
return ( 1.0 - Math.exp( stiffness * -x ) ) /
|
|
|
|
( 1.0 - Math.exp( -stiffness ) );
|
|
|
|
};
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Number} level The zoom level this tile belongs to.
|
|
|
|
* @param {Number} x The vector component 'x'.
|
|
|
|
* @param {Number} y The vector component 'y'.
|
|
|
|
* @param {OpenSeadragon.Point} bounds Where this tile fits, in normalized
|
2012-03-01 17:38:15 +04:00
|
|
|
* coordinates.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Boolean} exists Is this tile a part of a sparse image? ( Also has
|
2012-03-01 17:38:15 +04:00
|
|
|
* this tile failed to load? )
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {String} url The URL of this tile's image.
|
|
|
|
*
|
|
|
|
* @property {Number} level The zoom level this tile belongs to.
|
|
|
|
* @property {Number} x The vector component 'x'.
|
|
|
|
* @property {Number} y The vector component 'y'.
|
|
|
|
* @property {OpenSeadragon.Point} bounds Where this tile fits, in normalized
|
2012-03-01 17:38:15 +04:00
|
|
|
* coordinates
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {Boolean} exists Is this tile a part of a sparse image? ( Also has
|
2012-03-01 17:38:15 +04:00
|
|
|
* this tile failed to load?
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {String} url The URL of this tile's image.
|
|
|
|
* @property {Boolean} loaded Is this tile loaded?
|
|
|
|
* @property {Boolean} loading Is this tile loading
|
2012-02-02 01:56:04 +04:00
|
|
|
* @property {Element} element The HTML element for this tile
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {Image} image The Image object for this tile
|
2012-02-02 01:56:04 +04:00
|
|
|
* @property {String} style The alias of this.element.style.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {String} position This tile's position on screen, in pixels.
|
|
|
|
* @property {String} size This tile's size on screen, in pixels
|
|
|
|
* @property {String} blendStart The start time of this tile's blending
|
|
|
|
* @property {String} opacity The current opacity this tile should be.
|
|
|
|
* @property {String} distance The distance of this tile to the viewport center
|
|
|
|
* @property {String} visibility The visibility score of this tile.
|
|
|
|
* @property {Boolean} beingDrawn Whether this tile is currently being drawn
|
|
|
|
* @property {Number} lastTouchTime Timestamp the tile was last touched.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
$.Tile = function(level, x, y, bounds, exists, url) {
|
2012-01-12 03:22:13 +04:00
|
|
|
this.level = level;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2012-02-01 00:59:09 +04:00
|
|
|
this.bounds = bounds;
|
|
|
|
this.exists = exists;
|
|
|
|
this.url = url;
|
|
|
|
this.loaded = false;
|
|
|
|
this.loading = false;
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element = null;
|
2012-04-03 11:08:27 +04:00
|
|
|
this.image = null;
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
this.style = null;
|
|
|
|
this.position = null;
|
|
|
|
this.size = null;
|
|
|
|
this.blendStart = null;
|
|
|
|
this.opacity = null;
|
|
|
|
this.distance = null;
|
|
|
|
this.visibility = null;
|
|
|
|
|
|
|
|
this.beingDrawn = false;
|
|
|
|
this.lastTouchTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Tile.prototype = {
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Provides a string representation of this tiles level and (x,y)
|
|
|
|
* components.
|
|
|
|
* @function
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
toString: function() {
|
|
|
|
return this.level + "/" + this.x + "_" + this.y;
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Renders the tile in an html container.
|
|
|
|
* @function
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
2012-01-12 03:22:13 +04:00
|
|
|
drawHTML: function( container ) {
|
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
var position = this.position.apply( Math.floor ),
|
|
|
|
size = this.size.apply( Math.ceil );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
if ( !this.loaded || !this.image ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
$.console.warn(
|
2012-01-24 07:48:45 +04:00
|
|
|
"Attempting to draw tile %s when it's not yet loaded.",
|
|
|
|
this.toString()
|
2012-01-12 03:22:13 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( !this.element ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
this.element = $.makeNeutralElement("img");
|
|
|
|
this.element.src = this.url;
|
|
|
|
this.style = this.element.style;
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
this.style.position = "absolute";
|
2011-12-06 07:50:25 +04:00
|
|
|
this.style.msInterpolationMode = "nearest-neighbor";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( this.element.parentNode != container ) {
|
|
|
|
container.appendChild( this.element );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element.style.left = position.x + "px";
|
|
|
|
this.element.style.top = position.y + "px";
|
|
|
|
this.element.style.width = size.x + "px";
|
|
|
|
this.element.style.height = size.y + "px";
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
$.setElementOpacity( this.element, this.opacity );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Renders the tile in a canvas-based context.
|
|
|
|
* @function
|
|
|
|
* @param {Canvas} context
|
|
|
|
*/
|
|
|
|
drawCanvas: function( context ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
|
|
|
var position = this.position,
|
|
|
|
size = this.size;
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
if ( !this.loaded || !this.image ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
$.console.warn(
|
2012-01-24 07:48:45 +04:00
|
|
|
"Attempting to draw tile %s when it's not yet loaded.",
|
|
|
|
this.toString()
|
2012-01-12 03:22:13 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
context.globalAlpha = this.opacity;
|
2012-02-01 00:59:09 +04:00
|
|
|
context.drawImage( this.image, position.x, position.y, size.x, size.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* Removes tile from it's contianer.
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
unload: function() {
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( this.element && this.element.parentNode ) {
|
|
|
|
this.element.parentNode.removeChild( this.element );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:56:04 +04:00
|
|
|
this.element = null;
|
2012-01-18 03:30:41 +04:00
|
|
|
this.image = null;
|
|
|
|
this.loaded = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* An enumeration of positions that an overlay may be assigned relative
|
|
|
|
* to the viewport including CENTER, TOP_LEFT (default), TOP, TOP_RIGHT,
|
|
|
|
* RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, and LEFT.
|
|
|
|
* @static
|
|
|
|
*/
|
2011-12-14 02:40:52 +04:00
|
|
|
$.OverlayPlacement = {
|
2012-01-24 07:48:45 +04:00
|
|
|
CENTER: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP: 2,
|
|
|
|
TOP_RIGHT: 3,
|
|
|
|
RIGHT: 4,
|
2011-12-14 02:40:52 +04:00
|
|
|
BOTTOM_RIGHT: 5,
|
2012-01-24 07:48:45 +04:00
|
|
|
BOTTOM: 6,
|
|
|
|
BOTTOM_LEFT: 7,
|
|
|
|
LEFT: 8
|
2011-12-14 02:40:52 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-01 06:01:37 +04:00
|
|
|
* An Overlay provides a
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
|
|
|
*/
|
2012-02-02 01:56:04 +04:00
|
|
|
$.Overlay = function( element, location, placement ) {
|
2012-03-16 19:36:28 +04:00
|
|
|
this.element = element;
|
2011-12-30 02:14:42 +04:00
|
|
|
this.scales = location instanceof $.Rect;
|
|
|
|
this.bounds = new $.Rect(
|
|
|
|
location.x,
|
|
|
|
location.y,
|
|
|
|
location.width,
|
2012-01-24 07:48:45 +04:00
|
|
|
location.height
|
|
|
|
);
|
2011-12-30 02:14:42 +04:00
|
|
|
this.position = new $.Point(
|
|
|
|
location.x,
|
|
|
|
location.y
|
|
|
|
);
|
|
|
|
this.size = new $.Point(
|
|
|
|
location.width,
|
|
|
|
location.height
|
|
|
|
);
|
2012-02-02 01:56:04 +04:00
|
|
|
this.style = element.style;
|
2011-12-14 02:40:52 +04:00
|
|
|
// rects are always top-left
|
2011-12-30 02:14:42 +04:00
|
|
|
this.placement = location instanceof $.Point ?
|
2011-12-14 02:40:52 +04:00
|
|
|
placement :
|
|
|
|
$.OverlayPlacement.TOP_LEFT;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
$.Overlay.prototype = {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.OverlayPlacement} position
|
|
|
|
* @param {OpenSeadragon.Point} size
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
adjust: function( position, size ) {
|
|
|
|
switch ( this.placement ) {
|
2011-12-14 02:40:52 +04:00
|
|
|
case $.OverlayPlacement.TOP_LEFT:
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.TOP:
|
|
|
|
position.x -= size.x / 2;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.TOP_RIGHT:
|
|
|
|
position.x -= size.x;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.RIGHT:
|
|
|
|
position.x -= size.x;
|
|
|
|
position.y -= size.y / 2;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.BOTTOM_RIGHT:
|
|
|
|
position.x -= size.x;
|
|
|
|
position.y -= size.y;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.BOTTOM:
|
|
|
|
position.x -= size.x / 2;
|
|
|
|
position.y -= size.y;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.BOTTOM_LEFT:
|
|
|
|
position.y -= size.y;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.LEFT:
|
|
|
|
position.y -= size.y / 2;
|
|
|
|
break;
|
|
|
|
case $.OverlayPlacement.CENTER:
|
|
|
|
default:
|
|
|
|
position.x -= size.x / 2;
|
|
|
|
position.y -= size.y / 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-14 02:40:52 +04:00
|
|
|
destroy: function() {
|
2012-02-02 01:56:04 +04:00
|
|
|
var element = this.element,
|
2012-01-24 07:48:45 +04:00
|
|
|
style = this.style;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( element.parentNode ) {
|
|
|
|
element.parentNode.removeChild( element );
|
2011-12-14 02:40:52 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
style.top = "";
|
|
|
|
style.left = "";
|
|
|
|
style.position = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( this.scales ) {
|
2011-12-14 02:40:52 +04:00
|
|
|
style.width = "";
|
|
|
|
style.height = "";
|
|
|
|
}
|
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
2011-12-30 02:14:42 +04:00
|
|
|
drawHTML: function( container ) {
|
2012-02-02 01:56:04 +04:00
|
|
|
var element = this.element,
|
2011-12-30 02:14:42 +04:00
|
|
|
style = this.style,
|
|
|
|
scales = this.scales,
|
|
|
|
position,
|
|
|
|
size;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( element.parentNode != container ) {
|
|
|
|
container.appendChild( element );
|
2011-12-14 02:40:52 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if ( !scales ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
this.size = $.getElementSize( element );
|
2011-12-14 02:40:52 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
position = this.position;
|
|
|
|
size = this.size;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.adjust( position, size );
|
2011-12-14 02:40:52 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
position = position.apply( Math.floor );
|
|
|
|
size = size.apply( Math.ceil );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
style.left = position.x + "px";
|
|
|
|
style.top = position.y + "px";
|
2011-12-14 02:40:52 +04:00
|
|
|
style.position = "absolute";
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if ( scales ) {
|
|
|
|
style.width = size.x + "px";
|
2011-12-14 02:40:52 +04:00
|
|
|
style.height = size.y + "px";
|
|
|
|
}
|
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point|OpenSeadragon.Rect} location
|
|
|
|
* @param {OpenSeadragon.OverlayPlacement} position
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
update: function( location, placement ) {
|
|
|
|
this.scales = location instanceof $.Rect;
|
|
|
|
this.bounds = new $.Rect(
|
|
|
|
location.x,
|
|
|
|
location.y,
|
|
|
|
location.width,
|
|
|
|
location.height
|
|
|
|
);
|
2011-12-30 02:14:42 +04:00
|
|
|
// rects are always top-left
|
2012-01-24 07:48:45 +04:00
|
|
|
this.placement = location instanceof $.Point ?
|
|
|
|
placement :
|
|
|
|
$.OverlayPlacement.TOP_LEFT;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
var TIMEOUT = 5000,
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
BROWSER = $.Browser.vendor,
|
|
|
|
BROWSER_VERSION = $.Browser.version,
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
SUBPIXEL_RENDERING = (
|
2012-01-18 03:30:41 +04:00
|
|
|
( BROWSER == $.BROWSERS.FIREFOX ) ||
|
|
|
|
( BROWSER == $.BROWSERS.OPERA ) ||
|
|
|
|
( BROWSER == $.BROWSERS.SAFARI && BROWSER_VERSION >= 4 ) ||
|
|
|
|
( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 )
|
2012-03-01 17:38:15 +04:00
|
|
|
) && ( !navigator.appVersion.match( 'Mobile' ) ),
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
USE_CANVAS = $.isFunction( document.createElement( "canvas" ).getContext ) &&
|
2012-01-12 03:22:13 +04:00
|
|
|
SUBPIXEL_RENDERING;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//console.error( 'USE_CANVAS ' + USE_CANVAS );
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {OpenSeadragon.TileSource} source - Reference to Viewer tile source.
|
|
|
|
* @param {OpenSeadragon.Viewport} viewport - Reference to Viewer viewport.
|
|
|
|
* @param {Element} element - Reference to Viewer 'canvas'.
|
|
|
|
* @property {OpenSeadragon.TileSource} source - Reference to Viewer tile source.
|
|
|
|
* @property {OpenSeadragon.Viewport} viewport - Reference to Viewer viewport.
|
2012-02-01 06:01:37 +04:00
|
|
|
* @property {Element} container - Reference to Viewer 'canvas'.
|
|
|
|
* @property {Element|Canvas} canvas - TODO
|
|
|
|
* @property {CanvasContext} context - TODO
|
2012-02-01 00:59:09 +04:00
|
|
|
* @property {Object} config - Reference to Viewer config.
|
|
|
|
* @property {Number} downloading - How many images are currently being loaded in parallel.
|
|
|
|
* @property {Number} normHeight - Ratio of zoomable image height to width.
|
2012-02-01 06:01:37 +04:00
|
|
|
* @property {Object} tilesMatrix - A '3d' dictionary [level][x][y] --> Tile.
|
|
|
|
* @property {Array} tilesLoaded - An unordered list of Tiles with loaded images.
|
|
|
|
* @property {Object} coverage - A '3d' dictionary [level][x][y] --> Boolean.
|
|
|
|
* @property {Array} overlays - An unordered list of Overlays added.
|
|
|
|
* @property {Array} lastDrawn - An unordered list of Tiles drawn last frame.
|
|
|
|
* @property {Number} lastResetTime - Last time for which the drawer was reset.
|
|
|
|
* @property {Boolean} midUpdate - Is the drawer currently updating the viewport?
|
|
|
|
* @property {Boolean} updateAgain - Does the drawer need to update the viewort again?
|
2012-02-02 01:56:04 +04:00
|
|
|
* @property {Element} element - DEPRECATED Alias for container.
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-03-01 17:38:15 +04:00
|
|
|
$.Drawer = function( options ) {
|
|
|
|
|
|
|
|
//backward compatibility for positional args while prefering more
|
|
|
|
//idiomatic javascript options object as the only argument
|
2012-03-16 19:36:28 +04:00
|
|
|
var args = arguments,
|
|
|
|
i;
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if( !$.isPlainObject( options ) ){
|
|
|
|
options = {
|
|
|
|
source: args[ 0 ],
|
|
|
|
viewport: args[ 1 ],
|
|
|
|
element: args[ 2 ]
|
|
|
|
};
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
$.extend( true, this, {
|
|
|
|
|
|
|
|
//internal state properties
|
|
|
|
downloading: 0,
|
|
|
|
tilesMatrix: {},
|
|
|
|
tilesLoaded: [],
|
|
|
|
coverage: {},
|
|
|
|
lastDrawn: [],
|
|
|
|
lastResetTime: 0,
|
|
|
|
midUpdate: false,
|
|
|
|
updateAgain: true,
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
//internal state / configurable settings
|
|
|
|
overlays: [],
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//configurable settings
|
|
|
|
maxImageCacheCount: $.DEFAULT_SETTINGS.maxImageCacheCount,
|
|
|
|
imageLoaderLimit: $.DEFAULT_SETTINGS.imageLoaderLimit,
|
|
|
|
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
|
|
|
|
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
|
|
|
|
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
|
|
|
|
immediateRender: $.DEFAULT_SETTINGS.immediateRender,
|
|
|
|
blendTime: $.DEFAULT_SETTINGS.blendTime,
|
|
|
|
alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend,
|
|
|
|
minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio
|
|
|
|
|
|
|
|
}, options );
|
|
|
|
|
|
|
|
this.container = $.getElement( this.element );
|
2012-02-01 00:59:09 +04:00
|
|
|
this.canvas = $.makeNeutralElement( USE_CANVAS ? "canvas" : "div" );
|
|
|
|
this.context = USE_CANVAS ? this.canvas.getContext( "2d" ) : null;
|
2012-03-01 17:38:15 +04:00
|
|
|
this.normHeight = this.source.dimensions.y / this.source.dimensions.x;
|
|
|
|
this.element = this.container;
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
this.canvas.style.width = "100%";
|
|
|
|
this.canvas.style.height = "100%";
|
|
|
|
this.canvas.style.position = "absolute";
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
// explicit left-align
|
|
|
|
this.container.style.textAlign = "left";
|
2012-02-01 00:59:09 +04:00
|
|
|
this.container.appendChild( this.canvas );
|
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
//create the correct type of overlay by convention if the overlays
|
|
|
|
//are not already OpenSeadragon.Overlays
|
|
|
|
for( i = 0; i < this.overlays.length; i++ ){
|
|
|
|
if( $.isPlainObject( this.overlays[ i ] ) ){
|
|
|
|
|
|
|
|
(function( _this, overlay ){
|
|
|
|
|
|
|
|
var link = document.createElement("a"),
|
|
|
|
rect = new $.Rect(
|
|
|
|
overlay.x,
|
|
|
|
overlay.y,
|
|
|
|
overlay.width,
|
|
|
|
overlay.height
|
|
|
|
),
|
|
|
|
id = Math.floor(Math.random()*10000000);
|
|
|
|
|
|
|
|
link.href = "#/overlay/"+id;
|
|
|
|
link.id = id;
|
2012-03-20 23:00:25 +04:00
|
|
|
link.className = overlay.className ?
|
|
|
|
overlay.className :
|
2012-03-16 19:36:28 +04:00
|
|
|
"openseadragon-overlay";
|
|
|
|
|
|
|
|
_this.overlays[ i ] = new $.Overlay( link, rect );
|
|
|
|
|
|
|
|
}( this, this.overlays[ i ] ));
|
|
|
|
|
|
|
|
} else if ( $.isFunction( this.overlays[ i ] ) ){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//this.profiler = new $.Profiler();
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Drawer.prototype = {
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Adds an html element as an overlay to the current viewport. Useful for
|
|
|
|
* highlighting words or areas of interest on an image or other zoomable
|
|
|
|
* interface.
|
|
|
|
* @method
|
|
|
|
* @param {Element|String} element - A reference to an element or an id for
|
|
|
|
* the element which will overlayed.
|
|
|
|
* @param {OpenSeadragon.Point|OpenSeadragon.Rect} location - The point or
|
|
|
|
* rectangle which will be overlayed.
|
|
|
|
* @param {OpenSeadragon.OverlayPlacement} placement - The position of the
|
|
|
|
* viewport which the location coordinates will be treated as relative
|
|
|
|
* to.
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
addOverlay: function( element, location, placement ) {
|
|
|
|
element = $.getElement( element );
|
|
|
|
|
|
|
|
if ( getOverlayIndex( this.overlays, element ) >= 0 ) {
|
|
|
|
// they're trying to add a duplicate overlay
|
|
|
|
return;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
this.overlays.push( new $.Overlay( element, location, placement ) );
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Updates the overlay represented by the reference to the element or
|
|
|
|
* element id moving it to the new location, relative to the new placement.
|
|
|
|
* @method
|
|
|
|
* @param {OpenSeadragon.Point|OpenSeadragon.Rect} location - The point or
|
|
|
|
* rectangle which will be overlayed.
|
|
|
|
* @param {OpenSeadragon.OverlayPlacement} placement - The position of the
|
|
|
|
* viewport which the location coordinates will be treated as relative
|
|
|
|
* to.
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
updateOverlay: function( element, location, placement ) {
|
|
|
|
var i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
i = getOverlayIndex( this.overlays, element );
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.overlays[ i ].update( location, placement );
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Removes and overlay identified by the reference element or element id
|
|
|
|
* and schedules and update.
|
|
|
|
* @method
|
|
|
|
* @param {Element|String} element - A reference to the element or an
|
|
|
|
* element id which represent the ovelay content to be removed.
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
removeOverlay: function( element ) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
element = $.getElement( element );
|
|
|
|
i = getOverlayIndex( this.overlays, element );
|
|
|
|
|
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.overlays[ i ].destroy();
|
|
|
|
this.overlays.splice( i, 1 );
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Removes all currently configured Overlays from this Drawer and schedules
|
|
|
|
* and update.
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
clearOverlays: function() {
|
|
|
|
while ( this.overlays.length > 0 ) {
|
|
|
|
this.overlays.pop().destroy();
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Returns whether the Drawer is scheduled for an update at the
|
|
|
|
* soonest possible opportunity.
|
|
|
|
* @method
|
|
|
|
* @returns {Boolean} - Whether the Drawer is scheduled for an update at the
|
|
|
|
* soonest possible opportunity.
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
needsUpdate: function() {
|
|
|
|
return this.updateAgain;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Returns the total number of tiles that have been loaded by this Drawer.
|
|
|
|
* @method
|
|
|
|
* @returns {Number} - The total number of tiles that have been loaded by
|
|
|
|
* this Drawer.
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
numTilesLoaded: function() {
|
|
|
|
return this.tilesLoaded.length;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Clears all tiles and triggers an update on the next call to
|
|
|
|
* Drawer.prototype.update().
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
reset: function() {
|
|
|
|
clearTiles( this );
|
|
|
|
this.lastResetTime = +new Date();
|
|
|
|
this.updateAgain = true;
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Forces the Drawer to update.
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
update: function() {
|
|
|
|
//this.profiler.beginUpdate();
|
|
|
|
this.midUpdate = true;
|
|
|
|
updateViewport( this );
|
|
|
|
this.midUpdate = false;
|
|
|
|
//this.profiler.endUpdate();
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
/**
|
|
|
|
* Used internally to load images when required. May also be used to
|
|
|
|
* preload a set of images so the browser will have them available in
|
|
|
|
* the local cache to optimize user experience in certain cases. Because
|
|
|
|
* the number of parallel image loads is configurable, if too many images
|
|
|
|
* are currently being loaded, the request will be ignored. Since by
|
2012-03-01 17:38:15 +04:00
|
|
|
* default drawer.imageLoaderLimit is 0, the native browser parallel
|
2012-02-01 06:01:37 +04:00
|
|
|
* image loading policy will be used.
|
|
|
|
* @method
|
|
|
|
* @param {String} src - The url of the image to load.
|
|
|
|
* @param {Function} callback - The function that will be called with the
|
|
|
|
* Image object as the only parameter, whether on 'load' or on 'abort'.
|
|
|
|
* For now this means the callback is expected to distinguish between
|
|
|
|
* error and success conditions by inspecting the Image object.
|
|
|
|
* @return {Boolean} loading - Wheter the request was submitted or ignored
|
2012-03-01 17:38:15 +04:00
|
|
|
* based on OpenSeadragon.DEFAULT_SETTINGS.imageLoaderLimit.
|
2012-02-01 06:01:37 +04:00
|
|
|
*/
|
2012-02-01 00:59:09 +04:00
|
|
|
loadImage: function( src, callback ) {
|
|
|
|
var _this = this,
|
|
|
|
loading = false,
|
|
|
|
image,
|
|
|
|
jobid,
|
|
|
|
complete;
|
2012-02-23 16:18:28 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !this.imageLoaderLimit ||
|
|
|
|
this.downloading < this.imageLoaderLimit ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
this.downloading++;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
image = new Image();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
complete = function( imagesrc ){
|
|
|
|
_this.downloading--;
|
|
|
|
if (typeof ( callback ) == "function") {
|
|
|
|
try {
|
|
|
|
callback( image );
|
|
|
|
} catch ( e ) {
|
|
|
|
$.console.error(
|
|
|
|
"%s while executing %s callback: %s",
|
|
|
|
e.name,
|
|
|
|
src,
|
|
|
|
e.message,
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
image.onload = function(){
|
|
|
|
finishLoadingImage( image, complete, true );
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
image.onabort = image.onerror = function(){
|
|
|
|
finishLoadingImage( image, complete, false );
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
jobid = window.setTimeout( function(){
|
|
|
|
finishLoadingImage( image, complete, false, jobid );
|
|
|
|
}, TIMEOUT );
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
image.src = src;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return loading;
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Pretty much every other line in this needs to be documented so its clear
|
|
|
|
* how each piece of this routine contributes to the drawing process. That's
|
|
|
|
* why there are so many TODO's inside this function.
|
|
|
|
*/
|
|
|
|
function updateViewport( drawer ) {
|
2012-02-23 16:18:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
drawer.updateAgain = false;
|
|
|
|
|
|
|
|
var tile,
|
|
|
|
level,
|
|
|
|
best = null,
|
|
|
|
haveDrawn = false,
|
|
|
|
currentTime = +new Date(),
|
|
|
|
viewportSize = drawer.viewport.getContainerSize(),
|
|
|
|
viewportBounds = drawer.viewport.getBounds( true ),
|
|
|
|
viewportTL = viewportBounds.getTopLeft(),
|
|
|
|
viewportBR = viewportBounds.getBottomRight(),
|
|
|
|
zeroRatioC = drawer.viewport.deltaPixelsFromPoints(
|
|
|
|
drawer.source.getPixelRatio( 0 ),
|
|
|
|
true
|
|
|
|
).x,
|
|
|
|
lowestLevel = Math.max(
|
|
|
|
drawer.source.minLevel,
|
|
|
|
Math.floor(
|
2012-03-01 17:38:15 +04:00
|
|
|
Math.log( drawer.minZoomImageRatio ) /
|
2012-02-01 00:59:09 +04:00
|
|
|
Math.log( 2 )
|
|
|
|
)
|
|
|
|
),
|
|
|
|
highestLevel = Math.min(
|
|
|
|
drawer.source.maxLevel,
|
|
|
|
Math.floor(
|
2012-03-01 17:38:15 +04:00
|
|
|
Math.log( zeroRatioC / drawer.minPixelRatio ) /
|
2012-02-01 00:59:09 +04:00
|
|
|
Math.log( 2 )
|
|
|
|
)
|
2012-02-23 16:18:28 +04:00
|
|
|
),
|
|
|
|
renderPixelRatioC,
|
|
|
|
renderPixelRatioT,
|
|
|
|
zeroRatioT,
|
|
|
|
optimalRatio,
|
|
|
|
levelOpacity,
|
|
|
|
levelVisibility;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
while ( drawer.lastDrawn.length > 0 ) {
|
|
|
|
tile = drawer.lastDrawn.pop();
|
|
|
|
tile.beingDrawn = false;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
drawer.canvas.innerHTML = "";
|
|
|
|
if ( USE_CANVAS ) {
|
|
|
|
drawer.canvas.width = viewportSize.x;
|
|
|
|
drawer.canvas.height = viewportSize.y;
|
|
|
|
drawer.context.clearRect( 0, 0, viewportSize.x, viewportSize.y );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !drawer.wrapHorizontal &&
|
2012-02-01 00:59:09 +04:00
|
|
|
( viewportBR.x < 0 || viewportTL.x > 1 ) ) {
|
|
|
|
return;
|
|
|
|
} else if
|
2012-03-01 17:38:15 +04:00
|
|
|
( !drawer.wrapVertical &&
|
2012-02-01 00:59:09 +04:00
|
|
|
( viewportBR.y < 0 || viewportTL.y > drawer.normHeight ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !drawer.wrapHorizontal ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
viewportTL.x = Math.max( viewportTL.x, 0 );
|
|
|
|
viewportBR.x = Math.min( viewportBR.x, 1 );
|
|
|
|
}
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !drawer.wrapVertical ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
viewportTL.y = Math.max( viewportTL.y, 0 );
|
|
|
|
viewportBR.y = Math.min( viewportBR.y, drawer.normHeight );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
lowestLevel = Math.min( lowestLevel, highestLevel );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
for ( level = highestLevel; level >= lowestLevel; level-- ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-23 16:18:28 +04:00
|
|
|
//Avoid calculations for draw if we have already drawn this
|
|
|
|
renderPixelRatioC = drawer.viewport.deltaPixelsFromPoints(
|
|
|
|
drawer.source.getPixelRatio( level ),
|
|
|
|
true
|
|
|
|
).x;
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( ( !haveDrawn && renderPixelRatioC >= drawer.minPixelRatio ) ||
|
2012-02-23 16:18:28 +04:00
|
|
|
( level == lowestLevel ) ) {
|
|
|
|
drawLevel = true;
|
|
|
|
haveDrawn = true;
|
|
|
|
} else if ( !haveDrawn ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPixelRatioT = drawer.viewport.deltaPixelsFromPoints(
|
|
|
|
drawer.source.getPixelRatio( level ),
|
|
|
|
false
|
|
|
|
).x;
|
|
|
|
|
|
|
|
zeroRatioT = drawer.viewport.deltaPixelsFromPoints(
|
|
|
|
drawer.source.getPixelRatio( 0 ),
|
|
|
|
false
|
|
|
|
).x;
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
optimalRatio = drawer.immediateRender ?
|
2012-02-23 16:18:28 +04:00
|
|
|
1 :
|
|
|
|
zeroRatioT;
|
|
|
|
|
|
|
|
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
|
|
|
|
|
|
|
|
levelVisibility = optimalRatio / Math.abs(
|
|
|
|
optimalRatio - renderPixelRatioT
|
|
|
|
);
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
best = updateLevel(
|
|
|
|
drawer,
|
2012-02-23 16:18:28 +04:00
|
|
|
haveDrawn,
|
2012-02-01 00:59:09 +04:00
|
|
|
level,
|
2012-02-23 16:18:28 +04:00
|
|
|
levelOpacity,
|
|
|
|
levelVisibility,
|
2012-02-01 00:59:09 +04:00
|
|
|
viewportTL,
|
|
|
|
viewportBR,
|
|
|
|
currentTime,
|
|
|
|
best
|
2012-01-19 05:15:54 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
if ( providesCoverage( drawer.coverage, level ) ) {
|
|
|
|
break;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
drawTiles( drawer, drawer.lastDrawn );
|
|
|
|
drawOverlays( drawer.viewport, drawer.overlays, drawer.container );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//TODO
|
|
|
|
if ( best ) {
|
|
|
|
loadTile( drawer, best, currentTime );
|
|
|
|
// because we haven't finished drawing, so
|
|
|
|
drawer.updateAgain = true;
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-02-23 16:18:28 +04:00
|
|
|
function updateLevel( drawer, haveDrawn, level, levelOpacity, levelVisibility, viewportTL, viewportBR, currentTime, best ){
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
var x, y,
|
|
|
|
tileTL,
|
|
|
|
tileBR,
|
|
|
|
numberOfTiles,
|
2012-02-23 16:18:28 +04:00
|
|
|
viewportCenter = drawer.viewport.pixelFromPoint( drawer.viewport.getCenter() );
|
2012-02-01 00:59:09 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
//OK, a new drawing so do your calculations
|
|
|
|
tileTL = drawer.source.getTileAtPoint( level, viewportTL );
|
|
|
|
tileBR = drawer.source.getTileAtPoint( level, viewportBR );
|
|
|
|
numberOfTiles = drawer.source.getNumTiles( level );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
resetCoverage( drawer.coverage, level );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !drawer.wrapHorizontal ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
tileBR.x = Math.min( tileBR.x, numberOfTiles.x - 1 );
|
|
|
|
}
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !drawer.wrapVertical ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
tileBR.y = Math.min( tileBR.y, numberOfTiles.y - 1 );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
|
|
|
|
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
|
|
|
|
|
|
|
|
best = updateTile(
|
|
|
|
drawer,
|
|
|
|
drawLevel,
|
|
|
|
haveDrawn,
|
|
|
|
x, y,
|
|
|
|
level,
|
|
|
|
levelOpacity,
|
|
|
|
levelVisibility,
|
|
|
|
viewportCenter,
|
|
|
|
numberOfTiles,
|
|
|
|
currentTime,
|
|
|
|
best
|
2012-01-19 05:15:54 +04:00
|
|
|
);
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
|
|
|
return best;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, levelVisibility, viewportCenter, numberOfTiles, currentTime, best){
|
|
|
|
|
|
|
|
var tile = getTile(
|
|
|
|
x, y,
|
|
|
|
level,
|
|
|
|
drawer.source,
|
|
|
|
drawer.tilesMatrix,
|
|
|
|
currentTime,
|
|
|
|
numberOfTiles,
|
|
|
|
drawer.normHeight
|
|
|
|
),
|
2012-03-20 03:03:58 +04:00
|
|
|
drawTile = drawLevel,
|
|
|
|
newbest;
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
setCoverage( drawer.coverage, level, x, y, false );
|
|
|
|
|
|
|
|
if ( !tile.exists ) {
|
|
|
|
return best;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( haveDrawn && !drawTile ) {
|
|
|
|
if ( isCovered( drawer.coverage, level, x, y ) ) {
|
|
|
|
setCoverage( drawer.coverage, level, x, y, true );
|
|
|
|
} else {
|
|
|
|
drawTile = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !drawTile ) {
|
|
|
|
return best;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
positionTile(
|
|
|
|
tile,
|
|
|
|
drawer.source.tileOverlap,
|
|
|
|
drawer.viewport,
|
|
|
|
viewportCenter,
|
|
|
|
levelVisibility
|
|
|
|
);
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( tile.loaded ) {
|
|
|
|
|
|
|
|
drawer.updateAgain = blendTile(
|
|
|
|
drawer,
|
|
|
|
tile,
|
|
|
|
x, y,
|
|
|
|
level,
|
|
|
|
levelOpacity,
|
|
|
|
currentTime
|
|
|
|
);
|
2012-03-20 11:38:27 +04:00
|
|
|
} else if ( tile.loading ) {
|
|
|
|
// the tile is already in the download queue
|
2012-03-20 23:00:25 +04:00
|
|
|
// thanks josh1093 for finally translating this typo
|
2012-02-01 00:59:09 +04:00
|
|
|
} else {
|
|
|
|
best = compareTiles( best, tile );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return best;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function getTile( x, y, level, tileSource, tilesMatrix, time, numTiles, normHeight ) {
|
|
|
|
var xMod,
|
|
|
|
yMod,
|
|
|
|
bounds,
|
|
|
|
exists,
|
|
|
|
url,
|
|
|
|
tile;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !tilesMatrix[ level ] ) {
|
|
|
|
tilesMatrix[ level ] = {};
|
|
|
|
}
|
|
|
|
if ( !tilesMatrix[ level ][ x ] ) {
|
|
|
|
tilesMatrix[ level ][ x ] = {};
|
|
|
|
}
|
2012-01-19 06:52:22 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !tilesMatrix[ level ][ x ][ y ] ) {
|
|
|
|
xMod = ( numTiles.x + ( x % numTiles.x ) ) % numTiles.x;
|
|
|
|
yMod = ( numTiles.y + ( y % numTiles.y ) ) % numTiles.y;
|
|
|
|
bounds = tileSource.getTileBounds( level, xMod, yMod );
|
|
|
|
exists = tileSource.tileExists( level, xMod, yMod );
|
|
|
|
url = tileSource.getTileUrl( level, xMod, yMod );
|
|
|
|
|
|
|
|
bounds.x += 1.0 * ( x - xMod ) / numTiles.x;
|
|
|
|
bounds.y += normHeight * ( y - yMod ) / numTiles.y;
|
|
|
|
|
|
|
|
tilesMatrix[ level ][ x ][ y ] = new $.Tile(
|
|
|
|
level,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
bounds,
|
|
|
|
exists,
|
|
|
|
url
|
|
|
|
);
|
|
|
|
}
|
2012-01-19 06:52:22 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tile = tilesMatrix[ level ][ x ][ y ];
|
|
|
|
tile.lastTouchTime = time;
|
2012-01-19 06:52:22 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return tile;
|
|
|
|
};
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function loadTile( drawer, tile, time ) {
|
|
|
|
tile.loading = drawer.loadImage(
|
|
|
|
tile.url,
|
|
|
|
function( image ){
|
|
|
|
onTileLoad( drawer, tile, time, image );
|
2012-01-19 06:52:22 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
);
|
|
|
|
};
|
2012-01-19 06:52:22 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function onTileLoad( drawer, tile, time, image ) {
|
|
|
|
var insertionIndex,
|
|
|
|
cutoff,
|
|
|
|
worstTile,
|
|
|
|
worstTime,
|
|
|
|
worstLevel,
|
|
|
|
worstTileIndex,
|
|
|
|
prevTile,
|
|
|
|
prevTime,
|
|
|
|
prevLevel,
|
|
|
|
i;
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tile.loading = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( drawer.midUpdate ) {
|
|
|
|
$.console.warn( "Tile load callback in middle of drawing routine." );
|
|
|
|
return;
|
|
|
|
} else if ( !image ) {
|
|
|
|
$.console.log( "Tile %s failed to load: %s", tile, tile.url );
|
|
|
|
tile.exists = false;
|
|
|
|
return;
|
|
|
|
} else if ( time < drawer.lastResetTime ) {
|
|
|
|
$.console.log( "Ignoring tile %s loaded before reset: %s", tile, tile.url );
|
|
|
|
return;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tile.loaded = true;
|
|
|
|
tile.image = image;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
insertionIndex = drawer.tilesLoaded.length;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( drawer.tilesLoaded.length >= drawer.maxImageCacheCount ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
cutoff = Math.ceil( Math.log( drawer.source.tileSize ) / Math.log( 2 ) );
|
2012-01-19 06:52:22 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
worstTile = null;
|
|
|
|
worstTileIndex = -1;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
for ( i = drawer.tilesLoaded.length - 1; i >= 0; i-- ) {
|
|
|
|
prevTile = drawer.tilesLoaded[ i ];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( prevTile.level <= drawer.cutoff || prevTile.beingDrawn ) {
|
|
|
|
continue;
|
|
|
|
} else if ( !worstTile ) {
|
|
|
|
worstTile = prevTile;
|
|
|
|
worstTileIndex = i;
|
|
|
|
continue;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
prevTime = prevTile.lastTouchTime;
|
|
|
|
worstTime = worstTile.lastTouchTime;
|
|
|
|
prevLevel = prevTile.level;
|
|
|
|
worstLevel = worstTile.level;
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( prevTime < worstTime ||
|
|
|
|
( prevTime == worstTime && prevLevel > worstLevel ) ) {
|
|
|
|
worstTile = prevTile;
|
|
|
|
worstTileIndex = i;
|
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( worstTile && worstTileIndex >= 0 ) {
|
|
|
|
worstTile.unload();
|
|
|
|
insertionIndex = worstTileIndex;
|
2012-01-19 05:15:54 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
drawer.tilesLoaded[ insertionIndex ] = tile;
|
|
|
|
drawer.updateAgain = true;
|
|
|
|
};
|
2012-01-19 05:15:54 +04:00
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility ){
|
|
|
|
var boundsTL = tile.bounds.getTopLeft(),
|
|
|
|
boundsSize = tile.bounds.getSize(),
|
|
|
|
positionC = viewport.pixelFromPoint( boundsTL, true ),
|
|
|
|
positionT = viewport.pixelFromPoint( boundsTL, false ),
|
|
|
|
sizeC = viewport.deltaPixelsFromPoints( boundsSize, true ),
|
|
|
|
sizeT = viewport.deltaPixelsFromPoints( boundsSize, false ),
|
|
|
|
tileCenter = positionT.plus( sizeT.divide( 2 ) ),
|
|
|
|
tileDistance = viewportCenter.distanceTo( tileCenter );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !overlap ) {
|
|
|
|
sizeC = sizeC.plus( new $.Point( 1, 1 ) );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tile.position = positionC;
|
|
|
|
tile.size = sizeC;
|
|
|
|
tile.distance = tileDistance;
|
|
|
|
tile.visibility = levelVisibility;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function blendTile( drawer, tile, x, y, level, levelOpacity, currentTime ){
|
2012-03-01 17:38:15 +04:00
|
|
|
var blendTimeMillis = 1000 * drawer.blendTime,
|
2012-02-01 00:59:09 +04:00
|
|
|
deltaTime,
|
|
|
|
opacity;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !tile.blendStart ) {
|
|
|
|
tile.blendStart = currentTime;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
deltaTime = currentTime - tile.blendStart;
|
|
|
|
opacity = Math.min( 1, deltaTime / blendTimeMillis );
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( drawer.alwaysBlend ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
opacity *= levelOpacity;
|
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
tile.opacity = opacity;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
drawer.lastDrawn.push( tile );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( opacity == 1 ) {
|
|
|
|
setCoverage( drawer.coverage, level, x, y, true );
|
|
|
|
} else if ( deltaTime < blendTimeMillis ) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return false;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
function clearTiles( drawer ) {
|
|
|
|
drawer.tilesMatrix = {};
|
|
|
|
drawer.tilesLoaded = [];
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Returns true if the given tile provides coverage to lower-level tiles of
|
|
|
|
* lower resolution representing the same content. If neither x nor y is
|
|
|
|
* given, returns true if the entire visible level provides coverage.
|
|
|
|
*
|
|
|
|
* Note that out-of-bounds tiles provide coverage in this sense, since
|
|
|
|
* there's no content that they would need to cover. Tiles at non-existent
|
|
|
|
* levels that are within the image bounds, however, do not.
|
|
|
|
*/
|
|
|
|
function providesCoverage( coverage, level, x, y ) {
|
|
|
|
var rows,
|
|
|
|
cols,
|
|
|
|
i, j;
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !coverage[ level ] ) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( x === undefined || y === undefined ) {
|
|
|
|
rows = coverage[ level ];
|
|
|
|
for ( i in rows ) {
|
|
|
|
if ( rows.hasOwnProperty( i ) ) {
|
|
|
|
cols = rows[ i ];
|
|
|
|
for ( j in cols ) {
|
|
|
|
if ( cols.hasOwnProperty( j ) && !cols[ j ] ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return (
|
|
|
|
coverage[ level ][ x] === undefined ||
|
|
|
|
coverage[ level ][ x ][ y ] === undefined ||
|
|
|
|
coverage[ level ][ x ][ y ] === true
|
|
|
|
);
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Returns true if the given tile is completely covered by higher-level
|
|
|
|
* tiles of higher resolution representing the same content. If neither x
|
|
|
|
* nor y is given, returns true if the entire visible level is covered.
|
|
|
|
*/
|
|
|
|
function isCovered( coverage, level, x, y ) {
|
|
|
|
if ( x === undefined || y === undefined ) {
|
|
|
|
return providesCoverage( coverage, level + 1 );
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
providesCoverage( coverage, level + 1, 2 * x, 2 * y ) &&
|
|
|
|
providesCoverage( coverage, level + 1, 2 * x, 2 * y + 1 ) &&
|
|
|
|
providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y ) &&
|
|
|
|
providesCoverage( coverage, level + 1, 2 * x + 1, 2 * y + 1 )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Sets whether the given tile provides coverage or not.
|
|
|
|
*/
|
|
|
|
function setCoverage( coverage, level, x, y, covers ) {
|
|
|
|
if ( !coverage[ level ] ) {
|
|
|
|
$.console.warn(
|
|
|
|
"Setting coverage for a tile before its level's coverage has been reset: %s",
|
|
|
|
level
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( !coverage[ level ][ x ] ) {
|
|
|
|
coverage[ level ][ x ] = {};
|
|
|
|
}
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
coverage[ level ][ x ][ y ] = covers;
|
|
|
|
};
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Resets coverage information for the given level. This should be called
|
|
|
|
* after every draw routine. Note that at the beginning of the next draw
|
|
|
|
* routine, coverage for every visible tile should be explicitly set.
|
|
|
|
*/
|
|
|
|
function resetCoverage( coverage, level ) {
|
|
|
|
coverage[ level ] = {};
|
|
|
|
};
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Determines the 'z-index' of the given overlay. Overlays are ordered in
|
|
|
|
* a z-index based on the order they are added to the Drawer.
|
|
|
|
*/
|
|
|
|
function getOverlayIndex( overlays, element ) {
|
|
|
|
var i;
|
|
|
|
for ( i = overlays.length - 1; i >= 0; i-- ) {
|
2012-02-02 01:56:04 +04:00
|
|
|
if ( overlays[ i ].element == element ) {
|
2012-02-01 00:59:09 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
return -1;
|
|
|
|
};
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @inner
|
|
|
|
* Determines whether the 'last best' tile for the area is better than the
|
|
|
|
* tile in question.
|
|
|
|
*/
|
|
|
|
function compareTiles( previousBest, tile ) {
|
|
|
|
if ( !previousBest ) {
|
|
|
|
return tile;
|
|
|
|
}
|
2011-12-28 03:17:24 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
if ( tile.visibility > previousBest.visibility ) {
|
|
|
|
return tile;
|
|
|
|
} else if ( tile.visibility == previousBest.visibility ) {
|
|
|
|
if ( tile.distance < previousBest.distance ) {
|
|
|
|
return tile;
|
2011-12-28 03:17:24 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
return previousBest;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2011-12-28 03:17:24 +04:00
|
|
|
function finishLoadingImage( image, callback, successful, jobid ){
|
|
|
|
|
|
|
|
image.onload = null;
|
|
|
|
image.onabort = null;
|
|
|
|
image.onerror = null;
|
|
|
|
|
|
|
|
if ( jobid ) {
|
|
|
|
window.clearTimeout( jobid );
|
|
|
|
}
|
|
|
|
window.setTimeout( function() {
|
|
|
|
callback( image.src, successful ? image : null);
|
|
|
|
}, 1 );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
|
|
|
|
function drawOverlays( viewport, overlays, container ){
|
|
|
|
var i,
|
|
|
|
length = overlays.length;
|
|
|
|
for ( i = 0; i < length; i++ ) {
|
|
|
|
drawOverlay( viewport, overlays[ i ], container );
|
2012-01-12 03:32:17 +04:00
|
|
|
}
|
2012-02-01 00:59:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function drawOverlay( viewport, overlay, container ){
|
2012-01-12 03:32:17 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
overlay.position = viewport.pixelFromPoint(
|
|
|
|
overlay.bounds.getTopLeft(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
overlay.size = viewport.deltaPixelsFromPoints(
|
|
|
|
overlay.bounds.getSize(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
overlay.drawHTML( container );
|
|
|
|
};
|
|
|
|
|
|
|
|
function drawTiles( drawer, lastDrawn ){
|
|
|
|
var i,
|
|
|
|
tile;
|
|
|
|
|
|
|
|
for ( i = lastDrawn.length - 1; i >= 0; i-- ) {
|
|
|
|
tile = lastDrawn[ i ];
|
|
|
|
|
|
|
|
//TODO: get rid of this if by determining the tile draw method once up
|
|
|
|
// front and defining the appropriate 'draw' function
|
|
|
|
if ( USE_CANVAS ) {
|
|
|
|
tile.drawCanvas( drawer.context );
|
|
|
|
} else {
|
|
|
|
tile.drawHTML( drawer.canvas );
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.beingDrawn = true;
|
|
|
|
}
|
2012-01-12 03:32:17 +04:00
|
|
|
};
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
2012-01-25 23:14:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
$.Viewport = function( options ) {
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//backward compatibility for positional args while prefering more
|
|
|
|
//idiomatic javascript options object as the only argument
|
|
|
|
var args = arguments;
|
|
|
|
if( args.length && args[ 0 ] instanceof $.Point ){
|
2012-01-24 07:48:45 +04:00
|
|
|
options = {
|
2012-03-01 17:38:15 +04:00
|
|
|
containerSize: args[ 0 ],
|
|
|
|
contentSize: args[ 1 ],
|
|
|
|
config: args[ 2 ]
|
2012-01-24 07:48:45 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//options.config and the general config argument are deprecated
|
|
|
|
//in favor of the more direct specification of optional settings
|
|
|
|
//being pass directly on the options object
|
|
|
|
if ( options.config ){
|
|
|
|
$.extend( true, options, options.config );
|
|
|
|
delete options.config;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( true, this, {
|
|
|
|
|
|
|
|
//required settings
|
|
|
|
containerSize: null,
|
|
|
|
contentSize: null,
|
|
|
|
|
|
|
|
//internal state properties
|
|
|
|
zoomPoint: null,
|
|
|
|
|
|
|
|
//configurable options
|
|
|
|
springStiffness: $.DEFAULT_SETTINGS.springStiffness,
|
|
|
|
animationTime: $.DEFAULT_SETTINGS.animationTime,
|
|
|
|
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
|
|
|
|
maxZoomPixelRatio: $.DEFAULT_SETTINGS.maxZoomPixelRatio,
|
|
|
|
visibilityRatio: $.DEFAULT_SETTINGS.visibilityRatio,
|
|
|
|
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
|
|
|
|
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical
|
|
|
|
|
|
|
|
}, options );
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX = new $.Spring({
|
|
|
|
initial: 0,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
|
|
|
this.centerSpringY = new $.Spring({
|
|
|
|
initial: 0,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
2012-02-28 03:29:00 +04:00
|
|
|
this.zoomSpring = new $.Spring({
|
2012-01-05 03:14:20 +04:00
|
|
|
initial: 1,
|
2012-03-01 17:38:15 +04:00
|
|
|
springStiffness: this.springStiffness,
|
|
|
|
animationTime: this.animationTime
|
2012-01-05 03:14:20 +04:00
|
|
|
});
|
2012-02-28 03:29:00 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.resetContentSize( this.contentSize );
|
2012-01-05 04:45:47 +04:00
|
|
|
this.goHome( true );
|
2012-04-03 11:08:27 +04:00
|
|
|
//this.fitHorizontally( true );
|
2011-12-06 07:50:25 +04:00
|
|
|
this.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Viewport.prototype = {
|
2012-01-25 23:14:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
resetContentSize: function( contentSize ){
|
|
|
|
this.contentSize = contentSize;
|
|
|
|
this.contentAspectX = this.contentSize.x / this.contentSize.y;
|
|
|
|
this.contentAspectY = this.contentSize.y / this.contentSize.x;
|
|
|
|
this.homeBounds = new $.Rect(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
this.contentAspectY
|
|
|
|
);
|
|
|
|
this.fitWidthBounds = new $.Rect( 0, 0, 1, this.contentAspectX );
|
|
|
|
this.fitHeightBounds = new $.Rect( 0, 0, 1, this.contentAspectY );
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getHomeZoom: function() {
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
var aspectFactor = Math.min(
|
|
|
|
this.contentAspectX,
|
|
|
|
this.contentAspectY
|
|
|
|
) / this.getAspectRatio();
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
return ( aspectFactor >= 1 ) ?
|
|
|
|
1 :
|
|
|
|
aspectFactor;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getMinZoom: function() {
|
|
|
|
var homeZoom = this.getHomeZoom()
|
|
|
|
zoom = this.minZoomImageRatio * homeZoom;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
return Math.min( zoom, homeZoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 03:14:20 +04:00
|
|
|
getMaxZoom: function() {
|
2012-01-18 03:30:41 +04:00
|
|
|
var zoom =
|
|
|
|
this.contentSize.x *
|
|
|
|
this.maxZoomPixelRatio /
|
|
|
|
this.containerSize.x;
|
2012-01-25 23:14:02 +04:00
|
|
|
return Math.max( zoom, this.getHomeZoom() );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-05 03:14:20 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getAspectRatio: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.containerSize.x / this.containerSize.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-05 03:14:20 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
getContainerSize: function() {
|
2012-01-25 23:14:02 +04:00
|
|
|
return new $.Point(
|
|
|
|
this.containerSize.x,
|
|
|
|
this.containerSize.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getBounds: function( current ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
var center = this.getCenter( current ),
|
|
|
|
width = 1.0 / this.getZoom( current ),
|
2012-01-05 03:14:20 +04:00
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
|
|
|
|
return new $.Rect(
|
2012-03-07 07:20:00 +04:00
|
|
|
center.x - ( width / 2.0 ),
|
|
|
|
center.y - ( height / 2.0 ),
|
2012-01-05 03:14:20 +04:00
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getCenter: function( current ) {
|
2011-12-17 02:56:38 +04:00
|
|
|
var centerCurrent = new $.Point(
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.current.value,
|
|
|
|
this.centerSpringY.current.value
|
|
|
|
),
|
|
|
|
centerTarget = new $.Point(
|
|
|
|
this.centerSpringX.target.value,
|
|
|
|
this.centerSpringY.target.value
|
|
|
|
),
|
|
|
|
oldZoomPixel,
|
|
|
|
zoom,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
bounds,
|
|
|
|
newZoomPixel,
|
|
|
|
deltaZoomPixels,
|
|
|
|
deltaZoomPoints;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( current ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return centerCurrent;
|
2012-01-25 23:14:02 +04:00
|
|
|
} else if ( !this.zoomPoint ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return centerTarget;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
oldZoomPixel = this.pixelFromPoint(this.zoomPoint, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
zoom = this.getZoom();
|
|
|
|
width = 1.0 / zoom;
|
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
bounds = new $.Rect(
|
|
|
|
centerCurrent.x - width / 2.0,
|
|
|
|
centerCurrent.y - height / 2.0,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
newZoomPixel = this.zoomPoint.minus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
).times(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
);
|
|
|
|
deltaZoomPixels = newZoomPixel.minus( oldZoomPixel );
|
|
|
|
deltaZoomPoints = deltaZoomPixels.divide( this.containerSize.x * zoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
return centerTarget.plus( deltaZoomPoints );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
getZoom: function( current ) {
|
|
|
|
if ( current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.zoomSpring.current.value;
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.zoomSpring.target.value;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
applyConstraints: function( immediately ) {
|
|
|
|
var actualZoom = this.getZoom(),
|
|
|
|
constrainedZoom = Math.max(
|
|
|
|
Math.min( actualZoom, this.getMaxZoom() ),
|
|
|
|
this.getMinZoom()
|
|
|
|
),
|
|
|
|
bounds,
|
|
|
|
horizontalThreshold,
|
|
|
|
verticalThreshold,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
top,
|
|
|
|
bottom,
|
|
|
|
dx = 0,
|
|
|
|
dy = 0;
|
|
|
|
|
|
|
|
if ( actualZoom != constrainedZoom ) {
|
|
|
|
this.zoomTo( constrainedZoom, this.zoomPoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
bounds = this.getBounds();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
horizontalThreshold = this.visibilityRatio * bounds.width;
|
|
|
|
verticalThreshold = this.visibilityRatio * bounds.height;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
left = bounds.x + bounds.width;
|
|
|
|
right = 1 - bounds.x;
|
|
|
|
top = bounds.y + bounds.height;
|
2012-04-03 11:08:27 +04:00
|
|
|
bottom = this.contentAspectY - bounds.y;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapHorizontal ) {
|
2012-01-05 04:45:47 +04:00
|
|
|
//do nothing
|
|
|
|
} else if ( left < horizontalThreshold ) {
|
|
|
|
dx = horizontalThreshold - left;
|
|
|
|
} else if ( right < horizontalThreshold ) {
|
|
|
|
dx = right - horizontalThreshold;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapVertical ) {
|
2012-01-05 04:45:47 +04:00
|
|
|
//do nothing
|
|
|
|
} else if ( top < verticalThreshold ) {
|
|
|
|
dy = verticalThreshold - top;
|
|
|
|
} else if ( bottom < verticalThreshold ) {
|
|
|
|
dy = bottom - verticalThreshold;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
if ( dx || dy ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
bounds.x += dx;
|
|
|
|
bounds.y += dy;
|
2012-01-05 04:45:47 +04:00
|
|
|
this.fitBounds( bounds, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
ensureVisible: function( immediately ) {
|
|
|
|
this.applyConstraints( immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-15 23:50:27 +04:00
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Rect} bounds
|
|
|
|
* @param {Boolean} immediately
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2012-01-05 04:45:47 +04:00
|
|
|
fitBounds: function( bounds, immediately ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var aspect = this.getAspectRatio(),
|
|
|
|
center = bounds.getCenter(),
|
|
|
|
newBounds = new $.Rect(
|
|
|
|
bounds.x,
|
|
|
|
bounds.y,
|
|
|
|
bounds.width,
|
|
|
|
bounds.height
|
|
|
|
),
|
|
|
|
oldBounds,
|
|
|
|
oldZoom,
|
|
|
|
newZoom,
|
2012-01-05 04:45:47 +04:00
|
|
|
referencePoint;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( newBounds.getAspectRatio() >= aspect ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
newBounds.height = bounds.width / aspect;
|
2012-01-05 04:45:47 +04:00
|
|
|
newBounds.y = center.y - newBounds.height / 2;
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
newBounds.width = bounds.height * aspect;
|
2012-01-05 04:45:47 +04:00
|
|
|
newBounds.x = center.x - newBounds.width / 2;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.panTo( this.getCenter( true ), true );
|
|
|
|
this.zoomTo( this.getZoom( true ), null, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
oldBounds = this.getBounds();
|
|
|
|
oldZoom = this.getZoom();
|
|
|
|
newZoom = 1.0 / newBounds.width;
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( newZoom == oldZoom || newBounds.width == oldBounds.width ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.panTo( center, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
referencePoint = oldBounds.getTopLeft().times(
|
2012-01-05 03:14:20 +04:00
|
|
|
this.containerSize.x / oldBounds.width
|
|
|
|
).minus(
|
|
|
|
newBounds.getTopLeft().times(
|
|
|
|
this.containerSize.x / newBounds.width
|
|
|
|
)
|
|
|
|
).divide(
|
|
|
|
this.containerSize.x / oldBounds.width -
|
|
|
|
this.containerSize.x / newBounds.width
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
this.zoomTo( newZoom, referencePoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
goHome: function( immediately ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
return this.fitVertically( immediately );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
|
|
|
fitVertically: function( immediately ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
var center = this.getCenter();
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapHorizontal ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
center.x = ( 1 + ( center.x % 1 ) ) % 1;
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapVertical ) {
|
2012-01-25 23:14:02 +04:00
|
|
|
center.y = (
|
2012-04-03 11:08:27 +04:00
|
|
|
this.contentAspectY + ( center.y % this.contentAspectY )
|
|
|
|
) % this.contentAspectY;
|
2012-01-25 23:14:02 +04:00
|
|
|
this.centerSpringY.resetTo( center.y );
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringY.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.fitBounds( this.homeBounds, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
|
|
|
fitHorizontally: function( immediately ) {
|
|
|
|
var center = this.getCenter();
|
|
|
|
|
|
|
|
if ( this.wrapHorizontal ) {
|
|
|
|
center.x = (
|
|
|
|
this.contentAspectX + ( center.x % this.contentAspectX )
|
|
|
|
) % this.contentAspectX;
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
|
|
|
this.centerSpringX.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.wrapVertical ) {
|
|
|
|
center.y = ( 1 + ( center.y % 1 ) ) % 1;
|
|
|
|
this.centerSpringY.resetTo( center.y );
|
|
|
|
this.centerSpringY.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.fitBounds( this.fitWidthBounds, immediately );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} delta
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
panBy: function( delta, immediately ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var center = new $.Point(
|
|
|
|
this.centerSpringX.target.value,
|
|
|
|
this.centerSpringY.target.value
|
|
|
|
);
|
|
|
|
this.panTo( center.plus( delta ), immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {OpenSeadragon.Point} center
|
|
|
|
* @param {Boolean} immediately
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
panTo: function( center, immediately ) {
|
|
|
|
if ( immediately ) {
|
|
|
|
this.centerSpringX.resetTo( center.x );
|
|
|
|
this.centerSpringY.resetTo( center.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-25 23:14:02 +04:00
|
|
|
this.centerSpringX.springTo( center.x );
|
|
|
|
this.centerSpringY.springTo( center.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
zoomBy: function( factor, refPoint, immediately ) {
|
|
|
|
this.zoomTo( this.zoomSpring.target.value * factor, refPoint, immediately );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
zoomTo: function( zoom, refPoint, immediately ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( immediately ) {
|
|
|
|
this.zoomSpring.resetTo( zoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-25 23:14:02 +04:00
|
|
|
this.zoomSpring.springTo( zoom );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.zoomPoint = refPoint instanceof $.Point ?
|
|
|
|
refPoint :
|
|
|
|
null;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
resize: function( newContainerSize, maintain ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var oldBounds = this.getBounds(),
|
|
|
|
newBounds = oldBounds,
|
|
|
|
widthDeltaFactor = newContainerSize.x / this.containerSize.x;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.containerSize = new $.Point(
|
|
|
|
newContainerSize.x,
|
|
|
|
newContainerSize.y
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (maintain) {
|
2012-01-18 03:30:41 +04:00
|
|
|
newBounds.width = oldBounds.width * widthDeltaFactor;
|
2011-12-06 07:50:25 +04:00
|
|
|
newBounds.height = newBounds.width / this.getAspectRatio();
|
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
this.fitBounds( newBounds, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
update: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
var oldCenterX = this.centerSpringX.current.value,
|
|
|
|
oldCenterY = this.centerSpringY.current.value,
|
|
|
|
oldZoom = this.zoomSpring.current.value,
|
|
|
|
oldZoomPixel,
|
|
|
|
newZoomPixel,
|
|
|
|
deltaZoomPixels,
|
|
|
|
deltaZoomPoints;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (this.zoomPoint) {
|
2012-01-25 23:14:02 +04:00
|
|
|
oldZoomPixel = this.pixelFromPoint( this.zoomPoint, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.zoomSpring.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if (this.zoomPoint && this.zoomSpring.current.value != oldZoom) {
|
|
|
|
newZoomPixel = this.pixelFromPoint( this.zoomPoint, true );
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaZoomPixels = newZoomPixel.minus( oldZoomPixel );
|
2012-01-05 03:14:20 +04:00
|
|
|
deltaZoomPoints = this.deltaPointsFromPixels( deltaZoomPixels, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.shiftBy( deltaZoomPoints.x );
|
|
|
|
this.centerSpringY.shiftBy( deltaZoomPoints.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
this.zoomPoint = null;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.update();
|
|
|
|
this.centerSpringY.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
return this.centerSpringX.current.value != oldCenterX ||
|
|
|
|
this.centerSpringY.current.value != oldCenterY ||
|
|
|
|
this.zoomSpring.current.value != oldZoom;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaPixelsFromPoints: function( deltaPoints, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return deltaPoints.times(
|
|
|
|
this.containerSize.x * this.getZoom( current )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
deltaPointsFromPixels: function( deltaPixels, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
return deltaPixels.divide(
|
|
|
|
this.containerSize.x * this.getZoom( current )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
pixelFromPoint: function( point, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var bounds = this.getBounds( current );
|
|
|
|
return point.minus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
).times(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2012-01-25 23:14:02 +04:00
|
|
|
pointFromPixel: function( pixel, current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var bounds = this.getBounds( current );
|
|
|
|
return pixel.divide(
|
|
|
|
this.containerSize.x / bounds.width
|
|
|
|
).plus(
|
|
|
|
bounds.getTopLeft()
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|