var jwt = ''; var cskey = ''; var city_id = ''; var JWT_LOCALSTORAGE_KEY = 'HKECL_JWT'; var HKECTopbarToken = null; var _this = this; var http_type = "http://"; if (self.location.href.match(/^https\:\/\//)) { http_type = "https://"; } var static_server_host = http_type + "static2.hkedcity.net"; var sc_host = encodeURIComponent(http_type + "b5togb.hkedcity.net/gate/gb/videoplayer.hkedcity.net"); var tc_host = encodeURIComponent(http_type + "videoplayer.hkedcity.net"); var request_uri = "%2Fjs%2Fjwt.js.php%3Fispopup%3D1"; var login_url = http_type + 'videoplayer.hkedcity.net/'; var locale = 0; var curr_host = ''; // host of current page if (window.location.hostname == 'b5togb.hkedcity.net') { curr_host = sc_host; locale = 1; } else { curr_host = tc_host; locale = 0; } if(homeURL === undefined){ var homeURL = curr_host + request_uri; // url of current page } var getAuthenticationCode = function(callback) { if (callback == null || typeof callback !== 'function') { callback = authentication_code_callback; } $.ajax({ dataType: 'json', url: '/hkectopbar/prepare_common_session.php', xhrFields: { withCredentials: true } }).success(callback); }; $.ajaxSetup({ 'beforeSend': function (xhr) { if (_this.jwt !== null) { xhr.setRequestHeader('Authorization', 'Bearer ' + _this.jwt); } } }); var authentication_code_callback = function(json) { console.log(json); homeURL = encodeURIComponent(self.location.href); _this.cskey = (json.result == null) ? '' : json.result; if (_this.cskey != '') { // Can find cskey if (_this.jwt == undefined) { $.post('//videoplayer.hkedcity.net/index.php?caslogin', {'payload': _this.cskey, 'type': 'key'}, function(data) { city_id = data["city_id"]; token = data["token"]; console.log(data); if (token == '') { //DEBUG } else { _this.jwt = token; window.localStorage.setItem(JWT_LOCALSTORAGE_KEY, jwt); // Save JWT //DEBUG } var topbar_url = "/hkectopbar/topbar.js.php?homeURL=" + homeURL + "&apps_city_id=" + city_id + "&lang=0&locale=0&ispopup=1&version=new&global_css_loaded=0"; console.log(1); console.log(topbar_url); loadJS(topbar_url, yourCodeToBeCalled, document.body); //$.getScript(topbar_url, function(data, textStatus, jqxhr) {}); },"json"); } else { // Old JWT is found $.post('//videoplayer.hkedcity.net/index.php?caslogin', {'payload': _this.cskey, 'type': 'key'}, function(data) { city_id = data["city_id"]; token = data["token"]; console.log(data); if (jwt == '') { //DEBUG } else if(jwt.indexOf("") >=0) { } else { _this.jwt = jwt; window.localStorage.setItem(JWT_LOCALSTORAGE_KEY, jwt); // Save JWT //DEBUG } var topbar_url = "/hkectopbar/topbar.js.php?homeURL=" + homeURL + "&apps_city_id=" + city_id + "&lang=0&locale=0&ispopup=1&version=new&global_css_loaded=0"; console.log(2); console.log(topbar_url); loadJS(topbar_url, yourCodeToBeCalled, document.body); //$.getScript(topbar_url, function(data, textStatus, jqxhr) {}); },"json"); } } else { // Cannot find cskey //_this.init(); if(_this.jwt == null) _this.jwt = ''; var topbar_url = "/hkectopbar/topbar.js.php?homeURL=" + homeURL + "&apps_city_id=" + '' + "&lang=0&locale=0&ispopup=1&version=new&global_css_loaded=0"; console.log(topbar_url); loadJS(topbar_url, yourCodeToBeCalled, document.body); //$.getScript(topbar_url, function(data, textStatus, jqxhr) {}); } }; var loadJS = function(url, implementationCode, location){ console.log(implementationCode); console.log(location); //url is URL of external file, implementationCode is the code //to be called from the file, location is the location to //insert the