-
Notifications
You must be signed in to change notification settings - Fork 1
/
vk_popup.js
142 lines (142 loc) · 4.87 KB
/
vk_popup.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
/**
* $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 <ilya@lebedev.net>
* @version $Rev$
* @lastchange $Author$ $Date$
* @class PopupVirtualKeyboard
* @constructor
*/
PopupVirtualKeyboard = new function() {
var self = this;
/**
* popup window handler
*
* @type {Window}
* @scope private
*/
var hWnd = null;
/**
* Unload handler
*
* @type {Function}
* @scope private
*/
var unloadHandler;
/**
* 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_popup.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.closed && hWnd.VirtualKeyboard) {
return hWnd.VirtualKeyboard.attachInput(el);
}
return false
}
/**
* Shows keyboard
*
* @param {HTMLElement, String} input element or it to bind keyboard to
* @param {Function} unload monitor
* @return {Boolean} operation state
* @scope public
*/
self.open =
self.show = function (target, unload) {
if (!hWnd || hWnd.closed) {
var features = ["status=0","title=0","dependent=yes","dialog=yes","resizable=no","scroll=no","scrollbars=no","width=500","height=500"];
hWnd = (window.showModelessDialog||window.open)(p[0]+"vk_popup.html"+p[1],window,features.join(window.showModelessDialog?";":","));
unloadHandler = unload;
tgt = target;
return true;
}
return false;
}
/**
* Hides keyboard
*
* @scope public
*/
self.close =
self.hide = function (target) {
if (!hWnd || hWnd.closed) return false;
if (hWnd.VirtualKeyboard.isOpen()) hWnd.VirtualKeyboard.hide();
hWnd.close();
hWnd = null;
if ('function' == typeof unloadHandler) {
unloadHandler();
}
}
/**
* Toggles keyboard state
*
* @param {HTMLElement, String} input element or it to bind keyboard to
* @return {Boolean} operation state
* @access public
*/
self.toggle = function (input) {
self.isOpen()?self.close():self.open(input);
}
/**
* Onload callback event, invoked from the target window when onload event fires
*
* @scope protected
*/
self.onload = function () {
if ('string' == typeof tgt)
tgt = document.getElementById(tgt);
hWnd.VirtualKeyboard.show( tgt
,hWnd.document.body
);
/*
* set class names to add some styling to html, body
*/
hWnd.document.body.className = hWnd.document.body.parentNode.className = 'VirtualKeyboardPopup';
if (hWnd.sizeToContent) {
hWnd.sizeToContent();
} else {
var kbd = hWnd.document.body.firstChild;
while ("virtualKeyboard" != kbd.id) {
hWnd.document.body.removeChild(kbd);
kbd = hWnd.document.body.firstChild;
}
hWnd.dialogHeight = kbd.offsetHeight+'px';
hWnd.dialogWidth = kbd.offsetWidth+'px';
hWnd.resizeTo(kbd.offsetWidth+hWnd.DOM.getOffsetWidth()-hWnd.DOM.getClientWidth()
,kbd.offsetHeight+hWnd.DOM.getOffsetHeight()-hWnd.DOM.getClientHeight());
}
hWnd.onunload = self.close;
}
if (window.attachEvent) window.attachEvent('onunload', self.close);
else if (window.addEventListener) window.addEventListener('unload', self.close, false);
}