├── LICENSE ├── README.md ├── SMS.js ├── bower.json ├── digitsCordova.js ├── inappbrowser.js └── telephonenumber.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Yang Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # digits-cordova 2 | Integrating digits with cordova 3 | Additionally, this package can autofill phone number and even intercept SMS 4 | 5 | ## Installation 6 | ``` 7 | bower install digits-cordova 8 | cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git 9 | 10 | /* Optional cordova plugins */ 11 | cordova plugin add com.simonmacdonald.telephonenumber 12 | cordova plugin add com.rjfun.cordova.sms 13 | ``` 14 | 15 | In your index.html page 16 | 17 | ```html 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | ``` 28 | 29 | ##Usage 30 | 31 | ```html 32 | 33 | ``` 34 | 35 | ```javascript 36 | function openDigits(){ 37 | var digits = new DigitsCordova('gmoaaZhEG88hMQUdpWHnF1IAz', 'http://cannonballapp.io/'); //Replace with your own consumerKey and your url 38 | digits.open() 39 | .successCallback(function(loginResponse){ 40 | var oAuthHeaders = loginResponse.oauth_echo_headers; 41 | var verifyData = { 42 | authHeader: oAuthHeaders['X-Verify-Credentials-Authorization'], 43 | apiUrl: oAuthHeaders['X-Auth-Service-Provider'] 44 | }; 45 | 46 | $.post('/verify', verifyData) 47 | .done(function(){ window.reload(); }); 48 | }).failCallback(function(error){ 49 | //error 50 | }).errorCallback(function(error){ 51 | //error 52 | }) 53 | } 54 | ``` 55 | 56 | ##API 57 | ```javascript 58 | new DigitsCordova('consumerKey', 'http://yourUrl', options) 59 | .successCallback(loginCallback) //When user successfully logs in 60 | .failCallback(failedLoginCallback) //When user failed to login 61 | .errorCallback(errorOccurredCallback) //If digits was not rendered properly 62 | ``` 63 | 64 | ###Options include 65 | ####autoFill {boolean}(default: true) 66 | By setting this true, and if com.simonmacdonald.telephonenumber is installed properly then the app will automatically fill the phone number and country code 67 | 68 | ####smsIntercept {boolean}(default: true) 69 | By setting this true, and if com.rjfun.cordova.sms is installed properly the app will intercept sms after user has requested for one. This will turn itself off when digits is closed. 70 | 71 | ####autoProceed {boolean}(default: true) 72 | By setting this true and if sms is being intercepted then it will automatically confirm and close digits when the sms is intercepted properly. 73 | 74 | *Additionally, if you don't include the phonenumber and sms cordova packages, these will not work. 75 | 76 | ```javascript 77 | new DigitsCordova('consumerKey', 'http://yourUrl', {autoFill: false, smsIntercept: false, autoProceed: false}) 78 | .successCallback(loginCallback) //When user successfully logs in 79 | .failCallback(failedLoginCallback) //When user failed to login 80 | .errorCallback(errorOccurredCallback) //If digits was not rendered properly 81 | ``` 82 | ##License 83 | The MIT License (MIT) 84 | 85 | Copyright (c) 2015 Yang Li 86 | 87 | Permission is hereby granted, free of charge, to any person obtaining a copy 88 | of this software and associated documentation files (the "Software"), to deal 89 | in the Software without restriction, including without limitation the rights 90 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 91 | copies of the Software, and to permit persons to whom the Software is 92 | furnished to do so, subject to the following conditions: 93 | 94 | The above copyright notice and this permission notice shall be included in all 95 | copies or substantial portions of the Software. 96 | 97 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 98 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 99 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 100 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 101 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 102 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 103 | SOFTWARE. 104 | -------------------------------------------------------------------------------- /SMS.js: -------------------------------------------------------------------------------- 1 | var argscheck = require('cordova/argscheck'), 2 | exec = require('cordova/exec'); 3 | 4 | var safesmsExport = {}; 5 | 6 | /* 7 | * Methods 8 | */ 9 | 10 | /* 11 | * set options: 12 | * { 13 | * position: integer, // default position 14 | * x: integer, // default X of banner 15 | * y: integer, // default Y of banner 16 | * isTesting: boolean, // if set to true, to receive test ads 17 | * autoShow: boolean, // if set to true, no need call showBanner or showInterstitial 18 | * } 19 | */ 20 | safesmsExport.setOptions = function(options, successCallback, failureCallback) { 21 | if(typeof options === 'object') { 22 | cordova.exec( successCallback, failureCallback, 'SMS', 'setOptions', [options] ); 23 | } else { 24 | if(typeof failureCallback === 'function') { 25 | failureCallback('options should be specified.'); 26 | } 27 | } 28 | }; 29 | 30 | safesmsExport.startWatch = function(successCallback, failureCallback) { 31 | cordova.exec( successCallback, failureCallback, 'SMS', 'startWatch', [] ); 32 | }; 33 | 34 | safesmsExport.stopWatch = function(successCallback, failureCallback) { 35 | cordova.exec( successCallback, failureCallback, 'SMS', 'stopWatch', [] ); 36 | }; 37 | 38 | safesmsExport.enableIntercept = function(on_off, successCallback, failureCallback) { 39 | on_off = !! on_off; 40 | cordova.exec( successCallback, failureCallback, 'SMS', 'enableIntercept', [ on_off ] ); 41 | }; 42 | 43 | safesmsExport.sendSMS = function(address, text, successCallback, failureCallback) { 44 | var numbers; 45 | if( Object.prototype.toString.call( address ) === '[object Array]' ) { 46 | numbers = address; 47 | } else if(typeof address === 'string') { 48 | numbers = [ address ]; 49 | } else { 50 | if(typeof failureCallback === 'function') { 51 | failureCallback("require address, phone number as string, or array of string"); 52 | } 53 | return; 54 | } 55 | 56 | cordova.exec( successCallback, failureCallback, 'SMS', 'sendSMS', [ numbers, text ] ); 57 | }; 58 | 59 | safesmsExport.listSMS = function(filter, successCallback, failureCallback) { 60 | cordova.exec( successCallback, failureCallback, 'SMS', 'listSMS', [ filter ] ); 61 | }; 62 | 63 | safesmsExport.deleteSMS = function(filter, successCallback, failureCallback) { 64 | cordova.exec( successCallback, failureCallback, 'SMS', 'deleteSMS', [ filter ] ); 65 | }; 66 | 67 | safesmsExport.restoreSMS = function(msg, successCallback, failureCallback) { 68 | var smsList = []; 69 | if(Array.isArray(msg)) { 70 | if(msg.length > 0) smsList = msg; 71 | } else if(typeof msg === 'object') { 72 | if(msg !== null) smsList = [ msg ]; 73 | } 74 | cordova.exec( successCallback, failureCallback, 'SMS', 'restoreSMS', [ msg ] ); 75 | }; 76 | 77 | /* 78 | * Events: 79 | * 80 | * document.addEventListener('onSMSArrive', function(e) { var sms = e.data; } 81 | * 82 | */ 83 | 84 | module.exports = safesmsExport; -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "digits-cordova", 3 | "version": "1.0.0", 4 | "main": ["digitsCordova.js", "inappbrowser.js", "telephonenumber.js", "SMS.js"], 5 | "description": "Integrating digits with cordova/phonegap apps", 6 | "keywords": [ 7 | "cordova", 8 | "phonegap", 9 | "digits" 10 | ], 11 | "authors": [ 12 | "Yang Li" 13 | ], 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /digitsCordova.js: -------------------------------------------------------------------------------- 1 | //-- Required Plugins -- 2 | //cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git 3 | 4 | //-- Optional Plugins -- 5 | //cordova plugin add com.simonmacdonald.telephonenumber 6 | //cordova plugin add com.rjfun.cordova.sms 7 | 8 | (function(window){ 9 | 10 | //Country data 11 | var regionCodes = { 12 | "+1": "US", 13 | "+93": "AF", 14 | "+358": "AX", 15 | "+355": "AL", 16 | "+213": "DZ", 17 | "+376": "AD", 18 | "+244": "AO", 19 | "+54": "AR", 20 | "+374": "AM", 21 | "+297": "AW", 22 | "+247": "AC", 23 | "+61": "AU", 24 | "+43": "AT", 25 | "+994": "AZ", 26 | "+973": "BH", 27 | "+880": "BD", 28 | "+375": "BY", 29 | "+32": "BE", 30 | "+501": "BZ", 31 | "+229": "BJ", 32 | "+975": "BT", 33 | "+591": "BO", 34 | "+387": "BA", 35 | "+267": "BW", 36 | "+55": "BR", 37 | "+246": "IO", 38 | "+673": "BN", 39 | "+359": "BG", 40 | "+226": "BF", 41 | "+257": "BI", 42 | "+855": "KH", 43 | "+237": "CM", 44 | "+238": "CV", 45 | "+599": "BQ", 46 | "+236": "CF", 47 | "+235": "TD", 48 | "+56": "CL", 49 | "+86": "CN", 50 | "+57": "CO", 51 | "+269": "KM", 52 | "+243": "CD", 53 | "+242": "CG", 54 | "+682": "CK", 55 | "+506": "CR", 56 | "+225": "CI", 57 | "+385": "HR", 58 | "+53": "CU", 59 | "+357": "CY", 60 | "+420": "CZ", 61 | "+45": "DK", 62 | "+253": "DJ", 63 | "+670": "TL", 64 | "+593": "EC", 65 | "+20": "EG", 66 | "+503": "SV", 67 | "+240": "GQ", 68 | "+291": "ER", 69 | "+372": "EE", 70 | "+251": "ET", 71 | "+500": "FK", 72 | "+298": "FO", 73 | "+679": "FJ", 74 | "+33": "FR", 75 | "+594": "GF", 76 | "+689": "PF", 77 | "+241": "GA", 78 | "+220": "GM", 79 | "+995": "GE", 80 | "+49": "DE", 81 | "+233": "GH", 82 | "+350": "GI", 83 | "+30": "GR", 84 | "+299": "GL", 85 | "+590": "GP", 86 | "+502": "GT", 87 | "+44": "GG", 88 | "+224": "GN", 89 | "+245": "GW", 90 | "+592": "GY", 91 | "+509": "HT", 92 | "+672": "HM", 93 | "+504": "HN", 94 | "+852": "HK", 95 | "+36": "HU", 96 | "+354": "IS", 97 | "+91": "IN", 98 | "+62": "ID", 99 | "+98": "IR", 100 | "+964": "IQ", 101 | "+353": "IE", 102 | "+972": "IL", 103 | "+39": "IT", 104 | "+81": "JP", 105 | "+962": "JO", 106 | "+7": "KZ", 107 | "+254": "KE", 108 | "+686": "KI", 109 | "+377": "XK", 110 | "+381": "XK", 111 | "+386": "XK", 112 | "+965": "KW", 113 | "+996": "KG", 114 | "+856": "LA", 115 | "+371": "LV", 116 | "+961": "LB", 117 | "+266": "LS", 118 | "+231": "LR", 119 | "+218": "LY", 120 | "+423": "LI", 121 | "+370": "LT", 122 | "+352": "LU", 123 | "+853": "MO", 124 | "+389": "MK", 125 | "+261": "MG", 126 | "+265": "MW", 127 | "+60": "MY", 128 | "+960": "MV", 129 | "+223": "ML", 130 | "+356": "MT", 131 | "+692": "MH", 132 | "+596": "MQ", 133 | "+222": "MR", 134 | "+230": "MU", 135 | "+262": "YT", 136 | "+52": "MX", 137 | "+691": "FM", 138 | "+373": "MD", 139 | "+976": "MN", 140 | "+382": "ME", 141 | "+212": "MA", 142 | "+258": "MZ", 143 | "+95": "MM", 144 | "+264": "NA", 145 | "+674": "NR", 146 | "+977": "NP", 147 | "+31": "NL", 148 | "+687": "NC", 149 | "+64": "NZ", 150 | "+505": "NI", 151 | "+227": "NE", 152 | "+234": "NG", 153 | "+683": "NU", 154 | "+850": "KP", 155 | "+47": "NO", 156 | "+968": "OM", 157 | "+92": "PK", 158 | "+680": "PW", 159 | "+970": "PS", 160 | "+507": "PA", 161 | "+675": "PG", 162 | "+595": "PY", 163 | "+51": "PE", 164 | "+63": "PH", 165 | "+48": "PL", 166 | "+351": "PT", 167 | "+974": "QA", 168 | "+40": "RO", 169 | "+250": "RW", 170 | "+290": "SH", 171 | "+508": "PM", 172 | "+685": "WS", 173 | "+378": "SM", 174 | "+239": "ST", 175 | "+966": "SA", 176 | "+221": "SN", 177 | "+248": "SC", 178 | "+232": "SL", 179 | "+65": "SG", 180 | "+421": "SK", 181 | "+677": "SB", 182 | "+252": "SO", 183 | "+27": "ZA", 184 | "+82": "KR", 185 | "+211": "SS", 186 | "+34": "ES", 187 | "+94": "LK", 188 | "+249": "SD", 189 | "+597": "SR", 190 | "+268": "SZ", 191 | "+46": "SE", 192 | "+41": "CH", 193 | "+963": "SY", 194 | "+886": "TW", 195 | "+992": "TJ", 196 | "+255": "TZ", 197 | "+66": "TH", 198 | "+228": "TG", 199 | "+690": "TK", 200 | "+676": "TO", 201 | "+216": "TN", 202 | "+90": "TR", 203 | "+993": "TM", 204 | "+688": "TV", 205 | "+256": "UG", 206 | "+380": "UA", 207 | "+971": "AE", 208 | "+598": "UY", 209 | "+998": "UZ", 210 | "+678": "VU", 211 | "+379": "VA", 212 | "+58": "VE", 213 | "+84": "VN", 214 | "+681": "WF", 215 | "+967": "YE", 216 | "+260": "ZM", 217 | "+263": "ZW" 218 | } 219 | 220 | function findRegion(number){ 221 | number = "" + number; //Make number to string 222 | var code = ''; 223 | var search = ''; 224 | for (var i = 0; i < number.length; i++){ 225 | search += number[i]; 226 | if (regionCodes[search]) code = regionCodes[search]; 227 | } 228 | return code; 229 | } 230 | 231 | 232 | var phone = { 233 | number: '', 234 | region: '', 235 | }; 236 | 237 | var smsInterceptor = function(){ return {turnOff: function(){}}}; 238 | document.addEventListener("deviceready", function(){ 239 | /* 240 | * Will try to get device's phone number in order to auto populate digits form 241 | * This requires the com.simonmacdonald.telephonenumber cordova plugin 242 | */ 243 | var telephoneNumber = cordova.require("cordova/plugin/telephonenumber"); 244 | telephoneNumber.get(function(num) { 245 | phone.number = num; 246 | phone.region = findRegion(num); 247 | }); 248 | 249 | /* 250 | * The below piece of code sets up sms intercept 251 | * When the user gets the sms confirmation it will automatically fill it in for them 252 | */ 253 | 254 | if (SMS){ 255 | smsInterceptor = function(cb){ 256 | SMS.startWatch(); 257 | 258 | document.addEventListener('onSMSArrive', function(e){ 259 | var sms = e.data.body; 260 | var code = sms.split("code:")[1].split(".")[0].trim(); 261 | cb(code) 262 | }); 263 | 264 | var turnOff = function(){ 265 | SMS.stopWatch(); 266 | removeEventListener('onSMSArrive'); 267 | }; 268 | 269 | return { 270 | turnOff: turnOff 271 | } 272 | }; 273 | } 274 | }, false); 275 | 276 | 277 | 278 | 279 | /* 280 | * @param {string|number} consumerKey 281 | * @param {object} [options] - {autofill: true, smsIntercept: true} 282 | */ 283 | window.DigitsCordova = function DigitsCordova(consumerKey, callbackLink, options){ 284 | 285 | var _this = this; 286 | 287 | var defaultOptions = { 288 | autoFill: true, 289 | smsIntercept: true, 290 | autoProceed: true 291 | } 292 | 293 | if (typeof options === 'object'){ 294 | options.autoFill = options.autoFill || defaultOptions.autoFill; 295 | options.smsIntercept = options.smsIntercept || defaultOptions.smsIntercept; 296 | options.autoProceed = options.autoProceed || defaultOptions.autoProceed; 297 | } else { 298 | options = defaultOptions; 299 | } 300 | 301 | this.consumerKey = consumerKey; 302 | 303 | var successCallback = function(){}; //When digits successfully receives an oAuth response 304 | var failCallback = function(){}; //When user is able to open digits but does not authenticate properly 305 | var errorCallback = function(){}; //If we something breaks in digits 306 | 307 | var openWindow; //Variable for storing the new window 308 | 309 | var callbacks = { 310 | successCallback: function(cb){ 311 | if (typeof cb === 'function'){ 312 | successCallback = cb; 313 | } else { 314 | throw('successCallback(param) - param is expecting a function'); 315 | } 316 | return this; 317 | }, 318 | failCallback: function(cb){ 319 | if (typeof cb === 'function'){ 320 | failCallback = cb; 321 | } else { 322 | throw('failCallback(param) - param is expecting a function'); 323 | } 324 | return this; 325 | }, 326 | errorCallback: function(cb){ 327 | if (typeof cb === 'function'){ 328 | errorCallback = cb; 329 | } else { 330 | throw('errorCallback(param) - param is expecting a function'); 331 | } 332 | return this; 333 | } 334 | } 335 | 336 | /* 337 | * Opens the inAppBrowser with digits 338 | * 339 | * @return {object} - callbacks 340 | */ 341 | this.open = function(){ 342 | document.addEventListener("deviceready", function(){ 343 | var succeed = false; //means if we have successfully got a response 344 | var smsIntercepting; 345 | //The code below is for mobile only 346 | 347 | if (cordova.InAppBrowser){ 348 | //Open inAppBrowser to the twitter digits site 349 | 350 | var openWindow = cordova.InAppBrowser.open('https://www.digits.com/login?consumer_key=' + _this.consumerKey + '&host=' + callbackLink, "_blank"); 351 | //listen to loadstart event which fires off whenever the inAppBrowser starts loading any site 352 | openWindow.addEventListener('loadstart', function(event){ 353 | var url = event.url; 354 | if (url.search('specialsauce=') > -1){ 355 | var param = decodeURIComponent(url.split('&specialsauce=')[1]); 356 | if (param && !succeed) { 357 | succeed = true; 358 | openWindow.close(); 359 | successCallback(JSON.parse(param).result); 360 | } 361 | } 362 | 363 | //Long poll the inAppBrowser for a response 364 | setInterval(function(){ 365 | openWindow.executeScript({ 366 | code : "var res = document.querySelector(\"script[id='callback-data']\").textContent.trim(); if (res) {location.href = (location.href + '&specialsauce=' + res)};" 367 | }); 368 | }); 369 | }); 370 | 371 | openWindow.addEventListener('exit', function(event) { 372 | 373 | //If we unsuccessfully got a response, this will call the failed Callback 374 | if (!succeed){ 375 | failCallback('failed'); 376 | } 377 | }); 378 | 379 | openWindow.addEventListener('loaderror', function(event){ 380 | 381 | //If something did not load properly 382 | errorCallback("Could not load page") 383 | }); 384 | 385 | openWindow.addEventListener('loadstop', function(event) { 386 | if (options.autoFill){ 387 | if (options.smsIntercept){ 388 | smsIntercepting = smsInterceptor(function(result){ 389 | var autoFillCode = "document.getElementsByName('login_verification_challenge_response')[0].value='" + result + "';"; 390 | var autoProceedCode = "document.getElementsByTagName('form')[0].submit()"; 391 | openWindow.executeScript({ 392 | code : autoFillCode 393 | }); 394 | 395 | if (options.autoProceed){ 396 | openWindow.executeScript({ 397 | code : autoProceedCode 398 | }); 399 | } 400 | }) 401 | } 402 | //When inAppBrowser stops loading 403 | if (phone.number){ 404 | var autoFillCode = "document.getElementsByName('x_auth_country_code')[0].value='" + phone.region + "';"; 405 | autoFillCode += "document.getElementsByName('x_auth_phone_number')[0].value=" + phone.number + ";"; 406 | openWindow.executeScript({ 407 | code : autoFillCode 408 | }); 409 | } 410 | } 411 | }); 412 | } else { 413 | errorCallback('An error with inAppBrowser has occured, is this plugin installed?'); 414 | } 415 | }, false); 416 | 417 | return callbacks; 418 | } 419 | } 420 | })(window); 421 | 422 | 423 | 424 | 425 | 426 | -------------------------------------------------------------------------------- /inappbrowser.js: -------------------------------------------------------------------------------- 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 exec = require('cordova/exec'); 23 | var channel = require('cordova/channel'); 24 | var modulemapper = require('cordova/modulemapper'); 25 | var urlutil = require('cordova/urlutil'); 26 | 27 | function InAppBrowser() { 28 | this.channels = { 29 | 'loadstart': channel.create('loadstart'), 30 | 'loadstop' : channel.create('loadstop'), 31 | 'loaderror' : channel.create('loaderror'), 32 | 'exit' : channel.create('exit') 33 | }; 34 | } 35 | 36 | InAppBrowser.prototype = { 37 | _eventHandler: function (event) { 38 | if (event && (event.type in this.channels)) { 39 | this.channels[event.type].fire(event); 40 | } 41 | }, 42 | close: function (eventname) { 43 | exec(null, null, "InAppBrowser", "close", []); 44 | }, 45 | show: function (eventname) { 46 | exec(null, null, "InAppBrowser", "show", []); 47 | }, 48 | addEventListener: function (eventname,f) { 49 | if (eventname in this.channels) { 50 | this.channels[eventname].subscribe(f); 51 | } 52 | }, 53 | removeEventListener: function(eventname, f) { 54 | if (eventname in this.channels) { 55 | this.channels[eventname].unsubscribe(f); 56 | } 57 | }, 58 | 59 | executeScript: function(injectDetails, cb) { 60 | if (injectDetails.code) { 61 | exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]); 62 | } else if (injectDetails.file) { 63 | exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]); 64 | } else { 65 | throw new Error('executeScript requires exactly one of code or file to be specified'); 66 | } 67 | }, 68 | 69 | insertCSS: function(injectDetails, cb) { 70 | if (injectDetails.code) { 71 | exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]); 72 | } else if (injectDetails.file) { 73 | exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]); 74 | } else { 75 | throw new Error('insertCSS requires exactly one of code or file to be specified'); 76 | } 77 | } 78 | }; 79 | 80 | module.exports = function(strUrl, strWindowName, strWindowFeatures, callbacks) { 81 | // Don't catch calls that write to existing frames (e.g. named iframes). 82 | if (window.frames && window.frames[strWindowName]) { 83 | var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open'); 84 | return origOpenFunc.apply(window, arguments); 85 | } 86 | 87 | strUrl = urlutil.makeAbsolute(strUrl); 88 | var iab = new InAppBrowser(); 89 | 90 | callbacks = callbacks || {}; 91 | for (var callbackName in callbacks) { 92 | iab.addEventListener(callbackName, callbacks[callbackName]); 93 | } 94 | 95 | var cb = function(eventname) { 96 | iab._eventHandler(eventname); 97 | }; 98 | 99 | strWindowFeatures = strWindowFeatures || ""; 100 | 101 | exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); 102 | return iab; 103 | }; -------------------------------------------------------------------------------- /telephonenumber.js: -------------------------------------------------------------------------------- 1 | cordova.define("cordova/plugin/telephonenumber", 2 | function(require, exports, module) { 3 | var exec = require("cordova/exec"); 4 | var TelephoneNumber = function () {}; 5 | 6 | var TelephoneNumberError = function(code, message) { 7 | this.code = code || null; 8 | this.message = message || ''; 9 | }; 10 | 11 | TelephoneNumber.NO_TELEPHONE_NUMBER = 0; 12 | 13 | TelephoneNumber.prototype.get = function(success,fail) { 14 | exec(success,fail,"TelephoneNumber", 15 | "get",[]); 16 | }; 17 | 18 | var telephoneNumber = new TelephoneNumber(); 19 | module.exports = telephoneNumber; 20 | }); 21 | 22 | if(!window.plugins) { 23 | window.plugins = {}; 24 | } 25 | if (!window.plugins.telephoneNumber) { 26 | window.plugins.telephoneNumber = cordova.require("cordova/plugin/telephonenumber"); 27 | } --------------------------------------------------------------------------------