From 90092f23c30caf93441a237588516efe1d65cd41 Mon Sep 17 00:00:00 2001
From: Thomas Fradet <t.fradet8@gmail.com>
Date: Fri, 15 Feb 2019 14:02:51 +0100
Subject: [PATCH] v354plus

---
 CHANGELOG.md                         | 13 +++++
 filter.php                           | 71 ++++++++++++++-------------
 filtersettings.php                   |  1 +
 js/iena-filter-accessibility.js      |  9 ----
 js/iena.js                           | 50 ++++++++++---------
 js/iframe_true.js                    | 73 ++++++++++++++++++----------
 lang/en/filter_iena.php              |  2 +
 lang/fr/filter_iena.php              |  2 +
 nbproject/private/private.properties |  2 -
 nbproject/private/private.xml        | 11 -----
 nbproject/project.properties         |  7 ---
 nbproject/project.xml                |  9 ----
 styles.css                           | 12 ++++-
 version.php                          |  2 +-
 14 files changed, 143 insertions(+), 121 deletions(-)
 create mode 100644 CHANGELOG.md
 delete mode 100644 js/iena-filter-accessibility.js
 delete mode 100644 nbproject/private/private.properties
 delete mode 100644 nbproject/private/private.xml
 delete mode 100644 nbproject/project.properties
 delete mode 100644 nbproject/project.xml

diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..a2d08c4
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,13 @@
+# 19/02/19
+
+## Vitesse de chargement
+
+La source de la fenêtre modale n'est plus définie en PHP, mais en Javascript à son ouverture. En conséquence, la page se charge plus rapidement lorsqu'il y a de nombreux éléments, et la ressource se charge dans la fenêtre modale lors de son ouverture. 
+
+## Affichage
+
+L'affichage du contenu de l'iframe sans les menus de nativation et le footer est réactivé. 
+
+L'affichage du contenu de l'iframe sans les menus de nativation et le footer est optimisé pour MOODLE 3.5.4+. 
+
+L'affichage du contenu de l'iframe sans les menus de nativation et le footer fait l'objet d'un paramètre du plugin (case à cochée). Il est activé par défaut. 
diff --git a/filter.php b/filter.php
index 88bb4d3..69ae966 100644
--- a/filter.php
+++ b/filter.php
@@ -31,21 +31,22 @@
 class filter_iena extends moodle_text_filter
 {
 
-	/** @var string This variable is used for delemiter */
+	/* @var string This variable is used for delemiter */
 	public $start = "[IENA]";
-	/** @var string This variable is used for delemiter */
+	/* @var string This variable is used for delemiter */
 	public $end = "[/IENA]";
-/** @var string Contain button name, the button name is
-		 * automatically the name of resource */
-public $btn_name;
-/** @var string Contain the type of button */
-public $btn_type;
-/** @var string Hex color of button is defined in settings ($CFG->color_btn) */
-public $color_btn = "#009085";
-/** @var string Hex color of button text is defined in settings ($CFG->color_btn_txt) */
-public $color_btn_txt = "#ffffff";
-/** @var string set empty, if the id does not exist then turn to "disabled" */
-public $disabled = "";
+	/* @var string Contain button name, the button name is automatically the name of resource */
+	public $btn_name;
+	/** @var string Contain the type of button */
+	public $btn_type;
+	/** @var string Hex color of button is defined in settings ($CFG->color_btn) */
+	public $color_btn = "#009085";
+	/** @var string Hex color of button text is defined in settings ($CFG->color_btn_txt) */
+	public $color_btn_txt = "#ffffff";
+	/** @var string set empty, if the id does not exist then turn to "disabled" */
+	public $disabled = "";
+	/** @var string hide iframe nav and footer, admin setting */
+	public $iena_filter_iframe = true;
 
 /**
  * Get name and type of resource with the id
@@ -138,13 +139,16 @@ function filter($text, array $options = array())
 	}
 
 	//$PAGE->requires->js('/filter/iena/js/jquery-3.3.1.min.js');
-	//$PAGE->requires->js('/filter/iena/js/iena.js');
+	$PAGE->requires->js('/filter/iena/js/iena.js');
 	//We hide the menus and block if the iframe parameter is a true
-	// if (isset($_GET['iframe'])) {
-	// 	if ($_GET['iframe'] == 'true') {
-	// 		$PAGE->requires->js('/filter/iena/js/iframe_true.js');
-	// 	}
-	// }
+	if (isset($CFG->iena_filter_iframe)) {
+		$this->iena_filter_iframe = $CFG->iena_filter_iframe;
+	}
+	if (isset($_GET['iframe']) && $this->iena_filter_iframe == "1") {
+		if ($_GET['iframe'] == 'true') {
+			$PAGE->requires->js('/filter/iena/js/iframe_true.js');
+		}
+	}
 
 	preg_match_all('/<a href="(.*?)">(.*?)<\/a>/s', $text, $matches);
 
@@ -193,26 +197,27 @@ function filter($text, array $options = array())
 
 		$pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", 
 			"<div>"
-			. "<a class=\"sr-only\" target=\"_blank\" href=\"$parsed\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button type=\"button\" " . $this->disabled . " "
+			. "<a class=\"sr-only\" target=\"_blank\" href=\"$parsed\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button data-iframe=\"" .$parsed. "&iframe=true\" type=\"button\" " . $this->disabled . " "
 			. "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $i . "\" style=\"background-color : " . $this->color_btn . "; "
 			. "color : $this->color_btn_txt;border-radius:0.15rem;\">"
 			. "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
 			. "" . $this->btn_name . " </button>"
 
 			. "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $i . "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $i . "\" aria-hidden=\"true\">"
-				. "<div class=\"modal-dialog\" role=\"document\">"
-					. '<div class="modal-content">'
-						. '<div class="modal-header">'
-							. '<h5 class="modal-title" id="iena-modal-btn-'.$i.'">'.$this->btn_name.'</h5>'
-							. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">
-									<span aria-hidden="true">&times;</span>
-								</button>'
-						. "</div>"
-						. '<div class="modal-body">'
-							. "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
-						. "</div>"
-					. "</div>"
-				. "</div>"
+			. "<div class=\"modal-dialog\" role=\"document\">"
+			. '<div class="modal-content">'
+			. '<div class="modal-header">'
+			. '<h5 class="modal-title" id="iena-modal-btn-'.$i.'">'.$this->btn_name.'</h5>'
+			. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">
+			<span aria-hidden="true">&times;</span>
+			</button>'
+			. "</div>"
+			. '<div class="modal-body">'
+			// . "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
+			. "<iframe src=\"\" frameborder=\"0\" allowfullscreen></iframe>"
+			. "</div>"
+			. "</div>"
+			. "</div>"
 			. "</div>"
 			
 			. "</div>"
diff --git a/filtersettings.php b/filtersettings.php
index 18e0d00..f66e0f0 100644
--- a/filtersettings.php
+++ b/filtersettings.php
@@ -2,4 +2,5 @@
 	
 	$settings->add(new admin_setting_configtext('color_btn', get_string('btn_settings', 'filter_iena'), get_string('setting_btn_settings', 'filter_iena'), "#009085"));
 	$settings->add(new admin_setting_configtext('color_btn_txt', get_string('btn_txt_settings', 'filter_iena'), get_string('setting_btn_txt_settings', 'filter_iena'), "#ffffff"));
+	$settings->add(new admin_setting_configcheckbox('iena_filter_iframe', get_string('btn_iframe_setting', 'filter_iena'), get_string('setting_btn_iframe_setting', 'filter_iena'), "1"));
 ?>
diff --git a/js/iena-filter-accessibility.js b/js/iena-filter-accessibility.js
deleted file mode 100644
index d3261c2..0000000
--- a/js/iena-filter-accessibility.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// (function() {
-// 	window.onload = function () {
-// 		$(".iena-filter-modal-btn").each(function(i, el){
-// 			el.click = function (e) {
-// 				console.log(e);
-// 			}
-// 		});
-// 	}
-// })()
\ No newline at end of file
diff --git a/js/iena.js b/js/iena.js
index b9b6f5e..882571c 100644
--- a/js/iena.js
+++ b/js/iena.js
@@ -1,22 +1,28 @@
-;(function ($) {
-	$('iframe').load(function () {
-		$('iframe').contents().find("body")
-		.append($("<style type='text/css'>  \n\
-			#page-header{display:none;}\n\
-			#page-footer{display:none;}  \n\
-			.hidden-print{display:none;}\n\
-			#page{margin-top: 15px;padding-left: 10px;padding-right: 15px;} \n\
-			#card-block{height: 837px;width: 990px;}  \n\
-			</style>"));
-		$('iframe').contents().find("header")
-		.append($("<style type='text/css'>  \n\
-			.pos-f-t{display:none;} \n\
-			.navbar{display:none;} \n\
-			.navbar-full{display:none;} \n\
-			.navbar-light{display:none;} \n\
-			.bg-faded{display:none;} \n\
-			.navbar-static-top{display:none;} \n\
-			.moodle-has-zindex{display:none;}\n\
-			</style>"));
-	});
-})(jQuery);
\ No newline at end of file
+;(function () {
+	var btns = document.querySelectorAll('.iena-filter-modal-btn');
+	for (var i = 0; i < btns.length; i++) {
+		document.querySelector(btns[i].dataset.target + " iframe").setAttribute('src', btns[i].dataset.iframe);
+	}
+})()
+// ;(function ($) {
+// 	$('iframe').load(function () {
+// 		$('iframe').contents().find("body")
+// 		.append($("<style type='text/css'>  \n\
+// 			#page-header{display:none;}\n\
+// 			#page-footer{display:none;}  \n\
+// 			.hidden-print{display:none;}\n\
+// 			#page{margin-top: 15px;padding-left: 10px;padding-right: 15px;} \n\
+// 			#card-block{height: 837px;width: 990px;}  \n\
+// 			</style>"));
+// 		$('iframe').contents().find("header")
+// 		.append($("<style type='text/css'>  \n\
+// 			.pos-f-t{display:none;} \n\
+// 			.navbar{display:none;} \n\
+// 			.navbar-full{display:none;} \n\
+// 			.navbar-light{display:none;} \n\
+// 			.bg-faded{display:none;} \n\
+// 			.navbar-static-top{display:none;} \n\
+// 			.moodle-has-zindex{display:none;}\n\
+// 			</style>"));
+// 	});
+// })(jQuery);
\ No newline at end of file
diff --git a/js/iframe_true.js b/js/iframe_true.js
index 96ff001..6e4ba48 100644
--- a/js/iframe_true.js
+++ b/js/iframe_true.js
@@ -4,28 +4,51 @@
  * and open the template in the editor.
  */
 
-var elmt = document.getElementById("page-header");
-elmt.className = "none_hidden";
-
-var elmt1 = document.getElementById("page-footer");
-elmt1.className = "none_hidden";
-
-var elmt2 = document.getElementsByClassName("hidden-print");
-elmt2.className = "none_hidden";
-
-var elmt2 = document.getElementsByClassName("hidden-print");
-elmt2.className = "none_hidden";
-
-var elmt3 = document.getElementsByClassName("pos-f-t");
-elmt3.className = "none_hidden";
-
-var elmt4 = document.getElementsByClassName("navbar");
-elmt3.className = "none_hidden";
-var elmt5 = document.getElementsByClassName("navbar-full");
-elmt3.className = "none_hidden";
-var elmt6 = document.getElementsByClassName("navbar-light");
-elmt3.className = "none_hidden";
-var elmt7 = document.getElementsByClassName("navbar-static-top");
-elmt3.className = "none_hidden";
-var elmt8 = document.getElementsByClassName("moodle-has-zindex");
-elmt3.className = "none_hidden";
+/* http://localhost:8888/moodle35/mod/assign/view.php?id=18&iframe=true
+
+&iframe=true
+
+*/
+
+;(function () {
+	var to_hide = [
+		"#page-header",
+		"#page-wrapper > nav",
+		"#page-footer"
+	];
+	for (var i = 0; i < to_hide.length; i++) {
+		document.querySelector(to_hide[i]).setAttribute('class', 'none-hidden');
+	}
+	document.querySelector('#page').setAttribute('class', '');
+	document.querySelector('#page').style.margin = 0;
+	document.querySelector('#page-wrapper').setAttribute('class', 'no-after');
+	document.querySelector('#page-content').setAttribute('class', 'no-margin-l-r');
+	document.querySelector('#region-main-box').style.padding = 0;
+	document.querySelector('#region-main>.card').style.minHeight = 0;
+})()
+
+// var elmt = document.getElementById("page-header");
+// elmt.className = "none_hidden";
+
+// var elmt1 = document.getElementById("page-footer");
+// elmt1.className = "none_hidden";
+
+// var elmt2 = document.getElementsByClassName("hidden-print");
+// elmt2.className = "none_hidden";
+
+// var elmt2 = document.getElementsByClassName("hidden-print");
+// elmt2.className = "none_hidden";
+
+// var elmt3 = document.getElementsByClassName("pos-f-t");
+// elmt3.className = "none_hidden";
+
+// var elmt4 = document.getElementsByClassName("navbar");
+// elmt3.className = "none_hidden";
+// var elmt5 = document.getElementsByClassName("navbar-full");
+// elmt3.className = "none_hidden";
+// var elmt6 = document.getElementsByClassName("navbar-light");
+// elmt3.className = "none_hidden";
+// var elmt7 = document.getElementsByClassName("navbar-static-top");
+// elmt3.className = "none_hidden";
+// var elmt8 = document.getElementsByClassName("moodle-has-zindex");
+// elmt3.className = "none_hidden";
diff --git a/lang/en/filter_iena.php b/lang/en/filter_iena.php
index 6a2a305..ba9eb1a 100644
--- a/lang/en/filter_iena.php
+++ b/lang/en/filter_iena.php
@@ -5,8 +5,10 @@ $string['pluginname'] = "filter_iena";
 $string['filter_iena'] = "filter_iena";
 $string['btn_settings'] = "Button background color";
 $string['btn_txt_settings'] = "Button text color";
+$string['btn_iframe_setting'] = "Diplay content only";
 $string['setting_btn_settings'] = "The value must be in hexa and start with a #";
 $string['setting_btn_txt_settings'] = "The value must be in hexa and start with a #";
+$string['setting_btn_iframe_setting'] = "Display only iframe content, without navigation controls and footer.";
 $string['erreur_ressource'] = "Ressource not found";
 
 ?>
\ No newline at end of file
diff --git a/lang/fr/filter_iena.php b/lang/fr/filter_iena.php
index 17b483d..57534ec 100644
--- a/lang/fr/filter_iena.php
+++ b/lang/fr/filter_iena.php
@@ -5,8 +5,10 @@ $string['pluginname'] = "filter_iena";
 $string['filter_iena'] = "filter_iena";
 $string['btn_settings'] = "Couleur du bouton";
 $string['btn_txt_settings'] = "Couleur du texte du bouton";
+$string['btn_iframe_setting'] = "N'afficher que le contenu";
 $string['setting_btn_settings'] = "La valeur doit être en hexadécimal et débuter avec un #";
 $string['setting_btn_txt_settings'] = "La valeur doit être en hexadécimal et débuter avec un #";
+$string['setting_btn_iframe_setting'] = "N'afficher que le contenu de la page ciblée, sans les menus ou le pied de page.";
 $string['erreur_ressource'] = "Ressource non trouvée";
 
 ?>
\ No newline at end of file
diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties
deleted file mode 100644
index 6d2691b..0000000
--- a/nbproject/private/private.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-index.file=index.php
-url=http://localhost/wikipediacalls/
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
deleted file mode 100644
index 8c26490..0000000
--- a/nbproject/private/private.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
-    <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
-    <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
-        <group>
-            <file>file:/home/softia/Bureau/wikipediacalls/filtersettings.php</file>
-            <file>file:/home/softia/Bureau/wikipediacalls/version.php</file>
-            <file>file:/home/softia/Bureau/wikipediacalls/filter.php</file>
-        </group>
-    </open-files>
-</project-private>
diff --git a/nbproject/project.properties b/nbproject/project.properties
deleted file mode 100644
index 9e7cd7b..0000000
--- a/nbproject/project.properties
+++ /dev/null
@@ -1,7 +0,0 @@
-include.path=${php.global.include.path}
-php.version=PHP_56
-source.encoding=UTF-8
-src.dir=.
-tags.asp=false
-tags.short=false
-web.root=.
diff --git a/nbproject/project.xml b/nbproject/project.xml
deleted file mode 100644
index 72848ec..0000000
--- a/nbproject/project.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://www.netbeans.org/ns/project/1">
-    <type>org.netbeans.modules.php.project</type>
-    <configuration>
-        <data xmlns="http://www.netbeans.org/ns/php-project/1">
-            <name>wikipediacalls</name>
-        </data>
-    </configuration>
-</project>
diff --git a/styles.css b/styles.css
index 823d490..69f00a5 100644
--- a/styles.css
+++ b/styles.css
@@ -24,7 +24,15 @@
 	font-size: 3rem;*/
 }
 
-.none_hidden {
-	/*display: none;*/
+.none-hidden {
+	display: none;
 }
 
+.no-after:after {
+	min-height: 0 !important;
+}
+
+.no-margin-l-r {
+	margin-left: 0;
+	margin-right: 0;
+}
diff --git a/version.php b/version.php
index 251da63..df00a05 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
 	
 	defined('MOODLE_INTERNAL') || die();
 	
-	$plugin->version = 2018071201;        // The current plugin version (Date: YYYYMMDDXX)
+	$plugin->version = 2018071202;        // The current plugin version (Date: YYYYMMDDXX)
 	$plugin->requires = 2011120500;        // Requires this Moodle version
 	$plugin->component = 'filter_iena'; // Full name of the plugin (used for diagnostics)
 	$plugin->release = "1.0";
-- 
GitLab