summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-network-information/src/browser
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
committerJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
commitef4f212fc1482136dba1e690ec589b315b4a377f (patch)
tree0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-network-information/src/browser
parent5fa81da81260d65113f57a293b6256d334fe8e2d (diff)
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-network-information/src/browser')
-rw-r--r--StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js b/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js
new file mode 100644
index 00000000..8a6ddb0e
--- /dev/null
+++ b/StoneIsland/plugins/cordova-plugin-network-information/src/browser/network.js
@@ -0,0 +1,48 @@
+/*
+ * 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'),
+ proxy = require("cordova/exec/proxy"),
+ Connection = require('./Connection');
+
+var type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
+
+// Subscribe to 'native' online/offline events
+function onStatusChange(evt) {
+ type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
+ // force async
+ setTimeout(function(){
+ cordova.fireDocumentEvent(evt.type);
+ },0);
+}
+
+window.addEventListener('online', onStatusChange);
+window.addEventListener('offline', onStatusChange);
+
+proxy.add("NetworkStatus", {
+ getConnectionInfo:function(cbSuccess) {
+ // force async
+ setTimeout(function(){
+ cbSuccess(type);
+ },0);
+ }
+});
+
+