@microsoft/office-js
Version:
Office JavaScript APIs
849 lines (845 loc) • 38.7 kB
JavaScript
/* Office JavaScript API library */
/* Version: 16.0.8828.1000 */
/*
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.
*/
var OSF = OSF || {};
OSF.HostSpecificFileVersionDefault = "16.00";
OSF.HostSpecificFileVersionMap = {
"access": {
"web": "16.00"
},
"agavito": {
"winrt": "16.00"
},
"excel": {
"ios": "16.00",
"mac": "16.00",
"web": "16.00",
"win32": "16.01",
"winrt": "16.00"
},
"onenote": {
"web": "16.00",
"win32": "16.00",
"winrt": "16.00"
},
"outlook": {
"ios": "16.00",
"mac": "16.00",
"web": "16.01",
"win32": "16.02"
},
"powerpoint": {
"ios": "16.00",
"mac": "16.00",
"web": "16.00",
"win32": "16.01",
"winrt": "16.00"
},
"project": {
"win32": "16.00"
},
"sway": {
"web": "16.00"
},
"word": {
"ios": "16.00",
"mac": "16.00",
"web": "16.00",
"win32": "16.01",
"winrt": "16.00"
}
};
OSF.SupportedLocales = {
"ar-sa": true,
"bg-bg": true,
"bn-in": true,
"ca-es": true,
"cs-cz": true,
"da-dk": true,
"de-de": true,
"el-gr": true,
"en-us": true,
"es-es": true,
"et-ee": true,
"eu-es": true,
"fa-ir": true,
"fi-fi": true,
"fr-fr": true,
"gl-es": true,
"he-il": true,
"hi-in": true,
"hr-hr": true,
"hu-hu": true,
"id-id": true,
"it-it": true,
"ja-jp": true,
"kk-kz": true,
"ko-kr": true,
"lt-lt": true,
"lv-lv": true,
"ms-my": true,
"nb-no": true,
"nl-nl": true,
"nn-no": true,
"pl-pl": true,
"pt-br": true,
"pt-pt": true,
"ro-ro": true,
"ru-ru": true,
"sk-sk": true,
"sl-si": true,
"sr-cyrl-cs": true,
"sr-cyrl-rs": true,
"sr-latn-cs": true,
"sr-latn-rs": true,
"sv-se": true,
"th-th": true,
"tr-tr": true,
"uk-ua": true,
"ur-pk": true,
"vi-vn": true,
"zh-cn": true,
"zh-tw": true
};
OSF.AssociatedLocales = {
ar: "ar-sa",
bg: "bg-bg",
bn: "bn-in",
ca: "ca-es",
cs: "cs-cz",
da: "da-dk",
de: "de-de",
el: "el-gr",
en: "en-us",
es: "es-es",
et: "et-ee",
eu: "eu-es",
fa: "fa-ir",
fi: "fi-fi",
fr: "fr-fr",
gl: "gl-es",
he: "he-il",
hi: "hi-in",
hr: "hr-hr",
hu: "hu-hu",
id: "id-id",
it: "it-it",
ja: "ja-jp",
kk: "kk-kz",
ko: "ko-kr",
lt: "lt-lt",
lv: "lv-lv",
ms: "ms-my",
nb: "nb-no",
nl: "nl-nl",
nn: "nn-no",
pl: "pl-pl",
pt: "pt-br",
ro: "ro-ro",
ru: "ru-ru",
sk: "sk-sk",
sl: "sl-si",
sr: "sr-cyrl-cs",
sv: "sv-se",
th: "th-th",
tr: "tr-tr",
uk: "uk-ua",
ur: "ur-pk",
vi: "vi-vn",
zh: "zh-cn"
};
OSF.getSupportedLocale = function OSF$getSupportedLocale(locale, defaultLocale) {
if (defaultLocale === void 0) { defaultLocale = "en-us"; }
if (!locale) {
return defaultLocale;
}
var supportedLocale;
locale = locale.toLowerCase();
if (locale in OSF.SupportedLocales) {
supportedLocale = locale;
}
else {
var localeParts = locale.split('-', 1);
if (localeParts && localeParts.length > 0) {
supportedLocale = OSF.AssociatedLocales[localeParts[0]];
}
}
if (!supportedLocale) {
supportedLocale = defaultLocale;
}
return supportedLocale;
};
var ScriptLoading;
(function (ScriptLoading) {
var ScriptInfo = (function () {
function ScriptInfo(url, isReady, hasStarted, timer, pendingCallback) {
this.url = url;
this.isReady = isReady;
this.hasStarted = hasStarted;
this.timer = timer;
this.hasError = false;
this.pendingCallbacks = [];
this.pendingCallbacks.push(pendingCallback);
}
return ScriptInfo;
})();
var ScriptTelemetry = (function () {
function ScriptTelemetry(scriptId, startTime, msResponseTime) {
this.scriptId = scriptId;
this.startTime = startTime;
this.msResponseTime = msResponseTime;
}
return ScriptTelemetry;
})();
var LoadScriptHelper = (function () {
function LoadScriptHelper() {
this.defaultScriptLoadingTimeout = 10000;
this.loadedScriptByIds = {};
this.scriptTelemetryBuffer = [];
this.osfControlAppCorrelationId = "";
this.basePath = null;
this.constantNames = {
OfficeJS: "office.js",
OfficeDebugJS: "office.debug.js"
};
}
LoadScriptHelper.prototype.isScriptLoading = function (id) {
return !!(this.loadedScriptByIds[id] && this.loadedScriptByIds[id].hasStarted);
};
LoadScriptHelper.prototype.getOfficeJsBasePath = function () {
if (this.basePath) {
return this.basePath;
}
else {
var getScriptBase = function (scriptSrc, scriptNameToCheck) {
var scriptBase, indexOfJS, scriptSrcLowerCase;
scriptSrcLowerCase = scriptSrc.toLowerCase();
indexOfJS = scriptSrcLowerCase.indexOf(scriptNameToCheck);
if (indexOfJS >= 0 && indexOfJS === (scriptSrc.length - scriptNameToCheck.length) && (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) {
scriptBase = scriptSrc.substring(0, indexOfJS);
}
else if (indexOfJS >= 0
&& indexOfJS < (scriptSrc.length - scriptNameToCheck.length)
&& scriptSrc.charAt(indexOfJS + scriptNameToCheck.length) === '?'
&& (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) {
scriptBase = scriptSrc.substring(0, indexOfJS);
}
return scriptBase;
};
var scripts = document.getElementsByTagName("script");
var scriptsCount = scripts.length;
var officeScripts = [this.constantNames.OfficeJS, this.constantNames.OfficeDebugJS];
var officeScriptsCount = officeScripts.length;
var i, j;
for (i = 0; !this.basePath && i < scriptsCount; i++) {
if (scripts[i].src) {
for (j = 0; !this.basePath && j < officeScriptsCount; j++) {
this.basePath = getScriptBase(scripts[i].src, officeScripts[j]);
}
}
}
return this.basePath;
}
};
LoadScriptHelper.prototype.loadScript = function (url, scriptId, callback, highPriority, timeoutInMs) {
this.loadScriptInternal(url, scriptId, callback, highPriority, timeoutInMs);
};
LoadScriptHelper.prototype.loadScriptParallel = function (url, scriptId, timeoutInMs) {
this.loadScriptInternal(url, scriptId, null, false, timeoutInMs);
};
LoadScriptHelper.prototype.waitForFunction = function (scriptLoadTest, callback, numberOfTries, delay) {
var attemptsRemaining = numberOfTries;
var timerId;
var validateFunction = function () {
attemptsRemaining--;
if (scriptLoadTest()) {
callback(true);
return;
}
else if (attemptsRemaining > 0) {
timerId = window.setTimeout(validateFunction, delay);
attemptsRemaining--;
}
else {
window.clearTimeout(timerId);
callback(false);
}
};
validateFunction();
};
LoadScriptHelper.prototype.waitForScripts = function (ids, callback) {
var _this = this;
if (this.invokeCallbackIfScriptsReady(ids, callback) == false) {
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
var loadedScriptEntry = this.loadedScriptByIds[id];
if (loadedScriptEntry) {
loadedScriptEntry.pendingCallbacks.push(function () {
_this.invokeCallbackIfScriptsReady(ids, callback);
});
}
}
}
};
LoadScriptHelper.prototype.logScriptLoading = function (scriptId, startTime, msResponseTime) {
startTime = Math.floor(startTime);
if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) {
if (OSF.AppTelemetry.onScriptDone.length == 3) {
OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime);
}
else {
OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime, this.osfControlAppCorrelationId);
}
}
else {
var scriptTelemetry = new ScriptTelemetry(scriptId, startTime, msResponseTime);
this.scriptTelemetryBuffer.push(scriptTelemetry);
}
};
LoadScriptHelper.prototype.setAppCorrelationId = function (appCorrelationId) {
this.osfControlAppCorrelationId = appCorrelationId;
};
LoadScriptHelper.prototype.invokeCallbackIfScriptsReady = function (ids, callback) {
var hasError = false;
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
var loadedScriptEntry = this.loadedScriptByIds[id];
if (!loadedScriptEntry) {
loadedScriptEntry = new ScriptInfo("", false, false, null, null);
this.loadedScriptByIds[id] = loadedScriptEntry;
}
if (loadedScriptEntry.isReady == false) {
return false;
}
else if (loadedScriptEntry.hasError) {
hasError = true;
}
}
callback(!hasError);
return true;
};
LoadScriptHelper.prototype.getScriptEntryByUrl = function (url) {
for (var key in this.loadedScriptByIds) {
var scriptEntry = this.loadedScriptByIds[key];
if (this.loadedScriptByIds.hasOwnProperty(key) && scriptEntry.url === url) {
return scriptEntry;
}
}
return null;
};
LoadScriptHelper.prototype.loadScriptInternal = function (url, scriptId, callback, highPriority, timeoutInMs) {
if (url) {
var self = this;
var doc = window.document;
var loadedScriptEntry = (scriptId && this.loadedScriptByIds[scriptId]) ? this.loadedScriptByIds[scriptId] : this.getScriptEntryByUrl(url);
if (!loadedScriptEntry || loadedScriptEntry.hasError || loadedScriptEntry.url.toLowerCase() != url.toLowerCase()) {
var script = doc.createElement("script");
script.type = "text/javascript";
if (scriptId) {
script.id = scriptId;
}
if (!loadedScriptEntry) {
loadedScriptEntry = new ScriptInfo(url, false, false, null, null);
this.loadedScriptByIds[(scriptId ? scriptId : url)] = loadedScriptEntry;
}
else {
loadedScriptEntry.url = url;
loadedScriptEntry.hasError = false;
loadedScriptEntry.isReady = false;
}
if (callback) {
if (highPriority) {
loadedScriptEntry.pendingCallbacks.unshift(callback);
}
else {
loadedScriptEntry.pendingCallbacks.push(callback);
}
}
var timeFromPageInit = -1;
if (window.performance && window.performance.now) {
timeFromPageInit = window.performance.now();
}
var startTime = (new Date()).getTime();
var logTelemetry = function (succeeded) {
if (scriptId) {
var totalTime = (new Date()).getTime() - startTime;
if (!succeeded) {
totalTime = -totalTime;
}
self.logScriptLoading(scriptId, timeFromPageInit, totalTime);
}
self.flushTelemetryBuffer();
};
var onLoadCallback = function OSF_OUtil_loadScript$onLoadCallback() {
if (OSF._OfficeAppFactory.getHostInfo().hostType == "onenote" && (typeof OSF.AppTelemetry !== 'undefined') && (typeof OSF.AppTelemetry.enableTelemetry !== 'undefined')) {
OSF.AppTelemetry.enableTelemetry = false;
}
logTelemetry(true);
loadedScriptEntry.isReady = true;
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();
if (currentCallback) {
var result = currentCallback(true);
if (result === false) {
break;
}
}
}
};
var onLoadError = function () {
logTelemetry(false);
loadedScriptEntry.hasError = true;
loadedScriptEntry.isReady = true;
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();
if (currentCallback) {
var result = currentCallback(false);
if (result === false) {
break;
}
}
}
};
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 || this.defaultScriptLoadingTimeout;
loadedScriptEntry.timer = setTimeout(onLoadError, timeoutInMs);
loadedScriptEntry.hasStarted = true;
script.setAttribute("crossOrigin", "anonymous");
script.src = url;
doc.getElementsByTagName("head")[0].appendChild(script);
}
else if (loadedScriptEntry.isReady) {
callback(true);
}
else {
if (highPriority) {
loadedScriptEntry.pendingCallbacks.unshift(callback);
}
else {
loadedScriptEntry.pendingCallbacks.push(callback);
}
}
}
};
LoadScriptHelper.prototype.flushTelemetryBuffer = function () {
if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) {
for (var i = 0; i < this.scriptTelemetryBuffer.length; i++) {
var scriptTelemetry = this.scriptTelemetryBuffer[i];
if (OSF.AppTelemetry.onScriptDone.length == 3) {
OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime);
}
else {
OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime, this.osfControlAppCorrelationId);
}
}
this.scriptTelemetryBuffer = [];
}
};
return LoadScriptHelper;
})();
ScriptLoading.LoadScriptHelper = LoadScriptHelper;
})(ScriptLoading || (ScriptLoading = {}));
OSF.ConstantNames = {
FileVersion: "16.0.8828.1000",
OfficeJS: "office.js",
OfficeDebugJS: "office.debug.js",
DefaultLocale: "en-us",
LocaleStringLoadingTimeout: 5000,
MicrosoftAjaxId: "MSAJAX",
OfficeStringsId: "OFFICESTRINGS",
OfficeJsId: "OFFICEJS",
HostFileId: "HOST",
O15MappingId: "O15Mapping",
OfficeStringJS: "office_strings.debug.js",
O15InitHelper: "o15apptofilemappingtable.debug.js",
SupportedLocales: OSF.SupportedLocales,
AssociatedLocales: OSF.AssociatedLocales
};
OSF.InitializationHelper = function OSF_InitializationHelper(hostInfo, webAppState, context, settings, hostFacade) {
this._hostInfo = hostInfo;
this._webAppState = webAppState;
this._context = context;
this._settings = settings;
this._hostFacade = hostFacade;
};
OSF.InitializationHelper.prototype.saveAndSetDialogInfo = function OSF_InitializationHelper$saveAndSetDialogInfo(hostInfoValue) {
};
OSF.InitializationHelper.prototype.getAppContext = function OSF_InitializationHelper$getAppContext(wnd, gotAppContext) {
};
OSF.InitializationHelper.prototype.setAgaveHostCommunication = function OSF_InitializationHelper$setAgaveHostCommunication() {
};
OSF.InitializationHelper.prototype.prepareRightBeforeWebExtensionInitialize = function OSF_InitializationHelper$prepareRightBeforeWebExtensionInitialize(appContext) {
};
OSF.InitializationHelper.prototype.loadAppSpecificScriptAndCreateOM = function OSF_InitializationHelper$loadAppSpecificScriptAndCreateOM(appContext, appReady, basePath) {
};
OSF.InitializationHelper.prototype.prepareRightAfterWebExtensionInitialize = function OSF_InitializationHelper$prepareRightAfterWebExtensionInitialize() {
};
OSF._OfficeAppFactory = (function OSF__OfficeAppFactory() {
var _setNamespace = function OSF_OUtil$_setNamespace(name, parent) {
if (parent && name && !parent[name]) {
parent[name] = {};
}
};
_setNamespace("Office", window);
_setNamespace("Microsoft", window);
_setNamespace("Office", Microsoft);
_setNamespace("WebExtension", Microsoft.Office);
window.Office = Microsoft.Office.WebExtension;
var _context = {};
var _settings = {};
var _hostFacade = {};
var _WebAppState = { id: null, webAppUrl: null, conversationID: null, clientEndPoint: null, wnd: window.parent, focused: false };
var _hostInfo = { isO15: true, isRichClient: true, hostType: "", hostPlatform: "", hostSpecificFileVersion: "", hostLocale: "", osfControlAppCorrelationId: "", isDialog: false };
var _initializationHelper = {};
var _appInstanceId = null;
var _loadScriptHelper = new ScriptLoading.LoadScriptHelper();
if (window.performance && window.performance.now) {
_loadScriptHelper.logScriptLoading(OSF.ConstantNames.OfficeJsId, -1, window.performance.now());
}
var _windowLocationHash = window.location.hash;
var _windowLocationSearch = window.location.search;
var _windowName = window.name;
var getQueryStringValue = function OSF__OfficeAppFactory$getQueryStringValue(paramName) {
var hostInfoValue;
var searchString = window.location.search;
if (searchString) {
var hostInfoParts = searchString.split(paramName + "=");
if (hostInfoParts.length > 1) {
var hostInfoValueRestString = hostInfoParts[1];
var separatorRegex = new RegExp("[&#]", "g");
var hostInfoValueParts = hostInfoValueRestString.split(separatorRegex);
if (hostInfoValueParts.length > 0) {
hostInfoValue = hostInfoValueParts[0];
}
}
}
return hostInfoValue;
};
var compareVersions = function _compareVersions(version1, version2) {
var splitVersion1 = version1.split(".");
var splitVersion2 = version2.split(".");
var iter;
for (iter in splitVersion1) {
if (parseInt(splitVersion1[iter]) < parseInt(splitVersion2[iter])) {
return false;
}
else if (parseInt(splitVersion1[iter]) > parseInt(splitVersion2[iter])) {
return true;
}
}
return false;
};
var shouldLoadOldMacJs = function _shouldLoadOldMacJs() {
var versionToUseNewJS = "15.30.1128.0";
var currentHostVersion = window.external.GetContext().GetHostFullVersion();
return !!compareVersions(versionToUseNewJS, currentHostVersion);
};
var _retrieveHostInfo = function OSF__OfficeAppFactory$_retrieveHostInfo() {
var hostInfoParaName = "_host_Info";
var hostInfoValue = getQueryStringValue(hostInfoParaName);
if (!hostInfoValue) {
try {
var windowNameObj = JSON.parse(_windowName);
hostInfoValue = windowNameObj ? windowNameObj["hostInfo"] : null;
}
catch (Exception) {
}
}
if (!hostInfoValue) {
try {
window.external = window.external || {};
if (typeof agaveHost !== "undefined" && agaveHost.GetHostInfo) {
window.external.GetHostInfo = function () {
return agaveHost.GetHostInfo();
};
}
var fallbackHostInfo = window.external.GetHostInfo();
if (fallbackHostInfo == "isDialog") {
_hostInfo.isO15 = true;
_hostInfo.isDialog = true;
}
else if (fallbackHostInfo.toLowerCase().indexOf("mac") !== -1 && fallbackHostInfo.toLowerCase().indexOf("outlook") !== -1 && shouldLoadOldMacJs()) {
_hostInfo.isO15 = true;
}
else {
var hostInfoParts = fallbackHostInfo.split(hostInfoParaName + "=");
if (hostInfoParts.length > 1) {
hostInfoValue = hostInfoParts[1];
}
else {
hostInfoValue = fallbackHostInfo;
}
}
}
catch (Exception) {
}
}
var getSessionStorage = function OSF__OfficeAppFactory$_retrieveHostInfo$getSessionStorage() {
var osfSessionStorage = null;
try {
if (window.sessionStorage) {
osfSessionStorage = window.sessionStorage;
}
}
catch (ex) {
}
return osfSessionStorage;
};
var osfSessionStorage = getSessionStorage();
if (!hostInfoValue && osfSessionStorage && osfSessionStorage.getItem("hostInfoValue")) {
hostInfoValue = osfSessionStorage.getItem("hostInfoValue");
}
if (hostInfoValue) {
hostInfoValue = decodeURIComponent(hostInfoValue);
_hostInfo.isO15 = false;
var items = hostInfoValue.split("$");
if (typeof items[2] == "undefined") {
items = hostInfoValue.split("|");
}
_hostInfo.hostType = (typeof items[0] == "undefined") ? "" : items[0].toLowerCase();
_hostInfo.hostPlatform = (typeof items[1] == "undefined") ? "" : items[1].toLowerCase();
;
_hostInfo.hostSpecificFileVersion = (typeof items[2] == "undefined") ? "" : items[2].toLowerCase();
_hostInfo.hostLocale = (typeof items[3] == "undefined") ? "" : items[3].toLowerCase();
_hostInfo.osfControlAppCorrelationId = (typeof items[4] == "undefined") ? "" : items[4];
if (_hostInfo.osfControlAppCorrelationId == "telemetry") {
_hostInfo.osfControlAppCorrelationId = "";
}
_hostInfo.isDialog = (((typeof items[5]) != "undefined") && items[5] == "isDialog") ? true : false;
var hostSpecificFileVersionValue = parseFloat(_hostInfo.hostSpecificFileVersion);
var fallbackVersion = OSF.HostSpecificFileVersionDefault;
if (OSF.HostSpecificFileVersionMap[_hostInfo.hostType] && OSF.HostSpecificFileVersionMap[_hostInfo.hostType][_hostInfo.hostPlatform]) {
fallbackVersion = OSF.HostSpecificFileVersionMap[_hostInfo.hostType][_hostInfo.hostPlatform];
}
if (hostSpecificFileVersionValue > parseFloat(fallbackVersion)) {
_hostInfo.hostSpecificFileVersion = fallbackVersion;
}
if (osfSessionStorage) {
try {
osfSessionStorage.setItem("hostInfoValue", hostInfoValue);
}
catch (e) {
}
}
}
else {
_hostInfo.isO15 = true;
_hostInfo.hostLocale = getQueryStringValue("locale");
}
};
var getAppContextAsync = function OSF__OfficeAppFactory$getAppContextAsync(wnd, gotAppContext) {
if (OSF.AppTelemetry && OSF.AppTelemetry.logAppCommonMessage) {
OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync starts");
}
_initializationHelper.getAppContext(wnd, gotAppContext);
};
var initialize = function OSF__OfficeAppFactory$initialize() {
_retrieveHostInfo();
if (_hostInfo.hostPlatform == "web" && _hostInfo.isDialog && window == window.top && window.opener == null) {
window.open('', '_self', '');
window.close();
}
_loadScriptHelper.setAppCorrelationId(_hostInfo.osfControlAppCorrelationId);
var basePath = _loadScriptHelper.getOfficeJsBasePath();
var requiresMsAjax = false;
if (!basePath)
throw "Office Web Extension script library file name should be " + OSF.ConstantNames.OfficeJS + " or " + OSF.ConstantNames.OfficeDebugJS + ".";
var isMicrosftAjaxLoaded = function OSF$isMicrosftAjaxLoaded() {
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 (OfficeExt) !== "undefined" && OfficeExt.MsAjaxError)) {
return true;
}
else {
return false;
}
};
var officeStrings = null;
var loadLocaleStrings = function OSF__OfficeAppFactory_initialize$loadLocaleStrings(appLocale) {
var fallbackLocaleTried = false;
var loadLocaleStringCallback = function OSF__OfficeAppFactory_initialize$loadLocaleStringCallback() {
if (typeof Strings == 'undefined' || typeof Strings.OfficeOM == 'undefined') {
if (!fallbackLocaleTried) {
fallbackLocaleTried = true;
var fallbackLocaleStringFile = basePath + OSF.ConstantNames.DefaultLocale + "/" + OSF.ConstantNames.OfficeStringJS;
_loadScriptHelper.loadScript(fallbackLocaleStringFile, OSF.ConstantNames.OfficeStringsId, loadLocaleStringCallback, true, OSF.ConstantNames.LocaleStringLoadingTimeout);
return false;
}
else {
throw "Neither the locale, " + appLocale.toLowerCase() + ", provided by the host app nor the fallback locale " + OSF.ConstantNames.DefaultLocale + " are supported.";
}
}
else {
fallbackLocaleTried = false;
officeStrings = Strings.OfficeOM;
}
};
if (!isMicrosftAjaxLoaded()) {
window.Type = Function;
Type.registerNamespace = function (ns) {
window[ns] = window[ns] || {};
};
Type.prototype.registerClass = function (cls) {
cls = {};
};
}
var localeStringFile = basePath + OSF.getSupportedLocale(appLocale, OSF.ConstantNames.DefaultLocale) + "/" + OSF.ConstantNames.OfficeStringJS;
_loadScriptHelper.loadScript(localeStringFile, OSF.ConstantNames.OfficeStringsId, loadLocaleStringCallback, true, OSF.ConstantNames.LocaleStringLoadingTimeout);
};
var onAppCodeAndMSAjaxReady = function OSF__OfficeAppFactory_initialize$onAppCodeAndMSAjaxReady(loadSuccess) {
if (loadSuccess) {
_initializationHelper = new OSF.InitializationHelper(_hostInfo, _WebAppState, _context, _settings, _hostFacade);
if (_hostInfo.hostPlatform == "web" && _initializationHelper.saveAndSetDialogInfo) {
_initializationHelper.saveAndSetDialogInfo(getQueryStringValue("_host_Info"));
}
_initializationHelper.setAgaveHostCommunication();
getAppContextAsync(_WebAppState.wnd, function (appContext) {
if (OSF.AppTelemetry && OSF.AppTelemetry.logAppCommonMessage) {
OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync callback start");
}
_appInstanceId = appContext._appInstanceId;
var updateVersionInfo = function updateVersionInfo() {
var hostVersionItems = _hostInfo.hostSpecificFileVersion.split(".");
if (appContext.get_appMinorVersion) {
var isIOS = _hostInfo.hostPlatform == "ios";
if (!isIOS) {
if (isNaN(appContext.get_appMinorVersion())) {
appContext._appMinorVersion = parseInt(hostVersionItems[1]);
}
else if (hostVersionItems.length > 1 && !isNaN(Number(hostVersionItems[1]))) {
appContext._appMinorVersion = parseInt(hostVersionItems[1]);
}
}
}
if (_hostInfo.isDialog) {
appContext._isDialog = _hostInfo.isDialog;
}
};
updateVersionInfo();
var appReady = function appReady() {
_initializationHelper.prepareApiSurface && _initializationHelper.prepareApiSurface(appContext);
_loadScriptHelper.waitForFunction(function () { return Microsoft.Office.WebExtension.initialize != undefined; }, function (initializedDeclared) {
if (initializedDeclared) {
if (_initializationHelper.prepareApiSurface) {
Microsoft.Office.WebExtension.initialize(_initializationHelper.getInitializationReason(appContext));
}
else {
_initializationHelper.prepareRightBeforeWebExtensionInitialize(appContext);
}
_initializationHelper.prepareRightAfterWebExtensionInitialize && _initializationHelper.prepareRightAfterWebExtensionInitialize();
}
else {
throw "Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function.";
}
}, 400, 50);
};
if (!_loadScriptHelper.isScriptLoading(OSF.ConstantNames.OfficeStringsId)) {
loadLocaleStrings(appContext.get_appUILocale());
}
_loadScriptHelper.waitForScripts([OSF.ConstantNames.OfficeStringsId], function () {
if (officeStrings && !Strings.OfficeOM) {
Strings.OfficeOM = officeStrings;
}
_initializationHelper.loadAppSpecificScriptAndCreateOM(appContext, appReady, basePath);
});
});
}
else {
var errorMsg = "MicrosoftAjax.js is not loaded successfully.";
if (OSF.AppTelemetry && OSF.AppTelemetry.logAppException) {
OSF.AppTelemetry.logAppException(errorMsg);
}
throw errorMsg;
}
};
var onAppCodeReady = function OSF__OfficeAppFactory_initialize$onAppCodeReady() {
if (OSF.AppTelemetry && OSF.AppTelemetry.setOsfControlAppCorrelationId) {
OSF.AppTelemetry.setOsfControlAppCorrelationId(_hostInfo.osfControlAppCorrelationId);
}
if (_loadScriptHelper.isScriptLoading(OSF.ConstantNames.MicrosoftAjaxId)) {
_loadScriptHelper.waitForScripts([OSF.ConstantNames.MicrosoftAjaxId], onAppCodeAndMSAjaxReady);
}
else {
_loadScriptHelper.waitForFunction(isMicrosftAjaxLoaded, onAppCodeAndMSAjaxReady, 500, 100);
}
};
if (_hostInfo.isO15) {
_loadScriptHelper.loadScript(basePath + OSF.ConstantNames.O15InitHelper, OSF.ConstantNames.O15MappingId, onAppCodeReady);
}
else {
var hostSpecificFileName;
hostSpecificFileName = _hostInfo.hostType + "-" + _hostInfo.hostPlatform + "-" + _hostInfo.hostSpecificFileVersion + ".debug.js";
_loadScriptHelper.loadScript(basePath + hostSpecificFileName.toLowerCase(), OSF.ConstantNames.HostFileId, onAppCodeReady);
}
if (_hostInfo.hostLocale) {
loadLocaleStrings(_hostInfo.hostLocale);
}
if (requiresMsAjax && !isMicrosftAjaxLoaded()) {
var msAjaxCDNPath = (window.location.protocol.toLowerCase() === 'https:' ? 'https:' : 'http:') + '//ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js';
_loadScriptHelper.loadScriptParallel(msAjaxCDNPath, OSF.ConstantNames.MicrosoftAjaxId);
}
window.confirm = function OSF__OfficeAppFactory_initialize$confirm(message) {
throw 'Function window.confirm is not supported.';
return false;
};
window.alert = function OSF__OfficeAppFactory_initialize$alert(message) {
throw 'Function window.alert is not supported.';
};
window.prompt = function OSF__OfficeAppFactory_initialize$prompt(message, defaultvalue) {
throw 'Function window.prompt is not supported.';
return null;
};
var isOutlookAndroid = _hostInfo.hostType == "outlook" && _hostInfo.hostPlatform == "android";
if (!isOutlookAndroid) {
window.history.replaceState = null;
window.history.pushState = null;
}
};
initialize();
return {
getId: function OSF__OfficeAppFactory$getId() { return _WebAppState.id; },
getClientEndPoint: function OSF__OfficeAppFactory$getClientEndPoint() { return _WebAppState.clientEndPoint; },
getContext: function OSF__OfficeAppFactory$getContext() { return _context; },
setContext: function OSF__OfficeAppFactory$setContext(context) { _context = context; },
getHostInfo: function OSF_OfficeAppFactory$getHostInfo() { return _hostInfo; },
getHostFacade: function OSF__OfficeAppFactory$getHostFacade() { return _hostFacade; },
setHostFacade: function setHostFacade(hostFacade) { _hostFacade = hostFacade; },
getInitializationHelper: function OSF__OfficeAppFactory$getInitializationHelper() { return _initializationHelper; },
getCachedSessionSettingsKey: function OSF__OfficeAppFactory$getCachedSessionSettingsKey() {
return (_WebAppState.conversationID != null ? _WebAppState.conversationID : _appInstanceId) + "CachedSessionSettings";
},
getWebAppState: function OSF__OfficeAppFactory$getWebAppState() { return _WebAppState; },
getWindowLocationHash: function OSF__OfficeAppFactory$getHash() { return _windowLocationHash; },
getWindowLocationSearch: function OSF__OfficeAppFactory$getSearch() { return _windowLocationSearch; },
getLoadScriptHelper: function OSF__OfficeAppFactory$getLoadScriptHelper() { return _loadScriptHelper; },
getWindowName: function OSF__OfficeAppFactory$getWindowName() { return _windowName; }
};
})();