//******************************************************************************************************// gsf.web.client.js - Gbtc//// Copyright © 2016, Grid Protection Alliance. All Rights Reserved.//// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See// the NOTICE file distributed with this work for additional information regarding copyright ownership.// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may// not use this file except in compliance with the License. You may obtain a copy of the License at://// http://opensource.org/licenses/MIT//// Unless agreed to in writing, the subject software distributed under the License is distributed on an// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the// License for the specific language governing permissions and limitations.//// Code Modification History:// ----------------------------------------------------------------------------------------------------// 01/26/2016 - J. Ritchie Carroll// Generated original version of source code.////******************************************************************************************************// ReSharper disable NativeTypePrototypeExtending// ReSharper disable UndeclaredGlobalVariableUsing // Grid Solutions Framework Core Web Client Script Functions"use strict"; if (typeof jQuery === "undefined") { throw new Error("gsf.web.client script requires jQuery - make sure jquery.js is loaded first");} const isIE = detectIE();var textMetrics; $(function() { // Create a canvas object that will be used for text metrics calculations $("<canvas id=\"textMetricsCanvas\" height=\"1px\" width=\"1px\" style=\"visibility: hidden\"></canvas>") .appendTo("body"); // Get text metrics canvas context textMetrics = document.getElementById("textMetricsCanvas").getContext("2d");}); // Miscellaneous functionsfunction notNull(value, nonNullValue) { return value || (nonNullValue || "");} function detectIE() { const ua = window.navigator.userAgent; const msie = ua.indexOf("MSIE "); if (msie > 0) { // IE 10 or older => return version number return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)), 10); } const trident = ua.indexOf("Trident/"); if (trident > 0) { // IE 11 => return version number const rv = ua.indexOf("rv:"); return parseInt(ua.substring(rv + 3, ua.indexOf(".", rv)), 10); } const edge = ua.indexOf("Edge/"); if (edge > 0) { // Edge (IE 12+) => return version number return parseInt(ua.substring(edge + 5, ua.indexOf(".", edge)), 10); } // Other browser return false;} function isNumber(val) { return !isNaN(parseFloat(val)) && isFinite(val);} function toHex(val, leftPadding) { if (leftPadding === undefined) leftPadding = 4; const isNegative = val < 0; return (isNegative ? "-" : "") + "0x" + Math.abs(val).toString(16).padLeft(leftPadding, "0").toUpperCase();} function isBool(val) { if (typeof value === "boolean") return true; const lval = val.toString().toLowerCase(); return lval === "true" || lval === "false";} function getBool(val) { const num = +val; return !isNaN(num) ? !!num : !!String(val).toLowerCase().replace(false, "");} function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ""; return decodeURIComponent(results[2].replace(/\+/g, " "));} function clearCachedCredentials(securedUrl, successCallback) { if (isIE) { document.execCommand("ClearAuthenticationCache", "false"); if (successCallback) successCallback(true); } else { const xhr = new XMLHttpRequest(); xhr.open("GET", securedUrl, true); xhr.setRequestHeader("Content-type", "application/json"); // Send in an invalid set of credentials, i.e., base64 encoded _logout:_logout: xhr.setRequestHeader("Authorization", "Basic X2xvZ291dDpfbG9nb3V0"); if (successCallback) xhr.onreadystatechange = function() { if (this.readyState === XMLHttpRequest.DONE) successCallback(this.status === 200, this.responseText); }; xhr.send(); }} const persistentStorage = (function() { function storageAvailable(type) { var storage = []; try { storage = window[type]; const x = "__storage_test__"; storage.setItem(x, x); storage.removeItem(x); return true; } catch (e) { return e instanceof DOMException && ( // everything except Firefox e.code === 22 || // Firefox e.code === 1014 || // test name field too, because code might not be present // everything except Firefox e.name === "QuotaExceededError" || // Firefox e.name === "NS_ERROR_DOM_QUOTA_REACHED" ) && // acknowledge QuotaExceededError only if there's something already stored storage.length !== 0; } } function fakeStorage() { return { getItem: function() {}, setItem: function() {}, removeItem: function() {} }; } if (storageAvailable("localStorage")) return localStorage; else return fakeStorage();})(); // Number functionsNumber.prototype.truncate = function() { if (typeof Math.trunc !== "function") return parseInt(this.toString()); return Math.trunc(this);}; Number.prototype.padLeft = function(totalWidth, paddingChar) { return this.truncate().toString().padLeft(totalWidth, paddingChar || "0");}; Number.prototype.padRight = function(totalWidth, paddingChar) { return this.truncate().toString().padRight(totalWidth, paddingChar || "0");}; // Array functions // Combines a dictionary of key-value pairs into a string. Values will be escaped within startValueDelimiter and endValueDelimiter// to contain nested key/value pair expressions like the following: "normalKVP=-1; nestedKVP={p1=true; p2=0.001}" when either the// parameterDelimiter or the keyValueDelimiter are detected in the value of the key/value pair.function joinKeyValuePairs(source, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { if (!parameterDelimiter) parameterDelimiter = ";"; if (!keyValueDelimiter) keyValueDelimiter = "="; if (!startValueDelimiter) startValueDelimiter = "{"; if (!endValueDelimiter) endValueDelimiter = "}"; const values = []; for (let key in source) { if (source.hasOwnProperty(key)) { let value = source[key]; if (isBool(value)) value = value.toString().toLowerCase(); else value = value ? value.toString() : ""; if (value.indexOf(parameterDelimiter) >= 0 || value.indexOf(keyValueDelimiter) >= 0 || value.indexOf(startValueDelimiter) >= 0 || value.indexOf(endValueDelimiter) >= 0) value = startValueDelimiter + value + endValueDelimiter; values.push(key + keyValueDelimiter + value); } } return values.join(parameterDelimiter + " ");} Array.prototype.joinKeyValuePairs = function(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { return joinKeyValuePairs(this, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter); }; Array.prototype.forEachWithDelay = function(iterationCallback, timeout, completedCallback, thisArg) { var index = 0, count = this.length, self = this, next = function() { if (self[index]) iterationCallback.call(thisArg || self, self[index], index, self); index++; if (index < count) setTimeout(next, timeout); else completedCallback.call(thisArg || self, self); }; next();}; if (!Array.prototype.any) { if (Array.prototype.some) { Array.prototype.any = Array.prototype.some; } else { Array.prototype.any = function(callback, thisArg) { var args; if (this === null) throw new TypeError("this is null or not defined"); const array = Object(this); const length = array.length >>> 0; // Convert array length to positive integer if (typeof callback !== "function") throw new TypeError(); if (arguments.length > 1) args = thisArg; else args = undefined; var index = 0; while (index < length) { if (index in array) { const element = array[index]; if (callback.call(args, element, index, array)) return true; } index++; } return false; }; }} if (!Array.prototype.count) { Array.prototype.count = function (callback, thisArg) { var args; if (this === null) throw new TypeError("this is null or not defined"); const array = Object(this); const length = array.length >>> 0; // Convert array length to positive integer if (typeof callback !== "function") throw new TypeError(); if (arguments.length > 1) args = thisArg; else args = undefined; var index = 0; var count = 0; while (index < length) { if (index in array) { const element = array[index]; if (callback.call(args, element, index, array)) count++; } index++; } return count; };} // Represents a dictionary style class with case-insensitive keysfunction Dictionary(source) { const self = this; if (!source) source = []; self._keys = []; self._values = []; self.count = function() { var size = 0; for (let property in self._values) { if (self._values.hasOwnProperty(property)) size++; } return size; }; self.keys = function() { const keys = []; for (let property in self._keys) { if (self._keys.hasOwnProperty(property)) keys.push(self._keys[property]); } return keys; }; self.values = function() { const values = []; for (let property in self._values) { if (self._keys.hasOwnProperty(property)) values.push(self._values[property]); } return values; }; self.get = function(key) { return self._values[String(key).toLowerCase()]; }; self.set = function(key, value) { const lkey = String(key).toLowerCase(); if (!self._keys[lkey] || self._keys[lkey].toLowerCase() !== key) self._keys[lkey] = key; if (isBool(value)) self._values[lkey] = getBool(value); else self._values[lkey] = value; }; self.remove = function(key) { const lkey = String(key).toLowerCase(); delete self._keys[lkey]; delete self._values[lkey]; }; self.containsKey = function(key) { const lkey = String(key).toLowerCase(); for (let property in self._values) { if (self._values.hasOwnProperty(property) && property === lkey) return true; } return false; }; self.containsValue = function(value) { for (let property in self._values) { if (self._values.hasOwnProperty(property) && self._values[property] === value) return true; } return false; }; self.clear = function() { self._keys = []; self._values = []; }; self.joinKeyValuePairs = function(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { const keyValuePairs = []; for (let property in self._values) { if (self._values.hasOwnProperty(property)) keyValuePairs[self._keys[property]] = self._values[property]; } return keyValuePairs.joinKeyValuePairs(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter); }; self.pushAll = function(source) { for (let property in source) if (source.hasOwnProperty(property)) self.set(property, source[property]); }; self.toObservableDictionary = function(useLowerKeys) { // See ko.observableDictionary.js const observableDictionary = new ko.observableDictionary(); for (let property in self._values) { if (self._values.hasOwnProperty(property)) observableDictionary.push(useLowerKeys ? property : self._keys[property], self._values[property]); } return observableDictionary; }; self.updateObservableDictionary = function(observableDictionary, useLowerKeys) { for (let property in self._values) { if (self._values.hasOwnProperty(property)) observableDictionary.set(useLowerKeys ? property : self._keys[property], self._values[property]); } }; // Construction if (source instanceof Dictionary) { for (let property in source._values) if (source._values.hasOwnProperty(property)) self.set(source._keys[property], source._values[property]); } else { for (let property in source) { if (source.hasOwnProperty(property)) self.set(property, source[property]); } }} Dictionary.fromObservableDictionary = function(observableDictionary) { const dictionary = new Dictionary(); dictionary.pushAll(observableDictionary.toJSON()); return dictionary;}; // String functionsfunction isEmpty(str) { return !str || String(str).length === 0;} String.prototype.trimLeft = String.prototype.trimLeft ||Lines 1–500 of 1213. Load more
//****************************************************************************************************** // gsf.web.client.js - Gbtc // // Copyright © 2016, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 01/26/2016 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** // ReSharper disable NativeTypePrototypeExtending // ReSharper disable UndeclaredGlobalVariableUsing // Grid Solutions Framework Core Web Client Script Functions "use strict"; if (typeof jQuery === "undefined") { throw new Error("gsf.web.client script requires jQuery - make sure jquery.js is loaded first"); } const isIE = detectIE(); var textMetrics; $(function() { // Create a canvas object that will be used for text metrics calculations $("<canvas id=\"textMetricsCanvas\" height=\"1px\" width=\"1px\" style=\"visibility: hidden\"></canvas>") .appendTo("body"); // Get text metrics canvas context textMetrics = document.getElementById("textMetricsCanvas").getContext("2d"); }); // Miscellaneous functions function notNull(value, nonNullValue) { return value || (nonNullValue || ""); } function detectIE() { const ua = window.navigator.userAgent; const msie = ua.indexOf("MSIE "); if (msie > 0) { // IE 10 or older => return version number return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)), 10); } const trident = ua.indexOf("Trident/"); if (trident > 0) { // IE 11 => return version number const rv = ua.indexOf("rv:"); return parseInt(ua.substring(rv + 3, ua.indexOf(".", rv)), 10); } const edge = ua.indexOf("Edge/"); if (edge > 0) { // Edge (IE 12+) => return version number return parseInt(ua.substring(edge + 5, ua.indexOf(".", edge)), 10); } // Other browser return false; } function isNumber(val) { return !isNaN(parseFloat(val)) && isFinite(val); } function toHex(val, leftPadding) { if (leftPadding === undefined) leftPadding = 4; const isNegative = val < 0; return (isNegative ? "-" : "") + "0x" + Math.abs(val).toString(16).padLeft(leftPadding, "0").toUpperCase(); } function isBool(val) { if (typeof value === "boolean") return true; const lval = val.toString().toLowerCase(); return lval === "true" || lval === "false"; } function getBool(val) { const num = +val; return !isNaN(num) ? !!num : !!String(val).toLowerCase().replace(false, ""); } function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ""; return decodeURIComponent(results[2].replace(/\+/g, " ")); } function clearCachedCredentials(securedUrl, successCallback) { if (isIE) { document.execCommand("ClearAuthenticationCache", "false"); if (successCallback) successCallback(true); } else { const xhr = new XMLHttpRequest(); xhr.open("GET", securedUrl, true); xhr.setRequestHeader("Content-type", "application/json"); // Send in an invalid set of credentials, i.e., base64 encoded _logout:_logout: xhr.setRequestHeader("Authorization", "Basic X2xvZ291dDpfbG9nb3V0"); if (successCallback) xhr.onreadystatechange = function() { if (this.readyState === XMLHttpRequest.DONE) successCallback(this.status === 200, this.responseText); }; xhr.send(); } } const persistentStorage = (function() { function storageAvailable(type) { var storage = []; try { storage = window[type]; const x = "__storage_test__"; storage.setItem(x, x); storage.removeItem(x); return true; } catch (e) { return e instanceof DOMException && ( // everything except Firefox e.code === 22 || // Firefox e.code === 1014 || // test name field too, because code might not be present // everything except Firefox e.name === "QuotaExceededError" || // Firefox e.name === "NS_ERROR_DOM_QUOTA_REACHED" ) && // acknowledge QuotaExceededError only if there's something already stored storage.length !== 0; } } function fakeStorage() { return { getItem: function() {}, setItem: function() {}, removeItem: function() {} }; } if (storageAvailable("localStorage")) return localStorage; else return fakeStorage(); })(); // Number functions Number.prototype.truncate = function() { if (typeof Math.trunc !== "function") return parseInt(this.toString()); return Math.trunc(this); }; Number.prototype.padLeft = function(totalWidth, paddingChar) { return this.truncate().toString().padLeft(totalWidth, paddingChar || "0"); }; Number.prototype.padRight = function(totalWidth, paddingChar) { return this.truncate().toString().padRight(totalWidth, paddingChar || "0"); }; // Array functions // Combines a dictionary of key-value pairs into a string. Values will be escaped within startValueDelimiter and endValueDelimiter // to contain nested key/value pair expressions like the following: "normalKVP=-1; nestedKVP={p1=true; p2=0.001}" when either the // parameterDelimiter or the keyValueDelimiter are detected in the value of the key/value pair. function joinKeyValuePairs(source, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { if (!parameterDelimiter) parameterDelimiter = ";"; if (!keyValueDelimiter) keyValueDelimiter = "="; if (!startValueDelimiter) startValueDelimiter = "{"; if (!endValueDelimiter) endValueDelimiter = "}"; const values = []; for (let key in source) { if (source.hasOwnProperty(key)) { let value = source[key]; if (isBool(value)) value = value.toString().toLowerCase(); else value = value ? value.toString() : ""; if (value.indexOf(parameterDelimiter) >= 0 || value.indexOf(keyValueDelimiter) >= 0 || value.indexOf(startValueDelimiter) >= 0 || value.indexOf(endValueDelimiter) >= 0) value = startValueDelimiter + value + endValueDelimiter; values.push(key + keyValueDelimiter + value); } } return values.join(parameterDelimiter + " "); } Array.prototype.joinKeyValuePairs = function(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { return joinKeyValuePairs(this, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter); }; Array.prototype.forEachWithDelay = function(iterationCallback, timeout, completedCallback, thisArg) { var index = 0, count = this.length, self = this, next = function() { if (self[index]) iterationCallback.call(thisArg || self, self[index], index, self); index++; if (index < count) setTimeout(next, timeout); else completedCallback.call(thisArg || self, self); }; next(); }; if (!Array.prototype.any) { if (Array.prototype.some) { Array.prototype.any = Array.prototype.some; } else { Array.prototype.any = function(callback, thisArg) { var args; if (this === null) throw new TypeError("this is null or not defined"); const array = Object(this); const length = array.length >>> 0; // Convert array length to positive integer if (typeof callback !== "function") throw new TypeError(); if (arguments.length > 1) args = thisArg; else args = undefined; var index = 0; while (index < length) { if (index in array) { const element = array[index]; if (callback.call(args, element, index, array)) return true; } index++; } return false; }; } } if (!Array.prototype.count) { Array.prototype.count = function (callback, thisArg) { var args; if (this === null) throw new TypeError("this is null or not defined"); const array = Object(this); const length = array.length >>> 0; // Convert array length to positive integer if (typeof callback !== "function") throw new TypeError(); if (arguments.length > 1) args = thisArg; else args = undefined; var index = 0; var count = 0; while (index < length) { if (index in array) { const element = array[index]; if (callback.call(args, element, index, array)) count++; } index++; } return count; }; } // Represents a dictionary style class with case-insensitive keys function Dictionary(source) { const self = this; if (!source) source = []; self._keys = []; self._values = []; self.count = function() { var size = 0; for (let property in self._values) { if (self._values.hasOwnProperty(property)) size++; } return size; }; self.keys = function() { const keys = []; for (let property in self._keys) { if (self._keys.hasOwnProperty(property)) keys.push(self._keys[property]); } return keys; }; self.values = function() { const values = []; for (let property in self._values) { if (self._keys.hasOwnProperty(property)) values.push(self._values[property]); } return values; }; self.get = function(key) { return self._values[String(key).toLowerCase()]; }; self.set = function(key, value) { const lkey = String(key).toLowerCase(); if (!self._keys[lkey] || self._keys[lkey].toLowerCase() !== key) self._keys[lkey] = key; if (isBool(value)) self._values[lkey] = getBool(value); else self._values[lkey] = value; }; self.remove = function(key) { const lkey = String(key).toLowerCase(); delete self._keys[lkey]; delete self._values[lkey]; }; self.containsKey = function(key) { const lkey = String(key).toLowerCase(); for (let property in self._values) { if (self._values.hasOwnProperty(property) && property === lkey) return true; } return false; }; self.containsValue = function(value) { for (let property in self._values) { if (self._values.hasOwnProperty(property) && self._values[property] === value) return true; } return false; }; self.clear = function() { self._keys = []; self._values = []; }; self.joinKeyValuePairs = function(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) { const keyValuePairs = []; for (let property in self._values) { if (self._values.hasOwnProperty(property)) keyValuePairs[self._keys[property]] = self._values[property]; } return keyValuePairs.joinKeyValuePairs(parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter); }; self.pushAll = function(source) { for (let property in source) if (source.hasOwnProperty(property)) self.set(property, source[property]); }; self.toObservableDictionary = function(useLowerKeys) { // See ko.observableDictionary.js const observableDictionary = new ko.observableDictionary(); for (let property in self._values) { if (self._values.hasOwnProperty(property)) observableDictionary.push(useLowerKeys ? property : self._keys[property], self._values[property]); } return observableDictionary; }; self.updateObservableDictionary = function(observableDictionary, useLowerKeys) { for (let property in self._values) { if (self._values.hasOwnProperty(property)) observableDictionary.set(useLowerKeys ? property : self._keys[property], self._values[property]); } }; // Construction if (source instanceof Dictionary) { for (let property in source._values) if (source._values.hasOwnProperty(property)) self.set(source._keys[property], source._values[property]); } else { for (let property in source) { if (source.hasOwnProperty(property)) self.set(property, source[property]); } } } Dictionary.fromObservableDictionary = function(observableDictionary) { const dictionary = new Dictionary(); dictionary.pushAll(observableDictionary.toJSON()); return dictionary; }; // String functions function isEmpty(str) { return !str || String(str).length === 0; } String.prototype.trimLeft = String.prototype.trimLeft ||