Skip to content

Commit

Permalink
Extracted export-related scripting to export.js
Browse files Browse the repository at this point in the history
  • Loading branch information
isagalaev committed Oct 7, 2014
1 parent 816f122 commit 354a3e9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
30 changes: 30 additions & 0 deletions demo/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Highlighted code export © Vladimir Gubarkov <[email protected]>
String.prototype.escape = function() {
return this.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
};

function ExportDoIt() {
var export_from = document.getElementById("export_from");
var export_to = document.getElementById("export_to");
var export_view = document.getElementById("export_view");
var selector = document.getElementById("langSelector");
var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase();
if (selectedLang) {
export_view.innerHTML = '<pre><code class="' + selectedLang + '">' + export_from.value.escape() + "</code></pre>";
} else { // try auto
export_view.innerHTML = '<pre><code>' + export_from.value.escape() + "</code></pre>";
}
hljs.highlightBlock(export_view.firstChild.firstChild);
export_to.value = export_view.innerHTML;
}

function ExportCopyToBuffer(textToCopy) {
if (window.clipboardData) { // IE
window.clipboardData.setData("Text", textToCopy);
} else if (window.netscape) { // FF
// from http://developer.mozilla.org/en/docs/Using_the_Clipboard
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(textToCopy);
}
}
33 changes: 1 addition & 32 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,8 @@
$(document).ready(hljs.initHighlighting);
</script>
<script src="detection.js"></script>
<script src="export.js"></script>

<script>
// Highlighted code export © Vladimir Gubarkov <[email protected]>
String.prototype.escape = function() {
return this.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
};

function ExportDoIt() {
var export_from = document.getElementById("export_from");
var export_to = document.getElementById("export_to");
var export_view = document.getElementById("export_view");
var selector = document.getElementById("langSelector");
var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase();
if (selectedLang) {
export_view.innerHTML = '<pre><code class="' + selectedLang + '">' + export_from.value.escape() + "</code></pre>";
} else { // try auto
export_view.innerHTML = '<pre><code>' + export_from.value.escape() + "</code></pre>";
}
hljs.highlightBlock(export_view.firstChild.firstChild);
export_to.value = export_view.innerHTML;
}

function ExportCopyToBuffer(textToCopy) {
if (window.clipboardData) { // IE
window.clipboardData.setData("Text", textToCopy);
} else if (window.netscape) { // FF
// from http://developer.mozilla.org/en/docs/Using_the_Clipboard
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
gClipboardHelper.copyString(textToCopy);
}
}
</script>
<body>
<div id="header">
<h1><a href="https://highlight.js.org/">highlight.js</a> demo</h1>
Expand Down

0 comments on commit 354a3e9

Please sign in to comment.