|
jQuery.sohaBase = {
isDirty: false,
refreshContent: function () {
this.isDirty = false;
window.location.reload(true);
},
setDirtyFlag: function (docDirty) {
$(window).unbind('beforeunload', this.confirmExit);
this.isDirty = docDirty;
if (docDirty)
$(window).bind('beforeunload', this.confirmExit);
},
getDirtyFlag: function () {
return this.isDirty;
},
confirmExit: function () {
if (this.isDirty)
return "Are you sure you want to leave this page? If you haven't saved your info, it could be lost.";
},
onUnloadPage: function () {
this.isDirty = false;
},
isNullOrEmpty: function (strParam) {
return (strParam == undefined || strParam == null || strParam == "");
},
getPageName: function () {
var requestedPage = window.location.pathname;
requestedPage = requestedPage.substr(requestedPage.lastIndexOf("/") + 1);
requestedPage = requestedPage.substr(0, requestedPage.lastIndexOf("."));
if (this.isNullOrEmpty(requestedPage))
requestedPage = "index";
return requestedPage;
},
getPathName: function () {
var requestedPage = window.location.pathname;
var endIdx = requestedPage.lastIndexOf("/");
var pathStr = requestedPage.substring(1, endIdx);
if (this.isNullOrEmpty(pathStr))
return null;
var startIdx = pathStr.lastIndexOf("/") + 1;
return requestedPage.substring(startIdx, endIdx);
},
loadPageScript: function (jsUrl, onResult) {
$.getScript(jsUrl, onResult);
},
loadPageCSS: function (cssUrl) {
$('<link>').appendTo('head').attr({
rel: "stylesheet",
type: "text/css",
href: cssUrl
});
},
loadContentHTML: function (containerID, htmlURL, onResult) {
$('#' + containerID).load(htmlURL, onResult);
},
isCookieEnabled: function () {
$.cookie('cbexp_cookie_detector', 'cbexp_test');
var retVal = (null != $.cookie('cbexp_cookie_detector'));
$.cookie('cbexp_cookie_detector', null);
return retVal;
},
isStorageEnabled: function () {
var testKey = "soha_base_storage_detector_key";
var testVal = "soha_base_storage_detector_soha_base_storage_detector_soha_base_storage_detector_soha_base_storage_detector_soha_base_storage_detector";
$.jStorage.set(testKey, testVal);
var retVal = (testVal == $.jStorage.get(testKey));
$.jStorage.deleteKey(testKey);
return retVal;
},
getQueryString: function () {
var qs = window.location.search;
if (qs.length <= 1)
return new Array();
qs = qs.substring(1, qs.length);
var a = qs.split("&");
var b = new Array();
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
b[p[0]] = decodeURIComponent(p[1]);
}
return b;
},
postJson: function (postURL, jsDataObj, onResult, onError) {
try {
$.ajax({
type: "POST",
beforeSend: function (xhr) { xhr.withCredentials = true; },
contentType: "application/json",
dataType: "json",
timeout: 90000,
url: postURL,
data: $.toJSON(jsDataObj),
async: true,
success: onResult,
error: onError
});
}
catch (err) { alert("ajax call failed: " + postURL); }
},
isBadResponse: function (response) {
var retVal = false;
try {
if (response.status.code > 206 || response.status.code < 200)
retVal = true;
}
catch (e) {
retVal = true;
}
return retVal;
}
};
$(window).bind('unload', jQuery.sohaBase.onUnloadPage);
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.