-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmobile.js
46 lines (42 loc) · 1.46 KB
/
mobile.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
// code needed for mobile insertion point tricks for iphone
/**
* Focus the text input box, which causes the onscreen
* keyboard to display.
*/
Richie.prototype.focusTextbox = function() {
if( this.m_keyboardInput.focused == undefined ) {
this.m_keyboardInput.focused = false;
}
Richie.trace( this.m_keyboardInput.focused );
if( this.m_keyboardInput.focused == false ) {
Richie.trace( "focusing input textbox" );
this.m_keyboardInput.focused = true;
this.m_keyboardInput.focus();
}
else {
Richie.trace( "not refocusing input textbox" );
}
}
/**
* updated the absolute position of the input control that receives
* text input. There is a fudge factor here that lines the cursor up with
* the text that is slightly different on different devices. TODO: find a
* better way of getting positioning right across different devices.
*/
Richie.prototype.repositionInputBox = function() {
this.m_keyboardInput.style.top = this.m_cursor.offsetTop - 2 + "px";
this.m_keyboardInput.style.left = this.m_cursor.offsetLeft - 6 + "px";
}
/**
* On mobile devices we have to fool the phone into thinking that
* an html input box is active. We do this via a floating input control
* that remains focused at all times. This method inserts the text
* box into the dom initially.
*/
Richie.prototype.insertKeyboardInput = function() {
var el = document.createElement( 'input' );
el.type = 'text';
el.id = 'keyboardinput';
this.m_editor.appendChild( el );
this.m_keyboardInput = el;
}