Advertisement
Opsavagebass

Untitled

Jan 20th, 2018
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. function scaleBodyWidthAndHeight()
  2. {
  3. if(WEBVIEW_RECEIVED_OS == 'ios') // Adjusting for IPAD (OS = ios)
  4. {
  5. // On iPad, the html body is slightly larger than the viewport
  6. if( typeof window.innerWidth != "undefined" &&
  7. (document.body.style.width != window.innerWidth || document.body.style.height != window.innerHeight))
  8. {
  9. document.body.style.width = window.innerWidth + 'px';
  10. document.body.style.height = window.innerHeight + 'px';
  11. }
  12. }
  13. }
  14.  
  15. function foobar_cont(){
  16. //console.log("Finished.");
  17. };
  18.  
  19. function sleep(millis, callback)
  20. {
  21. setTimeout(function() {
  22. callback();
  23. }, millis);
  24. }
  25.  
  26. function showLoading(blnShow) {
  27.  
  28. viewportDimensions = getViewportDimensions();
  29.  
  30. var currentViewportHeight = viewportDimensions['height'];
  31. var currentViewportWidth = viewportDimensions['width'];
  32.  
  33. if (blnShow)
  34. {
  35. LOADING_ELEM.style.width = currentViewportWidth + 'px';
  36. LOADING_ELEM.style.height = currentViewportHeight + 'px';
  37. LOADING_ELEM.style.display = 'table';
  38. }
  39. else
  40. {
  41. LOADING_ELEM.style.display = 'none';
  42. }
  43. }
  44.  
  45. function adjustLoading()
  46. {
  47. viewportDimensions = getViewportDimensions();
  48.  
  49. var currentViewportHeight = viewportDimensions['height'];
  50. var currentViewportWidth = viewportDimensions['width'];
  51.  
  52. LOADING_ELEM.style.width = currentViewportWidth + 'px';
  53. LOADING_ELEM.style.height = currentViewportHeight + 'px';
  54.  
  55. setTimeout("adjustLoading()", 50);
  56. }
  57.  
  58. // Getting areas;
  59. function getAreas()
  60. {
  61. IMG_AREAS = {};
  62.  
  63. if(typeof IMG_ELEM_AREA_LANDSCAPE != "undefined" && IMG_ELEM_AREA_LANDSCAPE)
  64. {
  65. var arrayAreas = IMG_ELEM_AREA_LANDSCAPE;
  66. IMG_AREAS[IMG_ELEM_LANDSCAPE_TAG] = {};
  67. for(var i = 0; i < arrayAreas.length; i++)
  68. {
  69. IMG_AREAS[IMG_ELEM_LANDSCAPE_TAG][i] = arrayAreas[i].coords;
  70. }
  71. }
  72.  
  73. }
  74.  
  75. // Scale areas
  76. function scaleAreas()
  77. {
  78. var rescale = IMG_RESIZED_WIDTH / IMG_WIDTH;
  79.  
  80. //console.log(rescale);
  81.  
  82. var arrayAreas = IMG_ELEM_AREA;
  83.  
  84. for(var i = 0; i < arrayAreas.length; i++)
  85. {
  86. var sarray = IMG_AREAS[IMG_ELEM_AREA_TAG][i].split(","); // convert coordinates to a numeric array assuming comma-delimited values
  87. //console.log(sarray);
  88. var rarray =new Array();
  89. for(var j = 0; j < sarray.length; j++)
  90. {
  91. // rescale the values
  92. rarray[j]=Math.round(parseInt(sarray[j]) * rescale);
  93. }
  94. arrayAreas[i].coords=rarray.join(","); // put the values back into a string
  95. //console.log(arrayAreas[i].coords);
  96. }
  97. }
  98.  
  99.  
  100. // display method, basically starts the processing
  101. var display = function() {
  102.  
  103. // Fetching various data
  104. webviewFetcher();
  105.  
  106. // Body fixes (OS specific)
  107. scaleBodyWidthAndHeight(); // re-add if needed, shouldn't be needed in the new processing
  108.  
  109. // Set details for actual image used
  110. orientationBasedAdjust();
  111.  
  112. if (isImgLoaded(IMG_ELEM) == false){
  113. setTimeout("display()", 500);
  114. return;
  115. }
  116.  
  117. // Fetching areas and loading them into a global object
  118. getAreas();
  119.  
  120. // Adjustment of splashscreen (initial call)
  121. adjustSplashScreen();
  122.  
  123. // Showing the splashscreen
  124. IMG_ELEM.style.display = 'block';
  125. IMG_ELEM.style.visibility = 'visible';
  126.  
  127. areaListenersInit();
  128.  
  129. showLoading(false);
  130. }
  131.  
  132. // onLoad - not all resources may be ready.
  133. var load = function(){
  134. if (document.addEventListener){
  135. document.addEventListener('touchmove', function(e){
  136. e.preventDefault();
  137. }, false);
  138. }
  139. else{
  140. document.attachEvent('ontouchmove', function(e){
  141. e.preventDefault();
  142. });
  143. }
  144.  
  145. // There must be some delay in order for the loading screen to show up.
  146. // TO DO: verify this, why is it needed ? (ulterior testing/tweaking)
  147. setTimeout("display()", 200);
  148. }
  149.  
  150. // simple algorithm to determine if element was loaded
  151. function isImgLoaded(elem)
  152. {
  153. // TO DO: Improve loading detection algorithm (if possible)
  154.  
  155. if(!elem)
  156. {
  157. return false;
  158. }
  159.  
  160. if(!elem.complete) //Some browsers report incorrectly that the image is completed when it is not but always report correctly when it is not loaded
  161. {
  162. return false;
  163. }
  164.  
  165. if (typeof elem.naturalWidth != "undefined" && elem.naturalWidth == 0) // IE does not have naturalWidth
  166. {
  167. return false;
  168. }
  169.  
  170. return true;// no other way of checking.. assume it's ok
  171. }
  172.  
  173. function orientationBasedAdjust()
  174. {
  175. // No adjustment can or needs to be done
  176. return true;
  177. }
  178.  
  179. function getResizeType()
  180. {
  181. viewportDimensions = getViewportDimensions();
  182.  
  183. var currentViewportHeight = viewportDimensions['height'];
  184. var currentViewportWidth = viewportDimensions['width'];
  185.  
  186. if(IMG_HEIGHT / currentViewportHeight > IMG_WIDTH / currentViewportWidth)
  187. {
  188. $resize_type = "height";
  189. }
  190. else
  191. {
  192. $resize_type = "width";
  193. }
  194.  
  195. return $resize_type;
  196. }
  197.  
  198. function adjustSplashScreen()
  199. {
  200. viewportDimensions = getViewportDimensions();
  201.  
  202. var currentViewportHeight = viewportDimensions['height'];
  203. var currentViewportWidth = viewportDimensions['width'];
  204.  
  205. window.scrollTo(0,0);
  206.  
  207. // If loader is present, re-adjust
  208. if(LOADING_ELEM.style.display == 'table')
  209. {
  210. LOADING_ELEM.style.width = currentViewportWidth + 'px';
  211. LOADING_ELEM.style.height = currentViewportHeight + 'px';
  212. }
  213.  
  214. if(WEBVIEW_RECEIVED_OS == 'WP8' || WEBVIEW_RECEIVED_OS == 'windows')
  215. {
  216. document.body.style.backgroundColor = '#000000';
  217. }
  218.  
  219. if(currentViewportHeight != STORED_VIEWPORT_HEIGHT || currentViewportWidth != STORED_VIEWPORT_WIDTH)
  220. {
  221. orientationBasedAdjust();
  222.  
  223. imageRatio = IMG_WIDTH / IMG_HEIGHT;
  224. currentViewRatio = currentViewportWidth / currentViewportHeight;
  225.  
  226. if(currentViewRatio > imageRatio)
  227. {
  228. IMG_RESIZED_WIDTH = IMG_WIDTH * currentViewportHeight / IMG_HEIGHT;
  229. IMG_RESIZED_HEIGHT = currentViewportHeight;
  230. }
  231. else
  232. {
  233. IMG_RESIZED_WIDTH = currentViewportWidth;
  234. IMG_RESIZED_HEIGHT = IMG_HEIGHT * currentViewportWidth / IMG_WIDTH;
  235. }
  236.  
  237. IMG_RESIZED_HEIGHT = Math.ceil(IMG_RESIZED_HEIGHT);
  238. IMG_RESIZED_WIDTH = Math.ceil(IMG_RESIZED_WIDTH);
  239.  
  240. // Resize Type based adjust
  241. /*resizeType = getResizeType();
  242. if(resizeType == "width")
  243. {
  244. IMG_ELEM.style.width = '100%';
  245. IMG_ELEM.style.height = 'auto';
  246. }
  247. else
  248. {
  249. IMG_ELEM.style.width = 'auto';
  250. IMG_ELEM.style.height = '100%';
  251. }*/
  252.  
  253. // Dynamically setting image dimensions
  254. IMG_ELEM.style.width = IMG_RESIZED_WIDTH + 'px';
  255. IMG_ELEM.style.height = IMG_RESIZED_HEIGHT + 'px';
  256.  
  257. // Aligning to center
  258. img_top = Math.round((currentViewportHeight - Math.round(parseInt(IMG_ELEM.style.height))) / 2);
  259. img_left = Math.round((currentViewportWidth - Math.round(parseInt(IMG_ELEM.style.width))) / 2);
  260. //img_top = 0;
  261. //img_left = -20;
  262. //IMG_ELEM.style.top = img_top + 'px';
  263. //IMG_ELEM.style.left = img_left + 'px';
  264. //IMG_ELEM.style.position = "absolute";
  265. //IMG_ELEM.style.marginLeft = '20px';
  266.  
  267. // Storing new dimensions
  268. STORED_VIEWPORT_HEIGHT = currentViewportHeight;
  269. STORED_VIEWPORT_WIDTH = currentViewportWidth;
  270.  
  271. scaleAreas();
  272. //scaleBodyWidthAndHeight();
  273. }
  274.  
  275. setTimeout("adjustSplashScreen()", 100);
  276. }
  277.  
  278. function redir(strlink)
  279. {
  280. if (!isFirstClick) return;
  281.  
  282. if(WEBVIEW_RECEIVED_OS == 'WP8' || WEBVIEW_RECEIVED_OS == 'windows') // Adjusting for WINDOWS (OS = windows)
  283. {
  284. window.external.notify('Initialize redir.');
  285. }
  286.  
  287. showLoading(true);
  288.  
  289. isFirstClick = false;
  290.  
  291. //Auto-closing after 10 seconds, if redirect error.
  292. setTimeout("autoClose('Redirect not completed (request too long).')", '10000');
  293.  
  294. // Check for Internet connection first
  295. // This is required only for external links (not used currently)
  296. if (strlink.indexOf("http") == 0 && 0)
  297. {
  298. // No logic here yet; no need;
  299. }
  300. else {
  301. setTimeout(function(){
  302. goToLink(strlink);
  303. }, 500);
  304. }
  305. }
  306.  
  307. function getByAttribute(tagType, tagAttribute, tagAttributeValue)
  308. {
  309. var elements = [];
  310. var tagList = document.getElementsByTagName(tagType);
  311. tagListLength = tagList.length;
  312. for(var i = 0; i < tagListLength; i++)
  313. {
  314. if(tagList[i].getAttribute(tagAttribute) == tagAttributeValue)
  315. {
  316. elements.push(tagList[i]);
  317. }
  318. }
  319.  
  320. return elements;
  321. }
  322.  
  323. ////////////////////
  324. // Global Variables
  325. ////////////////////
  326.  
  327. var LOADING_ELEM = document.getElementById('loading');
  328. var IMG_AREAS = new Array();
  329. var isFirstClick = true;
  330.  
  331. // Image settings for landscape and/or potrait
  332.  
  333. // Landscape
  334. var IMG_WIDTH_LANDSCAPE = 1520; // set on prerendering
  335. var IMG_HEIGHT_LANDSCAPE = 1008; // set on prerendering
  336. var IMG_ELEM_LANDSCAPE = document.getElementById('splashImage_landscape');
  337. var IMG_ELEM_AREA_LANDSCAPE = document.getElementsByName("splashscreen_landscape_area");
  338. if(IMG_ELEM_AREA_LANDSCAPE.length == 0)
  339. {
  340. IMG_ELEM_AREA_LANDSCAPE = getByAttribute('area', 'name', 'splashscreen_landscape_area');
  341. }
  342. var IMG_ELEM_LANDSCAPE_TAG = 'landscape';
  343.  
  344.  
  345. // Core IMG details - will be adapted on the fly based on detected ratio (if both landscape and portrait are available)
  346. var IMG_HEIGHT = 1008;
  347. var IMG_WIDTH = 1520;
  348. var IMG_ELEM = IMG_ELEM_LANDSCAPE;
  349. var IMG_ELEM_AREA = IMG_ELEM_AREA_LANDSCAPE;
  350. var IMG_ELEM_AREA_TAG = IMG_ELEM_LANDSCAPE_TAG;
  351.  
  352. // Resized width/height holders
  353. var IMG_RESIZED_WIDTH = 0;
  354. var IMG_RESIZED_HEIGHT = 0;
  355.  
  356. // Globals to hold stored viewport dimensions
  357. STORED_VIEWPORT_HEIGHT = 0;
  358. STORED_VIEWPORT_WIDTH = 0;
  359.  
  360. // show loader
  361. adjustLoading(); // forced adjustments in loop to make up for strange behavior
  362. showLoading(true);
  363.  
  364.  
  365. setTimeout(function() {
  366. if (isImgLoaded(IMG_ELEM_LANDSCAPE) == false) {
  367. autoClose('Timeout (resource not ready (landscape)).');
  368. }
  369. }, 10000);
  370.  
  371. if (window.addEventListener) //Webkit
  372. {
  373. window.addEventListener("load", load, false);
  374. }
  375. else //Windows
  376. {
  377. window.attachEvent("onload", load);
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement