Touchgui/plugins/org.apache.cordova.vibration/src/blackberry10/index.js

changeset 0
e8ccd40d0ef6
equal deleted inserted replaced
-1:000000000000 0:59a5846766fd
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 var vibration;
23
24 module.exports = {
25 vibrate: function (success, fail, args, env) {
26 var result = new PluginResult(args, env),
27 duration = args[0],
28 response = vibration.getInstance().vibrate(duration);
29 result.ok(response, false);
30 }
31 };
32
33 ///////////////////////////////////////////////////////////////////
34 // JavaScript wrapper for JNEXT plugin
35 ///////////////////////////////////////////////////////////////////
36
37 JNEXT.Vibration = function () {
38 var self = this,
39 hasInstance = false;
40
41 self.vibrate = function (duration) {
42 //This is how Javascript calls into native
43 return JNEXT.invoke(self.m_id, "vibrate " + duration);
44 };
45
46 self.init = function () {
47 //Checks that the jnext library is present and loads it
48 if (!JNEXT.require("libVibration")) {
49 return false;
50 }
51
52 //Creates the native object that this interface will call
53 self.m_id = JNEXT.createObject("libVibration.Vibration");
54
55 if (self.m_id === "") {
56 return false;
57 }
58
59 //Registers for the JNEXT event loop
60 JNEXT.registerEvents(self);
61 };
62
63 self.m_id = "";
64
65 //Used by JNEXT library to get the ID
66 self.getId = function () {
67 return self.m_id;
68 };
69
70 //Not truly required but useful for instance management
71 self.getInstance = function () {
72 if (!hasInstance) {
73 self.init();
74 hasInstance = true;
75 }
76 return self;
77 };
78 };
79
80 vibration = new JNEXT.Vibration();

mercurial