/
common.js
executable file
·75 lines (67 loc) · 2.04 KB
/
common.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
var timeout = null;
var reset = null;
function exec_command(cmd) {
if (typeof fireToPython != 'undefined') {
if(typeof fireToPython.send == 'function') {
fireToPython.send(cmd)
}
} else {
window.location = cmd;
}
}
function show_notice(message, type) {
$('#alert-label').html(message);
$('#alert-message').fadeIn();
$('#alert-message').addClass(type);
timeout = setTimeout(function(){hide_notice()}, 5000);
}
function hide_notice(force) {
clearTimeout(timeout);
if (force == undefined)
$('#alert-message').fadeOut();
else if (force == true)
$('#alert-message').hide();
reset = setTimeout(function(){reset_notice()}, 500);
}
function reset_notice() {
clearTimeout(reset);
$('#alert-label').html('');
$('#alert-message').removeClass('error');
$('#alert-message').removeClass('warning');
$('#alert-message').removeClass('info');
}
function packstr(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}
new function($) {
$.fn.getCursorPosition = function() {
var pos = 0;
var el = $(this).get(0);
// IE Support
if (document.selection) {
el.focus();
var Sel = document.selection.createRange();
var SelLength = document.selection.createRange().text.length;
Sel.moveStart('character', -el.value.length);
pos = Sel.text.length - SelLength;
}
// Firefox support
else if (el.selectionStart || el.selectionStart == '0')
pos = el.selectionStart;
return pos;
}
} (jQuery);
new function($) {
$.fn.setCursorPosition = function(pos) {
var el = $(this).get(0);
if (el.setSelectionRange) {
el.setSelectionRange(pos, pos);
} else if (el.createTextRange) {
var range = el.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
}(jQuery);