From e7f2844481263b4cbe88e4d99194c2d63f4bfa7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=B3na=20Lore?= <lonalore@freemail.hu>
Date: Tue, 25 Jul 2017 19:20:11 +0200
Subject: [PATCH] Issue #2745 - Move JS files to footer. (Tested with and
 without JS/CSS caching)

---
 e107_admin/header.php                  | 58 +++++++++-----------------
 e107_core/templates/header_default.php | 13 +++---
 e107_handlers/form_handler.php         |  7 ++--
 e107_handlers/shortcode_handler.php    |  3 +-
 4 files changed, 30 insertions(+), 51 deletions(-)

diff --git a/e107_admin/header.php b/e107_admin/header.php
index 4c1abd030..254886ca7 100644
--- a/e107_admin/header.php
+++ b/e107_admin/header.php
@@ -53,62 +53,42 @@ if(!deftrue('e_MENUMANAGER_ACTIVE'))
 
 function loadJSAddons()
 {
-	
 	if(deftrue('e_MENUMANAGER_ACTIVE'))
 	{
 		return; 
 	}
-	
-// e107::js('core',    'bootstrap/js/bootstrap-modal.js', 'jquery', 2);  // Special Version see: https://github.com/twitter/bootstrap/pull/4224
 
-	e107::css('core', 	'bootstrap-select/bootstrap-select.min.css', 'jquery');
-	e107::js('core', 	'bootstrap-select/bootstrap-select.min.js', 'jquery', 2);
+	// TODO use Library Manager. Remove unused libraries...
+
+	e107::css('core', 'bootstrap-select/bootstrap-select.min.css', 'jquery');
+	e107::js('footer', '{e_WEB}js/bootstrap-select/bootstrap-select.min.js', 'jquery', 2);
 	
-//	e107::css('core', 	'bootstrap-multiselect/css/bootstrap-multiselect.css', 'jquery');
-	e107::js('core', 	'bootstrap-multiselect/js/bootstrap-multiselect.js', 'jquery', 2);
+	// e107::css('core', 'bootstrap-multiselect/css/bootstrap-multiselect.css', 'jquery');
+	e107::js('footer', '{e_WEB}js/bootstrap-multiselect/js/bootstrap-multiselect.js', 'jquery', 2);
 
 	// TODO: remove typeahead.
-	e107::js('core', 	'bootstrap-jasny/js/jasny-bootstrap.js', 'jquery', 2);
+	e107::js('footer', '{e_WEB}js/bootstrap-jasny/js/jasny-bootstrap.js', 'jquery', 2);
 	
-	e107::css('core', 	'bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', 'jquery');
-	e107::js('core', 	'bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 2);
+	e107::css('core', 'bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', 'jquery');
+	e107::js('footer', '{e_WEB}js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 2);
 	
-	e107::js('core',	'jquery.h5validate.min.js','jquery',2);
+	e107::js('footer','{e_WEB}js/jquery.h5validate.min.js','jquery', 2);
 	
-	e107::js('core', 	'jquery.elastic.js', 'jquery', 2);
-	e107::js('core', 	'jquery.at.caret.min.js', 'jquery', 2);
-	
-	// e107::js('core', 	'jquery-ui-timepicker-addon.js', 'jquery', 2);
-	
-	
-	//e107::css('core', 	'chosen/chosen.css', 'jquery');
-	//e107::js('core', 	'chosen/chosen.jquery.min.js', 'jquery', 2);
-	
-	// e107::js('core', 	'password/jquery.pwdMeter.js', 'jquery', 2); // loaded in form-handler.
-	
-	// e107::css('core', 	'bootstrap-tag/bootstrap-tag.css', 'jquery');
-//	e107::js('core', 	'bootstrap-tag/bootstrap-tag.js', 'jquery', 2);
-	
-		
-//	e107::js("core",	"tags/jquery.tagit.js","jquery",3);
-//	e107::css('core', 	'tags/jquery.tagit.css', 'jquery');
+	e107::js('footer', '{e_WEB}js/jquery.elastic.js', 'jquery', 2);
+	e107::js('footer', '{e_WEB}js/jquery.at.caret.min.js', 'jquery', 2);
 
-	e107::css('core', 	'core/admin.jquery.css', 'jquery');
-	e107::js("core",	"core/admin.jquery.js","jquery",4); // Load all default functions.
-	e107::css('core', 	'core/all.jquery.css', 'jquery');
+	e107::css('core', 'core/admin.jquery.css', 'jquery');
+	e107::css('core', 'core/all.jquery.css', 'jquery');
 
-	e107::js("core",	"core/all.jquery.js","jquery",4); // Load all default functions.
+	e107::js('footer', '{e_WEB}js/core/admin.jquery.js', 'jquery', 5); // Load all default functions.
+	e107::js('footer', '{e_WEB}js/core/all.jquery.js', 'jquery', 5); // Load all default functions.
 
-	$plUpload = "plupload/i18n/".e_LAN.".js";
+	$plUpload = '{e_WEB}js/plupload/i18n/' . e_LAN . '.js';
 
-	if(e_LAN != 'en' && file_exists(e_WEB_JS.$plUpload))
+	if(e_LAN != 'en' && file_exists(e_WEB_JS . $plUpload))
 	{
-		e107::js('core', $plUpload); 
+		e107::js('footer', $plUpload, 'jquery', 5);
 	}
-
-
-
-
 }
 
 // Load library dependencies.
diff --git a/e107_core/templates/header_default.php b/e107_core/templates/header_default.php
index 73bcb9789..6db33f753 100644
--- a/e107_core/templates/header_default.php
+++ b/e107_core/templates/header_default.php
@@ -31,18 +31,17 @@ e107::getTheme('current', true)->loadLibrary();
 
 if(deftrue('BOOTSTRAP'))
 {
-	e107::js('core',	'bootstrap-notify/js/bootstrap-notify.js','jquery');
-	e107::css('core',	'bootstrap-notify/css/bootstrap-notify.css','jquery');
+	e107::js('footer', '{e_WEB}js/bootstrap-notify/js/bootstrap-notify.js', 'jquery', 2);
+	e107::css('core', 'bootstrap-notify/css/bootstrap-notify.css', 'jquery');
 }
 
 // ------------------
 
-// e107::js('core', 	'jquery.elastic.js', 'jquery', 2);
-e107::js('core', 	'rate/js/jquery.raty.js', 'jquery', 2);
-e107::css('core', 	'core/all.jquery.css', 'jquery');
+e107::js('footer', '{e_WEB}js/rate/js/jquery.raty.js', 'jquery', 2);
+e107::css('core', 'core/all.jquery.css', 'jquery');
 
-e107::js("core",	"core/front.jquery.js","jquery",5); // Load all default functions.
-e107::js("core",	"core/all.jquery.js","jquery",5); // Load all default functions.
+e107::js('footer', '{e_WEB}js/core/front.jquery.js', 'jquery', 5); // Load all default functions.
+e107::js('footer', '{e_WEB}js/core/all.jquery.js', 'jquery', 5); // Load all default functions.
 
 $js_body_onload = array();		// Legacy array of code to load with page.
 
diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php
index b0ab270f0..d082a5fcb 100644
--- a/e107_handlers/form_handler.php
+++ b/e107_handlers/form_handler.php
@@ -1429,11 +1429,10 @@ class e_form
 			$text .= "<input type='{$ftype}' name='{$name}' id='{$id}' value='{$hiddenValue}' />";
 		}
 
-		// Load it in the footer.
-		// FIXME use Library Manager (e107::library()) instead?
+		// TODO use Library Manager...
 		e107::css('core', 'bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css', 'jquery');
-		e107::js('core', 'bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 2);
-		e107::js('core', 'bootstrap-datetimepicker/js/bootstrap-datetimepicker.init.js', 'jquery', 2);
+		e107::js('footer', '{e_WEB}js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js', 'jquery', 4);
+		e107::js('footer', '{e_WEB}js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.init.js', 'jquery', 5);
 
 		if(e_LANGUAGE !== 'English')
 		{
diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php
index 64ce05122..993738304 100644
--- a/e107_handlers/shortcode_handler.php
+++ b/e107_handlers/shortcode_handler.php
@@ -814,7 +814,8 @@ class e_parse_shortcode
 
 				if(isset($this->editableCodes['perms']) && getperms($this->editableCodes['perms']))
 				{
-					e107::js('core', 'jquery.contenteditable.js', 'jquery');
+					// TODO use Library Manager...
+					e107::js('footer', '{e_WEB}js/jquery.contenteditable.js', 'jquery', 2);
 
 					$_SESSION['editable'][e_TOKEN] = $this->editableCodes;