2011-12-06 07:50:25 +04:00
|
|
|
/**
|
|
|
|
* (c) 2011 Christopher Thatcher
|
|
|
|
* (c) 2010 OpenSeadragon
|
|
|
|
* (c) 2010 CodePlex Foundation
|
|
|
|
*
|
2012-01-19 06:52:22 +04:00
|
|
|
* OpenSeadragon 0.8.20
|
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.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
OpenSeadragon = window.OpenSeadragon || (function(){
|
|
|
|
|
|
|
|
//Taken from jquery 1.6.1
|
|
|
|
// [[Class]] -> type pairs
|
|
|
|
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
|
|
|
|
|
|
|
return {
|
|
|
|
// See test/unit/core.js for details concerning isFunction.
|
|
|
|
// Since version 1.3, DOM methods and functions like alert
|
|
|
|
// aren't supported. They return false on IE (#2968).
|
|
|
|
isFunction: function( obj ) {
|
|
|
|
return OpenSeadragon.type(obj) === "function";
|
|
|
|
},
|
|
|
|
|
|
|
|
isArray: Array.isArray || function( obj ) {
|
|
|
|
return OpenSeadragon.type(obj) === "array";
|
|
|
|
},
|
|
|
|
|
|
|
|
// A crude way of determining if an object is a window
|
|
|
|
isWindow: function( obj ) {
|
|
|
|
return obj && typeof obj === "object" && "setInterval" in obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
type: function( obj ) {
|
|
|
|
return obj == null ?
|
|
|
|
String( obj ) :
|
|
|
|
class2type[ toString.call(obj) ] || "object";
|
|
|
|
},
|
|
|
|
|
|
|
|
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 || OpenSeadragon.isWindow( obj ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not own constructor property must be Object
|
|
|
|
if ( obj.constructor &&
|
|
|
|
!hasOwn.call(obj, "constructor") &&
|
|
|
|
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Own properties are enumerated firstly, so to speed up,
|
|
|
|
// if last one is own, then all properties are own.
|
|
|
|
|
|
|
|
var key;
|
|
|
|
for ( key in obj ) {}
|
|
|
|
|
|
|
|
return key === undefined || hasOwn.call( obj, key );
|
|
|
|
},
|
|
|
|
|
|
|
|
isEmptyObject: function( obj ) {
|
|
|
|
for ( var name in obj ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-06 16:21:30 +04:00
|
|
|
$.SIGNAL = "----seadragon----";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
$.delegate = function(object, method) {
|
|
|
|
return function() {
|
|
|
|
if (arguments === undefined)
|
|
|
|
arguments = [];
|
|
|
|
return method.apply(object, arguments);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
//Taken from jQuery 1.6.1:
|
|
|
|
$.extend = function() {
|
|
|
|
var options, name, src, copy, copyIsArray, clone,
|
|
|
|
target = arguments[0] || {},
|
|
|
|
i = 1,
|
|
|
|
length = arguments.length,
|
|
|
|
deep = false;
|
|
|
|
|
|
|
|
// Handle a deep copy situation
|
|
|
|
if ( typeof target === "boolean" ) {
|
|
|
|
deep = target;
|
|
|
|
target = arguments[1] || {};
|
|
|
|
// skip the boolean and the target
|
|
|
|
i = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
|
|
|
if ( typeof target !== "object" && !OpenSeadragon.isFunction(target) ) {
|
|
|
|
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
|
|
|
|
if ( (options = arguments[ i ]) != null ) {
|
|
|
|
// 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
|
|
|
|
if ( deep && copy && ( OpenSeadragon.isPlainObject(copy) || (copyIsArray = OpenSeadragon.isArray(copy)) ) ) {
|
|
|
|
if ( copyIsArray ) {
|
|
|
|
copyIsArray = false;
|
|
|
|
clone = src && OpenSeadragon.isArray(src) ? src : [];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
clone = src && OpenSeadragon.isPlainObject(src) ? src : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-18 03:30:41 +04:00
|
|
|
//The following functions are originally from the Openseadragon Utils
|
|
|
|
//module but have been moved to Openseadragon to avoid the Utils anti-
|
|
|
|
//pattern. Not all of the code is A-grade compared to equivalent functions
|
|
|
|
// from libraries like jquery, but until we need better we'll leave those
|
|
|
|
//orignally developed by the project.
|
|
|
|
$.BROWSERS = {
|
|
|
|
UNKNOWN: 0,
|
|
|
|
IE: 1,
|
|
|
|
FIREFOX: 2,
|
|
|
|
SAFARI: 3,
|
|
|
|
CHROME: 4,
|
|
|
|
OPERA: 5
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.Browser = {
|
|
|
|
vendor: $.BROWSERS.UNKNOWN,
|
|
|
|
version: 0,
|
|
|
|
alpha: true
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var ACTIVEX = [
|
|
|
|
"Msxml2.XMLHTTP",
|
|
|
|
"Msxml3.XMLHTTP",
|
|
|
|
"Microsoft.XMLHTTP"
|
|
|
|
],
|
|
|
|
FILEFORMATS = {
|
|
|
|
"bmp": false,
|
|
|
|
"jpeg": true,
|
|
|
|
"jpg": true,
|
|
|
|
"png": true,
|
|
|
|
"tif": false,
|
|
|
|
"wdp": false
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
URLPARAMS = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
(function() {
|
2011-12-17 03:29:16 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var app = navigator.appName,
|
|
|
|
ver = navigator.appVersion,
|
|
|
|
ua = navigator.userAgent;
|
2011-12-17 03:29:16 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
switch( navigator.appName ){
|
|
|
|
case "Microsoft Internet Explorer":
|
|
|
|
if( !!window.attachEvent &&
|
|
|
|
!!window.ActiveXObject ) {
|
2011-12-17 03:29:16 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.Browser.vendor = $.BROWSERS.IE;
|
|
|
|
$.Browser.version = parseFloat(
|
|
|
|
ua.substring(
|
|
|
|
ua.indexOf( "MSIE" ) + 5,
|
|
|
|
ua.indexOf( ";", ua.indexOf( "MSIE" ) ) )
|
|
|
|
);
|
2011-12-17 03:29:16 +04:00
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
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;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var query = window.location.search.substring( 1 ), // ignore '?'
|
|
|
|
parts = query.split('&'),
|
|
|
|
part,
|
|
|
|
sep,
|
|
|
|
i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
for ( i = 0; i < parts.length; i++ ) {
|
|
|
|
part = parts[ i ];
|
|
|
|
sep = part.indexOf( '=' );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( sep > 0 ) {
|
|
|
|
URLPARAMS[ part.substring( 0, sep ) ] =
|
|
|
|
decodeURIComponent( part.substring( sep + 1 ) );
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
//determine if this browser supports
|
|
|
|
$.Browser.alpha = !(
|
|
|
|
$.Browser.vendor == $.BROWSERS.IE || (
|
|
|
|
$.Browser.vendor == $.BROWSERS.CHROME &&
|
|
|
|
$.Browser.version < 2
|
|
|
|
)
|
|
|
|
);
|
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
|
|
|
//TODO: $.Debug is often used inside a try/catch block which generally
|
2012-01-18 08:13:29 +04:00
|
|
|
// prevents allowings errors to occur with detection until a debugger
|
2012-01-18 03:30:41 +04:00
|
|
|
// 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.
|
|
|
|
$.Debug = window.console ? window.console : function(){};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.extend( $, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
getElement: function( element ) {
|
|
|
|
if ( typeof ( element ) == "string") {
|
2012-01-18 03:30:41 +04:00
|
|
|
element = document.getElementById( element );
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
getOffsetParent: function( element, isFixed ) {
|
|
|
|
if ( isFixed && element != document.body ) {
|
|
|
|
return document.body;
|
|
|
|
} else {
|
|
|
|
return element.offsetParent;
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 07:50:25 +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";
|
|
|
|
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";
|
|
|
|
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-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-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-01-18 03:30:41 +04:00
|
|
|
getEvent: function( event ) {
|
|
|
|
return event ? event : window.event;
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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-01-18 03:30:41 +04:00
|
|
|
getPageScroll: function() {
|
|
|
|
var result = new $.Point(),
|
|
|
|
docElmt = document.documentElement || {},
|
|
|
|
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;
|
|
|
|
} else if ( docElmt.scrollLeft || docElmt.scrollTop ) {
|
|
|
|
result.x = docElmt.scrollLeft;
|
|
|
|
result.y = docElmt.scrollTop;
|
|
|
|
}
|
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-18 03:30:41 +04:00
|
|
|
getWindowSize: function() {
|
|
|
|
var result = new $.Point(),
|
|
|
|
docElmt = document.documentElement || {},
|
|
|
|
body = document.body || {};
|
|
|
|
|
|
|
|
if ( typeof( window.innerWidth ) == 'number' ) {
|
|
|
|
result.x = window.innerWidth;
|
|
|
|
result.y = window.innerHeight;
|
|
|
|
} else if ( docElmt.clientWidth || docElmt.clientHeight ) {
|
|
|
|
result.x = docElmt.clientWidth;
|
|
|
|
result.y = docElmt.clientHeight;
|
|
|
|
} 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-18 03:30:41 +04:00
|
|
|
imageFormatSupported: function( extension ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
extension = extension ? extension : "";
|
2012-01-18 03:30:41 +04:00
|
|
|
return !!FILEFORMATS[ extension.toLowerCase() ];
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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-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-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-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-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-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-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 ) {
|
|
|
|
event.preventDefault(); // W3C for preventing default
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
event.cancel = true; // legacy for preventing default
|
|
|
|
event.returnValue = false; // IE for preventing default
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
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-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-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-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 ) {
|
|
|
|
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) {
|
|
|
|
$.Debug.log(e.name + " while making AJAX request: " + 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-01-18 03:30:41 +04:00
|
|
|
parseXml: function( string ) {
|
|
|
|
//TODO: yet another example where we can determine the correct
|
|
|
|
// implementation once at start-up instead of everytime we use
|
|
|
|
// the function.
|
|
|
|
var xmlDoc = null,
|
|
|
|
parser;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( window.ActiveXObject ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
|
|
|
|
xmlDoc.async = false;
|
|
|
|
xmlDoc.loadXML( string );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
} else if ( window.DOMParser ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
parser = new DOMParser();
|
|
|
|
xmlDoc = parser.parseFromString( string, "text/xml" );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new Error( "Browser doesn't support XML DOM." );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
return xmlDoc;
|
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
|
|
|
|
|
|
|
}( 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-18 03:30:41 +04:00
|
|
|
$.EventHandler = function() {
|
|
|
|
this.events = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.EventHandler.prototype = {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
addHandler: function( id, handler ) {
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if( !events ){
|
|
|
|
this.events[ id ] = events = [];
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-18 03:30:41 +04:00
|
|
|
events[ events.length ] = handler;
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
removeHandler: function( id, handler ) {
|
|
|
|
//Start Thatcher - unneccessary indirection. Also, because events were
|
|
|
|
// - not actually being removed, we need to add the code
|
|
|
|
// - to do the removal ourselves. TODO
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if ( !events ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//End Thatcher
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
getHandler: function( id ) {
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if ( !events || !events.length ){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
events = events.length === 1 ?
|
|
|
|
[ events[ 0 ] ] :
|
|
|
|
Array.apply( null, events );
|
|
|
|
return function( source, args ) {
|
|
|
|
var i,
|
|
|
|
l = events.length;
|
|
|
|
for ( i = 0; i < l; i++ ) {
|
|
|
|
events[ i ]( source, 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-01-18 03:30:41 +04:00
|
|
|
raiseEvent: function( eventName, eventArgs ) {
|
|
|
|
var handler = this.getHandler( eventName );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( handler ) {
|
|
|
|
if ( !eventArgs ) {
|
|
|
|
eventArgs = new Object();
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
handler( this, eventArgs );
|
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( $ ){
|
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
//Ensures we dont break existing instances of mousetracker if we are dumb
|
|
|
|
//enough to load openseadragon.js onto the page twice. I don't know how
|
|
|
|
//useful this pattern is, but if we decide to use it we should use it
|
|
|
|
//everywhere
|
2011-12-06 07:50:25 +04:00
|
|
|
if ($.MouseTracker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var isIE = $.Browser.vendor == $.BROWSERS.IE,
|
2011-12-14 05:04:38 +04:00
|
|
|
buttonDownAny = false,
|
|
|
|
ieCapturingAny = false,
|
|
|
|
ieTrackersActive = {}, // dictionary from hash to MouseTracker
|
|
|
|
ieTrackersCapturing = []; // list of trackers interested in capture
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
$.MouseTracker = function (elmt, clickTimeThreshold, clickDistThreshold) {
|
|
|
|
//Start Thatcher - TODO: remove local function definitions in favor of
|
2011-12-20 16:39:02 +04:00
|
|
|
// - a global closure for MouseTracker so the number
|
2011-12-06 07:50:25 +04:00
|
|
|
// - of Viewers has less memory impact. Also use
|
|
|
|
// - prototype pattern instead of Singleton pattern.
|
|
|
|
//End Thatcher
|
2011-12-14 05:04:38 +04:00
|
|
|
var self = this,
|
|
|
|
ieSelf = null,
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
hash = Math.random(), // a unique hash for this tracker
|
2012-01-18 03:30:41 +04:00
|
|
|
elmt = $.getElement(elmt),
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
tracking = false,
|
|
|
|
capturing = false,
|
|
|
|
buttonDownElmt = false,
|
|
|
|
insideElmt = false,
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
lastPoint = null, // position of last mouse down/move
|
|
|
|
lastMouseDownTime = null, // time of last mouse down
|
|
|
|
lastMouseDownPoint = null, // position of last mouse down
|
|
|
|
clickTimeThreshold = clickTimeThreshold,
|
|
|
|
clickDistThreshold = clickDistThreshold;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
this.target = elmt;
|
|
|
|
this.enterHandler = null; // function(tracker, position, buttonDownElmt, buttonDownAny)
|
|
|
|
this.exitHandler = null; // function(tracker, position, buttonDownElmt, buttonDownAny)
|
|
|
|
this.pressHandler = null; // function(tracker, position)
|
2011-12-06 07:50:25 +04:00
|
|
|
this.releaseHandler = null; // function(tracker, position, insideElmtPress, insideElmtRelease)
|
2011-12-14 05:04:38 +04:00
|
|
|
this.scrollHandler = null; // function(tracker, position, scroll, shift)
|
|
|
|
this.clickHandler = null; // function(tracker, position, quick, shift)
|
|
|
|
this.dragHandler = null; // function(tracker, position, delta, shift)
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
(function () {
|
|
|
|
ieSelf = {
|
|
|
|
hasMouse: hasMouse,
|
|
|
|
onMouseOver: onMouseOver,
|
|
|
|
onMouseOut: onMouseOut,
|
|
|
|
onMouseUp: onMouseUp,
|
|
|
|
onMouseMove: onMouseMove
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
this.isTracking = function () {
|
|
|
|
return tracking;
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
this.setTracking = function (track) {
|
|
|
|
if (track) {
|
|
|
|
startTracking();
|
|
|
|
} else {
|
|
|
|
stopTracking();
|
|
|
|
}
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
function startTracking() {
|
|
|
|
if (!tracking) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.addEvent(elmt, "mouseover", onMouseOver, false);
|
|
|
|
$.addEvent(elmt, "mouseout", onMouseOut, false);
|
|
|
|
$.addEvent(elmt, "mousedown", onMouseDown, false);
|
|
|
|
$.addEvent(elmt, "mouseup", onMouseUp, false);
|
|
|
|
$.addEvent(elmt, "click", onMouseClick, false);
|
|
|
|
$.addEvent(elmt, "DOMMouseScroll", onMouseWheelSpin, false);
|
|
|
|
$.addEvent(elmt, "mousewheel", onMouseWheelSpin, false); // Firefox
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
tracking = true;
|
|
|
|
ieTrackersActive[hash] = ieSelf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopTracking() {
|
|
|
|
if (tracking) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.removeEvent(elmt, "mouseover", onMouseOver, false);
|
|
|
|
$.removeEvent(elmt, "mouseout", onMouseOut, false);
|
|
|
|
$.removeEvent(elmt, "mousedown", onMouseDown, false);
|
|
|
|
$.removeEvent(elmt, "mouseup", onMouseUp, false);
|
|
|
|
$.removeEvent(elmt, "click", onMouseClick, false);
|
|
|
|
$.removeEvent(elmt, "DOMMouseScroll", onMouseWheelSpin, false);
|
|
|
|
$.removeEvent(elmt, "mousewheel", onMouseWheelSpin, false);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
releaseMouse();
|
|
|
|
tracking = false;
|
|
|
|
delete ieTrackersActive[hash];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function captureMouse() {
|
|
|
|
if (!capturing) {
|
|
|
|
if (isIE) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.removeEvent(elmt, "mouseup", onMouseUp, false);
|
|
|
|
$.addEvent(elmt, "mouseup", onMouseUpIE, true);
|
|
|
|
$.addEvent(elmt, "mousemove", onMouseMoveIE, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.addEvent(window, "mouseup", onMouseUpWindow, true);
|
|
|
|
$.addEvent(window, "mousemove", onMouseMove, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
capturing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function releaseMouse() {
|
|
|
|
if (capturing) {
|
|
|
|
if (isIE) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.removeEvent(elmt, "mousemove", onMouseMoveIE, true);
|
|
|
|
$.removeEvent(elmt, "mouseup", onMouseUpIE, true);
|
|
|
|
$.addEvent(elmt, "mouseup", onMouseUp, false);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.removeEvent(window, "mousemove", onMouseMove, true);
|
|
|
|
$.removeEvent(window, "mouseup", onMouseUpWindow, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
capturing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function triggerOthers(eventName, event) {
|
|
|
|
var trackers = ieTrackersActive;
|
|
|
|
for (var otherHash in trackers) {
|
|
|
|
if (trackers.hasOwnProperty(otherHash) && hash != otherHash) {
|
|
|
|
trackers[otherHash][eventName](event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasMouse() {
|
|
|
|
return insideElmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onMouseOver(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (isIE && capturing && !isChild(event.srcElement, elmt)) {
|
|
|
|
triggerOthers("onMouseOver", event);
|
|
|
|
}
|
|
|
|
|
|
|
|
var to = event.target ? event.target : event.srcElement;
|
|
|
|
var from = event.relatedTarget ? event.relatedTarget : event.fromElement;
|
|
|
|
if (!isChild(elmt, to) || isChild(elmt, from)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
insideElmt = true;
|
|
|
|
|
|
|
|
if (typeof (self.enterHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.enterHandler(self, getMouseRelative(event, elmt),
|
|
|
|
buttonDownElmt, buttonDownAny);
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing enter handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseOut(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (isIE && capturing && !isChild(event.srcElement, elmt)) {
|
|
|
|
triggerOthers("onMouseOut", event);
|
|
|
|
}
|
|
|
|
|
|
|
|
var from = event.target ? event.target : event.srcElement;
|
|
|
|
var to = event.relatedTarget ? event.relatedTarget : event.toElement;
|
|
|
|
if (!isChild(elmt, from) || isChild(elmt, to)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
insideElmt = false;
|
|
|
|
|
|
|
|
if (typeof (self.exitHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.exitHandler(self, getMouseRelative(event, elmt),
|
|
|
|
buttonDownElmt, buttonDownAny);
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing exit handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseDown(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (event.button == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonDownElmt = true;
|
|
|
|
|
|
|
|
lastPoint = getMouseAbsolute(event);
|
|
|
|
lastMouseDownPoint = lastPoint;
|
|
|
|
lastMouseDownTime = new Date().getTime();
|
|
|
|
|
|
|
|
if (typeof (self.pressHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.pressHandler(self, getMouseRelative(event, elmt));
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing press handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.pressHandler || self.dragHandler) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.cancelEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isIE || !ieCapturingAny) {
|
|
|
|
captureMouse();
|
|
|
|
ieCapturingAny = true;
|
|
|
|
ieTrackersCapturing = [ieSelf]; // reset to empty & add us
|
|
|
|
} else if (isIE) {
|
|
|
|
ieTrackersCapturing.push(ieSelf); // add us to the list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseUp(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
var insideElmtPress = buttonDownElmt;
|
|
|
|
var insideElmtRelease = insideElmt;
|
|
|
|
|
|
|
|
if (event.button == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonDownElmt = false;
|
|
|
|
|
|
|
|
if (typeof (self.releaseHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.releaseHandler(self, getMouseRelative(event, elmt),
|
|
|
|
insideElmtPress, insideElmtRelease);
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing release handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (insideElmtPress && insideElmtRelease) {
|
|
|
|
handleMouseClick(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
function onMouseUpIE(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (event.button == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < ieTrackersCapturing.length; i++) {
|
|
|
|
var tracker = ieTrackersCapturing[i];
|
|
|
|
if (!tracker.hasMouse()) {
|
|
|
|
tracker.onMouseUp(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseMouse();
|
|
|
|
ieCapturingAny = false;
|
|
|
|
event.srcElement.fireEvent("on" + event.type,
|
|
|
|
document.createEventObject(event));
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.stopEvent(event);
|
2011-12-06 07:50:25 +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.
|
|
|
|
*/
|
|
|
|
function onMouseUpWindow(event) {
|
|
|
|
if (!insideElmt) {
|
|
|
|
onMouseUp(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseClick(event) {
|
|
|
|
|
|
|
|
if (self.clickHandler) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.cancelEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseWheelSpin(event) {
|
|
|
|
var nDelta = 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event.detail) { // Mozilla FireFox
|
|
|
|
nDelta = -event.detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
nDelta = nDelta > 0 ? 1 : -1;
|
|
|
|
|
|
|
|
if (typeof (self.scrollHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.scrollHandler(self, getMouseRelative(event, elmt), nDelta, event.shiftKey);
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing scroll handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.cancelEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMouseClick(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
if (event.button == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var time = new Date().getTime() - lastMouseDownTime;
|
|
|
|
var point = getMouseAbsolute(event);
|
|
|
|
var distance = lastMouseDownPoint.distanceTo(point);
|
|
|
|
var quick = time <= clickTimeThreshold &&
|
|
|
|
distance <= clickDistThreshold;
|
|
|
|
|
|
|
|
if (typeof (self.clickHandler) == "function") {
|
|
|
|
try {
|
|
|
|
self.clickHandler(self, getMouseRelative(event, elmt),
|
|
|
|
quick, event.shiftKey);
|
|
|
|
} catch (e) {
|
|
|
|
$.Debug.error(e.name +
|
|
|
|
" while executing click handler: " + e.message, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseMove(event) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var event = $.getEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
var point = getMouseAbsolute(event);
|
|
|
|
var delta = point.minus(lastPoint);
|
|
|
|
|
|
|
|
lastPoint = point;
|
|
|
|
|
|
|
|
if (typeof (self.dragHandler) == "function") {
|
|
|
|
try {
|
2012-01-18 03:30:41 +04:00
|
|
|
self.dragHandler(
|
|
|
|
self,
|
|
|
|
getMouseRelative( event, elmt ),
|
|
|
|
delta,
|
|
|
|
event.shiftKey
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
} catch (e) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.Debug.error(
|
|
|
|
e.name +
|
|
|
|
" while executing drag handler: "
|
|
|
|
+ e.message,
|
|
|
|
e
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.cancelEvent(event);
|
2011-12-06 07:50:25 +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).
|
|
|
|
*/
|
|
|
|
function onMouseMoveIE(event) {
|
|
|
|
for (var i = 0; i < ieTrackersCapturing.length; i++) {
|
|
|
|
ieTrackersCapturing[i].onMouseMove(event);
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.stopEvent(event);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
function getMouseAbsolute( event ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
return $.getMousePosition(event);
|
2011-12-14 05:04:38 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
function getMouseRelative( event, elmt ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var mouse = $.getMousePosition(event);
|
|
|
|
var offset = $.getElementPosition(elmt);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
return mouse.minus(offset);
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
/**
|
|
|
|
* Returns true if elmtB is a child node of elmtA, or if they're equal.
|
|
|
|
*/
|
|
|
|
function isChild( elmtA, elmtB ) {
|
|
|
|
var body = document.body;
|
|
|
|
while (elmtB && elmtA != elmtB && body != elmtB) {
|
|
|
|
try {
|
|
|
|
elmtB = elmtB.parentNode;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-14 05:04:38 +04:00
|
|
|
}
|
|
|
|
return elmtA == elmtB;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onGlobalMouseDown() {
|
|
|
|
buttonDownAny = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onGlobalMouseUp() {
|
|
|
|
buttonDownAny = false;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2011-12-14 05:04:38 +04:00
|
|
|
(function () {
|
|
|
|
if (isIE) {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.addEvent(document, "mousedown", onGlobalMouseDown, false);
|
|
|
|
$.addEvent(document, "mouseup", onGlobalMouseUp, false);
|
2011-12-14 05:04:38 +04:00
|
|
|
} else {
|
2012-01-18 03:30:41 +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( $ ){
|
|
|
|
|
|
|
|
|
2011-12-14 02:57:40 +04:00
|
|
|
$.ControlAnchor = {
|
|
|
|
NONE: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP_RIGHT: 2,
|
|
|
|
BOTTOM_RIGHT: 3,
|
|
|
|
BOTTOM_LEFT: 4
|
|
|
|
};
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
$.Control = function (elmt, anchor, container) {
|
|
|
|
this.elmt = elmt;
|
|
|
|
this.anchor = anchor;
|
|
|
|
this.container = container;
|
2012-01-18 03:30:41 +04:00
|
|
|
this.wrapper = $.makeNeutralElement("span");
|
2011-12-06 07:50:25 +04:00
|
|
|
this.wrapper.style.display = "inline-block";
|
|
|
|
this.wrapper.appendChild(this.elmt);
|
2011-12-14 02:57:40 +04:00
|
|
|
|
2011-12-06 07:50:25 +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 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.container.insertBefore(this.wrapper, this.container.firstChild);
|
|
|
|
} else {
|
|
|
|
this.container.appendChild(this.wrapper);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Control.prototype = {
|
|
|
|
destroy: function() {
|
|
|
|
this.wrapper.removeChild(this.elmt);
|
|
|
|
this.container.removeChild(this.wrapper);
|
|
|
|
},
|
|
|
|
isVisible: function() {
|
|
|
|
return this.wrapper.style.display != "none";
|
|
|
|
},
|
|
|
|
setVisible: function(visible) {
|
|
|
|
this.wrapper.style.display = visible ? "inline-block" : "none";
|
|
|
|
},
|
|
|
|
setOpacity: function(opacity) {
|
2012-01-18 03:30:41 +04:00
|
|
|
if (this.elmt[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.setElementOpacity(this.elmt, opacity, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-18 03:30:41 +04:00
|
|
|
$.setElementOpacity(this.wrapper, opacity, true);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
2011-12-07 05:26:06 +04:00
|
|
|
/**
|
|
|
|
* OpenSeadragon Viewer
|
|
|
|
*
|
|
|
|
* The main point of entry into creating a zoomable image on the page.
|
|
|
|
*
|
|
|
|
* We have provided an idiomatic javascript constructor which takes
|
|
|
|
* a single object, but still support the legacy positional arguments.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* options:{
|
|
|
|
* element: String id of Element to attach to,
|
|
|
|
* xmlPath: String xpath ( TODO: not sure! ),
|
|
|
|
* prefixUrl: String url used to prepend to paths, eg button images,
|
|
|
|
* controls: Array of Seadragon.Controls,
|
|
|
|
* overlays: Array of Seadragon.Overlays,
|
|
|
|
* overlayControls: An Array of ( TODO: not sure! )
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
$.Viewer = function( options ) {
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
var args = arguments,
|
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
$.EventHandler.call( this );
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
if( typeof( options ) != 'object' ){
|
|
|
|
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,
|
|
|
|
overlayControls: args.length > 5 ? args[ 5 ] : undefined,
|
|
|
|
config: {}
|
|
|
|
};
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
//Allow the options object to override global defaults
|
|
|
|
$.extend( true, this, {
|
|
|
|
id: options.id,
|
2011-12-08 06:10:13 +04:00
|
|
|
xmlPath: null,
|
|
|
|
prefixUrl: '',
|
|
|
|
controls: [],
|
|
|
|
overlays: [],
|
|
|
|
overlayControls: [],
|
2011-12-07 05:26:06 +04:00
|
|
|
config: {
|
|
|
|
debugMode: true,
|
|
|
|
animationTime: 1.5,
|
|
|
|
blendTime: 0.5,
|
|
|
|
alwaysBlend: false,
|
|
|
|
autoHideControls: true,
|
|
|
|
immediateRender: false,
|
|
|
|
wrapHorizontal: false,
|
|
|
|
wrapVertical: false,
|
|
|
|
minZoomImageRatio: 0.8,
|
|
|
|
maxZoomPixelRatio: 2,
|
|
|
|
visibilityRatio: 0.5,
|
|
|
|
springStiffness: 5.0,
|
2011-12-28 03:01:20 +04:00
|
|
|
imageLoaderLimit: 0,
|
2011-12-07 05:26:06 +04:00
|
|
|
clickTimeThreshold: 200,
|
|
|
|
clickDistThreshold: 5,
|
|
|
|
zoomPerClick: 2.0,
|
|
|
|
zoomPerScroll: 1.2,
|
|
|
|
zoomPerSecond: 2.0,
|
|
|
|
showNavigationControl: true,
|
|
|
|
maxImageCacheCount: 100,
|
|
|
|
minPixelRatio: 0.5,
|
|
|
|
mouseNavEnabled: true,
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
},
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//These were referenced but never defined
|
|
|
|
controlsFadeDelay: 2000,
|
|
|
|
controlsFadeLength: 1500,
|
|
|
|
|
|
|
|
//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,
|
|
|
|
profiler: null,
|
|
|
|
|
|
|
|
//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.
|
|
|
|
customControls: []
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
}, options );
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.element = document.getElementById( options.id );
|
2012-01-18 03:30:41 +04:00
|
|
|
this.container = $.makeNeutralElement("div");
|
|
|
|
this.canvas = $.makeNeutralElement("div");
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
this._fsBoundsDelta = new $.Point( 1, 1 );
|
2011-12-08 06:10:13 +04:00
|
|
|
this._prevContainerSize = null;
|
|
|
|
this._lastOpenStartTime = 0;
|
|
|
|
this._lastOpenEndTime = 0;
|
|
|
|
this._animating = false;
|
|
|
|
this._forceRedraw = false;
|
|
|
|
this._mouseInside = false;
|
|
|
|
|
2011-12-13 02:40:49 +04:00
|
|
|
this.innerTracker = new $.MouseTracker(
|
2011-12-08 06:10:13 +04:00
|
|
|
this.canvas,
|
|
|
|
this.config.clickTimeThreshold,
|
|
|
|
this.config.clickDistThreshold
|
|
|
|
);
|
2011-12-13 02:40:49 +04:00
|
|
|
this.innerTracker.clickHandler = $.delegate(this, onCanvasClick);
|
|
|
|
this.innerTracker.dragHandler = $.delegate(this, onCanvasDrag);
|
|
|
|
this.innerTracker.releaseHandler = $.delegate(this, onCanvasRelease);
|
|
|
|
this.innerTracker.scrollHandler = $.delegate(this, onCanvasScroll);
|
|
|
|
this.innerTracker.setTracking( true ); // default state
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-13 02:40:49 +04:00
|
|
|
this.outerTracker = new $.MouseTracker(
|
2011-12-08 06:10:13 +04:00
|
|
|
this.container,
|
|
|
|
this.config.clickTimeThreshold,
|
|
|
|
this.config.clickDistThreshold
|
|
|
|
);
|
2011-12-13 02:40:49 +04:00
|
|
|
this.outerTracker.enterHandler = $.delegate(this, onContainerEnter);
|
|
|
|
this.outerTracker.exitHandler = $.delegate(this, onContainerExit);
|
|
|
|
this.outerTracker.releaseHandler = $.delegate(this, onContainerRelease);
|
|
|
|
this.outerTracker.setTracking( true ); // always tracking
|
2011-12-08 06:10:13 +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 ));
|
|
|
|
|
|
|
|
var layouts = [ 'topleft', 'topright', 'bottomright', 'bottomleft'],
|
|
|
|
layout;
|
|
|
|
|
|
|
|
for( i = 0; i < layouts.length; i++ ){
|
|
|
|
layout = layouts[ i ]
|
2012-01-18 03:30:41 +04:00
|
|
|
this.controls[ layout ] = $.makeNeutralElement("div");
|
2011-12-08 06:10:13 +04:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
this._group = null;
|
|
|
|
this._zooming = false; // whether we should be continuously zooming
|
|
|
|
this._zoomFactor = null; // how much we should be continuously zooming by
|
|
|
|
this._lastZoomTime = null;
|
|
|
|
|
|
|
|
this.elmt = null;
|
|
|
|
|
|
|
|
var beginZoomingInHandler = $.delegate(this, beginZoomingIn);
|
|
|
|
var endZoomingHandler = $.delegate(this, endZooming);
|
|
|
|
var doSingleZoomInHandler = $.delegate(this, doSingleZoomIn);
|
|
|
|
var beginZoomingOutHandler = $.delegate(this, beginZoomingOut);
|
|
|
|
var doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut);
|
|
|
|
var onHomeHandler = $.delegate(this, onHome);
|
|
|
|
var onFullPageHandler = $.delegate(this, onFullPage);
|
|
|
|
|
|
|
|
var navImages = this.config.navImages;
|
|
|
|
|
|
|
|
var zoomIn = new $.Button({
|
|
|
|
config: this.config,
|
|
|
|
tooltip: $.Strings.getString("Tooltips.ZoomIn"),
|
|
|
|
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
|
|
|
|
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
|
|
|
|
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
|
|
|
|
srcDown: resolveUrl(this.urlPrefix, navImages.zoomIn.DOWN),
|
|
|
|
onPress: beginZoomingInHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomInHandler,
|
|
|
|
onEnter: beginZoomingInHandler,
|
|
|
|
onExit: endZoomingHandler
|
|
|
|
});
|
|
|
|
|
|
|
|
var zoomOut = new $.Button({
|
|
|
|
config: this.config,
|
|
|
|
tooltip: $.Strings.getString("Tooltips.ZoomOut"),
|
|
|
|
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
|
|
|
|
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
|
|
|
|
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
|
|
|
|
srcDown: resolveUrl(this.urlPrefix, navImages.zoomOut.DOWN),
|
|
|
|
onPress: beginZoomingOutHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomOutHandler,
|
|
|
|
onEnter: beginZoomingOutHandler,
|
|
|
|
onExit: endZoomingHandler
|
|
|
|
});
|
|
|
|
var goHome = new $.Button({
|
|
|
|
config: this.config,
|
|
|
|
tooltip: $.Strings.getString("Tooltips.Home"),
|
|
|
|
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
|
|
|
|
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
|
|
|
|
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
|
|
|
|
srcDown: resolveUrl(this.urlPrefix, navImages.home.DOWN),
|
|
|
|
onRelease: onHomeHandler
|
|
|
|
});
|
|
|
|
var fullPage = new $.Button({
|
|
|
|
config: this.config,
|
|
|
|
tooltip: $.Strings.getString("Tooltips.FullPage"),
|
|
|
|
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
|
|
|
|
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
|
|
|
|
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
|
|
|
|
srcDown: resolveUrl(this.urlPrefix, navImages.fullpage.DOWN),
|
|
|
|
onRelease: onFullPageHandler
|
|
|
|
});
|
|
|
|
|
|
|
|
this._group = new $.ButtonGroup({
|
|
|
|
config: this.config,
|
|
|
|
buttons: [ zoomIn, zoomOut, goHome, fullPage ]
|
|
|
|
});
|
|
|
|
|
|
|
|
this.navControl = this._group.element;
|
|
|
|
this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade
|
|
|
|
this.addHandler( 'open', $.delegate( this, lightUp ) );
|
|
|
|
|
2011-12-13 02:45:43 +04:00
|
|
|
if ( this.config.showNavigationControl ) {
|
2011-12-13 16:24:34 +04:00
|
|
|
this.navControl.style.marginRight = "4px";
|
|
|
|
this.navControl.style.marginBottom = "4px";
|
|
|
|
this.addControl(this.navControl, $.ControlAnchor.BOTTOM_RIGHT);
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
for ( i = 0; i < this.customControls.length; i++ ) {
|
|
|
|
this.addControl(
|
|
|
|
this.customControls[ i ].id,
|
|
|
|
this.customControls[ i ].anchor
|
|
|
|
);
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.container.appendChild( this.canvas );
|
|
|
|
this.container.appendChild( this.controls.topleft );
|
|
|
|
this.container.appendChild( this.controls.topright );
|
|
|
|
this.container.appendChild( this.controls.bottomright );
|
|
|
|
this.container.appendChild( this.controls.bottomleft );
|
|
|
|
this.element.appendChild( this.container );
|
2011-12-07 05:26:06 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
if (this.xmlPath){
|
|
|
|
this.openDzi( this.xmlPath );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
$.extend($.Viewer.prototype, $.EventHandler.prototype, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
addControl: function ( elmt, anchor ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var elmt = $.getElement( elmt ),
|
2011-12-08 06:10:13 +04:00
|
|
|
div = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
if ( getControlIndex( this, elmt ) >= 0 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return; // they're trying to add a duplicate control
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
switch ( anchor ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
case $.ControlAnchor.TOP_RIGHT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.topright;
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.position = "relative";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_RIGHT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.bottomright;
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.position = "relative";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_LEFT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.bottomleft;
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.position = "relative";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.TOP_LEFT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.topleft;
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.position = "relative";
|
|
|
|
break;
|
|
|
|
case $.ControlAnchor.NONE:
|
|
|
|
default:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.container;
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.position = "absolute";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.controls.push(
|
|
|
|
new $.Control( elmt, anchor, div )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
elmt.style.display = "inline-block";
|
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
isOpen: function () {
|
|
|
|
return !!this.source;
|
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
openDzi: function (xmlUrl, xmlString) {
|
2011-12-13 07:40:02 +04:00
|
|
|
var _this = this;
|
2011-12-08 06:10:13 +04:00
|
|
|
$.DziTileSourceHelper.createFromXml(
|
|
|
|
xmlUrl,
|
|
|
|
xmlString,
|
2011-12-13 07:40:02 +04:00
|
|
|
function( source ){
|
|
|
|
_this.open( source );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
openTileSource: function ( tileSource ) {
|
|
|
|
var _this = this;
|
|
|
|
window.setTimeout( function () {
|
|
|
|
_this.open( tileSource );
|
2011-12-23 05:47:21 +04:00
|
|
|
}, 1 );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
open: function( source ) {
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
if ( this.source ) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._lastOpenStartTime = new Date().getTime(); // to ignore earlier opens
|
|
|
|
|
|
|
|
window.setTimeout( function () {
|
|
|
|
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
|
|
|
|
_this._setMessage( $.Strings.getString( "Messages.Loading" ) );
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
this._lastOpenEndTime = new Date().getTime();
|
|
|
|
|
|
|
|
if ( this._lastOpenStartTime < viewer._lastOpenStartTime ) {
|
|
|
|
$.Debug.log( "Ignoring out-of-date open." );
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "ignore" );
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-01-18 03:30:41 +04:00
|
|
|
this._prevContainerSize = $.getElementSize( this.container );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
if( source ){
|
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
this.viewport = new $.Viewport(
|
|
|
|
this._prevContainerSize,
|
|
|
|
this.source.dimensions,
|
|
|
|
this.config
|
|
|
|
);
|
|
|
|
this.drawer = new $.Drawer(
|
|
|
|
this.source,
|
|
|
|
this.viewport,
|
|
|
|
this.canvas
|
|
|
|
);
|
|
|
|
this.profiler = new $.Profiler();
|
|
|
|
|
|
|
|
this._animating = false;
|
|
|
|
this._forceRedraw = true;
|
2011-12-23 05:47:21 +04:00
|
|
|
scheduleUpdate( this, updateMulti );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
for ( var i = 0; i < this.overlayControls.length; i++ ) {
|
|
|
|
var overlay = this.overlayControls[ i ];
|
|
|
|
if (overlay.point != null) {
|
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Point(
|
|
|
|
overlay.point.X,
|
|
|
|
overlay.point.Y
|
|
|
|
),
|
|
|
|
$.OverlayPlacement.TOP_LEFT
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Rect(
|
|
|
|
overlay.rect.Point.X,
|
|
|
|
overlay.rect.Point.Y,
|
|
|
|
overlay.rect.Width,
|
|
|
|
overlay.rect.Height
|
|
|
|
),
|
|
|
|
overlay.placement
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "open" );
|
2011-12-13 07:40:02 +04:00
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
|
|
|
|
this.source = null;
|
|
|
|
this.viewport = null;
|
|
|
|
this.drawer = null;
|
|
|
|
this.profiler = null;
|
|
|
|
|
|
|
|
this.canvas.innerHTML = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-08 06:10:13 +04:00
|
|
|
removeControl: function ( elmt ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
var elmt = $.getElement( elmt ),
|
2011-12-08 06:10:13 +04:00
|
|
|
i = getControlIndex( this, elmt );
|
|
|
|
if ( i >= 0 ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
this.controls[ i ].destroy();
|
|
|
|
this.controls.splice( i, 1 );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
clearControls: function () {
|
2011-12-07 05:26:06 +04:00
|
|
|
while ( this.controls.length > 0 ) {
|
|
|
|
this.controls.pop().destroy();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
isDashboardEnabled: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
var i;
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
if (this.controls[ i ].isVisible()) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
isFullPage: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
return this.container.parentNode == document.body;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
isMouseNavEnabled: function () {
|
2011-12-13 02:40:49 +04:00
|
|
|
return this.innerTracker.isTracking();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
isVisible: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
return this.container.style.visibility != "hidden";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
setDashboardEnabled: function (enabled) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var i;
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
this.controls[ i ].setVisible( enabled );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
setFullPage: function( fullPage ) {
|
|
|
|
if ( fullPage == this.isFullPage() ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
var body = document.body,
|
|
|
|
bodyStyle = body.style,
|
|
|
|
docStyle = document.documentElement.style,
|
|
|
|
containerStyle = this.container.style,
|
|
|
|
canvasStyle = this.canvas.style,
|
|
|
|
oldBounds,
|
|
|
|
newBounds;
|
|
|
|
|
|
|
|
if ( fullPage ) {
|
|
|
|
|
|
|
|
bodyOverflow = bodyStyle.overflow;
|
|
|
|
docOverflow = docStyle.overflow;
|
|
|
|
bodyStyle.overflow = "hidden";
|
|
|
|
docStyle.overflow = "hidden";
|
|
|
|
|
|
|
|
bodyWidth = bodyStyle.width;
|
|
|
|
bodyHeight = bodyStyle.height;
|
|
|
|
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";
|
2011-12-08 06:10:13 +04:00
|
|
|
containerStyle.zIndex = "99999999";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
body.appendChild( this.container );
|
2012-01-18 03:30:41 +04:00
|
|
|
this._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
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
bodyStyle.overflow = bodyOverflow;
|
|
|
|
docStyle.overflow = docOverflow;
|
|
|
|
|
|
|
|
bodyStyle.width = bodyWidth;
|
|
|
|
bodyStyle.height = 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
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.element.appendChild( this.container );
|
2012-01-18 03:30:41 +04:00
|
|
|
this._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();
|
2011-12-06 07:50:25 +04:00
|
|
|
this.viewport.resize(this._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 ) {
|
|
|
|
this._fsBoundsDelta = new $.Point(
|
|
|
|
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(
|
|
|
|
this._fsBoundsDelta.x,
|
|
|
|
this._fsBoundsDelta.y
|
|
|
|
),
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this._forceRedraw = true;
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "resize", this );
|
2011-12-23 05:36:17 +04:00
|
|
|
updateOnce( this );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
setMouseNavEnabled: function( enabled ){
|
2011-12-13 02:40:49 +04:00
|
|
|
this.innerTracker.setTracking( enabled );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
setVisible: function( visible ){
|
|
|
|
this.container.style.visibility = visible ? "" : "hidden";
|
|
|
|
}
|
|
|
|
|
2011-12-15 03:22:02 +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;
|
|
|
|
|
|
|
|
if (this._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;
|
|
|
|
targetTime = prevUpdateTime + 1000 / 60; // 60 fps ideal
|
|
|
|
deltaTime = Math.max(1, targetTime - currentTime);
|
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
return window.setTimeout( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
}, deltaTime );
|
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
|
|
|
};
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//initiates an animation to hide the controls
|
|
|
|
function beginControlsAutoHide( viewer ) {
|
|
|
|
if ( !viewer.config.autoHideControls ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
viewer.controlsShouldFade = true;
|
|
|
|
viewer.controlsFadeBeginTime =
|
|
|
|
new Date().getTime() +
|
|
|
|
viewer.controlsFadeDelay;
|
|
|
|
|
|
|
|
window.setTimeout( function(){
|
|
|
|
scheduleControlsFade( viewer );
|
|
|
|
}, viewer.controlsFadeDelay );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
opacity = 1.0 - deltaTime / viewer.controlsFadeLength;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default view event handlers.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function onCanvasClick(tracker, position, quick, shift) {
|
|
|
|
var zoomPreClick,
|
|
|
|
factor;
|
|
|
|
if (this.viewport && quick) { // ignore clicks where mouse moved
|
|
|
|
zoomPerClick = this.config.zoomPerClick;
|
|
|
|
factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
|
|
|
|
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true));
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onCanvasDrag(tracker, position, delta, shift) {
|
|
|
|
if (this.viewport) {
|
|
|
|
this.viewport.panBy(this.viewport.deltaPointsFromPixels(delta.negate()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onCanvasRelease(tracker, position, insideElmtPress, insideElmtRelease) {
|
|
|
|
if (insideElmtPress && this.viewport) {
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onCanvasScroll(tracker, position, scroll, shift) {
|
|
|
|
var factor;
|
|
|
|
if (this.viewport) {
|
|
|
|
factor = Math.pow(this.config.zoomPerScroll, scroll);
|
|
|
|
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true));
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onContainerExit(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
|
|
if (!buttonDownElmt) {
|
|
|
|
this._mouseInside = false;
|
|
|
|
if (!this._animating) {
|
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onContainerRelease(tracker, position, insideElmtPress, insideElmtRelease) {
|
|
|
|
if (!insideElmtRelease) {
|
|
|
|
this._mouseInside = false;
|
|
|
|
if (!this._animating) {
|
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onContainerEnter(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
|
|
this._mouseInside = true;
|
|
|
|
abortControlsAutoHide( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-13 07:40:02 +04:00
|
|
|
// Utility methods
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function getControlIndex( viewer, elmt ) {
|
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( viewer.controls[ i ].elmt == elmt ) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Page update routines ( aka Views - for future reference )
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-23 05:47:21 +04:00
|
|
|
|
|
|
|
function updateMulti( viewer ) {
|
|
|
|
if (!viewer.source) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var beginTime = new Date().getTime();
|
|
|
|
|
|
|
|
updateOnce( viewer );
|
|
|
|
scheduleUpdate( viewer, arguments.callee, beginTime );
|
|
|
|
};
|
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
function updateOnce( viewer ) {
|
|
|
|
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-18 03:30:41 +04:00
|
|
|
var containerSize = $.getElementSize( viewer.container );
|
2011-12-23 05:36:17 +04:00
|
|
|
|
|
|
|
if ( !containerSize.equals( viewer._prevContainerSize ) ) {
|
|
|
|
viewer.viewport.resize( containerSize, true ); // maintain image position
|
|
|
|
viewer._prevContainerSize = containerSize;
|
|
|
|
viewer.raiseEvent( "resize" );
|
|
|
|
}
|
|
|
|
|
|
|
|
var animated = viewer.viewport.update();
|
|
|
|
|
|
|
|
if ( !viewer._animating && animated ) {
|
|
|
|
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();
|
|
|
|
viewer.raiseEvent( "animation" );
|
|
|
|
} else if ( viewer._forceRedraw || viewer.drawer.needsUpdate() ) {
|
|
|
|
viewer.drawer.update();
|
|
|
|
viewer._forceRedraw = false;
|
2011-12-28 03:20:45 +04:00
|
|
|
}
|
2011-12-23 05:36:17 +04:00
|
|
|
|
|
|
|
if ( viewer._animating && !animated ) {
|
|
|
|
viewer.raiseEvent( "animationfinish" );
|
|
|
|
|
|
|
|
if ( !viewer._mouseInside ) {
|
|
|
|
beginControlsAutoHide( viewer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer._animating = animated;
|
|
|
|
|
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
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function resolveUrl( prefix, url ) {
|
|
|
|
return prefix ? prefix + url : url;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function beginZoomingIn() {
|
|
|
|
this._lastZoomTime = +new Date();
|
|
|
|
this._zoomFactor = this.config.zoomPerSecond;
|
|
|
|
this._zooming = true;
|
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
function beginZoomingOut() {
|
|
|
|
this._lastZoomTime = +new Date();
|
|
|
|
this._zoomFactor = 1.0 / this.config.zoomPerSecond;
|
|
|
|
this._zooming = true;
|
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
function endZooming() {
|
|
|
|
this._zooming = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scheduleZoom( viewer ) {
|
|
|
|
window.setTimeout($.delegate(viewer, doZoom), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
function doZoom() {
|
|
|
|
if (this._zooming && this.viewport) {
|
|
|
|
var currentTime = +new Date();
|
|
|
|
var deltaTime = currentTime - this._lastZoomTime;
|
|
|
|
var adjustedFactor = Math.pow(this._zoomFactor, deltaTime / 1000);
|
|
|
|
|
|
|
|
this.viewport.zoomBy(adjustedFactor);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
this._lastZoomTime = currentTime;
|
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function doSingleZoomIn() {
|
|
|
|
if (this.viewport) {
|
|
|
|
this._zooming = false;
|
|
|
|
this.viewport.zoomBy(
|
|
|
|
this.config.zoomPerClick / 1.0
|
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function doSingleZoomOut() {
|
|
|
|
if (this.viewport) {
|
|
|
|
this._zooming = false;
|
|
|
|
this.viewport.zoomBy(
|
|
|
|
1.0 / this.config.zoomPerClick
|
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function lightUp() {
|
|
|
|
this._group.emulateEnter();
|
|
|
|
this._group.emulateExit();
|
|
|
|
};
|
|
|
|
|
|
|
|
function onHome() {
|
|
|
|
if (this.viewport) {
|
|
|
|
this.viewport.goHome();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onFullPage() {
|
|
|
|
this.setFullPage( !this.isFullPage() );
|
|
|
|
this._group.emulateExit(); // correct for no mouseout event on change
|
|
|
|
|
|
|
|
if (this.viewport) {
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(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.
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
$.Strings = {
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
Errors: {
|
2012-01-12 03:22:13 +04:00
|
|
|
Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" +
|
2011-12-06 07:50:25 +04:00
|
|
|
"Please try using IE 7 or Firefox 3.\n",
|
2012-01-12 03:22:13 +04:00
|
|
|
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.",
|
2011-12-06 07:50:25 +04:00
|
|
|
ImageFormat: "Sorry, we don't support {0}-based Deep Zoom Images.",
|
2012-01-12 03:22:13 +04:00
|
|
|
Security: "It looks like a security restriction stopped us from " +
|
2011-12-06 07:50:25 +04:00
|
|
|
"loading this Deep Zoom Image.",
|
2012-01-12 03:22:13 +04:00
|
|
|
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-01-12 03:22:13 +04:00
|
|
|
Loading: "Loading..."
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
Tooltips: {
|
2012-01-12 03:22:13 +04:00
|
|
|
FullPage: "Toggle full page",
|
|
|
|
Home: "Go home",
|
|
|
|
ZoomIn: "Zoom in",
|
|
|
|
ZoomOut: "Zoom out"
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
getString: function( prop ) {
|
|
|
|
|
|
|
|
var props = prop.split('.'),
|
|
|
|
string = $.Strings,
|
|
|
|
args = arguments,
|
|
|
|
i;
|
|
|
|
|
|
|
|
for ( i = 0; i < props.length; i++ ) {
|
|
|
|
string = string[ props[ i ] ] || {}; // in case not a subproperty
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-28 05:58:16 +04:00
|
|
|
$.Point = function(x, y) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.x = typeof (x) == "number" ? x : 0;
|
|
|
|
this.y = typeof (y) == "number" ? y : 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Point.prototype = {
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
apply: function( func ) {
|
|
|
|
return new $.Point( func(this.x), func(this.y) );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
equals: function( point ) {
|
|
|
|
return ( point instanceof $.Point ) &&
|
|
|
|
( this.x === point.x ) &&
|
|
|
|
( this.y === point.y );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
toString: function() {
|
|
|
|
return "(" + this.x + "," + this.y + ")";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
$.Profiler = function() {
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = false;
|
|
|
|
this.numUpdates = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastBeginTime = null;
|
|
|
|
this.lastEndTime = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minUpdateTime = Infinity;
|
|
|
|
this.avgUpdateTime = 0;
|
|
|
|
this.maxUpdateTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minIdleTime = Infinity;
|
|
|
|
this.avgIdleTime = 0;
|
|
|
|
this.maxIdleTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Profiler.prototype = {
|
|
|
|
|
|
|
|
beginUpdate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
if (this.midUpdate) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.endUpdate();
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = true;
|
|
|
|
this.lastBeginTime = new Date().getTime();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (this.numUpdates < 1) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return; // this is the first update
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
var time = this.lastBeginTime - this.lastEndTime;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.avgIdleTime = (this.avgIdleTime * (this.numUpdates - 1) + time) / this.numUpdates;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time < this.minIdleTime) {
|
|
|
|
this.minIdleTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time > this.maxIdleTime) {
|
|
|
|
this.maxIdleTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
endUpdate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
if (!this.midUpdate) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastEndTime = new Date().getTime();
|
|
|
|
this.midUpdate = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
var time = this.lastEndTime - this.lastBeginTime;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.numUpdates++;
|
|
|
|
this.avgUpdateTime = (this.avgUpdateTime * (this.numUpdates - 1) + time) / this.numUpdates;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time < this.minUpdateTime) {
|
|
|
|
this.minUpdateTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time > this.maxUpdateTime) {
|
|
|
|
this.maxUpdateTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearProfile: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = false;
|
|
|
|
this.numUpdates = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastBeginTime = null;
|
|
|
|
this.lastEndTime = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minUpdateTime = Infinity;
|
|
|
|
this.avgUpdateTime = 0;
|
|
|
|
this.maxUpdateTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minIdleTime = Infinity;
|
|
|
|
this.avgIdleTime = 0;
|
|
|
|
this.maxIdleTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
$.TileSource = function(width, height, tileSize, tileOverlap, minLevel, maxLevel) {
|
|
|
|
this.aspectRatio = width / height;
|
|
|
|
this.dimensions = new $.Point(width, height);
|
|
|
|
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
|
|
|
this.tileSize = tileSize ? tileSize : 0;
|
|
|
|
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.TileSource.prototype = {
|
|
|
|
getLevelScale: function(level) {
|
|
|
|
return 1 / (1 << (this.maxLevel - level));
|
|
|
|
},
|
|
|
|
|
|
|
|
getNumTiles: function(level) {
|
|
|
|
var scale = this.getLevelScale(level);
|
|
|
|
var x = Math.ceil(scale * this.dimensions.x / this.tileSize);
|
|
|
|
var y = Math.ceil(scale * this.dimensions.y / this.tileSize);
|
|
|
|
|
|
|
|
return new $.Point(x, y);
|
|
|
|
},
|
|
|
|
|
|
|
|
getPixelRatio: function(level) {
|
|
|
|
var imageSizeScaled = this.dimensions.times(this.getLevelScale(level));
|
|
|
|
var rx = 1.0 / imageSizeScaled.x;
|
|
|
|
var ry = 1.0 / imageSizeScaled.y;
|
|
|
|
|
|
|
|
return new $.Point(rx, ry);
|
|
|
|
},
|
|
|
|
|
|
|
|
getTileAtPoint: function(level, point) {
|
|
|
|
var pixel = point.times(this.dimensions.x).times(this.getLevelScale(level));
|
|
|
|
|
|
|
|
var tx = Math.floor(pixel.x / this.tileSize);
|
|
|
|
var ty = Math.floor(pixel.y / this.tileSize);
|
|
|
|
|
|
|
|
return new $.Point(tx, ty);
|
|
|
|
},
|
|
|
|
|
|
|
|
getTileBounds: function(level, x, y) {
|
|
|
|
var dimensionsScaled = this.dimensions.times(this.getLevelScale(level));
|
|
|
|
|
|
|
|
var px = (x === 0) ? 0 : this.tileSize * x - this.tileOverlap;
|
|
|
|
var py = (y === 0) ? 0 : this.tileSize * y - this.tileOverlap;
|
|
|
|
|
|
|
|
var sx = this.tileSize + (x === 0 ? 1 : 2) * this.tileOverlap;
|
|
|
|
var sy = this.tileSize + (y === 0 ? 1 : 2) * this.tileOverlap;
|
|
|
|
|
|
|
|
sx = Math.min(sx, dimensionsScaled.x - px);
|
|
|
|
sy = Math.min(sy, dimensionsScaled.y - py);
|
|
|
|
|
|
|
|
var scale = 1.0 / dimensionsScaled.x;
|
|
|
|
return new $.Rect(px * scale, py * scale, sx * scale, sy * scale);
|
|
|
|
},
|
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
getTileUrl: function( level, x, y ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
throw new Error("Method not implemented.");
|
|
|
|
},
|
|
|
|
|
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( $ ){
|
|
|
|
|
|
|
|
|
|
|
|
$.DziTileSource = function(width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects) {
|
|
|
|
$.TileSource.call(this, width, height, tileSize, tileOverlap, null, null);
|
|
|
|
|
|
|
|
this._levelRects = {};
|
|
|
|
this.tilesUrl = tilesUrl;
|
|
|
|
|
|
|
|
this.fileFormat = fileFormat;
|
|
|
|
this.displayRects = displayRects;
|
2011-12-14 03:34:12 +04:00
|
|
|
|
|
|
|
if ( this.displayRects ) {
|
2011-12-14 03:29:25 +04:00
|
|
|
for (var i = this.displayRects.length - 1; i >= 0; i--) {
|
|
|
|
var rect = this.displayRects[i];
|
|
|
|
for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
|
|
|
|
if (!this._levelRects[level]) {
|
|
|
|
this._levelRects[level] = [];
|
|
|
|
}
|
|
|
|
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, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
getTileUrl: function(level, x, y) {
|
|
|
|
return [this.tilesUrl, level, '/', x, '_', y, '.', this.fileFormat].join('');
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
tileExists: function(level, x, y) {
|
|
|
|
var rects = this._levelRects[level];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
if (!rects || !rects.length) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
for (var i = rects.length - 1; i >= 0; i--) {
|
|
|
|
var rect = rects[i];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
if (level < rect.minLevel || level > rect.maxLevel) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
var scale = this.getLevelScale(level);
|
|
|
|
var xMin = rect.x * scale;
|
|
|
|
var yMin = rect.y * scale;
|
|
|
|
var xMax = xMin + rect.width * scale;
|
|
|
|
var yMax = yMin + rect.height * scale;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 03:29:25 +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
|
|
|
|
2011-12-14 03:29:25 +04:00
|
|
|
if (xMin <= x && x < xMax && yMin <= y && y < yMax) {
|
|
|
|
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
|
|
|
|
2011-12-14 03:24:04 +04:00
|
|
|
$.DziTileSourceHelper = {
|
2011-12-06 07:50:25 +04:00
|
|
|
createFromXml: function(xmlUrl, xmlString, callback) {
|
|
|
|
var async = typeof (callback) == "function";
|
|
|
|
var error = null;
|
|
|
|
|
|
|
|
if (!xmlUrl) {
|
|
|
|
this.error = $.Strings.getString("Errors.Empty");
|
|
|
|
if (async) {
|
|
|
|
window.setTimeout(function() {
|
|
|
|
callback(null, error);
|
|
|
|
}, 1);
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error(error);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var urlParts = xmlUrl.split('/');
|
|
|
|
var filename = urlParts[urlParts.length - 1];
|
|
|
|
var lastDot = filename.lastIndexOf('.');
|
|
|
|
|
|
|
|
if (lastDot > -1) {
|
|
|
|
urlParts[urlParts.length - 1] = filename.slice(0, lastDot);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tilesUrl = urlParts.join('/') + "_files/";
|
|
|
|
function finish(func, obj) {
|
|
|
|
try {
|
|
|
|
return func(obj, tilesUrl);
|
|
|
|
} catch (e) {
|
|
|
|
if (async) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2011-12-14 03:17:46 +04:00
|
|
|
throw e;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (async) {
|
|
|
|
if (xmlString) {
|
|
|
|
var handler = $.delegate(this, this.processXml);
|
|
|
|
window.setTimeout(function() {
|
2012-01-18 03:30:41 +04:00
|
|
|
var source = finish(handler, $.parseXml(xmlString));
|
2011-12-06 07:50:25 +04:00
|
|
|
callback(source, error); // call after finish sets error
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
var handler = $.delegate(this, this.processResponse);
|
2012-01-18 03:30:41 +04:00
|
|
|
$.makeAjaxRequest(xmlUrl, function(xhr) {
|
2011-12-06 07:50:25 +04:00
|
|
|
var source = finish(handler, xhr);
|
|
|
|
callback(source, error); // call after finish sets error
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xmlString) {
|
2012-01-18 03:30:41 +04:00
|
|
|
return finish($.delegate(this, this.processXml), $.parseXml(xmlString));
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-18 03:30:41 +04:00
|
|
|
return finish($.delegate(this, this.processResponse), $.makeAjaxRequest(xmlUrl));
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
processResponse: function(xhr, tilesUrl) {
|
|
|
|
if (!xhr) {
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.Security"));
|
2011-12-06 07:50:25 +04:00
|
|
|
} else if (xhr.status !== 200 && xhr.status !== 0) {
|
|
|
|
var status = xhr.status;
|
|
|
|
var statusText = (status == 404) ? "Not Found" : xhr.statusText;
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.Status", status, statusText));
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var doc = null;
|
|
|
|
|
|
|
|
if (xhr.responseXML && xhr.responseXML.documentElement) {
|
|
|
|
doc = xhr.responseXML;
|
|
|
|
} else if (xhr.responseText) {
|
2012-01-18 03:30:41 +04:00
|
|
|
doc = $.parseXml(xhr.responseText);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.processXml(doc, tilesUrl);
|
|
|
|
},
|
|
|
|
|
|
|
|
processXml: function(xmlDoc, tilesUrl) {
|
|
|
|
if (!xmlDoc || !xmlDoc.documentElement) {
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.Xml"));
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var root = xmlDoc.documentElement;
|
|
|
|
var rootName = root.tagName;
|
|
|
|
|
|
|
|
if (rootName == "Image") {
|
|
|
|
try {
|
|
|
|
return this.processDzi(root, tilesUrl);
|
|
|
|
} catch (e) {
|
|
|
|
var defMsg = $.Strings.getString("Errors.Dzi");
|
2011-12-14 03:17:46 +04:00
|
|
|
throw (e instanceof Error) ? e : new Error(defMsg);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
} else if (rootName == "Collection") {
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.Dzc"));
|
2011-12-06 07:50:25 +04:00
|
|
|
} else if (rootName == "Error") {
|
|
|
|
return this.processError(root);
|
|
|
|
}
|
|
|
|
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.Dzi"));
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
processDzi: function(imageNode, tilesUrl) {
|
|
|
|
var fileFormat = imageNode.getAttribute("Format");
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if (!$.imageFormatSupported(fileFormat)) {
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error($.Strings.getString("Errors.ImageFormat",
|
2011-12-06 07:50:25 +04:00
|
|
|
fileFormat.toUpperCase()));
|
|
|
|
}
|
|
|
|
|
|
|
|
var sizeNode = imageNode.getElementsByTagName("Size")[0];
|
|
|
|
var dispRectNodes = imageNode.getElementsByTagName("DisplayRect");
|
|
|
|
|
|
|
|
var width = parseInt(sizeNode.getAttribute("Width"), 10);
|
|
|
|
var height = parseInt(sizeNode.getAttribute("Height"), 10);
|
|
|
|
var tileSize = parseInt(imageNode.getAttribute("TileSize"));
|
|
|
|
var tileOverlap = parseInt(imageNode.getAttribute("Overlap"));
|
|
|
|
var dispRects = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < dispRectNodes.length; i++) {
|
|
|
|
var dispRectNode = dispRectNodes[i];
|
|
|
|
var rectNode = dispRectNode.getElementsByTagName("Rect")[0];
|
|
|
|
|
|
|
|
dispRects.push(new $.DisplayRect(
|
|
|
|
parseInt(rectNode.getAttribute("X"), 10),
|
|
|
|
parseInt(rectNode.getAttribute("Y"), 10),
|
|
|
|
parseInt(rectNode.getAttribute("Width"), 10),
|
|
|
|
parseInt(rectNode.getAttribute("Height"), 10),
|
|
|
|
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
|
|
|
|
parseInt(dispRectNode.getAttribute("MaxLevel"), 10)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return new $.DziTileSource(width, height, tileSize, tileOverlap,
|
|
|
|
tilesUrl, fileFormat, dispRects);
|
|
|
|
},
|
|
|
|
|
|
|
|
processError: function(errorNode) {
|
|
|
|
var messageNode = errorNode.getElementsByTagName("Message")[0];
|
|
|
|
var message = messageNode.firstChild.nodeValue;
|
|
|
|
|
2011-12-14 03:17:46 +04:00
|
|
|
throw new Error(message);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
$.ButtonState = {
|
|
|
|
REST: 0,
|
|
|
|
GROUP: 1,
|
|
|
|
HOVER: 2,
|
|
|
|
DOWN: 3
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.tooltip = options.tooltip;
|
|
|
|
this.srcRest = options.srcRest;
|
|
|
|
this.srcGroup = options.srcGroup;
|
|
|
|
this.srcHover = options.srcHover;
|
|
|
|
this.srcDown = options.srcDown;
|
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-01-18 03:30:41 +04:00
|
|
|
this.element = options.element || $.makeNeutralElement("span");
|
2011-12-15 02:40:22 +04:00
|
|
|
this.config = options.config;
|
2011-12-15 03:22:02 +04:00
|
|
|
|
|
|
|
if ( options.onPress != undefined ){
|
|
|
|
this.addHandler("onPress", options.onPress );
|
|
|
|
}
|
|
|
|
if ( options.onRelease != undefined ){
|
|
|
|
this.addHandler("onRelease", options.onRelease );
|
|
|
|
}
|
|
|
|
if ( options.onClick != undefined ){
|
|
|
|
this.addHandler("onClick", options.onClick );
|
|
|
|
}
|
|
|
|
if ( options.onEnter != undefined ){
|
|
|
|
this.addHandler("onEnter", options.onEnter );
|
|
|
|
}
|
|
|
|
if ( options.onExit != undefined ){
|
|
|
|
this.addHandler("onExit", options.onExit );
|
|
|
|
}
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.currentState = $.ButtonState.GROUP;
|
|
|
|
this.tracker = new $.MouseTracker(
|
2011-12-17 02:56:38 +04:00
|
|
|
this.element,
|
2011-12-15 02:40:22 +04:00
|
|
|
this.config.clickTimeThreshold,
|
|
|
|
this.config.clickDistThreshold
|
|
|
|
);
|
2012-01-18 03:30:41 +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.fadeDelay = 0; // begin fading immediately
|
|
|
|
this.fadeLength = 2000; // fade over a period of 2 seconds
|
|
|
|
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 );
|
|
|
|
|
|
|
|
var styleRest = this.imgRest.style;
|
|
|
|
var styleGroup = this.imgGroup.style;
|
|
|
|
var styleHover = this.imgHover.style;
|
|
|
|
var styleDown = this.imgDown.style;
|
|
|
|
|
|
|
|
styleGroup.position =
|
|
|
|
styleHover.position =
|
|
|
|
styleDown.position =
|
|
|
|
"absolute";
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
styleGroup.top =
|
|
|
|
styleHover.top =
|
|
|
|
styleDown.top =
|
|
|
|
"0px";
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
styleGroup.left =
|
|
|
|
styleHover.left =
|
|
|
|
styleDown.left =
|
|
|
|
"0px";
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
styleHover.visibility =
|
|
|
|
styleDown.visibility =
|
|
|
|
"hidden";
|
2011-12-15 02:40:22 +04:00
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( $.Browser.vendor == $.BROWSERS.FIREFOX
|
|
|
|
&& $.Browser.version < 3 ){
|
2011-12-17 03:29:16 +04:00
|
|
|
|
|
|
|
styleGroup.top =
|
|
|
|
styleHover.top =
|
|
|
|
styleDown.top = "";
|
2011-12-15 02:40:22 +04:00
|
|
|
}
|
|
|
|
|
2011-12-20 16:39:02 +04:00
|
|
|
//TODO - refactor mousetracer next to avoid this extension
|
|
|
|
$.extend( this.tracker, {
|
|
|
|
enterHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
|
|
if ( buttonDownElmt ) {
|
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
|
|
|
_this.raiseEvent( "onEnter", _this );
|
|
|
|
} else if ( !buttonDownAny ) {
|
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
exitHandler: function(tracker, position, buttonDownElmt, buttonDownAny) {
|
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
|
|
|
if ( buttonDownElmt ) {
|
|
|
|
_this.raiseEvent( "onExit", _this );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pressHandler: function(tracker, position) {
|
|
|
|
inTo( _this, $.ButtonState.DOWN );
|
2011-12-20 16:44:33 +04:00
|
|
|
_this.raiseEvent( "onPress", _this );
|
2011-12-20 16:39:02 +04:00
|
|
|
},
|
|
|
|
releaseHandler: function(tracker, position, insideElmtPress, insideElmtRelease) {
|
|
|
|
if ( insideElmtPress && insideElmtRelease ) {
|
|
|
|
outTo( _this, $.ButtonState.HOVER );
|
2011-12-20 16:44:33 +04:00
|
|
|
_this.raiseEvent( "onRelease", _this );
|
2011-12-20 16:39:02 +04:00
|
|
|
} else if ( insideElmtPress ) {
|
|
|
|
outTo( _this, $.ButtonState.GROUP );
|
|
|
|
} else {
|
|
|
|
inTo( _this, $.ButtonState.HOVER );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clickHandler: function(tracker, position, quick, shift) {
|
|
|
|
if ( quick ) {
|
|
|
|
_this.raiseEvent("onClick", _this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-17 03:29:16 +04:00
|
|
|
this.tracker.setTracking( true );
|
|
|
|
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, {
|
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
|
|
|
},
|
|
|
|
notifyGroupExit: function() {
|
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
|
|
|
});
|
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();
|
|
|
|
deltaTime = currentTime - this.fadeBeginTime;
|
|
|
|
opacity = 1.0 - deltaTime / this.fadeLength;
|
|
|
|
opacity = Math.min( 1.0, opacity );
|
|
|
|
opacity = Math.max( 0.0, opacity );
|
|
|
|
|
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;
|
|
|
|
button.fadeBeginTime = new Date().getTime() + button.fadeDelay;
|
|
|
|
window.setTimeout(function(){
|
|
|
|
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 ) {
|
|
|
|
if ( newState >= $.ButtonState.GROUP && button.currentState == $.ButtonState.REST ) {
|
|
|
|
stopFading( button );
|
|
|
|
button.currentState = $.ButtonState.GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newState >= $.ButtonState.HOVER && button.currentState == $.ButtonState.GROUP ) {
|
|
|
|
button.imgHover.style.visibility = "";
|
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newState >= $.ButtonState.DOWN && button.currentState == $.ButtonState.HOVER ) {
|
|
|
|
button.imgDown.style.visibility = "";
|
|
|
|
button.currentState = $.ButtonState.DOWN;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function outTo( button, newState ) {
|
|
|
|
if ( newState <= $.ButtonState.HOVER && button.currentState == $.ButtonState.DOWN ) {
|
|
|
|
button.imgDown.style.visibility = "hidden";
|
|
|
|
button.currentState = $.ButtonState.HOVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if ( button.newState <= $.ButtonState.REST && button.currentState == $.ButtonState.GROUP ) {
|
|
|
|
button.beginFading();
|
|
|
|
button.currentState = $.ButtonState.REST;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
2011-12-06 23:48:20 +04:00
|
|
|
/**
|
|
|
|
* OpenSeadragon ButtonGroup
|
|
|
|
*
|
|
|
|
* Manages events on groups of buttons.
|
|
|
|
*
|
2011-12-07 05:26:06 +04:00
|
|
|
* options: {
|
|
|
|
* buttons: Array of buttons * required,
|
|
|
|
* group: Element to use as the container,
|
|
|
|
* config: Object with Viewer settings ( TODO: is this actually used anywhere? )
|
|
|
|
* enter: Function callback for when the mouse enters group
|
|
|
|
* exit: Function callback for when mouse leaves the group
|
|
|
|
* release: Function callback for when mouse is released
|
|
|
|
* }
|
2011-12-06 23:48:20 +04:00
|
|
|
**/
|
|
|
|
$.ButtonGroup = function( options ) {
|
|
|
|
|
|
|
|
this.buttons = options.buttons;
|
2012-01-18 03:30:41 +04:00
|
|
|
this.element = options.group || $.makeNeutralElement("span");
|
2011-12-06 23:48:20 +04:00
|
|
|
this.config = options.config;
|
|
|
|
this.tracker = new $.MouseTracker(
|
|
|
|
this.element,
|
|
|
|
this.config.clickTimeThreshold,
|
|
|
|
this.config.clickDistThreshold
|
|
|
|
);
|
|
|
|
|
|
|
|
// copy the botton elements
|
|
|
|
var buttons = this.buttons.concat([]),
|
|
|
|
_this = this,
|
|
|
|
i;
|
|
|
|
|
|
|
|
this.element.style.display = "inline-block";
|
|
|
|
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
|
|
|
|
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.enter = options.enter || function() {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++) {
|
|
|
|
_this.buttons[ i ].notifyGroupEnter();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.exit = options.exit || function() {
|
|
|
|
var i,
|
|
|
|
buttonDownElmt = arguments.length > 2 ? arguments[2] : null;
|
|
|
|
if ( !buttonDownElmt ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.release = options.release || function() {
|
|
|
|
var i,
|
|
|
|
insideElmtRelease = arguments.length > 3 ? arguments[3] : null;
|
|
|
|
if ( !insideElmtRelease ) {
|
|
|
|
for ( i = 0; i < _this.buttons.length; i++ ) {
|
|
|
|
_this.buttons[ i ].notifyGroupExit();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 23:48:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
this.tracker.setTracking( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ButtonGroup.prototype = {
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
emulateEnter: function() {
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.enter();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
emulateExit: function() {
|
2011-12-06 23:48:20 +04:00
|
|
|
this.tracker.exit();
|
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( $ ){
|
|
|
|
|
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 = {
|
|
|
|
getAspectRatio: function() {
|
|
|
|
return this.width / this.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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-01-18 03:30:41 +04:00
|
|
|
equals: function( other ) {
|
2011-12-30 03:16:51 +04:00
|
|
|
return
|
|
|
|
( other instanceof $.Rect ) &&
|
|
|
|
( this.x === other.x ) &&
|
|
|
|
( this.y === other.y ) &&
|
|
|
|
( this.width === other.width ) &&
|
|
|
|
( this.height === other.height );
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
$.DisplayRect.prototype = new $.Rect();
|
|
|
|
$.DisplayRect.prototype.constructor = $.DisplayRect;
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
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 :
|
|
|
|
1.5,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-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-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-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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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( $ ){
|
|
|
|
|
|
|
|
$.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;
|
|
|
|
this.bounds = bounds; // where this tile fits, in normalized coordinates
|
|
|
|
this.exists = exists; // part of sparse image? tile hasn't failed to load?
|
|
|
|
this.loaded = false; // is this tile loaded?
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false; // or is this tile loading?
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt = null; // the HTML element for this tile
|
|
|
|
this.image = null; // the Image object for this tile
|
|
|
|
this.url = url; // the URL of this tile's image
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.style = null; // alias of this.elmt.style
|
|
|
|
this.position = null; // this tile's position on screen, in pixels
|
|
|
|
this.size = null; // this tile's size on screen, in pixels
|
2011-12-06 07:50:25 +04:00
|
|
|
this.blendStart = null; // the start time of this tile's blending
|
2012-01-12 03:22:13 +04:00
|
|
|
this.opacity = null; // the current opacity this tile should be
|
|
|
|
this.distance = null; // the distance of this tile to the viewport center
|
2011-12-06 07:50:25 +04:00
|
|
|
this.visibility = null; // the visibility score of this tile
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.beingDrawn = false; // whether this tile is currently being drawn
|
|
|
|
this.lastTouchTime = 0; // the time that tile was last touched
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Tile.prototype = {
|
|
|
|
|
|
|
|
toString: function() {
|
|
|
|
return this.level + "/" + this.x + "_" + this.y;
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
|
|
|
drawHTML: function( container ) {
|
|
|
|
|
|
|
|
if ( !this.loaded ) {
|
|
|
|
$.Debug.error(
|
|
|
|
"Attempting to draw tile " +
|
|
|
|
this.toString() +
|
|
|
|
" when it's not yet loaded."
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( !this.elmt ) {
|
2012-01-18 03:30:41 +04:00
|
|
|
this.elmt = $.makeNeutralElement("img");
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt.src = this.url;
|
|
|
|
this.style = this.elmt.style;
|
|
|
|
|
|
|
|
this.style.position = "absolute";
|
2011-12-06 07:50:25 +04:00
|
|
|
this.style.msInterpolationMode = "nearest-neighbor";
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
var position = this.position.apply( Math.floor );
|
|
|
|
var size = this.size.apply( Math.ceil );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( this.elmt.parentNode != container ) {
|
|
|
|
container.appendChild( this.elmt );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.elmt.style.left = position.x + "px";
|
|
|
|
this.elmt.style.top = position.y + "px";
|
|
|
|
this.elmt.style.width = size.x + "px";
|
|
|
|
this.elmt.style.height = size.y + "px";
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
$.setElementOpacity( this.elmt, this.opacity );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
},
|
2012-01-12 03:22:13 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
drawCanvas: function(context) {
|
|
|
|
if (!this.loaded) {
|
2012-01-12 03:22:13 +04:00
|
|
|
$.Debug.error(
|
|
|
|
"Attempting to draw tile " +
|
|
|
|
this.toString() +
|
|
|
|
" when it's not yet loaded."
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
var position = this.position,
|
|
|
|
size = this.size;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
context.globalAlpha = this.opacity;
|
|
|
|
context.drawImage(this.image, position.x, position.y, size.x, size.y);
|
|
|
|
},
|
2012-01-18 03:30:41 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
unload: function() {
|
2012-01-18 03:30:41 +04:00
|
|
|
if ( this.elmt && this.elmt.parentNode ) {
|
|
|
|
this.elmt.parentNode.removeChild( this.elmt );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
this.elmt = null;
|
|
|
|
this.image = null;
|
|
|
|
this.loaded = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
$.OverlayPlacement = {
|
|
|
|
CENTER: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP: 2,
|
|
|
|
TOP_RIGHT: 3,
|
|
|
|
RIGHT: 4,
|
|
|
|
BOTTOM_RIGHT: 5,
|
|
|
|
BOTTOM: 6,
|
|
|
|
BOTTOM_LEFT: 7,
|
|
|
|
LEFT: 8
|
|
|
|
};
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
$.Overlay = function(elmt, location, placement) {
|
2011-12-14 02:40:52 +04:00
|
|
|
this.elmt = elmt;
|
2011-12-30 02:14:42 +04:00
|
|
|
this.scales = location instanceof $.Rect;
|
|
|
|
this.bounds = new $.Rect(
|
|
|
|
location.x,
|
|
|
|
location.y,
|
|
|
|
location.width,
|
|
|
|
location.height)
|
|
|
|
;
|
|
|
|
this.position = new $.Point(
|
|
|
|
location.x,
|
|
|
|
location.y
|
|
|
|
);
|
|
|
|
this.size = new $.Point(
|
|
|
|
location.width,
|
|
|
|
location.height
|
|
|
|
);
|
2011-12-14 02:40:52 +04:00
|
|
|
this.style = elmt.style;
|
|
|
|
// 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
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
adjust: function(position, size) {
|
|
|
|
switch (this.placement) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroy: function() {
|
|
|
|
var elmt = this.elmt;
|
|
|
|
var style = this.style;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
if (elmt.parentNode) {
|
|
|
|
elmt.parentNode.removeChild(elmt);
|
|
|
|
}
|
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
|
|
|
|
2011-12-14 02:40:52 +04:00
|
|
|
if (this.scales) {
|
|
|
|
style.width = "";
|
|
|
|
style.height = "";
|
|
|
|
}
|
|
|
|
},
|
2011-12-30 02:14:42 +04:00
|
|
|
drawHTML: function( container ) {
|
|
|
|
var elmt = this.elmt,
|
|
|
|
style = this.style,
|
|
|
|
scales = this.scales,
|
|
|
|
position,
|
|
|
|
size;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if ( elmt.parentNode != container ) {
|
|
|
|
container.appendChild( elmt );
|
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-18 03:30:41 +04:00
|
|
|
this.size = $.getElementSize( elmt );
|
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";
|
|
|
|
}
|
|
|
|
},
|
2011-12-30 02:14:42 +04:00
|
|
|
update: function( loc, placement ) {
|
|
|
|
this.scales = ( loc instanceof $.Rect );
|
|
|
|
this.bounds = new $.Rect(loc.x, loc.y, loc.width, loc.height);
|
|
|
|
// rects are always top-left
|
|
|
|
this.placement = loc 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-01-12 03:22:13 +04:00
|
|
|
var // the max number of images we should keep in memory
|
|
|
|
QUOTA = 100,
|
|
|
|
// the most shrunk a tile should be
|
|
|
|
MIN_PIXEL_RATIO = 0.5,
|
|
|
|
//TODO: make TIMEOUT configurable
|
|
|
|
TIMEOUT = 5000,
|
|
|
|
|
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-01-12 03:22:13 +04:00
|
|
|
),
|
|
|
|
|
|
|
|
USE_CANVAS =
|
|
|
|
$.isFunction( document.createElement("canvas").getContext ) &&
|
|
|
|
SUBPIXEL_RENDERING;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
$.Drawer = function(source, viewport, elmt) {
|
|
|
|
|
2012-01-18 03:30:41 +04:00
|
|
|
this.container = $.getElement( elmt );
|
|
|
|
this.canvas = $.makeNeutralElement( USE_CANVAS ? "canvas" : "div" );
|
2012-01-12 03:22:13 +04:00
|
|
|
this.context = USE_CANVAS ? this.canvas.getContext("2d") : null;
|
|
|
|
this.viewport = viewport;
|
|
|
|
this.source = source;
|
|
|
|
this.config = this.viewport.config;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.downloading = 0;
|
|
|
|
this.imageLoaderLimit = this.config.imageLoaderLimit;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.profiler = new $.Profiler();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
this.minLevel = source.minLevel;
|
|
|
|
this.maxLevel = source.maxLevel;
|
|
|
|
this.tileSize = source.tileSize;
|
|
|
|
this.tileOverlap = source.tileOverlap;
|
|
|
|
this.normHeight = source.dimensions.y / source.dimensions.x;
|
|
|
|
|
|
|
|
// 1d dictionary [level] --> Point
|
|
|
|
this.cacheNumTiles = {};
|
|
|
|
// 1d dictionary [level] --> Point
|
|
|
|
this.cachePixelRatios = {};
|
|
|
|
// 3d dictionary [level][x][y] --> Tile
|
|
|
|
this.tilesMatrix = {};
|
|
|
|
// unordered list of Tiles with loaded images
|
|
|
|
this.tilesLoaded = [];
|
|
|
|
// 3d dictionary [level][x][y] --> Boolean
|
|
|
|
this.coverage = {};
|
|
|
|
|
|
|
|
// unordered list of Overlays added
|
|
|
|
this.overlays = [];
|
|
|
|
// unordered list of Tiles drawn last frame
|
|
|
|
this.lastDrawn = [];
|
|
|
|
this.lastResetTime = 0;
|
|
|
|
this.midUpdate = false;
|
|
|
|
this.updateAgain = true;
|
|
|
|
|
|
|
|
this.elmt = this.container;
|
|
|
|
|
|
|
|
this.canvas.style.width = "100%";
|
|
|
|
this.canvas.style.height = "100%";
|
|
|
|
this.canvas.style.position = "absolute";
|
2012-01-12 03:25:35 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
// explicit left-align
|
|
|
|
this.container.style.textAlign = "left";
|
|
|
|
this.container.appendChild(this.canvas);
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Drawer.prototype = {
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
getPixelRatio: function( level ) {
|
|
|
|
if ( !this.cachePixelRatios[ level ] ) {
|
|
|
|
this.cachePixelRatios[ level ] = this.source.getPixelRatio( level );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
return this.cachePixelRatios[ level ];
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_getTile: function( level, x, y, time, numTilesX, numTilesY ) {
|
|
|
|
var xMod,
|
|
|
|
yMod,
|
|
|
|
bounds,
|
|
|
|
exists,
|
|
|
|
url,
|
|
|
|
tile;
|
|
|
|
|
|
|
|
if ( !this.tilesMatrix[ level ] ) {
|
|
|
|
this.tilesMatrix[ level ] = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.tilesMatrix[ level ][ x ] ) {
|
|
|
|
this.tilesMatrix[ level ][ x ] = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.tilesMatrix[ level ][ x ][ y ] ) {
|
|
|
|
xMod = ( numTilesX + ( x % numTilesX ) ) % numTilesX;
|
|
|
|
yMod = ( numTilesY + ( y % numTilesY ) ) % numTilesY;
|
|
|
|
bounds = this.source.getTileBounds( level, xMod, yMod );
|
|
|
|
exists = this.source.tileExists( level, xMod, yMod );
|
|
|
|
url = this.source.getTileUrl( level, xMod, yMod );
|
|
|
|
|
|
|
|
bounds.x += 1.0 * ( x - xMod ) / numTilesX;
|
|
|
|
bounds.y += this.normHeight * ( y - yMod ) / numTilesY;
|
|
|
|
|
|
|
|
this.tilesMatrix[ level ][ x ][ y ] = new $.Tile(
|
|
|
|
level,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
bounds,
|
|
|
|
exists,
|
|
|
|
url
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
tile = this.tilesMatrix[ level ][ x ][ y ];
|
2011-12-06 07:50:25 +04:00
|
|
|
tile.lastTouchTime = time;
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
},
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_loadTile: function( tile, time ) {
|
2011-12-28 03:17:24 +04:00
|
|
|
tile.loading = this.loadImage(
|
|
|
|
tile.url,
|
2012-01-18 03:30:41 +04:00
|
|
|
$.createCallback(
|
2011-12-28 03:17:24 +04:00
|
|
|
null,
|
2012-01-19 05:15:54 +04:00
|
|
|
$.delegate( this, this._onTileLoad ),
|
2011-12-28 03:17:24 +04:00
|
|
|
tile,
|
|
|
|
time
|
|
|
|
)
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onTileLoad: function(tile, time, image) {
|
2012-01-19 05:15:54 +04:00
|
|
|
var insertionIndex,
|
|
|
|
cutoff,
|
|
|
|
worstTile,
|
|
|
|
worstTime,
|
|
|
|
worstLevel,
|
|
|
|
worstTileIndex,
|
|
|
|
prevTile,
|
|
|
|
prevTime,
|
|
|
|
prevLevel,
|
|
|
|
i;
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
tile.loading = false;
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( this.midUpdate ) {
|
|
|
|
$.Debug.error( "Tile load callback in middle of drawing routine." );
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
2012-01-19 05:15:54 +04:00
|
|
|
} else if ( !image ) {
|
|
|
|
$.Debug.log( "Tile " + tile + " failed to load: " + tile.url );
|
2011-12-06 07:50:25 +04:00
|
|
|
tile.exists = false;
|
|
|
|
return;
|
2012-01-19 05:15:54 +04:00
|
|
|
} else if ( time < this.lastResetTime ) {
|
|
|
|
$.Debug.log( "Ignoring tile " + tile + " loaded before reset: " + tile.url );
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.loaded = true;
|
2012-01-19 05:15:54 +04:00
|
|
|
tile.image = image;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
insertionIndex = this.tilesLoaded.length;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( this.tilesLoaded.length >= QUOTA ) {
|
|
|
|
cutoff = Math.ceil( Math.log( this.tileSize ) / Math.log( 2 ) );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
worstTile = null;
|
|
|
|
worstTileIndex = -1;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
for ( i = this.tilesLoaded.length - 1; i >= 0; i-- ) {
|
|
|
|
prevTile = this.tilesLoaded[ i ];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( prevTile.level <= this.cutoff || prevTile.beingDrawn ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
continue;
|
2012-01-19 05:15:54 +04:00
|
|
|
} else if ( !worstTile ) {
|
|
|
|
worstTile = prevTile;
|
|
|
|
worstTileIndex = i;
|
2011-12-06 07:50:25 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
prevTime = prevTile.lastTouchTime;
|
|
|
|
worstTime = worstTile.lastTouchTime;
|
|
|
|
prevLevel = prevTile.level;
|
|
|
|
worstLevel = worstTile.level;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( prevTime < worstTime ||
|
|
|
|
( prevTime == worstTime && prevLevel > worstLevel ) ) {
|
|
|
|
worstTile = prevTile;
|
|
|
|
worstTileIndex = i;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( worstTile && worstTileIndex >= 0 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
worstTile.unload();
|
|
|
|
insertionIndex = worstTileIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
this.tilesLoaded[ insertionIndex ] = tile;
|
2012-01-12 03:22:13 +04:00
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_clearTiles: function() {
|
2012-01-12 03:22:13 +04:00
|
|
|
this.tilesMatrix = {};
|
|
|
|
this.tilesLoaded = [];
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-01-19 05:15:54 +04:00
|
|
|
_providesCoverage: function( level, x, y ) {
|
|
|
|
var rows,
|
|
|
|
cols,
|
|
|
|
i, j;
|
|
|
|
|
|
|
|
if ( !this.coverage[ level ] ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( x === undefined || y === undefined ) {
|
|
|
|
rows = this.coverage[ level ];
|
|
|
|
for ( i in rows ) {
|
|
|
|
if ( rows.hasOwnProperty( i ) ) {
|
|
|
|
cols = rows[ i ];
|
|
|
|
for ( j in cols ) {
|
|
|
|
if ( cols.hasOwnProperty( j ) && !cols[ j ] ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
return (
|
|
|
|
this.coverage[ level ][ x] === undefined ||
|
|
|
|
this.coverage[ level ][ x ][ y ] === undefined ||
|
|
|
|
this.coverage[ level ][ x ][ y ] === true
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-01-19 05:15:54 +04:00
|
|
|
_isCovered: function( level, x, y ) {
|
|
|
|
if ( x === undefined || y === undefined ) {
|
|
|
|
return this._providesCoverage( level + 1 );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-19 05:15:54 +04:00
|
|
|
return (
|
|
|
|
this._providesCoverage( level + 1, 2 * x, 2 * y ) &&
|
|
|
|
this._providesCoverage( level + 1, 2 * x, 2 * y + 1 ) &&
|
|
|
|
this._providesCoverage( level + 1, 2 * x + 1, 2 * y ) &&
|
|
|
|
this._providesCoverage( level + 1, 2 * x + 1, 2 * y + 1 )
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether the given tile provides coverage or not.
|
|
|
|
*/
|
2012-01-19 05:15:54 +04:00
|
|
|
_setCoverage: function( level, x, y, covers ) {
|
|
|
|
if ( !this.coverage[ level ] ) {
|
|
|
|
$.Debug.error(
|
|
|
|
"Setting coverage for a tile before its level's coverage has been reset: " + level
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.coverage[ level ][ x ] ) {
|
|
|
|
this.coverage[ level ][ x ] = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
this.coverage[ level ][ x ][ y ] = covers;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-01-19 05:15:54 +04:00
|
|
|
_resetCoverage: function( level ) {
|
|
|
|
this.coverage[ level ] = {};
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_compareTiles: function( prevBest, tile ) {
|
|
|
|
if ( !prevBest ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( tile.visibility > prevBest.visibility ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return tile;
|
2012-01-19 05:15:54 +04:00
|
|
|
} else if ( tile.visibility == prevBest.visibility ) {
|
|
|
|
if ( tile.distance < prevBest.distance ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return prevBest;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_getOverlayIndex: function( elmt ) {
|
|
|
|
var i;
|
|
|
|
for ( i = this.overlays.length - 1; i >= 0; i-- ) {
|
|
|
|
if ( this.overlays[ i ].elmt == elmt ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_updateActual: function() {
|
2012-01-12 03:22:13 +04:00
|
|
|
this.updateAgain = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
var tile,
|
2012-01-19 05:15:54 +04:00
|
|
|
level,
|
|
|
|
viewportSize = this.viewport.getContainerSize(),
|
|
|
|
viewportWidth = viewportSize.x,
|
|
|
|
viewportHeight = viewportSize.y,
|
|
|
|
viewportBounds = this.viewport.getBounds( true ),
|
|
|
|
viewportTL = viewportBounds.getTopLeft(),
|
|
|
|
viewportBR = viewportBounds.getBottomRight(),
|
|
|
|
haveDrawn = false,
|
2012-01-19 06:52:22 +04:00
|
|
|
best = null,
|
2012-01-19 05:15:54 +04:00
|
|
|
currentTime = new Date().getTime(),
|
|
|
|
zeroRatioC = this.viewport.deltaPixelsFromPoints(
|
|
|
|
this.source.getPixelRatio( 0 ),
|
|
|
|
true
|
|
|
|
).x,
|
|
|
|
lowestLevel = Math.max(
|
|
|
|
this.minLevel,
|
|
|
|
Math.floor(
|
|
|
|
Math.log( this.config.minZoomImageRatio ) /
|
|
|
|
Math.log( 2 )
|
|
|
|
)
|
|
|
|
),
|
|
|
|
highestLevel = Math.min(
|
|
|
|
this.maxLevel,
|
|
|
|
Math.floor(
|
|
|
|
Math.log( zeroRatioC / MIN_PIXEL_RATIO ) /
|
|
|
|
Math.log( 2 )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
while ( this.lastDrawn.length > 0 ) {
|
|
|
|
tile = this.lastDrawn.pop();
|
2011-12-06 07:50:25 +04:00
|
|
|
tile.beingDrawn = false;
|
|
|
|
}
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( USE_CANVAS ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
this.canvas.width = viewportWidth;
|
|
|
|
this.canvas.height = viewportHeight;
|
|
|
|
this.context.clearRect( 0, 0, viewportWidth, viewportHeight );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.config.wrapHorizontal &&
|
|
|
|
( viewportBR.x < 0 || viewportTL.x > 1 ) ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
2012-01-19 06:52:22 +04:00
|
|
|
} else if
|
|
|
|
( !this.config.wrapVertical &&
|
2012-01-19 05:15:54 +04:00
|
|
|
( viewportBR.y < 0 || viewportTL.y > this.normHeight ) ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.config.wrapHorizontal ) {
|
|
|
|
viewportTL.x = Math.max( viewportTL.x, 0 );
|
|
|
|
viewportBR.x = Math.min( viewportBR.x, 1 );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( !this.config.wrapVertical ) {
|
|
|
|
viewportTL.y = Math.max( viewportTL.y, 0 );
|
|
|
|
viewportBR.y = Math.min( viewportBR.y, this.normHeight );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
lowestLevel = Math.min( lowestLevel, highestLevel );
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
2012-01-19 05:15:54 +04:00
|
|
|
for ( level = highestLevel; level >= lowestLevel; level-- ) {
|
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
|
|
|
best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best );
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
if ( this._providesCoverage( level ) ) {
|
|
|
|
break;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-19 06:52:22 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
|
|
|
this._drawTiles();
|
|
|
|
this._drawOverlays();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
//TODO
|
|
|
|
if ( best ) {
|
|
|
|
this._loadTile( best, currentTime );
|
|
|
|
// because we haven't finished drawing, so
|
|
|
|
this.updateAgain = true;
|
|
|
|
}
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
_drawLevel: function( level, lowestLevel, viewportTL, viewportBR, currentTime, best ){
|
|
|
|
var x, y,
|
|
|
|
levelOpacity,
|
|
|
|
levelVisibility,
|
|
|
|
drawTile,
|
|
|
|
tile,
|
|
|
|
tileTL,
|
|
|
|
tileBR,
|
|
|
|
numTiles,
|
|
|
|
numTilesX,
|
|
|
|
numTilesY,
|
|
|
|
renderPixelRatioC,
|
|
|
|
renderPixelRatioT,
|
|
|
|
levelOpacity,
|
|
|
|
levelVisibility,
|
|
|
|
haveDrawn = false,
|
|
|
|
drawLevel = false,
|
|
|
|
viewportCenter = this.viewport.pixelFromPoint( this.viewport.getCenter() ),
|
|
|
|
zeroRatioT = this.viewport.deltaPixelsFromPoints(
|
|
|
|
this.source.getPixelRatio( 0 ),
|
|
|
|
false
|
|
|
|
).x,
|
|
|
|
optimalRatio = this.config.immediateRender ?
|
|
|
|
1 :
|
|
|
|
zeroRatioT;
|
|
|
|
|
|
|
|
//Avoid calculations for draw if we have already drawn this
|
|
|
|
renderPixelRatioC = this.viewport.deltaPixelsFromPoints(
|
|
|
|
this.source.getPixelRatio( level ),
|
|
|
|
true
|
|
|
|
).x;
|
|
|
|
|
|
|
|
if ( ( !haveDrawn && renderPixelRatioC >= MIN_PIXEL_RATIO ) ||
|
|
|
|
( level == lowestLevel ) ) {
|
|
|
|
drawLevel = true;
|
|
|
|
haveDrawn = true;
|
|
|
|
} else if ( !haveDrawn ) {
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
//OK, a new drawing so do your calculations
|
|
|
|
tileTL = this.source.getTileAtPoint( level, viewportTL );
|
|
|
|
tileBR = this.source.getTileAtPoint( level, viewportBR );
|
|
|
|
numTiles = numberOfTiles( this, level );
|
|
|
|
numTilesX = numTiles.x;
|
|
|
|
numTilesY = numTiles.y;
|
|
|
|
|
|
|
|
renderPixelRatioT = this.viewport.deltaPixelsFromPoints(
|
|
|
|
this.source.getPixelRatio( level ),
|
|
|
|
false
|
|
|
|
).x;
|
|
|
|
|
|
|
|
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
|
|
|
|
levelVisibility = optimalRatio / Math.abs(
|
|
|
|
optimalRatio - renderPixelRatioT
|
|
|
|
);
|
2012-01-19 05:15:54 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
this._resetCoverage( level );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
if ( !this.config.wrapHorizontal ) {
|
|
|
|
tileBR.x = Math.min( tileBR.x, numTilesX - 1 );
|
|
|
|
}
|
|
|
|
if ( !this.config.wrapVertical ) {
|
|
|
|
tileBR.y = Math.min( tileBR.y, numTilesY - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
|
|
|
|
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
|
|
|
|
drawTile = drawLevel;
|
|
|
|
tile = this._getTile(
|
|
|
|
level,
|
|
|
|
x, y,
|
|
|
|
currentTime,
|
|
|
|
numTilesX,
|
|
|
|
numTilesY
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
this._setCoverage( level, x, y, false );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
if ( !tile.exists ) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
if ( haveDrawn && !drawTile ) {
|
|
|
|
if ( this._isCovered( level, x, y ) ) {
|
|
|
|
this._setCoverage( level, x, y, true );
|
|
|
|
} else {
|
|
|
|
drawTile = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-01-19 06:52:22 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
if ( !drawTile ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._positionTile(
|
|
|
|
tile,
|
|
|
|
viewportCenter,
|
|
|
|
levelVisibility
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
if ( tile.loaded ) {
|
|
|
|
|
|
|
|
updateAgain = this._blendTile(
|
2012-01-19 05:15:54 +04:00
|
|
|
tile,
|
2012-01-19 06:52:22 +04:00
|
|
|
x, y,
|
|
|
|
level,
|
|
|
|
levelOpacity,
|
|
|
|
currentTime
|
2012-01-19 05:15:54 +04:00
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 06:52:22 +04:00
|
|
|
} else if ( tile.Loading ) {
|
|
|
|
//TODO: .Loading is never defined... did they mean .loading?
|
|
|
|
// but they didnt do anything so what is this block if
|
|
|
|
// if it does nothing.
|
|
|
|
} else {
|
|
|
|
best = this._compareTiles( best, tile );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 06:52:22 +04:00
|
|
|
return best;
|
2012-01-19 05:15:54 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_positionTile: function( tile, viewportCenter, levelVisibility ){
|
|
|
|
var boundsTL = tile.bounds.getTopLeft(),
|
|
|
|
boundsSize = tile.bounds.getSize(),
|
|
|
|
positionC = this.viewport.pixelFromPoint( boundsTL, true ),
|
|
|
|
sizeC = this.viewport.deltaPixelsFromPoints( boundsSize, true ),
|
|
|
|
positionT = this.viewport.pixelFromPoint( boundsTL, false ),
|
|
|
|
sizeT = this.viewport.deltaPixelsFromPoints( boundsSize, false ),
|
|
|
|
tileCenter = positionT.plus( sizeT.divide( 2 ) ),
|
|
|
|
tileDistance = viewportCenter.distanceTo( tileCenter );
|
|
|
|
|
|
|
|
if ( !this.tileOverlap ) {
|
|
|
|
sizeC = sizeC.plus( new $.Point( 1, 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.position = positionC;
|
|
|
|
tile.size = sizeC;
|
|
|
|
tile.distance = tileDistance;
|
|
|
|
tile.visibility = levelVisibility;
|
|
|
|
},
|
|
|
|
|
|
|
|
_blendTile: function( tile, x, y, level, levelOpacity, currentTime ){
|
|
|
|
var blendTimeMillis = 1000 * this.config.blendTime,
|
|
|
|
deltaTime,
|
|
|
|
opacity;
|
|
|
|
|
|
|
|
if ( !tile.blendStart ) {
|
|
|
|
tile.blendStart = currentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
deltaTime = currentTime - tile.blendStart;
|
|
|
|
opacity = Math.min( 1, deltaTime / blendTimeMillis );
|
|
|
|
|
|
|
|
if ( this.config.alwaysBlend ) {
|
|
|
|
opacity *= levelOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
tile.opacity = opacity;
|
|
|
|
|
|
|
|
this.lastDrawn.push( tile );
|
|
|
|
|
|
|
|
if ( opacity == 1 ) {
|
|
|
|
this._setCoverage( level, x, y, true );
|
|
|
|
} else if ( deltaTime < blendTimeMillis ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_drawTiles: function(){
|
|
|
|
var i,
|
|
|
|
tile;
|
|
|
|
|
|
|
|
for ( i = this.lastDrawn.length - 1; i >= 0; i-- ) {
|
|
|
|
tile = this.lastDrawn[ i ];
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-12 03:22:13 +04:00
|
|
|
if ( USE_CANVAS ) {
|
2012-01-19 05:15:54 +04:00
|
|
|
tile.drawCanvas( this.context );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-19 05:15:54 +04:00
|
|
|
tile.drawHTML( this.canvas );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
tile.beingDrawn = true;
|
|
|
|
}
|
2012-01-19 05:15:54 +04:00
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_drawOverlays: function(){
|
|
|
|
var i,
|
|
|
|
length = this.overlays.length;
|
|
|
|
for ( i = 0; i < length; i++ ) {
|
|
|
|
this._drawOverlay( this.overlays[ i ] );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
_drawOverlay: function( overlay ){
|
|
|
|
|
|
|
|
var bounds = overlay.bounds;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
overlay.position = this.viewport.pixelFromPoint(
|
|
|
|
bounds.getTopLeft(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
overlay.size = this.viewport.deltaPixelsFromPoints(
|
|
|
|
bounds.getSize(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
overlay.drawHTML( this.container );
|
|
|
|
},
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
addOverlay: function( element, location, placement ) {
|
|
|
|
element = $.getElement( element );
|
|
|
|
|
|
|
|
if ( this._getOverlayIndex( element ) >= 0 ) {
|
|
|
|
// they're trying to add a duplicate overlay
|
|
|
|
return;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
this.overlays.push( new $.Overlay( element, location, placement ) );
|
2012-01-12 03:22:13 +04:00
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
updateOverlay: function( element, location, placement ) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
element = $.getElement( element );
|
|
|
|
i = this._getOverlayIndex( element );
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.overlays[ i ].update( location, placement );
|
2012-01-12 03:22:13 +04:00
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
removeOverlay: function( element ) {
|
|
|
|
var i;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-19 05:15:54 +04:00
|
|
|
element = $.getElement( element );
|
|
|
|
i = this._getOverlayIndex( element );
|
|
|
|
|
|
|
|
if ( i >= 0 ) {
|
|
|
|
this.overlays[ i ].destroy();
|
|
|
|
this.overlays.splice( i, 1 );
|
2012-01-12 03:22:13 +04:00
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearOverlays: function() {
|
2012-01-19 05:15:54 +04:00
|
|
|
while ( this.overlays.length > 0 ) {
|
2012-01-12 03:22:13 +04:00
|
|
|
this.overlays.pop().destroy();
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
needsUpdate: function() {
|
2012-01-12 03:22:13 +04:00
|
|
|
return this.updateAgain;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
numTilesLoaded: function() {
|
2012-01-12 03:22:13 +04:00
|
|
|
return this.tilesLoaded.length;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this._clearTiles();
|
2012-01-12 03:22:13 +04:00
|
|
|
this.lastResetTime = new Date().getTime();
|
|
|
|
this.updateAgain = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
2012-01-12 03:22:13 +04:00
|
|
|
//this.profiler.beginUpdate();
|
|
|
|
this.midUpdate = true;
|
2011-12-06 07:50:25 +04:00
|
|
|
this._updateActual();
|
2012-01-12 03:22:13 +04:00
|
|
|
this.midUpdate = false;
|
|
|
|
//this.profiler.endUpdate();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2011-12-28 03:17:24 +04:00
|
|
|
loadImage: function(src, callback) {
|
|
|
|
var _this = this,
|
|
|
|
loading = false,
|
|
|
|
image,
|
|
|
|
jobid,
|
|
|
|
complete;
|
|
|
|
|
|
|
|
if ( !this.imageLoaderLimit || this.downloading < this.imageLoaderLimit ) {
|
|
|
|
|
|
|
|
this.downloading++;
|
|
|
|
|
|
|
|
image = new Image();
|
|
|
|
|
|
|
|
complete = function( imagesrc ){
|
|
|
|
_this.downloading--;
|
|
|
|
if (typeof ( callback ) == "function") {
|
|
|
|
try {
|
|
|
|
callback( image );
|
|
|
|
} catch ( e ) {
|
|
|
|
$.Debug.error(
|
|
|
|
e.name + " while executing " + src +" callback: " + e.message,
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
image.onload = function(){
|
|
|
|
finishLoadingImage( image, complete, true );
|
|
|
|
};
|
|
|
|
|
|
|
|
image.onabort = image.onerror = function(){
|
|
|
|
finishLoadingImage( image, complete, false );
|
|
|
|
};
|
|
|
|
|
|
|
|
jobid = window.setTimeout( function(){
|
|
|
|
finishLoadingImage( image, complete, false, jobid );
|
|
|
|
}, TIMEOUT );
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
image.src = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
return loading;
|
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-01-12 03:32:17 +04:00
|
|
|
function numberOfTiles( drawer, level ){
|
|
|
|
|
|
|
|
if ( !drawer.cacheNumTiles[ level ] ) {
|
|
|
|
drawer.cacheNumTiles[ level ] = drawer.source.getNumTiles( level );
|
|
|
|
}
|
|
|
|
|
|
|
|
return drawer.cacheNumTiles[ level ];
|
|
|
|
};
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
$.Viewport = function(containerSize, contentSize, config) {
|
2012-01-05 04:45:47 +04:00
|
|
|
//TODO: this.config is something that should go away but currently the
|
|
|
|
// Drawer references the viewport.config
|
2011-12-06 07:50:25 +04:00
|
|
|
this.config = config;
|
2012-01-05 04:45:47 +04:00
|
|
|
this.zoomPoint = null;
|
2012-01-05 03:14:20 +04:00
|
|
|
this.containerSize = containerSize;
|
|
|
|
this.contentSize = contentSize;
|
|
|
|
this.contentAspect = contentSize.x / contentSize.y;
|
|
|
|
this.contentHeight = contentSize.y / contentSize.x;
|
|
|
|
this.centerSpringX = new $.Spring({
|
|
|
|
initial: 0,
|
|
|
|
springStiffness: config.springStiffness,
|
|
|
|
animationTime: config.animationTime
|
|
|
|
});
|
|
|
|
this.centerSpringY = new $.Spring({
|
|
|
|
initial: 0,
|
|
|
|
springStiffness: config.springStiffness,
|
|
|
|
animationTime: config.animationTime
|
|
|
|
});
|
|
|
|
this.zoomSpring = new $.Spring({
|
|
|
|
initial: 1,
|
|
|
|
springStiffness: config.springStiffness,
|
|
|
|
animationTime: config.animationTime
|
|
|
|
});
|
|
|
|
this.minZoomImageRatio = config.minZoomImageRatio;
|
|
|
|
this.maxZoomPixelRatio = config.maxZoomPixelRatio;
|
|
|
|
this.visibilityRatio = config.visibilityRatio;
|
|
|
|
this.wrapHorizontal = config.wrapHorizontal;
|
|
|
|
this.wrapVertical = config.wrapVertical;
|
2012-01-05 04:45:47 +04:00
|
|
|
this.homeBounds = new $.Rect( 0, 0, 1, this.contentHeight );
|
|
|
|
this.goHome( true );
|
2011-12-06 07:50:25 +04:00
|
|
|
this.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Viewport.prototype = {
|
2012-01-05 03:14:20 +04:00
|
|
|
getHomeZoom: function() {
|
|
|
|
var aspectFactor = this.contentAspect / this.getAspectRatio();
|
2011-12-06 07:50:25 +04:00
|
|
|
return (aspectFactor >= 1) ? 1 : aspectFactor;
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
|
|
return Math.min(zoom, homeZoom);
|
|
|
|
},
|
|
|
|
|
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-05 03:14:20 +04:00
|
|
|
return Math.max(zoom, this.getHomeZoom());
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-05 03:14:20 +04:00
|
|
|
|
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
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
getContainerSize: function() {
|
2012-01-05 03:14:20 +04:00
|
|
|
return new $.Point(this.containerSize.x, this.containerSize.y);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-01-05 04:45:47 +04:00
|
|
|
getBounds: function( current ) {
|
2012-01-05 03:14:20 +04:00
|
|
|
var center = this.getCenter(current),
|
|
|
|
width = 1.0 / this.getZoom(current),
|
|
|
|
height = width / this.getAspectRatio();
|
|
|
|
|
|
|
|
return new $.Rect(
|
|
|
|
center.x - width / 2.0,
|
|
|
|
center.y - height / 2.0,
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
|
|
if (current) {
|
|
|
|
return centerCurrent;
|
|
|
|
} else if (!this.zoomPoint) {
|
|
|
|
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-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-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;
|
|
|
|
bottom = this.contentHeight - 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-01-05 04:45:47 +04:00
|
|
|
ensureVisible: function( immediately ) {
|
|
|
|
this.applyConstraints( immediately );
|
2011-12-06 07:50:25 +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
|
|
|
|
|
|
|
if (newBounds.getAspectRatio() >= aspect) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
this.panTo(this.getCenter(true), true);
|
|
|
|
this.zoomTo(this.getZoom(true), null, true);
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
oldBounds = this.getBounds();
|
|
|
|
oldZoom = this.getZoom();
|
|
|
|
newZoom = 1.0 / newBounds.width;
|
2011-12-06 07:50:25 +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
|
|
|
},
|
|
|
|
|
|
|
|
goHome: function(immediately) {
|
|
|
|
var center = this.getCenter();
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapHorizontal ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
center.x = (1 + (center.x % 1)) % 1;
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.resetTo(center.x);
|
|
|
|
this.centerSpringX.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
if ( this.wrapVertical ) {
|
|
|
|
center.y = (this.contentHeight + (center.y % this.contentHeight)) % this.contentHeight;
|
|
|
|
this.centerSpringY.resetTo(center.y);
|
|
|
|
this.centerSpringY.update();
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-05 03:14:20 +04:00
|
|
|
this.fitBounds(this.homeBounds, immediately);
|
2011-12-06 07:50:25 +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
|
|
|
},
|
|
|
|
|
|
|
|
panTo: function(center, immediately) {
|
|
|
|
if (immediately) {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.resetTo(center.x);
|
|
|
|
this.centerSpringY.resetTo(center.y);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.centerSpringX.springTo(center.x);
|
|
|
|
this.centerSpringY.springTo(center.y);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
zoomBy: function(factor, refPoint, immediately) {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.zoomTo(this.zoomSpring.target.value * factor, refPoint, immediately);
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
zoomTo: function(zoom, refPoint, immediately) {
|
|
|
|
|
|
|
|
if (immediately) {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.zoomSpring.resetTo(zoom);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-05 03:14:20 +04:00
|
|
|
this.zoomSpring.springTo(zoom);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.zoomPoint = refPoint instanceof $.Point ? refPoint : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
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-05 03:14:20 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.fitBounds(newBounds, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
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-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
|
|
|
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 );
|
|
|
|
deltaZoomPixels = newZoomPixel.minus( oldZoomPixel);
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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 ));
|