diff --git a/filter.php b/filter.php index 9618a16ac7f06ae46c98bb68b204d5a2d190ad7d..e928ffa976b93d8f4eaf5ad96fd8c30e5dd8b2e1 100644 --- a/filter.php +++ b/filter.php @@ -170,6 +170,17 @@ function filter($text, array $options = array()) } $len = strpos($pieces[$i], $this->end, $ini) - $ini; $parsed = substr($pieces[$i], $ini, $len); + + /* calcul unique modale id for showing modale, based on module type (page, test, etc.) and module id */ + $modal_id = $i; /* default */ + $module_id = null; + preg_match('/id=([\d]+)*/', $pieces[$i], $module_id); + $module_type = ""; + preg_match('/\/mod\/([^\/]+)\//', $pieces[$i], $module_type); + if (isset($module_id[1]) && isset($module_id[1])) { + $modal_id = $module_type[1] . $module_id[1]; + } + preg_match_all('/id=[\d]*/', $parsed, $matches); if ($matches[0]) { preg_match_all('/[\d]+/', $matches[0][0], $id_btn); @@ -198,16 +209,16 @@ 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 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 . "; " + . "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $modal_id . "\" 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 fade iena-filter-modal\" id=\"iena-modal-" . $modal_id . "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $modal_id . "\" 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>' + . '<h5 class="modal-title" id="iena-modal-btn-'.$modal_id.'">'.$this->btn_name.'</h5>' . '<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button>' diff --git a/js/iena.js b/js/iena.js index ef2a6bd893eca04545c9c85cfcd1526b4eaa1f72..6b47f68289ee7ba68fdeceff09460b02bb5e1706 100644 --- a/js/iena.js +++ b/js/iena.js @@ -9,29 +9,11 @@ document.querySelector(e.target.dataset.target + " iframe").setAttribute('src', e.target.dataset.iframe); } } - $('.iena-filter-modal').on('hide.bs.modal', function (e) { - e.target.querySelector('iframe').src = ""; - }); + /* iframe kill after modale closing doesn't work... */ + // console.log($('.iena-filter-modal')); + // $('.iena-filter-modal').on('hidden.bs.modal', function (e) { + // console.log(e); + // console.log(this); + // this.querySelector('iframe').src = ""; + // }); })(jQuery); -// ;(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