Browse Source

set use strict on JS modules; remove some mostly useless stuff like get_minified_js()

Andrew Dolgov 1 year ago
parent
commit
f89924f7a1
17 changed files with 32 additions and 72 deletions
  1. 0 49
      include/functions.php
  2. 1 1
      include/login_form.php
  3. 4 5
      index.php
  4. 2 0
      js/Article.js
  5. 2 0
      js/ArticleCache.js
  6. 2 0
      js/CommonDialogs.js
  7. 2 0
      js/CommonFilters.js
  8. 2 0
      js/Feeds.js
  9. 2 2
      js/Headlines.js
  10. 2 2
      js/PluginHost.js
  11. 2 0
      js/PrefUsers.js
  12. 2 6
      js/Utils.js
  13. 1 0
      js/common.js
  14. 1 0
      js/prefs.js
  15. 1 0
      js/tt-rss.js
  16. 5 6
      prefs.php
  17. 1 1
      register.php

+ 0 - 49
include/functions.php

@@ -1310,9 +1310,6 @@
 		$data['last_article_id'] = Article::getLastArticleId();
 		$data['cdm_expanded'] = get_pref('CDM_EXPANDED');
 
-		$data['dep_ts'] = calculate_dep_timestamp();
-		$data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE');
-
 		$data["labels"] = Labels::get_all_labels($_SESSION["uid"]);
 
 		if (CHECK_FOR_UPDATES && !$disable_update_check && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
@@ -2379,52 +2376,6 @@
 		return in_array($interface, class_implements($class));
 	}
 
-	function get_minified_js($files) {
-
-		$rv = '';
-
-		foreach ($files as $js) {
-			if (!isset($_GET['debug'])) {
-				$cached_file = CACHE_DIR . "/js/".basename($js);
-
-				if (file_exists($cached_file) && is_readable($cached_file) && filemtime($cached_file) >= filemtime("js/$js")) {
-
-					list($header, $contents) = explode("\n", file_get_contents($cached_file), 2);
-
-					if ($header && $contents) {
-						list($htag, $hversion) = explode(":", $header);
-
-						if ($htag == "tt-rss" && $hversion == VERSION) {
-							$rv .= $contents;
-							continue;
-						}
-					}
-				}
-
-				$minified = JShrink\Minifier::minify(file_get_contents("js/$js"));
-				file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified);
-				$rv .= $minified;
-
-			} else {
-				$rv .= file_get_contents("js/$js"); // no cache in debug mode
-			}
-		}
-
-		return $rv;
-	}
-
-	function calculate_dep_timestamp() {
-		$files = array_merge(glob("js/*.js"), glob("css/*.css"));
-
-		$max_ts = -1;
-
-		foreach ($files as $file) {
-			if (filemtime($file) > $max_ts) $max_ts = filemtime($file);
-		}
-
-		return $max_ts;
-	}
-
 	function T_js_decl($s1, $s2) {
 		if ($s1 && $s2) {
 			$s1 = preg_replace("/\n/", "", $s1);

+ 1 - 1
include/login_form.php

@@ -10,7 +10,7 @@
 	foreach (array("lib/prototype.js",
 				"lib/dojo/dojo.js",
 				"lib/dojo/tt-rss-layer.js",
-				"js/functions.js",
+				"js/common.js",
 				"errors.php?mode=js") as $jsfile) {
 
 		echo javascript_tag($jsfile);

+ 4 - 5
index.php

@@ -103,6 +103,9 @@
 				"lib/scriptaculous/scriptaculous.js?load=effects,controls",
 				"lib/dojo/dojo.js",
 				"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);
@@ -110,13 +113,9 @@
 	} ?>
 
 	<script type="text/javascript">
-		'use strict';
 		require({cache:{}});
-	<?php
-		print get_minified_js(["tt-rss.js",
-			"functions.js", "PluginHost.js"]);
-	?>
 	</script>
+
 	<script type="text/javascript">
 	<?php
 		foreach (PluginHost::getInstance()->get_plugins() as $n => $p) {

+ 2 - 0
js/Article.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.Article", null, {
 		_active_article_id: 0,

+ 2 - 0
js/ArticleCache.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.ArticleCache", null, {
 		has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null,

+ 2 - 0
js/CommonDialogs.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.CommonDialogs", null, {
 		quickAddFeed: function() {

+ 2 - 0
js/CommonFilters.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.CommonFilters", null, {
 		filterDlgCheckAction: function(sender) {

+ 2 - 0
js/Feeds.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.Feeds", null, {
 		counters_last_request: 0,

+ 2 - 2
js/Headlines.js

@@ -1,5 +1,5 @@
-/* global dijit, __, ngettext, notify */
-
+'use strict';
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.Headlines", null, {
 		vgroup_last_feed: undefined,

+ 2 - 2
js/PluginHost.js

@@ -19,10 +19,10 @@ const PluginHost = {
 		this.hooks[name].push(callback);
 	},
 	run: function (name, args) {
-		console.warn('PluginHost::run ' + name);
+		//console.warn('PluginHost::run ' + name);
 
 		if (typeof(this.hooks[name]) != 'undefined')
-			for (var i = 0; i < this.hooks[name].length; i++)
+			for (let i = 0; i < this.hooks[name].length; i++)
 				if (!this.hooks[name][i](args)) break;
 	}
 };

+ 2 - 0
js/PrefUsers.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 
 	return declare("fox.PrefUsers", null, {

+ 2 - 6
js/Utils.js

@@ -1,3 +1,5 @@
+'use strict'
+/* global __, ngettext */
 define(["dojo/_base/declare"], function (declare) {
 	return declare("fox.Utils", null, {
 		_rpc_seq: 0,
@@ -235,12 +237,6 @@ define(["dojo/_base/declare"], function (declare) {
 
 					console.log("RI:", k, "=>", v);
 
-					if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
-						if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
-							window.location.reload();
-						}
-					}
-
 					if (k == "daemon_is_running" && v != 1) {
 						notify_error("<span onclick=\"Utils.explainError(1)\">Update daemon is not running.</span>", true);
 						return;

+ 1 - 0
js/functions.js → js/common.js

@@ -1,3 +1,4 @@
+'use strict'
 /* global dijit, __ */
 
 let init_params = {};

+ 1 - 0
js/prefs.js

@@ -1,3 +1,4 @@
+'use strict'
 /* global dijit, __ */
 
 let Utils;

+ 1 - 0
js/tt-rss.js

@@ -1,3 +1,4 @@
+'use strict'
 /* global dijit,__ */
 
 let Utils;

+ 5 - 6
prefs.php

@@ -70,19 +70,18 @@
 				"lib/scriptaculous/scriptaculous.js?load=effects,controls",
 				"lib/dojo/dojo.js",
 				"lib/dojo/tt-rss-layer.js",
+				"js/common.js",
+				"js/prefs.js",
 				"errors.php?mode=js") as $jsfile) {
 
 		echo javascript_tag($jsfile);
 
 	} ?>
 
-	<script type="text/javascript">
-		'use strict';
+    <script type="text/javascript">
 		require({cache:{}});
-	<?php
-		print get_minified_js(["functions.js", "prefs.js"]);
-	?>
-	</script>
+    </script>
+
 	<script type="text/javascript">
 	<?php
 		foreach (PluginHost::getInstance()->get_plugins() as $n => $p) {

+ 1 - 1
register.php

@@ -95,7 +95,7 @@
 <title>Create new account</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <?php echo stylesheet_tag("css/default.css") ?>
-<?php echo javascript_tag("js/functions.js") ?>
+<?php echo javascript_tag("js/common.js") ?>
 <?php echo javascript_tag("lib/prototype.js") ?>
 <?php echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") ?>
 </head>