-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwee-ui.js
45 lines (40 loc) · 1.48 KB
/
jwee-ui.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
//////////////////////////////////////////////////////////////////////////
// JWee JavaScript Framework & Toolkit
// Copyright (c) 2010 AUTHORS ([email protected])
// Licensed under the MIT and GPL (for now).
// http://www.jwee.org
//////////////////////////////////////////////////////////////////////////
// USER INTERFACE STUFF
// ** UNDER CONSTRUCTION **
///////////////////////////////////////////////////
wee.ui = (function(){
///////////////////////////////////////////////////
function getSelection(element) {
if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
var stored = range.duplicate();
stored.moveToElementText(element);
stored.setEndPoint("EndToEnd", range);
element.selectionStart = stored.text.length - range.text.length;
element.selectionEnd = element.selectionStart + range.text.length;
}
return [element.selectionStart, element.selectionEnd];
}
function setSelection(element, range) {
element.focus();
element.selectionStart = range[0];
element.selectionEnd = range[1];
if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
range.moveStart("character", element.selectionStart);
range.moveEnd("character", element.selectionEnd - element.selectionStart);
range.select();
}
}
return {
getSelection: getSelection,
setSelection: setSelection
}
///////////////////////////////////////////////////
})();
///////////////////////////////////////////////////