mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
Clean up and reorganize functions in xml_handler.js
This commit is contained in:
parent
c291309fad
commit
f7b9769428
2 changed files with 347 additions and 275 deletions
|
|
@ -4,7 +4,7 @@
|
|||
* Copyright 2001-2005 Michael Foster (Cross-Browser.com)
|
||||
**/
|
||||
function xDeprecate(funcName) {
|
||||
var msg = 'DEPRECATED : '+funcName+'() is deprecated function.';
|
||||
var msg = 'DEPRECATED : '+funcName+'() is deprecated in Rhymix.';
|
||||
if (typeof console == 'object' && typeof console.log == 'function') {
|
||||
console.log(msg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,351 @@
|
|||
/**
|
||||
* @file common/js/xml_handler.js
|
||||
* @brief XE에서 ajax기능을 이용함에 있어 module, act를 잘 사용하기 위한 자바스크립트
|
||||
**/
|
||||
* Functions for sending AJAX requests to the server.
|
||||
*/
|
||||
(function($){
|
||||
|
||||
// xml handler을 이용하는 user function
|
||||
var show_waiting_message = true;
|
||||
/**
|
||||
* Set this variable to false to hide the "waiting for server response" layer.
|
||||
*/
|
||||
window.show_waiting_message = true;
|
||||
var waiting_obj;
|
||||
|
||||
/**
|
||||
* Function for compatibility with XE's exec_xml()
|
||||
*/
|
||||
window.exec_xml = $.exec_xml = function(module, act, params, callback_success, return_fields, callback_success_arg, fo_obj) {
|
||||
|
||||
// Convert params to object and fill in the module and act.
|
||||
params = params ? ($.isArray(params) ? arr2obj(params) : params) : {};
|
||||
params.module = module;
|
||||
params.act = act;
|
||||
|
||||
// Fill in the XE vid.
|
||||
if (typeof(xeVid) != "undefined") params.vid = xeVid;
|
||||
|
||||
// Add 'error' and 'message' to response tags.
|
||||
if (typeof(return_fields) == "undefined" || return_fields.length < 1) {
|
||||
return_fields = ["error", "message"];
|
||||
} else {
|
||||
return_fields.push("error", "message");
|
||||
}
|
||||
|
||||
// Decide whether or not to use SSL.
|
||||
var url = request_uri;
|
||||
if ($.isArray(ssl_actions) && params.act && $.inArray(params.act, ssl_actions) >= 0) {
|
||||
url = default_url || request_uri;
|
||||
var port = window.https_port || 443;
|
||||
var _ul = $("<a>").attr("href", url)[0];
|
||||
var target = "https://" + _ul.hostname.replace(/:\d+$/, "");
|
||||
if (port != 443) target += ":" + port;
|
||||
if (_ul.pathname[0] != "/") target += "/";
|
||||
target += _ul.pathname;
|
||||
url = target.replace(/\/$/, "") + "/";
|
||||
}
|
||||
|
||||
// Check whether this is a cross-domain request. If so, use an alternative method.
|
||||
var _u1 = $("<a>").attr("href", location.href)[0];
|
||||
var _u2 = $("<a>").attr("href", url)[0];
|
||||
if (_u1.protocol != _u2.protocol || _u1.port != _u2.port) return send_by_form(url, params);
|
||||
|
||||
// Do not send AJAX request if another request is in progress.
|
||||
var _xhr = null;
|
||||
if (_xhr && _xhr.readyState !== 0) _xhr.abort();
|
||||
|
||||
// Define the success handler.
|
||||
var successHandler = function(data, textStatus, xhr) {
|
||||
|
||||
// Copy data to the result object.
|
||||
var result = {};
|
||||
$.each(data, function(key, val) {
|
||||
if (key == "act" || key == "redirect_url" || $.inArray(key, return_fields)) {
|
||||
if ($.isArray(val)) {
|
||||
result[key] = { item: val };
|
||||
} else {
|
||||
result[key] = val;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// If the response contains an error, display the error message.
|
||||
if (data.error != "0") {
|
||||
// This way of calling an error handler is deprecated. Do not use it.
|
||||
if ($.isFunction($.exec_xml.onerror)) {
|
||||
if (typeof console == "object" && typeof console.log == "function") {
|
||||
console.log("DEPRECATED : $.exec_xml.onerror() is deprecated in Rhymix.");
|
||||
}
|
||||
return $.exec_xml.onerror(module, act, data, callback_success, return_fields, callback_success_arg, fo_obj);
|
||||
}
|
||||
// Display the error message, or a generic stub if there is no error message.
|
||||
if (data.message) {
|
||||
alert(data.message.replace(/\\n/g, "\n"));
|
||||
} else {
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the response contains a redirect URL, redirect immediately.
|
||||
if (result.redirect_url) {
|
||||
window.location = result.redirect_url.replace(/&/g, "&");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If there was a success callback, call it.
|
||||
if ($.isFunction(callback_success)) {
|
||||
callback_success(result, return_fields, callback_success_arg, fo_obj);
|
||||
}
|
||||
};
|
||||
|
||||
// Define the error handler.
|
||||
var errorHandler = function(xhr, textStatus) {
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
};
|
||||
|
||||
// Send the AJAX request.
|
||||
try {
|
||||
$.ajax({
|
||||
url : url,
|
||||
type : "POST",
|
||||
dataType : "json",
|
||||
data : params,
|
||||
beforeSend : function(xhr) { _xhr = xhr; },
|
||||
success : successHandler,
|
||||
error : errorHandler,
|
||||
complete : function(xhr, textStatus) {
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Display the waiting message.
|
||||
if (show_waiting_message && waiting_obj.length) {
|
||||
var timeoutId = waiting_obj.data("timeout_id");
|
||||
if (timeoutId) clearTimeout(timeoutId);
|
||||
waiting_obj.css("opacity", 0.0).data("timeout_id", setTimeout(function() {
|
||||
waiting_obj.css("opacity", "");
|
||||
}, 1000));
|
||||
waiting_obj.html(waiting_message).show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Function for compatibility with XE's exec_json()
|
||||
*/
|
||||
window.exec_json = $.exec_json = function(action, params, callback_success, callback_error) {
|
||||
|
||||
// Convert params to object and fill in the module and act.
|
||||
params = params ? ($.isArray(params) ? arr2obj(params) : params) : {};
|
||||
action = action.split(".");
|
||||
if (action.length != 2) return;
|
||||
params.module = action[0];
|
||||
params.act = action[1];
|
||||
|
||||
// Fill in the XE vid.
|
||||
if (typeof(xeVid) != "undefined") params.vid = xeVid;
|
||||
|
||||
// Delay the waiting message for 1 second to prevent rapid blinking.
|
||||
waiting_obj.css("opacity", 0.0);
|
||||
var wfsr_timeout = setTimeout(function() {
|
||||
if (show_waiting_message) {
|
||||
waiting_obj.css("opacity", "").html(waiting_message).show();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Define the success handler.
|
||||
var successHandler = function(data, textStatus, xhr) {
|
||||
|
||||
// If the response contains an error, display the error message.
|
||||
if(data.error != "0" && data.error > -1000) {
|
||||
if(data.error == -1 && data.message == "msg_is_not_administrator") {
|
||||
alert("You are not logged in as an administrator.");
|
||||
if ($.isFunction(callback_error)) {
|
||||
callback_error(data);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if (data.message) {
|
||||
alert(data.message.replace(/\\n/g, "\n"));
|
||||
} else {
|
||||
alert("AJAX communication error while requesting " + data.module + "." + data.act);
|
||||
}
|
||||
if ($.isFunction(callback_error)) {
|
||||
callback_error(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If there was a success callback, call it.
|
||||
if($.isFunction(callback_success)) {
|
||||
callback_success(data);
|
||||
}
|
||||
};
|
||||
|
||||
// Define the error handler.
|
||||
var errorHandler = function(xhr, textStatus) {
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
};
|
||||
|
||||
// Send the AJAX request.
|
||||
try {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
url: request_uri,
|
||||
data: params,
|
||||
success : successHandler,
|
||||
error : errorHandler,
|
||||
complete : function(xhr, textStatus) {
|
||||
clearTimeout(wfsr_timeout);
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function for compatibility with XE's exec_html()
|
||||
*/
|
||||
window.exec_html = $.fn.exec_html = function(action, params, type, callback_func, callback_args) {
|
||||
|
||||
// Convert params to object and fill in the module and act.
|
||||
params = params ? ($.isArray(params) ? arr2obj(params) : params) : {};
|
||||
action = action.split(".");
|
||||
if (action.length != 2) return;
|
||||
params.module = action[0];
|
||||
params.act = action[1];
|
||||
|
||||
// Fill in the XE vid.
|
||||
if (typeof(xeVid) != "undefined") params.vid = xeVid;
|
||||
|
||||
// Determine the request type.
|
||||
if(!$.inArray(type, ["html", "append", "prepend"])) type = "html";
|
||||
var self = $(this);
|
||||
|
||||
// Delay the waiting message for 1 second to prevent rapid blinking.
|
||||
waiting_obj.css("opacity", 0.0);
|
||||
var wfsr_timeout = setTimeout(function() {
|
||||
if (show_waiting_message) {
|
||||
waiting_obj.css("opacity", "").html(waiting_message).show();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// Define the success handler.
|
||||
var successHandler = function(data, textStatus, xhr) {
|
||||
if (self && self[type]) {
|
||||
self[type](html);
|
||||
}
|
||||
if ($.isFunction(callback_func)) {
|
||||
callback_func(callback_args);
|
||||
}
|
||||
};
|
||||
|
||||
// Define the error handler.
|
||||
var errorHandler = function(xhr, textStatus) {
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
};
|
||||
|
||||
// Send the AJAX request.
|
||||
try {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "html",
|
||||
url: request_uri,
|
||||
data: params,
|
||||
success: successHandler,
|
||||
error: errorHandler,
|
||||
complete : function(xhr, textStatus) {
|
||||
clearTimeout(wfsr_timeout);
|
||||
waiting_obj.hide().trigger("cancel_confirm");
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Empty placeholder for beforeUnload handler.
|
||||
*/
|
||||
var beforeUnloadHandler = function() {
|
||||
return "";
|
||||
};
|
||||
|
||||
/**
|
||||
* Register the beforeUnload handler.
|
||||
*/
|
||||
$(function() {
|
||||
waiting_obj = $(".wfsr");
|
||||
$(document).ajaxStart(function() {
|
||||
$(window).bind("beforeunload", beforeUnloadHandler);
|
||||
}).bind("ajaxStop cancel_confirm", function() {
|
||||
$(window).unbind("beforeunload", beforeUnloadHandler);
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
/**
|
||||
* This function simulates AJAX requests with HTML forms.
|
||||
* It was meant for cross-domain requests, but should be replaced with JSONP.
|
||||
*/
|
||||
function send_by_form(url, params) {
|
||||
|
||||
// This function is deprecated!
|
||||
if (typeof console == "object" && typeof console.log == "function") {
|
||||
console.log("DEPRECATED : send_by_form() is deprecated in Rhymix.");
|
||||
}
|
||||
|
||||
// Create the hidden iframe.
|
||||
var frame_id = "xeTmpIframe";
|
||||
if (!$("#" + frame_id).length) {
|
||||
$('<iframe name="%id%" id="%id%" style="position:absolute;left:-1px;top:1px;width:1px;height:1px"></iframe>'.replace(/%id%/g, frame_id)).appendTo(document.body);
|
||||
}
|
||||
|
||||
// Create the hidden form.
|
||||
var form_id = "xeVirtualForm";
|
||||
$("#" + form_id).remove();
|
||||
var form = $('<form id="%id%"></form>'.replace(/%id%/g, form_id)).attr({
|
||||
"id" : form_id,
|
||||
"method" : "post",
|
||||
"action" : url,
|
||||
"target" : frame_id
|
||||
});
|
||||
|
||||
// Add virtual XML parameters.
|
||||
params.xeVirtualRequestMethod = "xml";
|
||||
params.xeRequestURI = location.href.replace(/#(.*)$/i, "");
|
||||
params.xeVirtualRequestUrl = request_uri;
|
||||
|
||||
// Add inputs to the form.
|
||||
$.each(params, function(key, value){
|
||||
$('<input type="hidden">').attr("name", key).attr("value", value).appendTo(form);
|
||||
});
|
||||
|
||||
// Submit the hidden form.
|
||||
form.appendTo(document.body).submit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function converts arrays into objects.
|
||||
*/
|
||||
function arr2obj(arr) {
|
||||
var ret = {};
|
||||
for (var key in arr) {
|
||||
if (arr.hasOwnProperty(key)) {
|
||||
ret[key] = arr[key];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
|
@ -194,272 +535,3 @@ function xml2json(xml, tab, ignoreAttrib) {
|
|||
return "{" + (tab ? json_str.replace(/\t/g, tab) : json_str.replace(/\t|\n/g, "")) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
(function($){
|
||||
/**
|
||||
* @brief exec_xml
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
**/
|
||||
$.exec_xml = window.exec_xml = function(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj) {
|
||||
params = params ? ($.isArray(params) ? arr2obj(params) : params) : {};
|
||||
params.module = module;
|
||||
params.act = act;
|
||||
|
||||
if(typeof(xeVid) != "undefined") params.vid = xeVid;
|
||||
if(typeof(response_tags) == "undefined" || response_tags.length < 1) {
|
||||
response_tags = ['error','message'];
|
||||
} else {
|
||||
response_tags.push('error', 'message');
|
||||
}
|
||||
|
||||
// use ssl?
|
||||
var url = request_uri;
|
||||
if ($.isArray(ssl_actions) && params.act && $.inArray(params.act, ssl_actions) >= 0) {
|
||||
url = default_url || request_uri;
|
||||
var port = window.https_port || 443;
|
||||
var _ul = $('<a>').attr('href', url)[0];
|
||||
var target = 'https://' + _ul.hostname.replace(/:\d+$/, '');
|
||||
|
||||
if(port != 443) target += ':'+port;
|
||||
if(_ul.pathname[0] != '/') target += '/';
|
||||
|
||||
target += _ul.pathname;
|
||||
url = target.replace(/\/$/, '')+'/';
|
||||
}
|
||||
|
||||
var _u1 = $('<a>').attr('href', location.href)[0];
|
||||
var _u2 = $('<a>').attr('href', url)[0];
|
||||
|
||||
// 현 url과 ajax call 대상 url의 schema 또는 port가 다르면 직접 form 전송
|
||||
if(_u1.protocol != _u2.protocol || _u1.port != _u2.port) return send_by_form(url, params);
|
||||
|
||||
var _xhr = null;
|
||||
if (_xhr && _xhr.readyState !== 0) _xhr.abort();
|
||||
|
||||
// 전송 성공시
|
||||
function onsuccess(data, textStatus, xhr) {
|
||||
waiting_obj.css('display', 'none').trigger('cancel_confirm');
|
||||
var ret = {};
|
||||
|
||||
$.each(data, function(key, val) {
|
||||
if(key == "act" || key == "redirect_url" || $.inArray(key, response_tags)) {
|
||||
if($.isArray(val)) {
|
||||
ret[key] = { item: val };
|
||||
} else {
|
||||
ret[key] = val;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(data.error != '0') {
|
||||
if ($.isFunction($.exec_xml.onerror)) {
|
||||
return $.exec_xml.onerror(module, act, data, callback_func, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
if (data.message) {
|
||||
alert(data.message.replace(/\\n/g, "\n"));
|
||||
} else {
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(ret.redirect_url) {
|
||||
location.href = ret.redirect_url.replace(/&/g, '&');
|
||||
return null;
|
||||
}
|
||||
|
||||
if($.isFunction(callback_func)) callback_func(ret, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
|
||||
// 모든 데이터는 POST방식으로 전송. try-catch문으로 오류 발생시 대처
|
||||
try {
|
||||
$.ajax({
|
||||
url : url,
|
||||
type : "POST",
|
||||
dataType : "json",
|
||||
data : params,
|
||||
beforeSend : function(xhr){ _xhr = xhr; },
|
||||
success : onsuccess,
|
||||
error : function(xhr, textStatus) {
|
||||
waiting_obj.css('display', 'none');
|
||||
alert("AJAX communication error while requesting " + params.module + "." + params.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// ajax 통신중 대기 메세지 출력 (show_waiting_message값을 false로 세팅시 보이지 않음)
|
||||
var waiting_obj = $('.wfsr');
|
||||
if(show_waiting_message && waiting_obj.length) {
|
||||
|
||||
var timeoutId = $(".wfsr").data('timeout_id');
|
||||
if(timeoutId) clearTimeout(timeoutId);
|
||||
$(".wfsr").css('opacity', 0.0);
|
||||
$(".wfsr").data('timeout_id', setTimeout(function(){
|
||||
$(".wfsr").css('opacity', '');
|
||||
}, 1000));
|
||||
|
||||
waiting_obj.html(waiting_message).show();
|
||||
}
|
||||
};
|
||||
|
||||
function send_by_form(url, params) {
|
||||
var frame_id = 'xeTmpIframe';
|
||||
var form_id = 'xeVirtualForm';
|
||||
|
||||
if (!$('#'+frame_id).length) {
|
||||
$('<iframe name="%id%" id="%id%" style="position:absolute;left:-1px;top:1px;width:1px;height:1px"></iframe>'.replace(/%id%/g, frame_id)).appendTo(document.body);
|
||||
}
|
||||
|
||||
$('#'+form_id).remove();
|
||||
var form = $('<form id="%id%"></form>'.replace(/%id%/g, form_id)).attr({
|
||||
'id' : form_id,
|
||||
'method' : 'post',
|
||||
'action' : url,
|
||||
'target' : frame_id
|
||||
});
|
||||
|
||||
params.xeVirtualRequestMethod = 'xml';
|
||||
params.xeRequestURI = location.href.replace(/#(.*)$/i,'');
|
||||
params.xeVirtualRequestUrl = request_uri;
|
||||
|
||||
$.each(params, function(key, value){
|
||||
$('<input type="hidden">').attr('name', key).attr('value', value).appendTo(form);
|
||||
});
|
||||
|
||||
form.appendTo(document.body).submit();
|
||||
}
|
||||
|
||||
function arr2obj(arr) {
|
||||
var ret = {};
|
||||
for(var key in arr) {
|
||||
if(arr.hasOwnProperty(key)) ret[key] = arr[key];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief exec_json (exec_xml와 같은 용도)
|
||||
**/
|
||||
$.exec_json = window.exec_json = function(action, data, callback_sucess, callback_error){
|
||||
data = data ? ($.isArray(data) ? arr2obj(data) : data) : {};
|
||||
action = action.split('.');
|
||||
|
||||
if(action.length == 2) {
|
||||
// The cover can be disturbing if it consistently blinks (because ajax call usually takes very short time). So make it invisible for the 1st 0.5 sec and then make it visible.
|
||||
var timeoutId = $(".wfsr").data('timeout_id');
|
||||
|
||||
if(timeoutId) clearTimeout(timeoutId);
|
||||
|
||||
$(".wfsr").css('opacity', 0.0);
|
||||
$(".wfsr").data('timeout_id', setTimeout(function(){
|
||||
$(".wfsr").css('opacity', '');
|
||||
}, 1000));
|
||||
|
||||
if(show_waiting_message) $(".wfsr").html(waiting_message).show();
|
||||
|
||||
data.module = action[0];
|
||||
data.act = action[1];
|
||||
|
||||
if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid});
|
||||
|
||||
try {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
url: request_uri,
|
||||
data: data,
|
||||
success: function(data) {
|
||||
$(".wfsr").hide().trigger('cancel_confirm');
|
||||
if(data.error != '0' && data.error > -1000) {
|
||||
if(data.error == -1 && data.message == 'msg_is_not_administrator') {
|
||||
alert('You are not logged in as an administrator');
|
||||
if($.isFunction(callback_error)) callback_error(data);
|
||||
|
||||
return;
|
||||
} else {
|
||||
if (data.message) {
|
||||
alert(data.message.replace(/\\n/g, "\n"));
|
||||
} else {
|
||||
alert("AJAX communication error while requesting " + data.module + "." + data.act);
|
||||
}
|
||||
if($.isFunction(callback_error)) callback_error(data);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if($.isFunction(callback_sucess)) callback_sucess(data);
|
||||
},
|
||||
error: function(xhr, textStatus) {
|
||||
$(".wfsr").hide();
|
||||
alert("AJAX communication error while requesting " + data.module + "." + data.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.exec_html = function(action, data, type, func, args){
|
||||
if(typeof(data) == 'undefined') data = {};
|
||||
if(!$.inArray(type, ['html','append','prepend'])) type = 'html';
|
||||
|
||||
var self = $(this);
|
||||
action = action.split(".");
|
||||
if(action.length == 2){
|
||||
var timeoutId = $(".wfsr").data('timeout_id');
|
||||
if(timeoutId) clearTimeout(timeoutId);
|
||||
$(".wfsr").css('opacity', 0.0);
|
||||
$(".wfsr").data('timeout_id', setTimeout(function(){
|
||||
$(".wfsr").css('opacity', '');
|
||||
}, 1000));
|
||||
if(show_waiting_message) $(".wfsr").html(waiting_message).show();
|
||||
|
||||
data.module = action[0];
|
||||
data.act = action[1];
|
||||
|
||||
try {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "html",
|
||||
url: request_uri,
|
||||
data: data,
|
||||
success: function(html) {
|
||||
$(".wfsr").hide().trigger('cancel_confirm');
|
||||
self[type](html);
|
||||
if($.isFunction(func)) func(args);
|
||||
},
|
||||
error: function(xhr, textStatus) {
|
||||
$(".wfsr").hide();
|
||||
alert("AJAX communication error while requesting " + data.module + "." + data.act + "\n\n" + xhr.status + " " + xhr.statusText);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function beforeUnloadHandler(){
|
||||
return '';
|
||||
}
|
||||
|
||||
$(function($){
|
||||
$(document)
|
||||
.ajaxStart(function(){
|
||||
$(window).bind('beforeunload', beforeUnloadHandler);
|
||||
})
|
||||
.bind('ajaxStop cancel_confirm', function(){
|
||||
$(window).unbind('beforeunload', beforeUnloadHandler);
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue