Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

office.debug.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /* Office JavaScript API library */
  2. /* Version: 16.0.7524.3000 */
  3. /*
  4. Copyright (c) Microsoft Corporation. All rights reserved.
  5. */
  6. /*
  7. Your use of this file is governed by the Microsoft Services Agreement http://go.microsoft.com/fwlink/?LinkId=266419.
  8. */
  9. var OSF = OSF || {};
  10. OSF.HostSpecificFileVersionDefault = "16.00";
  11. OSF.HostSpecificFileVersionMap = {
  12. "access": {
  13. "web": "16.00"
  14. },
  15. "agavito": {
  16. "winrt": "16.00"
  17. },
  18. "excel": {
  19. "ios": "16.00",
  20. "mac": "16.00",
  21. "web": "16.00",
  22. "win32": "16.01",
  23. "winrt": "16.00"
  24. },
  25. "onenote": {
  26. "web": "16.00",
  27. "win32": "16.00",
  28. "winrt": "16.00"
  29. },
  30. "outlook": {
  31. "ios": "16.00",
  32. "mac": "16.00",
  33. "web": "16.01",
  34. "win32": "16.02"
  35. },
  36. "powerpoint": {
  37. "ios": "16.00",
  38. "mac": "16.00",
  39. "web": "16.00",
  40. "win32": "16.01",
  41. "winrt": "16.00"
  42. },
  43. "project": {
  44. "win32": "16.00"
  45. },
  46. "sway": {
  47. "web": "16.00"
  48. },
  49. "word": {
  50. "ios": "16.00",
  51. "mac": "16.00",
  52. "web": "16.00",
  53. "win32": "16.01",
  54. "winrt": "16.00"
  55. }
  56. };
  57. OSF.SupportedLocales = {
  58. "ar-sa": true,
  59. "bg-bg": true,
  60. "ca-es": true,
  61. "cs-cz": true,
  62. "da-dk": true,
  63. "de-de": true,
  64. "el-gr": true,
  65. "en-us": true,
  66. "es-es": true,
  67. "et-ee": true,
  68. "eu-es": true,
  69. "fi-fi": true,
  70. "fr-fr": true,
  71. "gl-es": true,
  72. "he-il": true,
  73. "hi-in": true,
  74. "hr-hr": true,
  75. "hu-hu": true,
  76. "id-id": true,
  77. "it-it": true,
  78. "ja-jp": true,
  79. "kk-kz": true,
  80. "ko-kr": true,
  81. "lt-lt": true,
  82. "lv-lv": true,
  83. "ms-my": true,
  84. "nb-no": true,
  85. "nl-nl": true,
  86. "pl-pl": true,
  87. "pt-br": true,
  88. "pt-pt": true,
  89. "ro-ro": true,
  90. "ru-ru": true,
  91. "sk-sk": true,
  92. "sl-si": true,
  93. "sr-cyrl-cs": true,
  94. "sr-cyrl-rs": true,
  95. "sr-latn-cs": true,
  96. "sr-latn-rs": true,
  97. "sv-se": true,
  98. "th-th": true,
  99. "tr-tr": true,
  100. "uk-ua": true,
  101. "vi-vn": true,
  102. "zh-cn": true,
  103. "zh-tw": true
  104. };
  105. OSF.AssociatedLocales = {
  106. ar: "ar-sa",
  107. bg: "bg-bg",
  108. ca: "ca-es",
  109. cs: "cs-cz",
  110. da: "da-dk",
  111. de: "de-de",
  112. el: "el-gr",
  113. en: "en-us",
  114. es: "es-es",
  115. et: "et-ee",
  116. eu: "eu-es",
  117. fi: "fi-fi",
  118. fr: "fr-fr",
  119. gl: "gl-es",
  120. he: "he-il",
  121. hi: "hi-in",
  122. hr: "hr-hr",
  123. hu: "hu-hu",
  124. id: "id-id",
  125. it: "it-it",
  126. ja: "ja-jp",
  127. kk: "kk-kz",
  128. ko: "ko-kr",
  129. lt: "lt-lt",
  130. lv: "lv-lv",
  131. ms: "ms-my",
  132. nb: "nb-no",
  133. nl: "nl-nl",
  134. pl: "pl-pl",
  135. pt: "pt-br",
  136. ro: "ro-ro",
  137. ru: "ru-ru",
  138. sk: "sk-sk",
  139. sl: "sl-si",
  140. sr: "sr-cyrl-cs",
  141. sv: "sv-se",
  142. th: "th-th",
  143. tr: "tr-tr",
  144. uk: "uk-ua",
  145. vi: "vi-vn",
  146. zh: "zh-cn"
  147. };
  148. OSF.getSupportedLocale = function OSF$getSupportedLocale(locale, defaultLocale) {
  149. if (defaultLocale === void 0) { defaultLocale = "en-us"; }
  150. if (!locale) {
  151. return defaultLocale;
  152. }
  153. var supportedLocale;
  154. locale = locale.toLowerCase();
  155. if (locale in OSF.SupportedLocales) {
  156. supportedLocale = locale;
  157. }
  158. else {
  159. var localeParts = locale.split('-', 1);
  160. if (localeParts && localeParts.length > 0) {
  161. supportedLocale = OSF.AssociatedLocales[localeParts[0]];
  162. }
  163. }
  164. if (!supportedLocale) {
  165. supportedLocale = defaultLocale;
  166. }
  167. return supportedLocale;
  168. };
  169. var ScriptLoading;
  170. (function (ScriptLoading) {
  171. var ScriptInfo = (function () {
  172. function ScriptInfo(url, isReady, hasStarted, timer, pendingCallback) {
  173. this.url = url;
  174. this.isReady = isReady;
  175. this.hasStarted = hasStarted;
  176. this.timer = timer;
  177. this.hasError = false;
  178. this.pendingCallbacks = [];
  179. this.pendingCallbacks.push(pendingCallback);
  180. }
  181. return ScriptInfo;
  182. })();
  183. var ScriptTelemetry = (function () {
  184. function ScriptTelemetry(scriptId, startTime, msResponseTime) {
  185. this.scriptId = scriptId;
  186. this.startTime = startTime;
  187. this.msResponseTime = msResponseTime;
  188. }
  189. return ScriptTelemetry;
  190. })();
  191. var LoadScriptHelper = (function () {
  192. function LoadScriptHelper() {
  193. this.defaultScriptLoadingTimeout = 10000;
  194. this.loadedScriptByIds = {};
  195. this.scriptTelemetryBuffer = [];
  196. this.osfControlAppCorrelationId = "";
  197. this.basePath = null;
  198. this.constantNames = {
  199. OfficeJS: "office.js",
  200. OfficeDebugJS: "office.debug.js"
  201. };
  202. }
  203. LoadScriptHelper.prototype.isScriptLoading = function (id) {
  204. return !!(this.loadedScriptByIds[id] && this.loadedScriptByIds[id].hasStarted);
  205. };
  206. LoadScriptHelper.prototype.getOfficeJsBasePath = function () {
  207. if (this.basePath) {
  208. return this.basePath;
  209. }
  210. else {
  211. var getScriptBase = function (scriptSrc, scriptNameToCheck) {
  212. var scriptBase, indexOfJS, scriptSrcLowerCase;
  213. scriptSrcLowerCase = scriptSrc.toLowerCase();
  214. indexOfJS = scriptSrcLowerCase.indexOf(scriptNameToCheck);
  215. if (indexOfJS >= 0 && indexOfJS === (scriptSrc.length - scriptNameToCheck.length) && (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) {
  216. scriptBase = scriptSrc.substring(0, indexOfJS);
  217. }
  218. else if (indexOfJS >= 0
  219. && indexOfJS < (scriptSrc.length - scriptNameToCheck.length)
  220. && scriptSrc.charAt(indexOfJS + scriptNameToCheck.length) === '?'
  221. && (indexOfJS === 0 || scriptSrc.charAt(indexOfJS - 1) === '/' || scriptSrc.charAt(indexOfJS - 1) === '\\')) {
  222. scriptBase = scriptSrc.substring(0, indexOfJS);
  223. }
  224. return scriptBase;
  225. };
  226. var scripts = document.getElementsByTagName("script");
  227. var scriptsCount = scripts.length;
  228. var officeScripts = [this.constantNames.OfficeJS, this.constantNames.OfficeDebugJS];
  229. var officeScriptsCount = officeScripts.length;
  230. var i, j;
  231. for (i = 0; !this.basePath && i < scriptsCount; i++) {
  232. if (scripts[i].src) {
  233. for (j = 0; !this.basePath && j < officeScriptsCount; j++) {
  234. this.basePath = getScriptBase(scripts[i].src, officeScripts[j]);
  235. }
  236. }
  237. }
  238. return this.basePath;
  239. }
  240. };
  241. LoadScriptHelper.prototype.loadScript = function (url, scriptId, callback, highPriority, timeoutInMs) {
  242. this.loadScriptInternal(url, scriptId, callback, highPriority, timeoutInMs);
  243. };
  244. LoadScriptHelper.prototype.loadScriptParallel = function (url, scriptId, timeoutInMs) {
  245. this.loadScriptInternal(url, scriptId, null, false, timeoutInMs);
  246. };
  247. LoadScriptHelper.prototype.waitForFunction = function (scriptLoadTest, callback, numberOfTries, delay) {
  248. var attemptsRemaining = numberOfTries;
  249. var timerId;
  250. var validateFunction = function () {
  251. attemptsRemaining--;
  252. if (scriptLoadTest()) {
  253. callback(true);
  254. return;
  255. }
  256. else if (attemptsRemaining > 0) {
  257. timerId = window.setTimeout(validateFunction, delay);
  258. attemptsRemaining--;
  259. }
  260. else {
  261. window.clearTimeout(timerId);
  262. callback(false);
  263. }
  264. };
  265. validateFunction();
  266. };
  267. LoadScriptHelper.prototype.waitForScripts = function (ids, callback) {
  268. var _this = this;
  269. if (this.invokeCallbackIfScriptsReady(ids, callback) == false) {
  270. for (var i = 0; i < ids.length; i++) {
  271. var id = ids[i];
  272. var loadedScriptEntry = this.loadedScriptByIds[id];
  273. if (loadedScriptEntry) {
  274. loadedScriptEntry.pendingCallbacks.push(function () {
  275. _this.invokeCallbackIfScriptsReady(ids, callback);
  276. });
  277. }
  278. }
  279. }
  280. };
  281. LoadScriptHelper.prototype.logScriptLoading = function (scriptId, startTime, msResponseTime) {
  282. startTime = Math.floor(startTime);
  283. if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) {
  284. if (OSF.AppTelemetry.onScriptDone.length == 3) {
  285. OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime);
  286. }
  287. else {
  288. OSF.AppTelemetry.onScriptDone(scriptId, startTime, msResponseTime, this.osfControlAppCorrelationId);
  289. }
  290. }
  291. else {
  292. var scriptTelemetry = new ScriptTelemetry(scriptId, startTime, msResponseTime);
  293. this.scriptTelemetryBuffer.push(scriptTelemetry);
  294. }
  295. };
  296. LoadScriptHelper.prototype.setAppCorrelationId = function (appCorrelationId) {
  297. this.osfControlAppCorrelationId = appCorrelationId;
  298. };
  299. LoadScriptHelper.prototype.invokeCallbackIfScriptsReady = function (ids, callback) {
  300. var hasError = false;
  301. for (var i = 0; i < ids.length; i++) {
  302. var id = ids[i];
  303. var loadedScriptEntry = this.loadedScriptByIds[id];
  304. if (!loadedScriptEntry) {
  305. loadedScriptEntry = new ScriptInfo("", false, false, null, null);
  306. this.loadedScriptByIds[id] = loadedScriptEntry;
  307. }
  308. if (loadedScriptEntry.isReady == false) {
  309. return false;
  310. }
  311. else if (loadedScriptEntry.hasError) {
  312. hasError = true;
  313. }
  314. }
  315. callback(!hasError);
  316. return true;
  317. };
  318. LoadScriptHelper.prototype.getScriptEntryByUrl = function (url) {
  319. for (var key in this.loadedScriptByIds) {
  320. var scriptEntry = this.loadedScriptByIds[key];
  321. if (this.loadedScriptByIds.hasOwnProperty(key) && scriptEntry.url === url) {
  322. return scriptEntry;
  323. }
  324. }
  325. return null;
  326. };
  327. LoadScriptHelper.prototype.loadScriptInternal = function (url, scriptId, callback, highPriority, timeoutInMs) {
  328. if (url) {
  329. var self = this;
  330. var doc = window.document;
  331. var loadedScriptEntry = (scriptId && this.loadedScriptByIds[scriptId]) ? this.loadedScriptByIds[scriptId] : this.getScriptEntryByUrl(url);
  332. if (!loadedScriptEntry || loadedScriptEntry.hasError || loadedScriptEntry.url.toLowerCase() != url.toLowerCase()) {
  333. var script = doc.createElement("script");
  334. script.type = "text/javascript";
  335. if (scriptId) {
  336. script.id = scriptId;
  337. }
  338. if (!loadedScriptEntry) {
  339. loadedScriptEntry = new ScriptInfo(url, false, false, null, null);
  340. this.loadedScriptByIds[(scriptId ? scriptId : url)] = loadedScriptEntry;
  341. }
  342. else {
  343. loadedScriptEntry.url = url;
  344. loadedScriptEntry.hasError = false;
  345. loadedScriptEntry.isReady = false;
  346. }
  347. if (callback) {
  348. if (highPriority) {
  349. loadedScriptEntry.pendingCallbacks.unshift(callback);
  350. }
  351. else {
  352. loadedScriptEntry.pendingCallbacks.push(callback);
  353. }
  354. }
  355. var timeFromPageInit = -1;
  356. if (window.performance && window.performance.now) {
  357. timeFromPageInit = window.performance.now();
  358. }
  359. var startTime = (new Date()).getTime();
  360. var logTelemetry = function (succeeded) {
  361. if (scriptId) {
  362. var totalTime = (new Date()).getTime() - startTime;
  363. if (!succeeded) {
  364. totalTime = -totalTime;
  365. }
  366. self.logScriptLoading(scriptId, timeFromPageInit, totalTime);
  367. }
  368. self.flushTelemetryBuffer();
  369. };
  370. var onLoadCallback = function OSF_OUtil_loadScript$onLoadCallback() {
  371. logTelemetry(true);
  372. loadedScriptEntry.isReady = true;
  373. if (loadedScriptEntry.timer != null) {
  374. clearTimeout(loadedScriptEntry.timer);
  375. delete loadedScriptEntry.timer;
  376. }
  377. var pendingCallbackCount = loadedScriptEntry.pendingCallbacks.length;
  378. for (var i = 0; i < pendingCallbackCount; i++) {
  379. var currentCallback = loadedScriptEntry.pendingCallbacks.shift();
  380. if (currentCallback) {
  381. var result = currentCallback(true);
  382. if (result === false) {
  383. break;
  384. }
  385. }
  386. }
  387. };
  388. var onLoadError = function () {
  389. logTelemetry(false);
  390. loadedScriptEntry.hasError = true;
  391. loadedScriptEntry.isReady = true;
  392. if (loadedScriptEntry.timer != null) {
  393. clearTimeout(loadedScriptEntry.timer);
  394. delete loadedScriptEntry.timer;
  395. }
  396. var pendingCallbackCount = loadedScriptEntry.pendingCallbacks.length;
  397. for (var i = 0; i < pendingCallbackCount; i++) {
  398. var currentCallback = loadedScriptEntry.pendingCallbacks.shift();
  399. if (currentCallback) {
  400. var result = currentCallback(false);
  401. if (result === false) {
  402. break;
  403. }
  404. }
  405. }
  406. };
  407. if (script.readyState) {
  408. script.onreadystatechange = function () {
  409. if (script.readyState == "loaded" || script.readyState == "complete") {
  410. script.onreadystatechange = null;
  411. onLoadCallback();
  412. }
  413. };
  414. }
  415. else {
  416. script.onload = onLoadCallback;
  417. }
  418. script.onerror = onLoadError;
  419. timeoutInMs = timeoutInMs || this.defaultScriptLoadingTimeout;
  420. loadedScriptEntry.timer = setTimeout(onLoadError, timeoutInMs);
  421. loadedScriptEntry.hasStarted = true;
  422. script.src = url;
  423. doc.getElementsByTagName("head")[0].appendChild(script);
  424. }
  425. else if (loadedScriptEntry.isReady) {
  426. callback(true);
  427. }
  428. else {
  429. if (highPriority) {
  430. loadedScriptEntry.pendingCallbacks.unshift(callback);
  431. }
  432. else {
  433. loadedScriptEntry.pendingCallbacks.push(callback);
  434. }
  435. }
  436. }
  437. };
  438. LoadScriptHelper.prototype.flushTelemetryBuffer = function () {
  439. if (OSF.AppTelemetry && OSF.AppTelemetry.onScriptDone) {
  440. for (var i = 0; i < this.scriptTelemetryBuffer.length; i++) {
  441. var scriptTelemetry = this.scriptTelemetryBuffer[i];
  442. if (OSF.AppTelemetry.onScriptDone.length == 3) {
  443. OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime);
  444. }
  445. else {
  446. OSF.AppTelemetry.onScriptDone(scriptTelemetry.scriptId, scriptTelemetry.startTime, scriptTelemetry.msResponseTime, this.osfControlAppCorrelationId);
  447. }
  448. }
  449. this.scriptTelemetryBuffer = [];
  450. }
  451. };
  452. return LoadScriptHelper;
  453. })();
  454. ScriptLoading.LoadScriptHelper = LoadScriptHelper;
  455. })(ScriptLoading || (ScriptLoading = {}));
  456. OSF.ConstantNames = {
  457. FileVersion: "16.0.7524.3000",
  458. OfficeJS: "office.js",
  459. OfficeDebugJS: "office.debug.js",
  460. DefaultLocale: "en-us",
  461. LocaleStringLoadingTimeout: 5000,
  462. MicrosoftAjaxId: "MSAJAX",
  463. OfficeStringsId: "OFFICESTRINGS",
  464. OfficeJsId: "OFFICEJS",
  465. HostFileId: "HOST",
  466. O15MappingId: "O15Mapping",
  467. OfficeStringJS: "office_strings.debug.js",
  468. O15InitHelper: "o15apptofilemappingtable.debug.js",
  469. SupportedLocales: OSF.SupportedLocales,
  470. AssociatedLocales: OSF.AssociatedLocales
  471. };
  472. OSF.InitializationHelper = function OSF_InitializationHelper(hostInfo, webAppState, context, settings, hostFacade) {
  473. this._hostInfo = hostInfo;
  474. this._webAppState = webAppState;
  475. this._context = context;
  476. this._settings = settings;
  477. this._hostFacade = hostFacade;
  478. };
  479. OSF.InitializationHelper.prototype.saveAndSetDialogInfo = function OSF_InitializationHelper$saveAndSetDialogInfo(hostInfoValue) {
  480. };
  481. OSF.InitializationHelper.prototype.getAppContext = function OSF_InitializationHelper$getAppContext(wnd, gotAppContext) {
  482. };
  483. OSF.InitializationHelper.prototype.setAgaveHostCommunication = function OSF_InitializationHelper$setAgaveHostCommunication() {
  484. };
  485. OSF.InitializationHelper.prototype.prepareRightBeforeWebExtensionInitialize = function OSF_InitializationHelper$prepareRightBeforeWebExtensionInitialize(appContext) {
  486. };
  487. OSF.InitializationHelper.prototype.loadAppSpecificScriptAndCreateOM = function OSF_InitializationHelper$loadAppSpecificScriptAndCreateOM(appContext, appReady, basePath) {
  488. };
  489. OSF.InitializationHelper.prototype.prepareRightAfterWebExtensionInitialize = function OSF_InitializationHelper$prepareRightAfterWebExtensionInitialize() {
  490. };
  491. OSF._OfficeAppFactory = (function OSF__OfficeAppFactory() {
  492. var _setNamespace = function OSF_OUtil$_setNamespace(name, parent) {
  493. if (parent && name && !parent[name]) {
  494. parent[name] = {};
  495. }
  496. };
  497. _setNamespace("Office", window);
  498. _setNamespace("Microsoft", window);
  499. _setNamespace("Office", Microsoft);
  500. _setNamespace("WebExtension", Microsoft.Office);
  501. window.Office = Microsoft.Office.WebExtension;
  502. var _context = {};
  503. var _settings = {};
  504. var _hostFacade = {};
  505. var _WebAppState = { id: null, webAppUrl: null, conversationID: null, clientEndPoint: null, wnd: window.parent, focused: false };
  506. var _hostInfo = { isO15: true, isRichClient: true, hostType: "", hostPlatform: "", hostSpecificFileVersion: "", hostLocale: "", osfControlAppCorrelationId: "", isDialog: false };
  507. var _initializationHelper = {};
  508. var _appInstanceId = null;
  509. var _loadScriptHelper = new ScriptLoading.LoadScriptHelper();
  510. if (window.performance && window.performance.now) {
  511. _loadScriptHelper.logScriptLoading(OSF.ConstantNames.OfficeJsId, -1, window.performance.now());
  512. }
  513. var _windowLocationHash = window.location.hash;
  514. var _windowLocationSearch = window.location.search;
  515. var _windowName = window.name;
  516. var getQueryStringValue = function OSF__OfficeAppFactory$getQueryStringValue(paramName) {
  517. var hostInfoValue;
  518. var searchString = window.location.search;
  519. if (searchString) {
  520. var hostInfoParts = searchString.split(paramName + "=");
  521. if (hostInfoParts.length > 1) {
  522. var hostInfoValueRestString = hostInfoParts[1];
  523. var separatorRegex = new RegExp("[&#]", "g");
  524. var hostInfoValueParts = hostInfoValueRestString.split(separatorRegex);
  525. if (hostInfoValueParts.length > 0) {
  526. hostInfoValue = hostInfoValueParts[0];
  527. }
  528. }
  529. }
  530. return hostInfoValue;
  531. };
  532. var _retrieveHostInfo = function OSF__OfficeAppFactory$_retrieveHostInfo() {
  533. var hostInfoParaName = "_host_Info";
  534. var hostInfoValue = getQueryStringValue(hostInfoParaName);
  535. if (!hostInfoValue) {
  536. try {
  537. var windowNameObj = JSON.parse(_windowName);
  538. hostInfoValue = windowNameObj ? windowNameObj["hostInfo"] : null;
  539. }
  540. catch (Exception) {
  541. }
  542. }
  543. if (!hostInfoValue) {
  544. try {
  545. var fallbackHostInfo = window.external.GetHostInfo();
  546. if (fallbackHostInfo == "isDialog") {
  547. _hostInfo.isO15 = true;
  548. _hostInfo.isDialog = true;
  549. }
  550. else if (fallbackHostInfo.toLowerCase().indexOf("mac") !== -1 && fallbackHostInfo.toLowerCase().indexOf("outlook") !== -1) {
  551. _hostInfo.isO15 = true;
  552. }
  553. else {
  554. var hostInfoParts = fallbackHostInfo.split(hostInfoParaName + "=");
  555. if (hostInfoParts.length > 1) {
  556. hostInfoValue = hostInfoParts[1];
  557. }
  558. else {
  559. hostInfoValue = fallbackHostInfo;
  560. }
  561. }
  562. }
  563. catch (Exception) {
  564. }
  565. }
  566. var getSessionStorage = function OSF__OfficeAppFactory$_retrieveHostInfo$getSessionStorage() {
  567. var osfSessionStorage = null;
  568. try {
  569. if (window.sessionStorage) {
  570. osfSessionStorage = window.sessionStorage;
  571. }
  572. }
  573. catch (ex) {
  574. }
  575. return osfSessionStorage;
  576. };
  577. var osfSessionStorage = getSessionStorage();
  578. if (!hostInfoValue && osfSessionStorage && osfSessionStorage.getItem("hostInfoValue")) {
  579. hostInfoValue = osfSessionStorage.getItem("hostInfoValue");
  580. }
  581. if (hostInfoValue) {
  582. hostInfoValue = decodeURIComponent(hostInfoValue);
  583. _hostInfo.isO15 = false;
  584. var items = hostInfoValue.split("$");
  585. if (typeof items[2] == "undefined") {
  586. items = hostInfoValue.split("|");
  587. }
  588. _hostInfo.hostType = (typeof items[0] == "undefined") ? "" : items[0].toLowerCase();
  589. _hostInfo.hostPlatform = (typeof items[1] == "undefined") ? "" : items[1].toLowerCase();
  590. ;
  591. _hostInfo.hostSpecificFileVersion = (typeof items[2] == "undefined") ? "" : items[2].toLowerCase();
  592. _hostInfo.hostLocale = (typeof items[3] == "undefined") ? "" : items[3].toLowerCase();
  593. _hostInfo.osfControlAppCorrelationId = (typeof items[4] == "undefined") ? "" : items[4];
  594. if (_hostInfo.osfControlAppCorrelationId == "telemetry") {
  595. _hostInfo.osfControlAppCorrelationId = "";
  596. }
  597. _hostInfo.isDialog = (((typeof items[5]) != "undefined") && items[5] == "isDialog") ? true : false;
  598. var hostSpecificFileVersionValue = parseFloat(_hostInfo.hostSpecificFileVersion);
  599. var fallbackVersion = OSF.HostSpecificFileVersionDefault;
  600. if (OSF.HostSpecificFileVersionMap[_hostInfo.hostType] && OSF.HostSpecificFileVersionMap[_hostInfo.hostType][_hostInfo.hostPlatform]) {
  601. fallbackVersion = OSF.HostSpecificFileVersionMap[_hostInfo.hostType][_hostInfo.hostPlatform];
  602. }
  603. if (hostSpecificFileVersionValue > parseFloat(fallbackVersion)) {
  604. _hostInfo.hostSpecificFileVersion = fallbackVersion;
  605. }
  606. if (osfSessionStorage) {
  607. try {
  608. osfSessionStorage.setItem("hostInfoValue", hostInfoValue);
  609. }
  610. catch (e) {
  611. }
  612. }
  613. }
  614. else {
  615. _hostInfo.isO15 = true;
  616. _hostInfo.hostLocale = getQueryStringValue("locale");
  617. }
  618. };
  619. var getAppContextAsync = function OSF__OfficeAppFactory$getAppContextAsync(wnd, gotAppContext) {
  620. if (OSF.AppTelemetry && OSF.AppTelemetry.logAppCommonMessage) {
  621. OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync starts");
  622. }
  623. _initializationHelper.getAppContext(wnd, gotAppContext);
  624. };
  625. var initialize = function OSF__OfficeAppFactory$initialize() {
  626. _retrieveHostInfo();
  627. if (_hostInfo.hostPlatform == "web" && _hostInfo.isDialog && window == window.top && window.opener == null) {
  628. window.open('', '_self', '');
  629. window.close();
  630. }
  631. _loadScriptHelper.setAppCorrelationId(_hostInfo.osfControlAppCorrelationId);
  632. var basePath = _loadScriptHelper.getOfficeJsBasePath();
  633. var requiresMsAjax = false;
  634. if (!basePath)
  635. throw "Office Web Extension script library file name should be " + OSF.ConstantNames.OfficeJS + " or " + OSF.ConstantNames.OfficeDebugJS + ".";
  636. var isMicrosftAjaxLoaded = function OSF$isMicrosftAjaxLoaded() {
  637. if ((typeof (Sys) !== 'undefined' && typeof (Type) !== 'undefined' &&
  638. Sys.StringBuilder && typeof (Sys.StringBuilder) === "function" &&
  639. Type.registerNamespace && typeof (Type.registerNamespace) === "function" &&
  640. Type.registerClass && typeof (Type.registerClass) === "function") ||
  641. (typeof (OfficeExt) !== "undefined" && OfficeExt.MsAjaxError)) {
  642. return true;
  643. }
  644. else {
  645. return false;
  646. }
  647. };
  648. var officeStrings = null;
  649. var loadLocaleStrings = function OSF__OfficeAppFactory_initialize$loadLocaleStrings(appLocale) {
  650. var fallbackLocaleTried = false;
  651. var loadLocaleStringCallback = function OSF__OfficeAppFactory_initialize$loadLocaleStringCallback() {
  652. if (typeof Strings == 'undefined' || typeof Strings.OfficeOM == 'undefined') {
  653. if (!fallbackLocaleTried) {
  654. fallbackLocaleTried = true;
  655. var fallbackLocaleStringFile = basePath + OSF.ConstantNames.DefaultLocale + "/" + OSF.ConstantNames.OfficeStringJS;
  656. _loadScriptHelper.loadScript(fallbackLocaleStringFile, OSF.ConstantNames.OfficeStringsId, loadLocaleStringCallback, true, OSF.ConstantNames.LocaleStringLoadingTimeout);
  657. return false;
  658. }
  659. else {
  660. throw "Neither the locale, " + appLocale.toLowerCase() + ", provided by the host app nor the fallback locale " + OSF.ConstantNames.DefaultLocale + " are supported.";
  661. }
  662. }
  663. else {
  664. fallbackLocaleTried = false;
  665. officeStrings = Strings.OfficeOM;
  666. }
  667. };
  668. if (!isMicrosftAjaxLoaded()) {
  669. window.Type = Function;
  670. Type.registerNamespace = function (ns) {
  671. window[ns] = window[ns] || {};
  672. };
  673. Type.prototype.registerClass = function (cls) {
  674. cls = {};
  675. };
  676. }
  677. var localeStringFile = basePath + OSF.getSupportedLocale(appLocale, OSF.ConstantNames.DefaultLocale) + "/" + OSF.ConstantNames.OfficeStringJS;
  678. _loadScriptHelper.loadScript(localeStringFile, OSF.ConstantNames.OfficeStringsId, loadLocaleStringCallback, true, OSF.ConstantNames.LocaleStringLoadingTimeout);
  679. };
  680. var onAppCodeAndMSAjaxReady = function OSF__OfficeAppFactory_initialize$onAppCodeAndMSAjaxReady(loadSuccess) {
  681. if (loadSuccess) {
  682. _initializationHelper = new OSF.InitializationHelper(_hostInfo, _WebAppState, _context, _settings, _hostFacade);
  683. if (_hostInfo.hostPlatform == "web" && _initializationHelper.saveAndSetDialogInfo) {
  684. _initializationHelper.saveAndSetDialogInfo(getQueryStringValue("_host_Info"));
  685. }
  686. _initializationHelper.setAgaveHostCommunication();
  687. getAppContextAsync(_WebAppState.wnd, function (appContext) {
  688. if (OSF.AppTelemetry && OSF.AppTelemetry.logAppCommonMessage) {
  689. OSF.AppTelemetry.logAppCommonMessage("getAppContextAsync callback start");
  690. }
  691. _appInstanceId = appContext._appInstanceId;
  692. var updateVersionInfo = function updateVersionInfo() {
  693. var hostVersionItems = _hostInfo.hostSpecificFileVersion.split(".");
  694. if (appContext.get_appMinorVersion) {
  695. var isIOS = _hostInfo.hostPlatform == "ios";
  696. if (!isIOS) {
  697. if (isNaN(appContext.get_appMinorVersion())) {
  698. appContext._appMinorVersion = parseInt(hostVersionItems[1]);
  699. }
  700. else if (hostVersionItems.length > 1 && !isNaN(Number(hostVersionItems[1]))) {
  701. appContext._appMinorVersion = parseInt(hostVersionItems[1]);
  702. }
  703. }
  704. }
  705. if (_hostInfo.isDialog) {
  706. appContext._isDialog = _hostInfo.isDialog;
  707. }
  708. };
  709. updateVersionInfo();
  710. var appReady = function appReady() {
  711. _initializationHelper.prepareApiSurface && _initializationHelper.prepareApiSurface(appContext);
  712. _loadScriptHelper.waitForFunction(function () { return Microsoft.Office.WebExtension.initialize != undefined; }, function (initializedDeclared) {
  713. if (initializedDeclared) {
  714. if (_initializationHelper.prepareApiSurface) {
  715. Microsoft.Office.WebExtension.initialize(_initializationHelper.getInitializationReason(appContext));
  716. }
  717. else {
  718. _initializationHelper.prepareRightBeforeWebExtensionInitialize(appContext);
  719. }
  720. _initializationHelper.prepareRightAfterWebExtensionInitialize && _initializationHelper.prepareRightAfterWebExtensionInitialize();
  721. }
  722. else {
  723. 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.";
  724. }
  725. }, 400, 50);
  726. };
  727. if (!_loadScriptHelper.isScriptLoading(OSF.ConstantNames.OfficeStringsId)) {
  728. loadLocaleStrings(appContext.get_appUILocale());
  729. }
  730. _loadScriptHelper.waitForScripts([OSF.ConstantNames.OfficeStringsId], function () {
  731. if (officeStrings && !Strings.OfficeOM) {
  732. Strings.OfficeOM = officeStrings;
  733. }
  734. _initializationHelper.loadAppSpecificScriptAndCreateOM(appContext, appReady, basePath);
  735. });
  736. });
  737. }
  738. else {
  739. var errorMsg = "MicrosoftAjax.js is not loaded successfully.";
  740. if (OSF.AppTelemetry && OSF.AppTelemetry.logAppException) {
  741. OSF.AppTelemetry.logAppException(errorMsg);
  742. }
  743. throw errorMsg;
  744. }
  745. };
  746. var onAppCodeReady = function OSF__OfficeAppFactory_initialize$onAppCodeReady() {
  747. if (OSF.AppTelemetry && OSF.AppTelemetry.setOsfControlAppCorrelationId) {
  748. OSF.AppTelemetry.setOsfControlAppCorrelationId(_hostInfo.osfControlAppCorrelationId);
  749. }
  750. if (_loadScriptHelper.isScriptLoading(OSF.ConstantNames.MicrosoftAjaxId)) {
  751. _loadScriptHelper.waitForScripts([OSF.ConstantNames.MicrosoftAjaxId], onAppCodeAndMSAjaxReady);
  752. }
  753. else {
  754. _loadScriptHelper.waitForFunction(isMicrosftAjaxLoaded, onAppCodeAndMSAjaxReady, 500, 100);
  755. }
  756. };
  757. if (_hostInfo.isO15) {
  758. _loadScriptHelper.loadScript(basePath + OSF.ConstantNames.O15InitHelper, OSF.ConstantNames.O15MappingId, onAppCodeReady);
  759. }
  760. else {
  761. var hostSpecificFileName;
  762. hostSpecificFileName = _hostInfo.hostType + "-" + _hostInfo.hostPlatform + "-" + _hostInfo.hostSpecificFileVersion + ".debug.js";
  763. _loadScriptHelper.loadScript(basePath + hostSpecificFileName.toLowerCase(), OSF.ConstantNames.HostFileId, onAppCodeReady);
  764. }
  765. if (_hostInfo.hostLocale) {
  766. loadLocaleStrings(_hostInfo.hostLocale);
  767. }
  768. if (requiresMsAjax && !isMicrosftAjaxLoaded()) {
  769. var msAjaxCDNPath = (window.location.protocol.toLowerCase() === 'https:' ? 'https:' : 'http:') + '//ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js';
  770. _loadScriptHelper.loadScriptParallel(msAjaxCDNPath, OSF.ConstantNames.MicrosoftAjaxId);
  771. }
  772. window.confirm = function OSF__OfficeAppFactory_initialize$confirm(message) {
  773. throw 'Function window.confirm is not supported.';
  774. return false;
  775. };
  776. window.alert = function OSF__OfficeAppFactory_initialize$alert(message) {
  777. throw 'Function window.alert is not supported.';
  778. };
  779. window.prompt = function OSF__OfficeAppFactory_initialize$prompt(message, defaultvalue) {
  780. throw 'Function window.prompt is not supported.';
  781. return null;
  782. };
  783. window.history.replaceState = null;
  784. window.history.pushState = null;
  785. };
  786. initialize();
  787. return {
  788. getId: function OSF__OfficeAppFactory$getId() { return _WebAppState.id; },
  789. getClientEndPoint: function OSF__OfficeAppFactory$getClientEndPoint() { return _WebAppState.clientEndPoint; },
  790. getContext: function OSF__OfficeAppFactory$getContext() { return _context; },
  791. setContext: function OSF__OfficeAppFactory$setContext(context) { _context = context; },
  792. getHostInfo: function OSF_OfficeAppFactory$getHostInfo() { return _hostInfo; },
  793. getHostFacade: function OSF__OfficeAppFactory$getHostFacade() { return _hostFacade; },
  794. setHostFacade: function setHostFacade(hostFacade) { _hostFacade = hostFacade; },
  795. getInitializationHelper: function OSF__OfficeAppFactory$getInitializationHelper() { return _initializationHelper; },
  796. getCachedSessionSettingsKey: function OSF__OfficeAppFactory$getCachedSessionSettingsKey() {
  797. return (_WebAppState.conversationID != null ? _WebAppState.conversationID : _appInstanceId) + "CachedSessionSettings";
  798. },
  799. getWebAppState: function OSF__OfficeAppFactory$getWebAppState() { return _WebAppState; },
  800. getWindowLocationHash: function OSF__OfficeAppFactory$getHash() { return _windowLocationHash; },
  801. getWindowLocationSearch: function OSF__OfficeAppFactory$getSearch() { return _windowLocationSearch; },
  802. getLoadScriptHelper: function OSF__OfficeAppFactory$getLoadScriptHelper() { return _loadScriptHelper; },
  803. getWindowName: function OSF__OfficeAppFactory$getWindowName() { return _windowName; }
  804. };
  805. })();