init.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright © 2014 - 2018 Esri. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. ///////////////////////////////////////////////////////////////////////////
  16. var dojoConfig, jimuConfig;
  17. /*global weinreUrl, loadResources, _loadPolyfills, loadingCallback, debug, allCookies, unescape */
  18. var ie = (function() {
  19. var undef,
  20. v = 3,
  21. div = document.createElement('div'),
  22. all = div.getElementsByTagName('i');
  23. div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->';
  24. while(all[0]){
  25. div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->';
  26. }
  27. return v > 4 ? v : undef;
  28. }());
  29. (function(argument) {
  30. if (ie < 8){
  31. var mainLoading = document.getElementById('main-loading');
  32. var appLoading = document.getElementById('app-loading');
  33. var ieNotes = document.getElementById('ie-note');
  34. appLoading.style.display = 'none';
  35. ieNotes.style.display = 'block';
  36. mainLoading.style.backgroundColor = "#fff";
  37. return;
  38. }
  39. //handle edit=true parameter
  40. if(!window.isXT && window.location.pathname.indexOf('/apps/webappviewer3d') > -1 &&
  41. window.queryObject.edit === 'true' && window.queryObject.appid){
  42. window.location.href = window.location.href.replace('webappviewer3d', 'webappbuilder');
  43. return;
  44. }
  45. var resources = [];
  46. if (debug) {
  47. resources.push(weinreUrl);
  48. }
  49. if (!window.path)
  50. window.path = "/GISBIM/";
  51. if (!window.apiUrl) {
  52. console.error('no apiUrl.');
  53. } else if (!window.path) {
  54. console.error('no path.');
  55. } else {
  56. if(window.location.protocol === 'https:'){
  57. var reg = /^http:\/\//i;
  58. if(reg.test(window.apiUrl)){
  59. window.apiUrl = window.apiUrl.replace(reg, 'https://');
  60. }
  61. if(reg.test(window.path)){
  62. window.path = window.path.replace(reg, 'https://');
  63. }
  64. }
  65. /*jshint unused:false*/
  66. dojoConfig = {
  67. parseOnLoad: false,
  68. async: true,
  69. tlmSiblingOfDojo: false,
  70. has: {
  71. 'extend-esri': 1
  72. }
  73. };
  74. setLocale();
  75. if (window.isRTL) {
  76. dojoConfig.has['dojo-bidi'] = true;
  77. }
  78. resources = resources.concat([
  79. window.apiUrl + 'dojo/resources/dojo.css',
  80. window.apiUrl + 'dijit/themes/claro/claro.css',
  81. window.apiUrl + 'dijit/themes/dijit.css',
  82. window.apiUrl + 'dijit/themes/dijit_rtl.css',
  83. window.apiUrl + 'esri/css/main.css',
  84. window.apiUrl + 'dojox/layout/resources/ResizeHandle.css',
  85. window.path + 'jimu.js/css/jimu-theme.css',
  86. window.path + 'libs/caja-html-sanitizer-minified.js',
  87. //because we have jimu/dijit/GridLayout dijit, so we import this css here
  88. window.path + 'libs/goldenlayout/goldenlayout-base.css',
  89. window.path + 'libs/goldenlayout/goldenlayout-light-theme.css'
  90. ]);
  91. if (window.apiUrl.substr(window.apiUrl.length - 'arcgis-js-api/'.length,
  92. 'arcgis-js-api/'.length) === 'arcgis-js-api/') {
  93. //after build, we put js api here
  94. //user can also download release api package and put here
  95. dojoConfig.baseUrl = window.path;
  96. dojoConfig.packages = [{
  97. name: "dojo",
  98. location: window.apiUrl + "dojo"
  99. }, {
  100. name: "dijit",
  101. location: window.apiUrl + "dijit"
  102. }, {
  103. name: "dojox",
  104. location: window.apiUrl + "dojox"
  105. }, {
  106. name: "dgrid",
  107. location: window.apiUrl + "dgrid"
  108. }, {
  109. name: "esri",
  110. location: window.apiUrl + "esri"
  111. }, {
  112. name: "moment",
  113. location: window.apiUrl + "moment"
  114. }, {
  115. name: "@dojo",
  116. location: window.apiUrl + "node_modules/@dojo"
  117. }, {
  118. name: "tslib",
  119. location: window.apiUrl + "node_modules/tslib",
  120. main: "tslib"
  121. }, {
  122. name: "cldrjs",
  123. location: window.apiUrl + "node_modules/cldrjs",
  124. main: "dist/cldr"
  125. }, {
  126. name: "globalize",
  127. location: window.apiUrl + "node_modules/globalize",
  128. main: "dist/globalize"
  129. }, {
  130. name: "maquette",
  131. location: window.apiUrl + "node_modules/maquette",
  132. main: "dist/maquette.umd"
  133. }, {
  134. name: "maquette-jsx",
  135. location: window.apiUrl + "node_modules/maquette-jsx",
  136. main: "dist/maquette-jsx.umd"
  137. }, {
  138. name: "maquette-css-transitions",
  139. location: window.apiUrl + "node_modules/maquette-css-transitions",
  140. main: "dist/maquette-css-transitions.umd"
  141. }, {
  142. name: "widgets",
  143. location: "widgets"
  144. }, {
  145. name: "jimu",
  146. location: "jimu.js"
  147. }, {
  148. name: "themes",
  149. location: "themes"
  150. }, {
  151. name: "libs",
  152. location: "libs"
  153. }, {
  154. name: "dynamic-modules",
  155. location: "dynamic-modules"
  156. }, {
  157. name: "fx3d",
  158. location: "fx3d/esri"
  159. }];
  160. resources.push(window.apiUrl + '/dojo/dojo.js');
  161. } else {
  162. dojoConfig.baseUrl = window.apiUrl + 'dojo';
  163. dojoConfig.packages = [{
  164. name: "widgets",
  165. location: window.path + "widgets"
  166. }, {
  167. name: "jimu",
  168. location: window.path + "jimu.js"
  169. }, {
  170. name: "themes",
  171. location: window.path + "themes"
  172. }, {
  173. name: "libs",
  174. location: window.path + "libs"
  175. }, {
  176. name: "dynamic-modules",
  177. location: window.path + "dynamic-modules"
  178. }, {
  179. name: "configs",
  180. location: window.path + "configs"
  181. }, {
  182. name: "fx3d",
  183. location: window.path + "fx3d/esri"
  184. }];
  185. resources.push(window.apiUrl + 'init.js');
  186. }
  187. jimuConfig = {
  188. loadingId: 'main-loading',
  189. mainPageId: 'main-page',
  190. layoutId: 'jimu-layout-manager',
  191. mapId: 'map'
  192. };
  193. loadResources(resources, null, function(url, loaded) {
  194. if (typeof loadingCallback === 'function') {
  195. loadingCallback(url, loaded, resources.length);
  196. }
  197. }, function() {
  198. continueLoad();
  199. function continueLoad(){
  200. if(typeof require === 'undefined'){
  201. if (window.console){
  202. console.log('Waiting for API loaded.');
  203. }
  204. setTimeout(continueLoad, 100);
  205. return;
  206. }
  207. _loadPolyfills("", function() {
  208. window.appInfo.appPath = window.path;
  209. require(['jimu/main', 'libs/main', 'dynamic-modules/preload'], function(jimuMain) {
  210. //loadingCallback('jimu', resources.length + 1, resources.length);
  211. jimuMain.initApp();
  212. });
  213. });
  214. }
  215. });
  216. }
  217. function setLocale(){
  218. if(window.queryObject.locale){
  219. dojoConfig.locale = window.queryObject.locale.toLowerCase();
  220. window._setRTL(dojoConfig.locale);
  221. return;
  222. }
  223. if(allCookies.esri_auth){
  224. /*jshint -W061 */
  225. var userObj = eval('(' + unescape(allCookies.esri_auth) + ')');
  226. if(userObj.culture){
  227. dojoConfig.locale = userObj.culture;
  228. }
  229. }
  230. if(window.queryObject.mode){
  231. if(allCookies.wab_locale){
  232. dojoConfig.locale = allCookies.wab_locale;
  233. }
  234. }else{
  235. if(allCookies.wab_app_locale){
  236. dojoConfig.locale = allCookies.wab_app_locale;
  237. }
  238. }
  239. if(!dojoConfig.locale){
  240. dojoConfig.locale = navigator.language ? navigator.language : navigator.userLanguage;
  241. }
  242. dojoConfig.locale = dojoConfig.locale.toLowerCase();
  243. window._setRTL(dojoConfig.locale);
  244. }
  245. })();