25 lines
8.8 KiB
JavaScript
25 lines
8.8 KiB
JavaScript
/*
|
|
* noVNC: HTML5 VNC client
|
|
* Copyright (C) 2012 Joel Martin
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
*
|
|
* See README.md for usage and integration instructions.
|
|
*/
|
|
|
|
// IE does not support map (even in IE9)
|
|
//This prototype is provided by the Mozilla foundation and
|
|
//is distributed under the MIT license.
|
|
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
|
|
|
// IE <9 does not support indexOf
|
|
//This prototype is provided by the Mozilla foundation and
|
|
//is distributed under the MIT license.
|
|
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
|
|
|
// PhantomJS 1.x doesn't support bind,
|
|
// so leave this in until PhantomJS 2.0 is released
|
|
//This prototype is provided by the Mozilla foundation and
|
|
//is distributed under the MIT license.
|
|
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
|
|
|
var Util={},addFunc=function(t,e,n){t.prototype[e]||Object.defineProperty(t.prototype,e,{enumerable:!1,value:n})};addFunc(Array,"push8",function(t){"use strict";this.push(255&t)}),addFunc(Array,"push16",function(t){"use strict";this.push(t>>8&255,255&t)}),addFunc(Array,"push32",function(t){"use strict";this.push(t>>24&255,t>>16&255,t>>8&255,255&t)}),addFunc(Array,"map",function(t){"use strict";var e=this.length;if("function"!=typeof t)throw new TypeError;for(var n=new Array(e),r=arguments[1],o=0;o<e;o++)o in this&&(n[o]=t.call(r,this[o],o,this));return n}),addFunc(Array,"indexOf",function(t){"use strict";var e=this.length>>>0,n=Number(arguments[1])||0;for(n=n<0?Math.ceil(n):Math.floor(n),n<0&&(n+=e);n<e;n++)if(n in this&&this[n]===t)return n;return-1}),Object.keys||(Object.keys=function(){"use strict";var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),n=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],r=n.length;return function(o){if("object"!=typeof o&&("function"!=typeof o||null===o))throw new TypeError("Object.keys called on non-object");var i,s,a=[];for(i in o)t.call(o,i)&&a.push(i);if(e)for(s=0;s<r;s++)t.call(o,n[s])&&a.push(n[s]);return a}}()),addFunc(Function,"bind",function(t){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=Array.prototype.slice.call(arguments,1),n=this,r=function(){},o=function(){return n.apply(this instanceof r&&t?this:t,e.concat(Array.prototype.slice.call(arguments)))};return r.prototype=this.prototype,o.prototype=new r,o}),window.requestAnimFrame=function(){"use strict";return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}(),Util._log_level="warn",Util.init_logging=function(t){"use strict";switch(void 0===t?t=Util._log_level:Util._log_level=t,void 0===window.console&&(void 0!==window.opera?window.console={log:window.opera.postError,warn:window.opera.postError,error:window.opera.postError}:window.console={log:function(t){},warn:function(t){},error:function(t){}}),Util.Debug=Util.Info=Util.Warn=Util.Error=function(t){},t){case"debug":Util.Debug=function(t){console.log(t)};case"info":Util.Info=function(t){console.log(t)};case"warn":Util.Warn=function(t){console.warn(t)};case"error":Util.Error=function(t){console.error(t)};case"none":break;default:throw new Error("invalid logging type '"+t+"'")}},Util.get_logging=function(){return Util._log_level},Util.init_logging(),Util.make_property=function(t,e,n,r){"use strict";var o;o="arr"===r?function(t){return void 0!==t?this["_"+e][t]:this["_"+e]}:function(){return this["_"+e]};var i,s=function(t){return t?function(n,r){void 0!==r?this["_"+e][r]=t(n):this["_"+e]=t(n)}:function(t,n){void 0!==n?this["_"+e][n]=t:this["_"+e]=t}};if("bool"===r)i=s(function(t){return!(!t||t in{0:1,no:1,false:1})});else if("int"===r)i=s(function(t){return parseInt(t,10)});else if("float"===r)i=s(parseFloat);else if("str"===r)i=s(String);else if("func"===r)i=s(function(t){return t||function(){}});else{if("arr"!==r&&"dom"!==r&&"raw"!=r)throw new Error("Unknown property type "+r);i=s()}void 0===t["get_"+e]&&(t["get_"+e]=o),void 0===t["set_"+e]&&("rw"===n?t["set_"+e]=i:"wo"===n&&(t["set_"+e]=function(t,n){if(void 0!==this["_"+e])throw new Error(e+" can only be set once");i.call(this,t,n)})),t["_raw_set_"+e]=function(t,e){i.call(this,t,e)}},Util.make_properties=function(t,e){"use strict";for(var n=0;n<e.length;n++)Util.make_property(t.prototype,e[n][0],e[n][1],e[n][2])},Util.set_defaults=function(t,e,n){var r,o=Object.keys(n),i=Object.keys(e),s={};for(r=0;r<o.length;r++)s[o[r]]=1;for(r=0;r<i.length;r++)s[i[r]]=1;var a=Object.keys(s);for(r=0;r<a.length;r++){var c=t["_raw_set_"+a[r]];c?a[r]in e?c.call(t,e[a[r]]):c.call(t,n[a[r]]):Util.Warn("Invalid property "+a[r])}},Util.decodeUTF8=function(t){"use strict";return decodeURIComponent(escape(t))},Util.get_include_uri=function(){return"undefined"!=typeof INCLUDE_URI?INCLUDE_URI:"terminal/"},Util._loading_scripts=[],Util._pending_scripts=[],Util.load_scripts=function(t){"use strict";for(var e,n=document.getElementsByTagName("head")[0],r=Util._loading_scripts,o=Util._pending_scripts,i=function(t){for(;r.length>0&&("loaded"===r[0].readyState||"complete"===r[0].readyState);){var e=r.shift();n.appendChild(e)}(!this.readyState||Util.Engine.presto&&"loaded"===this.readyState||"complete"===this.readyState)&&o.indexOf(this)>=0&&(this.onload=this.onreadystatechange=null,o.splice(o.indexOf(this),1),0===o.length&&window.onscriptsload&&window.onscriptsload())},s=0;s<t.length;s++)e=document.createElement("script"),e.type="text/javascript",e.src=Util.get_include_uri()+t[s],e.onload=e.onreadystatechange=i,Util.Engine.trident?r.push(e):(e.async=!1,n.appendChild(e)),o.push(e)},Util.getPosition=function(t){"use strict";var e=t.getBoundingClientRect();return{x:e.left+window.pageXOffset,y:e.top+window.pageYOffset,width:e.width,height:e.height}},Util.getEventPosition=function(t,e,n){"use strict";var r,o,i,s;r=t||window.event,r=r.changedTouches?r.changedTouches[0]:r.touches?r.touches[0]:r,r.pageX||r.pageY?(o=r.pageX,i=r.pageY):(r.clientX||r.clientY)&&(o=r.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,i=r.clientY+document.body.scrollTop+document.documentElement.scrollTop),s=Util.getPosition(e),void 0===n&&(n=1);var a=o-s.x,c=i-s.y;return{x:Math.max(Math.min(a,s.width-1),0)/n,y:Math.max(Math.min(c,s.height-1),0)/n,realx:a/n,realy:c/n}},Util.addEvent=function(t,e,n){"use strict";if(t.attachEvent){return t.attachEvent("on"+e,n)}if(t.addEventListener)return t.addEventListener(e,n,!1),!0;throw new Error("Handler could not be attached")},Util.removeEvent=function(t,e,n){"use strict";if(t.detachEvent){return t.detachEvent("on"+e,n)}if(t.removeEventListener)return t.removeEventListener(e,n,!1),!0;throw new Error("Handler could not be removed")},Util.stopEvent=function(t){"use strict";t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault?t.preventDefault():t.returnValue=!1},Util._cursor_uris_supported=null,Util.browserSupportsCursorURIs=function(){if(null===Util._cursor_uris_supported)try{var t=document.createElement("canvas");t.style.cursor='url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default',t.style.cursor?(Util.Info("Data URI scheme cursor supported"),Util._cursor_uris_supported=!0):(Util.Warn("Data URI scheme cursor not supported"),Util._cursor_uris_supported=!1)}catch(t){Util.Error("Data URI scheme cursor test exception: "+t),Util._cursor_uris_supported=!1}return Util._cursor_uris_supported},Util.Features={xpath:!!document.evaluate,air:!!window.runtime,query:!!document.querySelector},function(){"use strict";Util.Engine={presto:function(){return!!window.opera}(),trident:function(){return!!window.ActiveXObject&&(window.XMLHttpRequest?document.querySelectorAll?6:5:4)}(),webkit:function(){try{return!navigator.taintEnabled&&(Util.Features.xpath?Util.Features.query?525:420:419)}catch(t){return!1}}(),gecko:function(){return!(!document.getBoxObjectFor&&null==window.mozInnerScreenX)&&(document.getElementsByClassName?19:18)}()},Util.Engine.webkit&&(Util.Engine.webkit=function(t){var e=/WebKit\/([0-9\.]*) /,n=(navigator.userAgent.match(e)||["",t])[1];return parseFloat(n,10)}(Util.Engine.webkit))}(),Util.Flash=function(){"use strict";var t,e;try{t=navigator.plugins["Shockwave Flash"].description}catch(e){try{t=new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version")}catch(e){t="0 r0"}}return e=t.match(/\d+/g),{version:parseInt(e[0]||"0."+e[1],10)||0,build:parseInt(e[2],10)||0}}(); |