forked from mathquill/mathquill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublicapi.js
67 lines (62 loc) · 2.19 KB
/
publicapi.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
/*********************************************************
* The actual jQuery plugin and document ready handlers.
********************************************************/
//The publicy exposed method of jQuery.prototype, available (and meant to be
//called) on jQuery-wrapped HTML DOM elements.
$.fn.mathquill = function(cmd, latex) {
switch (cmd) {
case 'redraw':
this.find(':not(:has(:first))')
.data(jQueryDataKey).cmd.redraw();
return this;
case 'revert':
return this.each(function() {
var data = $(this).data(jQueryDataKey);
if (data && data.revert)
data.revert();
});
case 'latex':
if (arguments.length > 1) {
return this.each(function() {
var data = $(this).data(jQueryDataKey);
if (data && data.block && data.block.renderLatex)
data.block.renderLatex(latex);
});
}
var data = this.data(jQueryDataKey);
return data && data.block && data.block.latex();
case 'text':
var data = this.data(jQueryDataKey);
return data && data.block && data.block.text();
case 'html':
return this.html().replace(/<span class="?cursor( blink)?"?><\/span>/i, '')
.replace(/<span class="?textarea"?><textarea><\/textarea><\/span>/i, '');
case 'write':
if (arguments.length > 1)
return this.each(function() {
var data = $(this).data(jQueryDataKey),
block = data && data.block,
cursor = block && block.cursor;
if (cursor) {
cursor.writeLatex(latex);
block.blur();
}
});
default:
var textbox = cmd === 'textbox',
include_toolbar = cmd === 'editor',
editable = include_toolbar || textbox || cmd === 'editable',
RootBlock = textbox ? RootTextBlock : RootMathBlock;
return this.each(function() {
createRoot($(this), new RootBlock, textbox, editable, include_toolbar);
});
}
};
//on document ready, mathquill-ify all `<tag class="mathquill-*">latex</tag>`
//elements according to their CSS class.
$(function() {
$('.mathquill-editable').mathquill('editable');
$('.mathquill-editor').mathquill('editor');
$('.mathquill-textbox').mathquill('textbox');
$('.mathquill-embedded-latex').mathquill();
});