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

This commit is contained in:
Andrew Dolgov 2018-12-02 18:38:27 +03:00
parent 807ff07454
commit f89924f7a1
17 changed files with 32 additions and 72 deletions

View File

@ -1310,9 +1310,6 @@
$data['last_article_id'] = Article::getLastArticleId(); $data['last_article_id'] = Article::getLastArticleId();
$data['cdm_expanded'] = get_pref('CDM_EXPANDED'); $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"]); $data["labels"] = Labels::get_all_labels($_SESSION["uid"]);
if (CHECK_FOR_UPDATES && !$disable_update_check && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { 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)); 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) { function T_js_decl($s1, $s2) {
if ($s1 && $s2) { if ($s1 && $s2) {
$s1 = preg_replace("/\n/", "", $s1); $s1 = preg_replace("/\n/", "", $s1);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,10 +19,10 @@ const PluginHost = {
this.hooks[name].push(callback); this.hooks[name].push(callback);
}, },
run: function (name, args) { run: function (name, args) {
console.warn('PluginHost::run ' + name); //console.warn('PluginHost::run ' + name);
if (typeof(this.hooks[name]) != 'undefined') 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; if (!this.hooks[name][i](args)) break;
} }
}; };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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