SyntaxHighlighting sur windows.open
hello :ccool:
je voudrais appliquer � posteriori la fonction SyntaxHighlighter.all() sur une window ouverte sur un onclick, dont le contenu a �t� modifi�. en grous ouvrir un fichier du site avec coloration syntaxique dans une nouvelle fen�tre, rien de m�chant.
la fen�tre OpenWindow est construite � partir d'un template relatif � l'url du site, et contient une balise avec id � modifier. Je fais cela avec $.get(theUrl, function(dataUrl) {}
J'arrive bien � cr�er une nouvelle fen�tre avec le contenu du template, et � modifier la balise.
Le probl�me c'est la fonction SyntaxHighlighter.all() qui
- soit ne s'applique pas
- soit revert le contenu modifi� de la balise
voil� la fonction qui marche :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| function brushThis(filename) {
var theTemplateUrl=encodeURI('http://' + window.location.host + '/CV/' + "template.html");
var theUrl=encodeURI('http://' + window.location.host + '/CV/' + filename);
var OpenWindow = window.open(theTemplateUrl);
OpenWindow.onload = function(){
preToBrush = this.document.getElementById("preToBrush");
$.get(theUrl, function(dataUrl) {
preToBrush.innerHTML = dataUrl;
});
OpenWindow.onload = OpenWindow.SyntaxHighlighter.all();
};
} |
et voil� le template:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<!-- http://htmlhelp.com/tools/validator/doctype.html -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushJScript.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCore.css">
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeDefault.css">
</head>
<body>
<pre id="preToBrush" class="brush: js">
//empty
var aa='bb';
</pre>
</body>
</html> |
et on l'appelle comme ceci:
Code:
<a href="javascript:void(0)" onclick="brushThis('path/fileToShow.js'); return false;">clickme</a>
j'ai mis 10mn � faire cr�er le code fonctionnel avec la modif de la balise, mais pass� plus de 5 heures sur le post-apply de la fonction de highlight.
rien � faire, quand la fonction passe le texte r�cup�r� dispara�t et je ne comprend pas pourquoi.
besoin d'aiiiideuuuuuuu plzzzzz :cry: