diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/Article.js | 2 | ||||
-rw-r--r-- | js/CommonDialogs.js | 34 | ||||
-rw-r--r-- | js/CommonFilters.js | 4 | ||||
-rw-r--r-- | js/Feeds.js | 2 | ||||
-rw-r--r-- | js/PrefFilterTree.js | 2 | ||||
-rw-r--r-- | js/PrefLabelTree.js | 2 | ||||
-rw-r--r-- | js/PrefUsers.js | 2 | ||||
-rw-r--r-- | js/Utils.js | 2 | ||||
-rwxr-xr-x | js/common.js | 126 | ||||
-rw-r--r-- | js/tt-rss.js | 32 |
10 files changed, 85 insertions, 123 deletions
diff --git a/js/Article.js b/js/Article.js index 0e1318948..7e5241fa5 100644 --- a/js/Article.js +++ b/js/Article.js @@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) { return false; }, editTags: function(id) { - const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); + const query = "backend.php?op=article&method=editArticleTags¶m=" + encodeURIComponent(id); if (dijit.byId("editTagsDlg")) dijit.byId("editTagsDlg").destroyRecursive(); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index d8733e1c2..efdc4e503 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -2,6 +2,40 @@ /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { return declare("fox.CommonDialogs", null, { + closeInfoBox: function() { + const dialog = dijit.byId("infoBox"); + if (dialog) dialog.hide(); + }, + removeFeedIcon: function(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; + }, + uploadFeedIcon: function() { + 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; + }, quickAddFeed: function() { const query = "backend.php?op=feeds&method=quickAddFeed"; diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 3f508ef71..ef087b50c 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -126,7 +126,7 @@ define(["dojo/_base/declare"], function (declare) { dijit.byId("filterNewRuleDlg").destroyRecursive(); const query = "backend.php?op=pref-filters&method=newrule&rule=" + - param_escape(ruleStr); + encodeURIComponent(ruleStr); const rule_dlg = new dijit.Dialog({ id: "filterNewRuleDlg", @@ -148,7 +148,7 @@ define(["dojo/_base/declare"], function (declare) { dijit.byId("filterNewActionDlg").destroyRecursive(); const query = "backend.php?op=pref-filters&method=newaction&action=" + - param_escape(actionStr); + encodeURIComponent(actionStr); const rule_dlg = new dijit.Dialog({ id: "filterNewActionDlg", diff --git a/js/Feeds.js b/js/Feeds.js index c7db1aee5..ec90caba7 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -608,7 +608,7 @@ define(["dojo/_base/declare"], function (declare) { }, search: function() { const query = "backend.php?op=feeds&method=search¶m=" + - param_escape(Feeds.getActive() + ":" + Feeds.activeIsCat()); + encodeURIComponent(Feeds.getActive() + ":" + Feeds.activeIsCat()); if (dijit.byId("searchDlg")) dijit.byId("searchDlg").destroyRecursive(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 9a2dd6c1c..6823fa8ad 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -138,7 +138,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }, editFilter: function(id) { - const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); + const query = "backend.php?op=pref-filters&method=edit&id=" + encodeURIComponent(id); if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").destroyRecursive(); diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 914df9a19..abe79a114 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -56,7 +56,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }, editLabel: function(id) { const query = "backend.php?op=pref-labels&method=edit&id=" + - param_escape(id); + encodeURIComponent(id); if (dijit.byId("labelEditDlg")) dijit.byId("labelEditDlg").destroyRecursive(); diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 891af8ddb..eed64e76b 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -27,7 +27,7 @@ define(["dojo/_base/declare"], function (declare) { }, edit: function(id) { const query = "backend.php?op=pref-users&method=edit&id=" + - param_escape(id); + encodeURIComponent(id); if (dijit.byId("userEditDlg")) dijit.byId("userEditDlg").destroyRecursive(); diff --git a/js/Utils.js b/js/Utils.js index 8778143f2..f01ecbc48 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -95,7 +95,7 @@ define(["dojo/_base/declare"], function (declare) { }); }, helpDialog: function(topic) { - const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); + const query = "backend.php?op=backend&method=help&topic=" + encodeURIComponent(topic); if (dijit.byId("helpDlg")) dijit.byId("helpDlg").destroyRecursive(); diff --git a/js/common.js b/js/common.js index b63257099..9a3c1715d 100755 --- a/js/common.js +++ b/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) { diff --git a/js/tt-rss.js b/js/tt-rss.js index 74b8403f8..4eeeed131 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -116,9 +116,9 @@ const App = { Feeds.reload(); Article.close(); - if (parseInt(getCookie("ttrss_fh_width")) > 0) { + if (parseInt(Cookie.get("ttrss_fh_width")) > 0) { dijit.byId("feeds-holder").domNode.setStyle( - {width: getCookie("ttrss_fh_width") + "px"}); + {width: Cookie.get("ttrss_fh_width") + "px"}); } dijit.byId("main").resize(); @@ -126,19 +126,19 @@ const App = { dojo.connect(dijit.byId('feeds-holder'), 'resize', function (args) { if (args && args.w >= 0) { - setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); } }); dojo.connect(dijit.byId('content-insert'), 'resize', function (args) { if (args && args.w >= 0 && args.h >= 0) { - setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); - setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); + Cookie.set("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); } }); - delCookie("ttrss_test"); + Cookie.delete("ttrss_test"); const toolbar = document.forms["main_toolbar_form"]; @@ -172,9 +172,9 @@ const App = { console.log("second stage ok"); }, genericSanityCheck: function() { - setCookie("ttrss_test", "TEST"); + Cookie.set("ttrss_test", "TEST"); - if (getCookie("ttrss_test") != "TEST") { + if (Cookie.get("ttrss_test") != "TEST") { return fatalError(2); } @@ -224,9 +224,9 @@ const App = { height: 'auto', borderTopWidth: '0px' }); - if (parseInt(getCookie("ttrss_ci_width")) > 0) { + if (parseInt(Cookie.get("ttrss_ci_width")) > 0) { dijit.byId("content-insert").domNode.setStyle( - {width: getCookie("ttrss_ci_width") + "px" }); + {width: Cookie.get("ttrss_ci_width") + "px" }); } $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); @@ -240,9 +240,9 @@ const App = { height: '50%', borderTopWidth: '0px'}); - if (parseInt(getCookie("ttrss_ci_height")) > 0) { + if (parseInt(Cookie.get("ttrss_ci_height")) > 0) { dijit.byId("content-insert").domNode.setStyle( - {height: getCookie("ttrss_ci_height") + "px" }); + {height: Cookie.get("ttrss_ci_height") + "px" }); } $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); @@ -466,8 +466,8 @@ const App = { App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); App.switchPanelMode(App._widescreen_mode); } else { @@ -557,8 +557,8 @@ const App = { App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); App.switchPanelMode(App._widescreen_mode); } else { |