From 120df57edf91352fd3eb512da4d4472e49e76bc8 Mon Sep 17 00:00:00 2001 From: printempw Date: Wed, 18 Jan 2017 21:49:23 +0800 Subject: [PATCH] add JavaScript helper function url() --- resources/assets/src/js/general.js | 6 +++--- resources/assets/src/js/utils.js | 31 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/resources/assets/src/js/general.js b/resources/assets/src/js/general.js index 674fbb5c..bd30d654 100644 --- a/resources/assets/src/js/general.js +++ b/resources/assets/src/js/general.js @@ -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); diff --git a/resources/assets/src/js/utils.js b/resources/assets/src/js/utils.js index 1eeaec0c..1b579cc6 100644 --- a/resources/assets/src/js/utils.js +++ b/resources/assets/src/js/utils.js @@ -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; }