Skip to content

Commit

Permalink
Dev: Dev: remove the scripts loaded via ajax when loading next page
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 4, 2017
1 parent d298271 commit 74c00e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -7168,9 +7168,9 @@ static function GetRelevanceAndTailoringJavaScript()
$allJsVarsUsed=array();
$rowdividList=array(); // list of subquestions needing relevance entries
/* All function for expression manager */
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."expressions/em_javascript.js");
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."expressions/em_javascript.js" );
/* Call the function when trigerring event */
App()->getClientScript()->registerScript("triggerEmClassChange","triggerEmClassChange();\n",CClientScript::POS_END);
App()->getClientScript()->registerScript("triggerEmClassChange","triggerEmClassChange();\n",CClientScript::POS_END, array("class"=>"toRemoveOnAjax"));

$jsParts[] = "\n<script type='text/javascript'>\n<!--\n";
$jsParts[] = "var LEMmode='" . $LEM->surveyMode . "';\n";
Expand Down
27 changes: 11 additions & 16 deletions templates/default/views/subviews/head.twig
Expand Up @@ -71,22 +71,17 @@
success : function(body_html, statut){
$("body").empty().append(body_html);
// This chunk of script will eval all the scripts of the loaded body
var scriptElements = $("body").find('script');
for (i = 0; i < scriptElements.length; i ++) {
var scriptElement = document.createElement('SCRIPT');
scriptElement.type = 'text/javascript';
if (!scriptElements[i].src) {
scriptElement.innerHTML = scriptElements[i].innerHTML;
} else {
scriptElement.src = scriptElements[i].src;
}
document.head.appendChild(scriptElement);
}
$('.toRemoveOnAjax').each(function(){
$(this).remove();
});
var $dataScripts = $(body_html).filter('script');
$("body").empty().append($.parseHTML(body_html));
$dataScripts.each(function() {
$(this).attr('type', 'text/javascript').addClass('toRemoveOnAjax').appendTo('head');
});
// We reapply the function to the new form
ajaxSubmit();
Expand Down

0 comments on commit 74c00e4

Please sign in to comment.