Clean up repeating code and add redirect() function

This commit is contained in:
Kijin Sung 2016-03-07 08:34:06 +09:00
parent 006474cb98
commit 9b5a17fb59
3 changed files with 29 additions and 58 deletions

View file

@ -377,6 +377,21 @@ function sendMailTo(to) {
location.href="mailto:"+to; location.href="mailto:"+to;
} }
/**
* @brief url이동 (Rhymix 개선된 버전)
*/
function redirect(url) {
if (url === window.location.href || url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0)
{
window.location.href = url;
window.location.reload();
}
else
{
window.location.href = url;
}
}
/** /**
* @brief url이동 (open_window 값이 N 아니면 새창으로 띄움) * @brief url이동 (open_window 값이 N 아니면 새창으로 띄움)
**/ **/
@ -394,7 +409,7 @@ function move_url(url, open_window) {
if(open_window) { if(open_window) {
winopen(url); winopen(url);
} else { } else {
location.href=url; redirect(url);
} }
return false; return false;

View file

@ -106,16 +106,7 @@
data.redirect_url = data.redirect_url.replace(/&/g, "&"); data.redirect_url = data.redirect_url.replace(/&/g, "&");
} }
if (data.redirect_url && !$.isFunction(callback_success)) { if (data.redirect_url && !$.isFunction(callback_success)) {
if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) return redirect(data.redirect_url);
{
window.location = data.redirect_url;
window.location.reload();
}
else
{
window.location = data.redirect_url;
}
return;
} }
// If there was a success callback, call it. // If there was a success callback, call it.
@ -236,16 +227,7 @@
data.redirect_url = data.redirect_url.replace(/&/g, "&"); data.redirect_url = data.redirect_url.replace(/&/g, "&");
} }
if (data.redirect_url && !$.isFunction(callback_success)) { if (data.redirect_url && !$.isFunction(callback_success)) {
if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) return redirect(data.redirect_url);
{
window.location = data.redirect_url;
window.location.reload();
}
else
{
window.location = data.redirect_url;
}
return;
} }
// If there was a success callback, call it. // If there was a success callback, call it.

View file

@ -14,7 +14,7 @@ function completeDocumentInserted(ret_obj)
var category_srl = ret_obj.category_srl; var category_srl = ret_obj.category_srl;
if (ret_obj.redirect_url) { if (ret_obj.redirect_url) {
location.href = ret_obj.redirect_url; redirect(ret_obj.redirect_url);
} else { } else {
var url; var url;
if(!document_srl) if(!document_srl)
@ -26,7 +26,7 @@ function completeDocumentInserted(ret_obj)
url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
} }
if(category_srl) url = url.setQuery('category',category_srl); if(category_srl) url = url.setQuery('category',category_srl);
location.href = url; redirect(url);
} }
} }
@ -40,7 +40,7 @@ function completeDeleteDocument(ret_obj)
var url = current_url.setQuery('mid',mid).setQuery('act','').setQuery('document_srl',''); var url = current_url.setQuery('mid',mid).setQuery('act','').setQuery('document_srl','');
if(page) url = url.setQuery('page',page); if(page) url = url.setQuery('page',page);
location.href = url; redirect(url);
} }
/* document search */ /* document search */
@ -53,8 +53,7 @@ function completeVote(ret_obj)
{ {
var error = ret_obj.error; var error = ret_obj.error;
var message = ret_obj.message; var message = ret_obj.message;
alert(message); redirect(window.location.href);
location.href = location.href;
} }
// current page reload // current page reload
@ -62,8 +61,7 @@ function completeReload(ret_obj)
{ {
var error = ret_obj.error; var error = ret_obj.error;
var message = ret_obj.message; var message = ret_obj.message;
redirect(window.location.href);
location.href = location.href;
} }
/* complete to insert comment*/ /* complete to insert comment*/
@ -75,19 +73,11 @@ function completeInsertComment(ret_obj)
var document_srl = ret_obj.document_srl; var document_srl = ret_obj.document_srl;
var comment_srl = ret_obj.comment_srl; var comment_srl = ret_obj.comment_srl;
if (ret_obj.redirect_url) { if (ret_obj.redirect_url) {
if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) redirect(ret_obj.redirect_url);
{
window.location = ret_obj.redirect_url;
window.location.reload();
}
else
{
window.location = ret_obj.redirect_url;
}
} else { } else {
var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
if (comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl; if (comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl;
window.location.href = url; redirect(url);
} }
} }
@ -101,19 +91,11 @@ function completeDeleteComment(ret_obj)
var page = ret_obj.page; var page = ret_obj.page;
if (ret_obj.redirect_url) { if (ret_obj.redirect_url) {
if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) redirect(ret_obj.redirect_url);
{
window.location = ret_obj.redirect_url;
window.location.reload();
}
else
{
window.location = ret_obj.redirect_url;
}
} else { } else {
var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
if (page) url = url.setQuery('page',page); if (page) url = url.setQuery('page',page);
window.location.href = url; redirect(url);
} }
} }
@ -127,19 +109,11 @@ function completeDeleteTrackback(ret_obj)
var page = ret_obj.page; var page = ret_obj.page;
if (ret_obj.redirect_url) { if (ret_obj.redirect_url) {
if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) redirect(ret_obj.redirect_url);
{
window.location = ret_obj.redirect_url;
window.location.reload();
}
else
{
window.location = ret_obj.redirect_url;
}
} else { } else {
var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
if (page) url = url.setQuery('page',page); if (page) url = url.setQuery('page',page);
window.location.href = url; redirect(url);
} }
} }