-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.js
More file actions
149 lines (140 loc) · 5.83 KB
/
Copy pathdashboard.js
File metadata and controls
149 lines (140 loc) · 5.83 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
$(function () {
// To expand lists in sidebar
$('#sessions_list span:first').on('click', function () {
var icon = $(this).children('i')
icon.toggleClass('fa-angle-right');
icon.toggleClass('fa-angle-down');
if (icon.hasClass('fa-angle-right'))
$('#sessions_list').children('li').css('display', 'none');
if (icon.hasClass('fa-angle-down'))
$('#sessions_list').children('li').css('display', 'block');
});
var iframe = document.getElementsByTagName('iframe')[0];
// For iframe editable
iframe.contentDocument.body.contentEditable = "true";
// For integrating mathjax
var math_script = iframe.contentDocument.createElement('script');
math_script.type = 'text/javascript';
math_script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML';
math_script.async = true;
iframe.contentDocument.head.appendChild(math_script);
math_script.onload = function () {
// For configuring Latex
iframe.contentWindow.MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$', '$']], // for allowing use of $
processEscapes: true, // for interpreting \$ as literal $
preview: '[math]', // text to display while processing
skipTags: ["script", "noscript", "style", "pre", "code"], //for ignoring these tags
},
showProcessingMessages: false,
messageStyle: 'none',
jax: ['input/TeX', 'output/SVG']
// Use MathJax.Hub.Typeset() to re-run typesetting
});
};
function toggleTypeset() {
var HTML = iframe.contentWindow.MathJax.HTML, jax = iframe.contentWindow.MathJax.Hub.getAllJax();
for (var i = 0, m = jax.length; i < m; i++) {
var script = jax[i].SourceElement(), tex = jax[i].originalText;
if (script.type.match(/display/)) { tex = "\\[" + tex + "\\]" } else { tex = "$" + tex + "$" }
jax[i].Remove();
var preview = script.previousSibling;
script.parentNode.removeChild(preview);
preview = document.createTextNode(tex);
script.parentNode.insertBefore(preview, script);
script.parentNode.removeChild(script);
}
}
var mathjax_show = false;
$('#preview_latex').on('click', function () {
if (mathjax_show) {
mathjax_show = false;
$('#preview_latex').css({ 'background': 'springgreen', 'color': 'black' });
$('#preview_latex').html('Preview LaTeX');
toggleTypeset();
}
else {
mathjax_show = true;
$('#preview_latex').css({ 'background': '#F44336', 'color': 'floralwhite' });
$('#preview_latex').html('View Code');
iframe.contentWindow.MathJax.Hub.Typeset();
}
});
var font_css = iframe.contentDocument.createElement('link');
font_css.rel = 'stylesheet';
font_css.href = 'https://fonts.googleapis.com/css?family=Quicksand:400,700';
iframe.contentDocument.head.appendChild(font_css);
iframe.contentDocument.body.style.fontFamily = 'quicksand';
// for iframe resize
iframe.contentDocument.body.style.overflowY = 'hidden';
iframe.contentDocument.body.style.whiteSpace = 'pre-wrap';
iframe.contentDocument.body.style.wordWrap = 'break-word';
iframe.contentDocument.execCommand('styleWithCSS', false, false);
iframe.contentDocument.body.spellcheck = false;
function resize() {
var top = document.getElementById('site').scrollTop;
var left = document.getElementById('site').scrollLeft;
iframe.height = 'auto';
iframe.height = iframe.contentDocument.body.scrollHeight + 'px';
document.getElementById('site').scrollTo(left, top);
}
function delayedResize() {
setTimeout(resize, 0);
}
iframe.contentDocument.body.addEventListener('cut', delayedResize);
iframe.contentDocument.body.addEventListener('keydown', delayedResize);
iframe.contentDocument.body.addEventListener('drop', function (e) {
var data = e.dataTransfer.getData("text/plain");
iframe.contentDocument.body.focus();
console.log(iframe.contentDocument.execCommand('insertText', false, data));
e.preventDefault();
delayedResize();
});
iframe.contentDocument.body.addEventListener('paste', function (e) {
e.preventDefault();
var pastedText = undefined;
if (window.clipboardData && window.clipboardData.getData) { // IE
pastedText = window.clipboardData.getData('Text');
} else if (e.clipboardData && e.clipboardData.getData) {
pastedText = e.clipboardData.getData('text/plain');
}
// pastedText = pastedText.replace(/[^\x00-\x7F]/gm, "");
prevent_paste = false;
iframe.contentDocument.execCommand('insertText', false, pastedText);
delayedResize();
return true;
});
// For editor buttons
var commands = ['bold', 'italic', 'strikethrough', 'underline', 'insertOrderedList', 'insertUnorderedList', 'indent', 'outdent', 'superscript', 'subscript', 'justifyFull', 'justifyLeft', 'justifyRight', 'justifyCenter'];
function click_events(command) {
return function () {
iframe.contentDocument.execCommand(command, false, null);
iframe.contentWindow.document.body.focus();
check_formatting();
}
}
for (var i = 0; i < commands.length; i++) {
$('.' + commands[i]).on('click', click_events(commands[i]));
}
// For changing colors of editor bar
function check_formatting() {
var commands = ['bold', 'italic', 'strikethrough', 'underline', 'insertOrderedList', 'insertUnorderedList', 'indent', 'outdent', 'superscript', 'subscript', 'justifyFull', 'justifyLeft', 'justifyRight', 'justifyCenter'];
for (var i = 0; i < commands.length; i++) {
var elements = document.getElementsByClassName(commands[i]);
if (iframe.contentDocument.queryCommandState(commands[i])) {
for (var j = 0; j < elements.length; j++) {
elements[j].style.color = 'deepskyblue';
}
}
else for (var j = 0; j < elements.length; j++) {
elements[j].style.color = 'black';
}
}
}
// To change colors of editor bar
var things_to_check_for_editor = ['keydown', 'cut', 'paste', 'drop', 'click'];
for (var i = 0; i < things_to_check_for_editor.length; i++) {
iframe.contentDocument.body.addEventListener(things_to_check_for_editor[i], function () { setTimeout(check_formatting, 0) });
}
})