-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStatax.js
88 lines (73 loc) · 2.81 KB
/
Statax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Developed by E. F. Haghish http://www.haghish.com/
Center for Medical Biometry and Medical Informatics
University of Freiburg, Germany
for documentation visit http://www.haghish.com/statax
This file loads sh_main.js, stataxsource.js, and Statax.css files and also
highlight syntax of Global Macros in Stata.
*/
//********************************************************
//* LOAD JQuery
//********************************************************
function include(filename, onload) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
script.onload = script.onreadystatechange = function() {
if (script.readyState) {
if (script.readyState === 'complete' || script.readyState === 'loaded') {
script.onreadystatechange = null;
onload();
}
}
else {
onload();
}
};
head.appendChild(script);
}
include('https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', function() {
$(document).ready(function() {
//********************************************************
//* JQuery script for highlighting Stata Global Macro
//********************************************************
$(document).ready(function(){
$("pre.sh_stata").html(function(_, html){
return html.replace(/(\$\w+)/g,'<span class="sh_macro">$1</span>');
});
});
});
});
//********************************************************
//* LOAD Statax.js
//********************************************************
var imported = document.createElement('script');
imported.src = 'StataxSource.js';
document.head.appendChild(imported);
var imported2 = document.createElement('script');
imported2.src = 'http://haghish.com/statax/sh_main.js';
document.head.appendChild(imported2);
//********************************************************
//* LOAD THE Statax.css
//********************************************************
var cssId = 'myCss'; // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'http://haghish.com/statax/Statax.css';
link.media = 'all';
head.appendChild(link);
//********************************************************
//* AUTOMATICALLY RUN SCRIPT
//********************************************************
window.onload = function()
{
sh_highlightDocument();
};
}