web-common-resource/terminal/smartxKs/smartxksUtil.js

25 lines
8.8 KiB
JavaScript
Raw Normal View History

2024-08-20 12:11:35 +00:00
/*
* 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_i