Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isMobile(){
- return /android|ip(hone|ad|od)/i.test(navigator.userAgent);
- }
- function _(key, params) {
- var language = SETTINGS['language'];
- if(!(language in SSO_SERVER_I18N) || !(key in SSO_SERVER_I18N[language])) {
- return key;
- }
- var text = SSO_SERVER_I18N[language][key];
- if(params != null) {
- for(key in params) {
- text = text.replace('%(' + key + ')', params[key].toString());
- }
- }
- return text;
- }
- function getLocale(language, country) {
- if (language=='zh-TW') {
- return language
- } else {
- return language + '-' + country
- }
- }
- function getCurrentBaseUrl() {
- var url = window.location.href;
- var sep = url.indexOf('#');
- if(sep >= 0) {
- url = url.substring(0, sep);
- }
- sep = url.indexOf('?');
- if(sep >= 0) {
- url = url.substring(0, sep);
- }
- return url;
- }
- function getRequestParams() {
- var e = window.location.search.replace(/^\?/, "").split("&"), n = 0, r, i = {}, s, o, u;
- while(( r = e[n++]) !== undefined) s = r.match(/^([^=&]*)=(.*)$/), s && ( o = decodeURIComponent(s[1]), u = decodeURIComponent(s[2]), i[o] = u);
- return i;
- }
- function getRequestParam(key) {
- var params = getRequestParams();
- if(key in params) {
- return params[key];
- }
- return null;
- }
- function getRequestFragments() {
- var e = window.location.hash.replace(/^#/, "").split("&"), n = 0, r, i = {}, s, o, u;
- while(( r = e[n++]) !== undefined) s = r.match(/^([^=&]*)=(.*)$/), s && ( o = decodeURIComponent(s[1]), u = decodeURIComponent(s[2]), i[o] = u);
- return i;
- }
- function getRequestFragment(key) {
- var params = getRequestFragments();
- if(key in params) {
- return params[key];
- }
- return null;
- }
- function redirect(uri, params) {
- if(params != null) {
- var sParams = '';
- for(var key in params) {
- sParams += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
- }
- if(sParams.length > 0) {
- if(uri.indexOf('?') < 0) {
- sParams = '?' + sParams.substr(1);
- }
- uri += sParams;
- }
- }
- window.location = uri;
- }
- function setCookie(name, value, expiredSeconds, domain) {
- var sValue = escape(value);
- if(expiredSeconds != null) {
- var expires = new Date(new Date().getTime() + expiredSeconds);
- sValue += "; expires=" + expires.toUTCString();
- }
- if(domain != null) {
- sValue += "; domain=" + domain;
- }
- document.cookie = name + "=" + sValue;
- }
- function removeCookie(name, domain) {
- document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; domain=' + domain + '; path=/;';
- }
- function appendClearDiv(container) {
- container.append($('<div/>', {'class' : 'clear'}));
- }
- function clearMessage(parent) {
- $(parent + ' #msg').remove();
- $(parent+' input.error').removeClass('error');
- }
- function showMessage(msg, type, parent, clear_others, mode) {
- mode = (typeof mode === "undefined") ? "text" : mode;
- if(clear_others){
- $('span[id="msg"]').remove();
- } else {
- parent.find('span.errorMsg,span.successMsg').remove();
- }
- var panel = $('<span/>', {'id': 'msg', 'class': type + 'Msg'});
- if(mode=='html'){
- panel.html('<em></em>'+msg);
- } else {
- panel.text(msg);
- panel.prepend($('<em/>'));
- }
- parent.append(panel);
- }
- function showMobileRegisterAlert(msg) {
- var wrapper = $('<div/>').addClass('alertWrapper');
- var container = $('<div/>').addClass('alertContainer').appendTo(wrapper);
- var alert = $('<div/>').addClass('alert').appendTo(container);
- $('<span/>').addClass('icon-alert').appendTo(alert);
- $('<p/>').text(msg).appendTo(alert);
- $('<p/>').text(_('register_redirect_on_error')).appendTo(alert);
- var btnOK = $('<a/>', {'href': 'javascript:;', 'class': 'btn-ok'}).text(_('btn_ok')).appendTo(container);
- wrapper.appendTo($('body'));
- btnOK.click(function(){
- showRegisterPage('mobile');
- wrapper.remove();
- })
- }
- function showSuccess(msg, after, clear_others, mode) {
- showMessage(msg, 'success', after, clear_others, mode);
- }
- function showError(msg, after, clear_others, mode) {
- if(after===undefined){after=$('#line-btn');}
- after.find('span.icon-right').remove();
- clear_others = (typeof clear_others === "undefined") ? true : clear_others;
- if (clear_others) {
- $('input.error').removeClass('error');
- }
- showMessage(msg, 'error', after, clear_others, mode);
- after.find('input').addClass('error');
- }
- function requestJsonp(url, params, callback) {
- params['format'] = 'jsonp';
- params['callback'] = callback;
- params['id']= new Date().getTime();
- params['app_id'] = SETTINGS['app_id'];
- var first = true;
- for(var key in params) {
- var value = params[key];
- if(first) {
- url += '?';
- first = false;
- } else {
- url += '&';
- }
- url += encodeURIComponent(key);
- url += '=';
- url += encodeURIComponent(value);
- }
- var scriptTag = $('<script/>', {'type': 'text/javascript'}).appendTo($('body'));
- scriptTag.attr('src', url);
- }
- function requestJson(url, params, callback, method) {
- method = (typeof method === "undefined") ? "GET" : method;
- params['format'] = 'json';
- params['id']= new Date().getTime();
- params['app_id'] = SETTINGS['app_id'];
- $.ajax({
- type : method,
- url : url,
- data : params,
- dataType : 'json',
- success : callback,
- error : function() {
- callback({'error': 'error_server'});
- }
- });
- }
- function checkPasswordValid(username, password) {
- if(password.length < 8 || password.length > 16) {
- return false;
- }
- if(password === username) {
- return false;
- }
- var has_small_letter = false;
- var has_capital_letter = false;
- var has_number = false;
- var has_symbol = false;
- for(var i=0; i < password.length; i++) {
- var code = password.charCodeAt(i);
- var ch = password.charAt(i);
- if(code > 126 || code < 33) {
- return false;
- }
- if(ch >= 'a' && ch <= 'z') {
- has_small_letter = true;
- } else if(ch >= 'A' && ch <= 'Z') {
- has_capital_letter = true;
- } else if(ch >= '0' && ch <= '9') {
- has_number = true;
- } else {
- has_symbol = true;
- }
- }
- var pass_strength = 0;
- if(has_small_letter) {
- pass_strength++;
- }
- if(has_capital_letter) {
- pass_strength++;
- }
- if(has_number) {
- pass_strength++;
- }
- if(has_symbol) {
- pass_strength++;
- }
- return pass_strength >= 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement