mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 10:45:56 +00:00
move some more stuff out of common.js
rework client-side cookie functions a bit limit dojo cachebust based on server scripts modification time remove param_escape()
This commit is contained in:
126
js/common.js
126
js/common.js
@@ -54,6 +54,8 @@ Array.prototype.remove = function(s) {
|
||||
}
|
||||
};
|
||||
|
||||
/* common helpers not worthy of separate Dojo modules */
|
||||
|
||||
const Lists = {
|
||||
onRowChecked: function(elem) {
|
||||
const checked = elem.domNode ? elem.attr("checked") : elem.checked;
|
||||
@@ -113,6 +115,31 @@ const Tables = {
|
||||
}
|
||||
};
|
||||
|
||||
const Cookie = {
|
||||
set: function (name, value, lifetime) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + lifetime * 1000);
|
||||
const expires = "expires=" + d.toUTCString();
|
||||
document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires;
|
||||
},
|
||||
get: function (name) {
|
||||
name = name + "=";
|
||||
const ca = document.cookie.split(';');
|
||||
for (let i=0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1);
|
||||
if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length));
|
||||
}
|
||||
return "";
|
||||
},
|
||||
delete: function(name) {
|
||||
const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
||||
document.cookie = name + "=" + "" + "; " + expires;
|
||||
}
|
||||
};
|
||||
|
||||
/* error reporting */
|
||||
|
||||
function report_error(message, filename, lineno, colno, error) {
|
||||
exception_error(error, null, filename, lineno);
|
||||
}
|
||||
@@ -177,10 +204,6 @@ function exception_error(e, e_compat, filename, lineno, colno) {
|
||||
|
||||
}
|
||||
|
||||
function param_escape(arg) {
|
||||
return encodeURIComponent(arg);
|
||||
}
|
||||
|
||||
function notify_real(msg, no_hide, n_type) {
|
||||
|
||||
const n = $("notify");
|
||||
@@ -263,58 +286,6 @@ function notify_info(msg, no_hide) {
|
||||
notify_real(msg, no_hide, 4);
|
||||
}
|
||||
|
||||
function setCookie(name, value, lifetime, path, domain, secure) {
|
||||
|
||||
let d = false;
|
||||
|
||||
if (lifetime) {
|
||||
d = new Date();
|
||||
d.setTime(d.getTime() + (lifetime * 1000));
|
||||
}
|
||||
|
||||
console.log("setCookie: " + name + " => " + value + ": " + d);
|
||||
|
||||
int_setCookie(name, value, d, path, domain, secure);
|
||||
|
||||
}
|
||||
|
||||
function int_setCookie(name, value, expires, path, domain, secure) {
|
||||
document.cookie= name + "=" + escape(value) +
|
||||
((expires) ? "; expires=" + expires.toGMTString() : "") +
|
||||
((path) ? "; path=" + path : "") +
|
||||
((domain) ? "; domain=" + domain : "") +
|
||||
((secure) ? "; secure" : "");
|
||||
}
|
||||
|
||||
function delCookie(name, path, domain) {
|
||||
if (getCookie(name)) {
|
||||
document.cookie = name + "=" +
|
||||
((path) ? ";path=" + path : "") +
|
||||
((domain) ? ";domain=" + domain : "" ) +
|
||||
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getCookie(name) {
|
||||
|
||||
const dc = document.cookie;
|
||||
const prefix = name + "=";
|
||||
let begin = dc.indexOf("; " + prefix);
|
||||
if (begin == -1) {
|
||||
begin = dc.indexOf(prefix);
|
||||
if (begin != 0) return null;
|
||||
}
|
||||
else {
|
||||
begin += 2;
|
||||
}
|
||||
let end = document.cookie.indexOf(";", begin);
|
||||
if (end == -1) {
|
||||
end = dc.length;
|
||||
}
|
||||
return unescape(dc.substring(begin + prefix.length, end));
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function displayIfChecked(checkbox, elemId) {
|
||||
if (checkbox.checked) {
|
||||
@@ -324,15 +295,6 @@ function displayIfChecked(checkbox, elemId) {
|
||||
}
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function closeInfoBox() {
|
||||
const dialog = dijit.byId("infoBox");
|
||||
|
||||
if (dialog) dialog.hide();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getInitParam(key) {
|
||||
return init_params[key];
|
||||
}
|
||||
@@ -407,40 +369,6 @@ function uploadIconHandler(rc) {
|
||||
}
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function removeFeedIcon(id) {
|
||||
if (confirm(__("Remove stored feed icon?"))) {
|
||||
|
||||
notify_progress("Removing feed icon...", true);
|
||||
|
||||
const query = { op: "pref-feeds", method: "removeicon", feed_id: id };
|
||||
|
||||
xhrPost("backend.php", query, () => {
|
||||
notify_info("Feed icon removed.");
|
||||
if (App.isPrefs()) {
|
||||
Feeds.reload();
|
||||
} else {
|
||||
setTimeout('Feeds.reload(false, false)', 50);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function uploadFeedIcon() {
|
||||
const file = $("icon_file");
|
||||
|
||||
if (file.value.length == 0) {
|
||||
alert(__("Please select an image file to upload."));
|
||||
} else if (confirm(__("Upload new icon for this feed?"))) {
|
||||
notify_progress("Uploading, please wait...", true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function label_to_feed_id(label) {
|
||||
|
||||
Reference in New Issue
Block a user