Advertisement
gjnt1m

internetconnection - v1

Mar 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var isShowedDialog = false;
  2.  
  3. function showDialog(dialog) {
  4.     isShowedDialog = true;
  5.     var ele = document.getElementById(dialog);
  6.     ele.style.display = '';
  7.     application.onPause();
  8. }
  9.  
  10. function hideDialog(dialog) {
  11.     isShowedDialog = false;
  12.     var ele = document.getElementById(dialog);
  13.     ele.style.display = 'none';
  14. }
  15.  
  16. var InternetConnection = function(){
  17.    
  18.     this.CheckInternetState = null;
  19.     this.connected = true;
  20.    
  21.     this.canConnectInternet = function(){
  22.         return InternetConnection.connected;
  23.     }
  24.        
  25.     this.scheduler = function(){
  26.         if (typeof window.schedulerInterval == 'undefined'){
  27.        
  28.             window.schedulerInterval = setInterval(function(){
  29.                
  30.                 if (InternetConnection.connected){
  31.                     clearInterval(window.schedulerInterval);
  32.                     window.schedulerInterval = undefined;
  33.                 }
  34.                
  35.             }, 200);
  36.         }
  37.     }
  38.    
  39.     this.check = function(){
  40.  
  41.         var img = new Image(1,1);
  42.  
  43.         img.onerror = function () {
  44.            
  45.             InternetConnection.connected        = false;
  46.             //InternetConnection.scheduler();
  47.             showDialog('no_internet_popup');
  48.         };
  49.  
  50.         img.onload = function() {
  51.            
  52.             if (!InternetConnection.connected){
  53.  
  54.                 InternetConnection.connected        = true;
  55.             }
  56.             img = null;
  57.         };
  58.  
  59.         //img.src = _protocol + _domain_name + '/un/web/fullscreen/images/pixel.gif?time=' + new Date().getTime();
  60.         if (typeof resource !== 'undefined')
  61.             img.src = resource.get_src("assets/pixel.gif") + "?time=" + new Date().getTime();
  62.         else
  63.             img.src = "http://201205igp.gameloft.com//un/web/fullscreen/images/pixel.gif?time=" + new Date().getTime();
  64.     }
  65. }
  66.  
  67. var InternetConnection = new InternetConnection();
  68.  
  69. function checkConnection() {
  70.     if (!isShowedDialog)
  71.         InternetConnection.check();
  72. }
  73.  
  74. function no_internet_popup_close()
  75. {
  76.     mraid.close();
  77. }
  78.  
  79. function no_internet_popup_resume()
  80. {
  81.     hideDialog('no_internet_popup');
  82.     application.onResume();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement