summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/ionic-plugin-keyboard/src/blackberry10/index.js
blob: a91b94a2dda3255681df8b6747303d3a9719986a (plain)
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
var keyboard,
	resultObjs = {},
	threadCallback = null,
	_utils = require("../../lib/utils");
	_event = require("../../lib/event");
	_webview = require("../../lib/webview");

module.exports = {

	// Code can be declared and used outside the module.exports object,
	// but any functions to be called by client.js need to be declared
	// here in this object.

	// These methods call into JNEXT.Keyboard which handles the
	// communication through the JNEXT plugin to keyboard_js.cpp
	startService: function (success, fail, args, env) {
	var result = new PluginResult(args, env);

	result.ok(keyboard.getInstance().startService(), false);
	},
	show: function (success, fail, args, env) {
		var result = new PluginResult(args, env);

		result.ok(keyboard.getInstance().showKeyboard(), false);
	},
	close: function (success, fail, args, env) {
	var result = new PluginResult(args, env);

	result.ok(keyboard.getInstance().closeKeyboard(), false);
	}
};

keyboardShow = function(a){
	_webview.executeJavascript("cordova.plugins.Keyboard.isVisible = true");
	_webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardshow',"+a+")");
};
keyboardHide = function(){
	_webview.executeJavascript("cordova.plugins.Keyboard.isVisible = false");
	_webview.executeJavascript("cordova.fireDocumentEvent('native.keyboardhide','')");
};
onStart = function() {
	_webview.executeJavascript("cordova.exec("+null+", "+null+", 'Keyboard', 'startService', '')");
};

setTimeout(onStart,2000);

///////////////////////////////////////////////////////////////////
// JavaScript wrapper for JNEXT plugin for connection
///////////////////////////////////////////////////////////////////

JNEXT.Keyboard = function () {
	var self = this,
		hasInstance = false;

	self.getId = function () {
		return self.m_id;
	};

	self.init = function () {
		if (!JNEXT.require("libKeyboard")) {
			return false;
		}

		self.m_id = JNEXT.createObject("libKeyboard.Keyboard_JS");

		if (self.m_id === "") {
			return false;
		}

		JNEXT.registerEvents(self);
	};

	// ************************
	// Enter your methods here
	// ************************

	// calls into InvokeMethod(string command) in keyboard_js.cpp
	self.startService = function () {
		return JNEXT.invoke(self.m_id, "startService");
	};
	self.showKeyboard = function () {
		return JNEXT.invoke(self.m_id, "showKeyboard");
	};
	self.closeKeyboard = function () {
		return JNEXT.invoke(self.m_id, "closeKeyboard");
	};

	self.onEvent = function (strData) { // Fired by the Event framework (used by asynchronous callbacks)
		var arData = strData.split(" "),
		strEventDesc = arData[0],
		jsonData;

		if (strEventDesc === "native.keyboardshow") {
			jsonData = arData.slice(1, arData.length).join(" ");
			keyboardShow(jsonData);
		}
		else if (strEventDesc === "native.keyboardhide") {
			keyboardHide();
		}
	};

	// Thread methods
	self.keyboardStartThread = function (callbackId) {
		return JNEXT.invoke(self.m_id, "keyboardStartThread " + callbackId);
	};
	self.keyboardStopThread = function () {
		return JNEXT.invoke(self.m_id, "keyboardStopThread");
	};

	// ************************
	// End of methods to edit
	// ************************
	self.m_id = "";

	self.getInstance = function () {
		if (!hasInstance) {
			hasInstance = true;
			self.init();
		}
		return self;
	};

};

keyboard = new JNEXT.Keyboard();