Browse Source

rework dojo singleton modules to better work with phpstorm completion (ugh) - declare() is not needed there anyway
remove event.observe from login form (not needed)
load pluginhost via amd

Andrew Dolgov 1 year ago
parent
commit
84affc7b1d
14 changed files with 103 additions and 102 deletions
  1. 15 18
      include/login_form.php
  2. 0 1
      index.php
  3. 17 15
      js/Article.js
  4. 8 6
      js/ArticleCache.js
  5. 4 2
      js/CommonDialogs.js
  6. 4 2
      js/CommonFilters.js
  7. 4 2
      js/Feeds.js
  8. 38 36
      js/Headlines.js
  9. 1 1
      js/PluginHost.js
  10. 4 2
      js/PrefHelpers.js
  11. 4 3
      js/PrefUsers.js
  12. 0 5
      js/prefs.js
  13. 3 8
      js/tt-rss.js
  14. 1 1
      register.php

+ 15 - 18
include/login_form.php

@@ -19,30 +19,27 @@
 
 	<script type="text/javascript">
 		require({cache:{}});
-		Event.observe(window, 'load', function() {
-			init();
-		});
 	</script>
 </head>
 
 <body class="claro ttrss_main ttrss_login">
 
 <script type="text/javascript">
-function init() {
-
-	require(['dojo/parser','dijit/form/Button','dijit/form/CheckBox','dijit/form/Form',
-    	'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser){
-    		parser.parse();
-    		//show tooltip node only after this widget is instaniated.
-    		dojo.query('div[dojoType="dijit.Tooltip"]').style({
-    			display:''
-    		});
-		fetchProfiles();
-		dijit.byId("bw_limit").attr("checked", Cookie.get("ttrss_bwlimit") == 'true');
-		document.forms.loginForm.login.focus();
-    	});
-
-}
+require(['dojo/parser', "dojo/ready", 'dijit/form/Button','dijit/form/CheckBox','dijit/form/Form',
+    'dijit/form/Select','dijit/form/TextBox','dijit/form/ValidationTextBox'],function(parser, ready){
+        ready(function() {
+            parser.parse();
+
+            //show tooltip node only after this widget is instaniated.
+            dojo.query('div[dojoType="dijit.Tooltip"]').style({
+                display:''
+            });
+
+            fetchProfiles();
+            dijit.byId("bw_limit").attr("checked", Cookie.get("ttrss_bwlimit") == 'true');
+            document.forms.loginForm.login.focus();
+        });
+});
 
 function fetchProfiles() {
 	try {

+ 0 - 1
index.php

@@ -105,7 +105,6 @@
 				"lib/dojo/tt-rss-layer.js",
 				"js/tt-rss.js",
 				"js/common.js",
-				"js/PluginHost.js",
 				"errors.php?mode=js") as $jsfile) {
 
 		echo javascript_tag($jsfile);

+ 17 - 15
js/Article.js

@@ -1,9 +1,9 @@
 'use strict'
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.Article", null, {
+	Article = {
 		_active_article_id: 0,
-		selectionSetScore: function() {
+		selectionSetScore: function () {
 			const ids = Headlines.getSelected();
 
 			if (ids.length > 0) {
@@ -40,7 +40,7 @@ define(["dojo/_base/declare"], function (declare) {
 				alert(__("No articles selected."));
 			}
 		},
-		setScore: function(id, pic) {
+		setScore: function (id, pic) {
 			const score = pic.getAttribute("score");
 
 			const new_score = prompt(__("Please enter new score for this article:"), score);
@@ -57,7 +57,7 @@ define(["dojo/_base/declare"], function (declare) {
 				});
 			}
 		},
-		cdmUnsetActive: function(event) {
+		cdmUnsetActive: function (event) {
 			const row = $("RROW-" + Article.getActive());
 
 			if (row) {
@@ -119,7 +119,7 @@ define(["dojo/_base/declare"], function (declare) {
 			} catch (e) {
 			}
 		},
-		view: function(id, noexpand) {
+		view: function (id, noexpand) {
 			this.setActive(id);
 
 			if (!noexpand) {
@@ -175,7 +175,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			return false;
 		},
-		editTags: function(id) {
+		editTags: function (id) {
 			const query = "backend.php?op=article&method=editArticleTags&param=" + encodeURIComponent(id);
 
 			if (dijit.byId("editTagsDlg"))
@@ -224,7 +224,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			dialog.show();
 		},
-		cdmScrollToId: function(id, force) {
+		cdmScrollToId: function (id, force) {
 			const ctr = $("headlines-frame");
 			const e = $("RROW-" + id);
 
@@ -239,7 +239,7 @@ define(["dojo/_base/declare"], function (declare) {
 				Element.hide("floatingTitle");
 			}
 		},
-		setActive: function(id) {
+		setActive: function (id) {
 			console.log("setActive", id);
 
 			$$("div[id*=RROW][class*=active]").each((e) => {
@@ -287,10 +287,10 @@ define(["dojo/_base/declare"], function (declare) {
 
 			Headlines.updateSelectedPrompt();
 		},
-		getActive: function() {
+		getActive: function () {
 			return this._active_article_id;
 		},
-		scroll: function(offset) {
+		scroll: function (offset) {
 			if (!App.isCombinedMode()) {
 				const ci = $("content-insert");
 				if (ci) {
@@ -304,7 +304,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			}
 		},
-		getRelativeIds: function(id, limit) {
+		getRelativeIds: function (id, limit) {
 
 			const tmp = [];
 
@@ -324,14 +324,16 @@ define(["dojo/_base/declare"], function (declare) {
 
 			return tmp;
 		},
-		mouseIn: function(id) {
+		mouseIn: function (id) {
 			this.post_under_pointer = id;
 		},
-		mouseOut: function(id) {
+		mouseOut: function (id) {
 			this.post_under_pointer = false;
 		},
-		getUnderPointer: function() {
+		getUnderPointer: function () {
 			return this.post_under_pointer;
 		}
-	});
+	}
+
+	return Article;
 });

+ 8 - 6
js/ArticleCache.js

@@ -1,9 +1,9 @@
 'use strict'
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.ArticleCache", null, {
+	ArticleCache = {
 		has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null,
-		set: function(id, obj) {
+		set: function (id, obj) {
 			if (this.has_storage)
 				try {
 					sessionStorage["article:" + id] = obj;
@@ -11,17 +11,19 @@ define(["dojo/_base/declare"], function (declare) {
 					sessionStorage.clear();
 				}
 		},
-		get: function(id) {
+		get: function (id) {
 			if (this.has_storage)
 				return sessionStorage["article:" + id];
 		},
-		clear: function() {
+		clear: function () {
 			if (this.has_storage)
 				sessionStorage.clear();
 		},
-		del: function(id) {
+		del: function (id) {
 			if (this.has_storage)
 				sessionStorage.removeItem("article:" + id);
 		},
-	});
+	}
+
+	return ArticleCache;
 });

+ 4 - 2
js/CommonDialogs.js

@@ -2,7 +2,7 @@
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	// noinspection JSUnusedGlobalSymbols
-	return declare("fox.CommonDialogs", null, {
+	CommonDialogs = {
 		closeInfoBox: function() {
 			const dialog = dijit.byId("infoBox");
 			if (dialog)	dialog.hide();
@@ -443,5 +443,7 @@ define(["dojo/_base/declare"], function (declare) {
 			}
 			return false;
 		}
-	});
+	};
+
+	return CommonDialogs;
 });

+ 4 - 2
js/CommonFilters.js

@@ -1,7 +1,7 @@
 'use strict'
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.CommonFilters", null, {
+	Filters = {
 		filterDlgCheckAction: function(sender) {
 			const action = sender.value;
 
@@ -387,5 +387,7 @@ define(["dojo/_base/declare"], function (declare) {
 			}
 			dialog.show();
 		},
-	});
+	};
+
+	return Filters;
 });

+ 4 - 2
js/Feeds.js

@@ -1,7 +1,7 @@
 'use strict'
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.Feeds", null, {
+	Feeds = {
 		counters_last_request: 0,
 		_active_feed_id: 0,
 		_active_feed_is_cat: false,
@@ -636,5 +636,7 @@ define(["dojo/_base/declare"], function (declare) {
 				App.handleRpcJson(transport, true);
 			});
 		},
-	});
+	};
+
+	return Feeds;
 });

+ 38 - 36
js/Headlines.js

@@ -1,13 +1,13 @@
 'use strict';
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.Headlines", null, {
+	Headlines = {
 		vgroup_last_feed: undefined,
 		_headlines_scroll_timeout: 0,
 		loaded_article_ids: [],
 		current_first_id: 0,
 		catchup_id_batch: [],
-		click: function(event, id, in_body) {
+		click: function (event, id, in_body) {
 			in_body = in_body || false;
 
 			if (App.isCombinedMode()) {
@@ -34,16 +34,16 @@ define(["dojo/_base/declare"], function (declare) {
 				return false;
 			}
 		},
-		initScrollHandler: function() {
+		initScrollHandler: function () {
 			$("headlines-frame").onscroll = (event) => {
 				clearTimeout(this._headlines_scroll_timeout);
-				this._headlines_scroll_timeout = window.setTimeout(function() {
+				this._headlines_scroll_timeout = window.setTimeout(function () {
 					//console.log('done scrolling', event);
 					Headlines.scrollHandler();
 				}, 50);
 			}
 		},
-		loadMore: function() {
+		loadMore: function () {
 			const view_mode = document.forms["main_toolbar_form"].view_mode.value;
 			const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
 			const num_all = $$("#headlines-frame > div[id*=RROW]").length;
@@ -71,7 +71,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), offset: offset});
 		},
-		scrollHandler: function() {
+		scrollHandler: function () {
 			try {
 				Headlines.unpackVisible();
 
@@ -149,7 +149,7 @@ define(["dojo/_base/declare"], function (declare) {
 				console.warn("scrollHandler", e);
 			}
 		},
-		updateFloatingTitle: function(unread_only) {
+		updateFloatingTitle: function (unread_only) {
 			if (!App.isCombinedMode()/* || !App.getInitParam("cdm_expanded")*/) return;
 
 			const hf = $("headlines-frame");
@@ -200,7 +200,7 @@ define(["dojo/_base/declare"], function (declare) {
 				}
 			}
 		},
-		unpackVisible: function() {
+		unpackVisible: function () {
 			if (!App.isCombinedMode() || !App.getInitParam("cdm_expanded")) return;
 
 			const rows = $$("#headlines-frame div[id*=RROW][data-content]");
@@ -221,7 +221,7 @@ define(["dojo/_base/declare"], function (declare) {
 				}
 			}
 		},
-		onLoaded: function(transport, offset) {
+		onLoaded: function (transport, offset) {
 			const reply = App.handleRpcJson(transport);
 
 			console.log("Headlines.onLoaded: offset=", offset);
@@ -383,7 +383,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			Notify.close();
 		},
-		reverse: function() {
+		reverse: function () {
 			const toolbar = document.forms["main_toolbar_form"];
 			const order_by = dijit.getEnclosingWidget(toolbar.order_by);
 
@@ -398,7 +398,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			Feeds.reloadCurrent();
 		},
-		selectionToggleUnread: function(params) {
+		selectionToggleUnread: function (params) {
 			params = params || {};
 
 			const cmode = params.cmode || 2;
@@ -442,7 +442,7 @@ define(["dojo/_base/declare"], function (declare) {
 				if (callback) callback(transport);
 			});
 		},
-		selectionToggleMarked: function(ids) {
+		selectionToggleMarked: function (ids) {
 			const rows = ids || Headlines.getSelected();
 
 			if (rows.length == 0) {
@@ -463,7 +463,7 @@ define(["dojo/_base/declare"], function (declare) {
 				App.handleRpcJson(transport);
 			});
 		},
-		selectionTogglePublished: function(ids) {
+		selectionTogglePublished: function (ids) {
 			const rows = ids || Headlines.getSelected();
 
 			if (rows.length == 0) {
@@ -486,7 +486,7 @@ define(["dojo/_base/declare"], function (declare) {
 				});
 			}
 		},
-		toggleMark: function(id, client_only) {
+		toggleMark: function (id, client_only) {
 			const query = {op: "rpc", id: id, method: "mark"};
 			const row = $("RROW-" + id);
 
@@ -511,7 +511,7 @@ define(["dojo/_base/declare"], function (declare) {
 					});
 			}
 		},
-		togglePub: function(id, client_only) {
+		togglePub: function (id, client_only) {
 			const row = $("RROW-" + id);
 
 			if (row) {
@@ -538,7 +538,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			}
 		},
-		move: function(mode, noscroll, noexpand) {
+		move: function (mode, noscroll, noexpand) {
 			const rows = Headlines.getLoaded();
 
 			let prev_id = false;
@@ -620,7 +620,7 @@ define(["dojo/_base/declare"], function (declare) {
 				}
 			}
 		},
-		updateSelectedPrompt: function() {
+		updateSelectedPrompt: function () {
 			const count = Headlines.getSelected().length;
 			const elem = $("selected_prompt");
 
@@ -631,7 +631,7 @@ define(["dojo/_base/declare"], function (declare) {
 				count > 0 ? Element.show(elem) : Element.hide(elem);
 			}
 		},
-		toggleUnread: function(id, cmode) {
+		toggleUnread: function (id, cmode) {
 			const row = $("RROW-" + id);
 
 			if (row) {
@@ -658,7 +658,7 @@ define(["dojo/_base/declare"], function (declare) {
 						});
 			}
 		},
-		selectionRemoveLabel: function(id, ids) {
+		selectionRemoveLabel: function (id, ids) {
 			if (!ids) ids = Headlines.getSelected();
 
 			if (ids.length == 0) {
@@ -676,7 +676,7 @@ define(["dojo/_base/declare"], function (declare) {
 				this.onLabelsUpdated(transport);
 			});
 		},
-		selectionAssignLabel: function(id, ids) {
+		selectionAssignLabel: function (id, ids) {
 			if (!ids) ids = Headlines.getSelected();
 
 			if (ids.length == 0) {
@@ -694,7 +694,7 @@ define(["dojo/_base/declare"], function (declare) {
 				this.onLabelsUpdated(transport);
 			});
 		},
-		deleteSelection: function() {
+		deleteSelection: function () {
 			const rows = Headlines.getSelected();
 
 			if (rows.length == 0) {
@@ -725,7 +725,7 @@ define(["dojo/_base/declare"], function (declare) {
 				Feeds.reloadCurrent();
 			});
 		},
-		getSelected: function() {
+		getSelected: function () {
 			const rv = [];
 
 			$$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
@@ -739,7 +739,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			return rv.uniq();
 		},
-		getLoaded: function() {
+		getLoaded: function () {
 			const rv = [];
 
 			const children = $$("#headlines-frame > div[id*=RROW-]");
@@ -752,7 +752,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			return rv;
 		},
-		onRowChecked: function(elem) {
+		onRowChecked: function (elem) {
 			// account for dojo checkboxes
 			elem = elem.domNode || elem;
 
@@ -760,7 +760,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			this.updateSelectedPrompt();
 		},
-		select: function(mode) {
+		select: function (mode) {
 			// mode = all,none,unread,invert,marked,published
 			let query = "#headlines-frame > div[id*=RROW]";
 
@@ -814,7 +814,7 @@ define(["dojo/_base/declare"], function (declare) {
 				Headlines.updateSelectedPrompt();
 			}
 		},
-		archiveSelection: function() {
+		archiveSelection: function () {
 			const rows = Headlines.getSelected();
 
 			if (rows.length == 0) {
@@ -854,7 +854,7 @@ define(["dojo/_base/declare"], function (declare) {
 				Feeds.reloadCurrent();
 			});
 		},
-		catchupSelection: function() {
+		catchupSelection: function () {
 			const rows = Headlines.getSelected();
 
 			if (rows.length == 0) {
@@ -875,7 +875,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			Headlines.selectionToggleUnread({callback: Feeds.reloadCurrent, no_error: 1});
 		},
-		catchupBatched: function(callback) {
+		catchupBatched: function (callback) {
 			console.log("catchupBatched, size=", this.catchup_id_batch.length);
 
 			if (this.catchup_id_batch.length > 0) {
@@ -908,7 +908,7 @@ define(["dojo/_base/declare"], function (declare) {
 				if (callback) callback();
 			}
 		},
-		catchupRelativeTo: function(below, id) {
+		catchupRelativeTo: function (below, id) {
 
 			if (!id) id = Article.getActive();
 
@@ -970,7 +970,7 @@ define(["dojo/_base/declare"], function (declare) {
 				}
 			}
 		},
-		onLabelsUpdated: function(transport) {
+		onLabelsUpdated: function (transport) {
 			const data = JSON.parse(transport.responseText);
 
 			if (data) {
@@ -981,11 +981,11 @@ define(["dojo/_base/declare"], function (declare) {
 				});
 			}
 		},
-		onActionChanged: function(elem) {
+		onActionChanged: function (elem) {
 			eval(elem.value);
 			elem.attr('value', 'false');
 		},
-		correctHeadlinesOffset: function(id) {
+		correctHeadlinesOffset: function (id) {
 			const container = $("headlines-frame");
 			const row = $("RROW-" + id);
 
@@ -1005,7 +1005,7 @@ define(["dojo/_base/declare"], function (declare) {
 				container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
 			}
 		},
-		initFloatingMenu: function() {
+		initFloatingMenu: function () {
 			if (!dijit.byId("floatingMenu")) {
 
 				const menu = new dijit.Menu({
@@ -1018,7 +1018,7 @@ define(["dojo/_base/declare"], function (declare) {
 				menu.startup();
 			}
 		},
-		headlinesMenuCommon: function(menu) {
+		headlinesMenuCommon: function (menu) {
 
 			menu.addChild(new dijit.MenuItem({
 				label: __("Open original article"),
@@ -1146,7 +1146,7 @@ define(["dojo/_base/declare"], function (declare) {
 
 			}
 		},
-		initHeadlinesMenu: function() {
+		initHeadlinesMenu: function () {
 			if (!dijit.byId("headlinesMenu")) {
 
 				const menu = new dijit.Menu({
@@ -1209,5 +1209,7 @@ define(["dojo/_base/declare"], function (declare) {
 				menu.startup();
 			}
 		}
-	});
+	}
+
+	return Headlines;
 });

+ 1 - 1
js/PluginHost.js

@@ -1,6 +1,6 @@
 // based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system
 
-const PluginHost = {
+PluginHost = {
 	HOOK_ARTICLE_RENDERED: 1,
 	HOOK_ARTICLE_RENDERED_CDM: 2,
 	HOOK_ARTICLE_SET_ACTIVE: 3,

+ 4 - 2
js/PrefHelpers.js

@@ -1,5 +1,5 @@
 define(["dojo/_base/declare"], function (declare) {
-	return declare("fox.PrefHelpers", null, {
+	Prefs = {
 		clearFeedAccessKeys: function() {
 			if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) {
 				Notify.progress("Clearing URLs...");
@@ -148,5 +148,7 @@ define(["dojo/_base/declare"], function (declare) {
 				Notify.close();
 			});
 		}
-	});
+	}
+
+	return Prefs;
 });

+ 4 - 3
js/PrefUsers.js

@@ -1,8 +1,7 @@
 'use strict'
 /* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
-
-	return declare("fox.PrefUsers", null, {
+	Users = {
 		reload: function(sort) {
 			const user_search = $("user_search");
 			const search = user_search ? user_search.value : "";
@@ -115,7 +114,9 @@ define(["dojo/_base/declare"], function (declare) {
 		getSelection :function() {
 			return Tables.getSelected("prefUserList");
 		}
-	});
+	}
+
+	return Users;
 });
 
 

+ 0 - 5
js/prefs.js

@@ -60,11 +60,6 @@ require(["dojo/_base/kernel",
 						report_error(message, filename, lineno, colno, error);
 					};
 
-					CommonDialogs = fox.CommonDialogs();
-					Filters = fox.CommonFilters();
-					Users = fox.PrefUsers();
-					Prefs = fox.PrefHelpers();
-
 					parser.parse();
 
 					this.setLoadingProgress(50);

+ 3 - 8
js/tt-rss.js

@@ -8,6 +8,7 @@ let Feeds;
 let Headlines;
 let Article;
 let ArticleCache;
+let PluginHost;
 
 require(["dojo/_base/kernel",
 	"dojo/_base/declare",
@@ -45,8 +46,9 @@ require(["dojo/_base/kernel",
 	"dijit/tree/dndSource",
 	"dijit/tree/ForestStoreModel",
 	"dojo/data/ItemFileWriteStore",
-	"fox/CommonDialogs",
+	"fox/PluginHost",
 	"fox/CommonFilters",
+	"fox/CommonDialogs",
 	"fox/Feeds",
 	"fox/Headlines",
 	"fox/Article",
@@ -65,13 +67,6 @@ require(["dojo/_base/kernel",
 						report_error(message, filename, lineno, colno, error);
 					};
 
-					CommonDialogs = fox.CommonDialogs();
-					Filters = fox.CommonFilters();
-					Feeds = fox.Feeds();
-					Headlines = fox.Headlines();
-					Article = fox.Article();
-					ArticleCache = fox.ArticleCache();
-
 					parser.parse();
 
 					if (!this.genericSanityCheck())

+ 1 - 1
register.php

@@ -115,7 +115,7 @@
 			}
 
 			var query = "register.php?action=check&login=" +
-					param_escape(login);
+					encodeURIComponent(login);
 
 			new Ajax.Request(query, {
 				onComplete: function(transport) {