-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmathquilled.js
219 lines (195 loc) · 6.21 KB
/
mathquilled.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
var mqarea;
var mqmousebase;
$(function() {
$(window).load(function() {
hasTouch = 'ontouchstart' in document.documentElement;
mqarea = $('.mathquill-editable');
$('.mathquill-rendered-math').mathquill('redraw');
mqarea.find('textarea').focus();
if (!hasTouch) {
$('#mqee td.mqeebtn').bind('mouseover mouseup', function() {
if (!$(this).hasClass("mqeeactive")) {
$(this).addClass("mqeehighlight");
}
}).bind('mousedown', function () {
$(this).addClass("mqeeclick");
}).bind('mouseout', function () {
$(this).removeClass("mqeehighlight");
}).bind('mouseup', function () {
$(this).removeClass("mqeeclick");
}).bind('click',mqeeinsert);
$('#mqeetopbar').mousedown(function(evt) {
mqmousebase = {left:evt.pageX, top: evt.pageY};
$("body").bind('mousemove',mqeemousemove);
$("body").mouseup(function(event) {
var p = $('#mqee').offset();
lasteepos.left = p.left;
lasteepos.top = p.top;
$("body").unbind('mousemove',mqeemousemove);
$(this).unbind(event);
});
});
} else {
$('#mqee td.mqeebtn').bind('touchstart', function () {
$(this).addClass("mqeeclick");
}).bind('touchend', function () {
$(this).delay(500).removeClass("mqeeclick");
}).bind('touchend', mqeeinsert);
$('#mqeetopbar').bind('touchstart', function(evt) {
var touch = evt.originalEvent.changedTouches[0] || evt.originalEvent.touches[0];
mqmousebase = {left:touch.pageX, top: touch.pageY};
$("body").bind('touchmove',mqeetouchmove);
$("body").bind('touchend', function(event) {
var p = $('#mqee').offset();
lasteepos.left = p.left;
lasteepos.top = p.top;
$("body").unbind('touchmove',mqeetouchmove);
$(this).unbind(event);
});
});
}
});
//tabs
//from http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).show(); //Fade in the active ID content
return false;
});
//$("td.mqeebtn span.mathquill-rendered-math").mathquill().mathquill("redraw");
});
});
function mqPrepTabs(type,extras) { //type: 0 basic, 1 advanced. extras = 'interval' or 'ineq'
$(".tab_content").hide();
$("ul.tabs li").removeClass("active").each(function(index,el) {
if (index==0) {
if (type==0) {
$(el).addClass("active").show();
var activeTab = $(el).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).show();
} else {
$(el).hide();
}
} else if (index==1) {
if (type==1) {
$(el).addClass("active").show();
var activeTab = $(el).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).show();
} else {
$(el).hide();
}
} else if (index==2) {
if (extras=='int') {
$(el).show();
} else {
$(el).hide();
}
} else if (index==3) {
if (extras=='ineq') {
$(el).show();
} else {
$(el).hide();
}
} else {
if (type==1) {
$(el).show();
} else {
$(el).hide();
}
}
});
}
function mqeemousemove(evt) {
$('#mqee').css('left', (evt.pageX - mqmousebase.left) + lasteepos.left)
.css('top', (evt.pageY - mqmousebase.top) + lasteepos.top);
return false;
}
function mqeetouchmove(evt) {
var touch = evt.originalEvent.changedTouches[0] || evt.originalEvent.touches[0];
$('#mqee').css('left', (touch.pageX - mqmousebase.left) + lasteepos.left)
.css('top', (touch.pageY - mqmousebase.top) + lasteepos.top);
evt.preventDefault();
return false;
}
function mqeeinsert() {
var t = $(this).attr("btntext");
var type = $(this).attr("btntype");
t = t.replace('\\\\','\\');
if (type==0) {
mqarea.mathquill('cmd', t).find('textarea').focus();
} else if (type==1) {
mqarea.mathquill('write', t).find('textarea').focus();
} else if (type==2) {
mqarea.mathquill('writesimpfunc', t).find('textarea').focus();
} else if (type==3) {
mqarea.mathquill('writefunc', t).find('textarea').focus();
} else if (type==4) {
mqarea.mathquill('writeint', t).find('textarea').focus();
} else if (type==5) {
mqarea.mathquill('movecursor', t).find('textarea').focus();
}
}
var mqeeddclosetimer = null;
var cureedd = null;
var lasteepos = null;
function showeedd(eln,type,extras) {
if (mqeeddclosetimer) {
window.clearTimeout(mqeeddclosetimer);
mqeeddclosetimer = null;
}
hideee();
cureedd = {"id":eln, "type":type, "extras": extras};
var dd = $("#mqeedd");
var el = $("#"+eln);
var p = el.offset();
p.left += el.outerWidth();
dd.css('left',p.left+"px").css('top',p.top+"px").height(el.outerHeight()-2).show();
}
function hideeedd() {
mqeeddclosetimer = setTimeout(function() {$("#mqeedd").hide();}, 250);
}
function mqeetoggleactive(n) {
for (var i=1; i<=5; i++) {
if (n==i) {
$('#mqeetab'+i).addClass('mqeeactive').removeClass("mqeehighlight");
document.getElementById("mqee"+i).style.display = "";
} else {
document.getElementById("mqee"+i).style.display = "none";
$('#mqeetab'+i).removeClass('mqeeactive');
}
}
mqeeactivetab = n;
mqarea.find('textarea').focus();
}
function showee() {
mqPrepTabs(cureedd.type - 3,cureedd.extras);
var mqee = $("#mqee");
if (!lasteepos) {
lasteepos = {
left: ($(window).width() - mqee.outerWidth())/2,
top: $(window).scrollTop() + ((window.innerHeight ? window.innerHeight : $(window).height()) - mqee.outerHeight())/2,
scroll: $(window).scrollTop()
};
} else {
var scrollchg = $(window).scrollTop() - lasteepos.scroll;
lasteepos.top = lasteepos.top + scrollchg;
lasteepos.scroll = $(window).scrollTop();
}
mqee.css('left',lasteepos.left).css('top',lasteepos.top).show();
mqarea.mathquill('latex', AMtoMQ($("#"+cureedd.id).val()));
mqarea.find('textarea').focus();
}
function hideee() {
$("#mqee").hide();
}
function savemathquill() {
$("#"+cureedd.id).val(MQtoAM(mqarea.mathquill('latex')));
hideee();
}