add JavaScript helper function url()

This commit is contained in:
printempw 2017-01-18 21:49:23 +08:00
parent 4cfb3f27f6
commit 120df57edf
2 changed files with 24 additions and 13 deletions

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-09-15 10:39:41
* @Last Modified by: printempw
* @Last Modified time: 2017-01-14 22:36:55
* @Last Modified time: 2017-01-18 21:35:01
*/
'use strict';
@ -22,7 +22,7 @@ function logout(with_out_confirm, callback) {
html: json.msg
});
window.setTimeout(function() {
window.location = blessing.base_url;
window.location = url();
}, 1000);
});
});
@ -36,7 +36,7 @@ function logout(with_out_confirm, callback) {
function do_logout(callback) {
$.ajax({
type: "POST",
url: blessing.base_url + "/auth/logout",
url: url('auth/logout'),
dataType: "json",
success: function(json) {
if (callback) callback(json);

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-16 09:02:32
* @Last Modified by: printempw
* @Last Modified time: 2017-01-17 22:51:55
* @Last Modified time: 2017-01-18 21:36:24
*/
$.locales = {};
@ -153,13 +153,24 @@ function getQueryString(key) {
// quick fix for compatibility of String.prototype.endsWith
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.lastIndexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.lastIndexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
function url(relativeUri) {
relativeUri = relativeUri || "";
blessing.base_url = blessing.base_url || "";
if (relativeUri[0] != "/") {
relativeUri = "/" + relativeUri;
}
return blessing.base_url + relativeUri;
}