From a858456d38b88756a2d3eaadc148189c92a2169d Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 10 Dec 2016 22:01:05 +0800 Subject: [PATCH] add some application information for javascript --- app/Providers/AppServiceProvider.php | 12 ++++++++++++ resources/assets/src/js/general.js | 11 +++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3b7e711d..8d5f02a4 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,7 +3,10 @@ namespace App\Providers; use View; +use Event; use Validator; +use App\Events; +use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -24,6 +27,15 @@ class AppServiceProvider extends ServiceProvider $this->app['request']->headers->set('host', $host[1]); }; } + + Event::listen(Events\RenderingHeader::class, function($event) { + // provide some application information for javascript + $blessing = array_merge(Arr::except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [ + 'baseUrl' => url('/'), + ]); + + $event->addContent(''); + }); } /** diff --git a/resources/assets/src/js/general.js b/resources/assets/src/js/general.js index f40cd6ab..d5ef63e1 100644 --- a/resources/assets/src/js/general.js +++ b/resources/assets/src/js/general.js @@ -2,14 +2,11 @@ * @Author: printempw * @Date: 2016-09-15 10:39:41 * @Last Modified by: printempw -* @Last Modified time: 2016-10-23 11:04:11 +* @Last Modified time: 2016-12-10 21:57:23 */ 'use strict'; -// guesss base url -var base_url = (location.pathname.endsWith('user') || location.pathname.endsWith('admin')) ? "." : ".."; - function logout(with_out_confirm, callback) { if (!with_out_confirm) { swal({ @@ -24,7 +21,9 @@ function logout(with_out_confirm, callback) { type: 'success', html: json.msg }); - window.setTimeout('window.location = "'+base_url+'/"', 1000); + window.setTimeout(function() { + window.location = blessing.baseUrl; + }, 1000); }); }); } else { @@ -37,7 +36,7 @@ function logout(with_out_confirm, callback) { function do_logout(callback) { $.ajax({ type: "POST", - url: base_url + "/auth/logout", + url: blessing.baseUrl + "/auth/logout", dataType: "json", success: function(json) { if (callback) callback(json);