Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D56A1755E for ; Sat, 7 Feb 2015 01:52:14 +0000 (UTC) Received: (qmail 64962 invoked by uid 500); 7 Feb 2015 01:52:13 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 64933 invoked by uid 500); 7 Feb 2015 01:52:13 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 64923 invoked by uid 99); 7 Feb 2015 01:52:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Feb 2015 01:52:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9A215E01C2; Sat, 7 Feb 2015 01:52:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Message-Id: <1decd9eaea46491095f838624b4c6a3b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cordova-wp8 git commit: CB-8417 moved platform specific js into platform Date: Sat, 7 Feb 2015 01:52:13 +0000 (UTC) Repository: cordova-wp8 Updated Branches: refs/heads/master 06591601f -> cd90271b6 CB-8417 moved platform specific js into platform Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/cd90271b Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/cd90271b Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/cd90271b Branch: refs/heads/master Commit: cd90271b694dbd33fdc23cebdab1f3caba5e691e Parents: 0659160 Author: Steve Gill Authored: Fri Feb 6 17:52:08 2015 -0800 Committer: Steve Gill Committed: Fri Feb 6 17:52:08 2015 -0800 ---------------------------------------------------------------------- cordova-js-src/exec.js | 76 +++++++++++++++++++++++++++++++++++++++++ cordova-js-src/platform.js | 34 ++++++++++++++++++ 2 files changed, 110 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/cd90271b/cordova-js-src/exec.js ---------------------------------------------------------------------- diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js new file mode 100644 index 0000000..25fcf5c --- /dev/null +++ b/cordova-js-src/exec.js @@ -0,0 +1,76 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +var cordova = require('cordova'), + base64 = require('cordova/base64'); + +/** + * Execute a cordova command. It is up to the native side whether this action + * is synchronous or asynchronous. The native side can return: + * Synchronous: PluginResult object as a JSON string + * Asynchronous: Empty string "" + * If async, the native side will cordova.callbackSuccess or cordova.callbackError, + * depending upon the result of the action. + * + * @param {Function} success The success callback + * @param {Function} fail The fail callback + * @param {String} service The name of the service to use + * @param {String} action Action to be run in cordova + * @param {String[]} [args] Zero or more arguments to pass to the method + + */ + +module.exports = function(success, fail, service, action, args) { + + var callbackId = service + cordova.callbackId++; + if (typeof success == "function" || typeof fail == "function") { + cordova.callbacks[callbackId] = {success:success, fail:fail}; + } + args = args || []; + // generate a new command string, ex. DebugConsole/log/DebugConsole23/["wtf dude?"] + for(var n = 0; n < args.length; n++) + { + // special case for ArrayBuffer which could not be stringified out of the box + if(typeof ArrayBuffer !== "undefined" && args[n] instanceof ArrayBuffer) + { + args[n] = base64.fromArrayBuffer(args[n]); + } + + if(typeof args[n] !== "string") + { + args[n] = JSON.stringify(args[n]); + } + } + var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args); + // pass it on to Notify + try { + if(window.external) { + window.external.Notify(command); + } + else { + console.log("window.external not available :: command=" + command); + } + } + catch(e) { + console.log("Exception calling native with command :: " + command + " :: exception=" + e); + } +}; + http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/cd90271b/cordova-js-src/platform.js ---------------------------------------------------------------------- diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js new file mode 100644 index 0000000..237d4f5 --- /dev/null +++ b/cordova-js-src/platform.js @@ -0,0 +1,34 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +module.exports = { + id: 'windowsphone', + bootstrap: function() { + var cordova = require('cordova'), + exec = require('cordova/exec'); + + // Inject a listener for the backbutton, and tell native to override the flag (true/false) when we have 1 or more, or 0, listeners + var backButtonChannel = cordova.addDocumentEventHandler('backbutton'); + backButtonChannel.onHasSubscribersChange = function() { + exec(null, null, "CoreEvents", "overridebackbutton", [this.numHandlers == 1]); + }; + } +}; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org