UNPKG

@progress/telerik-jquery-report-viewer

Version:

Progress® Telerik® Report Viewer for jQuery

490 lines (486 loc) 13 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var stringFormatRegExp = /{(\w+?)}/g; var specialKeys = { DELETE: 46, BACKSPACE: 8, TAB: 9, ESC: 27, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, END: 35, HOME: 36 }; function isSpecialKey() { var userAgent = window.navigator.userAgent.toLowerCase(); if (userAgent.indexOf("firefox") > -1) { var specialKeysArray = Object.keys(specialKeys); var specialKeysLength = specialKeysArray.length; return function(keyCode) { for (var i = 0; i < specialKeysLength; i++) { if (specialKeys[specialKeysArray[i]] == keyCode) { return true; } } }; } return function(keyCode) { return false; }; } function toXhrErrorData(xhr, status, error) { return { xhr, status, error }; } function rectangle(left, top, width, height) { return { left, top, width, height, right: function() { return left + width; }, bottom: function() { return top + height; }, union: function(other) { var newLeft = Math.min(left, other.left); var newTop = Math.min(top, other.top); var newWidth = Math.max(this.right(), other.right()) - newLeft; var newHeight = Math.max(this.bottom(), other.bottom()) - newTop; return rectangle( newLeft, newTop, newWidth, newHeight ); } }; } function generateGuidString() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0; var v = c == "x" ? r : r & 3 | 8; return v.toString(16); }); } function trim(s, charlist) { return rTrim(lTrim(s, charlist), charlist); } function replaceAll(str, find, replace) { return str.replace(new RegExp(find, "g"), replace); } function lTrim(s, charlist) { if (charlist === void 0) { charlist = "s"; } return s.replace(new RegExp("^[" + charlist + "]+"), ""); } function rTrim(s, charlist) { if (charlist === void 0) { charlist = "s"; } return s.replace(new RegExp("[" + charlist + "]+$"), ""); } function stringFormat(template, data) { var isArray2 = Array.isArray(data); return template.replace(stringFormatRegExp, function($0, $1) { return data[isArray2 ? parseInt($1) : $1]; }); } function escapeHtml(str) { return $("<div>").text(str).html(); } function tryParseInt(value) { if (/^(\-|\+)?([0-9]+)$/.test(value)) { return Number(value); } return NaN; } function tryParseFloat(value) { if (/^(\-|\+)?([0-9]+(\.[0-9]+)?)$/.test(value)) { return Number(value); } return NaN; } function parseToLocalDate(date) { if (date instanceof Date) return date; var isUtc = /Z|[\+\-]\d\d:?\d\d/i.test(date); if (!isUtc) { date += "Z"; } return new Date(date); } function adjustTimezone(date) { return new Date( Date.UTC( date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds() ) ); } function unadjustTimezone(date) { return new Date( date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds() ); } function areEqual(v1, v2) { if (v1 instanceof Date && v2 instanceof Date) { if (v1.getTime() !== v2.getTime()) { return false; } } else if (v1 !== v2) { return false; } return true; } function reportSourcesAreEqual(rs1, rs2) { if (rs1 && rs2 && rs1.report === rs2.report) { var params1String = ""; if (rs1.parameters) { params1String = JSON.stringify(rs1.parameters); } var params2String = ""; if (rs2.parameters) { params2String = JSON.stringify(rs2.parameters); } return params1String === params2String; } return false; } function areEqualArrays(array1, array2) { if (array1 === null) { if (array2 !== null) { return false; } return true; } if (array2 === null) { return false; } if (array1.length !== array2.length) { return false; } for (var j = array1.length - 1; j >= 0; j--) { if (!areEqual(array1[j], array2[j])) { return false; } } return true; } function isSvgSupported() { var matches = /Version\/(\d+.\d+.\d+) Safari/.exec(navigator.userAgent); if (matches && matches.length > 1) { var version = parseFloat(matches[1]); return version >= 6; } return true; } function isInternalServerError(error) { if (error) { return replaceAll(error, " ", "").toLowerCase() === "internalservererror"; } return false; } function isSystemArgumentException(xhr) { var exceptionShortName = "ArgumentException"; var exceptionInstance = getExceptionInstance(xhr); return isExceptionInstanceOfType(exceptionInstance, exceptionShortName, "System." + exceptionShortName); } function isInvalidClientException(xhr) { var exceptionShortName = "InvalidClientException"; var exceptionInstance = getExceptionInstance(xhr); return isExceptionInstanceOfType(exceptionInstance, exceptionShortName, "Telerik.Reporting.Services.Engine." + exceptionShortName); } function isApplicationException(xhr) { return isApplicationExceptionInstance(getExceptionInstance(xhr)); } function isApplicationExceptionInstance(exception) { var exceptionShortName = "DrawingFactoryUnavailableException"; return isExceptionInstanceOfType(exception, exceptionShortName, "Telerik.Drawing.Contract." + exceptionShortName); } function isExceptionOfType(xhr, exceptionType) { return isExceptionInstanceOfType(getExceptionInstance(xhr), exceptionType, exceptionType); } function isExceptionInstanceOfType(exceptionInstance, exceptionTypeShortName, exceptionTypeFullName) { return exceptionInstance && exceptionInstance.exceptionType && exceptionTypeNamesMatch(exceptionInstance.exceptionType, exceptionTypeShortName, exceptionTypeFullName); } function exceptionTypeNamesMatch(instanceTypeName, exceptionTypeShortName, exceptionTypeFullName) { return instanceTypeName && (instanceTypeName === exceptionTypeFullName || instanceTypeName.endsWith(exceptionTypeShortName)); } function parseJSON(json) { try { return JSON.parse( json, function(key, value) { if (key && value) { var firstChar = key.charAt(0); if (firstChar === firstChar.toUpperCase()) { var newPropertyName = firstChar.toLowerCase() + key.slice(1); this[newPropertyName] = value; } } return value; } ); } catch (e) { return null; } } function getExceptionInstance(xhr) { if (!xhr || !xhr.responseText) { return false; } return parseJSON(xhr.responseText); } function extend() { var copy; var name; var options; var target; var i = 0; var length = arguments.length; target = length > 1 ? arguments[i++] || {} : {}; for (; i < length; i++) { if ((options = arguments[i]) != null) { for (name in options) { target[name]; copy = options[name]; if (target === copy) { continue; } if (copy !== void 0) { target[name] = copy; } } } } return target; } function each(obj, callback) { var length; var i = 0; if (isArray(obj)) { length = obj.length; for (; i < length; i++) { if (callback.call(obj[i], i, obj[i]) === false) { break; } } } else { for (i in obj) { if (callback.call(obj[i], i, obj[i]) === false) { break; } } } return obj; } function selector() { return document.querySelectorAll(arguments[0]); } function isArray(obj) { if (Array.isArray(obj)) return true; var length = Boolean(obj) && "length" in obj && obj.length; if (typeof length === "number") { return true; } return false; } function loadScriptWithCallback(src, done, version) { var js = document.createElement("script"); js.src = src; js.onload = function() { done(version); }; js.onerror = function() { logError(new Error("Failed to load script " + src)); }; document.head.appendChild(js); } function loadScript(url) { var ajaxOptions = { dataType: "script", cache: true }; return $ajax(url, ajaxOptions); } function filterUniqueLastOccurrence(array) { function onlyLastUnique(value, index, self) { return self.lastIndexOf(value) === index; } return array.filter(onlyLastUnique); } function logError(error) { var console = window.console; if (console && console.error) { console.error(error); } } function findElement(selectorChain) { if (selectorChain.constructor != Array) { selectorChain = [selectorChain]; } var $area = $(selectorChain[0]); for (var i = 1; i < selectorChain.length; i++) { $area = $area.find(selectorChain[i]); } return $area; } function toRgbColor(hexColor) { if (hexColor && hexColor.length < 6) { var index = 1; var hexParts = hexColor.split(""); if (hexParts[0] !== "#") { index = 0; } for (index; index < hexParts.length; index++) { hexParts[index] = hexParts[index] + hexParts[index]; } hexColor = hexParts.join(""); } var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor); return result ? parseInt(result[1], 16) + ", " + parseInt(result[2], 16) + ", " + parseInt(result[3], 16) : null; } function isRgbColor(color) { if (!color) { return false; } return color.indexOf(",") > -1 ? true : false; } function getColorAlphaValue(color) { if (color.toLowerCase() === "transparent") { return 0; } if (!isRgbColor(color)) { return 1; } if (color.indexOf("#") !== -1) { color = toRgbColor(color); } var colorComponents = color.split(",").map(function(c) { return c.trim(); }); var alpha = colorComponents.length === 4 ? parseFloat((parseFloat(colorComponents[3].replace(/[()]/g, "")) / 255).toFixed(2)) : 1; return alpha; } function $ajax(url, ajaxSettings) { return new Promise(function(resolve, reject) { $.ajax(url, ajaxSettings).done(function(data) { return resolve(data); }).fail(function(xhr, status, error) { reject(toXhrErrorData(xhr, status, error)); }); }); } function type(obj) { return Object.prototype.toString.call(obj).slice(8, -1); } function isEqual(a, b) { if (a === b) { return true; } if (a !== a && b !== b) { return true; } if (a !== a && b === b || a === a && b !== b) { return false; } const typeA = type(a); const typeB = type(b); if (typeA !== typeB) { return false; } if (typeA === "Array") { if (a.length !== b.length) { return false; } const length = a.length; for (let i = 0; i < length; i++) { if (!isEqual(a[i], b[i])) { return false; } } return true; } if (typeA === "Object") { const keysA = Object.keys(a); const keysB = Object.keys(b); if (keysA.length !== keysB.length) { return false; } const length = keysA.length; for (let i = 0; i < length; i++) { const key = keysA[i]; if (!isEqual(a[key], b[key])) { return false; } } return true; } if (typeA === "Date") { return a.getTime() === b.getTime(); } return false; } exports.$ajax = $ajax; exports.adjustTimezone = adjustTimezone; exports.areEqual = areEqual; exports.areEqualArrays = areEqualArrays; exports.each = each; exports.escapeHtml = escapeHtml; exports.exceptionTypeNamesMatch = exceptionTypeNamesMatch; exports.extend = extend; exports.filterUniqueLastOccurrence = filterUniqueLastOccurrence; exports.findElement = findElement; exports.generateGuidString = generateGuidString; exports.getColorAlphaValue = getColorAlphaValue; exports.getExceptionInstance = getExceptionInstance; exports.isApplicationException = isApplicationException; exports.isApplicationExceptionInstance = isApplicationExceptionInstance; exports.isArray = isArray; exports.isEqual = isEqual; exports.isExceptionOfType = isExceptionOfType; exports.isInternalServerError = isInternalServerError; exports.isInvalidClientException = isInvalidClientException; exports.isRgbColor = isRgbColor; exports.isSpecialKey = isSpecialKey; exports.isSvgSupported = isSvgSupported; exports.isSystemArgumentException = isSystemArgumentException; exports.lTrim = lTrim; exports.loadScript = loadScript; exports.loadScriptWithCallback = loadScriptWithCallback; exports.logError = logError; exports.parseJSON = parseJSON; exports.parseToLocalDate = parseToLocalDate; exports.rTrim = rTrim; exports.rectangle = rectangle; exports.replaceAll = replaceAll; exports.reportSourcesAreEqual = reportSourcesAreEqual; exports.selector = selector; exports.stringFormat = stringFormat; exports.toRgbColor = toRgbColor; exports.trim = trim; exports.tryParseFloat = tryParseFloat; exports.tryParseInt = tryParseInt; exports.type = type; exports.unadjustTimezone = unadjustTimezone;