id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
10,800
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( element, className ) {
var oldClasses,
newClasses = [],
i;
element = $.getElement( element );
oldClasses = element.className.split( /\s+/ );
for ( i = 0; i < oldClasses.length; i++ ) {
if ( oldClasses[ i ] && oldClasses[ i ] !== className ) {
newClasses.push( oldClasses[ i ] );
}
}
element.className = newClasses.join(' ');
}
|
javascript
|
function( element, className ) {
var oldClasses,
newClasses = [],
i;
element = $.getElement( element );
oldClasses = element.className.split( /\s+/ );
for ( i = 0; i < oldClasses.length; i++ ) {
if ( oldClasses[ i ] && oldClasses[ i ] !== className ) {
newClasses.push( oldClasses[ i ] );
}
}
element.className = newClasses.join(' ');
}
|
[
"function",
"(",
"element",
",",
"className",
")",
"{",
"var",
"oldClasses",
",",
"newClasses",
"=",
"[",
"]",
",",
"i",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"oldClasses",
"=",
"element",
".",
"className",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"oldClasses",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"oldClasses",
"[",
"i",
"]",
"&&",
"oldClasses",
"[",
"i",
"]",
"!==",
"className",
")",
"{",
"newClasses",
".",
"push",
"(",
"oldClasses",
"[",
"i",
"]",
")",
";",
"}",
"}",
"element",
".",
"className",
"=",
"newClasses",
".",
"join",
"(",
"' '",
")",
";",
"}"
] |
Remove the specified CSS class from the element.
@function
@param {Element|String} element
@param {String} className
|
[
"Remove",
"the",
"specified",
"CSS",
"class",
"from",
"the",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L1966-L1979
|
|
10,801
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( event ) {
event = $.getEvent( event );
if ( event.preventDefault ) {
$.cancelEvent = function( event ){
// W3C for preventing default
event.preventDefault();
};
} else {
$.cancelEvent = function( event ){
event = $.getEvent( event );
// legacy for preventing default
event.cancel = true;
// IE for preventing default
event.returnValue = false;
};
}
$.cancelEvent( event );
}
|
javascript
|
function( event ) {
event = $.getEvent( event );
if ( event.preventDefault ) {
$.cancelEvent = function( event ){
// W3C for preventing default
event.preventDefault();
};
} else {
$.cancelEvent = function( event ){
event = $.getEvent( event );
// legacy for preventing default
event.cancel = true;
// IE for preventing default
event.returnValue = false;
};
}
$.cancelEvent( event );
}
|
[
"function",
"(",
"event",
")",
"{",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"if",
"(",
"event",
".",
"preventDefault",
")",
"{",
"$",
".",
"cancelEvent",
"=",
"function",
"(",
"event",
")",
"{",
"// W3C for preventing default",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
".",
"cancelEvent",
"=",
"function",
"(",
"event",
")",
"{",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"// legacy for preventing default",
"event",
".",
"cancel",
"=",
"true",
";",
"// IE for preventing default",
"event",
".",
"returnValue",
"=",
"false",
";",
"}",
";",
"}",
"$",
".",
"cancelEvent",
"(",
"event",
")",
";",
"}"
] |
Cancels the default browser behavior had the event propagated all
the way up the DOM to the window object.
@function
@param {Event} [event]
|
[
"Cancels",
"the",
"default",
"browser",
"behavior",
"had",
"the",
"event",
"propagated",
"all",
"the",
"way",
"up",
"the",
"DOM",
"to",
"the",
"window",
"object",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2039-L2057
|
|
10,802
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( event ) {
event = $.getEvent( event );
if ( event.stopPropagation ) {
// W3C for stopping propagation
$.stopEvent = function( event ){
event.stopPropagation();
};
} else {
// IE for stopping propagation
$.stopEvent = function( event ){
event = $.getEvent( event );
event.cancelBubble = true;
};
}
$.stopEvent( event );
}
|
javascript
|
function( event ) {
event = $.getEvent( event );
if ( event.stopPropagation ) {
// W3C for stopping propagation
$.stopEvent = function( event ){
event.stopPropagation();
};
} else {
// IE for stopping propagation
$.stopEvent = function( event ){
event = $.getEvent( event );
event.cancelBubble = true;
};
}
$.stopEvent( event );
}
|
[
"function",
"(",
"event",
")",
"{",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"if",
"(",
"event",
".",
"stopPropagation",
")",
"{",
"// W3C for stopping propagation",
"$",
".",
"stopEvent",
"=",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"// IE for stopping propagation",
"$",
".",
"stopEvent",
"=",
"function",
"(",
"event",
")",
"{",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"event",
".",
"cancelBubble",
"=",
"true",
";",
"}",
";",
"}",
"$",
".",
"stopEvent",
"(",
"event",
")",
";",
"}"
] |
Stops the propagation of the event up the DOM.
@function
@param {Event} [event]
|
[
"Stops",
"the",
"propagation",
"of",
"the",
"event",
"up",
"the",
"DOM",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2065-L2083
|
|
10,803
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( object, method ) {
//TODO: This pattern is painful to use and debug. It's much cleaner
// to use pinning plus anonymous functions. Get rid of this
// pattern!
var initialArgs = [],
i;
for ( i = 2; i < arguments.length; i++ ) {
initialArgs.push( arguments[ i ] );
}
return function() {
var args = initialArgs.concat( [] ),
i;
for ( i = 0; i < arguments.length; i++ ) {
args.push( arguments[ i ] );
}
return method.apply( object, args );
};
}
|
javascript
|
function( object, method ) {
//TODO: This pattern is painful to use and debug. It's much cleaner
// to use pinning plus anonymous functions. Get rid of this
// pattern!
var initialArgs = [],
i;
for ( i = 2; i < arguments.length; i++ ) {
initialArgs.push( arguments[ i ] );
}
return function() {
var args = initialArgs.concat( [] ),
i;
for ( i = 0; i < arguments.length; i++ ) {
args.push( arguments[ i ] );
}
return method.apply( object, args );
};
}
|
[
"function",
"(",
"object",
",",
"method",
")",
"{",
"//TODO: This pattern is painful to use and debug. It's much cleaner",
"// to use pinning plus anonymous functions. Get rid of this",
"// pattern!",
"var",
"initialArgs",
"=",
"[",
"]",
",",
"i",
";",
"for",
"(",
"i",
"=",
"2",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"{",
"initialArgs",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"initialArgs",
".",
"concat",
"(",
"[",
"]",
")",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"{",
"args",
".",
"push",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"return",
"method",
".",
"apply",
"(",
"object",
",",
"args",
")",
";",
"}",
";",
"}"
] |
Similar to OpenSeadragon.delegate, but it does not immediately call
the method on the object, returning a function which can be called
repeatedly to delegate the method. It also allows additional arguments
to be passed during construction which will be added during each
invocation, and each invocation can add additional arguments as well.
@function
@param {Object} object
@param {Function} method
@param [args] any additional arguments are passed as arguments to the
created callback
@returns {Function}
|
[
"Similar",
"to",
"OpenSeadragon",
".",
"delegate",
"but",
"it",
"does",
"not",
"immediately",
"call",
"the",
"method",
"on",
"the",
"object",
"returning",
"a",
"function",
"which",
"can",
"be",
"called",
"repeatedly",
"to",
"delegate",
"the",
"method",
".",
"It",
"also",
"allows",
"additional",
"arguments",
"to",
"be",
"passed",
"during",
"construction",
"which",
"will",
"be",
"added",
"during",
"each",
"invocation",
"and",
"each",
"invocation",
"can",
"add",
"additional",
"arguments",
"as",
"well",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2100-L2119
|
|
10,804
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( url ) {
var match = url.match(/^([a-z]+:)\/\//i);
if ( match === null ) {
// Relative URL, retrive the protocol from window.location
return window.location.protocol;
}
return match[1].toLowerCase();
}
|
javascript
|
function( url ) {
var match = url.match(/^([a-z]+:)\/\//i);
if ( match === null ) {
// Relative URL, retrive the protocol from window.location
return window.location.protocol;
}
return match[1].toLowerCase();
}
|
[
"function",
"(",
"url",
")",
"{",
"var",
"match",
"=",
"url",
".",
"match",
"(",
"/",
"^([a-z]+:)\\/\\/",
"/",
"i",
")",
";",
"if",
"(",
"match",
"===",
"null",
")",
"{",
"// Relative URL, retrive the protocol from window.location",
"return",
"window",
".",
"location",
".",
"protocol",
";",
"}",
"return",
"match",
"[",
"1",
"]",
".",
"toLowerCase",
"(",
")",
";",
"}"
] |
Retrieves the protocol used by the url. The url can either be absolute
or relative.
@function
@private
@param {String} url The url to retrieve the protocol from.
@return {String} The protocol (http:, https:, file:, ftp: ...)
|
[
"Retrieves",
"the",
"protocol",
"used",
"by",
"the",
"url",
".",
"The",
"url",
"can",
"either",
"be",
"absolute",
"or",
"relative",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2142-L2149
|
|
10,805
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( local ) {
// IE11 does not support window.ActiveXObject so we just try to
// create one to see if it is supported.
// See: http://msdn.microsoft.com/en-us/library/ie/dn423948%28v=vs.85%29.aspx
var supportActiveX;
try {
/* global ActiveXObject:true */
supportActiveX = !!new ActiveXObject( "Microsoft.XMLHTTP" );
} catch( e ) {
supportActiveX = false;
}
if ( supportActiveX ) {
if ( window.XMLHttpRequest ) {
$.createAjaxRequest = function( local ) {
if ( local ) {
return new ActiveXObject( "Microsoft.XMLHTTP" );
}
return new XMLHttpRequest();
};
} else {
$.createAjaxRequest = function() {
return new ActiveXObject( "Microsoft.XMLHTTP" );
};
}
} else if ( window.XMLHttpRequest ) {
$.createAjaxRequest = function() {
return new XMLHttpRequest();
};
} else {
throw new Error( "Browser doesn't support XMLHttpRequest." );
}
return $.createAjaxRequest( local );
}
|
javascript
|
function( local ) {
// IE11 does not support window.ActiveXObject so we just try to
// create one to see if it is supported.
// See: http://msdn.microsoft.com/en-us/library/ie/dn423948%28v=vs.85%29.aspx
var supportActiveX;
try {
/* global ActiveXObject:true */
supportActiveX = !!new ActiveXObject( "Microsoft.XMLHTTP" );
} catch( e ) {
supportActiveX = false;
}
if ( supportActiveX ) {
if ( window.XMLHttpRequest ) {
$.createAjaxRequest = function( local ) {
if ( local ) {
return new ActiveXObject( "Microsoft.XMLHTTP" );
}
return new XMLHttpRequest();
};
} else {
$.createAjaxRequest = function() {
return new ActiveXObject( "Microsoft.XMLHTTP" );
};
}
} else if ( window.XMLHttpRequest ) {
$.createAjaxRequest = function() {
return new XMLHttpRequest();
};
} else {
throw new Error( "Browser doesn't support XMLHttpRequest." );
}
return $.createAjaxRequest( local );
}
|
[
"function",
"(",
"local",
")",
"{",
"// IE11 does not support window.ActiveXObject so we just try to",
"// create one to see if it is supported.",
"// See: http://msdn.microsoft.com/en-us/library/ie/dn423948%28v=vs.85%29.aspx",
"var",
"supportActiveX",
";",
"try",
"{",
"/* global ActiveXObject:true */",
"supportActiveX",
"=",
"!",
"!",
"new",
"ActiveXObject",
"(",
"\"Microsoft.XMLHTTP\"",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"supportActiveX",
"=",
"false",
";",
"}",
"if",
"(",
"supportActiveX",
")",
"{",
"if",
"(",
"window",
".",
"XMLHttpRequest",
")",
"{",
"$",
".",
"createAjaxRequest",
"=",
"function",
"(",
"local",
")",
"{",
"if",
"(",
"local",
")",
"{",
"return",
"new",
"ActiveXObject",
"(",
"\"Microsoft.XMLHTTP\"",
")",
";",
"}",
"return",
"new",
"XMLHttpRequest",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
".",
"createAjaxRequest",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"ActiveXObject",
"(",
"\"Microsoft.XMLHTTP\"",
")",
";",
"}",
";",
"}",
"}",
"else",
"if",
"(",
"window",
".",
"XMLHttpRequest",
")",
"{",
"$",
".",
"createAjaxRequest",
"=",
"function",
"(",
")",
"{",
"return",
"new",
"XMLHttpRequest",
"(",
")",
";",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Browser doesn't support XMLHttpRequest.\"",
")",
";",
"}",
"return",
"$",
".",
"createAjaxRequest",
"(",
"local",
")",
";",
"}"
] |
Create an XHR object
@private
@param {type} [local] If set to true, the XHR will be file: protocol
compatible if possible (but may raise a warning in the browser).
@returns {XMLHttpRequest}
|
[
"Create",
"an",
"XHR",
"object"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2158-L2191
|
|
10,806
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( options ){
var script,
url = options.url,
head = document.head ||
document.getElementsByTagName( "head" )[ 0 ] ||
document.documentElement,
jsonpCallback = options.callbackName || 'openseadragon' + $.now(),
previous = window[ jsonpCallback ],
replace = "$1" + jsonpCallback + "$2",
callbackParam = options.param || 'callback',
callback = options.callback;
url = url.replace( /(\=)\?(&|$)|\?\?/i, replace );
// Add callback manually
url += (/\?/.test( url ) ? "&" : "?") + callbackParam + "=" + jsonpCallback;
// Install callback
window[ jsonpCallback ] = function( response ) {
if ( !previous ){
try{
delete window[ jsonpCallback ];
}catch(e){
//swallow
}
} else {
window[ jsonpCallback ] = previous;
}
if( callback && $.isFunction( callback ) ){
callback( response );
}
};
script = document.createElement( "script" );
//TODO: having an issue with async info requests
if( undefined !== options.async || false !== options.async ){
script.async = "async";
}
if ( options.scriptCharset ) {
script.charset = options.scriptCharset;
}
script.src = url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _, isAbort ) {
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
// Remove the script
if ( head && script.parentNode ) {
head.removeChild( script );
}
// Dereference the script
script = undefined;
}
};
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild );
}
|
javascript
|
function( options ){
var script,
url = options.url,
head = document.head ||
document.getElementsByTagName( "head" )[ 0 ] ||
document.documentElement,
jsonpCallback = options.callbackName || 'openseadragon' + $.now(),
previous = window[ jsonpCallback ],
replace = "$1" + jsonpCallback + "$2",
callbackParam = options.param || 'callback',
callback = options.callback;
url = url.replace( /(\=)\?(&|$)|\?\?/i, replace );
// Add callback manually
url += (/\?/.test( url ) ? "&" : "?") + callbackParam + "=" + jsonpCallback;
// Install callback
window[ jsonpCallback ] = function( response ) {
if ( !previous ){
try{
delete window[ jsonpCallback ];
}catch(e){
//swallow
}
} else {
window[ jsonpCallback ] = previous;
}
if( callback && $.isFunction( callback ) ){
callback( response );
}
};
script = document.createElement( "script" );
//TODO: having an issue with async info requests
if( undefined !== options.async || false !== options.async ){
script.async = "async";
}
if ( options.scriptCharset ) {
script.charset = options.scriptCharset;
}
script.src = url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _, isAbort ) {
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
// Remove the script
if ( head && script.parentNode ) {
head.removeChild( script );
}
// Dereference the script
script = undefined;
}
};
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild );
}
|
[
"function",
"(",
"options",
")",
"{",
"var",
"script",
",",
"url",
"=",
"options",
".",
"url",
",",
"head",
"=",
"document",
".",
"head",
"||",
"document",
".",
"getElementsByTagName",
"(",
"\"head\"",
")",
"[",
"0",
"]",
"||",
"document",
".",
"documentElement",
",",
"jsonpCallback",
"=",
"options",
".",
"callbackName",
"||",
"'openseadragon'",
"+",
"$",
".",
"now",
"(",
")",
",",
"previous",
"=",
"window",
"[",
"jsonpCallback",
"]",
",",
"replace",
"=",
"\"$1\"",
"+",
"jsonpCallback",
"+",
"\"$2\"",
",",
"callbackParam",
"=",
"options",
".",
"param",
"||",
"'callback'",
",",
"callback",
"=",
"options",
".",
"callback",
";",
"url",
"=",
"url",
".",
"replace",
"(",
"/",
"(\\=)\\?(&|$)|\\?\\?",
"/",
"i",
",",
"replace",
")",
";",
"// Add callback manually",
"url",
"+=",
"(",
"/",
"\\?",
"/",
".",
"test",
"(",
"url",
")",
"?",
"\"&\"",
":",
"\"?\"",
")",
"+",
"callbackParam",
"+",
"\"=\"",
"+",
"jsonpCallback",
";",
"// Install callback",
"window",
"[",
"jsonpCallback",
"]",
"=",
"function",
"(",
"response",
")",
"{",
"if",
"(",
"!",
"previous",
")",
"{",
"try",
"{",
"delete",
"window",
"[",
"jsonpCallback",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"//swallow",
"}",
"}",
"else",
"{",
"window",
"[",
"jsonpCallback",
"]",
"=",
"previous",
";",
"}",
"if",
"(",
"callback",
"&&",
"$",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
"response",
")",
";",
"}",
"}",
";",
"script",
"=",
"document",
".",
"createElement",
"(",
"\"script\"",
")",
";",
"//TODO: having an issue with async info requests",
"if",
"(",
"undefined",
"!==",
"options",
".",
"async",
"||",
"false",
"!==",
"options",
".",
"async",
")",
"{",
"script",
".",
"async",
"=",
"\"async\"",
";",
"}",
"if",
"(",
"options",
".",
"scriptCharset",
")",
"{",
"script",
".",
"charset",
"=",
"options",
".",
"scriptCharset",
";",
"}",
"script",
".",
"src",
"=",
"url",
";",
"// Attach handlers for all browsers",
"script",
".",
"onload",
"=",
"script",
".",
"onreadystatechange",
"=",
"function",
"(",
"_",
",",
"isAbort",
")",
"{",
"if",
"(",
"isAbort",
"||",
"!",
"script",
".",
"readyState",
"||",
"/",
"loaded|complete",
"/",
".",
"test",
"(",
"script",
".",
"readyState",
")",
")",
"{",
"// Handle memory leak in IE",
"script",
".",
"onload",
"=",
"script",
".",
"onreadystatechange",
"=",
"null",
";",
"// Remove the script",
"if",
"(",
"head",
"&&",
"script",
".",
"parentNode",
")",
"{",
"head",
".",
"removeChild",
"(",
"script",
")",
";",
"}",
"// Dereference the script",
"script",
"=",
"undefined",
";",
"}",
"}",
";",
"// Use insertBefore instead of appendChild to circumvent an IE6 bug.",
"// This arises when a base node is used (#2709 and #4378).",
"head",
".",
"insertBefore",
"(",
"script",
",",
"head",
".",
"firstChild",
")",
";",
"}"
] |
Taken from jQuery 1.6.1
@function
@param {Object} options
@param {String} options.url
@param {Function} options.callback
@param {String} [options.param='callback'] The name of the url parameter
to request the jsonp provider with.
@param {String} [options.callbackName=] The name of the callback to
request the jsonp provider with.
|
[
"Taken",
"from",
"jQuery",
"1",
".",
"6",
".",
"1"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2344-L2410
|
|
10,807
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function( string ) {
if ( window.DOMParser ) {
$.parseXml = function( string ) {
var xmlDoc = null,
parser;
parser = new DOMParser();
xmlDoc = parser.parseFromString( string, "text/xml" );
return xmlDoc;
};
} else if ( window.ActiveXObject ) {
$.parseXml = function( string ) {
var xmlDoc = null;
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false;
xmlDoc.loadXML( string );
return xmlDoc;
};
} else {
throw new Error( "Browser doesn't support XML DOM." );
}
return $.parseXml( string );
}
|
javascript
|
function( string ) {
if ( window.DOMParser ) {
$.parseXml = function( string ) {
var xmlDoc = null,
parser;
parser = new DOMParser();
xmlDoc = parser.parseFromString( string, "text/xml" );
return xmlDoc;
};
} else if ( window.ActiveXObject ) {
$.parseXml = function( string ) {
var xmlDoc = null;
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false;
xmlDoc.loadXML( string );
return xmlDoc;
};
} else {
throw new Error( "Browser doesn't support XML DOM." );
}
return $.parseXml( string );
}
|
[
"function",
"(",
"string",
")",
"{",
"if",
"(",
"window",
".",
"DOMParser",
")",
"{",
"$",
".",
"parseXml",
"=",
"function",
"(",
"string",
")",
"{",
"var",
"xmlDoc",
"=",
"null",
",",
"parser",
";",
"parser",
"=",
"new",
"DOMParser",
"(",
")",
";",
"xmlDoc",
"=",
"parser",
".",
"parseFromString",
"(",
"string",
",",
"\"text/xml\"",
")",
";",
"return",
"xmlDoc",
";",
"}",
";",
"}",
"else",
"if",
"(",
"window",
".",
"ActiveXObject",
")",
"{",
"$",
".",
"parseXml",
"=",
"function",
"(",
"string",
")",
"{",
"var",
"xmlDoc",
"=",
"null",
";",
"xmlDoc",
"=",
"new",
"ActiveXObject",
"(",
"\"Microsoft.XMLDOM\"",
")",
";",
"xmlDoc",
".",
"async",
"=",
"false",
";",
"xmlDoc",
".",
"loadXML",
"(",
"string",
")",
";",
"return",
"xmlDoc",
";",
"}",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Browser doesn't support XML DOM.\"",
")",
";",
"}",
"return",
"$",
".",
"parseXml",
"(",
"string",
")",
";",
"}"
] |
Parses an XML string into a DOM Document.
@function
@param {String} string
@returns {Document}
|
[
"Parses",
"an",
"XML",
"string",
"into",
"a",
"DOM",
"Document",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2428-L2456
|
|
10,808
|
openseadragon/openseadragon
|
src/openseadragon.js
|
function(string) {
if (window.JSON && window.JSON.parse) {
$.parseJSON = window.JSON.parse;
} else {
// Should only be used by IE8 in non standards mode
$.parseJSON = function(string) {
/*jshint evil:true*/
//eslint-disable-next-line no-eval
return eval('(' + string + ')');
};
}
return $.parseJSON(string);
}
|
javascript
|
function(string) {
if (window.JSON && window.JSON.parse) {
$.parseJSON = window.JSON.parse;
} else {
// Should only be used by IE8 in non standards mode
$.parseJSON = function(string) {
/*jshint evil:true*/
//eslint-disable-next-line no-eval
return eval('(' + string + ')');
};
}
return $.parseJSON(string);
}
|
[
"function",
"(",
"string",
")",
"{",
"if",
"(",
"window",
".",
"JSON",
"&&",
"window",
".",
"JSON",
".",
"parse",
")",
"{",
"$",
".",
"parseJSON",
"=",
"window",
".",
"JSON",
".",
"parse",
";",
"}",
"else",
"{",
"// Should only be used by IE8 in non standards mode",
"$",
".",
"parseJSON",
"=",
"function",
"(",
"string",
")",
"{",
"/*jshint evil:true*/",
"//eslint-disable-next-line no-eval",
"return",
"eval",
"(",
"'('",
"+",
"string",
"+",
"')'",
")",
";",
"}",
";",
"}",
"return",
"$",
".",
"parseJSON",
"(",
"string",
")",
";",
"}"
] |
Parses a JSON string into a Javascript object.
@function
@param {String} string
@returns {Object}
|
[
"Parses",
"a",
"JSON",
"string",
"into",
"a",
"Javascript",
"object",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/openseadragon.js#L2464-L2476
|
|
10,809
|
openseadragon/openseadragon
|
src/rectangle.js
|
function(other) {
return (other instanceof $.Rect) &&
this.x === other.x &&
this.y === other.y &&
this.width === other.width &&
this.height === other.height &&
this.degrees === other.degrees;
}
|
javascript
|
function(other) {
return (other instanceof $.Rect) &&
this.x === other.x &&
this.y === other.y &&
this.width === other.width &&
this.height === other.height &&
this.degrees === other.degrees;
}
|
[
"function",
"(",
"other",
")",
"{",
"return",
"(",
"other",
"instanceof",
"$",
".",
"Rect",
")",
"&&",
"this",
".",
"x",
"===",
"other",
".",
"x",
"&&",
"this",
".",
"y",
"===",
"other",
".",
"y",
"&&",
"this",
".",
"width",
"===",
"other",
".",
"width",
"&&",
"this",
".",
"height",
"===",
"other",
".",
"height",
"&&",
"this",
".",
"degrees",
"===",
"other",
".",
"degrees",
";",
"}"
] |
Determines if two Rectangles have equivalent components.
@function
@param {OpenSeadragon.Rect} rectangle The Rectangle to compare to.
@return {Boolean} 'true' if all components are equal, otherwise 'false'.
|
[
"Determines",
"if",
"two",
"Rectangles",
"have",
"equivalent",
"components",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/rectangle.js#L240-L247
|
|
10,810
|
openseadragon/openseadragon
|
src/rectangle.js
|
function(rect) {
var thisBoundingBox = this.getBoundingBox();
var otherBoundingBox = rect.getBoundingBox();
var left = Math.min(thisBoundingBox.x, otherBoundingBox.x);
var top = Math.min(thisBoundingBox.y, otherBoundingBox.y);
var right = Math.max(
thisBoundingBox.x + thisBoundingBox.width,
otherBoundingBox.x + otherBoundingBox.width);
var bottom = Math.max(
thisBoundingBox.y + thisBoundingBox.height,
otherBoundingBox.y + otherBoundingBox.height);
return new $.Rect(
left,
top,
right - left,
bottom - top);
}
|
javascript
|
function(rect) {
var thisBoundingBox = this.getBoundingBox();
var otherBoundingBox = rect.getBoundingBox();
var left = Math.min(thisBoundingBox.x, otherBoundingBox.x);
var top = Math.min(thisBoundingBox.y, otherBoundingBox.y);
var right = Math.max(
thisBoundingBox.x + thisBoundingBox.width,
otherBoundingBox.x + otherBoundingBox.width);
var bottom = Math.max(
thisBoundingBox.y + thisBoundingBox.height,
otherBoundingBox.y + otherBoundingBox.height);
return new $.Rect(
left,
top,
right - left,
bottom - top);
}
|
[
"function",
"(",
"rect",
")",
"{",
"var",
"thisBoundingBox",
"=",
"this",
".",
"getBoundingBox",
"(",
")",
";",
"var",
"otherBoundingBox",
"=",
"rect",
".",
"getBoundingBox",
"(",
")",
";",
"var",
"left",
"=",
"Math",
".",
"min",
"(",
"thisBoundingBox",
".",
"x",
",",
"otherBoundingBox",
".",
"x",
")",
";",
"var",
"top",
"=",
"Math",
".",
"min",
"(",
"thisBoundingBox",
".",
"y",
",",
"otherBoundingBox",
".",
"y",
")",
";",
"var",
"right",
"=",
"Math",
".",
"max",
"(",
"thisBoundingBox",
".",
"x",
"+",
"thisBoundingBox",
".",
"width",
",",
"otherBoundingBox",
".",
"x",
"+",
"otherBoundingBox",
".",
"width",
")",
";",
"var",
"bottom",
"=",
"Math",
".",
"max",
"(",
"thisBoundingBox",
".",
"y",
"+",
"thisBoundingBox",
".",
"height",
",",
"otherBoundingBox",
".",
"y",
"+",
"otherBoundingBox",
".",
"height",
")",
";",
"return",
"new",
"$",
".",
"Rect",
"(",
"left",
",",
"top",
",",
"right",
"-",
"left",
",",
"bottom",
"-",
"top",
")",
";",
"}"
] |
Returns the smallest rectangle that will contain this and the given
rectangle bounding boxes.
@param {OpenSeadragon.Rect} rect
@return {OpenSeadragon.Rect} The new rectangle.
|
[
"Returns",
"the",
"smallest",
"rectangle",
"that",
"will",
"contain",
"this",
"and",
"the",
"given",
"rectangle",
"bounding",
"boxes",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/rectangle.js#L287-L305
|
|
10,811
|
openseadragon/openseadragon
|
src/rectangle.js
|
function(degrees, pivot) {
degrees = $.positiveModulo(degrees, 360);
if (degrees === 0) {
return this.clone();
}
pivot = pivot || this.getCenter();
var newTopLeft = this.getTopLeft().rotate(degrees, pivot);
var newTopRight = this.getTopRight().rotate(degrees, pivot);
var diff = newTopRight.minus(newTopLeft);
// Handle floating point error
diff = diff.apply(function(x) {
var EPSILON = 1e-15;
return Math.abs(x) < EPSILON ? 0 : x;
});
var radians = Math.atan(diff.y / diff.x);
if (diff.x < 0) {
radians += Math.PI;
} else if (diff.y < 0) {
radians += 2 * Math.PI;
}
return new $.Rect(
newTopLeft.x,
newTopLeft.y,
this.width,
this.height,
radians / Math.PI * 180);
}
|
javascript
|
function(degrees, pivot) {
degrees = $.positiveModulo(degrees, 360);
if (degrees === 0) {
return this.clone();
}
pivot = pivot || this.getCenter();
var newTopLeft = this.getTopLeft().rotate(degrees, pivot);
var newTopRight = this.getTopRight().rotate(degrees, pivot);
var diff = newTopRight.minus(newTopLeft);
// Handle floating point error
diff = diff.apply(function(x) {
var EPSILON = 1e-15;
return Math.abs(x) < EPSILON ? 0 : x;
});
var radians = Math.atan(diff.y / diff.x);
if (diff.x < 0) {
radians += Math.PI;
} else if (diff.y < 0) {
radians += 2 * Math.PI;
}
return new $.Rect(
newTopLeft.x,
newTopLeft.y,
this.width,
this.height,
radians / Math.PI * 180);
}
|
[
"function",
"(",
"degrees",
",",
"pivot",
")",
"{",
"degrees",
"=",
"$",
".",
"positiveModulo",
"(",
"degrees",
",",
"360",
")",
";",
"if",
"(",
"degrees",
"===",
"0",
")",
"{",
"return",
"this",
".",
"clone",
"(",
")",
";",
"}",
"pivot",
"=",
"pivot",
"||",
"this",
".",
"getCenter",
"(",
")",
";",
"var",
"newTopLeft",
"=",
"this",
".",
"getTopLeft",
"(",
")",
".",
"rotate",
"(",
"degrees",
",",
"pivot",
")",
";",
"var",
"newTopRight",
"=",
"this",
".",
"getTopRight",
"(",
")",
".",
"rotate",
"(",
"degrees",
",",
"pivot",
")",
";",
"var",
"diff",
"=",
"newTopRight",
".",
"minus",
"(",
"newTopLeft",
")",
";",
"// Handle floating point error",
"diff",
"=",
"diff",
".",
"apply",
"(",
"function",
"(",
"x",
")",
"{",
"var",
"EPSILON",
"=",
"1e-15",
";",
"return",
"Math",
".",
"abs",
"(",
"x",
")",
"<",
"EPSILON",
"?",
"0",
":",
"x",
";",
"}",
")",
";",
"var",
"radians",
"=",
"Math",
".",
"atan",
"(",
"diff",
".",
"y",
"/",
"diff",
".",
"x",
")",
";",
"if",
"(",
"diff",
".",
"x",
"<",
"0",
")",
"{",
"radians",
"+=",
"Math",
".",
"PI",
";",
"}",
"else",
"if",
"(",
"diff",
".",
"y",
"<",
"0",
")",
"{",
"radians",
"+=",
"2",
"*",
"Math",
".",
"PI",
";",
"}",
"return",
"new",
"$",
".",
"Rect",
"(",
"newTopLeft",
".",
"x",
",",
"newTopLeft",
".",
"y",
",",
"this",
".",
"width",
",",
"this",
".",
"height",
",",
"radians",
"/",
"Math",
".",
"PI",
"*",
"180",
")",
";",
"}"
] |
Rotates a rectangle around a point.
@function
@param {Number} degrees The angle in degrees to rotate.
@param {OpenSeadragon.Point} [pivot] The point about which to rotate.
Defaults to the center of the rectangle.
@return {OpenSeadragon.Rect}
|
[
"Rotates",
"a",
"rectangle",
"around",
"a",
"point",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/rectangle.js#L441-L469
|
|
10,812
|
openseadragon/openseadragon
|
src/rectangle.js
|
function() {
return "[" +
(Math.round(this.x * 100) / 100) + ", " +
(Math.round(this.y * 100) / 100) + ", " +
(Math.round(this.width * 100) / 100) + "x" +
(Math.round(this.height * 100) / 100) + ", " +
(Math.round(this.degrees * 100) / 100) + "deg" +
"]";
}
|
javascript
|
function() {
return "[" +
(Math.round(this.x * 100) / 100) + ", " +
(Math.round(this.y * 100) / 100) + ", " +
(Math.round(this.width * 100) / 100) + "x" +
(Math.round(this.height * 100) / 100) + ", " +
(Math.round(this.degrees * 100) / 100) + "deg" +
"]";
}
|
[
"function",
"(",
")",
"{",
"return",
"\"[\"",
"+",
"(",
"Math",
".",
"round",
"(",
"this",
".",
"x",
"*",
"100",
")",
"/",
"100",
")",
"+",
"\", \"",
"+",
"(",
"Math",
".",
"round",
"(",
"this",
".",
"y",
"*",
"100",
")",
"/",
"100",
")",
"+",
"\", \"",
"+",
"(",
"Math",
".",
"round",
"(",
"this",
".",
"width",
"*",
"100",
")",
"/",
"100",
")",
"+",
"\"x\"",
"+",
"(",
"Math",
".",
"round",
"(",
"this",
".",
"height",
"*",
"100",
")",
"/",
"100",
")",
"+",
"\", \"",
"+",
"(",
"Math",
".",
"round",
"(",
"this",
".",
"degrees",
"*",
"100",
")",
"/",
"100",
")",
"+",
"\"deg\"",
"+",
"\"]\"",
";",
"}"
] |
Provides a string representation of the rectangle which is useful for
debugging.
@function
@returns {String} A string representation of the rectangle.
|
[
"Provides",
"a",
"string",
"representation",
"of",
"the",
"rectangle",
"which",
"is",
"useful",
"for",
"debugging",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/rectangle.js#L546-L554
|
|
10,813
|
openseadragon/openseadragon
|
src/legacytilesource.js
|
filterFiles
|
function filterFiles( files ){
var filtered = [],
file,
i;
for( i = 0; i < files.length; i++ ){
file = files[ i ];
if( file.height &&
file.width &&
file.url ){
//This is sufficient to serve as a level
filtered.push({
url: file.url,
width: Number( file.width ),
height: Number( file.height )
});
}
else {
$.console.error( 'Unsupported image format: %s', file.url ? file.url : '<no URL>' );
}
}
return filtered.sort(function(a, b) {
return a.height - b.height;
});
}
|
javascript
|
function filterFiles( files ){
var filtered = [],
file,
i;
for( i = 0; i < files.length; i++ ){
file = files[ i ];
if( file.height &&
file.width &&
file.url ){
//This is sufficient to serve as a level
filtered.push({
url: file.url,
width: Number( file.width ),
height: Number( file.height )
});
}
else {
$.console.error( 'Unsupported image format: %s', file.url ? file.url : '<no URL>' );
}
}
return filtered.sort(function(a, b) {
return a.height - b.height;
});
}
|
[
"function",
"filterFiles",
"(",
"files",
")",
"{",
"var",
"filtered",
"=",
"[",
"]",
",",
"file",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"files",
".",
"length",
";",
"i",
"++",
")",
"{",
"file",
"=",
"files",
"[",
"i",
"]",
";",
"if",
"(",
"file",
".",
"height",
"&&",
"file",
".",
"width",
"&&",
"file",
".",
"url",
")",
"{",
"//This is sufficient to serve as a level",
"filtered",
".",
"push",
"(",
"{",
"url",
":",
"file",
".",
"url",
",",
"width",
":",
"Number",
"(",
"file",
".",
"width",
")",
",",
"height",
":",
"Number",
"(",
"file",
".",
"height",
")",
"}",
")",
";",
"}",
"else",
"{",
"$",
".",
"console",
".",
"error",
"(",
"'Unsupported image format: %s'",
",",
"file",
".",
"url",
"?",
"file",
".",
"url",
":",
"'<no URL>'",
")",
";",
"}",
"}",
"return",
"filtered",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"height",
"-",
"b",
".",
"height",
";",
"}",
")",
";",
"}"
] |
This method removes any files from the Array which don't conform to our
basic requirements for a 'level' in the LegacyTileSource.
@private
@inner
@function
|
[
"This",
"method",
"removes",
"any",
"files",
"from",
"the",
"Array",
"which",
"don",
"t",
"conform",
"to",
"our",
"basic",
"requirements",
"for",
"a",
"level",
"in",
"the",
"LegacyTileSource",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/legacytilesource.js#L199-L224
|
10,814
|
openseadragon/openseadragon
|
src/viewer.js
|
function( ) {
if ( !THIS[ this.hash ] ) {
//this viewer has already been destroyed: returning immediately
return;
}
this.close();
this.clearOverlays();
this.overlaysContainer.innerHTML = "";
//TODO: implement this...
//this.unbindSequenceControls()
//this.unbindStandardControls()
if (this.referenceStrip) {
this.referenceStrip.destroy();
this.referenceStrip = null;
}
if ( this._updateRequestId !== null ) {
$.cancelAnimationFrame( this._updateRequestId );
this._updateRequestId = null;
}
if ( this.drawer ) {
this.drawer.destroy();
}
this.removeAllHandlers();
// Go through top element (passed to us) and remove all children
// Use removeChild to make sure it handles SVG or any non-html
// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
if (this.element){
while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
}
// destroy the mouse trackers
if (this.innerTracker){
this.innerTracker.destroy();
}
if (this.outerTracker){
this.outerTracker.destroy();
}
THIS[ this.hash ] = null;
delete THIS[ this.hash ];
// clear all our references to dom objects
this.canvas = null;
this.container = null;
// clear our reference to the main element - they will need to pass it in again, creating a new viewer
this.element = null;
}
|
javascript
|
function( ) {
if ( !THIS[ this.hash ] ) {
//this viewer has already been destroyed: returning immediately
return;
}
this.close();
this.clearOverlays();
this.overlaysContainer.innerHTML = "";
//TODO: implement this...
//this.unbindSequenceControls()
//this.unbindStandardControls()
if (this.referenceStrip) {
this.referenceStrip.destroy();
this.referenceStrip = null;
}
if ( this._updateRequestId !== null ) {
$.cancelAnimationFrame( this._updateRequestId );
this._updateRequestId = null;
}
if ( this.drawer ) {
this.drawer.destroy();
}
this.removeAllHandlers();
// Go through top element (passed to us) and remove all children
// Use removeChild to make sure it handles SVG or any non-html
// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
if (this.element){
while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
}
// destroy the mouse trackers
if (this.innerTracker){
this.innerTracker.destroy();
}
if (this.outerTracker){
this.outerTracker.destroy();
}
THIS[ this.hash ] = null;
delete THIS[ this.hash ];
// clear all our references to dom objects
this.canvas = null;
this.container = null;
// clear our reference to the main element - they will need to pass it in again, creating a new viewer
this.element = null;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"THIS",
"[",
"this",
".",
"hash",
"]",
")",
"{",
"//this viewer has already been destroyed: returning immediately",
"return",
";",
"}",
"this",
".",
"close",
"(",
")",
";",
"this",
".",
"clearOverlays",
"(",
")",
";",
"this",
".",
"overlaysContainer",
".",
"innerHTML",
"=",
"\"\"",
";",
"//TODO: implement this...",
"//this.unbindSequenceControls()",
"//this.unbindStandardControls()",
"if",
"(",
"this",
".",
"referenceStrip",
")",
"{",
"this",
".",
"referenceStrip",
".",
"destroy",
"(",
")",
";",
"this",
".",
"referenceStrip",
"=",
"null",
";",
"}",
"if",
"(",
"this",
".",
"_updateRequestId",
"!==",
"null",
")",
"{",
"$",
".",
"cancelAnimationFrame",
"(",
"this",
".",
"_updateRequestId",
")",
";",
"this",
".",
"_updateRequestId",
"=",
"null",
";",
"}",
"if",
"(",
"this",
".",
"drawer",
")",
"{",
"this",
".",
"drawer",
".",
"destroy",
"(",
")",
";",
"}",
"this",
".",
"removeAllHandlers",
"(",
")",
";",
"// Go through top element (passed to us) and remove all children",
"// Use removeChild to make sure it handles SVG or any non-html",
"// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15",
"if",
"(",
"this",
".",
"element",
")",
"{",
"while",
"(",
"this",
".",
"element",
".",
"firstChild",
")",
"{",
"this",
".",
"element",
".",
"removeChild",
"(",
"this",
".",
"element",
".",
"firstChild",
")",
";",
"}",
"}",
"// destroy the mouse trackers",
"if",
"(",
"this",
".",
"innerTracker",
")",
"{",
"this",
".",
"innerTracker",
".",
"destroy",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"outerTracker",
")",
"{",
"this",
".",
"outerTracker",
".",
"destroy",
"(",
")",
";",
"}",
"THIS",
"[",
"this",
".",
"hash",
"]",
"=",
"null",
";",
"delete",
"THIS",
"[",
"this",
".",
"hash",
"]",
";",
"// clear all our references to dom objects",
"this",
".",
"canvas",
"=",
"null",
";",
"this",
".",
"container",
"=",
"null",
";",
"// clear our reference to the main element - they will need to pass it in again, creating a new viewer",
"this",
".",
"element",
"=",
"null",
";",
"}"
] |
Function to destroy the viewer and clean up everything created by OpenSeadragon.
Example:
var viewer = OpenSeadragon({
[...]
});
//when you are done with the viewer:
viewer.destroy();
viewer = null; //important
@function
|
[
"Function",
"to",
"destroy",
"the",
"viewer",
"and",
"clean",
"up",
"everything",
"created",
"by",
"OpenSeadragon",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L739-L796
|
|
10,815
|
openseadragon/openseadragon
|
src/viewer.js
|
function(debugMode){
for (var i = 0; i < this.world.getItemCount(); i++) {
this.world.getItemAt(i).debugMode = debugMode;
}
this.debugMode = debugMode;
this.forceRedraw();
}
|
javascript
|
function(debugMode){
for (var i = 0; i < this.world.getItemCount(); i++) {
this.world.getItemAt(i).debugMode = debugMode;
}
this.debugMode = debugMode;
this.forceRedraw();
}
|
[
"function",
"(",
"debugMode",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"world",
".",
"getItemCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"this",
".",
"world",
".",
"getItemAt",
"(",
"i",
")",
".",
"debugMode",
"=",
"debugMode",
";",
"}",
"this",
".",
"debugMode",
"=",
"debugMode",
";",
"this",
".",
"forceRedraw",
"(",
")",
";",
"}"
] |
Turns debugging mode on or off for this viewer.
@function
@param {Boolean} true to turn debug on, false to turn debug off.
|
[
"Turns",
"debugging",
"mode",
"on",
"or",
"off",
"for",
"this",
"viewer",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L878-L886
|
|
10,816
|
openseadragon/openseadragon
|
src/viewer.js
|
function( fullScreen ) {
var _this = this;
if ( !$.supportsFullScreen ) {
return this.setFullPage( fullScreen );
}
if ( $.isFullScreen() === fullScreen ) {
return this;
}
var fullScreeEventArgs = {
fullScreen: fullScreen,
preventDefaultAction: false
};
/**
* Raised when the viewer is about to change to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).
* Note: the pre-full-screen event is not raised when the user is exiting
* full-screen mode by pressing the Esc key. In that case, consider using
* the full-screen, pre-full-page or full-page events.
*
* @event pre-full-screen
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Boolean} fullScreen - True if entering full-screen mode, false if exiting full-screen mode.
* @property {Boolean} preventDefaultAction - Set to true to prevent full-screen mode change. Default: false.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'pre-full-screen', fullScreeEventArgs );
if ( fullScreeEventArgs.preventDefaultAction ) {
return this;
}
if ( fullScreen ) {
this.setFullPage( true );
// If the full page mode is not actually entered, we need to prevent
// the full screen mode.
if ( !this.isFullPage() ) {
return this;
}
this.fullPageStyleWidth = this.element.style.width;
this.fullPageStyleHeight = this.element.style.height;
this.element.style.width = '100%';
this.element.style.height = '100%';
var onFullScreenChange = function() {
var isFullScreen = $.isFullScreen();
if ( !isFullScreen ) {
$.removeEvent( document, $.fullScreenEventName, onFullScreenChange );
$.removeEvent( document, $.fullScreenErrorEventName, onFullScreenChange );
_this.setFullPage( false );
if ( _this.isFullPage() ) {
_this.element.style.width = _this.fullPageStyleWidth;
_this.element.style.height = _this.fullPageStyleHeight;
}
}
if ( _this.navigator && _this.viewport ) {
//09/08/2018 - Fabroh : Fix issue #1504 : Ensure to get the navigator updated on fullscreen out with custom location with a timeout
setTimeout(function(){
_this.navigator.update( _this.viewport );
});
}
/**
* Raised when the viewer has changed to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).
*
* @event full-screen
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Boolean} fullScreen - True if changed to full-screen mode, false if exited full-screen mode.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
_this.raiseEvent( 'full-screen', { fullScreen: isFullScreen } );
};
$.addEvent( document, $.fullScreenEventName, onFullScreenChange );
$.addEvent( document, $.fullScreenErrorEventName, onFullScreenChange );
$.requestFullScreen( document.body );
} else {
$.exitFullScreen();
}
return this;
}
|
javascript
|
function( fullScreen ) {
var _this = this;
if ( !$.supportsFullScreen ) {
return this.setFullPage( fullScreen );
}
if ( $.isFullScreen() === fullScreen ) {
return this;
}
var fullScreeEventArgs = {
fullScreen: fullScreen,
preventDefaultAction: false
};
/**
* Raised when the viewer is about to change to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).
* Note: the pre-full-screen event is not raised when the user is exiting
* full-screen mode by pressing the Esc key. In that case, consider using
* the full-screen, pre-full-page or full-page events.
*
* @event pre-full-screen
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Boolean} fullScreen - True if entering full-screen mode, false if exiting full-screen mode.
* @property {Boolean} preventDefaultAction - Set to true to prevent full-screen mode change. Default: false.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'pre-full-screen', fullScreeEventArgs );
if ( fullScreeEventArgs.preventDefaultAction ) {
return this;
}
if ( fullScreen ) {
this.setFullPage( true );
// If the full page mode is not actually entered, we need to prevent
// the full screen mode.
if ( !this.isFullPage() ) {
return this;
}
this.fullPageStyleWidth = this.element.style.width;
this.fullPageStyleHeight = this.element.style.height;
this.element.style.width = '100%';
this.element.style.height = '100%';
var onFullScreenChange = function() {
var isFullScreen = $.isFullScreen();
if ( !isFullScreen ) {
$.removeEvent( document, $.fullScreenEventName, onFullScreenChange );
$.removeEvent( document, $.fullScreenErrorEventName, onFullScreenChange );
_this.setFullPage( false );
if ( _this.isFullPage() ) {
_this.element.style.width = _this.fullPageStyleWidth;
_this.element.style.height = _this.fullPageStyleHeight;
}
}
if ( _this.navigator && _this.viewport ) {
//09/08/2018 - Fabroh : Fix issue #1504 : Ensure to get the navigator updated on fullscreen out with custom location with a timeout
setTimeout(function(){
_this.navigator.update( _this.viewport );
});
}
/**
* Raised when the viewer has changed to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).
*
* @event full-screen
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Boolean} fullScreen - True if changed to full-screen mode, false if exited full-screen mode.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
_this.raiseEvent( 'full-screen', { fullScreen: isFullScreen } );
};
$.addEvent( document, $.fullScreenEventName, onFullScreenChange );
$.addEvent( document, $.fullScreenErrorEventName, onFullScreenChange );
$.requestFullScreen( document.body );
} else {
$.exitFullScreen();
}
return this;
}
|
[
"function",
"(",
"fullScreen",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"if",
"(",
"!",
"$",
".",
"supportsFullScreen",
")",
"{",
"return",
"this",
".",
"setFullPage",
"(",
"fullScreen",
")",
";",
"}",
"if",
"(",
"$",
".",
"isFullScreen",
"(",
")",
"===",
"fullScreen",
")",
"{",
"return",
"this",
";",
"}",
"var",
"fullScreeEventArgs",
"=",
"{",
"fullScreen",
":",
"fullScreen",
",",
"preventDefaultAction",
":",
"false",
"}",
";",
"/**\n * Raised when the viewer is about to change to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).\n * Note: the pre-full-screen event is not raised when the user is exiting\n * full-screen mode by pressing the Esc key. In that case, consider using\n * the full-screen, pre-full-page or full-page events.\n *\n * @event pre-full-screen\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {Boolean} fullScreen - True if entering full-screen mode, false if exiting full-screen mode.\n * @property {Boolean} preventDefaultAction - Set to true to prevent full-screen mode change. Default: false.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'pre-full-screen'",
",",
"fullScreeEventArgs",
")",
";",
"if",
"(",
"fullScreeEventArgs",
".",
"preventDefaultAction",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"fullScreen",
")",
"{",
"this",
".",
"setFullPage",
"(",
"true",
")",
";",
"// If the full page mode is not actually entered, we need to prevent",
"// the full screen mode.",
"if",
"(",
"!",
"this",
".",
"isFullPage",
"(",
")",
")",
"{",
"return",
"this",
";",
"}",
"this",
".",
"fullPageStyleWidth",
"=",
"this",
".",
"element",
".",
"style",
".",
"width",
";",
"this",
".",
"fullPageStyleHeight",
"=",
"this",
".",
"element",
".",
"style",
".",
"height",
";",
"this",
".",
"element",
".",
"style",
".",
"width",
"=",
"'100%'",
";",
"this",
".",
"element",
".",
"style",
".",
"height",
"=",
"'100%'",
";",
"var",
"onFullScreenChange",
"=",
"function",
"(",
")",
"{",
"var",
"isFullScreen",
"=",
"$",
".",
"isFullScreen",
"(",
")",
";",
"if",
"(",
"!",
"isFullScreen",
")",
"{",
"$",
".",
"removeEvent",
"(",
"document",
",",
"$",
".",
"fullScreenEventName",
",",
"onFullScreenChange",
")",
";",
"$",
".",
"removeEvent",
"(",
"document",
",",
"$",
".",
"fullScreenErrorEventName",
",",
"onFullScreenChange",
")",
";",
"_this",
".",
"setFullPage",
"(",
"false",
")",
";",
"if",
"(",
"_this",
".",
"isFullPage",
"(",
")",
")",
"{",
"_this",
".",
"element",
".",
"style",
".",
"width",
"=",
"_this",
".",
"fullPageStyleWidth",
";",
"_this",
".",
"element",
".",
"style",
".",
"height",
"=",
"_this",
".",
"fullPageStyleHeight",
";",
"}",
"}",
"if",
"(",
"_this",
".",
"navigator",
"&&",
"_this",
".",
"viewport",
")",
"{",
"//09/08/2018 - Fabroh : Fix issue #1504 : Ensure to get the navigator updated on fullscreen out with custom location with a timeout",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"_this",
".",
"navigator",
".",
"update",
"(",
"_this",
".",
"viewport",
")",
";",
"}",
")",
";",
"}",
"/**\n * Raised when the viewer has changed to/from full-screen mode (see {@link OpenSeadragon.Viewer#setFullScreen}).\n *\n * @event full-screen\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {Boolean} fullScreen - True if changed to full-screen mode, false if exited full-screen mode.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"_this",
".",
"raiseEvent",
"(",
"'full-screen'",
",",
"{",
"fullScreen",
":",
"isFullScreen",
"}",
")",
";",
"}",
";",
"$",
".",
"addEvent",
"(",
"document",
",",
"$",
".",
"fullScreenEventName",
",",
"onFullScreenChange",
")",
";",
"$",
".",
"addEvent",
"(",
"document",
",",
"$",
".",
"fullScreenErrorEventName",
",",
"onFullScreenChange",
")",
";",
"$",
".",
"requestFullScreen",
"(",
"document",
".",
"body",
")",
";",
"}",
"else",
"{",
"$",
".",
"exitFullScreen",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Toggle full screen mode if supported. Toggle full page mode otherwise.
@function
@param {Boolean} fullScreen
If true, enter full screen mode. If false, exit full screen mode.
@return {OpenSeadragon.Viewer} Chainable.
@fires OpenSeadragon.Viewer.event:pre-full-screen
@fires OpenSeadragon.Viewer.event:full-screen
|
[
"Toggle",
"full",
"screen",
"mode",
"if",
"supported",
".",
"Toggle",
"full",
"page",
"mode",
"otherwise",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L1116-L1203
|
|
10,817
|
openseadragon/openseadragon
|
src/viewer.js
|
function( element, location, placement, onDraw ) {
var options;
if( $.isPlainObject( element ) ){
options = element;
} else {
options = {
element: element,
location: location,
placement: placement,
onDraw: onDraw
};
}
element = $.getElement( options.element );
if ( getOverlayIndex( this.currentOverlays, element ) >= 0 ) {
// they're trying to add a duplicate overlay
return this;
}
var overlay = getOverlayObject( this, options);
this.currentOverlays.push(overlay);
overlay.drawHTML( this.overlaysContainer, this.viewport );
/**
* Raised when an overlay is added to the viewer (see {@link OpenSeadragon.Viewer#addOverlay}).
*
* @event add-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Element} element - The overlay element.
* @property {OpenSeadragon.Point|OpenSeadragon.Rect} location
* @property {OpenSeadragon.Placement} placement
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'add-overlay', {
element: element,
location: options.location,
placement: options.placement
});
return this;
}
|
javascript
|
function( element, location, placement, onDraw ) {
var options;
if( $.isPlainObject( element ) ){
options = element;
} else {
options = {
element: element,
location: location,
placement: placement,
onDraw: onDraw
};
}
element = $.getElement( options.element );
if ( getOverlayIndex( this.currentOverlays, element ) >= 0 ) {
// they're trying to add a duplicate overlay
return this;
}
var overlay = getOverlayObject( this, options);
this.currentOverlays.push(overlay);
overlay.drawHTML( this.overlaysContainer, this.viewport );
/**
* Raised when an overlay is added to the viewer (see {@link OpenSeadragon.Viewer#addOverlay}).
*
* @event add-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Element} element - The overlay element.
* @property {OpenSeadragon.Point|OpenSeadragon.Rect} location
* @property {OpenSeadragon.Placement} placement
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'add-overlay', {
element: element,
location: options.location,
placement: options.placement
});
return this;
}
|
[
"function",
"(",
"element",
",",
"location",
",",
"placement",
",",
"onDraw",
")",
"{",
"var",
"options",
";",
"if",
"(",
"$",
".",
"isPlainObject",
"(",
"element",
")",
")",
"{",
"options",
"=",
"element",
";",
"}",
"else",
"{",
"options",
"=",
"{",
"element",
":",
"element",
",",
"location",
":",
"location",
",",
"placement",
":",
"placement",
",",
"onDraw",
":",
"onDraw",
"}",
";",
"}",
"element",
"=",
"$",
".",
"getElement",
"(",
"options",
".",
"element",
")",
";",
"if",
"(",
"getOverlayIndex",
"(",
"this",
".",
"currentOverlays",
",",
"element",
")",
">=",
"0",
")",
"{",
"// they're trying to add a duplicate overlay",
"return",
"this",
";",
"}",
"var",
"overlay",
"=",
"getOverlayObject",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"currentOverlays",
".",
"push",
"(",
"overlay",
")",
";",
"overlay",
".",
"drawHTML",
"(",
"this",
".",
"overlaysContainer",
",",
"this",
".",
"viewport",
")",
";",
"/**\n * Raised when an overlay is added to the viewer (see {@link OpenSeadragon.Viewer#addOverlay}).\n *\n * @event add-overlay\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {Element} element - The overlay element.\n * @property {OpenSeadragon.Point|OpenSeadragon.Rect} location\n * @property {OpenSeadragon.Placement} placement\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'add-overlay'",
",",
"{",
"element",
":",
"element",
",",
"location",
":",
"options",
".",
"location",
",",
"placement",
":",
"options",
".",
"placement",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds an html element as an overlay to the current viewport. Useful for
highlighting words or areas of interest on an image or other zoomable
interface. The overlays added via this method are removed when the viewport
is closed which include when changing page.
@method
@param {Element|String|Object} element - A reference to an element or an id for
the element which will be overlaid. Or an Object specifying the configuration for the overlay.
If using an object, see {@link OpenSeadragon.Overlay} for a list of
all available options.
@param {OpenSeadragon.Point|OpenSeadragon.Rect} location - The point or
rectangle which will be overlaid. This is a viewport relative location.
@param {OpenSeadragon.Placement} placement - The position of the
viewport which the location coordinates will be treated as relative
to.
@param {function} onDraw - If supplied the callback is called when the overlay
needs to be drawn. It it the responsibility of the callback to do any drawing/positioning.
It is passed position, size and element.
@return {OpenSeadragon.Viewer} Chainable.
@fires OpenSeadragon.Viewer.event:add-overlay
|
[
"Adds",
"an",
"html",
"element",
"as",
"an",
"overlay",
"to",
"the",
"current",
"viewport",
".",
"Useful",
"for",
"highlighting",
"words",
"or",
"areas",
"of",
"interest",
"on",
"an",
"image",
"or",
"other",
"zoomable",
"interface",
".",
"The",
"overlays",
"added",
"via",
"this",
"method",
"are",
"removed",
"when",
"the",
"viewport",
"is",
"closed",
"which",
"include",
"when",
"changing",
"page",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L1923-L1965
|
|
10,818
|
openseadragon/openseadragon
|
src/viewer.js
|
function( element, location, placement ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if ( i >= 0 ) {
this.currentOverlays[ i ].update( location, placement );
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when an overlay's location or placement changes
* (see {@link OpenSeadragon.Viewer#updateOverlay}).
*
* @event update-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the
* Viewer which raised the event.
* @property {Element} element
* @property {OpenSeadragon.Point|OpenSeadragon.Rect} location
* @property {OpenSeadragon.Placement} placement
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'update-overlay', {
element: element,
location: location,
placement: placement
});
}
return this;
}
|
javascript
|
function( element, location, placement ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if ( i >= 0 ) {
this.currentOverlays[ i ].update( location, placement );
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when an overlay's location or placement changes
* (see {@link OpenSeadragon.Viewer#updateOverlay}).
*
* @event update-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the
* Viewer which raised the event.
* @property {Element} element
* @property {OpenSeadragon.Point|OpenSeadragon.Rect} location
* @property {OpenSeadragon.Placement} placement
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'update-overlay', {
element: element,
location: location,
placement: placement
});
}
return this;
}
|
[
"function",
"(",
"element",
",",
"location",
",",
"placement",
")",
"{",
"var",
"i",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"i",
"=",
"getOverlayIndex",
"(",
"this",
".",
"currentOverlays",
",",
"element",
")",
";",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"this",
".",
"currentOverlays",
"[",
"i",
"]",
".",
"update",
"(",
"location",
",",
"placement",
")",
";",
"THIS",
"[",
"this",
".",
"hash",
"]",
".",
"forceRedraw",
"=",
"true",
";",
"/**\n * Raised when an overlay's location or placement changes\n * (see {@link OpenSeadragon.Viewer#updateOverlay}).\n *\n * @event update-overlay\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the\n * Viewer which raised the event.\n * @property {Element} element\n * @property {OpenSeadragon.Point|OpenSeadragon.Rect} location\n * @property {OpenSeadragon.Placement} placement\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'update-overlay'",
",",
"{",
"element",
":",
"element",
",",
"location",
":",
"location",
",",
"placement",
":",
"placement",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Updates the overlay represented by the reference to the element or
element id moving it to the new location, relative to the new placement.
@method
@param {Element|String} element - A reference to an element or an id for
the element which is overlaid.
@param {OpenSeadragon.Point|OpenSeadragon.Rect} location - The point or
rectangle which will be overlaid. This is a viewport relative location.
@param {OpenSeadragon.Placement} placement - The position of the
viewport which the location coordinates will be treated as relative
to.
@return {OpenSeadragon.Viewer} Chainable.
@fires OpenSeadragon.Viewer.event:update-overlay
|
[
"Updates",
"the",
"overlay",
"represented",
"by",
"the",
"reference",
"to",
"the",
"element",
"or",
"element",
"id",
"moving",
"it",
"to",
"the",
"new",
"location",
"relative",
"to",
"the",
"new",
"placement",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L1981-L2011
|
|
10,819
|
openseadragon/openseadragon
|
src/viewer.js
|
function( element ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if ( i >= 0 ) {
this.currentOverlays[ i ].destroy();
this.currentOverlays.splice( i, 1 );
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when an overlay is removed from the viewer
* (see {@link OpenSeadragon.Viewer#removeOverlay}).
*
* @event remove-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the
* Viewer which raised the event.
* @property {Element} element - The overlay element.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'remove-overlay', {
element: element
});
}
return this;
}
|
javascript
|
function( element ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if ( i >= 0 ) {
this.currentOverlays[ i ].destroy();
this.currentOverlays.splice( i, 1 );
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when an overlay is removed from the viewer
* (see {@link OpenSeadragon.Viewer#removeOverlay}).
*
* @event remove-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the
* Viewer which raised the event.
* @property {Element} element - The overlay element.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'remove-overlay', {
element: element
});
}
return this;
}
|
[
"function",
"(",
"element",
")",
"{",
"var",
"i",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"i",
"=",
"getOverlayIndex",
"(",
"this",
".",
"currentOverlays",
",",
"element",
")",
";",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"this",
".",
"currentOverlays",
"[",
"i",
"]",
".",
"destroy",
"(",
")",
";",
"this",
".",
"currentOverlays",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"THIS",
"[",
"this",
".",
"hash",
"]",
".",
"forceRedraw",
"=",
"true",
";",
"/**\n * Raised when an overlay is removed from the viewer\n * (see {@link OpenSeadragon.Viewer#removeOverlay}).\n *\n * @event remove-overlay\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the\n * Viewer which raised the event.\n * @property {Element} element - The overlay element.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'remove-overlay'",
",",
"{",
"element",
":",
"element",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Removes an overlay identified by the reference element or element id
and schedules an update.
@method
@param {Element|String} element - A reference to the element or an
element id which represent the ovelay content to be removed.
@return {OpenSeadragon.Viewer} Chainable.
@fires OpenSeadragon.Viewer.event:remove-overlay
|
[
"Removes",
"an",
"overlay",
"identified",
"by",
"the",
"reference",
"element",
"or",
"element",
"id",
"and",
"schedules",
"an",
"update",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2022-L2049
|
|
10,820
|
openseadragon/openseadragon
|
src/viewer.js
|
function() {
while ( this.currentOverlays.length > 0 ) {
this.currentOverlays.pop().destroy();
}
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when all overlays are removed from the viewer (see {@link OpenSeadragon.Drawer#clearOverlays}).
*
* @event clear-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'clear-overlay', {} );
return this;
}
|
javascript
|
function() {
while ( this.currentOverlays.length > 0 ) {
this.currentOverlays.pop().destroy();
}
THIS[ this.hash ].forceRedraw = true;
/**
* Raised when all overlays are removed from the viewer (see {@link OpenSeadragon.Drawer#clearOverlays}).
*
* @event clear-overlay
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'clear-overlay', {} );
return this;
}
|
[
"function",
"(",
")",
"{",
"while",
"(",
"this",
".",
"currentOverlays",
".",
"length",
">",
"0",
")",
"{",
"this",
".",
"currentOverlays",
".",
"pop",
"(",
")",
".",
"destroy",
"(",
")",
";",
"}",
"THIS",
"[",
"this",
".",
"hash",
"]",
".",
"forceRedraw",
"=",
"true",
";",
"/**\n * Raised when all overlays are removed from the viewer (see {@link OpenSeadragon.Drawer#clearOverlays}).\n *\n * @event clear-overlay\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'clear-overlay'",
",",
"{",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Removes all currently configured Overlays from this Viewer and schedules
an update.
@method
@return {OpenSeadragon.Viewer} Chainable.
@fires OpenSeadragon.Viewer.event:clear-overlay
|
[
"Removes",
"all",
"currently",
"configured",
"Overlays",
"from",
"this",
"Viewer",
"and",
"schedules",
"an",
"update",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2058-L2074
|
|
10,821
|
openseadragon/openseadragon
|
src/viewer.js
|
function( element ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if (i >= 0) {
return this.currentOverlays[i];
} else {
return null;
}
}
|
javascript
|
function( element ) {
var i;
element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element );
if (i >= 0) {
return this.currentOverlays[i];
} else {
return null;
}
}
|
[
"function",
"(",
"element",
")",
"{",
"var",
"i",
";",
"element",
"=",
"$",
".",
"getElement",
"(",
"element",
")",
";",
"i",
"=",
"getOverlayIndex",
"(",
"this",
".",
"currentOverlays",
",",
"element",
")",
";",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"return",
"this",
".",
"currentOverlays",
"[",
"i",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Finds an overlay identified by the reference element or element id
and returns it as an object, return null if not found.
@method
@param {Element|String} element - A reference to the element or an
element id which represents the overlay content.
@return {OpenSeadragon.Overlay} the matching overlay or null if none found.
|
[
"Finds",
"an",
"overlay",
"identified",
"by",
"the",
"reference",
"element",
"or",
"element",
"id",
"and",
"returns",
"it",
"as",
"an",
"object",
"return",
"null",
"if",
"not",
"found",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2084-L2095
|
|
10,822
|
openseadragon/openseadragon
|
src/viewer.js
|
function( page ) {
if ( this.nextButton ) {
if(!this.tileSources || this.tileSources.length - 1 === page) {
//Disable next button
if ( !this.navPrevNextWrap ) {
this.nextButton.disable();
}
} else {
this.nextButton.enable();
}
}
if ( this.previousButton ) {
if ( page > 0 ) {
//Enable previous button
this.previousButton.enable();
} else {
if ( !this.navPrevNextWrap ) {
this.previousButton.disable();
}
}
}
}
|
javascript
|
function( page ) {
if ( this.nextButton ) {
if(!this.tileSources || this.tileSources.length - 1 === page) {
//Disable next button
if ( !this.navPrevNextWrap ) {
this.nextButton.disable();
}
} else {
this.nextButton.enable();
}
}
if ( this.previousButton ) {
if ( page > 0 ) {
//Enable previous button
this.previousButton.enable();
} else {
if ( !this.navPrevNextWrap ) {
this.previousButton.disable();
}
}
}
}
|
[
"function",
"(",
"page",
")",
"{",
"if",
"(",
"this",
".",
"nextButton",
")",
"{",
"if",
"(",
"!",
"this",
".",
"tileSources",
"||",
"this",
".",
"tileSources",
".",
"length",
"-",
"1",
"===",
"page",
")",
"{",
"//Disable next button",
"if",
"(",
"!",
"this",
".",
"navPrevNextWrap",
")",
"{",
"this",
".",
"nextButton",
".",
"disable",
"(",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"nextButton",
".",
"enable",
"(",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"previousButton",
")",
"{",
"if",
"(",
"page",
">",
"0",
")",
"{",
"//Enable previous button",
"this",
".",
"previousButton",
".",
"enable",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"this",
".",
"navPrevNextWrap",
")",
"{",
"this",
".",
"previousButton",
".",
"disable",
"(",
")",
";",
"}",
"}",
"}",
"}"
] |
Updates the sequence buttons.
@function OpenSeadragon.Viewer.prototype._updateSequenceButtons
@private
@param {Number} Sequence Value
|
[
"Updates",
"the",
"sequence",
"buttons",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2103-L2125
|
|
10,823
|
openseadragon/openseadragon
|
src/viewer.js
|
function ( message ) {
this._hideMessage();
var div = $.makeNeutralElement( "div" );
div.appendChild( document.createTextNode( message ) );
this.messageDiv = $.makeCenteredNode( div );
$.addClass(this.messageDiv, "openseadragon-message");
this.container.appendChild( this.messageDiv );
}
|
javascript
|
function ( message ) {
this._hideMessage();
var div = $.makeNeutralElement( "div" );
div.appendChild( document.createTextNode( message ) );
this.messageDiv = $.makeCenteredNode( div );
$.addClass(this.messageDiv, "openseadragon-message");
this.container.appendChild( this.messageDiv );
}
|
[
"function",
"(",
"message",
")",
"{",
"this",
".",
"_hideMessage",
"(",
")",
";",
"var",
"div",
"=",
"$",
".",
"makeNeutralElement",
"(",
"\"div\"",
")",
";",
"div",
".",
"appendChild",
"(",
"document",
".",
"createTextNode",
"(",
"message",
")",
")",
";",
"this",
".",
"messageDiv",
"=",
"$",
".",
"makeCenteredNode",
"(",
"div",
")",
";",
"$",
".",
"addClass",
"(",
"this",
".",
"messageDiv",
",",
"\"openseadragon-message\"",
")",
";",
"this",
".",
"container",
".",
"appendChild",
"(",
"this",
".",
"messageDiv",
")",
";",
"}"
] |
Display a message in the viewport
@function OpenSeadragon.Viewer.prototype._showMessage
@private
@param {String} text message
|
[
"Display",
"a",
"message",
"in",
"the",
"viewport"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2133-L2144
|
|
10,824
|
openseadragon/openseadragon
|
src/viewer.js
|
function() {
this.showReferenceStrip = true;
if (this.sequenceMode) {
if (this.referenceStrip) {
return;
}
if (this.tileSources.length && this.tileSources.length > 1) {
this.referenceStrip = new $.ReferenceStrip({
id: this.referenceStripElement,
position: this.referenceStripPosition,
sizeRatio: this.referenceStripSizeRatio,
scroll: this.referenceStripScroll,
height: this.referenceStripHeight,
width: this.referenceStripWidth,
tileSources: this.tileSources,
prefixUrl: this.prefixUrl,
viewer: this
});
this.referenceStrip.setFocus( this._sequenceIndex );
}
} else {
$.console.warn('Attempting to display a reference strip while "sequenceMode" is off.');
}
}
|
javascript
|
function() {
this.showReferenceStrip = true;
if (this.sequenceMode) {
if (this.referenceStrip) {
return;
}
if (this.tileSources.length && this.tileSources.length > 1) {
this.referenceStrip = new $.ReferenceStrip({
id: this.referenceStripElement,
position: this.referenceStripPosition,
sizeRatio: this.referenceStripSizeRatio,
scroll: this.referenceStripScroll,
height: this.referenceStripHeight,
width: this.referenceStripWidth,
tileSources: this.tileSources,
prefixUrl: this.prefixUrl,
viewer: this
});
this.referenceStrip.setFocus( this._sequenceIndex );
}
} else {
$.console.warn('Attempting to display a reference strip while "sequenceMode" is off.');
}
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"showReferenceStrip",
"=",
"true",
";",
"if",
"(",
"this",
".",
"sequenceMode",
")",
"{",
"if",
"(",
"this",
".",
"referenceStrip",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"tileSources",
".",
"length",
"&&",
"this",
".",
"tileSources",
".",
"length",
">",
"1",
")",
"{",
"this",
".",
"referenceStrip",
"=",
"new",
"$",
".",
"ReferenceStrip",
"(",
"{",
"id",
":",
"this",
".",
"referenceStripElement",
",",
"position",
":",
"this",
".",
"referenceStripPosition",
",",
"sizeRatio",
":",
"this",
".",
"referenceStripSizeRatio",
",",
"scroll",
":",
"this",
".",
"referenceStripScroll",
",",
"height",
":",
"this",
".",
"referenceStripHeight",
",",
"width",
":",
"this",
".",
"referenceStripWidth",
",",
"tileSources",
":",
"this",
".",
"tileSources",
",",
"prefixUrl",
":",
"this",
".",
"prefixUrl",
",",
"viewer",
":",
"this",
"}",
")",
";",
"this",
".",
"referenceStrip",
".",
"setFocus",
"(",
"this",
".",
"_sequenceIndex",
")",
";",
"}",
"}",
"else",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"'Attempting to display a reference strip while \"sequenceMode\" is off.'",
")",
";",
"}",
"}"
] |
Enables and displays the reference strip based on the currently set tileSources.
Works only when the Viewer has sequenceMode set to true.
@function
|
[
"Enables",
"and",
"displays",
"the",
"reference",
"strip",
"based",
"on",
"the",
"currently",
"set",
"tileSources",
".",
"Works",
"only",
"when",
"the",
"Viewer",
"has",
"sequenceMode",
"set",
"to",
"true",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2212-L2238
|
|
10,825
|
openseadragon/openseadragon
|
src/viewer.js
|
beginControlsAutoHide
|
function beginControlsAutoHide( viewer ) {
if ( !viewer.autoHideControls ) {
return;
}
viewer.controlsShouldFade = true;
viewer.controlsFadeBeginTime =
$.now() +
viewer.controlsFadeDelay;
window.setTimeout( function(){
scheduleControlsFade( viewer );
}, viewer.controlsFadeDelay );
}
|
javascript
|
function beginControlsAutoHide( viewer ) {
if ( !viewer.autoHideControls ) {
return;
}
viewer.controlsShouldFade = true;
viewer.controlsFadeBeginTime =
$.now() +
viewer.controlsFadeDelay;
window.setTimeout( function(){
scheduleControlsFade( viewer );
}, viewer.controlsFadeDelay );
}
|
[
"function",
"beginControlsAutoHide",
"(",
"viewer",
")",
"{",
"if",
"(",
"!",
"viewer",
".",
"autoHideControls",
")",
"{",
"return",
";",
"}",
"viewer",
".",
"controlsShouldFade",
"=",
"true",
";",
"viewer",
".",
"controlsFadeBeginTime",
"=",
"$",
".",
"now",
"(",
")",
"+",
"viewer",
".",
"controlsFadeDelay",
";",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"scheduleControlsFade",
"(",
"viewer",
")",
";",
"}",
",",
"viewer",
".",
"controlsFadeDelay",
")",
";",
"}"
] |
initiates an animation to hide the controls
|
[
"initiates",
"an",
"animation",
"to",
"hide",
"the",
"controls"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2451-L2463
|
10,826
|
openseadragon/openseadragon
|
src/viewer.js
|
updateControlsFade
|
function updateControlsFade( viewer ) {
var currentTime,
deltaTime,
opacity,
i;
if ( viewer.controlsShouldFade ) {
currentTime = $.now();
deltaTime = currentTime - viewer.controlsFadeBeginTime;
opacity = 1.0 - deltaTime / viewer.controlsFadeLength;
opacity = Math.min( 1.0, opacity );
opacity = Math.max( 0.0, opacity );
for ( i = viewer.controls.length - 1; i >= 0; i--) {
if (viewer.controls[ i ].autoFade) {
viewer.controls[ i ].setOpacity( opacity );
}
}
if ( opacity > 0 ) {
// fade again
scheduleControlsFade( viewer );
}
}
}
|
javascript
|
function updateControlsFade( viewer ) {
var currentTime,
deltaTime,
opacity,
i;
if ( viewer.controlsShouldFade ) {
currentTime = $.now();
deltaTime = currentTime - viewer.controlsFadeBeginTime;
opacity = 1.0 - deltaTime / viewer.controlsFadeLength;
opacity = Math.min( 1.0, opacity );
opacity = Math.max( 0.0, opacity );
for ( i = viewer.controls.length - 1; i >= 0; i--) {
if (viewer.controls[ i ].autoFade) {
viewer.controls[ i ].setOpacity( opacity );
}
}
if ( opacity > 0 ) {
// fade again
scheduleControlsFade( viewer );
}
}
}
|
[
"function",
"updateControlsFade",
"(",
"viewer",
")",
"{",
"var",
"currentTime",
",",
"deltaTime",
",",
"opacity",
",",
"i",
";",
"if",
"(",
"viewer",
".",
"controlsShouldFade",
")",
"{",
"currentTime",
"=",
"$",
".",
"now",
"(",
")",
";",
"deltaTime",
"=",
"currentTime",
"-",
"viewer",
".",
"controlsFadeBeginTime",
";",
"opacity",
"=",
"1.0",
"-",
"deltaTime",
"/",
"viewer",
".",
"controlsFadeLength",
";",
"opacity",
"=",
"Math",
".",
"min",
"(",
"1.0",
",",
"opacity",
")",
";",
"opacity",
"=",
"Math",
".",
"max",
"(",
"0.0",
",",
"opacity",
")",
";",
"for",
"(",
"i",
"=",
"viewer",
".",
"controls",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"viewer",
".",
"controls",
"[",
"i",
"]",
".",
"autoFade",
")",
"{",
"viewer",
".",
"controls",
"[",
"i",
"]",
".",
"setOpacity",
"(",
"opacity",
")",
";",
"}",
"}",
"if",
"(",
"opacity",
">",
"0",
")",
"{",
"// fade again",
"scheduleControlsFade",
"(",
"viewer",
")",
";",
"}",
"}",
"}"
] |
determines if fade animation is done or continues the animation
|
[
"determines",
"if",
"fade",
"animation",
"is",
"done",
"or",
"continues",
"the",
"animation"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2467-L2491
|
10,827
|
openseadragon/openseadragon
|
src/viewer.js
|
abortControlsAutoHide
|
function abortControlsAutoHide( viewer ) {
var i;
viewer.controlsShouldFade = false;
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
viewer.controls[ i ].setOpacity( 1.0 );
}
}
|
javascript
|
function abortControlsAutoHide( viewer ) {
var i;
viewer.controlsShouldFade = false;
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
viewer.controls[ i ].setOpacity( 1.0 );
}
}
|
[
"function",
"abortControlsAutoHide",
"(",
"viewer",
")",
"{",
"var",
"i",
";",
"viewer",
".",
"controlsShouldFade",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"viewer",
".",
"controls",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"viewer",
".",
"controls",
"[",
"i",
"]",
".",
"setOpacity",
"(",
"1.0",
")",
";",
"}",
"}"
] |
stop the fade animation on the controls and show them
|
[
"stop",
"the",
"fade",
"animation",
"on",
"the",
"controls",
"and",
"show",
"them"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewer.js#L2495-L2501
|
10,828
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function () {
var i;
stopTracking( this );
this.element = null;
for ( i = 0; i < MOUSETRACKERS.length; i++ ) {
if ( MOUSETRACKERS[ i ] === this ) {
MOUSETRACKERS.splice( i, 1 );
break;
}
}
THIS[ this.hash ] = null;
delete THIS[ this.hash ];
}
|
javascript
|
function () {
var i;
stopTracking( this );
this.element = null;
for ( i = 0; i < MOUSETRACKERS.length; i++ ) {
if ( MOUSETRACKERS[ i ] === this ) {
MOUSETRACKERS.splice( i, 1 );
break;
}
}
THIS[ this.hash ] = null;
delete THIS[ this.hash ];
}
|
[
"function",
"(",
")",
"{",
"var",
"i",
";",
"stopTracking",
"(",
"this",
")",
";",
"this",
".",
"element",
"=",
"null",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"MOUSETRACKERS",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"MOUSETRACKERS",
"[",
"i",
"]",
"===",
"this",
")",
"{",
"MOUSETRACKERS",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"THIS",
"[",
"this",
".",
"hash",
"]",
"=",
"null",
";",
"delete",
"THIS",
"[",
"this",
".",
"hash",
"]",
";",
"}"
] |
Clean up any events or objects created by the tracker.
@function
|
[
"Clean",
"up",
"any",
"events",
"or",
"objects",
"created",
"by",
"the",
"tracker",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L277-L292
|
|
10,829
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function () {
var delegate = THIS[ this.hash ],
i,
len = delegate.activePointersLists.length,
count = 0;
for ( i = 0; i < len; i++ ) {
count += delegate.activePointersLists[ i ].getLength();
}
return count;
}
|
javascript
|
function () {
var delegate = THIS[ this.hash ],
i,
len = delegate.activePointersLists.length,
count = 0;
for ( i = 0; i < len; i++ ) {
count += delegate.activePointersLists[ i ].getLength();
}
return count;
}
|
[
"function",
"(",
")",
"{",
"var",
"delegate",
"=",
"THIS",
"[",
"this",
".",
"hash",
"]",
",",
"i",
",",
"len",
"=",
"delegate",
".",
"activePointersLists",
".",
"length",
",",
"count",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"count",
"+=",
"delegate",
".",
"activePointersLists",
"[",
"i",
"]",
".",
"getLength",
"(",
")",
";",
"}",
"return",
"count",
";",
"}"
] |
Returns the total number of pointers currently active on the tracked element.
@function
@returns {Number}
|
[
"Returns",
"the",
"total",
"number",
"of",
"pointers",
"currently",
"active",
"on",
"the",
"tracked",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L368-L379
|
|
10,830
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function ( tracker, gPoint ) {
return tracker.hash.toString() + gPoint.type + gPoint.id.toString();
}
|
javascript
|
function ( tracker, gPoint ) {
return tracker.hash.toString() + gPoint.type + gPoint.id.toString();
}
|
[
"function",
"(",
"tracker",
",",
"gPoint",
")",
"{",
"return",
"tracker",
".",
"hash",
".",
"toString",
"(",
")",
"+",
"gPoint",
".",
"type",
"+",
"gPoint",
".",
"id",
".",
"toString",
"(",
")",
";",
"}"
] |
Generates a unique identifier for a tracked gesture point
|
[
"Generates",
"a",
"unique",
"identifier",
"for",
"a",
"tracked",
"gesture",
"point"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L915-L917
|
|
10,831
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function () {
var i,
len = trackerPoints.length,
trackPoint,
gPoint,
now = $.now(),
elapsedTime,
distance,
speed;
elapsedTime = now - lastTime;
lastTime = now;
for ( i = 0; i < len; i++ ) {
trackPoint = trackerPoints[ i ];
gPoint = trackPoint.gPoint;
// Math.atan2 gives us just what we need for a velocity vector, as we can simply
// use cos()/sin() to extract the x/y velocity components.
gPoint.direction = Math.atan2( gPoint.currentPos.y - trackPoint.lastPos.y, gPoint.currentPos.x - trackPoint.lastPos.x );
// speed = distance / elapsed time
distance = trackPoint.lastPos.distanceTo( gPoint.currentPos );
trackPoint.lastPos = gPoint.currentPos;
speed = 1000 * distance / ( elapsedTime + 1 );
// Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.
gPoint.speed = 0.75 * speed + 0.25 * gPoint.speed;
}
}
|
javascript
|
function () {
var i,
len = trackerPoints.length,
trackPoint,
gPoint,
now = $.now(),
elapsedTime,
distance,
speed;
elapsedTime = now - lastTime;
lastTime = now;
for ( i = 0; i < len; i++ ) {
trackPoint = trackerPoints[ i ];
gPoint = trackPoint.gPoint;
// Math.atan2 gives us just what we need for a velocity vector, as we can simply
// use cos()/sin() to extract the x/y velocity components.
gPoint.direction = Math.atan2( gPoint.currentPos.y - trackPoint.lastPos.y, gPoint.currentPos.x - trackPoint.lastPos.x );
// speed = distance / elapsed time
distance = trackPoint.lastPos.distanceTo( gPoint.currentPos );
trackPoint.lastPos = gPoint.currentPos;
speed = 1000 * distance / ( elapsedTime + 1 );
// Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.
gPoint.speed = 0.75 * speed + 0.25 * gPoint.speed;
}
}
|
[
"function",
"(",
")",
"{",
"var",
"i",
",",
"len",
"=",
"trackerPoints",
".",
"length",
",",
"trackPoint",
",",
"gPoint",
",",
"now",
"=",
"$",
".",
"now",
"(",
")",
",",
"elapsedTime",
",",
"distance",
",",
"speed",
";",
"elapsedTime",
"=",
"now",
"-",
"lastTime",
";",
"lastTime",
"=",
"now",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"trackPoint",
"=",
"trackerPoints",
"[",
"i",
"]",
";",
"gPoint",
"=",
"trackPoint",
".",
"gPoint",
";",
"// Math.atan2 gives us just what we need for a velocity vector, as we can simply",
"// use cos()/sin() to extract the x/y velocity components.",
"gPoint",
".",
"direction",
"=",
"Math",
".",
"atan2",
"(",
"gPoint",
".",
"currentPos",
".",
"y",
"-",
"trackPoint",
".",
"lastPos",
".",
"y",
",",
"gPoint",
".",
"currentPos",
".",
"x",
"-",
"trackPoint",
".",
"lastPos",
".",
"x",
")",
";",
"// speed = distance / elapsed time",
"distance",
"=",
"trackPoint",
".",
"lastPos",
".",
"distanceTo",
"(",
"gPoint",
".",
"currentPos",
")",
";",
"trackPoint",
".",
"lastPos",
"=",
"gPoint",
".",
"currentPos",
";",
"speed",
"=",
"1000",
"*",
"distance",
"/",
"(",
"elapsedTime",
"+",
"1",
")",
";",
"// Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.",
"gPoint",
".",
"speed",
"=",
"0.75",
"*",
"speed",
"+",
"0.25",
"*",
"gPoint",
".",
"speed",
";",
"}",
"}"
] |
Interval timer callback. Computes velocity for all tracked gesture points.
|
[
"Interval",
"timer",
"callback",
".",
"Computes",
"velocity",
"for",
"all",
"tracked",
"gesture",
"points",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L920-L946
|
|
10,832
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function ( tracker, gPoint ) {
var guid = _generateGuid( tracker, gPoint );
trackerPoints.push(
{
guid: guid,
gPoint: gPoint,
lastPos: gPoint.currentPos
} );
// Only fire up the interval timer when there's gesture pointers to track
if ( trackerPoints.length === 1 ) {
lastTime = $.now();
intervalId = window.setInterval( _doTracking, 50 );
}
}
|
javascript
|
function ( tracker, gPoint ) {
var guid = _generateGuid( tracker, gPoint );
trackerPoints.push(
{
guid: guid,
gPoint: gPoint,
lastPos: gPoint.currentPos
} );
// Only fire up the interval timer when there's gesture pointers to track
if ( trackerPoints.length === 1 ) {
lastTime = $.now();
intervalId = window.setInterval( _doTracking, 50 );
}
}
|
[
"function",
"(",
"tracker",
",",
"gPoint",
")",
"{",
"var",
"guid",
"=",
"_generateGuid",
"(",
"tracker",
",",
"gPoint",
")",
";",
"trackerPoints",
".",
"push",
"(",
"{",
"guid",
":",
"guid",
",",
"gPoint",
":",
"gPoint",
",",
"lastPos",
":",
"gPoint",
".",
"currentPos",
"}",
")",
";",
"// Only fire up the interval timer when there's gesture pointers to track",
"if",
"(",
"trackerPoints",
".",
"length",
"===",
"1",
")",
"{",
"lastTime",
"=",
"$",
".",
"now",
"(",
")",
";",
"intervalId",
"=",
"window",
".",
"setInterval",
"(",
"_doTracking",
",",
"50",
")",
";",
"}",
"}"
] |
Public. Add a gesture point to be tracked
|
[
"Public",
".",
"Add",
"a",
"gesture",
"point",
"to",
"be",
"tracked"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L949-L964
|
|
10,833
|
openseadragon/openseadragon
|
src/mousetracker.js
|
function ( tracker, gPoint ) {
var guid = _generateGuid( tracker, gPoint ),
i,
len = trackerPoints.length;
for ( i = 0; i < len; i++ ) {
if ( trackerPoints[ i ].guid === guid ) {
trackerPoints.splice( i, 1 );
// Only run the interval timer if theres gesture pointers to track
len--;
if ( len === 0 ) {
window.clearInterval( intervalId );
}
break;
}
}
}
|
javascript
|
function ( tracker, gPoint ) {
var guid = _generateGuid( tracker, gPoint ),
i,
len = trackerPoints.length;
for ( i = 0; i < len; i++ ) {
if ( trackerPoints[ i ].guid === guid ) {
trackerPoints.splice( i, 1 );
// Only run the interval timer if theres gesture pointers to track
len--;
if ( len === 0 ) {
window.clearInterval( intervalId );
}
break;
}
}
}
|
[
"function",
"(",
"tracker",
",",
"gPoint",
")",
"{",
"var",
"guid",
"=",
"_generateGuid",
"(",
"tracker",
",",
"gPoint",
")",
",",
"i",
",",
"len",
"=",
"trackerPoints",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"trackerPoints",
"[",
"i",
"]",
".",
"guid",
"===",
"guid",
")",
"{",
"trackerPoints",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"// Only run the interval timer if theres gesture pointers to track",
"len",
"--",
";",
"if",
"(",
"len",
"===",
"0",
")",
"{",
"window",
".",
"clearInterval",
"(",
"intervalId",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
] |
Public. Stop tracking a gesture point
|
[
"Public",
".",
"Stop",
"tracking",
"a",
"gesture",
"point"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L967-L982
|
|
10,834
|
openseadragon/openseadragon
|
src/mousetracker.js
|
startTracking
|
function startTracking( tracker ) {
var delegate = THIS[ tracker.hash ],
event,
i;
if ( !delegate.tracking ) {
for ( i = 0; i < $.MouseTracker.subscribeEvents.length; i++ ) {
event = $.MouseTracker.subscribeEvents[ i ];
$.addEvent(
tracker.element,
event,
delegate[ event ],
false
);
}
clearTrackedPointers( tracker );
delegate.tracking = true;
}
}
|
javascript
|
function startTracking( tracker ) {
var delegate = THIS[ tracker.hash ],
event,
i;
if ( !delegate.tracking ) {
for ( i = 0; i < $.MouseTracker.subscribeEvents.length; i++ ) {
event = $.MouseTracker.subscribeEvents[ i ];
$.addEvent(
tracker.element,
event,
delegate[ event ],
false
);
}
clearTrackedPointers( tracker );
delegate.tracking = true;
}
}
|
[
"function",
"startTracking",
"(",
"tracker",
")",
"{",
"var",
"delegate",
"=",
"THIS",
"[",
"tracker",
".",
"hash",
"]",
",",
"event",
",",
"i",
";",
"if",
"(",
"!",
"delegate",
".",
"tracking",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"$",
".",
"MouseTracker",
".",
"subscribeEvents",
".",
"length",
";",
"i",
"++",
")",
"{",
"event",
"=",
"$",
".",
"MouseTracker",
".",
"subscribeEvents",
"[",
"i",
"]",
";",
"$",
".",
"addEvent",
"(",
"tracker",
".",
"element",
",",
"event",
",",
"delegate",
"[",
"event",
"]",
",",
"false",
")",
";",
"}",
"clearTrackedPointers",
"(",
"tracker",
")",
";",
"delegate",
".",
"tracking",
"=",
"true",
";",
"}",
"}"
] |
Starts tracking pointer events on the tracked element.
@private
@inner
|
[
"Starts",
"tracking",
"pointer",
"events",
"on",
"the",
"tracked",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L1335-L1355
|
10,835
|
openseadragon/openseadragon
|
src/mousetracker.js
|
stopTracking
|
function stopTracking( tracker ) {
var delegate = THIS[ tracker.hash ],
event,
i;
if ( delegate.tracking ) {
for ( i = 0; i < $.MouseTracker.subscribeEvents.length; i++ ) {
event = $.MouseTracker.subscribeEvents[ i ];
$.removeEvent(
tracker.element,
event,
delegate[ event ],
false
);
}
clearTrackedPointers( tracker );
delegate.tracking = false;
}
}
|
javascript
|
function stopTracking( tracker ) {
var delegate = THIS[ tracker.hash ],
event,
i;
if ( delegate.tracking ) {
for ( i = 0; i < $.MouseTracker.subscribeEvents.length; i++ ) {
event = $.MouseTracker.subscribeEvents[ i ];
$.removeEvent(
tracker.element,
event,
delegate[ event ],
false
);
}
clearTrackedPointers( tracker );
delegate.tracking = false;
}
}
|
[
"function",
"stopTracking",
"(",
"tracker",
")",
"{",
"var",
"delegate",
"=",
"THIS",
"[",
"tracker",
".",
"hash",
"]",
",",
"event",
",",
"i",
";",
"if",
"(",
"delegate",
".",
"tracking",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"$",
".",
"MouseTracker",
".",
"subscribeEvents",
".",
"length",
";",
"i",
"++",
")",
"{",
"event",
"=",
"$",
".",
"MouseTracker",
".",
"subscribeEvents",
"[",
"i",
"]",
";",
"$",
".",
"removeEvent",
"(",
"tracker",
".",
"element",
",",
"event",
",",
"delegate",
"[",
"event",
"]",
",",
"false",
")",
";",
"}",
"clearTrackedPointers",
"(",
"tracker",
")",
";",
"delegate",
".",
"tracking",
"=",
"false",
";",
"}",
"}"
] |
Stops tracking pointer events on the tracked element.
@private
@inner
|
[
"Stops",
"tracking",
"pointer",
"events",
"on",
"the",
"tracked",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L1362-L1382
|
10,836
|
openseadragon/openseadragon
|
src/mousetracker.js
|
capturePointer
|
function capturePointer( tracker, pointerType, pointerCount ) {
var pointsList = tracker.getActivePointersListByType( pointerType ),
eventParams;
pointsList.captureCount += (pointerCount || 1);
if ( pointsList.captureCount === 1 ) {
if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) {
tracker.element.setCapture( true );
} else {
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) {
$.addEvent(
window.top,
eventParams.upName,
eventParams.upHandler,
true
);
}
$.addEvent(
$.MouseTracker.captureElement,
eventParams.upName,
eventParams.upHandler,
true
);
$.addEvent(
$.MouseTracker.captureElement,
eventParams.moveName,
eventParams.moveHandler,
true
);
}
}
}
|
javascript
|
function capturePointer( tracker, pointerType, pointerCount ) {
var pointsList = tracker.getActivePointersListByType( pointerType ),
eventParams;
pointsList.captureCount += (pointerCount || 1);
if ( pointsList.captureCount === 1 ) {
if ( $.Browser.vendor === $.BROWSERS.IE && $.Browser.version < 9 ) {
tracker.element.setCapture( true );
} else {
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) {
$.addEvent(
window.top,
eventParams.upName,
eventParams.upHandler,
true
);
}
$.addEvent(
$.MouseTracker.captureElement,
eventParams.upName,
eventParams.upHandler,
true
);
$.addEvent(
$.MouseTracker.captureElement,
eventParams.moveName,
eventParams.moveHandler,
true
);
}
}
}
|
[
"function",
"capturePointer",
"(",
"tracker",
",",
"pointerType",
",",
"pointerCount",
")",
"{",
"var",
"pointsList",
"=",
"tracker",
".",
"getActivePointersListByType",
"(",
"pointerType",
")",
",",
"eventParams",
";",
"pointsList",
".",
"captureCount",
"+=",
"(",
"pointerCount",
"||",
"1",
")",
";",
"if",
"(",
"pointsList",
".",
"captureCount",
"===",
"1",
")",
"{",
"if",
"(",
"$",
".",
"Browser",
".",
"vendor",
"===",
"$",
".",
"BROWSERS",
".",
"IE",
"&&",
"$",
".",
"Browser",
".",
"version",
"<",
"9",
")",
"{",
"tracker",
".",
"element",
".",
"setCapture",
"(",
"true",
")",
";",
"}",
"else",
"{",
"eventParams",
"=",
"getCaptureEventParams",
"(",
"tracker",
",",
"$",
".",
"MouseTracker",
".",
"havePointerEvents",
"?",
"'pointerevent'",
":",
"pointerType",
")",
";",
"// We emulate mouse capture by hanging listeners on the document object.",
"// (Note we listen on the capture phase so the captured handlers will get called first)",
"// eslint-disable-next-line no-use-before-define",
"if",
"(",
"isInIframe",
"&&",
"canAccessEvents",
"(",
"window",
".",
"top",
")",
")",
"{",
"$",
".",
"addEvent",
"(",
"window",
".",
"top",
",",
"eventParams",
".",
"upName",
",",
"eventParams",
".",
"upHandler",
",",
"true",
")",
";",
"}",
"$",
".",
"addEvent",
"(",
"$",
".",
"MouseTracker",
".",
"captureElement",
",",
"eventParams",
".",
"upName",
",",
"eventParams",
".",
"upHandler",
",",
"true",
")",
";",
"$",
".",
"addEvent",
"(",
"$",
".",
"MouseTracker",
".",
"captureElement",
",",
"eventParams",
".",
"moveName",
",",
"eventParams",
".",
"moveHandler",
",",
"true",
")",
";",
"}",
"}",
"}"
] |
Begin capturing pointer events to the tracked element.
@private
@inner
|
[
"Begin",
"capturing",
"pointer",
"events",
"to",
"the",
"tracked",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L1422-L1458
|
10,837
|
openseadragon/openseadragon
|
src/mousetracker.js
|
onMouseWheel
|
function onMouseWheel( tracker, event ) {
event = $.getEvent( event );
// Simulate a 'wheel' event
var simulatedEvent = {
target: event.target || event.srcElement,
type: "wheel",
shiftKey: event.shiftKey || false,
clientX: event.clientX,
clientY: event.clientY,
pageX: event.pageX ? event.pageX : event.clientX,
pageY: event.pageY ? event.pageY : event.clientY,
deltaMode: event.type == "MozMousePixelScroll" ? 0 : 1, // 0=pixel, 1=line, 2=page
deltaX: 0,
deltaZ: 0
};
// Calculate deltaY
if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
simulatedEvent.deltaY = -event.wheelDelta / $.DEFAULT_SETTINGS.pixelsPerWheelLine;
} else {
simulatedEvent.deltaY = event.detail;
}
handleWheelEvent( tracker, simulatedEvent, event );
}
|
javascript
|
function onMouseWheel( tracker, event ) {
event = $.getEvent( event );
// Simulate a 'wheel' event
var simulatedEvent = {
target: event.target || event.srcElement,
type: "wheel",
shiftKey: event.shiftKey || false,
clientX: event.clientX,
clientY: event.clientY,
pageX: event.pageX ? event.pageX : event.clientX,
pageY: event.pageY ? event.pageY : event.clientY,
deltaMode: event.type == "MozMousePixelScroll" ? 0 : 1, // 0=pixel, 1=line, 2=page
deltaX: 0,
deltaZ: 0
};
// Calculate deltaY
if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
simulatedEvent.deltaY = -event.wheelDelta / $.DEFAULT_SETTINGS.pixelsPerWheelLine;
} else {
simulatedEvent.deltaY = event.detail;
}
handleWheelEvent( tracker, simulatedEvent, event );
}
|
[
"function",
"onMouseWheel",
"(",
"tracker",
",",
"event",
")",
"{",
"event",
"=",
"$",
".",
"getEvent",
"(",
"event",
")",
";",
"// Simulate a 'wheel' event",
"var",
"simulatedEvent",
"=",
"{",
"target",
":",
"event",
".",
"target",
"||",
"event",
".",
"srcElement",
",",
"type",
":",
"\"wheel\"",
",",
"shiftKey",
":",
"event",
".",
"shiftKey",
"||",
"false",
",",
"clientX",
":",
"event",
".",
"clientX",
",",
"clientY",
":",
"event",
".",
"clientY",
",",
"pageX",
":",
"event",
".",
"pageX",
"?",
"event",
".",
"pageX",
":",
"event",
".",
"clientX",
",",
"pageY",
":",
"event",
".",
"pageY",
"?",
"event",
".",
"pageY",
":",
"event",
".",
"clientY",
",",
"deltaMode",
":",
"event",
".",
"type",
"==",
"\"MozMousePixelScroll\"",
"?",
"0",
":",
"1",
",",
"// 0=pixel, 1=line, 2=page",
"deltaX",
":",
"0",
",",
"deltaZ",
":",
"0",
"}",
";",
"// Calculate deltaY",
"if",
"(",
"$",
".",
"MouseTracker",
".",
"wheelEventName",
"==",
"\"mousewheel\"",
")",
"{",
"simulatedEvent",
".",
"deltaY",
"=",
"-",
"event",
".",
"wheelDelta",
"/",
"$",
".",
"DEFAULT_SETTINGS",
".",
"pixelsPerWheelLine",
";",
"}",
"else",
"{",
"simulatedEvent",
".",
"deltaY",
"=",
"event",
".",
"detail",
";",
"}",
"handleWheelEvent",
"(",
"tracker",
",",
"simulatedEvent",
",",
"event",
")",
";",
"}"
] |
Handler for 'mousewheel', 'DOMMouseScroll', and 'MozMousePixelScroll' events
@private
@inner
|
[
"Handler",
"for",
"mousewheel",
"DOMMouseScroll",
"and",
"MozMousePixelScroll",
"events"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/mousetracker.js#L1751-L1776
|
10,838
|
openseadragon/openseadragon
|
src/tile.js
|
function( container ) {
if (!this.cacheImageRecord) {
$.console.warn(
'[Tile.drawHTML] attempting to draw tile %s when it\'s not cached',
this.toString());
return;
}
if ( !this.loaded ) {
$.console.warn(
"Attempting to draw tile %s when it's not yet loaded.",
this.toString()
);
return;
}
//EXPERIMENTAL - trying to figure out how to scale the container
// content during animation of the container size.
if ( !this.element ) {
this.element = $.makeNeutralElement( "div" );
this.imgElement = this.cacheImageRecord.getImage().cloneNode();
this.imgElement.style.msInterpolationMode = "nearest-neighbor";
this.imgElement.style.width = "100%";
this.imgElement.style.height = "100%";
this.style = this.element.style;
this.style.position = "absolute";
}
if ( this.element.parentNode != container ) {
container.appendChild( this.element );
}
if ( this.imgElement.parentNode != this.element ) {
this.element.appendChild( this.imgElement );
}
this.style.top = this.position.y + "px";
this.style.left = this.position.x + "px";
this.style.height = this.size.y + "px";
this.style.width = this.size.x + "px";
$.setElementOpacity( this.element, this.opacity );
}
|
javascript
|
function( container ) {
if (!this.cacheImageRecord) {
$.console.warn(
'[Tile.drawHTML] attempting to draw tile %s when it\'s not cached',
this.toString());
return;
}
if ( !this.loaded ) {
$.console.warn(
"Attempting to draw tile %s when it's not yet loaded.",
this.toString()
);
return;
}
//EXPERIMENTAL - trying to figure out how to scale the container
// content during animation of the container size.
if ( !this.element ) {
this.element = $.makeNeutralElement( "div" );
this.imgElement = this.cacheImageRecord.getImage().cloneNode();
this.imgElement.style.msInterpolationMode = "nearest-neighbor";
this.imgElement.style.width = "100%";
this.imgElement.style.height = "100%";
this.style = this.element.style;
this.style.position = "absolute";
}
if ( this.element.parentNode != container ) {
container.appendChild( this.element );
}
if ( this.imgElement.parentNode != this.element ) {
this.element.appendChild( this.imgElement );
}
this.style.top = this.position.y + "px";
this.style.left = this.position.x + "px";
this.style.height = this.size.y + "px";
this.style.width = this.size.x + "px";
$.setElementOpacity( this.element, this.opacity );
}
|
[
"function",
"(",
"container",
")",
"{",
"if",
"(",
"!",
"this",
".",
"cacheImageRecord",
")",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"'[Tile.drawHTML] attempting to draw tile %s when it\\'s not cached'",
",",
"this",
".",
"toString",
"(",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"this",
".",
"loaded",
")",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"\"Attempting to draw tile %s when it's not yet loaded.\"",
",",
"this",
".",
"toString",
"(",
")",
")",
";",
"return",
";",
"}",
"//EXPERIMENTAL - trying to figure out how to scale the container",
"// content during animation of the container size.",
"if",
"(",
"!",
"this",
".",
"element",
")",
"{",
"this",
".",
"element",
"=",
"$",
".",
"makeNeutralElement",
"(",
"\"div\"",
")",
";",
"this",
".",
"imgElement",
"=",
"this",
".",
"cacheImageRecord",
".",
"getImage",
"(",
")",
".",
"cloneNode",
"(",
")",
";",
"this",
".",
"imgElement",
".",
"style",
".",
"msInterpolationMode",
"=",
"\"nearest-neighbor\"",
";",
"this",
".",
"imgElement",
".",
"style",
".",
"width",
"=",
"\"100%\"",
";",
"this",
".",
"imgElement",
".",
"style",
".",
"height",
"=",
"\"100%\"",
";",
"this",
".",
"style",
"=",
"this",
".",
"element",
".",
"style",
";",
"this",
".",
"style",
".",
"position",
"=",
"\"absolute\"",
";",
"}",
"if",
"(",
"this",
".",
"element",
".",
"parentNode",
"!=",
"container",
")",
"{",
"container",
".",
"appendChild",
"(",
"this",
".",
"element",
")",
";",
"}",
"if",
"(",
"this",
".",
"imgElement",
".",
"parentNode",
"!=",
"this",
".",
"element",
")",
"{",
"this",
".",
"element",
".",
"appendChild",
"(",
"this",
".",
"imgElement",
")",
";",
"}",
"this",
".",
"style",
".",
"top",
"=",
"this",
".",
"position",
".",
"y",
"+",
"\"px\"",
";",
"this",
".",
"style",
".",
"left",
"=",
"this",
".",
"position",
".",
"x",
"+",
"\"px\"",
";",
"this",
".",
"style",
".",
"height",
"=",
"this",
".",
"size",
".",
"y",
"+",
"\"px\"",
";",
"this",
".",
"style",
".",
"width",
"=",
"this",
".",
"size",
".",
"x",
"+",
"\"px\"",
";",
"$",
".",
"setElementOpacity",
"(",
"this",
".",
"element",
",",
"this",
".",
"opacity",
")",
";",
"}"
] |
Renders the tile in an html container.
@function
@param {Element} container
|
[
"Renders",
"the",
"tile",
"in",
"an",
"html",
"container",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tile.js#L258-L300
|
|
10,839
|
openseadragon/openseadragon
|
src/tile.js
|
function( context, drawingHandler, scale, translate ) {
var position = this.position.times($.pixelDensityRatio),
size = this.size.times($.pixelDensityRatio),
rendered;
if (!this.context2D && !this.cacheImageRecord) {
$.console.warn(
'[Tile.drawCanvas] attempting to draw tile %s when it\'s not cached',
this.toString());
return;
}
rendered = this.context2D || this.cacheImageRecord.getRenderedContext();
if ( !this.loaded || !rendered ){
$.console.warn(
"Attempting to draw tile %s when it's not yet loaded.",
this.toString()
);
return;
}
context.save();
context.globalAlpha = this.opacity;
if (typeof scale === 'number' && scale !== 1) {
// draw tile at a different scale
position = position.times(scale);
size = size.times(scale);
}
if (translate instanceof $.Point) {
// shift tile position slightly
position = position.plus(translate);
}
//if we are supposed to be rendering fully opaque rectangle,
//ie its done fading or fading is turned off, and if we are drawing
//an image with an alpha channel, then the only way
//to avoid seeing the tile underneath is to clear the rectangle
if (context.globalAlpha === 1 && this._hasTransparencyChannel()) {
//clearing only the inside of the rectangle occupied
//by the png prevents edge flikering
context.clearRect(
position.x,
position.y,
size.x,
size.y
);
}
// This gives the application a chance to make image manipulation
// changes as we are rendering the image
drawingHandler({context: context, tile: this, rendered: rendered});
var sourceWidth, sourceHeight;
if (this.sourceBounds) {
sourceWidth = Math.min(this.sourceBounds.width, rendered.canvas.width);
sourceHeight = Math.min(this.sourceBounds.height, rendered.canvas.height);
} else {
sourceWidth = rendered.canvas.width;
sourceHeight = rendered.canvas.height;
}
context.drawImage(
rendered.canvas,
0,
0,
sourceWidth,
sourceHeight,
position.x,
position.y,
size.x,
size.y
);
context.restore();
}
|
javascript
|
function( context, drawingHandler, scale, translate ) {
var position = this.position.times($.pixelDensityRatio),
size = this.size.times($.pixelDensityRatio),
rendered;
if (!this.context2D && !this.cacheImageRecord) {
$.console.warn(
'[Tile.drawCanvas] attempting to draw tile %s when it\'s not cached',
this.toString());
return;
}
rendered = this.context2D || this.cacheImageRecord.getRenderedContext();
if ( !this.loaded || !rendered ){
$.console.warn(
"Attempting to draw tile %s when it's not yet loaded.",
this.toString()
);
return;
}
context.save();
context.globalAlpha = this.opacity;
if (typeof scale === 'number' && scale !== 1) {
// draw tile at a different scale
position = position.times(scale);
size = size.times(scale);
}
if (translate instanceof $.Point) {
// shift tile position slightly
position = position.plus(translate);
}
//if we are supposed to be rendering fully opaque rectangle,
//ie its done fading or fading is turned off, and if we are drawing
//an image with an alpha channel, then the only way
//to avoid seeing the tile underneath is to clear the rectangle
if (context.globalAlpha === 1 && this._hasTransparencyChannel()) {
//clearing only the inside of the rectangle occupied
//by the png prevents edge flikering
context.clearRect(
position.x,
position.y,
size.x,
size.y
);
}
// This gives the application a chance to make image manipulation
// changes as we are rendering the image
drawingHandler({context: context, tile: this, rendered: rendered});
var sourceWidth, sourceHeight;
if (this.sourceBounds) {
sourceWidth = Math.min(this.sourceBounds.width, rendered.canvas.width);
sourceHeight = Math.min(this.sourceBounds.height, rendered.canvas.height);
} else {
sourceWidth = rendered.canvas.width;
sourceHeight = rendered.canvas.height;
}
context.drawImage(
rendered.canvas,
0,
0,
sourceWidth,
sourceHeight,
position.x,
position.y,
size.x,
size.y
);
context.restore();
}
|
[
"function",
"(",
"context",
",",
"drawingHandler",
",",
"scale",
",",
"translate",
")",
"{",
"var",
"position",
"=",
"this",
".",
"position",
".",
"times",
"(",
"$",
".",
"pixelDensityRatio",
")",
",",
"size",
"=",
"this",
".",
"size",
".",
"times",
"(",
"$",
".",
"pixelDensityRatio",
")",
",",
"rendered",
";",
"if",
"(",
"!",
"this",
".",
"context2D",
"&&",
"!",
"this",
".",
"cacheImageRecord",
")",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"'[Tile.drawCanvas] attempting to draw tile %s when it\\'s not cached'",
",",
"this",
".",
"toString",
"(",
")",
")",
";",
"return",
";",
"}",
"rendered",
"=",
"this",
".",
"context2D",
"||",
"this",
".",
"cacheImageRecord",
".",
"getRenderedContext",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"loaded",
"||",
"!",
"rendered",
")",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"\"Attempting to draw tile %s when it's not yet loaded.\"",
",",
"this",
".",
"toString",
"(",
")",
")",
";",
"return",
";",
"}",
"context",
".",
"save",
"(",
")",
";",
"context",
".",
"globalAlpha",
"=",
"this",
".",
"opacity",
";",
"if",
"(",
"typeof",
"scale",
"===",
"'number'",
"&&",
"scale",
"!==",
"1",
")",
"{",
"// draw tile at a different scale",
"position",
"=",
"position",
".",
"times",
"(",
"scale",
")",
";",
"size",
"=",
"size",
".",
"times",
"(",
"scale",
")",
";",
"}",
"if",
"(",
"translate",
"instanceof",
"$",
".",
"Point",
")",
"{",
"// shift tile position slightly",
"position",
"=",
"position",
".",
"plus",
"(",
"translate",
")",
";",
"}",
"//if we are supposed to be rendering fully opaque rectangle,",
"//ie its done fading or fading is turned off, and if we are drawing",
"//an image with an alpha channel, then the only way",
"//to avoid seeing the tile underneath is to clear the rectangle",
"if",
"(",
"context",
".",
"globalAlpha",
"===",
"1",
"&&",
"this",
".",
"_hasTransparencyChannel",
"(",
")",
")",
"{",
"//clearing only the inside of the rectangle occupied",
"//by the png prevents edge flikering",
"context",
".",
"clearRect",
"(",
"position",
".",
"x",
",",
"position",
".",
"y",
",",
"size",
".",
"x",
",",
"size",
".",
"y",
")",
";",
"}",
"// This gives the application a chance to make image manipulation",
"// changes as we are rendering the image",
"drawingHandler",
"(",
"{",
"context",
":",
"context",
",",
"tile",
":",
"this",
",",
"rendered",
":",
"rendered",
"}",
")",
";",
"var",
"sourceWidth",
",",
"sourceHeight",
";",
"if",
"(",
"this",
".",
"sourceBounds",
")",
"{",
"sourceWidth",
"=",
"Math",
".",
"min",
"(",
"this",
".",
"sourceBounds",
".",
"width",
",",
"rendered",
".",
"canvas",
".",
"width",
")",
";",
"sourceHeight",
"=",
"Math",
".",
"min",
"(",
"this",
".",
"sourceBounds",
".",
"height",
",",
"rendered",
".",
"canvas",
".",
"height",
")",
";",
"}",
"else",
"{",
"sourceWidth",
"=",
"rendered",
".",
"canvas",
".",
"width",
";",
"sourceHeight",
"=",
"rendered",
".",
"canvas",
".",
"height",
";",
"}",
"context",
".",
"drawImage",
"(",
"rendered",
".",
"canvas",
",",
"0",
",",
"0",
",",
"sourceWidth",
",",
"sourceHeight",
",",
"position",
".",
"x",
",",
"position",
".",
"y",
",",
"size",
".",
"x",
",",
"size",
".",
"y",
")",
";",
"context",
".",
"restore",
"(",
")",
";",
"}"
] |
Renders the tile in a canvas-based context.
@function
@param {Canvas} context
@param {Function} drawingHandler - Method for firing the drawing event.
drawingHandler({context, tile, rendered})
where <code>rendered</code> is the context with the pre-drawn image.
@param {Number} [scale=1] - Apply a scale to position and size
@param {OpenSeadragon.Point} [translate] - A translation vector
|
[
"Renders",
"the",
"tile",
"in",
"a",
"canvas",
"-",
"based",
"context",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tile.js#L312-L392
|
|
10,840
|
openseadragon/openseadragon
|
src/tile.js
|
function() {
var context;
if (this.cacheImageRecord) {
context = this.cacheImageRecord.getRenderedContext();
} else if (this.context2D) {
context = this.context2D;
} else {
$.console.warn(
'[Tile.drawCanvas] attempting to get tile scale %s when tile\'s not cached',
this.toString());
return 1;
}
return context.canvas.width / (this.size.x * $.pixelDensityRatio);
}
|
javascript
|
function() {
var context;
if (this.cacheImageRecord) {
context = this.cacheImageRecord.getRenderedContext();
} else if (this.context2D) {
context = this.context2D;
} else {
$.console.warn(
'[Tile.drawCanvas] attempting to get tile scale %s when tile\'s not cached',
this.toString());
return 1;
}
return context.canvas.width / (this.size.x * $.pixelDensityRatio);
}
|
[
"function",
"(",
")",
"{",
"var",
"context",
";",
"if",
"(",
"this",
".",
"cacheImageRecord",
")",
"{",
"context",
"=",
"this",
".",
"cacheImageRecord",
".",
"getRenderedContext",
"(",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"context2D",
")",
"{",
"context",
"=",
"this",
".",
"context2D",
";",
"}",
"else",
"{",
"$",
".",
"console",
".",
"warn",
"(",
"'[Tile.drawCanvas] attempting to get tile scale %s when tile\\'s not cached'",
",",
"this",
".",
"toString",
"(",
")",
")",
";",
"return",
"1",
";",
"}",
"return",
"context",
".",
"canvas",
".",
"width",
"/",
"(",
"this",
".",
"size",
".",
"x",
"*",
"$",
".",
"pixelDensityRatio",
")",
";",
"}"
] |
Get the ratio between current and original size.
@function
@return {Float}
|
[
"Get",
"the",
"ratio",
"between",
"current",
"and",
"original",
"size",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tile.js#L399-L412
|
|
10,841
|
openseadragon/openseadragon
|
src/tile.js
|
function(scale, canvasSize, sketchCanvasSize) {
// The translation vector must have positive values, otherwise the image goes a bit off
// the sketch canvas to the top and left and we must use negative coordinates to repaint it
// to the main canvas. In that case, some browsers throw:
// INDEX_SIZE_ERR: DOM Exception 1: Index or size was negative, or greater than the allowed value.
var x = Math.max(1, Math.ceil((sketchCanvasSize.x - canvasSize.x) / 2));
var y = Math.max(1, Math.ceil((sketchCanvasSize.y - canvasSize.y) / 2));
return new $.Point(x, y).minus(
this.position
.times($.pixelDensityRatio)
.times(scale || 1)
.apply(function(x) {
return x % 1;
})
);
}
|
javascript
|
function(scale, canvasSize, sketchCanvasSize) {
// The translation vector must have positive values, otherwise the image goes a bit off
// the sketch canvas to the top and left and we must use negative coordinates to repaint it
// to the main canvas. In that case, some browsers throw:
// INDEX_SIZE_ERR: DOM Exception 1: Index or size was negative, or greater than the allowed value.
var x = Math.max(1, Math.ceil((sketchCanvasSize.x - canvasSize.x) / 2));
var y = Math.max(1, Math.ceil((sketchCanvasSize.y - canvasSize.y) / 2));
return new $.Point(x, y).minus(
this.position
.times($.pixelDensityRatio)
.times(scale || 1)
.apply(function(x) {
return x % 1;
})
);
}
|
[
"function",
"(",
"scale",
",",
"canvasSize",
",",
"sketchCanvasSize",
")",
"{",
"// The translation vector must have positive values, otherwise the image goes a bit off",
"// the sketch canvas to the top and left and we must use negative coordinates to repaint it",
"// to the main canvas. In that case, some browsers throw:",
"// INDEX_SIZE_ERR: DOM Exception 1: Index or size was negative, or greater than the allowed value.",
"var",
"x",
"=",
"Math",
".",
"max",
"(",
"1",
",",
"Math",
".",
"ceil",
"(",
"(",
"sketchCanvasSize",
".",
"x",
"-",
"canvasSize",
".",
"x",
")",
"/",
"2",
")",
")",
";",
"var",
"y",
"=",
"Math",
".",
"max",
"(",
"1",
",",
"Math",
".",
"ceil",
"(",
"(",
"sketchCanvasSize",
".",
"y",
"-",
"canvasSize",
".",
"y",
")",
"/",
"2",
")",
")",
";",
"return",
"new",
"$",
".",
"Point",
"(",
"x",
",",
"y",
")",
".",
"minus",
"(",
"this",
".",
"position",
".",
"times",
"(",
"$",
".",
"pixelDensityRatio",
")",
".",
"times",
"(",
"scale",
"||",
"1",
")",
".",
"apply",
"(",
"function",
"(",
"x",
")",
"{",
"return",
"x",
"%",
"1",
";",
"}",
")",
")",
";",
"}"
] |
Get a translation vector that when applied to the tile position produces integer coordinates.
Needed to avoid swimming and twitching.
@function
@param {Number} [scale=1] - Scale to be applied to position.
@return {OpenSeadragon.Point}
|
[
"Get",
"a",
"translation",
"vector",
"that",
"when",
"applied",
"to",
"the",
"tile",
"position",
"produces",
"integer",
"coordinates",
".",
"Needed",
"to",
"avoid",
"swimming",
"and",
"twitching",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tile.js#L421-L436
|
|
10,842
|
openseadragon/openseadragon
|
src/tile.js
|
function() {
if ( this.imgElement && this.imgElement.parentNode ) {
this.imgElement.parentNode.removeChild( this.imgElement );
}
if ( this.element && this.element.parentNode ) {
this.element.parentNode.removeChild( this.element );
}
this.element = null;
this.imgElement = null;
this.loaded = false;
this.loading = false;
}
|
javascript
|
function() {
if ( this.imgElement && this.imgElement.parentNode ) {
this.imgElement.parentNode.removeChild( this.imgElement );
}
if ( this.element && this.element.parentNode ) {
this.element.parentNode.removeChild( this.element );
}
this.element = null;
this.imgElement = null;
this.loaded = false;
this.loading = false;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"imgElement",
"&&",
"this",
".",
"imgElement",
".",
"parentNode",
")",
"{",
"this",
".",
"imgElement",
".",
"parentNode",
".",
"removeChild",
"(",
"this",
".",
"imgElement",
")",
";",
"}",
"if",
"(",
"this",
".",
"element",
"&&",
"this",
".",
"element",
".",
"parentNode",
")",
"{",
"this",
".",
"element",
".",
"parentNode",
".",
"removeChild",
"(",
"this",
".",
"element",
")",
";",
"}",
"this",
".",
"element",
"=",
"null",
";",
"this",
".",
"imgElement",
"=",
"null",
";",
"this",
".",
"loaded",
"=",
"false",
";",
"this",
".",
"loading",
"=",
"false",
";",
"}"
] |
Removes tile from its container.
@function
|
[
"Removes",
"tile",
"from",
"its",
"container",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/tile.js#L442-L454
|
|
10,843
|
openseadragon/openseadragon
|
src/world.js
|
function( item, options ) {
$.console.assert(item, "[World.addItem] item is required");
$.console.assert(item instanceof $.TiledImage, "[World.addItem] only TiledImages supported at this time");
options = options || {};
if (options.index !== undefined) {
var index = Math.max(0, Math.min(this._items.length, options.index));
this._items.splice(index, 0, item);
} else {
this._items.push( item );
}
if (this._autoRefigureSizes) {
this._figureSizes();
} else {
this._needsSizesFigured = true;
}
this._needsDraw = true;
item.addHandler('bounds-change', this._delegatedFigureSizes);
item.addHandler('clip-change', this._delegatedFigureSizes);
/**
* Raised when an item is added to the World.
* @event add-item
* @memberOf OpenSeadragon.World
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the World which raised the event.
* @property {OpenSeadragon.TiledImage} item - The item that has been added.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'add-item', {
item: item
} );
}
|
javascript
|
function( item, options ) {
$.console.assert(item, "[World.addItem] item is required");
$.console.assert(item instanceof $.TiledImage, "[World.addItem] only TiledImages supported at this time");
options = options || {};
if (options.index !== undefined) {
var index = Math.max(0, Math.min(this._items.length, options.index));
this._items.splice(index, 0, item);
} else {
this._items.push( item );
}
if (this._autoRefigureSizes) {
this._figureSizes();
} else {
this._needsSizesFigured = true;
}
this._needsDraw = true;
item.addHandler('bounds-change', this._delegatedFigureSizes);
item.addHandler('clip-change', this._delegatedFigureSizes);
/**
* Raised when an item is added to the World.
* @event add-item
* @memberOf OpenSeadragon.World
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the World which raised the event.
* @property {OpenSeadragon.TiledImage} item - The item that has been added.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'add-item', {
item: item
} );
}
|
[
"function",
"(",
"item",
",",
"options",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"item",
",",
"\"[World.addItem] item is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"item",
"instanceof",
"$",
".",
"TiledImage",
",",
"\"[World.addItem] only TiledImages supported at this time\"",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"options",
".",
"index",
"!==",
"undefined",
")",
"{",
"var",
"index",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"this",
".",
"_items",
".",
"length",
",",
"options",
".",
"index",
")",
")",
";",
"this",
".",
"_items",
".",
"splice",
"(",
"index",
",",
"0",
",",
"item",
")",
";",
"}",
"else",
"{",
"this",
".",
"_items",
".",
"push",
"(",
"item",
")",
";",
"}",
"if",
"(",
"this",
".",
"_autoRefigureSizes",
")",
"{",
"this",
".",
"_figureSizes",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"_needsSizesFigured",
"=",
"true",
";",
"}",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"item",
".",
"addHandler",
"(",
"'bounds-change'",
",",
"this",
".",
"_delegatedFigureSizes",
")",
";",
"item",
".",
"addHandler",
"(",
"'clip-change'",
",",
"this",
".",
"_delegatedFigureSizes",
")",
";",
"/**\n * Raised when an item is added to the World.\n * @event add-item\n * @memberOf OpenSeadragon.World\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the World which raised the event.\n * @property {OpenSeadragon.TiledImage} item - The item that has been added.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'add-item'",
",",
"{",
"item",
":",
"item",
"}",
")",
";",
"}"
] |
Add the specified item.
@param {OpenSeadragon.TiledImage} item - The item to add.
@param {Number} [options.index] - Index for the item. If not specified, goes at the top.
@fires OpenSeadragon.World.event:add-item
@fires OpenSeadragon.World.event:metrics-change
|
[
"Add",
"the",
"specified",
"item",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/world.js#L76-L111
|
|
10,844
|
openseadragon/openseadragon
|
src/world.js
|
function( item, index ) {
$.console.assert(item, "[World.setItemIndex] item is required");
$.console.assert(index !== undefined, "[World.setItemIndex] index is required");
var oldIndex = this.getIndexOfItem( item );
if ( index >= this._items.length ) {
throw new Error( "Index bigger than number of layers." );
}
if ( index === oldIndex || oldIndex === -1 ) {
return;
}
this._items.splice( oldIndex, 1 );
this._items.splice( index, 0, item );
this._needsDraw = true;
/**
* Raised when the order of the indexes has been changed.
* @event item-index-change
* @memberOf OpenSeadragon.World
* @type {object}
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.
* @property {OpenSeadragon.TiledImage} item - The item whose index has
* been changed
* @property {Number} previousIndex - The previous index of the item
* @property {Number} newIndex - The new index of the item
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'item-index-change', {
item: item,
previousIndex: oldIndex,
newIndex: index
} );
}
|
javascript
|
function( item, index ) {
$.console.assert(item, "[World.setItemIndex] item is required");
$.console.assert(index !== undefined, "[World.setItemIndex] index is required");
var oldIndex = this.getIndexOfItem( item );
if ( index >= this._items.length ) {
throw new Error( "Index bigger than number of layers." );
}
if ( index === oldIndex || oldIndex === -1 ) {
return;
}
this._items.splice( oldIndex, 1 );
this._items.splice( index, 0, item );
this._needsDraw = true;
/**
* Raised when the order of the indexes has been changed.
* @event item-index-change
* @memberOf OpenSeadragon.World
* @type {object}
* @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.
* @property {OpenSeadragon.TiledImage} item - The item whose index has
* been changed
* @property {Number} previousIndex - The previous index of the item
* @property {Number} newIndex - The new index of the item
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.raiseEvent( 'item-index-change', {
item: item,
previousIndex: oldIndex,
newIndex: index
} );
}
|
[
"function",
"(",
"item",
",",
"index",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"item",
",",
"\"[World.setItemIndex] item is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"index",
"!==",
"undefined",
",",
"\"[World.setItemIndex] index is required\"",
")",
";",
"var",
"oldIndex",
"=",
"this",
".",
"getIndexOfItem",
"(",
"item",
")",
";",
"if",
"(",
"index",
">=",
"this",
".",
"_items",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Index bigger than number of layers.\"",
")",
";",
"}",
"if",
"(",
"index",
"===",
"oldIndex",
"||",
"oldIndex",
"===",
"-",
"1",
")",
"{",
"return",
";",
"}",
"this",
".",
"_items",
".",
"splice",
"(",
"oldIndex",
",",
"1",
")",
";",
"this",
".",
"_items",
".",
"splice",
"(",
"index",
",",
"0",
",",
"item",
")",
";",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"/**\n * Raised when the order of the indexes has been changed.\n * @event item-index-change\n * @memberOf OpenSeadragon.World\n * @type {object}\n * @property {OpenSeadragon.World} eventSource - A reference to the World which raised the event.\n * @property {OpenSeadragon.TiledImage} item - The item whose index has\n * been changed\n * @property {Number} previousIndex - The previous index of the item\n * @property {Number} newIndex - The new index of the item\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"raiseEvent",
"(",
"'item-index-change'",
",",
"{",
"item",
":",
"item",
",",
"previousIndex",
":",
"oldIndex",
",",
"newIndex",
":",
"index",
"}",
")",
";",
"}"
] |
Change the index of a item so that it appears over or under others.
@param {OpenSeadragon.TiledImage} item - The item to move.
@param {Number} index - The new index.
@fires OpenSeadragon.World.event:item-index-change
|
[
"Change",
"the",
"index",
"of",
"a",
"item",
"so",
"that",
"it",
"appears",
"over",
"or",
"under",
"others",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/world.js#L146-L181
|
|
10,845
|
openseadragon/openseadragon
|
src/world.js
|
function() {
// We need to make sure any pending images are canceled so the world items don't get messed up
this.viewer._cancelPendingImages();
var item;
var i;
for (i = 0; i < this._items.length; i++) {
item = this._items[i];
item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes);
item.destroy();
}
var removedItems = this._items;
this._items = [];
this._figureSizes();
this._needsDraw = true;
for (i = 0; i < removedItems.length; i++) {
item = removedItems[i];
this._raiseRemoveItem(item);
}
}
|
javascript
|
function() {
// We need to make sure any pending images are canceled so the world items don't get messed up
this.viewer._cancelPendingImages();
var item;
var i;
for (i = 0; i < this._items.length; i++) {
item = this._items[i];
item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes);
item.destroy();
}
var removedItems = this._items;
this._items = [];
this._figureSizes();
this._needsDraw = true;
for (i = 0; i < removedItems.length; i++) {
item = removedItems[i];
this._raiseRemoveItem(item);
}
}
|
[
"function",
"(",
")",
"{",
"// We need to make sure any pending images are canceled so the world items don't get messed up",
"this",
".",
"viewer",
".",
"_cancelPendingImages",
"(",
")",
";",
"var",
"item",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_items",
".",
"length",
";",
"i",
"++",
")",
"{",
"item",
"=",
"this",
".",
"_items",
"[",
"i",
"]",
";",
"item",
".",
"removeHandler",
"(",
"'bounds-change'",
",",
"this",
".",
"_delegatedFigureSizes",
")",
";",
"item",
".",
"removeHandler",
"(",
"'clip-change'",
",",
"this",
".",
"_delegatedFigureSizes",
")",
";",
"item",
".",
"destroy",
"(",
")",
";",
"}",
"var",
"removedItems",
"=",
"this",
".",
"_items",
";",
"this",
".",
"_items",
"=",
"[",
"]",
";",
"this",
".",
"_figureSizes",
"(",
")",
";",
"this",
".",
"_needsDraw",
"=",
"true",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"removedItems",
".",
"length",
";",
"i",
"++",
")",
"{",
"item",
"=",
"removedItems",
"[",
"i",
"]",
";",
"this",
".",
"_raiseRemoveItem",
"(",
"item",
")",
";",
"}",
"}"
] |
Remove all items.
@fires OpenSeadragon.World.event:remove-item
@fires OpenSeadragon.World.event:metrics-change
|
[
"Remove",
"all",
"items",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/world.js#L211-L232
|
|
10,846
|
openseadragon/openseadragon
|
src/world.js
|
function() {
for ( var i = 0; i < this._items.length; i++ ) {
this._items[i].draw();
}
this._needsDraw = false;
}
|
javascript
|
function() {
for ( var i = 0; i < this._items.length; i++ ) {
this._items[i].draw();
}
this._needsDraw = false;
}
|
[
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_items",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"_items",
"[",
"i",
"]",
".",
"draw",
"(",
")",
";",
"}",
"this",
".",
"_needsDraw",
"=",
"false",
";",
"}"
] |
Draws all items.
|
[
"Draws",
"all",
"items",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/world.js#L258-L264
|
|
10,847
|
openseadragon/openseadragon
|
src/world.js
|
function(options) {
options = options || {};
var immediately = options.immediately || false;
var layout = options.layout || $.DEFAULT_SETTINGS.collectionLayout;
var rows = options.rows || $.DEFAULT_SETTINGS.collectionRows;
var columns = options.columns || $.DEFAULT_SETTINGS.collectionColumns;
var tileSize = options.tileSize || $.DEFAULT_SETTINGS.collectionTileSize;
var tileMargin = options.tileMargin || $.DEFAULT_SETTINGS.collectionTileMargin;
var increment = tileSize + tileMargin;
var wrap;
if (!options.rows && columns) {
wrap = columns;
} else {
wrap = Math.ceil(this._items.length / rows);
}
var x = 0;
var y = 0;
var item, box, width, height, position;
this.setAutoRefigureSizes(false);
for (var i = 0; i < this._items.length; i++) {
if (i && (i % wrap) === 0) {
if (layout === 'horizontal') {
y += increment;
x = 0;
} else {
x += increment;
y = 0;
}
}
item = this._items[i];
box = item.getBounds();
if (box.width > box.height) {
width = tileSize;
} else {
width = tileSize * (box.width / box.height);
}
height = width * (box.height / box.width);
position = new $.Point(x + ((tileSize - width) / 2),
y + ((tileSize - height) / 2));
item.setPosition(position, immediately);
item.setWidth(width, immediately);
if (layout === 'horizontal') {
x += increment;
} else {
y += increment;
}
}
this.setAutoRefigureSizes(true);
}
|
javascript
|
function(options) {
options = options || {};
var immediately = options.immediately || false;
var layout = options.layout || $.DEFAULT_SETTINGS.collectionLayout;
var rows = options.rows || $.DEFAULT_SETTINGS.collectionRows;
var columns = options.columns || $.DEFAULT_SETTINGS.collectionColumns;
var tileSize = options.tileSize || $.DEFAULT_SETTINGS.collectionTileSize;
var tileMargin = options.tileMargin || $.DEFAULT_SETTINGS.collectionTileMargin;
var increment = tileSize + tileMargin;
var wrap;
if (!options.rows && columns) {
wrap = columns;
} else {
wrap = Math.ceil(this._items.length / rows);
}
var x = 0;
var y = 0;
var item, box, width, height, position;
this.setAutoRefigureSizes(false);
for (var i = 0; i < this._items.length; i++) {
if (i && (i % wrap) === 0) {
if (layout === 'horizontal') {
y += increment;
x = 0;
} else {
x += increment;
y = 0;
}
}
item = this._items[i];
box = item.getBounds();
if (box.width > box.height) {
width = tileSize;
} else {
width = tileSize * (box.width / box.height);
}
height = width * (box.height / box.width);
position = new $.Point(x + ((tileSize - width) / 2),
y + ((tileSize - height) / 2));
item.setPosition(position, immediately);
item.setWidth(width, immediately);
if (layout === 'horizontal') {
x += increment;
} else {
y += increment;
}
}
this.setAutoRefigureSizes(true);
}
|
[
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"immediately",
"=",
"options",
".",
"immediately",
"||",
"false",
";",
"var",
"layout",
"=",
"options",
".",
"layout",
"||",
"$",
".",
"DEFAULT_SETTINGS",
".",
"collectionLayout",
";",
"var",
"rows",
"=",
"options",
".",
"rows",
"||",
"$",
".",
"DEFAULT_SETTINGS",
".",
"collectionRows",
";",
"var",
"columns",
"=",
"options",
".",
"columns",
"||",
"$",
".",
"DEFAULT_SETTINGS",
".",
"collectionColumns",
";",
"var",
"tileSize",
"=",
"options",
".",
"tileSize",
"||",
"$",
".",
"DEFAULT_SETTINGS",
".",
"collectionTileSize",
";",
"var",
"tileMargin",
"=",
"options",
".",
"tileMargin",
"||",
"$",
".",
"DEFAULT_SETTINGS",
".",
"collectionTileMargin",
";",
"var",
"increment",
"=",
"tileSize",
"+",
"tileMargin",
";",
"var",
"wrap",
";",
"if",
"(",
"!",
"options",
".",
"rows",
"&&",
"columns",
")",
"{",
"wrap",
"=",
"columns",
";",
"}",
"else",
"{",
"wrap",
"=",
"Math",
".",
"ceil",
"(",
"this",
".",
"_items",
".",
"length",
"/",
"rows",
")",
";",
"}",
"var",
"x",
"=",
"0",
";",
"var",
"y",
"=",
"0",
";",
"var",
"item",
",",
"box",
",",
"width",
",",
"height",
",",
"position",
";",
"this",
".",
"setAutoRefigureSizes",
"(",
"false",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_items",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"&&",
"(",
"i",
"%",
"wrap",
")",
"===",
"0",
")",
"{",
"if",
"(",
"layout",
"===",
"'horizontal'",
")",
"{",
"y",
"+=",
"increment",
";",
"x",
"=",
"0",
";",
"}",
"else",
"{",
"x",
"+=",
"increment",
";",
"y",
"=",
"0",
";",
"}",
"}",
"item",
"=",
"this",
".",
"_items",
"[",
"i",
"]",
";",
"box",
"=",
"item",
".",
"getBounds",
"(",
")",
";",
"if",
"(",
"box",
".",
"width",
">",
"box",
".",
"height",
")",
"{",
"width",
"=",
"tileSize",
";",
"}",
"else",
"{",
"width",
"=",
"tileSize",
"*",
"(",
"box",
".",
"width",
"/",
"box",
".",
"height",
")",
";",
"}",
"height",
"=",
"width",
"*",
"(",
"box",
".",
"height",
"/",
"box",
".",
"width",
")",
";",
"position",
"=",
"new",
"$",
".",
"Point",
"(",
"x",
"+",
"(",
"(",
"tileSize",
"-",
"width",
")",
"/",
"2",
")",
",",
"y",
"+",
"(",
"(",
"tileSize",
"-",
"height",
")",
"/",
"2",
")",
")",
";",
"item",
".",
"setPosition",
"(",
"position",
",",
"immediately",
")",
";",
"item",
".",
"setWidth",
"(",
"width",
",",
"immediately",
")",
";",
"if",
"(",
"layout",
"===",
"'horizontal'",
")",
"{",
"x",
"+=",
"increment",
";",
"}",
"else",
"{",
"y",
"+=",
"increment",
";",
"}",
"}",
"this",
".",
"setAutoRefigureSizes",
"(",
"true",
")",
";",
"}"
] |
Arranges all of the TiledImages with the specified settings.
@param {Object} options - Specifies how to arrange.
@param {Boolean} [options.immediately=false] - Whether to animate to the new arrangement.
@param {String} [options.layout] - See collectionLayout in {@link OpenSeadragon.Options}.
@param {Number} [options.rows] - See collectionRows in {@link OpenSeadragon.Options}.
@param {Number} [options.columns] - See collectionColumns in {@link OpenSeadragon.Options}.
@param {Number} [options.tileSize] - See collectionTileSize in {@link OpenSeadragon.Options}.
@param {Number} [options.tileMargin] - See collectionTileMargin in {@link OpenSeadragon.Options}.
@fires OpenSeadragon.World.event:metrics-change
|
[
"Arranges",
"all",
"of",
"the",
"TiledImages",
"with",
"the",
"specified",
"settings",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/world.js#L321-L374
|
|
10,848
|
openseadragon/openseadragon
|
src/overlay.js
|
function(position, size) {
var properties = $.Placement.properties[this.placement];
if (!properties) {
return;
}
if (properties.isHorizontallyCentered) {
position.x -= size.x / 2;
} else if (properties.isRight) {
position.x -= size.x;
}
if (properties.isVerticallyCentered) {
position.y -= size.y / 2;
} else if (properties.isBottom) {
position.y -= size.y;
}
}
|
javascript
|
function(position, size) {
var properties = $.Placement.properties[this.placement];
if (!properties) {
return;
}
if (properties.isHorizontallyCentered) {
position.x -= size.x / 2;
} else if (properties.isRight) {
position.x -= size.x;
}
if (properties.isVerticallyCentered) {
position.y -= size.y / 2;
} else if (properties.isBottom) {
position.y -= size.y;
}
}
|
[
"function",
"(",
"position",
",",
"size",
")",
"{",
"var",
"properties",
"=",
"$",
".",
"Placement",
".",
"properties",
"[",
"this",
".",
"placement",
"]",
";",
"if",
"(",
"!",
"properties",
")",
"{",
"return",
";",
"}",
"if",
"(",
"properties",
".",
"isHorizontallyCentered",
")",
"{",
"position",
".",
"x",
"-=",
"size",
".",
"x",
"/",
"2",
";",
"}",
"else",
"if",
"(",
"properties",
".",
"isRight",
")",
"{",
"position",
".",
"x",
"-=",
"size",
".",
"x",
";",
"}",
"if",
"(",
"properties",
".",
"isVerticallyCentered",
")",
"{",
"position",
".",
"y",
"-=",
"size",
".",
"y",
"/",
"2",
";",
"}",
"else",
"if",
"(",
"properties",
".",
"isBottom",
")",
"{",
"position",
".",
"y",
"-=",
"size",
".",
"y",
";",
"}",
"}"
] |
Internal function to adjust the position of an overlay
depending on it size and placement.
@function
@param {OpenSeadragon.Point} position
@param {OpenSeadragon.Point} size
|
[
"Internal",
"function",
"to",
"adjust",
"the",
"position",
"of",
"an",
"overlay",
"depending",
"on",
"it",
"size",
"and",
"placement",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/overlay.js#L178-L193
|
|
10,849
|
openseadragon/openseadragon
|
src/overlay.js
|
function(location, placement) {
var options = $.isPlainObject(location) ? location : {
location: location,
placement: placement
};
this._init({
location: options.location || this.location,
placement: options.placement !== undefined ?
options.placement : this.placement,
onDraw: options.onDraw || this.onDraw,
checkResize: options.checkResize || this.checkResize,
width: options.width !== undefined ? options.width : this.width,
height: options.height !== undefined ? options.height : this.height,
rotationMode: options.rotationMode || this.rotationMode
});
}
|
javascript
|
function(location, placement) {
var options = $.isPlainObject(location) ? location : {
location: location,
placement: placement
};
this._init({
location: options.location || this.location,
placement: options.placement !== undefined ?
options.placement : this.placement,
onDraw: options.onDraw || this.onDraw,
checkResize: options.checkResize || this.checkResize,
width: options.width !== undefined ? options.width : this.width,
height: options.height !== undefined ? options.height : this.height,
rotationMode: options.rotationMode || this.rotationMode
});
}
|
[
"function",
"(",
"location",
",",
"placement",
")",
"{",
"var",
"options",
"=",
"$",
".",
"isPlainObject",
"(",
"location",
")",
"?",
"location",
":",
"{",
"location",
":",
"location",
",",
"placement",
":",
"placement",
"}",
";",
"this",
".",
"_init",
"(",
"{",
"location",
":",
"options",
".",
"location",
"||",
"this",
".",
"location",
",",
"placement",
":",
"options",
".",
"placement",
"!==",
"undefined",
"?",
"options",
".",
"placement",
":",
"this",
".",
"placement",
",",
"onDraw",
":",
"options",
".",
"onDraw",
"||",
"this",
".",
"onDraw",
",",
"checkResize",
":",
"options",
".",
"checkResize",
"||",
"this",
".",
"checkResize",
",",
"width",
":",
"options",
".",
"width",
"!==",
"undefined",
"?",
"options",
".",
"width",
":",
"this",
".",
"width",
",",
"height",
":",
"options",
".",
"height",
"!==",
"undefined",
"?",
"options",
".",
"height",
":",
"this",
".",
"height",
",",
"rotationMode",
":",
"options",
".",
"rotationMode",
"||",
"this",
".",
"rotationMode",
"}",
")",
";",
"}"
] |
Changes the overlay settings.
@function
@param {OpenSeadragon.Point|OpenSeadragon.Rect|Object} location
If an object is specified, the options are the same than the constructor
except for the element which can not be changed.
@param {OpenSeadragon.Placement} placement
|
[
"Changes",
"the",
"overlay",
"settings",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/overlay.js#L407-L422
|
|
10,850
|
openseadragon/openseadragon
|
src/overlay.js
|
function(viewport) {
$.console.assert(viewport,
'A viewport must now be passed to Overlay.getBounds.');
var width = this.width;
var height = this.height;
if (width === null || height === null) {
var size = viewport.deltaPointsFromPixelsNoRotate(this.size, true);
if (width === null) {
width = size.x;
}
if (height === null) {
height = size.y;
}
}
var location = this.location.clone();
this.adjust(location, new $.Point(width, height));
return this._adjustBoundsForRotation(
viewport, new $.Rect(location.x, location.y, width, height));
}
|
javascript
|
function(viewport) {
$.console.assert(viewport,
'A viewport must now be passed to Overlay.getBounds.');
var width = this.width;
var height = this.height;
if (width === null || height === null) {
var size = viewport.deltaPointsFromPixelsNoRotate(this.size, true);
if (width === null) {
width = size.x;
}
if (height === null) {
height = size.y;
}
}
var location = this.location.clone();
this.adjust(location, new $.Point(width, height));
return this._adjustBoundsForRotation(
viewport, new $.Rect(location.x, location.y, width, height));
}
|
[
"function",
"(",
"viewport",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"viewport",
",",
"'A viewport must now be passed to Overlay.getBounds.'",
")",
";",
"var",
"width",
"=",
"this",
".",
"width",
";",
"var",
"height",
"=",
"this",
".",
"height",
";",
"if",
"(",
"width",
"===",
"null",
"||",
"height",
"===",
"null",
")",
"{",
"var",
"size",
"=",
"viewport",
".",
"deltaPointsFromPixelsNoRotate",
"(",
"this",
".",
"size",
",",
"true",
")",
";",
"if",
"(",
"width",
"===",
"null",
")",
"{",
"width",
"=",
"size",
".",
"x",
";",
"}",
"if",
"(",
"height",
"===",
"null",
")",
"{",
"height",
"=",
"size",
".",
"y",
";",
"}",
"}",
"var",
"location",
"=",
"this",
".",
"location",
".",
"clone",
"(",
")",
";",
"this",
".",
"adjust",
"(",
"location",
",",
"new",
"$",
".",
"Point",
"(",
"width",
",",
"height",
")",
")",
";",
"return",
"this",
".",
"_adjustBoundsForRotation",
"(",
"viewport",
",",
"new",
"$",
".",
"Rect",
"(",
"location",
".",
"x",
",",
"location",
".",
"y",
",",
"width",
",",
"height",
")",
")",
";",
"}"
] |
Returns the current bounds of the overlay in viewport coordinates
@function
@param {OpenSeadragon.Viewport} viewport the viewport
@returns {OpenSeadragon.Rect} overlay bounds
|
[
"Returns",
"the",
"current",
"bounds",
"of",
"the",
"overlay",
"in",
"viewport",
"coordinates"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/overlay.js#L430-L448
|
|
10,851
|
openseadragon/openseadragon
|
src/referencestrip.js
|
function() {
if (this.miniViewers) {
for (var key in this.miniViewers) {
this.miniViewers[key].destroy();
}
}
if (this.element) {
this.element.parentNode.removeChild(this.element);
}
}
|
javascript
|
function() {
if (this.miniViewers) {
for (var key in this.miniViewers) {
this.miniViewers[key].destroy();
}
}
if (this.element) {
this.element.parentNode.removeChild(this.element);
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"miniViewers",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"this",
".",
"miniViewers",
")",
"{",
"this",
".",
"miniViewers",
"[",
"key",
"]",
".",
"destroy",
"(",
")",
";",
"}",
"}",
"if",
"(",
"this",
".",
"element",
")",
"{",
"this",
".",
"element",
".",
"parentNode",
".",
"removeChild",
"(",
"this",
".",
"element",
")",
";",
"}",
"}"
] |
Overrides Viewer.destroy
|
[
"Overrides",
"Viewer",
".",
"destroy"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/referencestrip.js#L296-L306
|
|
10,852
|
openseadragon/openseadragon
|
src/viewport.js
|
function(contentSize) {
$.console.assert(contentSize, "[Viewport.resetContentSize] contentSize is required");
$.console.assert(contentSize instanceof $.Point, "[Viewport.resetContentSize] contentSize must be an OpenSeadragon.Point");
$.console.assert(contentSize.x > 0, "[Viewport.resetContentSize] contentSize.x must be greater than 0");
$.console.assert(contentSize.y > 0, "[Viewport.resetContentSize] contentSize.y must be greater than 0");
this._setContentBounds(new $.Rect(0, 0, 1, contentSize.y / contentSize.x), contentSize.x);
return this;
}
|
javascript
|
function(contentSize) {
$.console.assert(contentSize, "[Viewport.resetContentSize] contentSize is required");
$.console.assert(contentSize instanceof $.Point, "[Viewport.resetContentSize] contentSize must be an OpenSeadragon.Point");
$.console.assert(contentSize.x > 0, "[Viewport.resetContentSize] contentSize.x must be greater than 0");
$.console.assert(contentSize.y > 0, "[Viewport.resetContentSize] contentSize.y must be greater than 0");
this._setContentBounds(new $.Rect(0, 0, 1, contentSize.y / contentSize.x), contentSize.x);
return this;
}
|
[
"function",
"(",
"contentSize",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"contentSize",
",",
"\"[Viewport.resetContentSize] contentSize is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"contentSize",
"instanceof",
"$",
".",
"Point",
",",
"\"[Viewport.resetContentSize] contentSize must be an OpenSeadragon.Point\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"contentSize",
".",
"x",
">",
"0",
",",
"\"[Viewport.resetContentSize] contentSize.x must be greater than 0\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"contentSize",
".",
"y",
">",
"0",
",",
"\"[Viewport.resetContentSize] contentSize.y must be greater than 0\"",
")",
";",
"this",
".",
"_setContentBounds",
"(",
"new",
"$",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"1",
",",
"contentSize",
".",
"y",
"/",
"contentSize",
".",
"x",
")",
",",
"contentSize",
".",
"x",
")",
";",
"return",
"this",
";",
"}"
] |
Updates the viewport's home bounds and constraints for the given content size.
@function
@param {OpenSeadragon.Point} contentSize - size of the content in content units
@return {OpenSeadragon.Viewport} Chainable.
@fires OpenSeadragon.Viewer.event:reset-size
|
[
"Updates",
"the",
"viewport",
"s",
"home",
"bounds",
"and",
"constraints",
"for",
"the",
"given",
"content",
"size",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L153-L161
|
|
10,853
|
openseadragon/openseadragon
|
src/viewport.js
|
function(bounds, contentFactor) {
$.console.assert(bounds, "[Viewport._setContentBounds] bounds is required");
$.console.assert(bounds instanceof $.Rect, "[Viewport._setContentBounds] bounds must be an OpenSeadragon.Rect");
$.console.assert(bounds.width > 0, "[Viewport._setContentBounds] bounds.width must be greater than 0");
$.console.assert(bounds.height > 0, "[Viewport._setContentBounds] bounds.height must be greater than 0");
this._contentBoundsNoRotate = bounds.clone();
this._contentSizeNoRotate = this._contentBoundsNoRotate.getSize().times(
contentFactor);
this._contentBounds = bounds.rotate(this.degrees).getBoundingBox();
this._contentSize = this._contentBounds.getSize().times(contentFactor);
this._contentAspectRatio = this._contentSize.x / this._contentSize.y;
if (this.viewer) {
/**
* Raised when the viewer's content size or home bounds are reset
* (see {@link OpenSeadragon.Viewport#resetContentSize}).
*
* @event reset-size
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {OpenSeadragon.Point} contentSize
* @property {OpenSeadragon.Rect} contentBounds - Content bounds.
* @property {OpenSeadragon.Rect} homeBounds - Content bounds.
* Deprecated use contentBounds instead.
* @property {Number} contentFactor
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('reset-size', {
contentSize: this._contentSizeNoRotate.clone(),
contentFactor: contentFactor,
homeBounds: this._contentBoundsNoRotate.clone(),
contentBounds: this._contentBounds.clone()
});
}
}
|
javascript
|
function(bounds, contentFactor) {
$.console.assert(bounds, "[Viewport._setContentBounds] bounds is required");
$.console.assert(bounds instanceof $.Rect, "[Viewport._setContentBounds] bounds must be an OpenSeadragon.Rect");
$.console.assert(bounds.width > 0, "[Viewport._setContentBounds] bounds.width must be greater than 0");
$.console.assert(bounds.height > 0, "[Viewport._setContentBounds] bounds.height must be greater than 0");
this._contentBoundsNoRotate = bounds.clone();
this._contentSizeNoRotate = this._contentBoundsNoRotate.getSize().times(
contentFactor);
this._contentBounds = bounds.rotate(this.degrees).getBoundingBox();
this._contentSize = this._contentBounds.getSize().times(contentFactor);
this._contentAspectRatio = this._contentSize.x / this._contentSize.y;
if (this.viewer) {
/**
* Raised when the viewer's content size or home bounds are reset
* (see {@link OpenSeadragon.Viewport#resetContentSize}).
*
* @event reset-size
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {OpenSeadragon.Point} contentSize
* @property {OpenSeadragon.Rect} contentBounds - Content bounds.
* @property {OpenSeadragon.Rect} homeBounds - Content bounds.
* Deprecated use contentBounds instead.
* @property {Number} contentFactor
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('reset-size', {
contentSize: this._contentSizeNoRotate.clone(),
contentFactor: contentFactor,
homeBounds: this._contentBoundsNoRotate.clone(),
contentBounds: this._contentBounds.clone()
});
}
}
|
[
"function",
"(",
"bounds",
",",
"contentFactor",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"bounds",
",",
"\"[Viewport._setContentBounds] bounds is required\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"bounds",
"instanceof",
"$",
".",
"Rect",
",",
"\"[Viewport._setContentBounds] bounds must be an OpenSeadragon.Rect\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"bounds",
".",
"width",
">",
"0",
",",
"\"[Viewport._setContentBounds] bounds.width must be greater than 0\"",
")",
";",
"$",
".",
"console",
".",
"assert",
"(",
"bounds",
".",
"height",
">",
"0",
",",
"\"[Viewport._setContentBounds] bounds.height must be greater than 0\"",
")",
";",
"this",
".",
"_contentBoundsNoRotate",
"=",
"bounds",
".",
"clone",
"(",
")",
";",
"this",
".",
"_contentSizeNoRotate",
"=",
"this",
".",
"_contentBoundsNoRotate",
".",
"getSize",
"(",
")",
".",
"times",
"(",
"contentFactor",
")",
";",
"this",
".",
"_contentBounds",
"=",
"bounds",
".",
"rotate",
"(",
"this",
".",
"degrees",
")",
".",
"getBoundingBox",
"(",
")",
";",
"this",
".",
"_contentSize",
"=",
"this",
".",
"_contentBounds",
".",
"getSize",
"(",
")",
".",
"times",
"(",
"contentFactor",
")",
";",
"this",
".",
"_contentAspectRatio",
"=",
"this",
".",
"_contentSize",
".",
"x",
"/",
"this",
".",
"_contentSize",
".",
"y",
";",
"if",
"(",
"this",
".",
"viewer",
")",
"{",
"/**\n * Raised when the viewer's content size or home bounds are reset\n * (see {@link OpenSeadragon.Viewport#resetContentSize}).\n *\n * @event reset-size\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.\n * @property {OpenSeadragon.Point} contentSize\n * @property {OpenSeadragon.Rect} contentBounds - Content bounds.\n * @property {OpenSeadragon.Rect} homeBounds - Content bounds.\n * Deprecated use contentBounds instead.\n * @property {Number} contentFactor\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"viewer",
".",
"raiseEvent",
"(",
"'reset-size'",
",",
"{",
"contentSize",
":",
"this",
".",
"_contentSizeNoRotate",
".",
"clone",
"(",
")",
",",
"contentFactor",
":",
"contentFactor",
",",
"homeBounds",
":",
"this",
".",
"_contentBoundsNoRotate",
".",
"clone",
"(",
")",
",",
"contentBounds",
":",
"this",
".",
"_contentBounds",
".",
"clone",
"(",
")",
"}",
")",
";",
"}",
"}"
] |
Set the viewport's content bounds @param {OpenSeadragon.Rect} bounds - the new bounds in viewport coordinates without rotation @param {Number} contentFactor - how many content units per viewport unit @fires OpenSeadragon.Viewer.event:reset-size @private
|
[
"Set",
"the",
"viewport",
"s",
"content",
"bounds"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L175-L212
|
|
10,854
|
openseadragon/openseadragon
|
src/viewport.js
|
function() {
if (this.defaultZoomLevel) {
return this.defaultZoomLevel;
}
var aspectFactor = this._contentAspectRatio / this.getAspectRatio();
var output;
if (this.homeFillsViewer) { // fill the viewer and clip the image
output = aspectFactor >= 1 ? aspectFactor : 1;
} else {
output = aspectFactor >= 1 ? 1 : aspectFactor;
}
return output / this._contentBounds.width;
}
|
javascript
|
function() {
if (this.defaultZoomLevel) {
return this.defaultZoomLevel;
}
var aspectFactor = this._contentAspectRatio / this.getAspectRatio();
var output;
if (this.homeFillsViewer) { // fill the viewer and clip the image
output = aspectFactor >= 1 ? aspectFactor : 1;
} else {
output = aspectFactor >= 1 ? 1 : aspectFactor;
}
return output / this._contentBounds.width;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"defaultZoomLevel",
")",
"{",
"return",
"this",
".",
"defaultZoomLevel",
";",
"}",
"var",
"aspectFactor",
"=",
"this",
".",
"_contentAspectRatio",
"/",
"this",
".",
"getAspectRatio",
"(",
")",
";",
"var",
"output",
";",
"if",
"(",
"this",
".",
"homeFillsViewer",
")",
"{",
"// fill the viewer and clip the image",
"output",
"=",
"aspectFactor",
">=",
"1",
"?",
"aspectFactor",
":",
"1",
";",
"}",
"else",
"{",
"output",
"=",
"aspectFactor",
">=",
"1",
"?",
"1",
":",
"aspectFactor",
";",
"}",
"return",
"output",
"/",
"this",
".",
"_contentBounds",
".",
"width",
";",
"}"
] |
Returns the home zoom in "viewport zoom" value.
@function
@returns {Number} The home zoom in "viewport zoom".
|
[
"Returns",
"the",
"home",
"zoom",
"in",
"viewport",
"zoom",
"value",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L219-L233
|
|
10,855
|
openseadragon/openseadragon
|
src/viewport.js
|
function(margins) {
$.console.assert($.type(margins) === 'object', '[Viewport.setMargins] margins must be an object');
this._margins = $.extend({
left: 0,
top: 0,
right: 0,
bottom: 0
}, margins);
this._updateContainerInnerSize();
if (this.viewer) {
this.viewer.forceRedraw();
}
}
|
javascript
|
function(margins) {
$.console.assert($.type(margins) === 'object', '[Viewport.setMargins] margins must be an object');
this._margins = $.extend({
left: 0,
top: 0,
right: 0,
bottom: 0
}, margins);
this._updateContainerInnerSize();
if (this.viewer) {
this.viewer.forceRedraw();
}
}
|
[
"function",
"(",
"margins",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"$",
".",
"type",
"(",
"margins",
")",
"===",
"'object'",
",",
"'[Viewport.setMargins] margins must be an object'",
")",
";",
"this",
".",
"_margins",
"=",
"$",
".",
"extend",
"(",
"{",
"left",
":",
"0",
",",
"top",
":",
"0",
",",
"right",
":",
"0",
",",
"bottom",
":",
"0",
"}",
",",
"margins",
")",
";",
"this",
".",
"_updateContainerInnerSize",
"(",
")",
";",
"if",
"(",
"this",
".",
"viewer",
")",
"{",
"this",
".",
"viewer",
".",
"forceRedraw",
"(",
")",
";",
"}",
"}"
] |
The margins push the "home" region in from the sides by the specified amounts.
@function
@param {Object} margins - Properties (Numbers, in screen coordinates): left, top, right, bottom.
|
[
"The",
"margins",
"push",
"the",
"home",
"region",
"in",
"from",
"the",
"sides",
"by",
"the",
"specified",
"amounts",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L345-L359
|
|
10,856
|
openseadragon/openseadragon
|
src/viewport.js
|
function(immediately) {
var actualZoom = this.getZoom();
var constrainedZoom = this._applyZoomConstraints(actualZoom);
if (actualZoom !== constrainedZoom) {
this.zoomTo(constrainedZoom, this.zoomPoint, immediately);
}
var bounds = this.getBoundsNoRotate();
var constrainedBounds = this._applyBoundaryConstraints(bounds);
this._raiseConstraintsEvent(immediately);
if (bounds.x !== constrainedBounds.x ||
bounds.y !== constrainedBounds.y ||
immediately) {
this.fitBounds(
constrainedBounds.rotate(-this.getRotation()),
immediately);
}
return this;
}
|
javascript
|
function(immediately) {
var actualZoom = this.getZoom();
var constrainedZoom = this._applyZoomConstraints(actualZoom);
if (actualZoom !== constrainedZoom) {
this.zoomTo(constrainedZoom, this.zoomPoint, immediately);
}
var bounds = this.getBoundsNoRotate();
var constrainedBounds = this._applyBoundaryConstraints(bounds);
this._raiseConstraintsEvent(immediately);
if (bounds.x !== constrainedBounds.x ||
bounds.y !== constrainedBounds.y ||
immediately) {
this.fitBounds(
constrainedBounds.rotate(-this.getRotation()),
immediately);
}
return this;
}
|
[
"function",
"(",
"immediately",
")",
"{",
"var",
"actualZoom",
"=",
"this",
".",
"getZoom",
"(",
")",
";",
"var",
"constrainedZoom",
"=",
"this",
".",
"_applyZoomConstraints",
"(",
"actualZoom",
")",
";",
"if",
"(",
"actualZoom",
"!==",
"constrainedZoom",
")",
"{",
"this",
".",
"zoomTo",
"(",
"constrainedZoom",
",",
"this",
".",
"zoomPoint",
",",
"immediately",
")",
";",
"}",
"var",
"bounds",
"=",
"this",
".",
"getBoundsNoRotate",
"(",
")",
";",
"var",
"constrainedBounds",
"=",
"this",
".",
"_applyBoundaryConstraints",
"(",
"bounds",
")",
";",
"this",
".",
"_raiseConstraintsEvent",
"(",
"immediately",
")",
";",
"if",
"(",
"bounds",
".",
"x",
"!==",
"constrainedBounds",
".",
"x",
"||",
"bounds",
".",
"y",
"!==",
"constrainedBounds",
".",
"y",
"||",
"immediately",
")",
"{",
"this",
".",
"fitBounds",
"(",
"constrainedBounds",
".",
"rotate",
"(",
"-",
"this",
".",
"getRotation",
"(",
")",
")",
",",
"immediately",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Enforces the minZoom, maxZoom and visibilityRatio constraints by
zooming and panning to the closest acceptable zoom and location.
@function
@param {Boolean} [immediately=false]
@return {OpenSeadragon.Viewport} Chainable.
@fires OpenSeadragon.Viewer.event:constrain
|
[
"Enforces",
"the",
"minZoom",
"maxZoom",
"and",
"visibilityRatio",
"constraints",
"by",
"zooming",
"and",
"panning",
"to",
"the",
"closest",
"acceptable",
"zoom",
"and",
"location",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L570-L590
|
|
10,857
|
openseadragon/openseadragon
|
src/viewport.js
|
function(immediately) {
var box = new $.Rect(
this._contentBounds.x,
this._contentBounds.y + (this._contentBounds.height / 2),
this._contentBounds.width,
0);
return this.fitBounds(box, immediately);
}
|
javascript
|
function(immediately) {
var box = new $.Rect(
this._contentBounds.x,
this._contentBounds.y + (this._contentBounds.height / 2),
this._contentBounds.width,
0);
return this.fitBounds(box, immediately);
}
|
[
"function",
"(",
"immediately",
")",
"{",
"var",
"box",
"=",
"new",
"$",
".",
"Rect",
"(",
"this",
".",
"_contentBounds",
".",
"x",
",",
"this",
".",
"_contentBounds",
".",
"y",
"+",
"(",
"this",
".",
"_contentBounds",
".",
"height",
"/",
"2",
")",
",",
"this",
".",
"_contentBounds",
".",
"width",
",",
"0",
")",
";",
"return",
"this",
".",
"fitBounds",
"(",
"box",
",",
"immediately",
")",
";",
"}"
] |
Zooms so the image just fills the viewer horizontally.
@param {Boolean} immediately
@return {OpenSeadragon.Viewport} Chainable.
|
[
"Zooms",
"so",
"the",
"image",
"just",
"fills",
"the",
"viewer",
"horizontally",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L736-L743
|
|
10,858
|
openseadragon/openseadragon
|
src/viewport.js
|
function(current) {
var bounds,
constrainedBounds;
bounds = this.getBounds(current);
constrainedBounds = this._applyBoundaryConstraints(bounds);
return constrainedBounds;
}
|
javascript
|
function(current) {
var bounds,
constrainedBounds;
bounds = this.getBounds(current);
constrainedBounds = this._applyBoundaryConstraints(bounds);
return constrainedBounds;
}
|
[
"function",
"(",
"current",
")",
"{",
"var",
"bounds",
",",
"constrainedBounds",
";",
"bounds",
"=",
"this",
".",
"getBounds",
"(",
"current",
")",
";",
"constrainedBounds",
"=",
"this",
".",
"_applyBoundaryConstraints",
"(",
"bounds",
")",
";",
"return",
"constrainedBounds",
";",
"}"
] |
Returns bounds taking constraints into account
Added to improve constrained panning
@param {Boolean} current - Pass true for the current location; defaults to false (target location).
@return {OpenSeadragon.Viewport} Chainable.
|
[
"Returns",
"bounds",
"taking",
"constraints",
"into",
"account",
"Added",
"to",
"improve",
"constrained",
"panning"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L752-L761
|
|
10,859
|
openseadragon/openseadragon
|
src/viewport.js
|
function(zoom, refPoint, immediately) {
var _this = this;
this.zoomPoint = refPoint instanceof $.Point &&
!isNaN(refPoint.x) &&
!isNaN(refPoint.y) ?
refPoint :
null;
if (immediately) {
this._adjustCenterSpringsForZoomPoint(function() {
_this.zoomSpring.resetTo(zoom);
});
} else {
this.zoomSpring.springTo(zoom);
}
if (this.viewer) {
/**
* Raised when the viewport zoom level changes (see {@link OpenSeadragon.Viewport#zoomBy} and {@link OpenSeadragon.Viewport#zoomTo}).
*
* @event zoom
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {Number} zoom
* @property {OpenSeadragon.Point} refPoint
* @property {Boolean} immediately
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('zoom', {
zoom: zoom,
refPoint: refPoint,
immediately: immediately
});
}
return this;
}
|
javascript
|
function(zoom, refPoint, immediately) {
var _this = this;
this.zoomPoint = refPoint instanceof $.Point &&
!isNaN(refPoint.x) &&
!isNaN(refPoint.y) ?
refPoint :
null;
if (immediately) {
this._adjustCenterSpringsForZoomPoint(function() {
_this.zoomSpring.resetTo(zoom);
});
} else {
this.zoomSpring.springTo(zoom);
}
if (this.viewer) {
/**
* Raised when the viewport zoom level changes (see {@link OpenSeadragon.Viewport#zoomBy} and {@link OpenSeadragon.Viewport#zoomTo}).
*
* @event zoom
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
* @property {Number} zoom
* @property {OpenSeadragon.Point} refPoint
* @property {Boolean} immediately
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('zoom', {
zoom: zoom,
refPoint: refPoint,
immediately: immediately
});
}
return this;
}
|
[
"function",
"(",
"zoom",
",",
"refPoint",
",",
"immediately",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"this",
".",
"zoomPoint",
"=",
"refPoint",
"instanceof",
"$",
".",
"Point",
"&&",
"!",
"isNaN",
"(",
"refPoint",
".",
"x",
")",
"&&",
"!",
"isNaN",
"(",
"refPoint",
".",
"y",
")",
"?",
"refPoint",
":",
"null",
";",
"if",
"(",
"immediately",
")",
"{",
"this",
".",
"_adjustCenterSpringsForZoomPoint",
"(",
"function",
"(",
")",
"{",
"_this",
".",
"zoomSpring",
".",
"resetTo",
"(",
"zoom",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"zoomSpring",
".",
"springTo",
"(",
"zoom",
")",
";",
"}",
"if",
"(",
"this",
".",
"viewer",
")",
"{",
"/**\n * Raised when the viewport zoom level changes (see {@link OpenSeadragon.Viewport#zoomBy} and {@link OpenSeadragon.Viewport#zoomTo}).\n *\n * @event zoom\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.\n * @property {Number} zoom\n * @property {OpenSeadragon.Point} refPoint\n * @property {Boolean} immediately\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"viewer",
".",
"raiseEvent",
"(",
"'zoom'",
",",
"{",
"zoom",
":",
"zoom",
",",
"refPoint",
":",
"refPoint",
",",
"immediately",
":",
"immediately",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Zooms to the specified zoom level
@function
@param {Number} zoom The zoom level to zoom to.
@param {OpenSeadragon.Point} [refPoint] The point which will stay at
the same screen location. Defaults to the viewport center.
@param {Boolean} [immediately=false]
@return {OpenSeadragon.Viewport} Chainable.
@fires OpenSeadragon.Viewer.event:zoom
|
[
"Zooms",
"to",
"the",
"specified",
"zoom",
"level"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L835-L873
|
|
10,860
|
openseadragon/openseadragon
|
src/viewport.js
|
function(degrees) {
if (!this.viewer || !this.viewer.drawer.canRotate()) {
return this;
}
this.degrees = $.positiveModulo(degrees, 360);
this._setContentBounds(
this.viewer.world.getHomeBounds(),
this.viewer.world.getContentFactor());
this.viewer.forceRedraw();
/**
* Raised when rotation has been changed.
*
* @event rotate
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Number} degrees - The number of degrees the rotation was set to.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('rotate', {"degrees": degrees});
return this;
}
|
javascript
|
function(degrees) {
if (!this.viewer || !this.viewer.drawer.canRotate()) {
return this;
}
this.degrees = $.positiveModulo(degrees, 360);
this._setContentBounds(
this.viewer.world.getHomeBounds(),
this.viewer.world.getContentFactor());
this.viewer.forceRedraw();
/**
* Raised when rotation has been changed.
*
* @event rotate
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Number} degrees - The number of degrees the rotation was set to.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('rotate', {"degrees": degrees});
return this;
}
|
[
"function",
"(",
"degrees",
")",
"{",
"if",
"(",
"!",
"this",
".",
"viewer",
"||",
"!",
"this",
".",
"viewer",
".",
"drawer",
".",
"canRotate",
"(",
")",
")",
"{",
"return",
"this",
";",
"}",
"this",
".",
"degrees",
"=",
"$",
".",
"positiveModulo",
"(",
"degrees",
",",
"360",
")",
";",
"this",
".",
"_setContentBounds",
"(",
"this",
".",
"viewer",
".",
"world",
".",
"getHomeBounds",
"(",
")",
",",
"this",
".",
"viewer",
".",
"world",
".",
"getContentFactor",
"(",
")",
")",
";",
"this",
".",
"viewer",
".",
"forceRedraw",
"(",
")",
";",
"/**\n * Raised when rotation has been changed.\n *\n * @event rotate\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {Number} degrees - The number of degrees the rotation was set to.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"viewer",
".",
"raiseEvent",
"(",
"'rotate'",
",",
"{",
"\"degrees\"",
":",
"degrees",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Rotates this viewport to the angle specified.
@function
@return {OpenSeadragon.Viewport} Chainable.
|
[
"Rotates",
"this",
"viewport",
"to",
"the",
"angle",
"specified",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L880-L902
|
|
10,861
|
openseadragon/openseadragon
|
src/viewport.js
|
function(pixel, current) {
var bounds = this.getBoundsNoRotate(current);
return pixel.minus(
new $.Point(this._margins.left, this._margins.top)
).divide(
this._containerInnerSize.x / bounds.width
).plus(
bounds.getTopLeft()
);
}
|
javascript
|
function(pixel, current) {
var bounds = this.getBoundsNoRotate(current);
return pixel.minus(
new $.Point(this._margins.left, this._margins.top)
).divide(
this._containerInnerSize.x / bounds.width
).plus(
bounds.getTopLeft()
);
}
|
[
"function",
"(",
"pixel",
",",
"current",
")",
"{",
"var",
"bounds",
"=",
"this",
".",
"getBoundsNoRotate",
"(",
"current",
")",
";",
"return",
"pixel",
".",
"minus",
"(",
"new",
"$",
".",
"Point",
"(",
"this",
".",
"_margins",
".",
"left",
",",
"this",
".",
"_margins",
".",
"top",
")",
")",
".",
"divide",
"(",
"this",
".",
"_containerInnerSize",
".",
"x",
"/",
"bounds",
".",
"width",
")",
".",
"plus",
"(",
"bounds",
".",
"getTopLeft",
"(",
")",
")",
";",
"}"
] |
Convert pixel coordinates to viewport coordinates.
This method does not take rotation into account.
Consider using pointFromPixel if you need to account for rotation.
@param {OpenSeadragon.Point} pixel Pixel coordinates
@param {Boolean} [current=false] - Pass true for the current location;
defaults to false (target location).
@returns {OpenSeadragon.Point}
|
[
"Convert",
"pixel",
"coordinates",
"to",
"viewport",
"coordinates",
".",
"This",
"method",
"does",
"not",
"take",
"rotation",
"into",
"account",
".",
"Consider",
"using",
"pointFromPixel",
"if",
"you",
"need",
"to",
"account",
"for",
"rotation",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L1119-L1128
|
|
10,862
|
openseadragon/openseadragon
|
src/viewport.js
|
function(rectangle) {
return $.Rect.fromSummits(
this.pointFromPixel(rectangle.getTopLeft(), true),
this.pointFromPixel(rectangle.getTopRight(), true),
this.pointFromPixel(rectangle.getBottomLeft(), true)
);
}
|
javascript
|
function(rectangle) {
return $.Rect.fromSummits(
this.pointFromPixel(rectangle.getTopLeft(), true),
this.pointFromPixel(rectangle.getTopRight(), true),
this.pointFromPixel(rectangle.getBottomLeft(), true)
);
}
|
[
"function",
"(",
"rectangle",
")",
"{",
"return",
"$",
".",
"Rect",
".",
"fromSummits",
"(",
"this",
".",
"pointFromPixel",
"(",
"rectangle",
".",
"getTopLeft",
"(",
")",
",",
"true",
")",
",",
"this",
".",
"pointFromPixel",
"(",
"rectangle",
".",
"getTopRight",
"(",
")",
",",
"true",
")",
",",
"this",
".",
"pointFromPixel",
"(",
"rectangle",
".",
"getBottomLeft",
"(",
")",
",",
"true",
")",
")",
";",
"}"
] |
Convert a rectangle in pixel coordinates relative to the viewer element
to viewport coordinates.
@param {OpenSeadragon.Rect} rectangle the rectangle to convert
@returns {OpenSeadragon.Rect} the converted rectangle
|
[
"Convert",
"a",
"rectangle",
"in",
"pixel",
"coordinates",
"relative",
"to",
"the",
"viewer",
"element",
"to",
"viewport",
"coordinates",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L1407-L1413
|
|
10,863
|
openseadragon/openseadragon
|
src/viewport.js
|
function(rectangle) {
return $.Rect.fromSummits(
this.pixelFromPoint(rectangle.getTopLeft(), true),
this.pixelFromPoint(rectangle.getTopRight(), true),
this.pixelFromPoint(rectangle.getBottomLeft(), true)
);
}
|
javascript
|
function(rectangle) {
return $.Rect.fromSummits(
this.pixelFromPoint(rectangle.getTopLeft(), true),
this.pixelFromPoint(rectangle.getTopRight(), true),
this.pixelFromPoint(rectangle.getBottomLeft(), true)
);
}
|
[
"function",
"(",
"rectangle",
")",
"{",
"return",
"$",
".",
"Rect",
".",
"fromSummits",
"(",
"this",
".",
"pixelFromPoint",
"(",
"rectangle",
".",
"getTopLeft",
"(",
")",
",",
"true",
")",
",",
"this",
".",
"pixelFromPoint",
"(",
"rectangle",
".",
"getTopRight",
"(",
")",
",",
"true",
")",
",",
"this",
".",
"pixelFromPoint",
"(",
"rectangle",
".",
"getBottomLeft",
"(",
")",
",",
"true",
")",
")",
";",
"}"
] |
Convert a rectangle in viewport coordinates to pixel coordinates relative
to the viewer element.
@param {OpenSeadragon.Rect} rectangle the rectangle to convert
@returns {OpenSeadragon.Rect} the converted rectangle
|
[
"Convert",
"a",
"rectangle",
"in",
"viewport",
"coordinates",
"to",
"pixel",
"coordinates",
"relative",
"to",
"the",
"viewer",
"element",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L1421-L1427
|
|
10,864
|
openseadragon/openseadragon
|
src/viewport.js
|
function(point) {
$.console.assert(this.viewer,
"[Viewport.viewportToWindowCoordinates] the viewport must have a viewer.");
var viewerCoordinates = this.viewportToViewerElementCoordinates(point);
return viewerCoordinates.plus(
$.getElementPosition(this.viewer.element));
}
|
javascript
|
function(point) {
$.console.assert(this.viewer,
"[Viewport.viewportToWindowCoordinates] the viewport must have a viewer.");
var viewerCoordinates = this.viewportToViewerElementCoordinates(point);
return viewerCoordinates.plus(
$.getElementPosition(this.viewer.element));
}
|
[
"function",
"(",
"point",
")",
"{",
"$",
".",
"console",
".",
"assert",
"(",
"this",
".",
"viewer",
",",
"\"[Viewport.viewportToWindowCoordinates] the viewport must have a viewer.\"",
")",
";",
"var",
"viewerCoordinates",
"=",
"this",
".",
"viewportToViewerElementCoordinates",
"(",
"point",
")",
";",
"return",
"viewerCoordinates",
".",
"plus",
"(",
"$",
".",
"getElementPosition",
"(",
"this",
".",
"viewer",
".",
"element",
")",
")",
";",
"}"
] |
Convert viewport coordinates to pixel coordinates relative to the window.
@param {OpenSeadragon.Point} point
@returns {OpenSeadragon.Point}
|
[
"Convert",
"viewport",
"coordinates",
"to",
"pixel",
"coordinates",
"relative",
"to",
"the",
"window",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L1447-L1453
|
|
10,865
|
openseadragon/openseadragon
|
src/viewport.js
|
function( state ) {
if ( this.flipped === state ) {
return this;
}
this.flipped = state;
if(this.viewer.navigator){
this.viewer.navigator.setFlip(this.getFlip());
}
this.viewer.forceRedraw();
/**
* Raised when flip state has been changed.
*
* @event flip
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Number} flipped - The flip state after this change.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('flip', {"flipped": state});
return this;
}
|
javascript
|
function( state ) {
if ( this.flipped === state ) {
return this;
}
this.flipped = state;
if(this.viewer.navigator){
this.viewer.navigator.setFlip(this.getFlip());
}
this.viewer.forceRedraw();
/**
* Raised when flip state has been changed.
*
* @event flip
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {Number} flipped - The flip state after this change.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent('flip', {"flipped": state});
return this;
}
|
[
"function",
"(",
"state",
")",
"{",
"if",
"(",
"this",
".",
"flipped",
"===",
"state",
")",
"{",
"return",
"this",
";",
"}",
"this",
".",
"flipped",
"=",
"state",
";",
"if",
"(",
"this",
".",
"viewer",
".",
"navigator",
")",
"{",
"this",
".",
"viewer",
".",
"navigator",
".",
"setFlip",
"(",
"this",
".",
"getFlip",
"(",
")",
")",
";",
"}",
"this",
".",
"viewer",
".",
"forceRedraw",
"(",
")",
";",
"/**\n * Raised when flip state has been changed.\n *\n * @event flip\n * @memberof OpenSeadragon.Viewer\n * @type {object}\n * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.\n * @property {Number} flipped - The flip state after this change.\n * @property {?Object} userData - Arbitrary subscriber-defined object.\n */",
"this",
".",
"viewer",
".",
"raiseEvent",
"(",
"'flip'",
",",
"{",
"\"flipped\"",
":",
"state",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Sets flip state according to the state input argument.
@function
@param {Boolean} state - Flip state to set.
@return {OpenSeadragon.Viewport} Chainable.
|
[
"Sets",
"flip",
"state",
"according",
"to",
"the",
"state",
"input",
"argument",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/viewport.js#L1548-L1571
|
|
10,866
|
openseadragon/openseadragon
|
src/imagetilesource.js
|
function (level, x, y) {
var url = null;
if (level >= this.minLevel && level <= this.maxLevel) {
url = this.levels[level].url;
}
return url;
}
|
javascript
|
function (level, x, y) {
var url = null;
if (level >= this.minLevel && level <= this.maxLevel) {
url = this.levels[level].url;
}
return url;
}
|
[
"function",
"(",
"level",
",",
"x",
",",
"y",
")",
"{",
"var",
"url",
"=",
"null",
";",
"if",
"(",
"level",
">=",
"this",
".",
"minLevel",
"&&",
"level",
"<=",
"this",
".",
"maxLevel",
")",
"{",
"url",
"=",
"this",
".",
"levels",
"[",
"level",
"]",
".",
"url",
";",
"}",
"return",
"url",
";",
"}"
] |
Retrieves a tile url
@function
@param {Number} level Level of the tile
@param {Number} x x coordinate of the tile
@param {Number} y y coordinate of the tile
|
[
"Retrieves",
"a",
"tile",
"url"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imagetilesource.js#L177-L183
|
|
10,867
|
openseadragon/openseadragon
|
src/imagetilesource.js
|
function (level, x, y) {
var context = null;
if (level >= this.minLevel && level <= this.maxLevel) {
context = this.levels[level].context2D;
}
return context;
}
|
javascript
|
function (level, x, y) {
var context = null;
if (level >= this.minLevel && level <= this.maxLevel) {
context = this.levels[level].context2D;
}
return context;
}
|
[
"function",
"(",
"level",
",",
"x",
",",
"y",
")",
"{",
"var",
"context",
"=",
"null",
";",
"if",
"(",
"level",
">=",
"this",
".",
"minLevel",
"&&",
"level",
"<=",
"this",
".",
"maxLevel",
")",
"{",
"context",
"=",
"this",
".",
"levels",
"[",
"level",
"]",
".",
"context2D",
";",
"}",
"return",
"context",
";",
"}"
] |
Retrieves a tile context 2D
@function
@param {Number} level Level of the tile
@param {Number} x x coordinate of the tile
@param {Number} y y coordinate of the tile
|
[
"Retrieves",
"a",
"tile",
"context",
"2D"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imagetilesource.js#L191-L197
|
|
10,868
|
openseadragon/openseadragon
|
src/imageloader.js
|
function(){
var self = this;
var selfAbort = this.abort;
this.image = new Image();
this.image.onload = function(){
self.finish(true);
};
this.image.onabort = this.image.onerror = function() {
self.errorMsg = "Image load aborted";
self.finish(false);
};
this.jobId = window.setTimeout(function(){
self.errorMsg = "Image load exceeded timeout (" + self.timeout + " ms)";
self.finish(false);
}, this.timeout);
// Load the tile with an AJAX request if the loadWithAjax option is
// set. Otherwise load the image by setting the source proprety of the image object.
if (this.loadWithAjax) {
this.request = $.makeAjaxRequest({
url: this.src,
withCredentials: this.ajaxWithCredentials,
headers: this.ajaxHeaders,
responseType: "arraybuffer",
success: function(request) {
var blb;
// Make the raw data into a blob.
// BlobBuilder fallback adapted from
// http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
try {
blb = new window.Blob([request.response]);
} catch (e) {
var BlobBuilder = (
window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder
);
if (e.name === 'TypeError' && BlobBuilder) {
var bb = new BlobBuilder();
bb.append(request.response);
blb = bb.getBlob();
}
}
// If the blob is empty for some reason consider the image load a failure.
if (blb.size === 0) {
self.errorMsg = "Empty image response.";
self.finish(false);
}
// Create a URL for the blob data and make it the source of the image object.
// This will still trigger Image.onload to indicate a successful tile load.
var url = (window.URL || window.webkitURL).createObjectURL(blb);
self.image.src = url;
},
error: function(request) {
self.errorMsg = "Image load aborted - XHR error";
self.finish(false);
}
});
// Provide a function to properly abort the request.
this.abort = function() {
self.request.abort();
// Call the existing abort function if available
if (typeof selfAbort === "function") {
selfAbort();
}
};
} else {
if (this.crossOriginPolicy !== false) {
this.image.crossOrigin = this.crossOriginPolicy;
}
this.image.src = this.src;
}
}
|
javascript
|
function(){
var self = this;
var selfAbort = this.abort;
this.image = new Image();
this.image.onload = function(){
self.finish(true);
};
this.image.onabort = this.image.onerror = function() {
self.errorMsg = "Image load aborted";
self.finish(false);
};
this.jobId = window.setTimeout(function(){
self.errorMsg = "Image load exceeded timeout (" + self.timeout + " ms)";
self.finish(false);
}, this.timeout);
// Load the tile with an AJAX request if the loadWithAjax option is
// set. Otherwise load the image by setting the source proprety of the image object.
if (this.loadWithAjax) {
this.request = $.makeAjaxRequest({
url: this.src,
withCredentials: this.ajaxWithCredentials,
headers: this.ajaxHeaders,
responseType: "arraybuffer",
success: function(request) {
var blb;
// Make the raw data into a blob.
// BlobBuilder fallback adapted from
// http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility
try {
blb = new window.Blob([request.response]);
} catch (e) {
var BlobBuilder = (
window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder
);
if (e.name === 'TypeError' && BlobBuilder) {
var bb = new BlobBuilder();
bb.append(request.response);
blb = bb.getBlob();
}
}
// If the blob is empty for some reason consider the image load a failure.
if (blb.size === 0) {
self.errorMsg = "Empty image response.";
self.finish(false);
}
// Create a URL for the blob data and make it the source of the image object.
// This will still trigger Image.onload to indicate a successful tile load.
var url = (window.URL || window.webkitURL).createObjectURL(blb);
self.image.src = url;
},
error: function(request) {
self.errorMsg = "Image load aborted - XHR error";
self.finish(false);
}
});
// Provide a function to properly abort the request.
this.abort = function() {
self.request.abort();
// Call the existing abort function if available
if (typeof selfAbort === "function") {
selfAbort();
}
};
} else {
if (this.crossOriginPolicy !== false) {
this.image.crossOrigin = this.crossOriginPolicy;
}
this.image.src = this.src;
}
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"selfAbort",
"=",
"this",
".",
"abort",
";",
"this",
".",
"image",
"=",
"new",
"Image",
"(",
")",
";",
"this",
".",
"image",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"self",
".",
"finish",
"(",
"true",
")",
";",
"}",
";",
"this",
".",
"image",
".",
"onabort",
"=",
"this",
".",
"image",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"self",
".",
"errorMsg",
"=",
"\"Image load aborted\"",
";",
"self",
".",
"finish",
"(",
"false",
")",
";",
"}",
";",
"this",
".",
"jobId",
"=",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"errorMsg",
"=",
"\"Image load exceeded timeout (\"",
"+",
"self",
".",
"timeout",
"+",
"\" ms)\"",
";",
"self",
".",
"finish",
"(",
"false",
")",
";",
"}",
",",
"this",
".",
"timeout",
")",
";",
"// Load the tile with an AJAX request if the loadWithAjax option is",
"// set. Otherwise load the image by setting the source proprety of the image object.",
"if",
"(",
"this",
".",
"loadWithAjax",
")",
"{",
"this",
".",
"request",
"=",
"$",
".",
"makeAjaxRequest",
"(",
"{",
"url",
":",
"this",
".",
"src",
",",
"withCredentials",
":",
"this",
".",
"ajaxWithCredentials",
",",
"headers",
":",
"this",
".",
"ajaxHeaders",
",",
"responseType",
":",
"\"arraybuffer\"",
",",
"success",
":",
"function",
"(",
"request",
")",
"{",
"var",
"blb",
";",
"// Make the raw data into a blob.",
"// BlobBuilder fallback adapted from",
"// http://stackoverflow.com/questions/15293694/blob-constructor-browser-compatibility",
"try",
"{",
"blb",
"=",
"new",
"window",
".",
"Blob",
"(",
"[",
"request",
".",
"response",
"]",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"BlobBuilder",
"=",
"(",
"window",
".",
"BlobBuilder",
"||",
"window",
".",
"WebKitBlobBuilder",
"||",
"window",
".",
"MozBlobBuilder",
"||",
"window",
".",
"MSBlobBuilder",
")",
";",
"if",
"(",
"e",
".",
"name",
"===",
"'TypeError'",
"&&",
"BlobBuilder",
")",
"{",
"var",
"bb",
"=",
"new",
"BlobBuilder",
"(",
")",
";",
"bb",
".",
"append",
"(",
"request",
".",
"response",
")",
";",
"blb",
"=",
"bb",
".",
"getBlob",
"(",
")",
";",
"}",
"}",
"// If the blob is empty for some reason consider the image load a failure.",
"if",
"(",
"blb",
".",
"size",
"===",
"0",
")",
"{",
"self",
".",
"errorMsg",
"=",
"\"Empty image response.\"",
";",
"self",
".",
"finish",
"(",
"false",
")",
";",
"}",
"// Create a URL for the blob data and make it the source of the image object.",
"// This will still trigger Image.onload to indicate a successful tile load.",
"var",
"url",
"=",
"(",
"window",
".",
"URL",
"||",
"window",
".",
"webkitURL",
")",
".",
"createObjectURL",
"(",
"blb",
")",
";",
"self",
".",
"image",
".",
"src",
"=",
"url",
";",
"}",
",",
"error",
":",
"function",
"(",
"request",
")",
"{",
"self",
".",
"errorMsg",
"=",
"\"Image load aborted - XHR error\"",
";",
"self",
".",
"finish",
"(",
"false",
")",
";",
"}",
"}",
")",
";",
"// Provide a function to properly abort the request.",
"this",
".",
"abort",
"=",
"function",
"(",
")",
"{",
"self",
".",
"request",
".",
"abort",
"(",
")",
";",
"// Call the existing abort function if available",
"if",
"(",
"typeof",
"selfAbort",
"===",
"\"function\"",
")",
"{",
"selfAbort",
"(",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"crossOriginPolicy",
"!==",
"false",
")",
"{",
"this",
".",
"image",
".",
"crossOrigin",
"=",
"this",
".",
"crossOriginPolicy",
";",
"}",
"this",
".",
"image",
".",
"src",
"=",
"this",
".",
"src",
";",
"}",
"}"
] |
Starts the image job.
@method
|
[
"Starts",
"the",
"image",
"job",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imageloader.js#L72-L151
|
|
10,869
|
openseadragon/openseadragon
|
src/imageloader.js
|
function(options) {
var _this = this,
complete = function(job) {
completeJob(_this, job, options.callback);
},
jobOptions = {
src: options.src,
loadWithAjax: options.loadWithAjax,
ajaxHeaders: options.loadWithAjax ? options.ajaxHeaders : null,
crossOriginPolicy: options.crossOriginPolicy,
ajaxWithCredentials: options.ajaxWithCredentials,
callback: complete,
abort: options.abort,
timeout: this.timeout
},
newJob = new ImageJob(jobOptions);
if ( !this.jobLimit || this.jobsInProgress < this.jobLimit ) {
newJob.start();
this.jobsInProgress++;
}
else {
this.jobQueue.push( newJob );
}
}
|
javascript
|
function(options) {
var _this = this,
complete = function(job) {
completeJob(_this, job, options.callback);
},
jobOptions = {
src: options.src,
loadWithAjax: options.loadWithAjax,
ajaxHeaders: options.loadWithAjax ? options.ajaxHeaders : null,
crossOriginPolicy: options.crossOriginPolicy,
ajaxWithCredentials: options.ajaxWithCredentials,
callback: complete,
abort: options.abort,
timeout: this.timeout
},
newJob = new ImageJob(jobOptions);
if ( !this.jobLimit || this.jobsInProgress < this.jobLimit ) {
newJob.start();
this.jobsInProgress++;
}
else {
this.jobQueue.push( newJob );
}
}
|
[
"function",
"(",
"options",
")",
"{",
"var",
"_this",
"=",
"this",
",",
"complete",
"=",
"function",
"(",
"job",
")",
"{",
"completeJob",
"(",
"_this",
",",
"job",
",",
"options",
".",
"callback",
")",
";",
"}",
",",
"jobOptions",
"=",
"{",
"src",
":",
"options",
".",
"src",
",",
"loadWithAjax",
":",
"options",
".",
"loadWithAjax",
",",
"ajaxHeaders",
":",
"options",
".",
"loadWithAjax",
"?",
"options",
".",
"ajaxHeaders",
":",
"null",
",",
"crossOriginPolicy",
":",
"options",
".",
"crossOriginPolicy",
",",
"ajaxWithCredentials",
":",
"options",
".",
"ajaxWithCredentials",
",",
"callback",
":",
"complete",
",",
"abort",
":",
"options",
".",
"abort",
",",
"timeout",
":",
"this",
".",
"timeout",
"}",
",",
"newJob",
"=",
"new",
"ImageJob",
"(",
"jobOptions",
")",
";",
"if",
"(",
"!",
"this",
".",
"jobLimit",
"||",
"this",
".",
"jobsInProgress",
"<",
"this",
".",
"jobLimit",
")",
"{",
"newJob",
".",
"start",
"(",
")",
";",
"this",
".",
"jobsInProgress",
"++",
";",
"}",
"else",
"{",
"this",
".",
"jobQueue",
".",
"push",
"(",
"newJob",
")",
";",
"}",
"}"
] |
Add an unloaded image to the loader queue.
@method
@param {Object} options - Options for this job.
@param {String} [options.src] - URL of image to download.
@param {String} [options.loadWithAjax] - Whether to load this image with AJAX.
@param {String} [options.ajaxHeaders] - Headers to add to the image request if using AJAX.
@param {String|Boolean} [options.crossOriginPolicy] - CORS policy to use for downloads
@param {Boolean} [options.ajaxWithCredentials] - Whether to set withCredentials on AJAX
requests.
@param {Function} [options.callback] - Called once image has been downloaded.
@param {Function} [options.abort] - Called when this image job is aborted.
|
[
"Add",
"an",
"unloaded",
"image",
"to",
"the",
"loader",
"queue",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imageloader.js#L204-L228
|
|
10,870
|
openseadragon/openseadragon
|
src/imageloader.js
|
function() {
for( var i = 0; i < this.jobQueue.length; i++ ) {
var job = this.jobQueue[i];
if ( typeof job.abort === "function" ) {
job.abort();
}
}
this.jobQueue = [];
}
|
javascript
|
function() {
for( var i = 0; i < this.jobQueue.length; i++ ) {
var job = this.jobQueue[i];
if ( typeof job.abort === "function" ) {
job.abort();
}
}
this.jobQueue = [];
}
|
[
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"jobQueue",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"job",
"=",
"this",
".",
"jobQueue",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"job",
".",
"abort",
"===",
"\"function\"",
")",
"{",
"job",
".",
"abort",
"(",
")",
";",
"}",
"}",
"this",
".",
"jobQueue",
"=",
"[",
"]",
";",
"}"
] |
Clear any unstarted image loading jobs from the queue.
@method
|
[
"Clear",
"any",
"unstarted",
"image",
"loading",
"jobs",
"from",
"the",
"queue",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imageloader.js#L234-L243
|
|
10,871
|
openseadragon/openseadragon
|
src/imageloader.js
|
completeJob
|
function completeJob(loader, job, callback) {
var nextJob;
loader.jobsInProgress--;
if ((!loader.jobLimit || loader.jobsInProgress < loader.jobLimit) && loader.jobQueue.length > 0) {
nextJob = loader.jobQueue.shift();
nextJob.start();
loader.jobsInProgress++;
}
callback(job.image, job.errorMsg, job.request);
}
|
javascript
|
function completeJob(loader, job, callback) {
var nextJob;
loader.jobsInProgress--;
if ((!loader.jobLimit || loader.jobsInProgress < loader.jobLimit) && loader.jobQueue.length > 0) {
nextJob = loader.jobQueue.shift();
nextJob.start();
loader.jobsInProgress++;
}
callback(job.image, job.errorMsg, job.request);
}
|
[
"function",
"completeJob",
"(",
"loader",
",",
"job",
",",
"callback",
")",
"{",
"var",
"nextJob",
";",
"loader",
".",
"jobsInProgress",
"--",
";",
"if",
"(",
"(",
"!",
"loader",
".",
"jobLimit",
"||",
"loader",
".",
"jobsInProgress",
"<",
"loader",
".",
"jobLimit",
")",
"&&",
"loader",
".",
"jobQueue",
".",
"length",
">",
"0",
")",
"{",
"nextJob",
"=",
"loader",
".",
"jobQueue",
".",
"shift",
"(",
")",
";",
"nextJob",
".",
"start",
"(",
")",
";",
"loader",
".",
"jobsInProgress",
"++",
";",
"}",
"callback",
"(",
"job",
".",
"image",
",",
"job",
".",
"errorMsg",
",",
"job",
".",
"request",
")",
";",
"}"
] |
Cleans up ImageJob once completed.
@method
@private
@param loader - ImageLoader used to start job.
@param job - The ImageJob that has completed.
@param callback - Called once cleanup is finished.
|
[
"Cleans",
"up",
"ImageJob",
"once",
"completed",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/imageloader.js#L254-L266
|
10,872
|
openseadragon/openseadragon
|
src/iiiftilesource.js
|
function( level ) {
if(this.emulateLegacyImagePyramid) {
return $.TileSource.prototype.getTileWidth.call(this, level);
}
var scaleFactor = Math.pow(2, this.maxLevel - level);
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
return this.tileSizePerScaleFactor[scaleFactor].width;
}
return this._tileWidth;
}
|
javascript
|
function( level ) {
if(this.emulateLegacyImagePyramid) {
return $.TileSource.prototype.getTileWidth.call(this, level);
}
var scaleFactor = Math.pow(2, this.maxLevel - level);
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
return this.tileSizePerScaleFactor[scaleFactor].width;
}
return this._tileWidth;
}
|
[
"function",
"(",
"level",
")",
"{",
"if",
"(",
"this",
".",
"emulateLegacyImagePyramid",
")",
"{",
"return",
"$",
".",
"TileSource",
".",
"prototype",
".",
"getTileWidth",
".",
"call",
"(",
"this",
",",
"level",
")",
";",
"}",
"var",
"scaleFactor",
"=",
"Math",
".",
"pow",
"(",
"2",
",",
"this",
".",
"maxLevel",
"-",
"level",
")",
";",
"if",
"(",
"this",
".",
"tileSizePerScaleFactor",
"&&",
"this",
".",
"tileSizePerScaleFactor",
"[",
"scaleFactor",
"]",
")",
"{",
"return",
"this",
".",
"tileSizePerScaleFactor",
"[",
"scaleFactor",
"]",
".",
"width",
";",
"}",
"return",
"this",
".",
"_tileWidth",
";",
"}"
] |
Return the tileWidth for the given level.
@function
@param {Number} level
|
[
"Return",
"the",
"tileWidth",
"for",
"the",
"given",
"level",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/iiiftilesource.js#L219-L231
|
|
10,873
|
openseadragon/openseadragon
|
src/iiiftilesource.js
|
function( level ) {
if(this.emulateLegacyImagePyramid) {
return $.TileSource.prototype.getTileHeight.call(this, level);
}
var scaleFactor = Math.pow(2, this.maxLevel - level);
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
return this.tileSizePerScaleFactor[scaleFactor].height;
}
return this._tileHeight;
}
|
javascript
|
function( level ) {
if(this.emulateLegacyImagePyramid) {
return $.TileSource.prototype.getTileHeight.call(this, level);
}
var scaleFactor = Math.pow(2, this.maxLevel - level);
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
return this.tileSizePerScaleFactor[scaleFactor].height;
}
return this._tileHeight;
}
|
[
"function",
"(",
"level",
")",
"{",
"if",
"(",
"this",
".",
"emulateLegacyImagePyramid",
")",
"{",
"return",
"$",
".",
"TileSource",
".",
"prototype",
".",
"getTileHeight",
".",
"call",
"(",
"this",
",",
"level",
")",
";",
"}",
"var",
"scaleFactor",
"=",
"Math",
".",
"pow",
"(",
"2",
",",
"this",
".",
"maxLevel",
"-",
"level",
")",
";",
"if",
"(",
"this",
".",
"tileSizePerScaleFactor",
"&&",
"this",
".",
"tileSizePerScaleFactor",
"[",
"scaleFactor",
"]",
")",
"{",
"return",
"this",
".",
"tileSizePerScaleFactor",
"[",
"scaleFactor",
"]",
".",
"height",
";",
"}",
"return",
"this",
".",
"_tileHeight",
";",
"}"
] |
Return the tileHeight for the given level.
@function
@param {Number} level
|
[
"Return",
"the",
"tileHeight",
"for",
"the",
"given",
"level",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/iiiftilesource.js#L238-L250
|
|
10,874
|
openseadragon/openseadragon
|
src/iiiftilesource.js
|
function( level, x, y ){
if(this.emulateLegacyImagePyramid) {
var url = null;
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
url = this.levels[ level ].url;
}
return url;
}
//# constants
var IIIF_ROTATION = '0',
//## get the scale (level as a decimal)
scale = Math.pow( 0.5, this.maxLevel - level ),
//# image dimensions at this level
levelWidth = Math.ceil( this.width * scale ),
levelHeight = Math.ceil( this.height * scale ),
//## iiif region
tileWidth,
tileHeight,
iiifTileSizeWidth,
iiifTileSizeHeight,
iiifRegion,
iiifTileX,
iiifTileY,
iiifTileW,
iiifTileH,
iiifSize,
iiifSizeW,
iiifQuality,
uri,
isv1;
tileWidth = this.getTileWidth(level);
tileHeight = this.getTileHeight(level);
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
isv1 = ( this['@context'].indexOf('/1.0/context.json') > -1 ||
this['@context'].indexOf('/1.1/context.json') > -1 ||
this['@context'].indexOf('/1/context.json') > -1 );
if (isv1) {
iiifQuality = "native." + this.tileFormat;
} else {
iiifQuality = "default." + this.tileFormat;
}
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
if ( isv1 || levelWidth !== this.width ) {
iiifSize = levelWidth + ",";
} else {
iiifSize = "max";
}
iiifRegion = 'full';
} else {
iiifTileX = x * iiifTileSizeWidth;
iiifTileY = y * iiifTileSizeHeight;
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) {
iiifRegion = "full";
} else {
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
}
iiifSizeW = Math.ceil( iiifTileW * scale );
if ( (!isv1) && iiifSizeW === this.width ) {
iiifSize = "max";
} else {
iiifSize = iiifSizeW + ",";
}
}
uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
return uri;
}
|
javascript
|
function( level, x, y ){
if(this.emulateLegacyImagePyramid) {
var url = null;
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
url = this.levels[ level ].url;
}
return url;
}
//# constants
var IIIF_ROTATION = '0',
//## get the scale (level as a decimal)
scale = Math.pow( 0.5, this.maxLevel - level ),
//# image dimensions at this level
levelWidth = Math.ceil( this.width * scale ),
levelHeight = Math.ceil( this.height * scale ),
//## iiif region
tileWidth,
tileHeight,
iiifTileSizeWidth,
iiifTileSizeHeight,
iiifRegion,
iiifTileX,
iiifTileY,
iiifTileW,
iiifTileH,
iiifSize,
iiifSizeW,
iiifQuality,
uri,
isv1;
tileWidth = this.getTileWidth(level);
tileHeight = this.getTileHeight(level);
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
isv1 = ( this['@context'].indexOf('/1.0/context.json') > -1 ||
this['@context'].indexOf('/1.1/context.json') > -1 ||
this['@context'].indexOf('/1/context.json') > -1 );
if (isv1) {
iiifQuality = "native." + this.tileFormat;
} else {
iiifQuality = "default." + this.tileFormat;
}
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
if ( isv1 || levelWidth !== this.width ) {
iiifSize = levelWidth + ",";
} else {
iiifSize = "max";
}
iiifRegion = 'full';
} else {
iiifTileX = x * iiifTileSizeWidth;
iiifTileY = y * iiifTileSizeHeight;
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) {
iiifRegion = "full";
} else {
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
}
iiifSizeW = Math.ceil( iiifTileW * scale );
if ( (!isv1) && iiifSizeW === this.width ) {
iiifSize = "max";
} else {
iiifSize = iiifSizeW + ",";
}
}
uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
return uri;
}
|
[
"function",
"(",
"level",
",",
"x",
",",
"y",
")",
"{",
"if",
"(",
"this",
".",
"emulateLegacyImagePyramid",
")",
"{",
"var",
"url",
"=",
"null",
";",
"if",
"(",
"this",
".",
"levels",
".",
"length",
">",
"0",
"&&",
"level",
">=",
"this",
".",
"minLevel",
"&&",
"level",
"<=",
"this",
".",
"maxLevel",
")",
"{",
"url",
"=",
"this",
".",
"levels",
"[",
"level",
"]",
".",
"url",
";",
"}",
"return",
"url",
";",
"}",
"//# constants",
"var",
"IIIF_ROTATION",
"=",
"'0'",
",",
"//## get the scale (level as a decimal)",
"scale",
"=",
"Math",
".",
"pow",
"(",
"0.5",
",",
"this",
".",
"maxLevel",
"-",
"level",
")",
",",
"//# image dimensions at this level",
"levelWidth",
"=",
"Math",
".",
"ceil",
"(",
"this",
".",
"width",
"*",
"scale",
")",
",",
"levelHeight",
"=",
"Math",
".",
"ceil",
"(",
"this",
".",
"height",
"*",
"scale",
")",
",",
"//## iiif region",
"tileWidth",
",",
"tileHeight",
",",
"iiifTileSizeWidth",
",",
"iiifTileSizeHeight",
",",
"iiifRegion",
",",
"iiifTileX",
",",
"iiifTileY",
",",
"iiifTileW",
",",
"iiifTileH",
",",
"iiifSize",
",",
"iiifSizeW",
",",
"iiifQuality",
",",
"uri",
",",
"isv1",
";",
"tileWidth",
"=",
"this",
".",
"getTileWidth",
"(",
"level",
")",
";",
"tileHeight",
"=",
"this",
".",
"getTileHeight",
"(",
"level",
")",
";",
"iiifTileSizeWidth",
"=",
"Math",
".",
"ceil",
"(",
"tileWidth",
"/",
"scale",
")",
";",
"iiifTileSizeHeight",
"=",
"Math",
".",
"ceil",
"(",
"tileHeight",
"/",
"scale",
")",
";",
"isv1",
"=",
"(",
"this",
"[",
"'@context'",
"]",
".",
"indexOf",
"(",
"'/1.0/context.json'",
")",
">",
"-",
"1",
"||",
"this",
"[",
"'@context'",
"]",
".",
"indexOf",
"(",
"'/1.1/context.json'",
")",
">",
"-",
"1",
"||",
"this",
"[",
"'@context'",
"]",
".",
"indexOf",
"(",
"'/1/context.json'",
")",
">",
"-",
"1",
")",
";",
"if",
"(",
"isv1",
")",
"{",
"iiifQuality",
"=",
"\"native.\"",
"+",
"this",
".",
"tileFormat",
";",
"}",
"else",
"{",
"iiifQuality",
"=",
"\"default.\"",
"+",
"this",
".",
"tileFormat",
";",
"}",
"if",
"(",
"levelWidth",
"<",
"tileWidth",
"&&",
"levelHeight",
"<",
"tileHeight",
")",
"{",
"if",
"(",
"isv1",
"||",
"levelWidth",
"!==",
"this",
".",
"width",
")",
"{",
"iiifSize",
"=",
"levelWidth",
"+",
"\",\"",
";",
"}",
"else",
"{",
"iiifSize",
"=",
"\"max\"",
";",
"}",
"iiifRegion",
"=",
"'full'",
";",
"}",
"else",
"{",
"iiifTileX",
"=",
"x",
"*",
"iiifTileSizeWidth",
";",
"iiifTileY",
"=",
"y",
"*",
"iiifTileSizeHeight",
";",
"iiifTileW",
"=",
"Math",
".",
"min",
"(",
"iiifTileSizeWidth",
",",
"this",
".",
"width",
"-",
"iiifTileX",
")",
";",
"iiifTileH",
"=",
"Math",
".",
"min",
"(",
"iiifTileSizeHeight",
",",
"this",
".",
"height",
"-",
"iiifTileY",
")",
";",
"if",
"(",
"x",
"===",
"0",
"&&",
"y",
"===",
"0",
"&&",
"iiifTileW",
"===",
"this",
".",
"width",
"&&",
"iiifTileH",
"===",
"this",
".",
"height",
")",
"{",
"iiifRegion",
"=",
"\"full\"",
";",
"}",
"else",
"{",
"iiifRegion",
"=",
"[",
"iiifTileX",
",",
"iiifTileY",
",",
"iiifTileW",
",",
"iiifTileH",
"]",
".",
"join",
"(",
"','",
")",
";",
"}",
"iiifSizeW",
"=",
"Math",
".",
"ceil",
"(",
"iiifTileW",
"*",
"scale",
")",
";",
"if",
"(",
"(",
"!",
"isv1",
")",
"&&",
"iiifSizeW",
"===",
"this",
".",
"width",
")",
"{",
"iiifSize",
"=",
"\"max\"",
";",
"}",
"else",
"{",
"iiifSize",
"=",
"iiifSizeW",
"+",
"\",\"",
";",
"}",
"}",
"uri",
"=",
"[",
"this",
"[",
"'@id'",
"]",
",",
"iiifRegion",
",",
"iiifSize",
",",
"IIIF_ROTATION",
",",
"iiifQuality",
"]",
".",
"join",
"(",
"'/'",
")",
";",
"return",
"uri",
";",
"}"
] |
Responsible for retrieving the url which will return an image for the
region specified by the given x, y, and level components.
@function
@param {Number} level - z index
@param {Number} x
@param {Number} y
@throws {Error}
|
[
"Responsible",
"for",
"retrieving",
"the",
"url",
"which",
"will",
"return",
"an",
"image",
"for",
"the",
"region",
"specified",
"by",
"the",
"given",
"x",
"y",
"and",
"level",
"components",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/iiiftilesource.js#L314-L388
|
|
10,875
|
openseadragon/openseadragon
|
src/iiiftilesource.js
|
canBeTiled
|
function canBeTiled ( profile ) {
var level0Profiles = [
"http://library.stanford.edu/iiif/image-api/compliance.html#level0",
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
"http://iiif.io/api/image/2/level0.json"
];
var isLevel0 = (level0Profiles.indexOf(profile[0]) !== -1);
var hasSizeByW = false;
if ( profile.length > 1 && profile[1].supports ) {
hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) !== -1;
}
return !isLevel0 || hasSizeByW;
}
|
javascript
|
function canBeTiled ( profile ) {
var level0Profiles = [
"http://library.stanford.edu/iiif/image-api/compliance.html#level0",
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
"http://iiif.io/api/image/2/level0.json"
];
var isLevel0 = (level0Profiles.indexOf(profile[0]) !== -1);
var hasSizeByW = false;
if ( profile.length > 1 && profile[1].supports ) {
hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) !== -1;
}
return !isLevel0 || hasSizeByW;
}
|
[
"function",
"canBeTiled",
"(",
"profile",
")",
"{",
"var",
"level0Profiles",
"=",
"[",
"\"http://library.stanford.edu/iiif/image-api/compliance.html#level0\"",
",",
"\"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0\"",
",",
"\"http://iiif.io/api/image/2/level0.json\"",
"]",
";",
"var",
"isLevel0",
"=",
"(",
"level0Profiles",
".",
"indexOf",
"(",
"profile",
"[",
"0",
"]",
")",
"!==",
"-",
"1",
")",
";",
"var",
"hasSizeByW",
"=",
"false",
";",
"if",
"(",
"profile",
".",
"length",
">",
"1",
"&&",
"profile",
"[",
"1",
"]",
".",
"supports",
")",
"{",
"hasSizeByW",
"=",
"profile",
"[",
"1",
"]",
".",
"supports",
".",
"indexOf",
"(",
"\"sizeByW\"",
")",
"!==",
"-",
"1",
";",
"}",
"return",
"!",
"isLevel0",
"||",
"hasSizeByW",
";",
"}"
] |
Determine whether arbitrary tile requests can be made against a service with the given profile
@function
@param {array} profile - IIIF profile array
@throws {Error}
|
[
"Determine",
"whether",
"arbitrary",
"tile",
"requests",
"can",
"be",
"made",
"against",
"a",
"service",
"with",
"the",
"given",
"profile"
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/iiiftilesource.js#L398-L410
|
10,876
|
openseadragon/openseadragon
|
src/eventsource.js
|
function ( eventName, handler, userData ) {
var events = this.events[ eventName ];
if ( !events ) {
this.events[ eventName ] = events = [];
}
if ( handler && $.isFunction( handler ) ) {
events[ events.length ] = { handler: handler, userData: userData || null };
}
}
|
javascript
|
function ( eventName, handler, userData ) {
var events = this.events[ eventName ];
if ( !events ) {
this.events[ eventName ] = events = [];
}
if ( handler && $.isFunction( handler ) ) {
events[ events.length ] = { handler: handler, userData: userData || null };
}
}
|
[
"function",
"(",
"eventName",
",",
"handler",
",",
"userData",
")",
"{",
"var",
"events",
"=",
"this",
".",
"events",
"[",
"eventName",
"]",
";",
"if",
"(",
"!",
"events",
")",
"{",
"this",
".",
"events",
"[",
"eventName",
"]",
"=",
"events",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"handler",
"&&",
"$",
".",
"isFunction",
"(",
"handler",
")",
")",
"{",
"events",
"[",
"events",
".",
"length",
"]",
"=",
"{",
"handler",
":",
"handler",
",",
"userData",
":",
"userData",
"||",
"null",
"}",
";",
"}",
"}"
] |
Add an event handler for a given event.
@function
@param {String} eventName - Name of event to register.
@param {OpenSeadragon.EventHandler} handler - Function to call when event is triggered.
@param {Object} [userData=null] - Arbitrary object to be passed unchanged to the handler.
|
[
"Add",
"an",
"event",
"handler",
"for",
"a",
"given",
"event",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/eventsource.js#L92-L100
|
|
10,877
|
openseadragon/openseadragon
|
src/eventsource.js
|
function ( eventName, handler ) {
var events = this.events[ eventName ],
handlers = [],
i;
if ( !events ) {
return;
}
if ( $.isArray( events ) ) {
for ( i = 0; i < events.length; i++ ) {
if ( events[i].handler !== handler ) {
handlers.push( events[ i ] );
}
}
this.events[ eventName ] = handlers;
}
}
|
javascript
|
function ( eventName, handler ) {
var events = this.events[ eventName ],
handlers = [],
i;
if ( !events ) {
return;
}
if ( $.isArray( events ) ) {
for ( i = 0; i < events.length; i++ ) {
if ( events[i].handler !== handler ) {
handlers.push( events[ i ] );
}
}
this.events[ eventName ] = handlers;
}
}
|
[
"function",
"(",
"eventName",
",",
"handler",
")",
"{",
"var",
"events",
"=",
"this",
".",
"events",
"[",
"eventName",
"]",
",",
"handlers",
"=",
"[",
"]",
",",
"i",
";",
"if",
"(",
"!",
"events",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
".",
"isArray",
"(",
"events",
")",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"events",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"events",
"[",
"i",
"]",
".",
"handler",
"!==",
"handler",
")",
"{",
"handlers",
".",
"push",
"(",
"events",
"[",
"i",
"]",
")",
";",
"}",
"}",
"this",
".",
"events",
"[",
"eventName",
"]",
"=",
"handlers",
";",
"}",
"}"
] |
Remove a specific event handler for a given event.
@function
@param {String} eventName - Name of event for which the handler is to be removed.
@param {OpenSeadragon.EventHandler} handler - Function to be removed.
|
[
"Remove",
"a",
"specific",
"event",
"handler",
"for",
"a",
"given",
"event",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/eventsource.js#L108-L123
|
|
10,878
|
openseadragon/openseadragon
|
src/eventsource.js
|
function ( eventName ) {
var events = this.events[ eventName ];
if ( !events || !events.length ) {
return null;
}
events = events.length === 1 ?
[ events[ 0 ] ] :
Array.apply( null, events );
return function ( source, args ) {
var i,
length = events.length;
for ( i = 0; i < length; i++ ) {
if ( events[ i ] ) {
args.eventSource = source;
args.userData = events[ i ].userData;
events[ i ].handler( args );
}
}
};
}
|
javascript
|
function ( eventName ) {
var events = this.events[ eventName ];
if ( !events || !events.length ) {
return null;
}
events = events.length === 1 ?
[ events[ 0 ] ] :
Array.apply( null, events );
return function ( source, args ) {
var i,
length = events.length;
for ( i = 0; i < length; i++ ) {
if ( events[ i ] ) {
args.eventSource = source;
args.userData = events[ i ].userData;
events[ i ].handler( args );
}
}
};
}
|
[
"function",
"(",
"eventName",
")",
"{",
"var",
"events",
"=",
"this",
".",
"events",
"[",
"eventName",
"]",
";",
"if",
"(",
"!",
"events",
"||",
"!",
"events",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"events",
"=",
"events",
".",
"length",
"===",
"1",
"?",
"[",
"events",
"[",
"0",
"]",
"]",
":",
"Array",
".",
"apply",
"(",
"null",
",",
"events",
")",
";",
"return",
"function",
"(",
"source",
",",
"args",
")",
"{",
"var",
"i",
",",
"length",
"=",
"events",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"events",
"[",
"i",
"]",
")",
"{",
"args",
".",
"eventSource",
"=",
"source",
";",
"args",
".",
"userData",
"=",
"events",
"[",
"i",
"]",
".",
"userData",
";",
"events",
"[",
"i",
"]",
".",
"handler",
"(",
"args",
")",
";",
"}",
"}",
"}",
";",
"}"
] |
Get a function which iterates the list of all handlers registered for a given event, calling the handler for each.
@function
@param {String} eventName - Name of event to get handlers for.
|
[
"Get",
"a",
"function",
"which",
"iterates",
"the",
"list",
"of",
"all",
"handlers",
"registered",
"for",
"a",
"given",
"event",
"calling",
"the",
"handler",
"for",
"each",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/eventsource.js#L147-L166
|
|
10,879
|
openseadragon/openseadragon
|
src/eventsource.js
|
function( eventName, eventArgs ) {
//uncomment if you want to get a log of all events
//$.console.log( eventName );
var handler = this.getHandler( eventName );
if ( handler ) {
if ( !eventArgs ) {
eventArgs = {};
}
handler( this, eventArgs );
}
}
|
javascript
|
function( eventName, eventArgs ) {
//uncomment if you want to get a log of all events
//$.console.log( eventName );
var handler = this.getHandler( eventName );
if ( handler ) {
if ( !eventArgs ) {
eventArgs = {};
}
handler( this, eventArgs );
}
}
|
[
"function",
"(",
"eventName",
",",
"eventArgs",
")",
"{",
"//uncomment if you want to get a log of all events",
"//$.console.log( eventName );",
"var",
"handler",
"=",
"this",
".",
"getHandler",
"(",
"eventName",
")",
";",
"if",
"(",
"handler",
")",
"{",
"if",
"(",
"!",
"eventArgs",
")",
"{",
"eventArgs",
"=",
"{",
"}",
";",
"}",
"handler",
"(",
"this",
",",
"eventArgs",
")",
";",
"}",
"}"
] |
Trigger an event, optionally passing additional information.
@function
@param {String} eventName - Name of event to register.
@param {Object} eventArgs - Event-specific data.
|
[
"Trigger",
"an",
"event",
"optionally",
"passing",
"additional",
"information",
"."
] |
e7108f23602575fc6eb152d4b82a8b44b2ca698e
|
https://github.com/openseadragon/openseadragon/blob/e7108f23602575fc6eb152d4b82a8b44b2ca698e/src/eventsource.js#L174-L186
|
|
10,880
|
mlaursen/react-md
|
docs/src/scripts/createDocgen.js
|
createDocgen
|
async function createDocgen() {
const customPropTypes = await getCustomPropTypes();
const components = await getDocumentableComponents();
const propTypesDatabase = getPropTypeLinks(components);
const docgens = await Promise.all(components.map(c => createComponentsDocgen(c, customPropTypes)));
const database = docgens.reduce((db, { group, docgens }) => {
if (NESTED_GROUPS.indexOf(group) !== -1) {
db[group] = docgens.reduce((entry, docgen) => {
let name = kebabCase(docgen.component);
if (!name.endsWith('ss')) {
name = pluralize(name);
}
if (name.match(/selection-control-group/)) {
entry[name.replace(/-group/, '')].push(docgen);
} else {
entry[name.replace(/-(pickers|progress)/, '')] = [docgen];
}
return entry;
}, {});
} else {
db[group] = docgens;
}
return db;
}, {});
await writeFile(DOCGEN_DATABASE, JSON.stringify(database), 'UTF-8');
console.log(`Wrote docgen database to \`${DOCGEN_DATABASE}\``);
await writeFile(PROP_TYPE_DATABASE, JSON.stringify(propTypesDatabase), 'UTF-8');
console.log(`Wrote docgen database to \`${PROP_TYPE_DATABASE}\``);
}
|
javascript
|
async function createDocgen() {
const customPropTypes = await getCustomPropTypes();
const components = await getDocumentableComponents();
const propTypesDatabase = getPropTypeLinks(components);
const docgens = await Promise.all(components.map(c => createComponentsDocgen(c, customPropTypes)));
const database = docgens.reduce((db, { group, docgens }) => {
if (NESTED_GROUPS.indexOf(group) !== -1) {
db[group] = docgens.reduce((entry, docgen) => {
let name = kebabCase(docgen.component);
if (!name.endsWith('ss')) {
name = pluralize(name);
}
if (name.match(/selection-control-group/)) {
entry[name.replace(/-group/, '')].push(docgen);
} else {
entry[name.replace(/-(pickers|progress)/, '')] = [docgen];
}
return entry;
}, {});
} else {
db[group] = docgens;
}
return db;
}, {});
await writeFile(DOCGEN_DATABASE, JSON.stringify(database), 'UTF-8');
console.log(`Wrote docgen database to \`${DOCGEN_DATABASE}\``);
await writeFile(PROP_TYPE_DATABASE, JSON.stringify(propTypesDatabase), 'UTF-8');
console.log(`Wrote docgen database to \`${PROP_TYPE_DATABASE}\``);
}
|
[
"async",
"function",
"createDocgen",
"(",
")",
"{",
"const",
"customPropTypes",
"=",
"await",
"getCustomPropTypes",
"(",
")",
";",
"const",
"components",
"=",
"await",
"getDocumentableComponents",
"(",
")",
";",
"const",
"propTypesDatabase",
"=",
"getPropTypeLinks",
"(",
"components",
")",
";",
"const",
"docgens",
"=",
"await",
"Promise",
".",
"all",
"(",
"components",
".",
"map",
"(",
"c",
"=>",
"createComponentsDocgen",
"(",
"c",
",",
"customPropTypes",
")",
")",
")",
";",
"const",
"database",
"=",
"docgens",
".",
"reduce",
"(",
"(",
"db",
",",
"{",
"group",
",",
"docgens",
"}",
")",
"=>",
"{",
"if",
"(",
"NESTED_GROUPS",
".",
"indexOf",
"(",
"group",
")",
"!==",
"-",
"1",
")",
"{",
"db",
"[",
"group",
"]",
"=",
"docgens",
".",
"reduce",
"(",
"(",
"entry",
",",
"docgen",
")",
"=>",
"{",
"let",
"name",
"=",
"kebabCase",
"(",
"docgen",
".",
"component",
")",
";",
"if",
"(",
"!",
"name",
".",
"endsWith",
"(",
"'ss'",
")",
")",
"{",
"name",
"=",
"pluralize",
"(",
"name",
")",
";",
"}",
"if",
"(",
"name",
".",
"match",
"(",
"/",
"selection-control-group",
"/",
")",
")",
"{",
"entry",
"[",
"name",
".",
"replace",
"(",
"/",
"-group",
"/",
",",
"''",
")",
"]",
".",
"push",
"(",
"docgen",
")",
";",
"}",
"else",
"{",
"entry",
"[",
"name",
".",
"replace",
"(",
"/",
"-(pickers|progress)",
"/",
",",
"''",
")",
"]",
"=",
"[",
"docgen",
"]",
";",
"}",
"return",
"entry",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
"else",
"{",
"db",
"[",
"group",
"]",
"=",
"docgens",
";",
"}",
"return",
"db",
";",
"}",
",",
"{",
"}",
")",
";",
"await",
"writeFile",
"(",
"DOCGEN_DATABASE",
",",
"JSON",
".",
"stringify",
"(",
"database",
")",
",",
"'UTF-8'",
")",
";",
"console",
".",
"log",
"(",
"`",
"\\`",
"${",
"DOCGEN_DATABASE",
"}",
"\\`",
"`",
")",
";",
"await",
"writeFile",
"(",
"PROP_TYPE_DATABASE",
",",
"JSON",
".",
"stringify",
"(",
"propTypesDatabase",
")",
",",
"'UTF-8'",
")",
";",
"console",
".",
"log",
"(",
"`",
"\\`",
"${",
"PROP_TYPE_DATABASE",
"}",
"\\`",
"`",
")",
";",
"}"
] |
Creates the "database" file of all the documentation for the components.
|
[
"Creates",
"the",
"database",
"file",
"of",
"all",
"the",
"documentation",
"for",
"the",
"components",
"."
] |
28c78cac8cdaa3d9832a05025bdf50050627e23b
|
https://github.com/mlaursen/react-md/blob/28c78cac8cdaa3d9832a05025bdf50050627e23b/docs/src/scripts/createDocgen.js#L19-L53
|
10,881
|
mlaursen/react-md
|
docs/src/scripts/utils/getSassDocLinks.js
|
findLink
|
function findLink(ref) {
if (lastLink.indexOf(ref) !== -1) {
return lastLink;
}
lastLink = '';
routes.some((link) => {
if (link.indexOf(ref) !== -1) {
lastLink = link;
}
return lastLink;
});
return lastLink;
}
|
javascript
|
function findLink(ref) {
if (lastLink.indexOf(ref) !== -1) {
return lastLink;
}
lastLink = '';
routes.some((link) => {
if (link.indexOf(ref) !== -1) {
lastLink = link;
}
return lastLink;
});
return lastLink;
}
|
[
"function",
"findLink",
"(",
"ref",
")",
"{",
"if",
"(",
"lastLink",
".",
"indexOf",
"(",
"ref",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"lastLink",
";",
"}",
"lastLink",
"=",
"''",
";",
"routes",
".",
"some",
"(",
"(",
"link",
")",
"=>",
"{",
"if",
"(",
"link",
".",
"indexOf",
"(",
"ref",
")",
"!==",
"-",
"1",
")",
"{",
"lastLink",
"=",
"link",
";",
"}",
"return",
"lastLink",
";",
"}",
")",
";",
"return",
"lastLink",
";",
"}"
] |
"Lazily" finds the link to use for a sassdoc. It attempts to match the `lastLink`,
but otherwise searches the `LINKS` for a match.
@param {String} ref - the ref to match with
@return {String} link - the link to use for the ref.
|
[
"Lazily",
"finds",
"the",
"link",
"to",
"use",
"for",
"a",
"sassdoc",
".",
"It",
"attempts",
"to",
"match",
"the",
"lastLink",
"but",
"otherwise",
"searches",
"the",
"LINKS",
"for",
"a",
"match",
"."
] |
28c78cac8cdaa3d9832a05025bdf50050627e23b
|
https://github.com/mlaursen/react-md/blob/28c78cac8cdaa3d9832a05025bdf50050627e23b/docs/src/scripts/utils/getSassDocLinks.js#L21-L36
|
10,882
|
mlaursen/react-md
|
docs/src/server/api/github.js
|
githubProxy
|
async function githubProxy(req, res) {
const response = await fetchGithub(req.url, { headers });
setHeader(RATE_LIMIT, res, response);
setHeader(RATE_REMAINING, res, response);
setHeader(RATE_RESET, res, response);
if (response.ok) {
const json = await response.json();
res.json(json);
} else if (response.status === FORBIDDEN) {
const json = await response.json();
res.status(FORBIDDEN).json(json);
} else {
res.status(response.status).send(response.statusText);
}
}
|
javascript
|
async function githubProxy(req, res) {
const response = await fetchGithub(req.url, { headers });
setHeader(RATE_LIMIT, res, response);
setHeader(RATE_REMAINING, res, response);
setHeader(RATE_RESET, res, response);
if (response.ok) {
const json = await response.json();
res.json(json);
} else if (response.status === FORBIDDEN) {
const json = await response.json();
res.status(FORBIDDEN).json(json);
} else {
res.status(response.status).send(response.statusText);
}
}
|
[
"async",
"function",
"githubProxy",
"(",
"req",
",",
"res",
")",
"{",
"const",
"response",
"=",
"await",
"fetchGithub",
"(",
"req",
".",
"url",
",",
"{",
"headers",
"}",
")",
";",
"setHeader",
"(",
"RATE_LIMIT",
",",
"res",
",",
"response",
")",
";",
"setHeader",
"(",
"RATE_REMAINING",
",",
"res",
",",
"response",
")",
";",
"setHeader",
"(",
"RATE_RESET",
",",
"res",
",",
"response",
")",
";",
"if",
"(",
"response",
".",
"ok",
")",
"{",
"const",
"json",
"=",
"await",
"response",
".",
"json",
"(",
")",
";",
"res",
".",
"json",
"(",
"json",
")",
";",
"}",
"else",
"if",
"(",
"response",
".",
"status",
"===",
"FORBIDDEN",
")",
"{",
"const",
"json",
"=",
"await",
"response",
".",
"json",
"(",
")",
";",
"res",
".",
"status",
"(",
"FORBIDDEN",
")",
".",
"json",
"(",
"json",
")",
";",
"}",
"else",
"{",
"res",
".",
"status",
"(",
"response",
".",
"status",
")",
".",
"send",
"(",
"response",
".",
"statusText",
")",
";",
"}",
"}"
] |
Soo.. There's probably a better way to set up a proxy server, but that isn't
in my knowledge set. Anyways...
GitHub likes when you specify a custom User-Agent that contains your app name/username
when making api calls to help with debugging and other things. At the time of making
this server, the User-Agent header is considered read-only in most browser still, and breaks
api calls. This "proxy" server was created instead to help with this.
All this endpoint will do is proxy any requests from /api/github to the github api endpoint
and then provide the reate limiting headers in the response to my documentation website.
@see https://developer.github.com/v3/#user-agent-required
|
[
"Soo",
"..",
"There",
"s",
"probably",
"a",
"better",
"way",
"to",
"set",
"up",
"a",
"proxy",
"server",
"but",
"that",
"isn",
"t",
"in",
"my",
"knowledge",
"set",
".",
"Anyways",
"..."
] |
28c78cac8cdaa3d9832a05025bdf50050627e23b
|
https://github.com/mlaursen/react-md/blob/28c78cac8cdaa3d9832a05025bdf50050627e23b/docs/src/server/api/github.js#L32-L46
|
10,883
|
mlaursen/react-md
|
docs/src/utils/formatMarkdown/postTransforms.js
|
headerQuickLinkReplacer
|
function headerQuickLinkReplacer(fullMatch, openingTag, headerId, remainingHtml, headerText) {
const link = makeLink(headerId, headerText);
return `${openingTag} class="quick-link quick-link__container">${link}${remainingHtml}`;
}
|
javascript
|
function headerQuickLinkReplacer(fullMatch, openingTag, headerId, remainingHtml, headerText) {
const link = makeLink(headerId, headerText);
return `${openingTag} class="quick-link quick-link__container">${link}${remainingHtml}`;
}
|
[
"function",
"headerQuickLinkReplacer",
"(",
"fullMatch",
",",
"openingTag",
",",
"headerId",
",",
"remainingHtml",
",",
"headerText",
")",
"{",
"const",
"link",
"=",
"makeLink",
"(",
"headerId",
",",
"headerText",
")",
";",
"return",
"`",
"${",
"openingTag",
"}",
"${",
"link",
"}",
"${",
"remainingHtml",
"}",
"`",
";",
"}"
] |
Inserts the accessible quick link before any header tag and updates the header tag
to be a quick link container.
@param {String} fullMatch - The full match of the quick link regex.
@param {String} openingTag - This will be everything in the match
up to the first '>'. So something like: '<h1 id="h1"'
@param {String} headerId - The header id that was extracted from the openingTag.
@param {String} remainingHtml - This will be the remaining html after the first '>'
@param {String} headerText - All the text that is inbetween the opening and closing of the
header tags.
@return {String} the string updated with quick link html
|
[
"Inserts",
"the",
"accessible",
"quick",
"link",
"before",
"any",
"header",
"tag",
"and",
"updates",
"the",
"header",
"tag",
"to",
"be",
"a",
"quick",
"link",
"container",
"."
] |
28c78cac8cdaa3d9832a05025bdf50050627e23b
|
https://github.com/mlaursen/react-md/blob/28c78cac8cdaa3d9832a05025bdf50050627e23b/docs/src/utils/formatMarkdown/postTransforms.js#L44-L47
|
10,884
|
mlaursen/react-md
|
src/js/SelectionControls/SelectionControlGroup.js
|
requiredByAllControls
|
function requiredByAllControls(validator) {
return function validate(props, propName, component, ...others) {
let err = validator(props, propName, component, ...others);
if (!err && typeof props[propName] === 'undefined') {
const invalids = props.controls.filter(c => !c[propName]).map((_, i) => i);
if (invalids.length) {
const invalidPrefix = invalids.length === props.controls.length
? 'All `controls`'
: `The \`controls\` at indexes \`${invalids.join('`, `')}\``;
const invalidMsg = `${invalidPrefix} are missing the \`${propName}\` prop.`;
err = new Error(
`The \`${propName}\` prop is required to make \`${component}\` accessible for users of ` +
`assistive technologies such as screen readers. Either add the \`${propName}\` to the \`${component}\` ` +
`or add the \`${propName}\` to each \`control\` in the \`controls\` prop. ${invalidMsg}`
);
}
}
return err;
};
}
|
javascript
|
function requiredByAllControls(validator) {
return function validate(props, propName, component, ...others) {
let err = validator(props, propName, component, ...others);
if (!err && typeof props[propName] === 'undefined') {
const invalids = props.controls.filter(c => !c[propName]).map((_, i) => i);
if (invalids.length) {
const invalidPrefix = invalids.length === props.controls.length
? 'All `controls`'
: `The \`controls\` at indexes \`${invalids.join('`, `')}\``;
const invalidMsg = `${invalidPrefix} are missing the \`${propName}\` prop.`;
err = new Error(
`The \`${propName}\` prop is required to make \`${component}\` accessible for users of ` +
`assistive technologies such as screen readers. Either add the \`${propName}\` to the \`${component}\` ` +
`or add the \`${propName}\` to each \`control\` in the \`controls\` prop. ${invalidMsg}`
);
}
}
return err;
};
}
|
[
"function",
"requiredByAllControls",
"(",
"validator",
")",
"{",
"return",
"function",
"validate",
"(",
"props",
",",
"propName",
",",
"component",
",",
"...",
"others",
")",
"{",
"let",
"err",
"=",
"validator",
"(",
"props",
",",
"propName",
",",
"component",
",",
"...",
"others",
")",
";",
"if",
"(",
"!",
"err",
"&&",
"typeof",
"props",
"[",
"propName",
"]",
"===",
"'undefined'",
")",
"{",
"const",
"invalids",
"=",
"props",
".",
"controls",
".",
"filter",
"(",
"c",
"=>",
"!",
"c",
"[",
"propName",
"]",
")",
".",
"map",
"(",
"(",
"_",
",",
"i",
")",
"=>",
"i",
")",
";",
"if",
"(",
"invalids",
".",
"length",
")",
"{",
"const",
"invalidPrefix",
"=",
"invalids",
".",
"length",
"===",
"props",
".",
"controls",
".",
"length",
"?",
"'All `controls`'",
":",
"`",
"\\`",
"\\`",
"\\`",
"${",
"invalids",
".",
"join",
"(",
"'`, `'",
")",
"}",
"\\`",
"`",
";",
"const",
"invalidMsg",
"=",
"`",
"${",
"invalidPrefix",
"}",
"\\`",
"${",
"propName",
"}",
"\\`",
"`",
";",
"err",
"=",
"new",
"Error",
"(",
"`",
"\\`",
"${",
"propName",
"}",
"\\`",
"\\`",
"${",
"component",
"}",
"\\`",
"`",
"+",
"`",
"\\`",
"${",
"propName",
"}",
"\\`",
"\\`",
"${",
"component",
"}",
"\\`",
"`",
"+",
"`",
"\\`",
"${",
"propName",
"}",
"\\`",
"\\`",
"\\`",
"\\`",
"\\`",
"${",
"invalidMsg",
"}",
"`",
")",
";",
"}",
"}",
"return",
"err",
";",
"}",
";",
"}"
] |
A custom PropTypes validator to make sure that each `control` in the `controls` prop
contains the given `propName`, or the `SelectionControlGroup` has defined that prop.
|
[
"A",
"custom",
"PropTypes",
"validator",
"to",
"make",
"sure",
"that",
"each",
"control",
"in",
"the",
"controls",
"prop",
"contains",
"the",
"given",
"propName",
"or",
"the",
"SelectionControlGroup",
"has",
"defined",
"that",
"prop",
"."
] |
28c78cac8cdaa3d9832a05025bdf50050627e23b
|
https://github.com/mlaursen/react-md/blob/28c78cac8cdaa3d9832a05025bdf50050627e23b/src/js/SelectionControls/SelectionControlGroup.js#L16-L38
|
10,885
|
transistorsoft/react-native-background-geolocation
|
scripts/xcode-helpers.js
|
getBuildProperty
|
function getBuildProperty(project, property) {
const firstTarget = project.getFirstTarget().firstTarget;
const configurationList = project.pbxXCConfigurationList()[
firstTarget.buildConfigurationList
];
const defaultBuildConfiguration = configurationList.buildConfigurations.reduce(
(acc, config) => {
const buildSection = project.pbxXCBuildConfigurationSection()[
config.value
];
return buildSection.name ===
configurationList.defaultConfigurationName
? buildSection
: acc;
},
configurationList.buildConfigurations[0]
);
return defaultBuildConfiguration.buildSettings[property];
}
|
javascript
|
function getBuildProperty(project, property) {
const firstTarget = project.getFirstTarget().firstTarget;
const configurationList = project.pbxXCConfigurationList()[
firstTarget.buildConfigurationList
];
const defaultBuildConfiguration = configurationList.buildConfigurations.reduce(
(acc, config) => {
const buildSection = project.pbxXCBuildConfigurationSection()[
config.value
];
return buildSection.name ===
configurationList.defaultConfigurationName
? buildSection
: acc;
},
configurationList.buildConfigurations[0]
);
return defaultBuildConfiguration.buildSettings[property];
}
|
[
"function",
"getBuildProperty",
"(",
"project",
",",
"property",
")",
"{",
"const",
"firstTarget",
"=",
"project",
".",
"getFirstTarget",
"(",
")",
".",
"firstTarget",
";",
"const",
"configurationList",
"=",
"project",
".",
"pbxXCConfigurationList",
"(",
")",
"[",
"firstTarget",
".",
"buildConfigurationList",
"]",
";",
"const",
"defaultBuildConfiguration",
"=",
"configurationList",
".",
"buildConfigurations",
".",
"reduce",
"(",
"(",
"acc",
",",
"config",
")",
"=>",
"{",
"const",
"buildSection",
"=",
"project",
".",
"pbxXCBuildConfigurationSection",
"(",
")",
"[",
"config",
".",
"value",
"]",
";",
"return",
"buildSection",
".",
"name",
"===",
"configurationList",
".",
"defaultConfigurationName",
"?",
"buildSection",
":",
"acc",
";",
"}",
",",
"configurationList",
".",
"buildConfigurations",
"[",
"0",
"]",
")",
";",
"return",
"defaultBuildConfiguration",
".",
"buildSettings",
"[",
"property",
"]",
";",
"}"
] |
The getBuildProperty method of the 'xcode' project is a bit naive in that it doesn't take a specific target but iterates over all of them and doesn't have an exit condition if a property has been found. Which in the case of react-native projects usually is the tvOS target because it comes last.
|
[
"The",
"getBuildProperty",
"method",
"of",
"the",
"xcode",
"project",
"is",
"a",
"bit",
"naive",
"in",
"that",
"it",
"doesn",
"t",
"take",
"a",
"specific",
"target",
"but",
"iterates",
"over",
"all",
"of",
"them",
"and",
"doesn",
"t",
"have",
"an",
"exit",
"condition",
"if",
"a",
"property",
"has",
"been",
"found",
".",
"Which",
"in",
"the",
"case",
"of",
"react",
"-",
"native",
"projects",
"usually",
"is",
"the",
"tvOS",
"target",
"because",
"it",
"comes",
"last",
"."
] |
7c0836653222ee1dd7b6cf6a7b7215f556e63f7c
|
https://github.com/transistorsoft/react-native-background-geolocation/blob/7c0836653222ee1dd7b6cf6a7b7215f556e63f7c/scripts/xcode-helpers.js#L16-L35
|
10,886
|
transistorsoft/react-native-background-geolocation
|
scripts/xcode-helpers.js
|
getTargetAttributes
|
function getTargetAttributes(project, target) {
var attributes = project.getFirstProject()['firstProject']['attributes'];
target = target || project.getFirstTarget();
if (attributes['TargetAttributes'] === undefined) {
attributes['TargetAttributes'] = {};
}
if (attributes['TargetAttributes'][target.uuid] === undefined) {
attributes['TargetAttributes'][target.uuid] = {};
}
return attributes['TargetAttributes'][target.uuid];
}
|
javascript
|
function getTargetAttributes(project, target) {
var attributes = project.getFirstProject()['firstProject']['attributes'];
target = target || project.getFirstTarget();
if (attributes['TargetAttributes'] === undefined) {
attributes['TargetAttributes'] = {};
}
if (attributes['TargetAttributes'][target.uuid] === undefined) {
attributes['TargetAttributes'][target.uuid] = {};
}
return attributes['TargetAttributes'][target.uuid];
}
|
[
"function",
"getTargetAttributes",
"(",
"project",
",",
"target",
")",
"{",
"var",
"attributes",
"=",
"project",
".",
"getFirstProject",
"(",
")",
"[",
"'firstProject'",
"]",
"[",
"'attributes'",
"]",
";",
"target",
"=",
"target",
"||",
"project",
".",
"getFirstTarget",
"(",
")",
";",
"if",
"(",
"attributes",
"[",
"'TargetAttributes'",
"]",
"===",
"undefined",
")",
"{",
"attributes",
"[",
"'TargetAttributes'",
"]",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"attributes",
"[",
"'TargetAttributes'",
"]",
"[",
"target",
".",
"uuid",
"]",
"===",
"undefined",
")",
"{",
"attributes",
"[",
"'TargetAttributes'",
"]",
"[",
"target",
".",
"uuid",
"]",
"=",
"{",
"}",
";",
"}",
"return",
"attributes",
"[",
"'TargetAttributes'",
"]",
"[",
"target",
".",
"uuid",
"]",
";",
"}"
] |
The node-xcode library doesn't offer a method to get all target attributes, so we'll have to implement it ourselves.
|
[
"The",
"node",
"-",
"xcode",
"library",
"doesn",
"t",
"offer",
"a",
"method",
"to",
"get",
"all",
"target",
"attributes",
"so",
"we",
"ll",
"have",
"to",
"implement",
"it",
"ourselves",
"."
] |
7c0836653222ee1dd7b6cf6a7b7215f556e63f7c
|
https://github.com/transistorsoft/react-native-background-geolocation/blob/7c0836653222ee1dd7b6cf6a7b7215f556e63f7c/scripts/xcode-helpers.js#L143-L156
|
10,887
|
pegjs/pegjs
|
tools/benchmark/index.js
|
dup
|
function dup( text, count ) {
let result = "";
for ( let i = 1; i <= count; i++ ) result += text;
return result;
}
|
javascript
|
function dup( text, count ) {
let result = "";
for ( let i = 1; i <= count; i++ ) result += text;
return result;
}
|
[
"function",
"dup",
"(",
"text",
",",
"count",
")",
"{",
"let",
"result",
"=",
"\"\"",
";",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<=",
"count",
";",
"i",
"++",
")",
"result",
"+=",
"text",
";",
"return",
"result",
";",
"}"
] |
Results Table Manipulation
|
[
"Results",
"Table",
"Manipulation"
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/tools/benchmark/index.js#L10-L18
|
10,888
|
pegjs/pegjs
|
packages/pegjs/lib/compiler/passes/report-undefined-rules.js
|
reportUndefinedRules
|
function reportUndefinedRules( ast, session, options ) {
const check = session.buildVisitor( {
rule_ref( node ) {
if ( ! ast.findRule( node.name ) ) {
session.error(
`Rule "${ node.name }" is not defined.`,
node.location
);
}
}
} );
check( ast );
options.allowedStartRules.forEach( rule => {
if ( ! ast.findRule( rule ) ) {
session.error( `Start rule "${ rule }" is not defined.` );
}
} );
}
|
javascript
|
function reportUndefinedRules( ast, session, options ) {
const check = session.buildVisitor( {
rule_ref( node ) {
if ( ! ast.findRule( node.name ) ) {
session.error(
`Rule "${ node.name }" is not defined.`,
node.location
);
}
}
} );
check( ast );
options.allowedStartRules.forEach( rule => {
if ( ! ast.findRule( rule ) ) {
session.error( `Start rule "${ rule }" is not defined.` );
}
} );
}
|
[
"function",
"reportUndefinedRules",
"(",
"ast",
",",
"session",
",",
"options",
")",
"{",
"const",
"check",
"=",
"session",
".",
"buildVisitor",
"(",
"{",
"rule_ref",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"ast",
".",
"findRule",
"(",
"node",
".",
"name",
")",
")",
"{",
"session",
".",
"error",
"(",
"`",
"${",
"node",
".",
"name",
"}",
"`",
",",
"node",
".",
"location",
")",
";",
"}",
"}",
"}",
")",
";",
"check",
"(",
"ast",
")",
";",
"options",
".",
"allowedStartRules",
".",
"forEach",
"(",
"rule",
"=>",
"{",
"if",
"(",
"!",
"ast",
".",
"findRule",
"(",
"rule",
")",
")",
"{",
"session",
".",
"error",
"(",
"`",
"${",
"rule",
"}",
"`",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Checks that all referenced rules exist.
|
[
"Checks",
"that",
"all",
"referenced",
"rules",
"exist",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/compiler/passes/report-undefined-rules.js#L4-L33
|
10,889
|
pegjs/pegjs
|
packages/pegjs/lib/compiler/passes/calc-report-failures.js
|
calcReportFailures
|
function calcReportFailures( ast, session, options ) {
// By default, not report failures for rules...
ast.rules.forEach( rule => {
rule.reportFailures = false;
} );
// ...but report for start rules, because in that context report failures
// always enabled
const changedRules = options.allowedStartRules.map( name => {
const rule = ast.findRule( name );
rule.reportFailures = true;
return rule;
} );
const calc = session.buildVisitor( {
rule( node ) {
calc( node.expression );
},
// Because all rules already by default marked as not report any failures
// just break AST traversing when we need mark all referenced rules from
// this sub-AST as always not report anything (of course if it not be
// already marked as report failures).
named() {},
rule_ref( node ) {
const rule = ast.findRule( node.name );
// This function only called when rule can report failures. If so, we
// need recalculate all rules that referenced from it. But do not do
// this twice - if rule is already marked, it was in `changedRules`.
if ( ! rule.reportFailures ) {
rule.reportFailures = true;
changedRules.push( rule );
}
}
} );
while ( changedRules.length > 0 ) {
calc( changedRules.pop() );
}
}
|
javascript
|
function calcReportFailures( ast, session, options ) {
// By default, not report failures for rules...
ast.rules.forEach( rule => {
rule.reportFailures = false;
} );
// ...but report for start rules, because in that context report failures
// always enabled
const changedRules = options.allowedStartRules.map( name => {
const rule = ast.findRule( name );
rule.reportFailures = true;
return rule;
} );
const calc = session.buildVisitor( {
rule( node ) {
calc( node.expression );
},
// Because all rules already by default marked as not report any failures
// just break AST traversing when we need mark all referenced rules from
// this sub-AST as always not report anything (of course if it not be
// already marked as report failures).
named() {},
rule_ref( node ) {
const rule = ast.findRule( node.name );
// This function only called when rule can report failures. If so, we
// need recalculate all rules that referenced from it. But do not do
// this twice - if rule is already marked, it was in `changedRules`.
if ( ! rule.reportFailures ) {
rule.reportFailures = true;
changedRules.push( rule );
}
}
} );
while ( changedRules.length > 0 ) {
calc( changedRules.pop() );
}
}
|
[
"function",
"calcReportFailures",
"(",
"ast",
",",
"session",
",",
"options",
")",
"{",
"// By default, not report failures for rules...",
"ast",
".",
"rules",
".",
"forEach",
"(",
"rule",
"=>",
"{",
"rule",
".",
"reportFailures",
"=",
"false",
";",
"}",
")",
";",
"// ...but report for start rules, because in that context report failures",
"// always enabled",
"const",
"changedRules",
"=",
"options",
".",
"allowedStartRules",
".",
"map",
"(",
"name",
"=>",
"{",
"const",
"rule",
"=",
"ast",
".",
"findRule",
"(",
"name",
")",
";",
"rule",
".",
"reportFailures",
"=",
"true",
";",
"return",
"rule",
";",
"}",
")",
";",
"const",
"calc",
"=",
"session",
".",
"buildVisitor",
"(",
"{",
"rule",
"(",
"node",
")",
"{",
"calc",
"(",
"node",
".",
"expression",
")",
";",
"}",
",",
"// Because all rules already by default marked as not report any failures",
"// just break AST traversing when we need mark all referenced rules from",
"// this sub-AST as always not report anything (of course if it not be",
"// already marked as report failures).",
"named",
"(",
")",
"{",
"}",
",",
"rule_ref",
"(",
"node",
")",
"{",
"const",
"rule",
"=",
"ast",
".",
"findRule",
"(",
"node",
".",
"name",
")",
";",
"// This function only called when rule can report failures. If so, we",
"// need recalculate all rules that referenced from it. But do not do",
"// this twice - if rule is already marked, it was in `changedRules`.",
"if",
"(",
"!",
"rule",
".",
"reportFailures",
")",
"{",
"rule",
".",
"reportFailures",
"=",
"true",
";",
"changedRules",
".",
"push",
"(",
"rule",
")",
";",
"}",
"}",
"}",
")",
";",
"while",
"(",
"changedRules",
".",
"length",
">",
"0",
")",
"{",
"calc",
"(",
"changedRules",
".",
"pop",
"(",
")",
")",
";",
"}",
"}"
] |
Determines if rule always used in disabled report failure context, that means, that any failures, reported within it, are never will be visible, so the no need to report it.
|
[
"Determines",
"if",
"rule",
"always",
"used",
"in",
"disabled",
"report",
"failure",
"context",
"that",
"means",
"that",
"any",
"failures",
"reported",
"within",
"it",
"are",
"never",
"will",
"be",
"visible",
"so",
"the",
"no",
"need",
"to",
"report",
"it",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/compiler/passes/calc-report-failures.js#L6-L63
|
10,890
|
pegjs/pegjs
|
packages/pegjs/lib/compiler/passes/report-duplicate-labels.js
|
reportDuplicateLabels
|
function reportDuplicateLabels( ast, session ) {
let check;
function checkExpressionWithClonedEnv( node, env ) {
check( node.expression, util.clone( env ) );
}
check = session.buildVisitor( {
rule( node ) {
check( node.expression, {} );
},
choice( node, env ) {
node.alternatives.forEach( alternative => {
check( alternative, util.clone( env ) );
} );
},
action: checkExpressionWithClonedEnv,
labeled( node, env ) {
const label = node.label;
if ( label && __hasOwnProperty.call( env, label ) ) {
const start = env[ label ].start;
session.error(
`Label "${ label }" is already defined at line ${ start.line }, column ${ start.column }.`,
node.location
);
}
check( node.expression, env );
if ( label ) env[ label ] = node.location;
},
text: checkExpressionWithClonedEnv,
simple_and: checkExpressionWithClonedEnv,
simple_not: checkExpressionWithClonedEnv,
optional: checkExpressionWithClonedEnv,
zero_or_more: checkExpressionWithClonedEnv,
one_or_more: checkExpressionWithClonedEnv,
group: checkExpressionWithClonedEnv
} );
check( ast );
}
|
javascript
|
function reportDuplicateLabels( ast, session ) {
let check;
function checkExpressionWithClonedEnv( node, env ) {
check( node.expression, util.clone( env ) );
}
check = session.buildVisitor( {
rule( node ) {
check( node.expression, {} );
},
choice( node, env ) {
node.alternatives.forEach( alternative => {
check( alternative, util.clone( env ) );
} );
},
action: checkExpressionWithClonedEnv,
labeled( node, env ) {
const label = node.label;
if ( label && __hasOwnProperty.call( env, label ) ) {
const start = env[ label ].start;
session.error(
`Label "${ label }" is already defined at line ${ start.line }, column ${ start.column }.`,
node.location
);
}
check( node.expression, env );
if ( label ) env[ label ] = node.location;
},
text: checkExpressionWithClonedEnv,
simple_and: checkExpressionWithClonedEnv,
simple_not: checkExpressionWithClonedEnv,
optional: checkExpressionWithClonedEnv,
zero_or_more: checkExpressionWithClonedEnv,
one_or_more: checkExpressionWithClonedEnv,
group: checkExpressionWithClonedEnv
} );
check( ast );
}
|
[
"function",
"reportDuplicateLabels",
"(",
"ast",
",",
"session",
")",
"{",
"let",
"check",
";",
"function",
"checkExpressionWithClonedEnv",
"(",
"node",
",",
"env",
")",
"{",
"check",
"(",
"node",
".",
"expression",
",",
"util",
".",
"clone",
"(",
"env",
")",
")",
";",
"}",
"check",
"=",
"session",
".",
"buildVisitor",
"(",
"{",
"rule",
"(",
"node",
")",
"{",
"check",
"(",
"node",
".",
"expression",
",",
"{",
"}",
")",
";",
"}",
",",
"choice",
"(",
"node",
",",
"env",
")",
"{",
"node",
".",
"alternatives",
".",
"forEach",
"(",
"alternative",
"=>",
"{",
"check",
"(",
"alternative",
",",
"util",
".",
"clone",
"(",
"env",
")",
")",
";",
"}",
")",
";",
"}",
",",
"action",
":",
"checkExpressionWithClonedEnv",
",",
"labeled",
"(",
"node",
",",
"env",
")",
"{",
"const",
"label",
"=",
"node",
".",
"label",
";",
"if",
"(",
"label",
"&&",
"__hasOwnProperty",
".",
"call",
"(",
"env",
",",
"label",
")",
")",
"{",
"const",
"start",
"=",
"env",
"[",
"label",
"]",
".",
"start",
";",
"session",
".",
"error",
"(",
"`",
"${",
"label",
"}",
"${",
"start",
".",
"line",
"}",
"${",
"start",
".",
"column",
"}",
"`",
",",
"node",
".",
"location",
")",
";",
"}",
"check",
"(",
"node",
".",
"expression",
",",
"env",
")",
";",
"if",
"(",
"label",
")",
"env",
"[",
"label",
"]",
"=",
"node",
".",
"location",
";",
"}",
",",
"text",
":",
"checkExpressionWithClonedEnv",
",",
"simple_and",
":",
"checkExpressionWithClonedEnv",
",",
"simple_not",
":",
"checkExpressionWithClonedEnv",
",",
"optional",
":",
"checkExpressionWithClonedEnv",
",",
"zero_or_more",
":",
"checkExpressionWithClonedEnv",
",",
"one_or_more",
":",
"checkExpressionWithClonedEnv",
",",
"group",
":",
"checkExpressionWithClonedEnv",
"}",
")",
";",
"check",
"(",
"ast",
")",
";",
"}"
] |
Checks that each label is defined only once within each scope.
|
[
"Checks",
"that",
"each",
"label",
"is",
"defined",
"only",
"once",
"within",
"each",
"scope",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/compiler/passes/report-duplicate-labels.js#L7-L68
|
10,891
|
pegjs/pegjs
|
packages/pegjs/lib/util/vm.js
|
evalModule
|
function evalModule( source, context ) {
const argumentKeys = Object.keys( context );
const argumentValues = argumentKeys.map( argument => context[ argument ] );
const sandbox = { exports: {} };
argumentKeys.push( "module", "exports", source );
argumentValues.push( sandbox, sandbox.exports );
Function( ...argumentKeys )( ...argumentValues );
return sandbox.exports;
}
|
javascript
|
function evalModule( source, context ) {
const argumentKeys = Object.keys( context );
const argumentValues = argumentKeys.map( argument => context[ argument ] );
const sandbox = { exports: {} };
argumentKeys.push( "module", "exports", source );
argumentValues.push( sandbox, sandbox.exports );
Function( ...argumentKeys )( ...argumentValues );
return sandbox.exports;
}
|
[
"function",
"evalModule",
"(",
"source",
",",
"context",
")",
"{",
"const",
"argumentKeys",
"=",
"Object",
".",
"keys",
"(",
"context",
")",
";",
"const",
"argumentValues",
"=",
"argumentKeys",
".",
"map",
"(",
"argument",
"=>",
"context",
"[",
"argument",
"]",
")",
";",
"const",
"sandbox",
"=",
"{",
"exports",
":",
"{",
"}",
"}",
";",
"argumentKeys",
".",
"push",
"(",
"\"module\"",
",",
"\"exports\"",
",",
"source",
")",
";",
"argumentValues",
".",
"push",
"(",
"sandbox",
",",
"sandbox",
".",
"exports",
")",
";",
"Function",
"(",
"...",
"argumentKeys",
")",
"(",
"...",
"argumentValues",
")",
";",
"return",
"sandbox",
".",
"exports",
";",
"}"
] |
`eval` the given source as a CommonJS module, using properties found in `context` as top-level variables.
Based on `vm.runInContext` found in Node.js, this is a cross-env solution.
|
[
"eval",
"the",
"given",
"source",
"as",
"a",
"CommonJS",
"module",
"using",
"properties",
"found",
"in",
"context",
"as",
"top",
"-",
"level",
"variables",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/util/vm.js#L8-L21
|
10,892
|
pegjs/pegjs
|
packages/pegjs/lib/parser.js
|
createNode
|
function createNode( type, details ) {
const node = new ast.Node( type, location() );
if ( details === null ) return node;
util.extend( node, details );
return util.enforceFastProperties( node );
}
|
javascript
|
function createNode( type, details ) {
const node = new ast.Node( type, location() );
if ( details === null ) return node;
util.extend( node, details );
return util.enforceFastProperties( node );
}
|
[
"function",
"createNode",
"(",
"type",
",",
"details",
")",
"{",
"const",
"node",
"=",
"new",
"ast",
".",
"Node",
"(",
"type",
",",
"location",
"(",
")",
")",
";",
"if",
"(",
"details",
"===",
"null",
")",
"return",
"node",
";",
"util",
".",
"extend",
"(",
"node",
",",
"details",
")",
";",
"return",
"util",
".",
"enforceFastProperties",
"(",
"node",
")",
";",
"}"
] |
Helper to construct a new AST Node
|
[
"Helper",
"to",
"construct",
"a",
"new",
"AST",
"Node"
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/parser.js#L3424-L3432
|
10,893
|
pegjs/pegjs
|
packages/pegjs/lib/parser.js
|
addComment
|
function addComment( text, multiline ) {
if ( options.extractComments ) {
const loc = location();
comments[ loc.start.offset ] = {
text: text,
multiline: multiline,
location: loc,
};
}
return text;
}
|
javascript
|
function addComment( text, multiline ) {
if ( options.extractComments ) {
const loc = location();
comments[ loc.start.offset ] = {
text: text,
multiline: multiline,
location: loc,
};
}
return text;
}
|
[
"function",
"addComment",
"(",
"text",
",",
"multiline",
")",
"{",
"if",
"(",
"options",
".",
"extractComments",
")",
"{",
"const",
"loc",
"=",
"location",
"(",
")",
";",
"comments",
"[",
"loc",
".",
"start",
".",
"offset",
"]",
"=",
"{",
"text",
":",
"text",
",",
"multiline",
":",
"multiline",
",",
"location",
":",
"loc",
",",
"}",
";",
"}",
"return",
"text",
";",
"}"
] |
Helper that collects all the comments to pass to the Grammar AST
|
[
"Helper",
"that",
"collects",
"all",
"the",
"comments",
"to",
"pass",
"to",
"the",
"Grammar",
"AST"
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/parser.js#L3438-L3454
|
10,894
|
pegjs/pegjs
|
packages/pegjs/lib/compiler/passes/report-duplicate-rules.js
|
reportDuplicateRules
|
function reportDuplicateRules( ast, session ) {
const rules = {};
const check = session.buildVisitor( {
rule( node ) {
const name = node.name;
if ( __hasOwnProperty.call( rules, name ) ) {
const start = rules[ name ].start;
session.error(
`Rule "${ name }" is already defined at line ${ start.line }, column ${ start.column }.`,
node.location
);
}
rules[ node.name ] = node.location;
}
} );
check( ast );
}
|
javascript
|
function reportDuplicateRules( ast, session ) {
const rules = {};
const check = session.buildVisitor( {
rule( node ) {
const name = node.name;
if ( __hasOwnProperty.call( rules, name ) ) {
const start = rules[ name ].start;
session.error(
`Rule "${ name }" is already defined at line ${ start.line }, column ${ start.column }.`,
node.location
);
}
rules[ node.name ] = node.location;
}
} );
check( ast );
}
|
[
"function",
"reportDuplicateRules",
"(",
"ast",
",",
"session",
")",
"{",
"const",
"rules",
"=",
"{",
"}",
";",
"const",
"check",
"=",
"session",
".",
"buildVisitor",
"(",
"{",
"rule",
"(",
"node",
")",
"{",
"const",
"name",
"=",
"node",
".",
"name",
";",
"if",
"(",
"__hasOwnProperty",
".",
"call",
"(",
"rules",
",",
"name",
")",
")",
"{",
"const",
"start",
"=",
"rules",
"[",
"name",
"]",
".",
"start",
";",
"session",
".",
"error",
"(",
"`",
"${",
"name",
"}",
"${",
"start",
".",
"line",
"}",
"${",
"start",
".",
"column",
"}",
"`",
",",
"node",
".",
"location",
")",
";",
"}",
"rules",
"[",
"node",
".",
"name",
"]",
"=",
"node",
".",
"location",
";",
"}",
"}",
")",
";",
"check",
"(",
"ast",
")",
";",
"}"
] |
Checks that each rule is defined only once.
|
[
"Checks",
"that",
"each",
"rule",
"is",
"defined",
"only",
"once",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/compiler/passes/report-duplicate-rules.js#L6-L33
|
10,895
|
pegjs/pegjs
|
packages/pegjs/lib/compiler/passes/report-unused-rules.js
|
reportUnusedRules
|
function reportUnusedRules( ast, session, options ) {
const used = {};
function yes( node ) {
used[ node.name || node ] = true;
}
options.allowedStartRules.forEach( yes );
session.buildVisitor( { rule_ref: yes } )( ast );
ast.rules.forEach( rule => {
if ( used[ rule.name ] !== true ) {
session.warn(
`Rule "${ rule.name }" is not referenced.`,
rule.location
);
}
} );
}
|
javascript
|
function reportUnusedRules( ast, session, options ) {
const used = {};
function yes( node ) {
used[ node.name || node ] = true;
}
options.allowedStartRules.forEach( yes );
session.buildVisitor( { rule_ref: yes } )( ast );
ast.rules.forEach( rule => {
if ( used[ rule.name ] !== true ) {
session.warn(
`Rule "${ rule.name }" is not referenced.`,
rule.location
);
}
} );
}
|
[
"function",
"reportUnusedRules",
"(",
"ast",
",",
"session",
",",
"options",
")",
"{",
"const",
"used",
"=",
"{",
"}",
";",
"function",
"yes",
"(",
"node",
")",
"{",
"used",
"[",
"node",
".",
"name",
"||",
"node",
"]",
"=",
"true",
";",
"}",
"options",
".",
"allowedStartRules",
".",
"forEach",
"(",
"yes",
")",
";",
"session",
".",
"buildVisitor",
"(",
"{",
"rule_ref",
":",
"yes",
"}",
")",
"(",
"ast",
")",
";",
"ast",
".",
"rules",
".",
"forEach",
"(",
"rule",
"=>",
"{",
"if",
"(",
"used",
"[",
"rule",
".",
"name",
"]",
"!==",
"true",
")",
"{",
"session",
".",
"warn",
"(",
"`",
"${",
"rule",
".",
"name",
"}",
"`",
",",
"rule",
".",
"location",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Checks that all rules are used.
|
[
"Checks",
"that",
"all",
"rules",
"are",
"used",
"."
] |
30f32600084d8da6a50b801edad49619e53e2a05
|
https://github.com/pegjs/pegjs/blob/30f32600084d8da6a50b801edad49619e53e2a05/packages/pegjs/lib/compiler/passes/report-unused-rules.js#L4-L29
|
10,896
|
theturtle32/WebSocket-Node
|
lib/browser.js
|
W3CWebSocket
|
function W3CWebSocket(uri, protocols) {
var native_instance;
if (protocols) {
native_instance = new NativeWebSocket(uri, protocols);
}
else {
native_instance = new NativeWebSocket(uri);
}
/**
* 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
* class). Since it is an Object it will be returned as it is when creating an
* instance of W3CWebSocket via 'new W3CWebSocket()'.
*
* ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
*/
return native_instance;
}
|
javascript
|
function W3CWebSocket(uri, protocols) {
var native_instance;
if (protocols) {
native_instance = new NativeWebSocket(uri, protocols);
}
else {
native_instance = new NativeWebSocket(uri);
}
/**
* 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
* class). Since it is an Object it will be returned as it is when creating an
* instance of W3CWebSocket via 'new W3CWebSocket()'.
*
* ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
*/
return native_instance;
}
|
[
"function",
"W3CWebSocket",
"(",
"uri",
",",
"protocols",
")",
"{",
"var",
"native_instance",
";",
"if",
"(",
"protocols",
")",
"{",
"native_instance",
"=",
"new",
"NativeWebSocket",
"(",
"uri",
",",
"protocols",
")",
";",
"}",
"else",
"{",
"native_instance",
"=",
"new",
"NativeWebSocket",
"(",
"uri",
")",
";",
"}",
"/**\n\t * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket\n\t * class). Since it is an Object it will be returned as it is when creating an\n\t * instance of W3CWebSocket via 'new W3CWebSocket()'.\n\t *\n\t * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2\n\t */",
"return",
"native_instance",
";",
"}"
] |
Expose a W3C WebSocket class with just one or two arguments.
|
[
"Expose",
"a",
"W3C",
"WebSocket",
"class",
"with",
"just",
"one",
"or",
"two",
"arguments",
"."
] |
e109ba6b2c4d2bcf4b0f4c0aa7a60855a3cf0c12
|
https://github.com/theturtle32/WebSocket-Node/blob/e109ba6b2c4d2bcf4b0f4c0aa7a60855a3cf0c12/lib/browser.js#L9-L27
|
10,897
|
theturtle32/WebSocket-Node
|
lib/WebSocketFrame.js
|
WebSocketFrame
|
function WebSocketFrame(maskBytes, frameHeader, config) {
this.maskBytes = maskBytes;
this.frameHeader = frameHeader;
this.config = config;
this.maxReceivedFrameSize = config.maxReceivedFrameSize;
this.protocolError = false;
this.frameTooLarge = false;
this.invalidCloseFrameLength = false;
this.parseState = DECODE_HEADER;
this.closeStatus = -1;
}
|
javascript
|
function WebSocketFrame(maskBytes, frameHeader, config) {
this.maskBytes = maskBytes;
this.frameHeader = frameHeader;
this.config = config;
this.maxReceivedFrameSize = config.maxReceivedFrameSize;
this.protocolError = false;
this.frameTooLarge = false;
this.invalidCloseFrameLength = false;
this.parseState = DECODE_HEADER;
this.closeStatus = -1;
}
|
[
"function",
"WebSocketFrame",
"(",
"maskBytes",
",",
"frameHeader",
",",
"config",
")",
"{",
"this",
".",
"maskBytes",
"=",
"maskBytes",
";",
"this",
".",
"frameHeader",
"=",
"frameHeader",
";",
"this",
".",
"config",
"=",
"config",
";",
"this",
".",
"maxReceivedFrameSize",
"=",
"config",
".",
"maxReceivedFrameSize",
";",
"this",
".",
"protocolError",
"=",
"false",
";",
"this",
".",
"frameTooLarge",
"=",
"false",
";",
"this",
".",
"invalidCloseFrameLength",
"=",
"false",
";",
"this",
".",
"parseState",
"=",
"DECODE_HEADER",
";",
"this",
".",
"closeStatus",
"=",
"-",
"1",
";",
"}"
] |
WebSocketConnection will pass shared buffer objects for maskBytes and frameHeader into the constructor to avoid tons of small memory allocations for each frame we have to parse. This is only used for parsing frames we receive off the wire.
|
[
"WebSocketConnection",
"will",
"pass",
"shared",
"buffer",
"objects",
"for",
"maskBytes",
"and",
"frameHeader",
"into",
"the",
"constructor",
"to",
"avoid",
"tons",
"of",
"small",
"memory",
"allocations",
"for",
"each",
"frame",
"we",
"have",
"to",
"parse",
".",
"This",
"is",
"only",
"used",
"for",
"parsing",
"frames",
"we",
"receive",
"off",
"the",
"wire",
"."
] |
e109ba6b2c4d2bcf4b0f4c0aa7a60855a3cf0c12
|
https://github.com/theturtle32/WebSocket-Node/blob/e109ba6b2c4d2bcf4b0f4c0aa7a60855a3cf0c12/lib/WebSocketFrame.js#L31-L41
|
10,898
|
AlloyTeam/AlloyTouch
|
example/threejs/asset/three.js
|
function() {
var EPS = 0.000001;
this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
return this;
}
|
javascript
|
function() {
var EPS = 0.000001;
this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"EPS",
"=",
"0.000001",
";",
"this",
".",
"phi",
"=",
"Math",
".",
"max",
"(",
"EPS",
",",
"Math",
".",
"min",
"(",
"Math",
".",
"PI",
"-",
"EPS",
",",
"this",
".",
"phi",
")",
")",
";",
"return",
"this",
";",
"}"
] |
restrict phi to be betwee EPS and PI-EPS
|
[
"restrict",
"phi",
"to",
"be",
"betwee",
"EPS",
"and",
"PI",
"-",
"EPS"
] |
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
|
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L6926-L6933
|
|
10,899
|
AlloyTeam/AlloyTouch
|
example/threejs/asset/three.js
|
extractFromCache
|
function extractFromCache ( cache ) {
var values = [];
for ( var key in cache ) {
var data = cache[ key ];
delete data.metadata;
values.push( data );
}
return values;
}
|
javascript
|
function extractFromCache ( cache ) {
var values = [];
for ( var key in cache ) {
var data = cache[ key ];
delete data.metadata;
values.push( data );
}
return values;
}
|
[
"function",
"extractFromCache",
"(",
"cache",
")",
"{",
"var",
"values",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"cache",
")",
"{",
"var",
"data",
"=",
"cache",
"[",
"key",
"]",
";",
"delete",
"data",
".",
"metadata",
";",
"values",
".",
"push",
"(",
"data",
")",
";",
"}",
"return",
"values",
";",
"}"
] |
extract data from the cache hash remove metadata on each item and return as array
|
[
"extract",
"data",
"from",
"the",
"cache",
"hash",
"remove",
"metadata",
"on",
"each",
"item",
"and",
"return",
"as",
"array"
] |
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
|
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L9101-L9113
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.