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: