-
-
Save wate/01280e48fc5dab4a91167739fa9d0f95 to your computer and use it in GitHub Desktop.
Redmineのログイン後のリダイレクト処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* パスのパターン: /$ | |
* 挿入位置:全てのページのヘッダ | |
* 種別:JavaScript | |
*/ | |
(function(){ | |
// リダイレクト先一覧 | |
var redirects = { | |
mypage: {href: '/my/page', name: 'マイページ'}, | |
projects: {href: '/projects', name: 'プロジェクト一覧'}, | |
issues: {href: '/issues', name: 'チケット一覧(全プロジェクト)'} | |
}; | |
//リダイレクトするか否か | |
var is_redirect = false; | |
//リダイレクト先 | |
var redirect_to = localStorage.getItem('redirect_to'); | |
if(document.referrer){ | |
var parser = new URL(document.referrer); | |
if(location.origin == parser.origin && parser.pathname === '/login'){ | |
is_redirect = true; | |
} | |
} else { | |
is_redirect = true; | |
} | |
if(redirect_to && is_redirect && redirects[redirect_to]){ | |
location.href = redirects[redirect_to].href; | |
} else { | |
$(function(){ | |
$('.splitcontentleft').prepend('<div id="login_redirect"></div>'); | |
var login_redirect = $('#login_redirect'); | |
if(redirect_to){ | |
var clear_btn = $('<button>リダイレクト先情報をクリアする</button>').on('click', function(){ | |
localStorage.removeItem('redirect_to'); | |
alert("リダイレクト先情報をクリアしました"); | |
}); | |
$(login_redirect).prepend(clear_btn); | |
} else { | |
$.each(redirects, function(key, value) { | |
$(login_redirect).append('<label><input type="radio" name="redirect_to" value="' + key + '">' + value.name + '</label>'); | |
}); | |
$(login_redirect).append($('<button type="button" id="save_redirect">保存する</button>')); | |
$('#save_redirect').on('click', function(){ | |
localStorage.setItem('redirect_to', $('input[name=redirect_to]:checked').val()); | |
alert("ログイン後のリダイレクト先を保存しました\n※次回以降のログインより適用されます。"); | |
}); | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment