From 7ac6ab4dda90b20afe148c621eb39881f476390e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 1 Jun 2016 16:21:03 +0300 Subject: set referrer-policy to none --- index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/index.php b/index.php index 10c754803..203ecef66 100644 --- a/index.php +++ b/index.php @@ -118,6 +118,7 @@ + - + + get_plugins() as $n => $p) { if (method_exists($p, "get_js")) { diff --git a/js/tt-rss.js b/js/tt-rss.js index 108b65a7f..776c5d02b 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -216,90 +216,94 @@ function genericSanityCheck() { function init() { try { - //dojo.registerModulePath("fox", "../../js/"); - - dojo.require("fox.FeedTree"); - - dojo.require("dijit.ColorPalette"); - dojo.require("dijit.Dialog"); - dojo.require("dijit.form.Button"); - dojo.require("dijit.form.CheckBox"); - dojo.require("dijit.form.DropDownButton"); - dojo.require("dijit.form.FilteringSelect"); - dojo.require("dijit.form.Form"); - dojo.require("dijit.form.RadioButton"); - dojo.require("dijit.form.Select"); - dojo.require("dijit.form.SimpleTextarea"); - dojo.require("dijit.form.TextBox"); - dojo.require("dijit.form.ComboBox"); - dojo.require("dijit.form.ValidationTextBox"); - dojo.require("dijit.InlineEditBox"); - dojo.require("dijit.layout.AccordionContainer"); - dojo.require("dijit.layout.BorderContainer"); - dojo.require("dijit.layout.ContentPane"); - dojo.require("dijit.layout.TabContainer"); - dojo.require("dijit.Menu"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.Toolbar"); - dojo.require("dijit.Tree"); - dojo.require("dijit.tree.dndSource"); - dojo.require("dojo.data.ItemFileWriteStore"); - - dojo.parser.parse(); - - if (!genericSanityCheck()) - return false; - - loading_set_progress(30); - - var a = document.createElement('audio'); - - var hasAudio = !!a.canPlayType; - var hasSandbox = "sandbox" in document.createElement("iframe"); - var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); - var clientTzOffset = new Date().getTimezoneOffset() * 60; - - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio, - hasMp3: hasMp3, - clientTzOffset: clientTzOffset, - hasSandbox: hasSandbox}, - onComplete: function(transport) { + require(['dojo/_base/kernel', 'dojo/ready', 'dojo/parser', 'dojo/_base/loader'], function(dojo, ready, parser) { + + //dojo.registerModulePath("fox", "../../js/"); + + dojo.require("fox.FeedTree"); + + dojo.require("dijit.ColorPalette"); + dojo.require("dijit.Dialog"); + dojo.require("dijit.form.Button"); + dojo.require("dijit.form.ComboButton"); + dojo.require("dijit.form.CheckBox"); + dojo.require("dijit.form.DropDownButton"); + dojo.require("dijit.form.FilteringSelect"); + dojo.require("dijit.form.Form"); + dojo.require("dijit.form.RadioButton"); + dojo.require("dijit.form.Select"); + dojo.require("dijit.form.SimpleTextarea"); + dojo.require("dijit.form.TextBox"); + dojo.require("dijit.form.ComboBox"); + dojo.require("dijit.form.ValidationTextBox"); + dojo.require("dijit.InlineEditBox"); + dojo.require("dijit.layout.AccordionContainer"); + dojo.require("dijit.layout.BorderContainer"); + dojo.require("dijit.layout.ContentPane"); + dojo.require("dijit.layout.TabContainer"); + dojo.require("dijit.PopupMenuItem"); + dojo.require("dijit.Menu"); + dojo.require("dijit.ProgressBar"); + dojo.require("dijit.ProgressBar"); + dojo.require("dijit.Toolbar"); + dojo.require("dijit.Tree"); + dojo.require("dijit.tree.dndSource"); + dojo.require("dojo.data.ItemFileWriteStore"); + + dojo.parser.parse(); + + if (!genericSanityCheck()) + return false; + + loading_set_progress(30); + + var a = document.createElement('audio'); + + var hasAudio = !!a.canPlayType; + var hasSandbox = "sandbox" in document.createElement("iframe"); + var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); + var clientTzOffset = new Date().getTimezoneOffset() * 60; + + new Ajax.Request("backend.php", { + parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio, + hasMp3: hasMp3, + clientTzOffset: clientTzOffset, + hasSandbox: hasSandbox}, + onComplete: function(transport) { backend_sanity_check_callback(transport); } }); - hotkey_actions["next_feed"] = function() { + hotkey_actions["next_feed"] = function() { var rv = dijit.byId("feedTree").getNextFeed( - getActiveFeedId(), activeFeedIsCat()); + getActiveFeedId(), activeFeedIsCat()); if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) - }; - hotkey_actions["prev_feed"] = function() { + }; + hotkey_actions["prev_feed"] = function() { var rv = dijit.byId("feedTree").getPreviousFeed( - getActiveFeedId(), activeFeedIsCat()); + getActiveFeedId(), activeFeedIsCat()); if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) - }; - hotkey_actions["next_article"] = function() { + }; + hotkey_actions["next_article"] = function() { moveToPost('next'); - }; - hotkey_actions["prev_article"] = function() { + }; + hotkey_actions["prev_article"] = function() { moveToPost('prev'); - }; - hotkey_actions["next_article_noscroll"] = function() { + }; + hotkey_actions["next_article_noscroll"] = function() { moveToPost('next', true); - }; - hotkey_actions["prev_article_noscroll"] = function() { + }; + hotkey_actions["prev_article_noscroll"] = function() { moveToPost('prev', true); - }; - hotkey_actions["next_article_noexpand"] = function() { + }; + hotkey_actions["next_article_noexpand"] = function() { moveToPost('next', true, true); - }; - hotkey_actions["prev_article_noexpand"] = function() { + }; + hotkey_actions["prev_article_noexpand"] = function() { moveToPost('prev', true, true); - }; - hotkey_actions["collapse_article"] = function() { + }; + hotkey_actions["collapse_article"] = function() { var id = getActiveArticleId(); var elem = $("CICD-"+id); @@ -311,8 +315,8 @@ function init() { cdmExpandArticle(id); } } - }; - hotkey_actions["toggle_expand"] = function() { + }; + hotkey_actions["toggle_expand"] = function() { var id = getActiveArticleId(); var elem = $("CICD-"+id); @@ -324,48 +328,48 @@ function init() { cdmExpandArticle(id); } } - }; - hotkey_actions["search_dialog"] = function() { + }; + hotkey_actions["search_dialog"] = function() { search(); - }; - hotkey_actions["toggle_mark"] = function() { + }; + hotkey_actions["toggle_mark"] = function() { selectionToggleMarked(undefined, false, true); - }; - hotkey_actions["toggle_publ"] = function() { + }; + hotkey_actions["toggle_publ"] = function() { selectionTogglePublished(undefined, false, true); - }; - hotkey_actions["toggle_unread"] = function() { + }; + hotkey_actions["toggle_unread"] = function() { selectionToggleUnread(undefined, false, true); - }; - hotkey_actions["edit_tags"] = function() { + }; + hotkey_actions["edit_tags"] = function() { var id = getActiveArticleId(); if (id) { editArticleTags(id); }; } - hotkey_actions["open_in_new_window"] = function() { + hotkey_actions["open_in_new_window"] = function() { if (getActiveArticleId()) { openArticleInNewWindow(getActiveArticleId()); return; } - }; - hotkey_actions["catchup_below"] = function() { + }; + hotkey_actions["catchup_below"] = function() { catchupRelativeToArticle(1); - }; - hotkey_actions["catchup_above"] = function() { + }; + hotkey_actions["catchup_above"] = function() { catchupRelativeToArticle(0); - }; - hotkey_actions["article_scroll_down"] = function() { + }; + hotkey_actions["article_scroll_down"] = function() { var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); scrollArticle(40); - }; - hotkey_actions["article_scroll_up"] = function() { + }; + hotkey_actions["article_scroll_up"] = function() { var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); scrollArticle(-40); - }; - hotkey_actions["close_article"] = function() { + }; + hotkey_actions["close_article"] = function() { if (isCdmMode()) { if (!getInitParam("cdm_expanded")) { cdmCollapseArticle(false, getActiveArticleId()); @@ -373,8 +377,8 @@ function init() { } else { closeArticlePanel(); } - }; - hotkey_actions["email_article"] = function() { + }; + hotkey_actions["email_article"] = function() { if (typeof emailArticle != "undefined") { emailArticle(); } else if (typeof mailtoArticle != "undefined") { @@ -382,103 +386,103 @@ function init() { } else { alert(__("Please enable mail plugin first.")); } - }; - hotkey_actions["select_all"] = function() { + }; + hotkey_actions["select_all"] = function() { selectArticles('all'); - }; - hotkey_actions["select_unread"] = function() { + }; + hotkey_actions["select_unread"] = function() { selectArticles('unread'); - }; - hotkey_actions["select_marked"] = function() { + }; + hotkey_actions["select_marked"] = function() { selectArticles('marked'); - }; - hotkey_actions["select_published"] = function() { + }; + hotkey_actions["select_published"] = function() { selectArticles('published'); - }; - hotkey_actions["select_invert"] = function() { + }; + hotkey_actions["select_invert"] = function() { selectArticles('invert'); - }; - hotkey_actions["select_none"] = function() { + }; + hotkey_actions["select_none"] = function() { selectArticles('none'); - }; - hotkey_actions["feed_refresh"] = function() { + }; + hotkey_actions["feed_refresh"] = function() { if (getActiveFeedId() != undefined) { viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); return; } - }; - hotkey_actions["feed_unhide_read"] = function() { + }; + hotkey_actions["feed_unhide_read"] = function() { toggleDispRead(); - }; - hotkey_actions["feed_subscribe"] = function() { + }; + hotkey_actions["feed_subscribe"] = function() { quickAddFeed(); - }; - hotkey_actions["feed_debug_update"] = function() { - if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { - window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + - "&csrf_token=" + getInitParam("csrf_token")); - } else { - alert("You can't debug this kind of feed."); - } - }; + }; + hotkey_actions["feed_debug_update"] = function() { + if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { + window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + + "&csrf_token=" + getInitParam("csrf_token")); + } else { + alert("You can't debug this kind of feed."); + } + }; - hotkey_actions["feed_debug_viewfeed"] = function() { - viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); - }; + hotkey_actions["feed_debug_viewfeed"] = function() { + viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); + }; - hotkey_actions["feed_edit"] = function() { + hotkey_actions["feed_edit"] = function() { if (activeFeedIsCat()) alert(__("You can't edit this kind of feed.")); else editFeed(getActiveFeedId()); - }; - hotkey_actions["feed_catchup"] = function() { + }; + hotkey_actions["feed_catchup"] = function() { if (getActiveFeedId() != undefined) { catchupCurrentFeed(); return; } - }; - hotkey_actions["feed_reverse"] = function() { + }; + hotkey_actions["feed_reverse"] = function() { reverseHeadlineOrder(); - }; - hotkey_actions["feed_toggle_vgroup"] = function() { - var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; + }; + hotkey_actions["feed_toggle_vgroup"] = function() { + var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; - new Ajax.Request("backend.php", { - parameters: query_str, - onComplete: function(transport) { - viewCurrentFeed(); - } }); + new Ajax.Request("backend.php", { + parameters: query_str, + onComplete: function(transport) { + viewCurrentFeed(); + } }); - }; - hotkey_actions["catchup_all"] = function() { + }; + hotkey_actions["catchup_all"] = function() { catchupAllFeeds(); - }; - hotkey_actions["cat_toggle_collapse"] = function() { + }; + hotkey_actions["cat_toggle_collapse"] = function() { if (activeFeedIsCat()) { dijit.byId("feedTree").collapseCat(getActiveFeedId()); return; } - }; - hotkey_actions["goto_all"] = function() { + }; + hotkey_actions["goto_all"] = function() { viewfeed({feed: -4}); - }; - hotkey_actions["goto_fresh"] = function() { + }; + hotkey_actions["goto_fresh"] = function() { viewfeed({feed: -3}); - }; - hotkey_actions["goto_marked"] = function() { + }; + hotkey_actions["goto_marked"] = function() { viewfeed({feed: -1}); - }; - hotkey_actions["goto_published"] = function() { + }; + hotkey_actions["goto_published"] = function() { viewfeed({feed: -2}); - }; - hotkey_actions["goto_tagcloud"] = function() { + }; + hotkey_actions["goto_tagcloud"] = function() { displayDlg(__("Tag cloud"), "printTagCloud"); - }; - hotkey_actions["goto_prefs"] = function() { + }; + hotkey_actions["goto_prefs"] = function() { gotoPreferences(); - }; - hotkey_actions["select_article_cursor"] = function() { + }; + hotkey_actions["select_article_cursor"] = function() { var id = getArticleUnderPointer(); if (id) { var row = $("RROW-" + id); @@ -494,25 +498,25 @@ function init() { } } } - }; - hotkey_actions["create_label"] = function() { + }; + hotkey_actions["create_label"] = function() { addLabel(); - }; - hotkey_actions["create_filter"] = function() { + }; + hotkey_actions["create_filter"] = function() { quickAddFilter(); - }; - hotkey_actions["collapse_sidebar"] = function() { + }; + hotkey_actions["collapse_sidebar"] = function() { collapse_feedlist(); - }; - hotkey_actions["toggle_embed_original"] = function() { + }; + hotkey_actions["toggle_embed_original"] = function() { if (typeof embedOriginalArticle != "undefined") { if (getActiveArticleId()) embedOriginalArticle(getActiveArticleId()); } else { alert(__("Please enable embed_original plugin first.")); } - }; - hotkey_actions["toggle_widescreen"] = function() { + }; + hotkey_actions["toggle_widescreen"] = function() { if (!isCdmMode()) { _widescreen_mode = !_widescreen_mode; @@ -524,11 +528,11 @@ function init() { } else { alert(__("Widescreen is not available in combined mode.")); } - }; - hotkey_actions["help_dialog"] = function() { + }; + hotkey_actions["help_dialog"] = function() { helpDialog("main"); - }; - hotkey_actions["toggle_combined_mode"] = function() { + }; + hotkey_actions["toggle_combined_mode"] = function() { notify_progress("Loading, please wait..."); var value = isCdmMode() ? "false" : "true"; @@ -538,14 +542,14 @@ function init() { parameters: query, onComplete: function(transport) { setInitParam("combined_display_mode", - !getInitParam("combined_display_mode")); + !getInitParam("combined_display_mode")); closeArticlePanel(); viewCurrentFeed(); - } }); - }; - hotkey_actions["toggle_cdm_expanded"] = function() { + } }); + }; + hotkey_actions["toggle_cdm_expanded"] = function() { notify_progress("Loading, please wait..."); var value = getInitParam("cdm_expanded") ? "false" : "true"; @@ -557,8 +561,9 @@ function init() { setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); viewCurrentFeed(); } }); - }; + }; + }); } catch (e) { exception_error("init", e); @@ -568,7 +573,11 @@ function init() { function init_second_stage() { try { - dojo.addOnLoad(function() { + Event.observe(window, 'resize', function() { + dijit.byId("main").resize(); + }); + + //dojo.addOnLoad(function() { updateFeedList(); closeArticlePanel(); @@ -594,7 +603,7 @@ function init_second_stage() { } }); - }); + //}); delCookie("ttrss_test"); diff --git a/plugins/af_zz_noautoplay/init.js b/plugins/af_zz_noautoplay/init.js index 9b7bf0077..3cf3a381c 100644 --- a/plugins/af_zz_noautoplay/init.js +++ b/plugins/af_zz_noautoplay/init.js @@ -1,40 +1,43 @@ -dojo.addOnLoad(function() { - PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { - if (row) { - console.log("af_zz_noautoplay!"); - console.log(row); - - var videos = row.getElementsByTagName("video"); - console.log(row.innerHTML); - - for (i = 0; i < videos.length; i++) { - - videos[i].removeAttribute("autoplay"); - videos[i].pause(); - videos[i].onclick = function() { - this.paused ? this.play() : this.pause(); +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { + dojo.addOnLoad(function () { + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function (row) { + if (row) { + console.log("af_zz_noautoplay!"); + console.log(row); + + var videos = row.getElementsByTagName("video"); + console.log(row.innerHTML); + + for (i = 0; i < videos.length; i++) { + + videos[i].removeAttribute("autoplay"); + videos[i].pause(); + videos[i].onclick = function () { + this.paused ? this.play() : this.pause(); + } } } - } - return true; - }); + return true; + }); - PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, function(row) { - if (row) { - var videos = row.getElementsByTagName("video"); + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED, function (row) { + if (row) { + var videos = row.getElementsByTagName("video"); - for (i = 0; i < videos.length; i++) { - videos[i].removeAttribute("autoplay"); - videos[i].pause(); - videos[i].onclick = function() { - this.paused ? this.play() : this.pause(); + for (i = 0; i < videos.length; i++) { + videos[i].removeAttribute("autoplay"); + videos[i].pause(); + videos[i].onclick = function () { + this.paused ? this.play() : this.pause(); + } } + } - } + return true; + }); - return true; }); }); \ No newline at end of file diff --git a/plugins/shorten_expanded/init.js b/plugins/shorten_expanded/init.js index 5e9e84aec..899f8a54d 100644 --- a/plugins/shorten_expanded/init.js +++ b/plugins/shorten_expanded/init.js @@ -22,26 +22,30 @@ function expandSizeWrapper(id) { } -dojo.addOnLoad(function() { - PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { - if (getInitParam('cdm_expanded')) { +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { - window.setTimeout(function() { - if (row) { - if (row.offsetHeight >= _shorten_expanded_threshold * window.innerHeight) { - var content = row.select(".cdmContentInner")[0]; + dojo.addOnLoad(function() { + PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { + if (getInitParam('cdm_expanded')) { - if (content) { - content.innerHTML = "
" + - content.innerHTML + "
"; + window.setTimeout(function() { + if (row) { + if (row.offsetHeight >= _shorten_expanded_threshold * window.innerHeight) { + var content = row.select(".cdmContentInner")[0]; + if (content) { + content.innerHTML = "
" + + content.innerHTML + "
"; + + } } } - } - }, 150); - } + }, 150); + } - return true; + return true; + }); }); + }); -- cgit v1.2.3 From 0dbc20a8d48c58a180384a6a1047311c99545e48 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Aug 2016 11:48:09 +0300 Subject: load dijit properly, duh --- js/tt-rss.js | 749 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 377 insertions(+), 372 deletions(-) diff --git a/js/tt-rss.js b/js/tt-rss.js index 776c5d02b..e5e7a848f 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -216,352 +216,72 @@ function genericSanityCheck() { function init() { try { - require(['dojo/_base/kernel', 'dojo/ready', 'dojo/parser', 'dojo/_base/loader'], function(dojo, ready, parser) { - - //dojo.registerModulePath("fox", "../../js/"); - - dojo.require("fox.FeedTree"); - - dojo.require("dijit.ColorPalette"); - dojo.require("dijit.Dialog"); - dojo.require("dijit.form.Button"); - dojo.require("dijit.form.ComboButton"); - dojo.require("dijit.form.CheckBox"); - dojo.require("dijit.form.DropDownButton"); - dojo.require("dijit.form.FilteringSelect"); - dojo.require("dijit.form.Form"); - dojo.require("dijit.form.RadioButton"); - dojo.require("dijit.form.Select"); - dojo.require("dijit.form.SimpleTextarea"); - dojo.require("dijit.form.TextBox"); - dojo.require("dijit.form.ComboBox"); - dojo.require("dijit.form.ValidationTextBox"); - dojo.require("dijit.InlineEditBox"); - dojo.require("dijit.layout.AccordionContainer"); - dojo.require("dijit.layout.BorderContainer"); - dojo.require("dijit.layout.ContentPane"); - dojo.require("dijit.layout.TabContainer"); - dojo.require("dijit.PopupMenuItem"); - dojo.require("dijit.Menu"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.Toolbar"); - dojo.require("dijit.Tree"); - dojo.require("dijit.tree.dndSource"); - dojo.require("dojo.data.ItemFileWriteStore"); - - dojo.parser.parse(); - - if (!genericSanityCheck()) - return false; - - loading_set_progress(30); - - var a = document.createElement('audio'); - - var hasAudio = !!a.canPlayType; - var hasSandbox = "sandbox" in document.createElement("iframe"); - var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); - var clientTzOffset = new Date().getTimezoneOffset() * 60; - - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio, - hasMp3: hasMp3, - clientTzOffset: clientTzOffset, - hasSandbox: hasSandbox}, - onComplete: function(transport) { - backend_sanity_check_callback(transport); - } }); - - hotkey_actions["next_feed"] = function() { - var rv = dijit.byId("feedTree").getNextFeed( - getActiveFeedId(), activeFeedIsCat()); - - if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) - }; - hotkey_actions["prev_feed"] = function() { - var rv = dijit.byId("feedTree").getPreviousFeed( - getActiveFeedId(), activeFeedIsCat()); - - if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) - }; - hotkey_actions["next_article"] = function() { - moveToPost('next'); - }; - hotkey_actions["prev_article"] = function() { - moveToPost('prev'); - }; - hotkey_actions["next_article_noscroll"] = function() { - moveToPost('next', true); - }; - hotkey_actions["prev_article_noscroll"] = function() { - moveToPost('prev', true); - }; - hotkey_actions["next_article_noexpand"] = function() { - moveToPost('next', true, true); - }; - hotkey_actions["prev_article_noexpand"] = function() { - moveToPost('prev', true, true); - }; - hotkey_actions["collapse_article"] = function() { - var id = getActiveArticleId(); - var elem = $("CICD-"+id); - - if (elem) { - if (elem.visible()) { - cdmCollapseArticle(null, id); - } - else { - cdmExpandArticle(id); - } - } - }; - hotkey_actions["toggle_expand"] = function() { - var id = getActiveArticleId(); - var elem = $("CICD-"+id); - - if (elem) { - if (elem.visible()) { - cdmCollapseArticle(null, id, false); - } - else { - cdmExpandArticle(id); - } - } - }; - hotkey_actions["search_dialog"] = function() { - search(); - }; - hotkey_actions["toggle_mark"] = function() { - selectionToggleMarked(undefined, false, true); - }; - hotkey_actions["toggle_publ"] = function() { - selectionTogglePublished(undefined, false, true); - }; - hotkey_actions["toggle_unread"] = function() { - selectionToggleUnread(undefined, false, true); - }; - hotkey_actions["edit_tags"] = function() { - var id = getActiveArticleId(); - if (id) { - editArticleTags(id); - }; - } - hotkey_actions["open_in_new_window"] = function() { - if (getActiveArticleId()) { - openArticleInNewWindow(getActiveArticleId()); - return; - } - }; - hotkey_actions["catchup_below"] = function() { - catchupRelativeToArticle(1); - }; - hotkey_actions["catchup_above"] = function() { - catchupRelativeToArticle(0); - }; - hotkey_actions["article_scroll_down"] = function() { - var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); - - scrollArticle(40); - }; - hotkey_actions["article_scroll_up"] = function() { - var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); - - scrollArticle(-40); - }; - hotkey_actions["close_article"] = function() { - if (isCdmMode()) { - if (!getInitParam("cdm_expanded")) { - cdmCollapseArticle(false, getActiveArticleId()); - } - } else { - closeArticlePanel(); - } - }; - hotkey_actions["email_article"] = function() { - if (typeof emailArticle != "undefined") { - emailArticle(); - } else if (typeof mailtoArticle != "undefined") { - mailtoArticle(); - } else { - alert(__("Please enable mail plugin first.")); - } - }; - hotkey_actions["select_all"] = function() { - selectArticles('all'); - }; - hotkey_actions["select_unread"] = function() { - selectArticles('unread'); - }; - hotkey_actions["select_marked"] = function() { - selectArticles('marked'); - }; - hotkey_actions["select_published"] = function() { - selectArticles('published'); - }; - hotkey_actions["select_invert"] = function() { - selectArticles('invert'); - }; - hotkey_actions["select_none"] = function() { - selectArticles('none'); - }; - hotkey_actions["feed_refresh"] = function() { - if (getActiveFeedId() != undefined) { - viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); - return; - } - }; - hotkey_actions["feed_unhide_read"] = function() { - toggleDispRead(); - }; - hotkey_actions["feed_subscribe"] = function() { - quickAddFeed(); - }; - hotkey_actions["feed_debug_update"] = function() { - if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { - window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + - "&csrf_token=" + getInitParam("csrf_token")); - } else { - alert("You can't debug this kind of feed."); - } - }; - - hotkey_actions["feed_debug_viewfeed"] = function() { - viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); - }; - - hotkey_actions["feed_edit"] = function() { - if (activeFeedIsCat()) - alert(__("You can't edit this kind of feed.")); - else - editFeed(getActiveFeedId()); - }; - hotkey_actions["feed_catchup"] = function() { - if (getActiveFeedId() != undefined) { - catchupCurrentFeed(); - return; - } - }; - hotkey_actions["feed_reverse"] = function() { - reverseHeadlineOrder(); - }; - hotkey_actions["feed_toggle_vgroup"] = function() { - var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; - - new Ajax.Request("backend.php", { - parameters: query_str, - onComplete: function(transport) { - viewCurrentFeed(); - } }); - - }; - hotkey_actions["catchup_all"] = function() { - catchupAllFeeds(); - }; - hotkey_actions["cat_toggle_collapse"] = function() { - if (activeFeedIsCat()) { - dijit.byId("feedTree").collapseCat(getActiveFeedId()); - return; - } - }; - hotkey_actions["goto_all"] = function() { - viewfeed({feed: -4}); - }; - hotkey_actions["goto_fresh"] = function() { - viewfeed({feed: -3}); - }; - hotkey_actions["goto_marked"] = function() { - viewfeed({feed: -1}); - }; - hotkey_actions["goto_published"] = function() { - viewfeed({feed: -2}); - }; - hotkey_actions["goto_tagcloud"] = function() { - displayDlg(__("Tag cloud"), "printTagCloud"); - }; - hotkey_actions["goto_prefs"] = function() { - gotoPreferences(); - }; - hotkey_actions["select_article_cursor"] = function() { - var id = getArticleUnderPointer(); - if (id) { - var row = $("RROW-" + id); - - if (row) { - var cb = dijit.getEnclosingWidget( - row.getElementsByClassName("rchk")[0]); - - if (cb) { - cb.attr("checked", !cb.attr("checked")); - toggleSelectRowById(cb, "RROW-" + id); - return false; - } - } - } - }; - hotkey_actions["create_label"] = function() { - addLabel(); - }; - hotkey_actions["create_filter"] = function() { - quickAddFilter(); - }; - hotkey_actions["collapse_sidebar"] = function() { - collapse_feedlist(); - }; - hotkey_actions["toggle_embed_original"] = function() { - if (typeof embedOriginalArticle != "undefined") { - if (getActiveArticleId()) - embedOriginalArticle(getActiveArticleId()); - } else { - alert(__("Please enable embed_original plugin first.")); - } - }; - hotkey_actions["toggle_widescreen"] = function() { - if (!isCdmMode()) { - _widescreen_mode = !_widescreen_mode; - - // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); - - switchPanelMode(_widescreen_mode); - } else { - alert(__("Widescreen is not available in combined mode.")); - } - }; - hotkey_actions["help_dialog"] = function() { - helpDialog("main"); - }; - hotkey_actions["toggle_combined_mode"] = function() { - notify_progress("Loading, please wait..."); - - var value = isCdmMode() ? "false" : "true"; - var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value; - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - setInitParam("combined_display_mode", - !getInitParam("combined_display_mode")); - - closeArticlePanel(); - viewCurrentFeed(); - - } }); - }; - hotkey_actions["toggle_cdm_expanded"] = function() { - notify_progress("Loading, please wait..."); - - var value = getInitParam("cdm_expanded") ? "false" : "true"; - var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value; - - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); - viewCurrentFeed(); - } }); - }; + //dojo.registerModulePath("fox", "../../js/"); + + require(['dojo/_base/kernel', + 'dojo/ready', + 'dojo/parser', + 'dojo/_base/loader', + "dijit/ProgressBar", + "dijit/ColorPalette", + "dijit/Dialog", + "dijit/form/Button", + "dijit/form/ComboButton", + "dijit/form/CheckBox", + "dijit/form/DropDownButton", + "dijit/form/FilteringSelect", + "dijit/form/Form", + "dijit/form/RadioButton", + "dijit/form/Select", + "dijit/form/SimpleTextarea", + "dijit/form/TextBox", + "dijit/form/ComboBox", + "dijit/form/ValidationTextBox", + "dijit/InlineEditBox", + "dijit/layout/AccordionContainer", + "dijit/layout/BorderContainer", + "dijit/layout/ContentPane", + "dijit/layout/TabContainer", + "dijit/PopupMenuItem", + "dijit/Menu", + "dijit/Toolbar", + "dijit/Tree", + "dijit/tree/dndSource", + "dijit/tree/ForestStoreModel", + "dojo/data/ItemFileWriteStore" ], function (dojo, ready, parser) { + + ready(function() { + + dojo.require("fox.FeedTree"); + + dojo.parser.parse(); + + if (!genericSanityCheck()) + return false; + + loading_set_progress(30); + + var a = document.createElement('audio'); + + var hasAudio = !!a.canPlayType; + var hasSandbox = "sandbox" in document.createElement("iframe"); + var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); + var clientTzOffset = new Date().getTimezoneOffset() * 60; + + init_hotkey_actions(); + + new Ajax.Request("backend.php", { + parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio, + hasMp3: hasMp3, + clientTzOffset: clientTzOffset, + hasSandbox: hasSandbox}, + onComplete: function(transport) { + backend_sanity_check_callback(transport); + } }); + + + }); + }); @@ -570,40 +290,325 @@ function init() { } } -function init_second_stage() { +function init_hotkey_actions() { + hotkey_actions["next_feed"] = function() { + var rv = dijit.byId("feedTree").getNextFeed( + getActiveFeedId(), activeFeedIsCat()); + + if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) + }; + hotkey_actions["prev_feed"] = function() { + var rv = dijit.byId("feedTree").getPreviousFeed( + getActiveFeedId(), activeFeedIsCat()); + + if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) + }; + hotkey_actions["next_article"] = function() { + moveToPost('next'); + }; + hotkey_actions["prev_article"] = function() { + moveToPost('prev'); + }; + hotkey_actions["next_article_noscroll"] = function() { + moveToPost('next', true); + }; + hotkey_actions["prev_article_noscroll"] = function() { + moveToPost('prev', true); + }; + hotkey_actions["next_article_noexpand"] = function() { + moveToPost('next', true, true); + }; + hotkey_actions["prev_article_noexpand"] = function() { + moveToPost('prev', true, true); + }; + hotkey_actions["collapse_article"] = function() { + var id = getActiveArticleId(); + var elem = $("CICD-"+id); + + if (elem) { + if (elem.visible()) { + cdmCollapseArticle(null, id); + } + else { + cdmExpandArticle(id); + } + } + }; + hotkey_actions["toggle_expand"] = function() { + var id = getActiveArticleId(); + var elem = $("CICD-"+id); + + if (elem) { + if (elem.visible()) { + cdmCollapseArticle(null, id, false); + } + else { + cdmExpandArticle(id); + } + } + }; + hotkey_actions["search_dialog"] = function() { + search(); + }; + hotkey_actions["toggle_mark"] = function() { + selectionToggleMarked(undefined, false, true); + }; + hotkey_actions["toggle_publ"] = function() { + selectionTogglePublished(undefined, false, true); + }; + hotkey_actions["toggle_unread"] = function() { + selectionToggleUnread(undefined, false, true); + }; + hotkey_actions["edit_tags"] = function() { + var id = getActiveArticleId(); + if (id) { + editArticleTags(id); + }; + } + hotkey_actions["open_in_new_window"] = function() { + if (getActiveArticleId()) { + openArticleInNewWindow(getActiveArticleId()); + return; + } + }; + hotkey_actions["catchup_below"] = function() { + catchupRelativeToArticle(1); + }; + hotkey_actions["catchup_above"] = function() { + catchupRelativeToArticle(0); + }; + hotkey_actions["article_scroll_down"] = function() { + var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); + + scrollArticle(40); + }; + hotkey_actions["article_scroll_up"] = function() { + var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame"); + + scrollArticle(-40); + }; + hotkey_actions["close_article"] = function() { + if (isCdmMode()) { + if (!getInitParam("cdm_expanded")) { + cdmCollapseArticle(false, getActiveArticleId()); + } + } else { + closeArticlePanel(); + } + }; + hotkey_actions["email_article"] = function() { + if (typeof emailArticle != "undefined") { + emailArticle(); + } else if (typeof mailtoArticle != "undefined") { + mailtoArticle(); + } else { + alert(__("Please enable mail plugin first.")); + } + }; + hotkey_actions["select_all"] = function() { + selectArticles('all'); + }; + hotkey_actions["select_unread"] = function() { + selectArticles('unread'); + }; + hotkey_actions["select_marked"] = function() { + selectArticles('marked'); + }; + hotkey_actions["select_published"] = function() { + selectArticles('published'); + }; + hotkey_actions["select_invert"] = function() { + selectArticles('invert'); + }; + hotkey_actions["select_none"] = function() { + selectArticles('none'); + }; + hotkey_actions["feed_refresh"] = function() { + if (getActiveFeedId() != undefined) { + viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); + return; + } + }; + hotkey_actions["feed_unhide_read"] = function() { + toggleDispRead(); + }; + hotkey_actions["feed_subscribe"] = function() { + quickAddFeed(); + }; + hotkey_actions["feed_debug_update"] = function() { + if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { + window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + + "&csrf_token=" + getInitParam("csrf_token")); + } else { + alert("You can't debug this kind of feed."); + } + }; - try { - Event.observe(window, 'resize', function() { - dijit.byId("main").resize(); - }); + hotkey_actions["feed_debug_viewfeed"] = function() { + viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); + }; - //dojo.addOnLoad(function() { - updateFeedList(); - closeArticlePanel(); + hotkey_actions["feed_edit"] = function() { + if (activeFeedIsCat()) + alert(__("You can't edit this kind of feed.")); + else + editFeed(getActiveFeedId()); + }; + hotkey_actions["feed_catchup"] = function() { + if (getActiveFeedId() != undefined) { + catchupCurrentFeed(); + return; + } + }; + hotkey_actions["feed_reverse"] = function() { + reverseHeadlineOrder(); + }; + hotkey_actions["feed_toggle_vgroup"] = function() { + var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; - if (parseInt(getCookie("ttrss_fh_width")) > 0) { - dijit.byId("feeds-holder").domNode.setStyle( - {width: getCookie("ttrss_fh_width") + "px" }); + new Ajax.Request("backend.php", { + parameters: query_str, + onComplete: function(transport) { + viewCurrentFeed(); + } }); + + }; + hotkey_actions["catchup_all"] = function() { + catchupAllFeeds(); + }; + hotkey_actions["cat_toggle_collapse"] = function() { + if (activeFeedIsCat()) { + dijit.byId("feedTree").collapseCat(getActiveFeedId()); + return; + } + }; + hotkey_actions["goto_all"] = function() { + viewfeed({feed: -4}); + }; + hotkey_actions["goto_fresh"] = function() { + viewfeed({feed: -3}); + }; + hotkey_actions["goto_marked"] = function() { + viewfeed({feed: -1}); + }; + hotkey_actions["goto_published"] = function() { + viewfeed({feed: -2}); + }; + hotkey_actions["goto_tagcloud"] = function() { + displayDlg(__("Tag cloud"), "printTagCloud"); + }; + hotkey_actions["goto_prefs"] = function() { + gotoPreferences(); + }; + hotkey_actions["select_article_cursor"] = function() { + var id = getArticleUnderPointer(); + if (id) { + var row = $("RROW-" + id); + + if (row) { + var cb = dijit.getEnclosingWidget( + row.getElementsByClassName("rchk")[0]); + + if (cb) { + cb.attr("checked", !cb.attr("checked")); + toggleSelectRowById(cb, "RROW-" + id); + return false; + } } + } + }; + hotkey_actions["create_label"] = function() { + addLabel(); + }; + hotkey_actions["create_filter"] = function() { + quickAddFilter(); + }; + hotkey_actions["collapse_sidebar"] = function() { + collapse_feedlist(); + }; + hotkey_actions["toggle_embed_original"] = function() { + if (typeof embedOriginalArticle != "undefined") { + if (getActiveArticleId()) + embedOriginalArticle(getActiveArticleId()); + } else { + alert(__("Please enable embed_original plugin first.")); + } + }; + hotkey_actions["toggle_widescreen"] = function() { + if (!isCdmMode()) { + _widescreen_mode = !_widescreen_mode; + + // reset stored sizes because geometry changed + setCookie("ttrss_ci_width", 0); + setCookie("ttrss_ci_height", 0); + + switchPanelMode(_widescreen_mode); + } else { + alert(__("Widescreen is not available in combined mode.")); + } + }; + hotkey_actions["help_dialog"] = function() { + helpDialog("main"); + }; + hotkey_actions["toggle_combined_mode"] = function() { + notify_progress("Loading, please wait..."); + + var value = isCdmMode() ? "false" : "true"; + var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value; + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + setInitParam("combined_display_mode", + !getInitParam("combined_display_mode")); + + closeArticlePanel(); + viewCurrentFeed(); - dijit.byId("main").resize(); + } }); + }; + hotkey_actions["toggle_cdm_expanded"] = function() { + notify_progress("Loading, please wait..."); - var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize', - function (args) { - if (args && args.w >= 0) { - setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); - } - }); + var value = getInitParam("cdm_expanded") ? "false" : "true"; + var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value; - var tmph = 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")); - } - }); + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); + viewCurrentFeed(); + } }); + }; +} + +function init_second_stage() { - //}); + try { + updateFeedList(); + closeArticlePanel(); + + if (parseInt(getCookie("ttrss_fh_width")) > 0) { + dijit.byId("feeds-holder").domNode.setStyle( + {width: getCookie("ttrss_fh_width") + "px" }); + } + + dijit.byId("main").resize(); + + var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize', + function (args) { + if (args && args.w >= 0) { + setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); + } + }); + + var tmph = 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")); + } + }); delCookie("ttrss_test"); -- cgit v1.2.3 From fd539f280058f2606ba6a59403287b824b6fd195 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Aug 2016 12:22:30 +0300 Subject: prefs: use dojo asynchronously --- js/prefs.js | 119 +++++++++++++++++++++++++++++++----------------------------- prefs.php | 17 ++++++++- 2 files changed, 77 insertions(+), 59 deletions(-) diff --git a/js/prefs.js b/js/prefs.js index ddcdbe351..34d595a7d 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -889,22 +889,20 @@ function init_second_stage() { loading_set_progress(50); notify(""); - dojo.addOnLoad(function() { - var tab = getURLParam('tab'); + var tab = getURLParam('tab'); - if (tab) { - tab = dijit.byId(tab + "Tab"); - if (tab) dijit.byId("pref-tabs").selectChild(tab); - } + if (tab) { + tab = dijit.byId(tab + "Tab"); + if (tab) dijit.byId("pref-tabs").selectChild(tab); + } - var method = getURLParam('method'); + var method = getURLParam('method'); - if (method == 'editFeed') { - var param = getURLParam('methodparam'); + if (method == 'editFeed') { + var param = getURLParam('methodparam'); - window.setTimeout('editFeed(' + param + ')', 100); - } - }); + window.setTimeout('editFeed(' + param + ')', 100); + } setTimeout("hotkey_prefix_timeout()", 5*1000); @@ -916,53 +914,58 @@ function init_second_stage() { function init() { try { - dojo.registerModulePath("lib", ".."); - dojo.registerModulePath("fox", "../../js/"); - - dojo.require("dijit.ColorPalette"); - dojo.require("dijit.Dialog"); - dojo.require("dijit.form.Button"); - dojo.require("dijit.form.CheckBox"); - dojo.require("dijit.form.DropDownButton"); - dojo.require("dijit.form.FilteringSelect"); - dojo.require("dijit.form.Form"); - dojo.require("dijit.form.RadioButton"); - dojo.require("dijit.form.Select"); - dojo.require("dijit.form.SimpleTextarea"); - dojo.require("dijit.form.TextBox"); - dojo.require("dijit.form.ValidationTextBox"); - dojo.require("dijit.InlineEditBox"); - dojo.require("dijit.layout.AccordionContainer"); - dojo.require("dijit.layout.BorderContainer"); - dojo.require("dijit.layout.ContentPane"); - dojo.require("dijit.layout.TabContainer"); - dojo.require("dijit.Menu"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.ProgressBar"); - dojo.require("dijit.Toolbar"); - dojo.require("dijit.Tree"); - dojo.require("dijit.tree.dndSource"); - dojo.require("dojo.data.ItemFileWriteStore"); - - dojo.require("lib.CheckBoxTree"); - dojo.require("fox.PrefFeedTree"); - dojo.require("fox.PrefFilterTree"); - dojo.require("fox.PrefLabelTree"); - - dojo.parser.parse(); - - dojo.addOnLoad(function() { - loading_set_progress(50); - - var clientTzOffset = new Date().getTimezoneOffset() * 60; - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "sanityCheck", - clientTzOffset: clientTzOffset }, - onComplete: function(transport) { - backend_sanity_check_callback(transport); - } }); - }); + require(["dojo/_base/kernel", + "dojo/ready", + "dojo/parser", + "dojo/_base/loader", + "dijit/ColorPalette", + "dijit/Dialog", + "dijit/form/Button", + "dijit/form/CheckBox", + "dijit/form/DropDownButton", + "dijit/form/FilteringSelect", + "dijit/form/Form", + "dijit/form/RadioButton", + "dijit/form/ComboButton", + "dijit/form/Select", + "dijit/form/SimpleTextarea", + "dijit/form/TextBox", + "dijit/form/ValidationTextBox", + "dijit/InlineEditBox", + "dijit/layout/AccordionContainer", + "dijit/layout/AccordionPane", + "dijit/layout/BorderContainer", + "dijit/layout/ContentPane", + "dijit/layout/TabContainer", + "dijit/Menu", + "dijit/ProgressBar", + "dijit/Toolbar", + "dijit/Tree", + "dijit/tree/dndSource", + "dojo/data/ItemFileWriteStore"], function (dojo, ready, parser) { + + ready(function() { + + dojo.require("lib.CheckBoxTree"); + dojo.require("fox.PrefFeedTree"); + dojo.require("fox.PrefFilterTree"); + dojo.require("fox.PrefLabelTree"); + + parser.parse(); + + loading_set_progress(50); + + var clientTzOffset = new Date().getTimezoneOffset() * 60; + + new Ajax.Request("backend.php", { + parameters: {op: "rpc", method: "sanityCheck", + clientTzOffset: clientTzOffset }, + onComplete: function(transport) { + backend_sanity_check_callback(transport); + } }); + }); + }); } catch (e) { exception_error("init", e); diff --git a/prefs.php b/prefs.php index b20678abe..931373bad 100644 --- a/prefs.php +++ b/prefs.php @@ -54,6 +54,16 @@ + + get_plugins() as $n => $p) { if (method_exists($p, "get_prefs_js")) { + echo "try {"; echo JShrink\Minifier::minify($p->get_prefs_js()); + echo "} catch (e) { + console.warn('failed to initialize plugin JS: $n'); + console.warn(e); + }"; } } - print get_minified_js(array("../lib/CheckBoxTree","functions", "deprecated", "prefs", "PrefFeedTree", "PrefFilterTree", "PrefLabelTree")); + print get_minified_js(array("functions", "deprecated", "prefs")); init_js_translations(); ?> -- cgit v1.2.3 From f6d2787a8e139da6af412f87645402e0c193af01 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Aug 2016 12:22:55 +0300 Subject: plugins: use require() to hook into dojo --- plugins/af_zz_noautoplay/init.js | 4 +--- plugins/no_title_counters/init.js | 10 ++++++---- plugins/no_url_hashes/init.js | 11 ++++++++--- plugins/shorten_expanded/init.js | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/af_zz_noautoplay/init.js b/plugins/af_zz_noautoplay/init.js index 3cf3a381c..45dfc55ab 100644 --- a/plugins/af_zz_noautoplay/init.js +++ b/plugins/af_zz_noautoplay/init.js @@ -1,5 +1,5 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { - dojo.addOnLoad(function () { + ready(function () { PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function (row) { if (row) { console.log("af_zz_noautoplay!"); @@ -37,7 +37,5 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { return true; }); - }); - }); \ No newline at end of file diff --git a/plugins/no_title_counters/init.js b/plugins/no_title_counters/init.js index 9c16856a2..06edfb3ba 100644 --- a/plugins/no_title_counters/init.js +++ b/plugins/no_title_counters/init.js @@ -1,5 +1,7 @@ -dojo.addOnLoad(function() { - updateTitle = function() { - document.title = "Tiny Tiny RSS"; - }; +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { + ready(function () { + updateTitle = function () { + document.title = "Tiny Tiny RSS"; + }; + }); }); diff --git a/plugins/no_url_hashes/init.js b/plugins/no_url_hashes/init.js index a437a1f3e..fc4596724 100644 --- a/plugins/no_url_hashes/init.js +++ b/plugins/no_url_hashes/init.js @@ -1,4 +1,9 @@ -dojo.addOnLoad(function() { - hash_set = function() { }; - hash_get = function() { }; +require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { + ready(function () { + hash_set = function () { + }; + hash_get = function () { + }; + }); }); + diff --git a/plugins/shorten_expanded/init.js b/plugins/shorten_expanded/init.js index 899f8a54d..ffec6271d 100644 --- a/plugins/shorten_expanded/init.js +++ b/plugins/shorten_expanded/init.js @@ -24,7 +24,7 @@ function expandSizeWrapper(id) { require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { - dojo.addOnLoad(function() { + ready(function() { PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { if (getInitParam('cdm_expanded')) { -- cgit v1.2.3 From 546b419f52a741c150874fd233d91b88e88fa71a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Aug 2016 12:23:35 +0300 Subject: catch plugin JS errors --- index.php | 5 +++++ js/tt-rss.js | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 36734619f..6b27d9042 100644 --- a/index.php +++ b/index.php @@ -118,7 +118,12 @@ foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { if (method_exists($p, "get_js")) { + echo "try {"; echo JShrink\Minifier::minify($p->get_js()); + echo "} catch (e) { + console.warn('failed to initialize plugin JS: $n'); + console.warn(e); + }"; } } diff --git a/js/tt-rss.js b/js/tt-rss.js index e5e7a848f..78feb6ea3 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -218,10 +218,10 @@ function init() { try { //dojo.registerModulePath("fox", "../../js/"); - require(['dojo/_base/kernel', - 'dojo/ready', - 'dojo/parser', - 'dojo/_base/loader', + require(["dojo/_base/kernel", + "dojo/ready", + "dojo/parser", + "dojo/_base/loader", "dijit/ProgressBar", "dijit/ColorPalette", "dijit/Dialog", @@ -254,7 +254,7 @@ function init() { dojo.require("fox.FeedTree"); - dojo.parser.parse(); + parser.parse(); if (!genericSanityCheck()) return false; -- cgit v1.2.3 From d39a2f8005ba69f2940c8e3b547fbb18dc23bef0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Aug 2016 13:40:24 +0300 Subject: switch modules to new dojo definition format --- js/FeedTree.js | 1010 +++++++++++++++++++++++++------------------------- js/PrefFeedTree.js | 229 ++++++------ js/PrefFilterTree.js | 182 ++++----- js/PrefLabelTree.js | 62 ++-- js/prefs.js | 11 +- js/tt-rss.js | 5 +- lib/CheckBoxTree.js | 904 ++++++++++++++++++++++---------------------- 7 files changed, 1210 insertions(+), 1193 deletions(-) diff --git a/js/FeedTree.js b/js/FeedTree.js index c7c892b42..e4daec522 100644 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -1,589 +1,591 @@ -dojo.provide("fox.FeedTree"); -dojo.provide("fox.FeedStoreModel"); - -dojo.require("dijit.Tree"); -dojo.require("dijit.Menu"); - -dojo.declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, { - getItemsInCategory: function (id) { - if (!this.store._itemsByIdentity) return undefined; - - cat = this.store._itemsByIdentity['CAT:' + id]; - - if (cat && cat.items) - return cat.items; - else - return undefined; - - }, - getItemById: function(id) { - return this.store._itemsByIdentity[id]; - }, - getFeedValue: function(feed, is_cat, key) { - if (!this.store._itemsByIdentity) return undefined; - - if (is_cat) - treeItem = this.store._itemsByIdentity['CAT:' + feed]; - else - treeItem = this.store._itemsByIdentity['FEED:' + feed]; - - if (treeItem) - return this.store.getValue(treeItem, key); - }, - getFeedName: function(feed, is_cat) { - return this.getFeedValue(feed, is_cat, 'name'); - }, - getFeedUnread: function(feed, is_cat) { - var unread = parseInt(this.getFeedValue(feed, is_cat, 'unread')); - return (isNaN(unread)) ? 0 : unread; - }, - setFeedUnread: function(feed, is_cat, unread) { - return this.setFeedValue(feed, is_cat, 'unread', parseInt(unread)); - }, - setFeedValue: function(feed, is_cat, key, value) { - if (!value) value = ''; - if (!this.store._itemsByIdentity) return undefined; - - if (is_cat) - treeItem = this.store._itemsByIdentity['CAT:' + feed]; - else - treeItem = this.store._itemsByIdentity['FEED:' + feed]; - - if (treeItem) - return this.store.setValue(treeItem, key, value); - }, - getNextUnreadFeed: function (feed, is_cat) { - if (!this.store._itemsByIdentity) - return null; +require(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare) { + + return declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, { + getItemsInCategory: function (id) { + if (!this.store._itemsByIdentity) return undefined; + + cat = this.store._itemsByIdentity['CAT:' + id]; + + if (cat && cat.items) + return cat.items; + else + return undefined; + + }, + getItemById: function (id) { + return this.store._itemsByIdentity[id]; + }, + getFeedValue: function (feed, is_cat, key) { + if (!this.store._itemsByIdentity) return undefined; + + if (is_cat) + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + else + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + + if (treeItem) + return this.store.getValue(treeItem, key); + }, + getFeedName: function (feed, is_cat) { + return this.getFeedValue(feed, is_cat, 'name'); + }, + getFeedUnread: function (feed, is_cat) { + var unread = parseInt(this.getFeedValue(feed, is_cat, 'unread')); + return (isNaN(unread)) ? 0 : unread; + }, + setFeedUnread: function (feed, is_cat, unread) { + return this.setFeedValue(feed, is_cat, 'unread', parseInt(unread)); + }, + setFeedValue: function (feed, is_cat, key, value) { + if (!value) value = ''; + if (!this.store._itemsByIdentity) return undefined; + + if (is_cat) + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + else + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + + if (treeItem) + return this.store.setValue(treeItem, key, value); + }, + getNextUnreadFeed: function (feed, is_cat) { + if (!this.store._itemsByIdentity) + return null; - if (is_cat) { - treeItem = this.store._itemsByIdentity['CAT:' + feed]; - } else { - treeItem = this.store._itemsByIdentity['FEED:' + feed]; - } + if (is_cat) { + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + } else { + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + } - items = this.store._arrayOfAllItems; + items = this.store._arrayOfAllItems; - for (var i = 0; i < items.length; i++) { - if (items[i] == treeItem) { + for (var i = 0; i < items.length; i++) { + if (items[i] == treeItem) { - for (var j = i+1; j < items.length; j++) { - var unread = this.store.getValue(items[j], 'unread'); - var id = this.store.getValue(items[j], 'id'); + for (var j = i + 1; j < items.length; j++) { + var unread = this.store.getValue(items[j], 'unread'); + var id = this.store.getValue(items[j], 'id'); - if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) { - if( !is_cat || ! (this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed) ) return items[j]; + if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) { + if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j]; + } } - } - for (var j = 0; j < i; j++) { - var unread = this.store.getValue(items[j], 'unread'); - var id = this.store.getValue(items[j], 'id'); + for (var j = 0; j < i; j++) { + var unread = this.store.getValue(items[j], 'unread'); + var id = this.store.getValue(items[j], 'id'); - if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) { - if( !is_cat || ! (this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed) ) return items[j]; + if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) { + if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j]; + } } } } - } - - return null; - }, - hasCats: function() { - if (this.store && this.store._itemsByIdentity) - return this.store._itemsByIdentity['CAT:-1'] != undefined; - else - return false; - }, + + return null; + }, + hasCats: function () { + if (this.store && this.store._itemsByIdentity) + return this.store._itemsByIdentity['CAT:-1'] != undefined; + else + return false; + }, + + }); }); -dojo.declare("fox.FeedTree", dijit.Tree, { - _onKeyPress: function(/* Event */ e) { - return; // Stop dijit.Tree from interpreting keystrokes - }, - _createTreeNode: function(args) { - var tnode = new dijit._TreeNode(args); +require(["dojo/_base/declare", "dijit/Tree", "dijit/Menu"], function (declare) { - if (args.item.icon && args.item.icon[0]) - tnode.iconNode.src = args.item.icon[0]; + return declare("fox.FeedTree", dijit.Tree, { + _onKeyPress: function(/* Event */ e) { + return; // Stop dijit.Tree from interpreting keystrokes + }, + _createTreeNode: function(args) { + var tnode = new dijit._TreeNode(args); - var id = args.item.id[0]; - var bare_id = parseInt(id.substr(id.indexOf(':')+1)); + if (args.item.icon && args.item.icon[0]) + tnode.iconNode.src = args.item.icon[0]; - if (bare_id < _label_base_index) { - var span = dojo.doc.createElement('span'); - var fg_color = args.item.fg_color[0]; - var bg_color = args.item.bg_color[0]; + var id = args.item.id[0]; + var bare_id = parseInt(id.substr(id.indexOf(':')+1)); - span.innerHTML = "α"; - span.className = 'labelColorIndicator'; - span.setStyle({ - color: fg_color, - backgroundColor: bg_color}); + if (bare_id < _label_base_index) { + var span = dojo.doc.createElement('span'); + var fg_color = args.item.fg_color[0]; + var bg_color = args.item.bg_color[0]; - dojo.place(span, tnode.iconNode, 'replace'); - } + span.innerHTML = "α"; + span.className = 'labelColorIndicator'; + span.setStyle({ + color: fg_color, + backgroundColor: bg_color}); - if (id.match("FEED:")) { - var menu = new dijit.Menu(); - menu.row_id = bare_id; + dojo.place(span, tnode.iconNode, 'replace'); + } - menu.addChild(new dijit.MenuItem({ - label: __("Mark as read"), - onClick: function() { - catchupFeed(this.getParent().row_id); - }})); + if (id.match("FEED:")) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; - if (bare_id > 0) { menu.addChild(new dijit.MenuItem({ - label: __("Edit feed"), + label: __("Mark as read"), onClick: function() { - editFeed(this.getParent().row_id, false); + catchupFeed(this.getParent().row_id); }})); - /* menu.addChild(new dijit.MenuItem({ - label: __("Update feed"), + if (bare_id > 0) { + menu.addChild(new dijit.MenuItem({ + label: __("Edit feed"), + onClick: function() { + editFeed(this.getParent().row_id, false); + }})); + + /* menu.addChild(new dijit.MenuItem({ + label: __("Update feed"), + onClick: function() { + heduleFeedUpdate(this.getParent().row_id, false); + }})); */ + } + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; + } + + if (id.match("CAT:") && bare_id >= 0) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + + menu.addChild(new dijit.MenuItem({ + label: __("Mark as read"), onClick: function() { - heduleFeedUpdate(this.getParent().row_id, false); - }})); */ + catchupFeed(this.getParent().row_id, true); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; } - menu.bindDomNode(tnode.domNode); - tnode._menu = menu; - } - - if (id.match("CAT:") && bare_id >= 0) { - var menu = new dijit.Menu(); - menu.row_id = bare_id; - - menu.addChild(new dijit.MenuItem({ - label: __("Mark as read"), - onClick: function() { - catchupFeed(this.getParent().row_id, true); - }})); - - menu.bindDomNode(tnode.domNode); - tnode._menu = menu; - } - - if (id.match("CAT:")) { - loading = dojo.doc.createElement('img'); - loading.className = 'loadingNode'; - loading.src = 'images/blank_icon.gif'; - dojo.place(loading, tnode.labelNode, 'after'); - tnode.loadingNode = loading; - } - - if (id.match("CAT:") && bare_id == -1) { - var menu = new dijit.Menu(); - menu.row_id = bare_id; - - menu.addChild(new dijit.MenuItem({ - label: __("Mark all feeds as read"), - onClick: function() { - catchupAllFeeds(); - }})); - - menu.bindDomNode(tnode.domNode); - tnode._menu = menu; - } - - ctr = dojo.doc.createElement('span'); - ctr.className = 'counterNode'; - ctr.innerHTML = args.item.unread > 0 ? args.item.unread : args.item.auxcounter; - - //args.item.unread > 0 ? ctr.addClassName("unread") : ctr.removeClassName("unread"); - - args.item.unread > 0 || args.item.auxcounter > 0 ? Element.show(ctr) : Element.hide(ctr); - - args.item.unread == 0 && args.item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux"); - - dojo.place(ctr, tnode.rowNode, 'first'); - tnode.counterNode = ctr; - - //tnode.labelNode.innerHTML = args.label; - return tnode; - }, - postCreate: function() { - this.connect(this.model, "onChange", "updateCounter"); - this.connect(this, "_expandNode", function() { - this.hideRead(getInitParam("hide_read_feeds"), getInitParam("hide_read_shows_special")); - }); - - this.inherited(arguments); - }, - updateCounter: function (item) { - var tree = this; - - //console.log("updateCounter: " + item.id[0] + " " + item.unread + " " + tree); - - var node = tree._itemNodesMap[item.id]; - - if (node) { - node = node[0]; - - if (node.counterNode) { - ctr = node.counterNode; - ctr.innerHTML = item.unread > 0 ? item.unread : item.auxcounter; - item.unread > 0 || item.auxcounter > 0 ? - Effect.Appear(ctr, {duration : 0.3, - queue: { position: 'end', scope: 'CAPPEAR-' + item.id, limit: 1 }}) : - Element.hide(ctr); + if (id.match("CAT:")) { + loading = dojo.doc.createElement('img'); + loading.className = 'loadingNode'; + loading.src = 'images/blank_icon.gif'; + dojo.place(loading, tnode.labelNode, 'after'); + tnode.loadingNode = loading; + } - item.unread == 0 && item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux"); + if (id.match("CAT:") && bare_id == -1) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + menu.addChild(new dijit.MenuItem({ + label: __("Mark all feeds as read"), + onClick: function() { + catchupAllFeeds(); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; } - } - - }, - getTooltip: function (item) { - if (item.updated) - return item.updated; - else - return ""; - }, - getIconClass: function (item, opened) { - return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; - }, - getLabelClass: function (item, opened) { - return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread"; - }, - getRowClass: function (item, opened) { - var rc = (!item.error || item.error == '') ? "dijitTreeRow" : - "dijitTreeRow Error"; - - if (item.unread > 0) rc += " Unread"; - - return rc; - }, - getLabel: function(item) { - var name = String(item.name); - - /* Horrible */ - name = name.replace(/"/g, "\""); - name = name.replace(/&/g, "&"); - name = name.replace(/—/g, "-"); - name = name.replace(/</g, "<"); - name = name.replace(/>/g, ">"); - - /* var label; - - if (item.unread > 0) { - label = name + " (" + item.unread + ")"; - } else { - label = name; - } */ - - return name; - }, - expandParentNodes: function(feed, is_cat, list) { - try { - for (var i = 0; i < list.length; i++) { - var id = String(list[i].id); - var item = this._itemNodesMap[id]; - - if (item) { - item = item[0]; - this._expandNode(item); + + ctr = dojo.doc.createElement('span'); + ctr.className = 'counterNode'; + ctr.innerHTML = args.item.unread > 0 ? args.item.unread : args.item.auxcounter; + + //args.item.unread > 0 ? ctr.addClassName("unread") : ctr.removeClassName("unread"); + + args.item.unread > 0 || args.item.auxcounter > 0 ? Element.show(ctr) : Element.hide(ctr); + + args.item.unread == 0 && args.item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux"); + + dojo.place(ctr, tnode.rowNode, 'first'); + tnode.counterNode = ctr; + + //tnode.labelNode.innerHTML = args.label; + return tnode; + }, + postCreate: function() { + this.connect(this.model, "onChange", "updateCounter"); + this.connect(this, "_expandNode", function() { + this.hideRead(getInitParam("hide_read_feeds"), getInitParam("hide_read_shows_special")); + }); + + this.inherited(arguments); + }, + updateCounter: function (item) { + var tree = this; + + //console.log("updateCounter: " + item.id[0] + " " + item.unread + " " + tree); + + var node = tree._itemNodesMap[item.id]; + + if (node) { + node = node[0]; + + if (node.counterNode) { + ctr = node.counterNode; + ctr.innerHTML = item.unread > 0 ? item.unread : item.auxcounter; + item.unread > 0 || item.auxcounter > 0 ? + Effect.Appear(ctr, {duration : 0.3, + queue: { position: 'end', scope: 'CAPPEAR-' + item.id, limit: 1 }}) : + Element.hide(ctr); + + item.unread == 0 && item.auxcounter > 0 ? ctr.addClassName("aux") : ctr.removeClassName("aux"); + } } - } catch (e) { - exception_error("expandParentNodes", e); - } - }, - findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) { - // expands all parents of specified feed to properly mark it as active - // my fav thing about frameworks is doing everything myself - try { - var test_id = is_cat ? 'CAT:' + feed : 'FEED:' + feed; - - if (!root) { - if (!this.model || !this.model.store) return false; - - var items = this.model.store._arrayOfTopLevelItems; - - for (var i = 0; i < items.length; i++) { - if (String(items[i].id) == test_id) { - this.expandParentNodes(feed, is_cat, parents); - } else { - this.findNodeParentsAndExpandThem(feed, is_cat, items[i], []); + + }, + getTooltip: function (item) { + if (item.updated) + return item.updated; + else + return ""; + }, + getIconClass: function (item, opened) { + return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; + }, + getLabelClass: function (item, opened) { + return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread"; + }, + getRowClass: function (item, opened) { + var rc = (!item.error || item.error == '') ? "dijitTreeRow" : + "dijitTreeRow Error"; + + if (item.unread > 0) rc += " Unread"; + + return rc; + }, + getLabel: function(item) { + var name = String(item.name); + + /* Horrible */ + name = name.replace(/"/g, "\""); + name = name.replace(/&/g, "&"); + name = name.replace(/—/g, "-"); + name = name.replace(/</g, "<"); + name = name.replace(/>/g, ">"); + + /* var label; + + if (item.unread > 0) { + label = name + " (" + item.unread + ")"; + } else { + label = name; + } */ + + return name; + }, + expandParentNodes: function(feed, is_cat, list) { + try { + for (var i = 0; i < list.length; i++) { + var id = String(list[i].id); + var item = this._itemNodesMap[id]; + + if (item) { + item = item[0]; + this._expandNode(item); } } - } else { - if (root.items) { - parents.push(root); + } catch (e) { + exception_error("expandParentNodes", e); + } + }, + findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) { + // expands all parents of specified feed to properly mark it as active + // my fav thing about frameworks is doing everything myself + try { + var test_id = is_cat ? 'CAT:' + feed : 'FEED:' + feed; + + if (!root) { + if (!this.model || !this.model.store) return false; - for (var i = 0; i < root.items.length; i++) { - if (String(root.items[i].id) == test_id) { + var items = this.model.store._arrayOfTopLevelItems; + + for (var i = 0; i < items.length; i++) { + if (String(items[i].id) == test_id) { this.expandParentNodes(feed, is_cat, parents); } else { - this.findNodeParentsAndExpandThem(feed, is_cat, root.items[i], parents.slice(0)); + this.findNodeParentsAndExpandThem(feed, is_cat, items[i], []); } } } else { - if (String(root.id) == test_id) { - this.expandParentNodes(feed, is_cat, parents.slice(0)); + if (root.items) { + parents.push(root); + + for (var i = 0; i < root.items.length; i++) { + if (String(root.items[i].id) == test_id) { + this.expandParentNodes(feed, is_cat, parents); + } else { + this.findNodeParentsAndExpandThem(feed, is_cat, root.items[i], parents.slice(0)); + } + } + } else { + if (String(root.id) == test_id) { + this.expandParentNodes(feed, is_cat, parents.slice(0)); + } } } + } catch (e) { + exception_error("findNodeParentsAndExpandThem", e); } - } catch (e) { - exception_error("findNodeParentsAndExpandThem", e); - } - }, - selectFeed: function(feed, is_cat) { - this.findNodeParentsAndExpandThem(feed, is_cat, false, false); - - if (is_cat) - treeNode = this._itemNodesMap['CAT:' + feed]; - else - treeNode = this._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - if (!is_cat) this._expandNode(treeNode); - this.set("selectedNodes", [treeNode]); - } - }, - setFeedIcon: function(feed, is_cat, src) { - if (is_cat) - treeNode = this._itemNodesMap['CAT:' + feed]; - else - treeNode = this._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - treeNode.iconNode.src = src; - return true; - } - return false; - }, - setFeedExpandoIcon: function(feed, is_cat, src) { - if (is_cat) - treeNode = this._itemNodesMap['CAT:' + feed]; - else - treeNode = this._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - if (treeNode.loadingNode) { - treeNode.loadingNode.src = src; - return true; - } else { - treeNode.expandoNode.src = src; - return true; - } - } - - return false; - }, - hasCats: function() { - return this.model.hasCats(); - }, - hideReadCat: function (cat, hide, show_special) { - if (this.hasCats()) { - var tree = this; + }, + selectFeed: function(feed, is_cat) { + this.findNodeParentsAndExpandThem(feed, is_cat, false, false); - if (cat && cat.items) { - var cat_unread = tree.hideReadFeeds(cat.items, hide, show_special); + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; + + if (treeNode) { + treeNode = treeNode[0]; + if (!is_cat) this._expandNode(treeNode); + this.set("selectedNodes", [treeNode]); + } + }, + setFeedIcon: function(feed, is_cat, src) { + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; - var id = String(cat.id); - var node = tree._itemNodesMap[id]; - var bare_id = parseInt(id.substr(id.indexOf(":")+1)); + if (treeNode) { + treeNode = treeNode[0]; + treeNode.iconNode.src = src; + return true; + } + return false; + }, + setFeedExpandoIcon: function(feed, is_cat, src) { + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; - if (node) { - var check_unread = tree.model.getFeedUnread(bare_id, true); + if (treeNode) { + treeNode = treeNode[0]; + if (treeNode.loadingNode) { + treeNode.loadingNode.src = src; + return true; + } else { + treeNode.expandoNode.src = src; + return true; + } + } - if (hide && cat_unread == 0 && check_unread == 0 && (id != "CAT:-1" || !show_special)) { - Effect.Fade(node[0].rowNode, {duration : 0.3, - queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); - } else { - Element.show(node[0].rowNode); - ++cat_unread; + return false; + }, + hasCats: function() { + return this.model.hasCats(); + }, + hideReadCat: function (cat, hide, show_special) { + if (this.hasCats()) { + var tree = this; + + if (cat && cat.items) { + var cat_unread = tree.hideReadFeeds(cat.items, hide, show_special); + + var id = String(cat.id); + var node = tree._itemNodesMap[id]; + var bare_id = parseInt(id.substr(id.indexOf(":")+1)); + + if (node) { + var check_unread = tree.model.getFeedUnread(bare_id, true); + + if (hide && cat_unread == 0 && check_unread == 0 && (id != "CAT:-1" || !show_special)) { + Effect.Fade(node[0].rowNode, {duration : 0.3, + queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); + } else { + Element.show(node[0].rowNode); + ++cat_unread; + } } } } - } - }, - hideRead: function (hide, show_special) { - if (this.hasCats()) { + }, + hideRead: function (hide, show_special) { + if (this.hasCats()) { + + var tree = this; + var cats = this.model.store._arrayOfTopLevelItems; + cats.each(function(cat) { + tree.hideReadCat(cat, hide, show_special); + }); + + } else { + this.hideReadFeeds(this.model.store._arrayOfTopLevelItems, hide, + show_special); + } + }, + hideReadFeeds: function (items, hide, show_special) { var tree = this; - var cats = this.model.store._arrayOfTopLevelItems; + var cat_unread = 0; - cats.each(function(cat) { - tree.hideReadCat(cat, hide, show_special); - }); + items.each(function(feed) { + var id = String(feed.id); - } else { - this.hideReadFeeds(this.model.store._arrayOfTopLevelItems, hide, - show_special); - } - }, - hideReadFeeds: function (items, hide, show_special) { - var tree = this; - var cat_unread = 0; - - items.each(function(feed) { - var id = String(feed.id); - - // it's a subcategory - if (feed.items) { - tree.hideReadCat(feed, hide, show_special); - } else { // it's a feed - var bare_id = parseInt(feed.bare_id);; - - var unread = feed.unread[0]; - var has_error = feed.error[0] != ''; - var node = tree._itemNodesMap[id]; - - if (node) { - if (hide && unread == 0 && !has_error && (bare_id > 0 || bare_id < _label_base_index || !show_special)) { - Effect.Fade(node[0].rowNode, {duration : 0.3, - queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); - } else { - Element.show(node[0].rowNode); - ++cat_unread; + // it's a subcategory + if (feed.items) { + tree.hideReadCat(feed, hide, show_special); + } else { // it's a feed + var bare_id = parseInt(feed.bare_id);; + + var unread = feed.unread[0]; + var has_error = feed.error[0] != ''; + var node = tree._itemNodesMap[id]; + + if (node) { + if (hide && unread == 0 && !has_error && (bare_id > 0 || bare_id < _label_base_index || !show_special)) { + Effect.Fade(node[0].rowNode, {duration : 0.3, + queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); + } else { + Element.show(node[0].rowNode); + ++cat_unread; + } } } - } - }); + }); - return cat_unread; - }, - collapseCat: function(id) { - if (!this.model.hasCats()) return; + return cat_unread; + }, + collapseCat: function(id) { + if (!this.model.hasCats()) return; - var tree = this; + var tree = this; - var node = tree._itemNodesMap['CAT:' + id][0]; - var item = tree.model.store._itemsByIdentity['CAT:' + id]; + var node = tree._itemNodesMap['CAT:' + id][0]; + var item = tree.model.store._itemsByIdentity['CAT:' + id]; - if (node && item) { - if (!node.isExpanded) - tree._expandNode(node); - else - tree._collapseNode(node); + if (node && item) { + if (!node.isExpanded) + tree._expandNode(node); + else + tree._collapseNode(node); - } - }, - getVisibleUnreadFeeds: function() { - var items = this.model.store._arrayOfAllItems; - var rv = []; + } + }, + getVisibleUnreadFeeds: function() { + var items = this.model.store._arrayOfAllItems; + var rv = []; - for (var i = 0; i < items.length; i++) { - var id = String(items[i].id); - var box = this._itemNodesMap[id]; + for (var i = 0; i < items.length; i++) { + var id = String(items[i].id); + var box = this._itemNodesMap[id]; - if (box) { - var row = box[0].rowNode; - var cat = false; + if (box) { + var row = box[0].rowNode; + var cat = false; - try { - cat = box[0].rowNode.parentNode.parentNode; - } catch (e) { } + try { + cat = box[0].rowNode.parentNode.parentNode; + } catch (e) { } - if (row) { - if (Element.visible(row) && (!cat || Element.visible(cat))) { - var feed_id = String(items[i].bare_id); - var is_cat = !id.match('FEED:'); - var unread = this.model.getFeedUnread(feed_id, is_cat); + if (row) { + if (Element.visible(row) && (!cat || Element.visible(cat))) { + var feed_id = String(items[i].bare_id); + var is_cat = !id.match('FEED:'); + var unread = this.model.getFeedUnread(feed_id, is_cat); - if (unread > 0) - rv.push([feed_id, is_cat]); + if (unread > 0) + rv.push([feed_id, is_cat]); + } } } } - } - - return rv; - }, - getNextFeed: function (feed, is_cat) { - if (is_cat) { - treeItem = this.model.store._itemsByIdentity['CAT:' + feed]; - } else { - treeItem = this.model.store._itemsByIdentity['FEED:' + feed]; - } - - items = this.model.store._arrayOfAllItems; - var item = items[0]; - - for (var i = 0; i < items.length; i++) { - if (items[i] == treeItem) { - - for (var j = i+1; j < items.length; j++) { - var id = String(items[j].id); - var box = this._itemNodesMap[id]; - - if (box) { - var row = box[0].rowNode; - var cat = box[0].rowNode.parentNode.parentNode; - - if (Element.visible(cat) && Element.visible(row)) { - item = items[j]; - break; + + return rv; + }, + getNextFeed: function (feed, is_cat) { + if (is_cat) { + treeItem = this.model.store._itemsByIdentity['CAT:' + feed]; + } else { + treeItem = this.model.store._itemsByIdentity['FEED:' + feed]; + } + + items = this.model.store._arrayOfAllItems; + var item = items[0]; + + for (var i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + + for (var j = i+1; j < items.length; j++) { + var id = String(items[j].id); + var box = this._itemNodesMap[id]; + + if (box) { + var row = box[0].rowNode; + var cat = box[0].rowNode.parentNode.parentNode; + + if (Element.visible(cat) && Element.visible(row)) { + item = items[j]; + break; + } } } + break; } - break; } - } - if (item) { - return [this.model.store.getValue(item, 'bare_id'), - !this.model.store.getValue(item, 'id').match('FEED:')]; - } else { - return false; - } - }, - getPreviousFeed: function (feed, is_cat) { - if (is_cat) { - treeItem = this.model.store._itemsByIdentity['CAT:' + feed]; - } else { - treeItem = this.model.store._itemsByIdentity['FEED:' + feed]; - } - - items = this.model.store._arrayOfAllItems; - var item = items[0] == treeItem ? items[items.length-1] : items[0]; - - for (var i = 0; i < items.length; i++) { - if (items[i] == treeItem) { - - for (var j = i-1; j > 0; j--) { - var id = String(items[j].id); - var box = this._itemNodesMap[id]; - - if (box) { - var row = box[0].rowNode; - var cat = box[0].rowNode.parentNode.parentNode; - - if (Element.visible(cat) && Element.visible(row)) { - item = items[j]; - break; + if (item) { + return [this.model.store.getValue(item, 'bare_id'), + !this.model.store.getValue(item, 'id').match('FEED:')]; + } else { + return false; + } + }, + getPreviousFeed: function (feed, is_cat) { + if (is_cat) { + treeItem = this.model.store._itemsByIdentity['CAT:' + feed]; + } else { + treeItem = this.model.store._itemsByIdentity['FEED:' + feed]; + } + + items = this.model.store._arrayOfAllItems; + var item = items[0] == treeItem ? items[items.length-1] : items[0]; + + for (var i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + + for (var j = i-1; j > 0; j--) { + var id = String(items[j].id); + var box = this._itemNodesMap[id]; + + if (box) { + var row = box[0].rowNode; + var cat = box[0].rowNode.parentNode.parentNode; + + if (Element.visible(cat) && Element.visible(row)) { + item = items[j]; + break; + } } - } + } + break; } - break; } - } - if (item) { - return [this.model.store.getValue(item, 'bare_id'), - !this.model.store.getValue(item, 'id').match('FEED:')]; - } else { - return false; - } + if (item) { + return [this.model.store.getValue(item, 'bare_id'), + !this.model.store.getValue(item, 'id').match('FEED:')]; + } else { + return false; + } - }, - getFeedCategory: function(feed) { - try { - return this.getNodesByItem(this.model.store. + }, + getFeedCategory: function(feed) { + try { + return this.getNodesByItem(this.model.store. _itemsByIdentity["FEED:" + feed])[0]. - getParent().item.bare_id[0]; + getParent().item.bare_id[0]; - } catch (e) { - return false; - } - }, + } catch (e) { + return false; + } + }, + }); }); + diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index bf21baa90..c3b0d75f0 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -1,125 +1,126 @@ -dojo.provide("fox.PrefFeedTree"); -dojo.provide("fox.PrefFeedStore"); +require(["dojo/_base/declare", "dojo/data/ItemFileWriteStore"], function (declare) { -dojo.require("lib.CheckBoxTree"); -dojo.require("dojo.data.ItemFileWriteStore"); + return declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, { -dojo.declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, { + _saveEverything: function(saveCompleteCallback, saveFailedCallback, + newFileContentString) { - _saveEverything: function(saveCompleteCallback, saveFailedCallback, - newFileContentString) { + dojo.xhrPost({ + url: "backend.php", + content: {op: "pref-feeds", method: "savefeedorder", + payload: newFileContentString}, + error: saveFailedCallback, + load: saveCompleteCallback}); + }, - dojo.xhrPost({ - url: "backend.php", - content: {op: "pref-feeds", method: "savefeedorder", - payload: newFileContentString}, - error: saveFailedCallback, - load: saveCompleteCallback}); - }, + }); }); -dojo.declare("fox.PrefFeedTree", lib.CheckBoxTree, { - _createTreeNode: function(args) { - var tnode = this.inherited(arguments); - - if (args.item.icon) - tnode.iconNode.src = args.item.icon[0]; - - var param = this.model.store.getValue(args.item, 'param'); - - if (param) { - param = dojo.doc.createElement('span'); - param.className = 'feedParam'; - param.innerHTML = args.item.param[0]; - //dojo.place(param, tnode.labelNode, 'after'); - dojo.place(param, tnode.rowNode, 'first'); - } - - var id = args.item.id[0]; - var bare_id = parseInt(id.substr(id.indexOf(':')+1)); - - if (id.match("CAT:") && bare_id > 0) { - var menu = new dijit.Menu(); - menu.row_id = bare_id; - menu.item = args.item; - - menu.addChild(new dijit.MenuItem({ - label: __("Edit category"), - onClick: function() { - editCat(this.getParent().row_id, this.getParent().item, null); - }})); - - - menu.addChild(new dijit.MenuItem({ - label: __("Remove category"), - onClick: function() { - removeCategory(this.getParent().row_id, this.getParent().item); - }})); - - menu.bindDomNode(tnode.domNode); - tnode._menu = menu; - } else if (id.match("FEED:")) { - var menu = new dijit.Menu(); - menu.row_id = bare_id; - menu.item = args.item; - - menu.addChild(new dijit.MenuItem({ - label: __("Edit feed"), - onClick: function() { - editFeed(this.getParent().row_id); - }})); - - menu.addChild(new dijit.MenuItem({ - label: __("Unsubscribe"), - onClick: function() { - unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); - }})); - - menu.bindDomNode(tnode.domNode); - tnode._menu = menu; - - } - - return tnode; - }, - onDndDrop: function() { - this.inherited(arguments); - this.tree.model.store.save(); - }, - getRowClass: function (item, opened) { - return (!item.error || item.error == '') ? "dijitTreeRow" : - "dijitTreeRow Error"; - }, - getIconClass: function (item, opened) { - return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; - }, - checkItemAcceptance: function(target, source, position) { - var item = dijit.getEnclosingWidget(target).item; - - // disable copying items - source.copyState = function() { return false; }; - - var source_item = false; - - source.forInSelectedItems(function(node) { - source_item = node.data.item; - }); - - if (!source_item || !item) return false; - - var id = this.tree.model.store.getValue(item, 'id'); - var source_id = source.tree.model.store.getValue(source_item, 'id'); - - //console.log(id + " " + position + " " + source_id); - - if (source_id.match("FEED:")) { - return ((id.match("CAT:") && position == "over") || +require(["dojo/_base/declare", "lib/CheckBoxTree"], function (declare) { + + return declare("fox.PrefFeedTree", lib.CheckBoxTree, { + _createTreeNode: function(args) { + var tnode = this.inherited(arguments); + + if (args.item.icon) + tnode.iconNode.src = args.item.icon[0]; + + var param = this.model.store.getValue(args.item, 'param'); + + if (param) { + param = dojo.doc.createElement('span'); + param.className = 'feedParam'; + param.innerHTML = args.item.param[0]; + //dojo.place(param, tnode.labelNode, 'after'); + dojo.place(param, tnode.rowNode, 'first'); + } + + var id = args.item.id[0]; + var bare_id = parseInt(id.substr(id.indexOf(':')+1)); + + if (id.match("CAT:") && bare_id > 0) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + menu.item = args.item; + + menu.addChild(new dijit.MenuItem({ + label: __("Edit category"), + onClick: function() { + editCat(this.getParent().row_id, this.getParent().item, null); + }})); + + + menu.addChild(new dijit.MenuItem({ + label: __("Remove category"), + onClick: function() { + removeCategory(this.getParent().row_id, this.getParent().item); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; + } else if (id.match("FEED:")) { + var menu = new dijit.Menu(); + menu.row_id = bare_id; + menu.item = args.item; + + menu.addChild(new dijit.MenuItem({ + label: __("Edit feed"), + onClick: function() { + editFeed(this.getParent().row_id); + }})); + + menu.addChild(new dijit.MenuItem({ + label: __("Unsubscribe"), + onClick: function() { + unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); + }})); + + menu.bindDomNode(tnode.domNode); + tnode._menu = menu; + + } + + return tnode; + }, + onDndDrop: function() { + this.inherited(arguments); + this.tree.model.store.save(); + }, + getRowClass: function (item, opened) { + return (!item.error || item.error == '') ? "dijitTreeRow" : + "dijitTreeRow Error"; + }, + getIconClass: function (item, opened) { + return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; + }, + checkItemAcceptance: function(target, source, position) { + var item = dijit.getEnclosingWidget(target).item; + + // disable copying items + source.copyState = function() { return false; }; + + var source_item = false; + + source.forInSelectedItems(function(node) { + source_item = node.data.item; + }); + + if (!source_item || !item) return false; + + var id = this.tree.model.store.getValue(item, 'id'); + var source_id = source.tree.model.store.getValue(source_item, 'id'); + + //console.log(id + " " + position + " " + source_id); + + if (source_id.match("FEED:")) { + return ((id.match("CAT:") && position == "over") || (id.match("FEED:") && position != "over")); - } else if (source_id.match("CAT:")) { - return ((id.match("CAT:") && !id.match("CAT:0")) || + } else if (source_id.match("CAT:")) { + return ((id.match("CAT:") && !id.match("CAT:0")) || (id.match("root") && position == "over")); - } - }, + } + }, + }); }); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index ba06bbef4..5e055646c 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -1,96 +1,102 @@ -dojo.provide("fox.PrefFilterTree"); +require(["dojo/_base/declare", "dojo/data/ItemFileWriteStore"], function (declare) { -dojo.require("lib.CheckBoxTree"); -dojo.require("dojo.data.ItemFileWriteStore"); + return declare("fox.PrefFilterStore", dojo.data.ItemFileWriteStore, { -dojo.declare("fox.PrefFilterStore", dojo.data.ItemFileWriteStore, { + _saveEverything: function (saveCompleteCallback, saveFailedCallback, + newFileContentString) { - _saveEverything: function(saveCompleteCallback, saveFailedCallback, - newFileContentString) { - - dojo.xhrPost({ - url: "backend.php", - content: {op: "pref-filters", method: "savefilterorder", - payload: newFileContentString}, - error: saveFailedCallback, - load: saveCompleteCallback}); - }, + dojo.xhrPost({ + url: "backend.php", + content: { + op: "pref-filters", method: "savefilterorder", + payload: newFileContentString + }, + error: saveFailedCallback, + load: saveCompleteCallback + }); + }, + }); }); -dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, { - _createTreeNode: function(args) { - var tnode = this.inherited(arguments); - - var enabled = this.model.store.getValue(args.item, 'enabled'); - var param = this.model.store.getValue(args.item, 'param'); - var rules = this.model.store.getValue(args.item, 'rules'); - - if (param) { - param = dojo.doc.createElement('span'); - param.className = (enabled != false) ? 'labelParam' : 'labelParam filterDisabled'; - param.innerHTML = args.item.param[0]; - dojo.place(param, tnode.rowNode, 'first'); - } - - if (rules) { - param = dojo.doc.createElement('span'); - param.className = 'filterRules'; - param.innerHTML = rules; - dojo.place(param, tnode.rowNode, 'next'); - } - - if (this.model.store.getValue(args.item, 'id') != 'root') { - var img = dojo.doc.createElement('img'); - img.src ='images/filter.png'; - img.className = 'markedPic'; - tnode._filterIconNode = img; - dojo.place(tnode._filterIconNode, tnode.labelNode, 'before'); - } - - return tnode; - }, - - getLabel: function(item) { - var label = item.name; - - var feed = this.model.store.getValue(item, 'feed'); - var inverse = this.model.store.getValue(item, 'inverse'); - - if (feed) - label += " (" + __("in") + " " + feed + ")"; - - if (inverse) - label += " (" + __("Inverse") + ")"; - -/* if (item.param) - label = "" + label + - "" + item.param[0]; */ - - return label; - }, - getIconClass: function (item, opened) { - return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; - }, - getLabelClass: function (item, opened) { - var enabled = this.model.store.getValue(item, 'enabled'); - return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength filterDisabled"; - }, - getRowClass: function (item, opened) { - return (!item.error || item.error == '') ? "dijitTreeRow" : - "dijitTreeRow Error"; - }, - checkItemAcceptance: function(target, source, position) { - var item = dijit.getEnclosingWidget(target).item; - - // disable copying items - source.copyState = function() { return false; }; - - return position != 'over'; - }, - onDndDrop: function() { - this.inherited(arguments); - this.tree.model.store.save(); - }, +require(["dojo/_base/declare", "lib/CheckBoxTree"], function (declare) { + + return declare("fox.PrefFilterTree", lib.CheckBoxTree, { + _createTreeNode: function(args) { + var tnode = this.inherited(arguments); + + var enabled = this.model.store.getValue(args.item, 'enabled'); + var param = this.model.store.getValue(args.item, 'param'); + var rules = this.model.store.getValue(args.item, 'rules'); + + if (param) { + param = dojo.doc.createElement('span'); + param.className = (enabled != false) ? 'labelParam' : 'labelParam filterDisabled'; + param.innerHTML = args.item.param[0]; + dojo.place(param, tnode.rowNode, 'first'); + } + + if (rules) { + param = dojo.doc.createElement('span'); + param.className = 'filterRules'; + param.innerHTML = rules; + dojo.place(param, tnode.rowNode, 'next'); + } + + if (this.model.store.getValue(args.item, 'id') != 'root') { + var img = dojo.doc.createElement('img'); + img.src ='images/filter.png'; + img.className = 'markedPic'; + tnode._filterIconNode = img; + dojo.place(tnode._filterIconNode, tnode.labelNode, 'before'); + } + + return tnode; + }, + + getLabel: function(item) { + var label = item.name; + + var feed = this.model.store.getValue(item, 'feed'); + var inverse = this.model.store.getValue(item, 'inverse'); + + if (feed) + label += " (" + __("in") + " " + feed + ")"; + + if (inverse) + label += " (" + __("Inverse") + ")"; + + /* if (item.param) + label = "" + label + + "" + item.param[0]; */ + + return label; + }, + getIconClass: function (item, opened) { + return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; + }, + getLabelClass: function (item, opened) { + var enabled = this.model.store.getValue(item, 'enabled'); + return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength filterDisabled"; + }, + getRowClass: function (item, opened) { + return (!item.error || item.error == '') ? "dijitTreeRow" : + "dijitTreeRow Error"; + }, + checkItemAcceptance: function(target, source, position) { + var item = dijit.getEnclosingWidget(target).item; + + // disable copying items + source.copyState = function() { return false; }; + + return position != 'over'; + }, + onDndDrop: function() { + this.inherited(arguments); + this.tree.model.store.save(); + }, + }); + }); + diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 2f7dc0f53..673fd19ad 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -1,43 +1,43 @@ -dojo.provide("fox.PrefLabelTree"); +require(["dojo/_base/declare", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare) { -dojo.require("lib.CheckBoxTree"); -dojo.require("dijit.form.DropDownButton"); + return declare("fox.PrefLabelTree", lib.CheckBoxTree, { + setNameById: function (id, name) { + var item = this.model.store._itemsByIdentity['LABEL:' + id]; -dojo.declare("fox.PrefLabelTree", lib.CheckBoxTree, { - setNameById: function (id, name) { - var item = this.model.store._itemsByIdentity['LABEL:' + id]; + if (item) + this.model.store.setValue(item, 'name', name); - if (item) - this.model.store.setValue(item, 'name', name); + }, + _createTreeNode: function(args) { + var tnode = this.inherited(arguments); - }, - _createTreeNode: function(args) { - var tnode = this.inherited(arguments); + var fg_color = this.model.store.getValue(args.item, 'fg_color'); + var bg_color = this.model.store.getValue(args.item, 'bg_color'); + var type = this.model.store.getValue(args.item, 'type'); + var bare_id = this.model.store.getValue(args.item, 'bare_id'); - var fg_color = this.model.store.getValue(args.item, 'fg_color'); - var bg_color = this.model.store.getValue(args.item, 'bg_color'); - var type = this.model.store.getValue(args.item, 'type'); - var bare_id = this.model.store.getValue(args.item, 'bare_id'); + if (type == 'label') { + var span = dojo.doc.createElement('span'); + span.innerHTML = 'α'; + span.className = 'labelColorIndicator'; + span.id = 'LICID-' + bare_id; - if (type == 'label') { - var span = dojo.doc.createElement('span'); - span.innerHTML = 'α'; - span.className = 'labelColorIndicator'; - span.id = 'LICID-' + bare_id; + span.setStyle({ + color: fg_color, + backgroundColor: bg_color}); - span.setStyle({ - color: fg_color, - backgroundColor: bg_color}); + tnode._labelIconNode = span; - tnode._labelIconNode = span; + dojo.place(tnode._labelIconNode, tnode.labelNode, 'before'); + } - dojo.place(tnode._labelIconNode, tnode.labelNode, 'before'); - } + return tnode; + }, + getIconClass: function (item, opened) { + return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; + }, + }); - return tnode; - }, - getIconClass: function (item, opened) { - return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; - }, }); + diff --git a/js/prefs.js b/js/prefs.js index 34d595a7d..fdbb51ec0 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -943,15 +943,12 @@ function init() { "dijit/Toolbar", "dijit/Tree", "dijit/tree/dndSource", - "dojo/data/ItemFileWriteStore"], function (dojo, ready, parser) { + "dojo/data/ItemFileWriteStore", + "fox/PrefFeedTree", + "fox/PrefFilterTree", + "fox/PrefLabelTree" ], function (dojo, ready, parser) { ready(function() { - - dojo.require("lib.CheckBoxTree"); - dojo.require("fox.PrefFeedTree"); - dojo.require("fox.PrefFilterTree"); - dojo.require("fox.PrefLabelTree"); - parser.parse(); loading_set_progress(50); diff --git a/js/tt-rss.js b/js/tt-rss.js index 78feb6ea3..1b84025d1 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -248,12 +248,11 @@ function init() { "dijit/Tree", "dijit/tree/dndSource", "dijit/tree/ForestStoreModel", - "dojo/data/ItemFileWriteStore" ], function (dojo, ready, parser) { + "dojo/data/ItemFileWriteStore", + "fox/FeedTree" ], function (dojo, ready, parser) { ready(function() { - dojo.require("fox.FeedTree"); - parser.parse(); if (!genericSanityCheck()) diff --git a/lib/CheckBoxTree.js b/lib/CheckBoxTree.js index 48cfbae9a..1684c7174 100644 --- a/lib/CheckBoxTree.js +++ b/lib/CheckBoxTree.js @@ -1,474 +1,486 @@ -dojo.provide("lib.CheckBoxTree"); -dojo.provide("lib.CheckBoxStoreModel"); +//dojo.provide("lib.CheckBoxTree"); +//dojo.provide("lib.CheckBoxStoreModel"); // THIS WIDGET IS BASED ON DOJO/DIJIT 1.4.0 AND WILL NOT WORK WITH PREVIOUS VERSIONS // // Release date: 02/05/2010 // -dojo.require("dijit.Tree"); -dojo.require("dijit.form.CheckBox"); - -dojo.declare( "lib.CheckBoxStoreModel", dijit.tree.TreeStoreModel, -{ - // checkboxAll: Boolean - // If true, every node in the tree will receive a checkbox regardless if the 'checkbox' attribute - // is specified in the dojo.data. - checkboxAll: true, - - // checkboxState: Boolean - // The default state applied to every checkbox unless otherwise specified in the dojo.data. - // (see also: checkboxIdent) - checkboxState: false, - - // checkboxRoot: Boolean - // If true, the root node will receive a checkbox eventhough it's not a true entry in the store. - // This attribute is independent of the showRoot attribute of the tree itself. If the tree - // attribute 'showRoot' is set to false to checkbox for the root will not show either. - checkboxRoot: false, - - // checkboxStrict: Boolean - // If true, a strict parent-child checkbox relation is maintained. For example, if all children - // are checked the parent will automatically be checked or if any of the children are unchecked - // the parent will be unchecked. - checkboxStrict: true, - - // checkboxIdent: String - // The attribute name (attribute of the dojo.data.item) that specifies that items checkbox initial - // state. Example: { name:'Egypt', type:'country', checkbox: true } - // If a dojo.data.item has no 'checkbox' attribute specified it will depend on the attribute - // 'checkboxAll' if one will be created automatically and if so what the initial state will be as - // specified by 'checkboxState'. - checkboxIdent: "checkbox", - - updateCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { - // summary: - // Update the checkbox state (true/false) for the item and the associated parent and - // child checkboxes if any. - // description: - // Update a single checkbox state (true/false) for the item and the associated parent - // and child checkboxes if any. This function is called from the tree if a user checked - // or unchecked a checkbox on the tree. The parent and child tree nodes are updated to - // maintain consistency if 'checkboxStrict' is set to true. - // storeItem: - // The item in the dojo.data.store whos checkbox state needs updating. - // newState: - // The new state of the checkbox: true or false - // example: - // | model.updateCheckboxState(item, true); - // - - this._setCheckboxState( storeItem, newState ); - //if( this.checkboxStrict ) { I don't need all this 1-1 stuff, only parent -> child (fox) - this._updateChildCheckbox( storeItem, newState ); - //this._updateParentCheckbox( storeItem, newState ); - //} - }, - setAllChecked: function(checked) { - var items = this.store._arrayOfAllItems; - this.setCheckboxState(items, checked); - }, - setCheckboxState: function(items, checked) { - for (var i = 0; i < items.length; i++) { - this._setCheckboxState(items[i], checked); - } - }, - getCheckedItems: function() { - var items = this.store._arrayOfAllItems; - var result = []; - - for (var i = 0; i < items.length; i++) { - if (this.store.getValue(items[i], 'checkbox')) - result.push(items[i]); - } - - return result; - }, - - getCheckboxState: function(/*dojo.data.Item*/ storeItem) { - // summary: - // Get the current checkbox state from the dojo.data.store. - // description: - // Get the current checkbox state from the dojo.data store. A checkbox can have three - // different states: true, false or undefined. Undefined in this context means no - // checkbox identifier (checkboxIdent) was found in the dojo.data store. Depending on - // the checkbox attributes as specified above the following will take place: - // a) If the current checkbox state is undefined and the checkbox attribute 'checkboxAll' or - // 'checkboxRoot' is true one will be created and the default state 'checkboxState' will - // be applied. - // b) If the current state is undefined and 'checkboxAll' is false the state undefined remains - // unchanged and is returned. This will prevent any tree node from creating a checkbox. - // - // storeItem: - // The item in the dojo.data.store whos checkbox state is returned. - // example: - // | var currState = model.getCheckboxState(item); - // - var currState = undefined; - - // Special handling required for the 'fake' root entry (the root is NOT a dojo.data.item). - // this stuff is only relevant for Forest store -fox -/* if ( storeItem == this.root ) { - if( typeof(storeItem.checkbox) == "undefined" ) { - this.root.checkbox = undefined; // create a new checbox reference as undefined. - if( this.checkboxRoot ) { - currState = this.root.checkbox = this.checkboxState; +//dojo.require("dijit.Tree"); +//dojo.require("dijit.form.CheckBox"); + +require(["dojo/_base/declare", "dijit/tree/TreeStoreModel"], function (declare) { + + return declare( "lib.CheckBoxStoreModel", dijit.tree.TreeStoreModel, + { + // checkboxAll: Boolean + // If true, every node in the tree will receive a checkbox regardless if the 'checkbox' attribute + // is specified in the dojo.data. + checkboxAll: true, + + // checkboxState: Boolean + // The default state applied to every checkbox unless otherwise specified in the dojo.data. + // (see also: checkboxIdent) + checkboxState: false, + + // checkboxRoot: Boolean + // If true, the root node will receive a checkbox eventhough it's not a true entry in the store. + // This attribute is independent of the showRoot attribute of the tree itself. If the tree + // attribute 'showRoot' is set to false to checkbox for the root will not show either. + checkboxRoot: false, + + // checkboxStrict: Boolean + // If true, a strict parent-child checkbox relation is maintained. For example, if all children + // are checked the parent will automatically be checked or if any of the children are unchecked + // the parent will be unchecked. + checkboxStrict: true, + + // checkboxIdent: String + // The attribute name (attribute of the dojo.data.item) that specifies that items checkbox initial + // state. Example: { name:'Egypt', type:'country', checkbox: true } + // If a dojo.data.item has no 'checkbox' attribute specified it will depend on the attribute + // 'checkboxAll' if one will be created automatically and if so what the initial state will be as + // specified by 'checkboxState'. + checkboxIdent: "checkbox", + + updateCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { + // summary: + // Update the checkbox state (true/false) for the item and the associated parent and + // child checkboxes if any. + // description: + // Update a single checkbox state (true/false) for the item and the associated parent + // and child checkboxes if any. This function is called from the tree if a user checked + // or unchecked a checkbox on the tree. The parent and child tree nodes are updated to + // maintain consistency if 'checkboxStrict' is set to true. + // storeItem: + // The item in the dojo.data.store whos checkbox state needs updating. + // newState: + // The new state of the checkbox: true or false + // example: + // | model.updateCheckboxState(item, true); + // + + this._setCheckboxState( storeItem, newState ); + //if( this.checkboxStrict ) { I don't need all this 1-1 stuff, only parent -> child (fox) + this._updateChildCheckbox( storeItem, newState ); + //this._updateParentCheckbox( storeItem, newState ); + //} + }, + setAllChecked: function(checked) { + var items = this.store._arrayOfAllItems; + this.setCheckboxState(items, checked); + }, + setCheckboxState: function(items, checked) { + for (var i = 0; i < items.length; i++) { + this._setCheckboxState(items[i], checked); } - } else { - currState = this.root.checkbox; - } - } else { // a valid dojo.store.item - currState = this.store.getValue(storeItem, this.checkboxIdent); - if( currState == undefined && this.checkboxAll) { - this._setCheckboxState( storeItem, this.checkboxState ); - currState = this.checkboxState; - } - } */ - - currState = this.store.getValue(storeItem, this.checkboxIdent); - if( currState == undefined && this.checkboxAll) { - this._setCheckboxState( storeItem, this.checkboxState ); - currState = this.checkboxState; - } - - return currState; // the current state of the checkbox (true/false or undefined) - }, - - _setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { - // summary: - // Set/update the checkbox state on the dojo.data store. - // description: - // Set/update the checkbox state on the dojo.data.store. Retreive the current - // state of the checkbox and validate if an update is required, this will keep - // update events to a minimum. On completion a 'onCheckboxChange' event is - // triggered. - // If the current state is undefined (ie: no checkbox attribute specified for - // this dojo.data.item) the 'checkboxAll' attribute is checked to see if one - // needs to be created. In case of the root the 'checkboxRoot' attribute is checked. - // NOTE: the store.setValue function will create the 'checkbox' attribute for the - // item if none exists. - // storeItem: - // The item in the dojo.data.store whos checkbox state is updated. - // newState: - // The new state of the checkbox: true or false - // example: - // | model.setCheckboxState(item, true); - // - var stateChanged = true; - - if( storeItem != this.root ) { - var currState = this.store.getValue(storeItem, this.checkboxIdent); - if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) { - this.store.setValue(storeItem, this.checkboxIdent, newState); - } else { - stateChanged = false; // No changes to the checkbox - } - } else { // Tree root instance - if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) { - this.root.checkbox = newState; - } else { - stateChanged = false; - } - } - if( stateChanged ) { // In case of any changes trigger the update event. - this.onCheckboxChange(storeItem); - } - return stateChanged; - }, - - _updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) { - // summary: - // Set all child checkboxes to true/false depending on the parent checkbox state. - // description: - // If a parent checkbox changes state, all child and grandchild checkboxes will be - // updated to reflect the change. For example, if the parent state is set to true, - // all child and grandchild checkboxes will receive that same 'true' state. - // If a child checkbox changes state and has multiple parent, all of its parents - // need to be re-evaluated. - // parentItem: - // The parent dojo.data.item whos child/grandchild checkboxes require updating. - // newState: - // The new state of the checkbox: true or false - // - - if( this.mayHaveChildren( parentItem )) { - this.getChildren( parentItem, dojo.hitch( this, - function( children ) { - dojo.forEach( children, function(child) { - if( this._setCheckboxState(child, newState) ) { - var parents = this._getParentsItem(child); - if( parents.length > 1 ) { - this._updateParentCheckbox( child, newState ); - } + }, + getCheckedItems: function() { + var items = this.store._arrayOfAllItems; + var result = []; + + for (var i = 0; i < items.length; i++) { + if (this.store.getValue(items[i], 'checkbox')) + result.push(items[i]); + } + + return result; + }, + + getCheckboxState: function(/*dojo.data.Item*/ storeItem) { + // summary: + // Get the current checkbox state from the dojo.data.store. + // description: + // Get the current checkbox state from the dojo.data store. A checkbox can have three + // different states: true, false or undefined. Undefined in this context means no + // checkbox identifier (checkboxIdent) was found in the dojo.data store. Depending on + // the checkbox attributes as specified above the following will take place: + // a) If the current checkbox state is undefined and the checkbox attribute 'checkboxAll' or + // 'checkboxRoot' is true one will be created and the default state 'checkboxState' will + // be applied. + // b) If the current state is undefined and 'checkboxAll' is false the state undefined remains + // unchanged and is returned. This will prevent any tree node from creating a checkbox. + // + // storeItem: + // The item in the dojo.data.store whos checkbox state is returned. + // example: + // | var currState = model.getCheckboxState(item); + // + var currState = undefined; + + // Special handling required for the 'fake' root entry (the root is NOT a dojo.data.item). + // this stuff is only relevant for Forest store -fox + /* if ( storeItem == this.root ) { + if( typeof(storeItem.checkbox) == "undefined" ) { + this.root.checkbox = undefined; // create a new checbox reference as undefined. + if( this.checkboxRoot ) { + currState = this.root.checkbox = this.checkboxState; + } + } else { + currState = this.root.checkbox; + } + } else { // a valid dojo.store.item + currState = this.store.getValue(storeItem, this.checkboxIdent); + if( currState == undefined && this.checkboxAll) { + this._setCheckboxState( storeItem, this.checkboxState ); + currState = this.checkboxState; + } + } */ + + currState = this.store.getValue(storeItem, this.checkboxIdent); + if( currState == undefined && this.checkboxAll) { + this._setCheckboxState( storeItem, this.checkboxState ); + currState = this.checkboxState; + } + + return currState; // the current state of the checkbox (true/false or undefined) + }, + + _setCheckboxState: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { + // summary: + // Set/update the checkbox state on the dojo.data store. + // description: + // Set/update the checkbox state on the dojo.data.store. Retreive the current + // state of the checkbox and validate if an update is required, this will keep + // update events to a minimum. On completion a 'onCheckboxChange' event is + // triggered. + // If the current state is undefined (ie: no checkbox attribute specified for + // this dojo.data.item) the 'checkboxAll' attribute is checked to see if one + // needs to be created. In case of the root the 'checkboxRoot' attribute is checked. + // NOTE: the store.setValue function will create the 'checkbox' attribute for the + // item if none exists. + // storeItem: + // The item in the dojo.data.store whos checkbox state is updated. + // newState: + // The new state of the checkbox: true or false + // example: + // | model.setCheckboxState(item, true); + // + var stateChanged = true; + + if( storeItem != this.root ) { + var currState = this.store.getValue(storeItem, this.checkboxIdent); + if( currState != newState && ( currState !== undefined || this.checkboxAll ) ) { + this.store.setValue(storeItem, this.checkboxIdent, newState); + } else { + stateChanged = false; // No changes to the checkbox + } + } else { // Tree root instance + if( this.root.checkbox != newState && ( this.root.checkbox !== undefined || this.checkboxRoot ) ) { + this.root.checkbox = newState; + } else { + stateChanged = false; + } + } + if( stateChanged ) { // In case of any changes trigger the update event. + this.onCheckboxChange(storeItem); + } + return stateChanged; + }, + + _updateChildCheckbox: function(/*dojo.data.Item*/ parentItem, /*Boolean*/ newState ) { + // summary: + // Set all child checkboxes to true/false depending on the parent checkbox state. + // description: + // If a parent checkbox changes state, all child and grandchild checkboxes will be + // updated to reflect the change. For example, if the parent state is set to true, + // all child and grandchild checkboxes will receive that same 'true' state. + // If a child checkbox changes state and has multiple parent, all of its parents + // need to be re-evaluated. + // parentItem: + // The parent dojo.data.item whos child/grandchild checkboxes require updating. + // newState: + // The new state of the checkbox: true or false + // + + if( this.mayHaveChildren( parentItem )) { + this.getChildren( parentItem, dojo.hitch( this, + function( children ) { + dojo.forEach( children, function(child) { + if( this._setCheckboxState(child, newState) ) { + var parents = this._getParentsItem(child); + if( parents.length > 1 ) { + this._updateParentCheckbox( child, newState ); + } + } + if( this.mayHaveChildren( child )) { + this._updateChildCheckbox( child, newState ); + } + }, this ); + }), + function(err) { + console.error(this, ": updating child checkboxes: ", err); } - if( this.mayHaveChildren( child )) { - this._updateChildCheckbox( child, newState ); + ); + } + }, + + _updateParentCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { + // summary: + // Update the parent checkbox state depending on the state of all child checkboxes. + // description: + // Update the parent checkbox state depending on the state of all child checkboxes. + // The parent checkbox automatically changes state if ALL child checkboxes are true + // or false. If, as a result, the parent checkbox changes state, we will check if + // its parent needs to be updated as well all the way upto the root. + // storeItem: + // The dojo.data.item whos parent checkboxes require updating. + // newState: + // The new state of the checkbox: true or false + // + var parents = this._getParentsItem(storeItem); + dojo.forEach( parents, function( parentItem ) { + if( newState ) { // new state = true (checked) + this.getChildren( parentItem, dojo.hitch( this, + function(siblings) { + var allChecked = true; + dojo.some( siblings, function(sibling) { + siblState = this.getCheckboxState(sibling); + if( siblState !== undefined && allChecked ) + allChecked = siblState; + return !(allChecked); + }, this ); + if( allChecked ) { + this._setCheckboxState( parentItem, true ); + this._updateParentCheckbox( parentItem, true ); + } + }), + function(err) { + console.error(this, ": updating parent checkboxes: ", err); + } + ); + } else { // new state = false (unchecked) + if( this._setCheckboxState( parentItem, false ) ) { + this._updateParentCheckbox( parentItem, false ); } - }, this ); - }), - function(err) { - console.error(this, ": updating child checkboxes: ", err); + } + }, this ); + }, + + _getParentsItem: function(/*dojo.data.Item*/ storeItem ) { + // summary: + // Get the parent(s) of a dojo.data item. + // description: + // Get the parent(s) of a dojo.data item. The '_reverseRefMap' entry of the item is + // used to identify the parent(s). A child will have a parent reference if the parent + // specified the '_reference' attribute. + // For example: children:[{_reference:'Mexico'}, {_reference:'Canada'}, ... + // storeItem: + // The dojo.data.item whos parent(s) will be returned. + // + var parents = []; + + if( storeItem != this.root ) { + var references = storeItem[this.store._reverseRefMap]; + for(itemId in references ) { + parents.push(this.store._itemsByIdentity[itemId]); + } + if (!parents.length) { + parents.push(this.root); + } } - ); - } - }, - - _updateParentCheckbox: function(/*dojo.data.Item*/ storeItem, /*Boolean*/ newState ) { - // summary: - // Update the parent checkbox state depending on the state of all child checkboxes. - // description: - // Update the parent checkbox state depending on the state of all child checkboxes. - // The parent checkbox automatically changes state if ALL child checkboxes are true - // or false. If, as a result, the parent checkbox changes state, we will check if - // its parent needs to be updated as well all the way upto the root. - // storeItem: - // The dojo.data.item whos parent checkboxes require updating. - // newState: - // The new state of the checkbox: true or false - // - var parents = this._getParentsItem(storeItem); - dojo.forEach( parents, function( parentItem ) { - if( newState ) { // new state = true (checked) - this.getChildren( parentItem, dojo.hitch( this, - function(siblings) { + return parents; // parent(s) of a dojo.data.item (Array of dojo.data.items) + }, + + validateData: function(/*dojo.data.Item*/ storeItem, /*thisObject*/ scope ) { + // summary: + // Validate/normalize the parent(s) checkbox data in the dojo.data store. + // description: + // Validate/normalize the parent-child checkbox relationship if the attribute + // 'checkboxStrict' is set to true. This function is called as part of the post + // creation of the Tree instance. All parent checkboxes are set to the appropriate + // state according to the actual state(s) of their children. + // This will potentionally overwrite whatever was specified for the parent in the + // dojo.data store. This will garantee the tree is in a consistent state after startup. + // storeItem: + // The element to start traversing the dojo.data.store, typically model.root + // scope: + // The scope to use when this method executes. + // example: + // | this.model.validateData(this.model.root, this.model); + // + if( !scope.checkboxStrict ) { + return; + } + scope.getChildren( storeItem, dojo.hitch( scope, + function(children) { var allChecked = true; - dojo.some( siblings, function(sibling) { - siblState = this.getCheckboxState(sibling); - if( siblState !== undefined && allChecked ) - allChecked = siblState; - return !(allChecked); - }, this ); - if( allChecked ) { - this._setCheckboxState( parentItem, true ); - this._updateParentCheckbox( parentItem, true ); + var childState; + dojo.forEach( children, function( child ) { + if( this.mayHaveChildren( child )) { + this.validateData( child, this ); + } + childState = this.getCheckboxState( child ); + if( childState !== undefined && allChecked ) + allChecked = childState; + }, this); + + if ( this._setCheckboxState( storeItem, allChecked) ) { + this._updateParentCheckbox( storeItem, allChecked); } }), function(err) { - console.error(this, ": updating parent checkboxes: ", err); + console.error(this, ": validating checkbox data: ", err); } ); - } else { // new state = false (unchecked) - if( this._setCheckboxState( parentItem, false ) ) { - this._updateParentCheckbox( parentItem, false ); - } - } - }, this ); - }, - - _getParentsItem: function(/*dojo.data.Item*/ storeItem ) { - // summary: - // Get the parent(s) of a dojo.data item. - // description: - // Get the parent(s) of a dojo.data item. The '_reverseRefMap' entry of the item is - // used to identify the parent(s). A child will have a parent reference if the parent - // specified the '_reference' attribute. - // For example: children:[{_reference:'Mexico'}, {_reference:'Canada'}, ... - // storeItem: - // The dojo.data.item whos parent(s) will be returned. - // - var parents = []; - - if( storeItem != this.root ) { - var references = storeItem[this.store._reverseRefMap]; - for(itemId in references ) { - parents.push(this.store._itemsByIdentity[itemId]); + }, + + onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) { + // summary: + // Callback whenever a checkbox state has changed state, so that + // the Tree can update the checkbox. This callback is generally + // triggered by the '_setCheckboxState' function. + // tags: + // callback } - if (!parents.length) { - parents.push(this.root); - } - } - return parents; // parent(s) of a dojo.data.item (Array of dojo.data.items) - }, - - validateData: function(/*dojo.data.Item*/ storeItem, /*thisObject*/ scope ) { - // summary: - // Validate/normalize the parent(s) checkbox data in the dojo.data store. - // description: - // Validate/normalize the parent-child checkbox relationship if the attribute - // 'checkboxStrict' is set to true. This function is called as part of the post - // creation of the Tree instance. All parent checkboxes are set to the appropriate - // state according to the actual state(s) of their children. - // This will potentionally overwrite whatever was specified for the parent in the - // dojo.data store. This will garantee the tree is in a consistent state after startup. - // storeItem: - // The element to start traversing the dojo.data.store, typically model.root - // scope: - // The scope to use when this method executes. - // example: - // | this.model.validateData(this.model.root, this.model); - // - if( !scope.checkboxStrict ) { - return; - } - scope.getChildren( storeItem, dojo.hitch( scope, - function(children) { - var allChecked = true; - var childState; - dojo.forEach( children, function( child ) { - if( this.mayHaveChildren( child )) { - this.validateData( child, this ); - } - childState = this.getCheckboxState( child ); - if( childState !== undefined && allChecked ) - allChecked = childState; - }, this); - if ( this._setCheckboxState( storeItem, allChecked) ) { - this._updateParentCheckbox( storeItem, allChecked); + }); + +}); + +require(["dojo/_base/declare", "dijit/Tree"], function (declare) { + + return declare("lib._CheckBoxTreeNode", dijit._TreeNode, + { + // _checkbox: [protected] dojo.doc.element + // Local reference to the dojo.doc.element of type 'checkbox' + _checkbox: null, + + _createCheckbox: function () { + // summary: + // Create a checkbox on the CheckBoxTreeNode + // description: + // Create a checkbox on the CheckBoxTreeNode. The checkbox is ONLY created if a + // valid reference was found in the dojo.data store or the attribute 'checkboxAll' + // is set to true. If the current state is 'undefined' no reference was found and + // 'checkboxAll' is set to false. + // Note: the attribute 'checkboxAll' is validated by the getCheckboxState function + // therefore no need to do that here. (see getCheckboxState for details). + // + var currState = this.tree.model.getCheckboxState(this.item); + if (currState !== undefined) { + this._checkbox = new dijit.form.CheckBox(); + //this._checkbox = dojo.doc.createElement('input'); + this._checkbox.type = 'checkbox'; + this._checkbox.attr('checked', currState); + dojo.place(this._checkbox.domNode, this.expandoNode, 'after'); } - }), - function(err) { - console.error(this, ": validating checkbox data: ", err); + }, + + postCreate: function () { + // summary: + // Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated. + // description: + // Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated. + this._createCheckbox(); + this.inherited(arguments); } - ); - }, - - onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) { - // summary: - // Callback whenever a checkbox state has changed state, so that - // the Tree can update the checkbox. This callback is generally - // triggered by the '_setCheckboxState' function. - // tags: - // callback - } + }); }); -dojo.declare( "lib._CheckBoxTreeNode", dijit._TreeNode, -{ - // _checkbox: [protected] dojo.doc.element - // Local reference to the dojo.doc.element of type 'checkbox' - _checkbox: null, - - _createCheckbox: function() { - // summary: - // Create a checkbox on the CheckBoxTreeNode - // description: - // Create a checkbox on the CheckBoxTreeNode. The checkbox is ONLY created if a - // valid reference was found in the dojo.data store or the attribute 'checkboxAll' - // is set to true. If the current state is 'undefined' no reference was found and - // 'checkboxAll' is set to false. - // Note: the attribute 'checkboxAll' is validated by the getCheckboxState function - // therefore no need to do that here. (see getCheckboxState for details). - // - var currState = this.tree.model.getCheckboxState( this.item ); - if( currState !== undefined ) { - this._checkbox = new dijit.form.CheckBox(); - //this._checkbox = dojo.doc.createElement('input'); - this._checkbox.type = 'checkbox'; - this._checkbox.attr('checked', currState); - dojo.place(this._checkbox.domNode, this.expandoNode, 'after'); - } - }, - - postCreate: function() { - // summary: - // Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated. - // description: - // Handle the creation of the checkbox after the CheckBoxTreeNode has been instanciated. - this._createCheckbox(); - this.inherited( arguments ); - } +require(["dojo/_base/declare", "dijit/Tree"], function (declare) { + + return declare( "lib.CheckBoxTree", dijit.Tree, + { + + onNodeChecked: function(/*dojo.data.Item*/ storeItem, /*treeNode*/ treeNode) { + // summary: + // Callback when a checkbox tree node is checked + // tags: + // callback + }, + + onNodeUnchecked: function(/*dojo.data.Item*/ storeItem, /* treeNode */ treeNode) { + // summary: + // Callback when a checkbox tree node is unchecked + // tags: + // callback + }, + + _onClick: function(/*TreeNode*/ nodeWidget, /*Event*/ e) { + // summary: + // Translates click events into commands for the controller to process + // description: + // the _onClick function is called whenever a 'click' is detected. This + // instance of _onClick only handles the click events associated with + // the checkbox whos DOM name is INPUT. + // + var domElement = e.target; + + // Only handle checkbox clicks here + if(domElement.type != 'checkbox') { + return this.inherited( arguments ); + } -}); + this._publish("execute", { item: nodeWidget.item, node: nodeWidget} ); + // Go tell the model to update the checkbox state -dojo.declare( "lib.CheckBoxTree", dijit.Tree, -{ - - onNodeChecked: function(/*dojo.data.Item*/ storeItem, /*treeNode*/ treeNode) { - // summary: - // Callback when a checkbox tree node is checked - // tags: - // callback - }, - - onNodeUnchecked: function(/*dojo.data.Item*/ storeItem, /* treeNode */ treeNode) { - // summary: - // Callback when a checkbox tree node is unchecked - // tags: - // callback - }, - - _onClick: function(/*TreeNode*/ nodeWidget, /*Event*/ e) { - // summary: - // Translates click events into commands for the controller to process - // description: - // the _onClick function is called whenever a 'click' is detected. This - // instance of _onClick only handles the click events associated with - // the checkbox whos DOM name is INPUT. - // - var domElement = e.target; - - // Only handle checkbox clicks here - if(domElement.type != 'checkbox') { - return this.inherited( arguments ); - } - - this._publish("execute", { item: nodeWidget.item, node: nodeWidget} ); - // Go tell the model to update the checkbox state - - this.model.updateCheckbox( nodeWidget.item, nodeWidget._checkbox.checked ); - // Generate some additional events - //this.onClick( nodeWidget.item, nodeWidget, e ); - if(nodeWidget._checkbox.checked) { - this.onNodeChecked( nodeWidget.item, nodeWidget); - } else { - this.onNodeUnchecked( nodeWidget.item, nodeWidget); - } - this.focusNode(nodeWidget); - }, - - _onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) { - // summary: - // Processes notification of a change to a checkbox state (triggered by the model). - // description: - // Whenever the model changes the state of a checkbox in the dojo.data.store it will - // trigger the 'onCheckboxChange' event allowing the Tree to make the same changes - // on the tree Node. There are several conditions why a tree node or checkbox does not - // exists: - // a) The node has not been created yet (the user has not expanded the tree node yet). - // b) The checkbox may be null if condition (a) exists or no 'checkbox' attribute was - // specified for the associated dojo.data.item and the attribute 'checkboxAll' is - // set to false. - // tags: - // callback - var model = this.model, - identity = model.getIdentity(storeItem), - nodes = this._itemNodesMap[identity]; - - // As of dijit.Tree 1.4 multiple references (parents) are supported, therefore we may have - // to update multiple nodes which are all associated with the same dojo.data.item. - if( nodes ) { - dojo.forEach( nodes, function(node) { - if( node._checkbox != null ) { - node._checkbox.attr('checked', this.model.getCheckboxState( storeItem )); + this.model.updateCheckbox( nodeWidget.item, nodeWidget._checkbox.checked ); + // Generate some additional events + //this.onClick( nodeWidget.item, nodeWidget, e ); + if(nodeWidget._checkbox.checked) { + this.onNodeChecked( nodeWidget.item, nodeWidget); + } else { + this.onNodeUnchecked( nodeWidget.item, nodeWidget); + } + this.focusNode(nodeWidget); + }, + + _onCheckboxChange: function(/*dojo.data.Item*/ storeItem ) { + // summary: + // Processes notification of a change to a checkbox state (triggered by the model). + // description: + // Whenever the model changes the state of a checkbox in the dojo.data.store it will + // trigger the 'onCheckboxChange' event allowing the Tree to make the same changes + // on the tree Node. There are several conditions why a tree node or checkbox does not + // exists: + // a) The node has not been created yet (the user has not expanded the tree node yet). + // b) The checkbox may be null if condition (a) exists or no 'checkbox' attribute was + // specified for the associated dojo.data.item and the attribute 'checkboxAll' is + // set to false. + // tags: + // callback + var model = this.model, + identity = model.getIdentity(storeItem), + nodes = this._itemNodesMap[identity]; + + // As of dijit.Tree 1.4 multiple references (parents) are supported, therefore we may have + // to update multiple nodes which are all associated with the same dojo.data.item. + if( nodes ) { + dojo.forEach( nodes, function(node) { + if( node._checkbox != null ) { + node._checkbox.attr('checked', this.model.getCheckboxState( storeItem )); + } + }, this ); } - }, this ); - } - }, - - postCreate: function() { - // summary: - // Handle any specifics related to the tree and model after the instanciation of the Tree. - // description: - // Validate if we have a 'write' store first. Subscribe to the 'onCheckboxChange' event - // (triggered by the model) and kickoff the initial checkbox data validation. - // - var store = this.model.store; - if(!store.getFeatures()['dojo.data.api.Write']){ - throw new Error("lib.CheckboxTree: store must support dojo.data.Write"); - } - this.connect(this.model, "onCheckboxChange", "_onCheckboxChange"); - this.model.validateData( this.model.root, this.model ); - this.inherited(arguments); - }, - - _createTreeNode: function( args ) { - // summary: - // Create a new CheckboxTreeNode instance. - // description: - // Create a new CheckboxTreeNode instance. - return new lib._CheckBoxTreeNode(args); - } + }, + + postCreate: function() { + // summary: + // Handle any specifics related to the tree and model after the instanciation of the Tree. + // description: + // Validate if we have a 'write' store first. Subscribe to the 'onCheckboxChange' event + // (triggered by the model) and kickoff the initial checkbox data validation. + // + var store = this.model.store; + if(!store.getFeatures()['dojo.data.api.Write']){ + throw new Error("lib.CheckboxTree: store must support dojo.data.Write"); + } + this.connect(this.model, "onCheckboxChange", "_onCheckboxChange"); + this.model.validateData( this.model.root, this.model ); + this.inherited(arguments); + }, + + _createTreeNode: function( args ) { + // summary: + // Create a new CheckboxTreeNode instance. + // description: + // Create a new CheckboxTreeNode instance. + return new lib._CheckBoxTreeNode(args); + } + + }); }); + -- cgit v1.2.3 From 5cbd1fe8e4d9a67b002a681ab6bc2bc3ab60c628 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Aug 2016 15:01:01 +0300 Subject: perform housekeeping tasks for plugins loaded in user-context only --- include/functions.php | 9 ++++++--- include/rssfuncs.php | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/functions.php b/include/functions.php index 3ccc09d75..3902ac45a 100755 --- a/include/functions.php +++ b/include/functions.php @@ -833,14 +833,17 @@ return $csrf_token == $_SESSION['csrf_token']; } - function load_user_plugins($owner_uid) { + function load_user_plugins($owner_uid, $pluginhost = false) { + + if (!$pluginhost) $pluginhost = PluginHost::getInstance(); + if ($owner_uid && SCHEMA_VERSION >= 100) { $plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); - PluginHost::getInstance()->load($plugins, PluginHost::KIND_USER, $owner_uid); + $pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid); if (get_schema_version() > 100) { - PluginHost::getInstance()->load_data(); + $pluginhost->load_data(); } } } diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 522e4bf22..cbd011e5c 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -179,6 +179,8 @@ $nf = 0; $bstarted = microtime(true); + $batch_owners = array(); + // For each feed, we call the feed update function. foreach ($feeds_to_update as $feed) { if($debug) _debug("Base feed: $feed"); @@ -204,6 +206,9 @@ while ($tline = db_fetch_assoc($tmp_result)) { if($debug) _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); + if (array_search($tline["owner_uid"], $batch_owners) === FALSE) + array_push($batch_owners, $tline["owner_uid"]); + $fstarted = microtime(true); $rss = update_rss_feed($tline["id"], true, false); _debug_suppress(false); @@ -220,6 +225,12 @@ microtime(true) - $bstarted, (microtime(true) - $bstarted) / $nf)); } + foreach ($batch_owners as $owner_uid) { + _debug("Running housekeeping tasks for user $owner_uid..."); + + housekeeping_user($owner_uid); + } + require_once "digest.php"; // Send feed digests by email if needed. @@ -1502,6 +1513,14 @@ _debug("Removed $frows (feeds) $crows (cats) orphaned counter cache entries."); } + function housekeeping_user($owner_uid) { + $tmph = new PluginHost(); + + load_user_plugins($owner_uid, $tmph); + + $tmph->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); + } + function housekeeping_common($debug) { expire_cached_files($debug); expire_lock_files($debug); @@ -1517,6 +1536,5 @@ //_debug("Cleaned $rc cached tags."); PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); - } ?> -- cgit v1.2.3 From 539f6ee6cd09057b779e35fc45c6a3a04f497286 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Aug 2016 09:43:22 +0300 Subject: update schema 128 to properly set ttrss_feeds.last_updated default value to NULL --- schema/versions/mysql/128.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schema/versions/mysql/128.sql b/schema/versions/mysql/128.sql index 0a4d7ab7c..281379bb0 100644 --- a/schema/versions/mysql/128.sql +++ b/schema/versions/mysql/128.sql @@ -1,5 +1,8 @@ BEGIN; +update ttrss_feeds set last_updated = NULL; +alter table ttrss_feeds modify column last_updated datetime DEFAULT NULL; + alter table ttrss_feeds add column feed_language varchar(100); update ttrss_feeds set feed_language = ''; alter table ttrss_feeds change feed_language feed_language varchar(100) not null; -- cgit v1.2.3 From a84fb943b4c5a030e215fa819e579ca4646cf617 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Aug 2016 17:54:27 +0300 Subject: pre-users: disallow renaming admin user --- classes/pref/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/pref/users.php b/classes/pref/users.php index a10404d0a..164935b23 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -37,7 +37,7 @@ class Pref_Users extends Handler_Protected { $access_level = $this->dbh->fetch_result($result, 0, "access_level"); $email = $this->dbh->fetch_result($result, 0, "email"); - $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : ""; + $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : ""; print "
".__("User")."
"; print "
"; -- cgit v1.2.3 From 1a322ff3dfb47a73f52f4076b9d73601999c573e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Aug 2016 18:14:22 +0300 Subject: import_export: better error message if upload failed --- include/functions2.php | 16 ++++++++++++++++ plugins/import_export/init.php | 43 +++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/include/functions2.php b/include/functions2.php index dceea507e..7e1171b7d 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -2449,4 +2449,20 @@ return $tmp; } + + function get_upload_error_message($code) { + + $errors = array( + 0 => __('There is no error, the file uploaded with success'), + 1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini'), + 2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), + 3 => __('The uploaded file was only partially uploaded'), + 4 => __('No file was uploaded'), + 6 => __('Missing a temporary folder'), + 7 => __('Failed to write file to disk.'), + 8 => __('A PHP extension stopped the file upload.'), + ); + + return $errors[$code]; + } ?> diff --git a/plugins/import_export/init.php b/plugins/import_export/init.php index 7c628909f..491216e06 100644 --- a/plugins/import_export/init.php +++ b/plugins/import_export/init.php @@ -425,34 +425,35 @@ class Import_Export extends Plugin implements IHandler { print "
"; if ($_FILES['export_file']['error'] != 0) { - print_error(T_sprintf("Upload failed with error code %d", - $_FILES['export_file']['error'])); - return; - } + print_error(T_sprintf("Upload failed with error code %d (%s)", + $_FILES['export_file']['error'], + get_upload_error_message($_FILES['export_file']['error']))); + } else { - $tmp_file = false; + $tmp_file = false; - if (is_uploaded_file($_FILES['export_file']['tmp_name'])) { - $tmp_file = tempnam(CACHE_DIR . '/upload', 'export'); + if (is_uploaded_file($_FILES['export_file']['tmp_name'])) { + $tmp_file = tempnam(CACHE_DIR . '/upload', 'export'); - $result = move_uploaded_file($_FILES['export_file']['tmp_name'], - $tmp_file); + $result = move_uploaded_file($_FILES['export_file']['tmp_name'], + $tmp_file); - if (!$result) { - print_error(__("Unable to move uploaded file.")); + if (!$result) { + print_error(__("Unable to move uploaded file.")); + return; + } + } else { + print_error(__('Error: please upload OPML file.')); return; } - } else { - print_error(__('Error: please upload OPML file.')); - return; - } - if (is_file($tmp_file)) { - $this->perform_data_import($tmp_file, $_SESSION['uid']); - unlink($tmp_file); - } else { - print_error(__('No file uploaded.')); - return; + if (is_file($tmp_file)) { + $this->perform_data_import($tmp_file, $_SESSION['uid']); + unlink($tmp_file); + } else { + print_error(__('No file uploaded.')); + return; + } } print "