-
Notifications
You must be signed in to change notification settings - Fork 1
/
vk_iframe.js
169 lines (162 loc) · 5.19 KB
/
vk_iframe.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
/**
* $Id$
*
* Keyboard Iframe mode loader
*
* This software is protected by patent No.2009611147 issued on 20.02.2009 by Russian Federal Service for Intellectual Property Patents and Trademarks.
*
* @author Ilya Lebedev
* @copyright 2006-2011 Ilya Lebedev <[email protected]>
* @version $Rev$
* @lastchange $Author$ $Date$
* @class IFrameVirtualKeyboard
* @constructor
*/
IFrameVirtualKeyboard = new function() {
var self = this;
/**
* popup window handler
*
* @type {Window}
* @scope private
*/
var hWnd = null;
/**
* Frame with the keyboard
*
* @type {HTMLIFrame}
* @scope private
*/
var iFrame = null;
/**
* path to this file
*
* @type {String}
*/
var p = (function (sname) {var h =document.getElementsByTagName('html')[0].innerHTML,sr=new RegExp('<scr'+'ipt[^>]+?src\\s*=\\s*["\']?([^>]+?/|)'+sname+'([^"\'\\s]*)[^>]*>(.|[\r\n])*?</scr'+'ipt>','i'),m =h.match(sr);if (m) {if (m[1].match(/^((https?|file)\:\/{2,}|\w:[\\])/)) return [m[1],m[2]];if (m[1].indexOf("/")==0) return [m[1],m[2]];var b = document.getElementsByTagName('base');if (b[0] && b[0].href) return [b[0].href+m[1],m[2]];return [(document.location.href.match(/(.*[\/\\])/)[0]+m[1]).replace(/^\/+/,""),m[2]];}return [null,null];})('vk_iframe.js');
/**
* Tells, if the keyboard is open
*
* @return {Boolean}
* @scope public
*/
self.isOpen = function () {
return null!=hWnd && !hWnd.closed;
}
/**
* Target input
*
* @type {String}
* @scope private
*/
var tgt = null;
/**
* Attaches keyboard to the specified input field
*
* @param {Null, HTMLInputElement,String} element to attach keyboard to
* @return {HTMLInputElement, Null}
* @access public
*/
self.attachInput = function(el) {
if (hWnd&&hWnd.VirtualKeyboard)
return hWnd.VirtualKeyboard.attachInput(el);
return false;
}
/**
* Shows keyboard
*
* @param {HTMLElement, String} input element or it to bind keyboard to
* @return {Boolean} operation state
* @scope public
*/
self.open =
self.show = function (target,holder) {
var retval = false;
if ('string' == typeof holder)
holder = document.getElementById(holder);
if ('string' == typeof target)
target = document.getElementById(target);
if (target)
tgt = target;
if (!tgt)
return false;
if (!hWnd) {
if (holder) {
/*
* create frame only if holder passed
*/
var div = document.createElement('div');
div.innerHTML = "<iframe frameborder=\"0\" src=\""+p[0]+"vk_iframe.html"+p[1]+"\"></iframe>";
iFrame = div.firstChild;
retval = true;
}
} else if (!self.isOpen()) {
iFrame.style.display = 'block';
if (hWnd.VirtualKeyboard) {
hWnd.VirtualKeyboard.show( tgt
,hWnd.document.body
);
}
iFrame.style.height = hWnd.document.body.firstChild.offsetHeight+'px';
iFrame.style.width = hWnd.document.body.firstChild.offsetWidth+'px';
retval = true;
}
if (holder && iFrame && holder != iFrame.parentNode) {
/*
* if another valid holder passed, attach keyboard there
*/
holder.appendChild(iFrame);
}
return retval;
}
/**
* Hides keyboard
*
* @scope public
*/
self.close =
self.hide = function (target) {
if (self.isOpen()) {
iFrame.style.display='none';
if (hWnd.VirtualKeyboard) {
hWnd.VirtualKeyboard.close();
}
}
}
/**
* Returns open state
*
*
*/
self.isOpen = function () {
return iFrame&&'block'==iFrame.style.display;
}
/**
* Toggles keyboard state
*
* @param {HTMLElement, String} input element or it to bind keyboard to
* @param {HTMLElement, String} holder to draw keyboard in
* @return {Boolean} operation state
* @access public
*/
self.toggle = function (input,holder) {
self.isOpen()?self.close():self.open(input,holder);
}
/**
* Onload callback event, invoked from the target window when onload event fires
*
* @scope protected
*/
self.onload = function () {
hWnd = (iFrame.contentWindow||iFrame.contentDocument.window);
this.close();
/*
* set class names to add some styling to html, body
*/
hWnd.document.body.className = hWnd.document.body.parentNode.className = 'VirtualKeyboardPopup';
while (hWnd.document.body.firstChild) {
hWnd.document.body.removeChild(hWnd.document.body.firstChild);
}
this.show();
}
}