@microsoft/office-js
Version:
Office JavaScript APIs
1,094 lines (1,087 loc) • 1.48 MB
JavaScript
/*
Copyright (c) Microsoft Corporation. All rights reserved.
*/
/*
Your use of this file is governed by the Microsoft Services Agreement http://go.microsoft.com/fwlink/?LinkId=266419.
*/
/*
* @overview es6-promise - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
* @version 2.3.0
*/
// Sources:
// osfweb: 16.0\16.0.15407.10000
// runtime: 16.0\16.0.15407.10000
// core: 16.0\16.0.15407.10000
// host: 16.0\16.0.15407.10000
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var OfficeExt;
(function (OfficeExt) {
var MicrosoftAjaxFactory = (function () {
function MicrosoftAjaxFactory() {
}
MicrosoftAjaxFactory.prototype.isMsAjaxLoaded = function () {
if (typeof (Sys) !== 'undefined' && typeof (Type) !== 'undefined' &&
Sys.StringBuilder && typeof (Sys.StringBuilder) === "function" &&
Type.registerNamespace && typeof (Type.registerNamespace) === "function" &&
Type.registerClass && typeof (Type.registerClass) === "function" &&
typeof (Function._validateParams) === "function" &&
Sys.Serialization && Sys.Serialization.JavaScriptSerializer && typeof (Sys.Serialization.JavaScriptSerializer.serialize) === "function") {
return true;
}
else {
return false;
}
};
MicrosoftAjaxFactory.prototype.loadMsAjaxFull = function (callback) {
var msAjaxCDNPath = (window.location.protocol.toLowerCase() === 'https:' ? 'https:' : 'http:') + '//ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js';
OSF.OUtil.loadScript(msAjaxCDNPath, callback);
};
Object.defineProperty(MicrosoftAjaxFactory.prototype, "msAjaxError", {
get: function () {
if (this._msAjaxError == null && this.isMsAjaxLoaded()) {
this._msAjaxError = Error;
}
return this._msAjaxError;
},
set: function (errorClass) {
this._msAjaxError = errorClass;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MicrosoftAjaxFactory.prototype, "msAjaxString", {
get: function () {
if (this._msAjaxString == null && this.isMsAjaxLoaded()) {
this._msAjaxString = String;
}
return this._msAjaxString;
},
set: function (stringClass) {
this._msAjaxString = stringClass;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MicrosoftAjaxFactory.prototype, "msAjaxDebug", {
get: function () {
if (this._msAjaxDebug == null && this.isMsAjaxLoaded()) {
this._msAjaxDebug = Sys.Debug;
}
return this._msAjaxDebug;
},
set: function (debugClass) {
this._msAjaxDebug = debugClass;
},
enumerable: true,
configurable: true
});
return MicrosoftAjaxFactory;
}());
OfficeExt.MicrosoftAjaxFactory = MicrosoftAjaxFactory;
})(OfficeExt || (OfficeExt = {}));
var OsfMsAjaxFactory = new OfficeExt.MicrosoftAjaxFactory();
var OSF = OSF || {};
(function (OfficeExt) {
var SafeStorage = (function () {
function SafeStorage(_internalStorage) {
this._internalStorage = _internalStorage;
}
SafeStorage.prototype.getItem = function (key) {
try {
return this._internalStorage && this._internalStorage.getItem(key);
}
catch (e) {
return null;
}
};
SafeStorage.prototype.setItem = function (key, data) {
try {
this._internalStorage && this._internalStorage.setItem(key, data);
}
catch (e) {
}
};
SafeStorage.prototype.clear = function () {
try {
this._internalStorage && this._internalStorage.clear();
}
catch (e) {
}
};
SafeStorage.prototype.removeItem = function (key) {
try {
this._internalStorage && this._internalStorage.removeItem(key);
}
catch (e) {
}
};
SafeStorage.prototype.getKeysWithPrefix = function (keyPrefix) {
var keyList = [];
try {
var len = this._internalStorage && this._internalStorage.length || 0;
for (var i = 0; i < len; i++) {
var key = this._internalStorage.key(i);
if (key.indexOf(keyPrefix) === 0) {
keyList.push(key);
}
}
}
catch (e) {
}
return keyList;
};
SafeStorage.prototype.isLocalStorageAvailable = function () {
return (this._internalStorage != null);
};
return SafeStorage;
}());
OfficeExt.SafeStorage = SafeStorage;
})(OfficeExt || (OfficeExt = {}));
OSF.XdmFieldName = {
ConversationUrl: "ConversationUrl",
AppId: "AppId"
};
OSF.TestFlightStart = 1000;
OSF.TestFlightEnd = 1009;
OSF.FlightNames = {
UseOriginNotUrl: 0,
AddinEnforceHttps: 2,
FirstPartyAnonymousProxyReadyCheckTimeout: 6,
AddinRibbonIdAllowUnknown: 9,
ManifestParserDevConsoleLog: 15,
AddinActionDefinitionHybridMode: 18,
UseActionIdForUILessCommand: 20,
RequirementSetRibbonApiOnePointTwo: 21,
SetFocusToTaskpaneIsEnabled: 22,
ShortcutInfoArrayInUserPreferenceData: 23,
OSFTestFlight1000: OSF.TestFlightStart,
OSFTestFlight1001: OSF.TestFlightStart + 1,
OSFTestFlight1002: OSF.TestFlightStart + 2,
OSFTestFlight1003: OSF.TestFlightStart + 3,
OSFTestFlight1004: OSF.TestFlightStart + 4,
OSFTestFlight1005: OSF.TestFlightStart + 5,
OSFTestFlight1006: OSF.TestFlightStart + 6,
OSFTestFlight1007: OSF.TestFlightStart + 7,
OSFTestFlight1008: OSF.TestFlightStart + 8,
OSFTestFlight1009: OSF.TestFlightEnd
};
OSF.TrustUXFlightValues = {
TrustUXControlA: 0,
TrustUXExperimentB: 1,
TrustUXExperimentC: 2
};
OSF.FlightTreatmentNames = {
AddinDialogIFrameContentWindowKillSwitch: "Microsoft.Office.SharedOnline.AddinDialogIFrameContentWindowKillSwitch",
AddinTrustUXImprovement: "Microsoft.Office.SharedOnline.AddinTrustUXImprovement",
AllowStorageAccessByUserActivationOnIFrameCheck: "Microsoft.Office.SharedOnline.AllowStorageAccessByUserActivationOnIFrameCheck",
BlockAutoOpenAddInIfStoreDisabled: "Microsoft.Office.SharedOnline.BlockAutoOpenAddInIfStoreDisabled",
CheckProxyIsReadyRetry: "Microsoft.Office.SharedOnline.OEP.CheckProxyIsReadyRetry",
InsertionDialogFixesEnabled: "Microsoft.Office.SharedOnline.InsertionDialogFixesEnabled",
TeachingUIForPrivateCatelogEnabled: "Microsoft.Office.SharedOnline.TeachingUIForPrivateCatelogEnabled",
WopiPreinstalledAddInsEnabled: "Microsoft.Office.SharedOnline.WopiPreinstalledAddInsEnabled",
WopiUseNewActivate: "Microsoft.Office.SharedOnline.WopiUseNewActivate",
MosManifestEnabled: "Microsoft.Office.SharedOnline.OEP.MosManifest"
};
OSF.Flights = [];
OSF.IntFlights = {};
OSF.Settings = {};
OSF.WindowNameItemKeys = {
BaseFrameName: "baseFrameName",
HostInfo: "hostInfo",
XdmInfo: "xdmInfo",
SerializerVersion: "serializerVersion",
AppContext: "appContext",
Flights: "flights"
};
OSF.OUtil = (function () {
var _uniqueId = -1;
var _xdmInfoKey = '&_xdm_Info=';
var _serializerVersionKey = '&_serializer_version=';
var _flightsKey = '&_flights=';
var _xdmSessionKeyPrefix = '_xdm_';
var _serializerVersionKeyPrefix = '_serializer_version=';
var _flightsKeyPrefix = '_flights=';
var _fragmentSeparator = '#';
var _fragmentInfoDelimiter = '&';
var _classN = "class";
var _loadedScripts = {};
var _defaultScriptLoadingTimeout = 30000;
var _safeSessionStorage = null;
var _safeLocalStorage = null;
var _rndentropy = new Date().getTime();
function _random() {
var nextrand = 0x7fffffff * (Math.random());
nextrand ^= _rndentropy ^ ((new Date().getMilliseconds()) << Math.floor(Math.random() * (31 - 10)));
return nextrand.toString(16);
}
;
function _getSessionStorage() {
if (!_safeSessionStorage) {
try {
var sessionStorage = window.sessionStorage;
}
catch (ex) {
sessionStorage = null;
}
_safeSessionStorage = new OfficeExt.SafeStorage(sessionStorage);
}
return _safeSessionStorage;
}
;
function _reOrderTabbableElements(elements) {
var bucket0 = [];
var bucketPositive = [];
var i;
var len = elements.length;
var ele;
for (i = 0; i < len; i++) {
ele = elements[i];
if (ele.tabIndex) {
if (ele.tabIndex > 0) {
bucketPositive.push(ele);
}
else if (ele.tabIndex === 0) {
bucket0.push(ele);
}
}
else {
bucket0.push(ele);
}
}
bucketPositive = bucketPositive.sort(function (left, right) {
var diff = left.tabIndex - right.tabIndex;
if (diff === 0) {
diff = bucketPositive.indexOf(left) - bucketPositive.indexOf(right);
}
return diff;
});
return [].concat(bucketPositive, bucket0);
}
;
return {
set_entropy: function OSF_OUtil$set_entropy(entropy) {
if (typeof entropy == "string") {
for (var i = 0; i < entropy.length; i += 4) {
var temp = 0;
for (var j = 0; j < 4 && i + j < entropy.length; j++) {
temp = (temp << 8) + entropy.charCodeAt(i + j);
}
_rndentropy ^= temp;
}
}
else if (typeof entropy == "number") {
_rndentropy ^= entropy;
}
else {
_rndentropy ^= 0x7fffffff * Math.random();
}
_rndentropy &= 0x7fffffff;
},
extend: function OSF_OUtil$extend(child, parent) {
var F = function () { };
F.prototype = parent.prototype;
child.prototype = new F();
child.prototype.constructor = child;
child.uber = parent.prototype;
if (parent.prototype.constructor === Object.prototype.constructor) {
parent.prototype.constructor = parent;
}
},
setNamespace: function OSF_OUtil$setNamespace(name, parent) {
if (parent && name && !parent[name]) {
parent[name] = {};
}
},
unsetNamespace: function OSF_OUtil$unsetNamespace(name, parent) {
if (parent && name && parent[name]) {
delete parent[name];
}
},
serializeSettings: function OSF_OUtil$serializeSettings(settingsCollection) {
var ret = {};
for (var key in settingsCollection) {
var value = settingsCollection[key];
try {
if (JSON) {
value = JSON.stringify(value, function dateReplacer(k, v) {
return OSF.OUtil.isDate(this[k]) ? OSF.DDA.SettingsManager.DateJSONPrefix + this[k].getTime() + OSF.DDA.SettingsManager.DataJSONSuffix : v;
});
}
else {
value = Sys.Serialization.JavaScriptSerializer.serialize(value);
}
ret[key] = value;
}
catch (ex) {
}
}
return ret;
},
deserializeSettings: function OSF_OUtil$deserializeSettings(serializedSettings) {
var ret = {};
serializedSettings = serializedSettings || {};
for (var key in serializedSettings) {
var value = serializedSettings[key];
try {
if (JSON) {
value = JSON.parse(value, function dateReviver(k, v) {
var d;
if (typeof v === 'string' && v && v.length > 6 && v.slice(0, 5) === OSF.DDA.SettingsManager.DateJSONPrefix && v.slice(-1) === OSF.DDA.SettingsManager.DataJSONSuffix) {
d = new Date(parseInt(v.slice(5, -1)));
if (d) {
return d;
}
}
return v;
});
}
else {
value = Sys.Serialization.JavaScriptSerializer.deserialize(value, true);
}
ret[key] = value;
}
catch (ex) {
}
}
return ret;
},
loadScript: function OSF_OUtil$loadScript(url, callback, timeoutInMs) {
if (url && callback) {
var doc = window.document;
var _loadedScriptEntry = _loadedScripts[url];
if (!_loadedScriptEntry) {
var script = doc.createElement("script");
script.type = "text/javascript";
_loadedScriptEntry = { loaded: false, pendingCallbacks: [callback], timer: null };
_loadedScripts[url] = _loadedScriptEntry;
var onLoadCallback = function OSF_OUtil_loadScript$onLoadCallback() {
if (_loadedScriptEntry.timer != null) {
clearTimeout(_loadedScriptEntry.timer);
delete _loadedScriptEntry.timer;
}
_loadedScriptEntry.loaded = true;
var pendingCallbackCount = _loadedScriptEntry.pendingCallbacks.length;
for (var i = 0; i < pendingCallbackCount; i++) {
var currentCallback = _loadedScriptEntry.pendingCallbacks.shift();
currentCallback();
}
};
var onLoadTimeOut = function OSF_OUtil_loadScript$onLoadTimeOut() {
if (window.navigator.userAgent.indexOf("Trident") > 0) {
onLoadError(null);
}
else {
onLoadError(new Event("Script load timed out"));
}
};
var onLoadError = function OSF_OUtil_loadScript$onLoadError(errorEvent) {
delete _loadedScripts[url];
if (_loadedScriptEntry.timer != null) {
clearTimeout(_loadedScriptEntry.timer);
delete _loadedScriptEntry.timer;
}
var pendingCallbackCount = _loadedScriptEntry.pendingCallbacks.length;
for (var i = 0; i < pendingCallbackCount; i++) {
var currentCallback = _loadedScriptEntry.pendingCallbacks.shift();
currentCallback(errorEvent);
}
};
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
onLoadCallback();
}
};
}
else {
script.onload = onLoadCallback;
}
script.onerror = onLoadError;
timeoutInMs = timeoutInMs || _defaultScriptLoadingTimeout;
_loadedScriptEntry.timer = setTimeout(onLoadTimeOut, timeoutInMs);
script.setAttribute("crossOrigin", "anonymous");
script.src = url;
doc.getElementsByTagName("head")[0].appendChild(script);
}
else if (_loadedScriptEntry.loaded) {
callback();
}
else {
_loadedScriptEntry.pendingCallbacks.push(callback);
}
}
},
loadCSS: function OSF_OUtil$loadCSS(url) {
if (url) {
var doc = window.document;
var link = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
doc.getElementsByTagName("head")[0].appendChild(link);
}
},
parseEnum: function OSF_OUtil$parseEnum(str, enumObject) {
var parsed = enumObject[str.trim()];
if (typeof (parsed) == 'undefined') {
OsfMsAjaxFactory.msAjaxDebug.trace("invalid enumeration string:" + str);
throw OsfMsAjaxFactory.msAjaxError.argument("str");
}
return parsed;
},
delayExecutionAndCache: function OSF_OUtil$delayExecutionAndCache() {
var obj = { calc: arguments[0] };
return function () {
if (obj.calc) {
obj.val = obj.calc.apply(this, arguments);
delete obj.calc;
}
return obj.val;
};
},
getUniqueId: function OSF_OUtil$getUniqueId() {
_uniqueId = _uniqueId + 1;
return _uniqueId.toString();
},
formatString: function OSF_OUtil$formatString() {
var args = arguments;
var source = args[0];
return source.replace(/{(\d+)}/gm, function (match, number) {
var index = parseInt(number, 10) + 1;
return args[index] === undefined ? '{' + number + '}' : args[index];
});
},
generateConversationId: function OSF_OUtil$generateConversationId() {
return [_random(), _random(), (new Date()).getTime().toString()].join('_');
},
getFrameName: function OSF_OUtil$getFrameName(cacheKey) {
return _xdmSessionKeyPrefix + cacheKey + this.generateConversationId();
},
addXdmInfoAsHash: function OSF_OUtil$addXdmInfoAsHash(url, xdmInfoValue) {
return OSF.OUtil.addInfoAsHash(url, _xdmInfoKey, xdmInfoValue, false);
},
addSerializerVersionAsHash: function OSF_OUtil$addSerializerVersionAsHash(url, serializerVersion) {
return OSF.OUtil.addInfoAsHash(url, _serializerVersionKey, serializerVersion, true);
},
addFlightsAsHash: function OSF_OUtil$addFlightsAsHash(url, flights) {
return OSF.OUtil.addInfoAsHash(url, _flightsKey, flights, true);
},
addInfoAsHash: function OSF_OUtil$addInfoAsHash(url, keyName, infoValue, encodeInfo) {
url = url.trim() || '';
var urlParts = url.split(_fragmentSeparator);
var urlWithoutFragment = urlParts.shift();
var fragment = urlParts.join(_fragmentSeparator);
var newFragment;
if (encodeInfo) {
newFragment = [keyName, encodeURIComponent(infoValue), fragment].join('');
}
else {
newFragment = [fragment, keyName, infoValue].join('');
}
return [urlWithoutFragment, _fragmentSeparator, newFragment].join('');
},
parseHostInfoFromWindowName: function OSF_OUtil$parseHostInfoFromWindowName(skipSessionStorage, windowName) {
return OSF.OUtil.parseInfoFromWindowName(skipSessionStorage, windowName, OSF.WindowNameItemKeys.HostInfo);
},
parseXdmInfo: function OSF_OUtil$parseXdmInfo(skipSessionStorage) {
var xdmInfoValue = OSF.OUtil.parseXdmInfoWithGivenFragment(skipSessionStorage, window.location.hash);
if (!xdmInfoValue) {
xdmInfoValue = OSF.OUtil.parseXdmInfoFromWindowName(skipSessionStorage, window.name);
}
return xdmInfoValue;
},
parseXdmInfoFromWindowName: function OSF_OUtil$parseXdmInfoFromWindowName(skipSessionStorage, windowName) {
return OSF.OUtil.parseInfoFromWindowName(skipSessionStorage, windowName, OSF.WindowNameItemKeys.XdmInfo);
},
parseXdmInfoWithGivenFragment: function OSF_OUtil$parseXdmInfoWithGivenFragment(skipSessionStorage, fragment) {
return OSF.OUtil.parseInfoWithGivenFragment(_xdmInfoKey, _xdmSessionKeyPrefix, false, skipSessionStorage, fragment);
},
parseSerializerVersion: function OSF_OUtil$parseSerializerVersion(skipSessionStorage) {
var serializerVersion = OSF.OUtil.parseSerializerVersionWithGivenFragment(skipSessionStorage, window.location.hash);
if (isNaN(serializerVersion)) {
serializerVersion = OSF.OUtil.parseSerializerVersionFromWindowName(skipSessionStorage, window.name);
}
return serializerVersion;
},
parseSerializerVersionFromWindowName: function OSF_OUtil$parseSerializerVersionFromWindowName(skipSessionStorage, windowName) {
return parseInt(OSF.OUtil.parseInfoFromWindowName(skipSessionStorage, windowName, OSF.WindowNameItemKeys.SerializerVersion));
},
parseSerializerVersionWithGivenFragment: function OSF_OUtil$parseSerializerVersionWithGivenFragment(skipSessionStorage, fragment) {
return parseInt(OSF.OUtil.parseInfoWithGivenFragment(_serializerVersionKey, _serializerVersionKeyPrefix, true, skipSessionStorage, fragment));
},
parseFlights: function OSF_OUtil$parseFlights(skipSessionStorage) {
var flights = OSF.OUtil.parseFlightsWithGivenFragment(skipSessionStorage, window.location.hash);
if (flights.length == 0) {
flights = OSF.OUtil.parseFlightsFromWindowName(skipSessionStorage, window.name);
}
return flights;
},
checkFlight: function OSF_OUtil$checkFlightEnabled(flight) {
return OSF.Flights && OSF.Flights.indexOf(flight) >= 0;
},
pushFlight: function OSF_OUtil$pushFlight(flight) {
if (OSF.Flights.indexOf(flight) < 0) {
OSF.Flights.push(flight);
return true;
}
return false;
},
getBooleanSetting: function OSF_OUtil$getSetting(settingName) {
return OSF.OUtil.getBooleanFromDictionary(OSF.Settings, settingName);
},
getBooleanFromDictionary: function OSF_OUtil$getBooleanFromDictionary(settings, settingName) {
var result = (settings && settingName && settings[settingName] !== undefined && settings[settingName] &&
((typeof (settings[settingName]) === "string" && settings[settingName].toUpperCase() === 'TRUE') ||
(typeof (settings[settingName]) === "boolean" && settings[settingName])));
return result !== undefined ? result : false;
},
getIntFromDictionary: function OSF_OUtil$getIntFromDictionary(settings, settingName) {
if (settings && settingName && settings[settingName] !== undefined && (typeof settings[settingName] === "string")) {
return parseInt(settings[settingName]);
}
else {
return NaN;
}
},
pushIntFlight: function OSF_OUtil$pushIntFlight(flight, flightValue) {
if (!(flight in OSF.IntFlights)) {
OSF.IntFlights[flight] = flightValue;
return true;
}
return false;
},
getIntFlight: function OSF_OUtil$getIntFlight(flight) {
if (OSF.IntFlights && (flight in OSF.IntFlights)) {
return OSF.IntFlights[flight];
}
else {
return NaN;
}
},
parseFlightsFromWindowName: function OSF_OUtil$parseFlightsFromWindowName(skipSessionStorage, windowName) {
return OSF.OUtil.parseArrayWithDefault(OSF.OUtil.parseInfoFromWindowName(skipSessionStorage, windowName, OSF.WindowNameItemKeys.Flights));
},
parseFlightsWithGivenFragment: function OSF_OUtil$parseFlightsWithGivenFragment(skipSessionStorage, fragment) {
return OSF.OUtil.parseArrayWithDefault(OSF.OUtil.parseInfoWithGivenFragment(_flightsKey, _flightsKeyPrefix, true, skipSessionStorage, fragment));
},
parseArrayWithDefault: function OSF_OUtil$parseArrayWithDefault(jsonString) {
var array = [];
try {
array = JSON.parse(jsonString);
}
catch (ex) { }
if (!Array.isArray(array)) {
array = [];
}
return array;
},
parseInfoFromWindowName: function OSF_OUtil$parseInfoFromWindowName(skipSessionStorage, windowName, infoKey) {
try {
var windowNameObj = JSON.parse(windowName);
var infoValue = windowNameObj != null ? windowNameObj[infoKey] : null;
var osfSessionStorage = _getSessionStorage();
if (!skipSessionStorage && osfSessionStorage && windowNameObj != null) {
var sessionKey = windowNameObj[OSF.WindowNameItemKeys.BaseFrameName] + infoKey;
if (infoValue) {
osfSessionStorage.setItem(sessionKey, infoValue);
}
else {
infoValue = osfSessionStorage.getItem(sessionKey);
}
}
return infoValue;
}
catch (Exception) {
return null;
}
},
parseInfoWithGivenFragment: function OSF_OUtil$parseInfoWithGivenFragment(infoKey, infoKeyPrefix, decodeInfo, skipSessionStorage, fragment) {
var fragmentParts = fragment.split(infoKey);
var infoValue = fragmentParts.length > 1 ? fragmentParts[fragmentParts.length - 1] : null;
if (decodeInfo && infoValue != null) {
if (infoValue.indexOf(_fragmentInfoDelimiter) >= 0) {
infoValue = infoValue.split(_fragmentInfoDelimiter)[0];
}
infoValue = decodeURIComponent(infoValue);
}
var osfSessionStorage = _getSessionStorage();
if (!skipSessionStorage && osfSessionStorage) {
var sessionKeyStart = window.name.indexOf(infoKeyPrefix);
if (sessionKeyStart > -1) {
var sessionKeyEnd = window.name.indexOf(";", sessionKeyStart);
if (sessionKeyEnd == -1) {
sessionKeyEnd = window.name.length;
}
var sessionKey = window.name.substring(sessionKeyStart, sessionKeyEnd);
if (infoValue) {
osfSessionStorage.setItem(sessionKey, infoValue);
}
else {
infoValue = osfSessionStorage.getItem(sessionKey);
}
}
}
return infoValue;
},
getConversationId: function OSF_OUtil$getConversationId() {
var searchString = window.location.search;
var conversationId = null;
if (searchString) {
var index = searchString.indexOf("&");
conversationId = index > 0 ? searchString.substring(1, index) : searchString.substr(1);
if (conversationId && conversationId.charAt(conversationId.length - 1) === '=') {
conversationId = conversationId.substring(0, conversationId.length - 1);
if (conversationId) {
conversationId = decodeURIComponent(conversationId);
}
}
}
return conversationId;
},
getInfoItems: function OSF_OUtil$getInfoItems(strInfo) {
var items = strInfo.split("$");
if (typeof items[1] == "undefined") {
items = strInfo.split("|");
}
if (typeof items[1] == "undefined") {
items = strInfo.split("%7C");
}
return items;
},
getXdmFieldValue: function OSF_OUtil$getXdmFieldValue(xdmFieldName, skipSessionStorage) {
var fieldValue = '';
var xdmInfoValue = OSF.OUtil.parseXdmInfo(skipSessionStorage);
if (xdmInfoValue) {
var items = OSF.OUtil.getInfoItems(xdmInfoValue);
if (items != undefined && items.length >= 3) {
switch (xdmFieldName) {
case OSF.XdmFieldName.ConversationUrl:
fieldValue = items[2];
break;
case OSF.XdmFieldName.AppId:
fieldValue = items[1];
break;
}
}
}
return fieldValue;
},
validateParamObject: function OSF_OUtil$validateParamObject(params, expectedProperties, callback) {
var e = Function._validateParams(arguments, [{ name: "params", type: Object, mayBeNull: false },
{ name: "expectedProperties", type: Object, mayBeNull: false },
{ name: "callback", type: Function, mayBeNull: true }
]);
if (e)
throw e;
for (var p in expectedProperties) {
e = Function._validateParameter(params[p], expectedProperties[p], p);
if (e)
throw e;
}
},
writeProfilerMark: function OSF_OUtil$writeProfilerMark(text) {
if (window.msWriteProfilerMark) {
window.msWriteProfilerMark(text);
OsfMsAjaxFactory.msAjaxDebug.trace(text);
}
},
outputDebug: function OSF_OUtil$outputDebug(text) {
if (typeof (OsfMsAjaxFactory) !== 'undefined' && OsfMsAjaxFactory.msAjaxDebug && OsfMsAjaxFactory.msAjaxDebug.trace) {
OsfMsAjaxFactory.msAjaxDebug.trace(text);
}
},
defineNondefaultProperty: function OSF_OUtil$defineNondefaultProperty(obj, prop, descriptor, attributes) {
descriptor = descriptor || {};
for (var nd in attributes) {
var attribute = attributes[nd];
if (descriptor[attribute] == undefined) {
descriptor[attribute] = true;
}
}
Object.defineProperty(obj, prop, descriptor);
return obj;
},
defineNondefaultProperties: function OSF_OUtil$defineNondefaultProperties(obj, descriptors, attributes) {
descriptors = descriptors || {};
for (var prop in descriptors) {
OSF.OUtil.defineNondefaultProperty(obj, prop, descriptors[prop], attributes);
}
return obj;
},
defineEnumerableProperty: function OSF_OUtil$defineEnumerableProperty(obj, prop, descriptor) {
return OSF.OUtil.defineNondefaultProperty(obj, prop, descriptor, ["enumerable"]);
},
defineEnumerableProperties: function OSF_OUtil$defineEnumerableProperties(obj, descriptors) {
return OSF.OUtil.defineNondefaultProperties(obj, descriptors, ["enumerable"]);
},
defineMutableProperty: function OSF_OUtil$defineMutableProperty(obj, prop, descriptor) {
return OSF.OUtil.defineNondefaultProperty(obj, prop, descriptor, ["writable", "enumerable", "configurable"]);
},
defineMutableProperties: function OSF_OUtil$defineMutableProperties(obj, descriptors) {
return OSF.OUtil.defineNondefaultProperties(obj, descriptors, ["writable", "enumerable", "configurable"]);
},
finalizeProperties: function OSF_OUtil$finalizeProperties(obj, descriptor) {
descriptor = descriptor || {};
var props = Object.getOwnPropertyNames(obj);
var propsLength = props.length;
for (var i = 0; i < propsLength; i++) {
var prop = props[i];
var desc = Object.getOwnPropertyDescriptor(obj, prop);
if (!desc.get && !desc.set) {
desc.writable = descriptor.writable || false;
}
desc.configurable = descriptor.configurable || false;
desc.enumerable = descriptor.enumerable || true;
Object.defineProperty(obj, prop, desc);
}
return obj;
},
mapList: function OSF_OUtil$MapList(list, mapFunction) {
var ret = [];
if (list) {
for (var item in list) {
ret.push(mapFunction(list[item]));
}
}
return ret;
},
listContainsKey: function OSF_OUtil$listContainsKey(list, key) {
for (var item in list) {
if (key == item) {
return true;
}
}
return false;
},
listContainsValue: function OSF_OUtil$listContainsElement(list, value) {
for (var item in list) {
if (value == list[item]) {
return true;
}
}
return false;
},
augmentList: function OSF_OUtil$augmentList(list, addenda) {
var add = list.push ? function (key, value) { list.push(value); } : function (key, value) { list[key] = value; };
for (var key in addenda) {
add(key, addenda[key]);
}
},
redefineList: function OSF_Outil$redefineList(oldList, newList) {
for (var key1 in oldList) {
delete oldList[key1];
}
for (var key2 in newList) {
oldList[key2] = newList[key2];
}
},
isArray: function OSF_OUtil$isArray(obj) {
return Object.prototype.toString.apply(obj) === "[object Array]";
},
isFunction: function OSF_OUtil$isFunction(obj) {
return Object.prototype.toString.apply(obj) === "[object Function]";
},
isDate: function OSF_OUtil$isDate(obj) {
return Object.prototype.toString.apply(obj) === "[object Date]";
},
addEventListener: function OSF_OUtil$addEventListener(element, eventName, listener) {
if (element.addEventListener) {
element.addEventListener(eventName, listener, false);
}
else if ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && element.attachEvent) {
element.attachEvent("on" + eventName, listener);
}
else {
element["on" + eventName] = listener;
}
},
removeEventListener: function OSF_OUtil$removeEventListener(element, eventName, listener) {
if (element.removeEventListener) {
element.removeEventListener(eventName, listener, false);
}
else if ((Sys.Browser.agent === Sys.Browser.InternetExplorer) && element.detachEvent) {
element.detachEvent("on" + eventName, listener);
}
else {
element["on" + eventName] = null;
}
},
xhrGet: function OSF_OUtil$xhrGet(url, onSuccess, onError) {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
onSuccess(xmlhttp.responseText);
}
else {
onError(xmlhttp.status);
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
catch (ex) {
onError(ex);
}
},
encodeBase64: function OSF_Outil$encodeBase64(input) {
if (!input)
return input;
var codex = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/=";
var output = [];
var temp = [];
var index = 0;
var c1, c2, c3, a, b, c;
var i;
var length = input.length;
do {
c1 = input.charCodeAt(index++);
c2 = input.charCodeAt(index++);
c3 = input.charCodeAt(index++);
i = 0;
a = c1 & 255;
b = c1 >> 8;
c = c2 & 255;
temp[i++] = a >> 2;
temp[i++] = ((a & 3) << 4) | (b >> 4);
temp[i++] = ((b & 15) << 2) | (c >> 6);
temp[i++] = c & 63;
if (!isNaN(c2)) {
a = c2 >> 8;
b = c3 & 255;
c = c3 >> 8;
temp[i++] = a >> 2;
temp[i++] = ((a & 3) << 4) | (b >> 4);
temp[i++] = ((b & 15) << 2) | (c >> 6);
temp[i++] = c & 63;
}
if (isNaN(c2)) {
temp[i - 1] = 64;
}
else if (isNaN(c3)) {
temp[i - 2] = 64;
temp[i - 1] = 64;
}
for (var t = 0; t < i; t++) {
output.push(codex.charAt(temp[t]));
}
} while (index < length);
return output.join("");
},
getSessionStorage: function OSF_Outil$getSessionStorage() {
return _getSessionStorage();
},
getLocalStorage: function OSF_Outil$getLocalStorage() {
if (!_safeLocalStorage) {
try {
var localStorage = window.localStorage;
}
catch (ex) {
localStorage = null;
}
_safeLocalStorage = new OfficeExt.SafeStorage(localStorage);
}
return _safeLocalStorage;
},
convertIntToCssHexColor: function OSF_Outil$convertIntToCssHexColor(val) {
var hex = "#" + (Number(val) + 0x1000000).toString(16).slice(-6);
return hex;
},
attachClickHandler: function OSF_Outil$attachClickHandler(element, handler) {
element.onclick = function (e) {
handler();
};
element.ontouchend = function (e) {
handler();
e.preventDefault();
};
},
getQueryStringParamValue: function OSF_Outil$getQueryStringParamValue(queryString, paramName) {
var e = Function._validateParams(arguments, [{ name: "queryString", type: String, mayBeNull: false },
{ name: "paramName", type: String, mayBeNull: false }
]);
if (e) {
OsfMsAjaxFactory.msAjaxDebug.trace("OSF_Outil_getQueryStringParamValue: Parameters cannot be null.");
return "";
}
var queryExp = new RegExp("[\\?&]" + paramName + "=([^&#]*)", "i");
if (!queryExp.test(queryString)) {
OsfMsAjaxFactory.msAjaxDebug.trace("OSF_Outil_getQueryStringParamValue: The parameter is not found.");
return "";
}
return queryExp.exec(queryString)[1];
},
getHostnamePortionForLogging: function OSF_Outil$getHostnamePortionForLogging(hostname) {
var e = Function._validateParams(arguments, [{ name: "hostname", type: String, mayBeNull: false }
]);
if (e) {
return "";
}
var hostnameSubstrings = hostname.split('.');
var len = hostnameSubstrings.length;
if (len >= 2) {
return hostnameSubstrings[len - 2] + "." + hostnameSubstrings[len - 1];
}
else if (len == 1) {
return hostnameSubstrings[0];
}
},
isiOS: function OSF_Outil$isiOS() {
return (window.navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
},
isChrome: function OSF_Outil$isChrome() {
return (window.navigator.userAgent.indexOf("Chrome") > 0) && !OSF.OUtil.isEdge();
},
isEdge: function OSF_Outil$isEdge() {
return window.navigator.userAgent.indexOf("Edge") > 0;
},
isIE: function OSF_Outil$isIE() {
return window.navigator.userAgent.indexOf("Trident") > 0;
},
isFirefox: function OSF_Outil$isFirefox() {
return window.navigator.userAgent.indexOf("Firefox") > 0;
},
startsWith: function OSF_Outil$startsWith(originalString, patternToCheck, browserIsIE) {
if (browserIsIE) {
return originalString.substr(0, patternToCheck.length) === patternToCheck;
}
else {
return originalString.startsWith(patternToCheck);
}
},
containsPort: function OSF_Outil$containsPort(url, protocol, hostname, portNumber) {
return this.startsWith(url, protocol + "//" + hostname + ":" + portNumber, true) || this.startsWith(url, hostname + ":" + portNumber, true);
},
getRedundandPortString: function OSF_Outil$getRedundandPortString(url, parser) {
if (!url || !parser)
return "";
if (parser.protocol == "https:" && this.containsPort(url, "https:", parser.hostname, "443"))
return ":443";
else if (parser.protocol == "http:" && this.containsPort(url, "http:", parser.hostname, "80"))
return ":80";
return "";
},
removeChar: function OSF_Outil$removeChar(url, indexOfCharToRemove) {
if (indexOfCharToRemove < url.length - 1)
return url.substring(0, indexOfCharToRemove) + url.substring(indexOfCharToRemove + 1);
else if (indexOfCharToRemove == url.length - 1)
return url.substring(0, url.length - 1);
else
return url;
},
cleanUrlOfChar: function OSF_Outil$cleanUrlOfChar(url, charToClean) {
var i;
for (i = 0; i < url.length; i++) {
if (url.charAt(i) === charToClean) {
if (i + 1 >= url.length) {
return this.removeChar(url, i);
}
else if (charToClean === '/') {
if (url.charAt(i + 1) === '?' || url.charAt(i + 1) === '#') {
return this.removeChar(url, i);
}
}
else if (charToClean === '?') {
if (url.charAt(i + 1) === '#') {
return this.removeChar(url, i);
}
}
}
}
return url;
},
cleanUrl: function OSF_Outil$cleanUrl(url) {
url = this.cleanUrlOfChar(url, '/');
url = this.cleanUrlOfChar(url, '?');
url = this.cleanUrlOfChar(url, '#');
if (url.substr(0, 8) == "https://") {
var portIndex = url.indexOf(":443");
if (portIndex != -1) {
if (portIndex == url.length - 4 || url.charAt(portIndex + 4) == "/" || url.charAt(portIndex + 4) == "?" || url.charAt(portIndex + 4) == "#") {
url = url.substring(0, portIndex) + url.substring(portIndex + 4);
}
}
}
else if (url.substr(0, 7) == "http://") {
var portIndex = url.indexOf(":80");
if (portIndex != -1) {
if (portIndex == url.length - 3 || url.charAt(portIndex + 3) == "/" || url.charAt(portIndex + 3) == "?" || url.charAt(portIndex + 3) == "#") {
url = url.substring(0, portIndex) + url.substring(portIndex + 3);
}
}
}
return url;
},
parseUrl: function OSF_Outil$parseUrl(url, enforceHttps) {
if (enforceHttps === void 0) {
enforceHttps = false;
}
if (typeof url === "undefined" || !url) {
return undefined;
}
var notHttpsErrorMessage = "NotHttps";
var invalidUrlErrorMessage = "InvalidUrl";
var isIEBoolean = this.isIE();
var parsedUrlObj = {
protocol: undefined,
hostname: undefined,
host: undefined,
port: undefined,
pathname: undefined,
search: undefined,
hash: undefined,
isPortPartOfUrl: undefined
};
try {
if (isIEBoolean) {
var parser = document.createElement("a");
parser.href = url;
if (!parser || !parser.protocol || !parser.host || !parser.hostname || !parser.href
|| this.cleanUrl(parser.href).toLowerCase() !== this.cleanUrl(url).toLowerCase()) {
throw invalidUrlErrorMessage;
}
if (OSF.OUtil.checkFlight(OSF.FlightNames.AddinEnforceHttps)) {
if (enforceHttps && parser.protocol != "https:")
throw new Error(notHttpsErrorMessage);
}
var redundandPortString = this.getRedundandPortString(url, parser);
parsedUrlObj.protocol = parser.protocol;
parsedUrlObj.hostname = parser.hostname;
parsedUrlObj.port = (redundandPortString == "") ? parser.port : "";
parsedUrlObj.host = (redundandPortString != "") ? parser.hostname : parser.host;
parsedUrlObj.pathname = (isIEBoolean ? "/" : "") + parser.pathname;
parsedUrlObj.search = parser.search;
parsedUrlObj.hash = parser.hash;
parsedUrlObj.isPortPartOfUrl = this.containsPort(url, parser.protocol, parser.hostname, parser.port);
}
else {
var urlObj = new URL(url);
if (urlObj && urlObj.protocol && urlObj.host && urlObj.hostname) {
if (OSF.OUtil.checkFlight(OSF.FlightNames.AddinEnforceHttps)) {
if (enforceHttps && urlObj.protocol != "https:")
throw new Error(notHttpsErrorMessage);
}
parsedUrlObj.protocol = urlObj.protocol;
parsedUrlObj.hostname = urlObj.hostname;
p