Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (whl, $) {
  2.  
  3.  
  4.     whl.readCookie = function (name) {
  5.         var nameEQ = name + "=";
  6.         var ca = document.cookie.split(';');
  7.         for (var i = 0; i < ca.length; i++) {
  8.             var c = ca[i];
  9.             c = c.trim();
  10.             if (c.indexOf(nameEQ) === 0)
  11.                 return c.substring(nameEQ.length, c.length);
  12.         }
  13.         return null;
  14.     };
  15.  
  16.     // STATUS
  17.     whl.status = function (callback) {
  18.         this.status_callback = callback;
  19.  
  20.         var userId = this.readCookie('userID');
  21.         if (!!userId) {
  22.             var that = this;
  23.             $.ajax({
  24.                 type: 'POST',
  25.                 url: 'WebsiteService?',
  26.                 dataType: "json",
  27.                 contentType: "application/json; charset=utf-8",
  28.                 //crossDomain: true,
  29.                 //dataType: "jsonp",
  30.                 //jsonp: false,
  31.                 //jsonpCallback: 'jsoncb',
  32.                 data:  JSON.stringify({
  33.                     "req": "isSessionActive",
  34.                     "userID": userId
  35.                 }),
  36.                 success: function (data) {
  37.                     that.statusCallback(data);
  38.                 },
  39.                 failure: function (err) {
  40.                     console.log('failure refresh', err);
  41.                 }
  42.             });
  43.         }
  44.     };
  45.  
  46.     whl.statusCallback = function (data) {
  47.         if (this.status_callback) {
  48.             var result = {};
  49.             result.uid = 'uid';
  50.             result.token = 'token';
  51.             result.status = data.StatusCode === 10 ? 'real' : 'anon';
  52.  
  53.             this.status_callback(result);
  54.         }
  55.     };
  56.  
  57.     // REFRESH
  58.     whl.refreshSession = function (callback) {
  59.         this.refresh_callback = callback;
  60.  
  61.         var userId = this.readCookie('userID');
  62.         if (!!userId) {
  63.             var that = this;
  64.             $.ajax({
  65.                 type: 'POST',
  66.                 url: 'WebsiteService?',
  67.                 dataType: "json",
  68.                 contentType: "application/json; charset=utf-8",
  69.                 //crossDomain: true,
  70.                 //dataType: "jsonp",
  71.                 //jsonp: false,
  72.                 //jsonpCallback: 'jsoncb',
  73.                 data:  JSON.stringify({
  74.                     "req": "isSessionActive",
  75.                     "userID": userId
  76.                 }),
  77.                 success: function (data) {
  78.                     console.log('success refresh', data);
  79.                     that.refreshToken(data);
  80.                 },
  81.                 failure: function (err) {
  82.                     console.log('failure refresh', err);
  83.                 }
  84.             });
  85.         }
  86.     };
  87.  
  88.     whl.refreshCallback = function (data) {
  89.         if (this.refresh_callback) {
  90.             var result = {};
  91.             if (!!data && data.StatusCode === 10) {
  92.                 result.status = "success";
  93.             } else {
  94.                 result.status = "failure";
  95.             }
  96.             this.refresh_callback(result);
  97.         }
  98.     };
  99.  
  100.     whl.setDeviceTypeAndOrientation = function (deviceDetails) {
  101.         console.log("device details", deviceDetails);
  102.     };
  103.  
  104.     whl.ChangeDeviceTypeandOrientation = function (deviceDetails) {
  105.         console.log("change device details", deviceDetails);
  106.     };
  107. })(window.whl = window.whl || {}, jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement