From 08e955335ecb65c308dbc68bf0610dce39ce3623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Pu=C5=A1nik?= Date: Tue, 20 Oct 2015 17:39:04 +0200 Subject: - icons - any state marker from the URL before everything else loads removed - settings dropdown separator visibility in case of saml login fixed - profile screen: - go back button refactored - name, email field - phone, browser and platform type detection (misc.js) added - mobile apps: - meta viewport and add HandheldFriendly changed - style @-ms-viewport defined - ajaxPrefix and eioHost temporary changed to dev server - android: phonegap whitelistening in config.xml fixed - ios: add hide status bar to config.xml TODO: - WP8 mobile app: test - iOS mobile app: saml login solution (iframe cross domain url not allowed) - "No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin." --- js/codeq/core.js | 4 +++ js/codeq/init.js | 8 ++++-- js/codeq/login.js | 24 +++++++++--------- js/codeq/misc.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ js/codeq/profile.js | 16 +++++++----- 5 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 js/codeq/misc.js (limited to 'js/codeq') diff --git a/js/codeq/core.js b/js/codeq/core.js index a3e9589..309195b 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -391,6 +391,10 @@ 'line-layout', 'square-layout' ], + + 'runningOnPhone': false, // default value, will be changed if detected otherwise + 'browserType': 'unknown', + 'platformType': 'unknown', 'isWebApp': false, // this is a PhoneGap/Cordova build, will be overridden in cordova.js for webapp 'setLayout': function(newLayout){ diff --git a/js/codeq/init.js b/js/codeq/init.js index 811d781..98a41a2 100644 --- a/js/codeq/init.js +++ b/js/codeq/init.js @@ -94,8 +94,12 @@ else { // we are a phonegap native app document.addEventListener("deviceready", Boot, false); - codeq.ajaxPrefix = 'http://codeq.si/'; - codeq.eioHost= 'wss://codeq.si'; + // production + //codeq.ajaxPrefix = 'http://codeq.si/'; + //codeq.eioHost= 'ws://codeq.si'; + // dev + codeq.ajaxPrefix = 'http://212.235.189.51:22180/'; + codeq.eioHost= 'ws://212.235.189.51:22180'; } })(); diff --git a/js/codeq/login.js b/js/codeq/login.js index 61f248d..db90b43 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -7,19 +7,21 @@ jqNavigationHomeBtn = $('#navigation-home'), jqAAILoginBtn = $('#aai_login_button'), jqSignupBtn = $('#signup_button'), - jqSubmitLoginBtn = $("#submit"); + jqSubmitLoginBtn = $("#submit"), + jqDisabled = $('#disabled'); //the loginCallbackFunction is used here and in the AAI login as well codeq.loginCallbackFunction = function (data) { - $('#disabled').css('display', 'none'); - $('#disabled').css('cursor', ''); + jqDisabled.css('display', 'none'); + jqDisabled.css('cursor', ''); if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message); //nav signed in... - $('#signed-in-title').html(data.name||$('#username').val()); + $('#signed-in-title').html(data.name||data.username||data.email||'undefined'); //merge with profile page - $('#profileUsername').html($('#username').val()); + $('#profileUsername').html(data.username||data.email||'undefined'); $('#profileName').html(data.name||'undefined'); + $('#profileEmail').html(data.email||'undefined'); $('#profileJoined').html(new Date(data.joined).toLocaleString()); $('#profileLastLogin').html(new Date(data["last-login"]).toLocaleString()); @@ -42,19 +44,19 @@ var loginFun = function(){ $('.saml-login-hide').css('display','');//if we login the normal way we want to show the change password buttons. if we enter the saml login they will be hidden - $('#disabled').css('display', ''); - $('#disabled').css('cursor', 'wait'); + jqDisabled.css('display', ''); + jqDisabled.css('cursor', 'wait'); codeq.comms.connect() .then(function () { return codeq.comms.login($('#username').val(), $('#password').val()); }) .then(codeq.loginCallbackFunction) .fail(function (reason) { - $('#disabled').css('display', 'none'); - $('#disabled').css('cursor', ''); + jqDisabled.css('display', 'none'); + jqDisabled.css('cursor', ''); codeq.log.error('Login failed: ' + reason, reason); alert('Login request failed: ' + reason); - $('#disabled').css('display', 'none'); + jqDisabled.css('display', 'none'); }) .done(); }, @@ -85,7 +87,7 @@ }); //$('#modalLogIn').modal(); $("#screen_login").css('display', ''); - $('#disabled').css('display', 'none'); + jqDisabled.css('display', 'none'); }, 'exit' : function(){ //remove the listener from the buttons specific to this page diff --git a/js/codeq/misc.js b/js/codeq/misc.js new file mode 100644 index 0000000..b83f271 --- /dev/null +++ b/js/codeq/misc.js @@ -0,0 +1,71 @@ +/* Detect if we're on a phone, browser and platform type */ +(function browserDetection() { + var platform = navigator.platform, + userAgent = navigator.userAgent, + runningOnPhone = false, // default value, will be changed if detected otherwise + browserType = 'unknown', + platformType = 'unknown'; + + // Apple platforms + if ((/iPod/.test(platform)) || (/iPhone/.test(platform))) { + runningOnPhone = true; + browserType = 'safari'; + platformType = 'iapple'; + } + else if (/iPad/.test(platform)) { + runningOnPhone = false; + browserType = 'safari'; + platformType = 'iapple'; + } + else { + // general test for phones + if (/[Mm]obile/.test(userAgent)) { + runningOnPhone = true; + } + + if ((/MSIE/.test(userAgent) && /Touch/.test(userAgent)) || (/IEMobile/.test(userAgent))) { + platformType = 'ietouch'; + } + + if (/BlackBerry/.test(userAgent) || /BB10/.test(userAgent)) { + platformType = 'blackberry'; + } + + // general browser tests + if (/Presto/.test(userAgent)) { + browserType = 'opera'; + } + else if (/Android/.test(userAgent)) { + // Android platform: only firefox, webkit, and chrome are possible + platformType = 'android'; + if (/Chrome/.test(userAgent)) { + browserType = 'chrome'; + } + else if (/Firefox/.test(userAgent)) { + browserType = 'firefox'; + } + else if (/Safari/.test(userAgent)) { + browserType = 'webkit'; + } + } + else { + // desktop, or other mobile platforms + if (/Chrome/.test(userAgent)) { + browserType = 'chrome'; + } + else if (/Firefox/.test(userAgent)) { + browserType = 'firefox'; + } + else if (/Safari/.test(userAgent)) { + browserType = 'webkit'; + } + else if (/MSIE/.test(userAgent)) { + browserType = 'ie'; + } + } + } + + codeq.runningOnPhone = runningOnPhone; + codeq.browserType = browserType; + codeq.platformType = platformType; +})(); \ No newline at end of file diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 133c947..36c5ccf 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -4,13 +4,20 @@ (function(){ - var jqBtnChangePass = $("#change_pass_profile"); + var jqBtnChangePass = $("#change_pass_profile"), + jqBtnGoBack = $("#btnProfileGoBack"); codeq.profile = { }; codeq.globalStateMachine.register('profile',{ 'enter': function(){ + jqBtnChangePass.on('click',function(){ + codeq.globalStateMachine.transition('changePassword'); + }); + jqBtnGoBack.on('click',function(){ + history.back();//forces a transition to the previous state + }); $("#screen_profile").css('display', ''); $('#disabled').css('display', 'none'); codeq.comms.getUserStat() @@ -19,7 +26,6 @@ data = data.stat; var columns = ['language', 'problem_group', 'problems_count', 'done', 'in_progress'], - labels = ['Language', 'Problem group', 'All', 'Done', 'In progress'], items='', tr_gui = codeq.tr.getDictionary('gui'); @@ -53,13 +59,11 @@ alert('GetUserStat failed: ' + reason); }) .done(); - jqBtnChangePass.on('click',function(){ - codeq.globalStateMachine.transition('changePassword'); - }); }, 'exit' : function(){ - $("#screen_profile").css('display', 'none'); jqBtnChangePass.off('click'); + jqBtnGoBack.off('click'); + $("#screen_profile").css('display', 'none'); } }); })(); \ No newline at end of file -- cgit v1.2.1