Skip to content

Commit

Permalink
Merge pull request GoogleChrome#302 from beaufortfrancois/mergeWarnings
Browse files Browse the repository at this point in the history
web-bluetooth: move flag check into utils.html
  • Loading branch information
jeffposnick committed Feb 23, 2016
2 parents 7ef098a + 5cd2fa3 commit 55a8f14
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 42 deletions.
13 changes: 13 additions & 0 deletions web-bluetooth/_includes/utils.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
log = ChromeSamples.log;

function isWebBluetoothEnabled() {
if (navigator.bluetooth) {
return true;
} else {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
return false;
}
}
</script>
7 changes: 2 additions & 5 deletions web-bluetooth/battery-level.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to retrieve battery
information from a nearby Bluetooth Device advertising Battery information with
Expand All @@ -21,13 +22,9 @@

<script>
document.querySelector('button').addEventListener('click', function() {
if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onButtonClick();
}
});
log = ChromeSamples.log;
</script>
7 changes: 2 additions & 5 deletions web-bluetooth/characteristic-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to display all
properties of a specific characteristic from a nearby Bluetooth Low Energy
Expand All @@ -31,13 +32,9 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onFormSubmit();
}
});
log = ChromeSamples.log;
</script>
17 changes: 4 additions & 13 deletions web-bluetooth/device-disconnect.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to <a href="http://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserver-disconnect">disconnect</a> and get notified from a disconnection of a nearby Bluetooth Low Energy Device after connecting to it.</p>

Expand All @@ -28,10 +29,7 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onScanButtonClick();
}
Expand All @@ -40,23 +38,16 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
onDisconnectButtonClick();
}
});
document.querySelector('#reconnect').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
onReconnectButtonClick();
}
});
log = ChromeSamples.log;
</script>
7 changes: 2 additions & 5 deletions web-bluetooth/device-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to retrieve basic
device information from a nearby Bluetooth Low Energy Device.</p>
Expand All @@ -27,13 +28,9 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onFormSubmit();
}
});
log = ChromeSamples.log;
</script>
12 changes: 3 additions & 9 deletions web-bluetooth/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to start and stop
characteristic notifications from a nearby Bluetooth Low Energy Device. You may
Expand Down Expand Up @@ -32,10 +33,7 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onStartButtonClick();
}
Expand All @@ -44,12 +42,8 @@
event.stopPropagation();
event.preventDefault();

if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
onStopButtonClick();
}
});
log = ChromeSamples.log;
</script>
7 changes: 2 additions & 5 deletions web-bluetooth/reset-energy.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
---

{% include_relative _includes/intro.html %}
{% include_relative _includes/utils.html %}

<p>This sample illustrates the use of the Web Bluetooth API to reset energy
expended from a nearby Bluetooth Device advertising Heart Rate with Bluetooth
Expand All @@ -21,13 +22,9 @@

<script>
document.querySelector('button').addEventListener('click', function() {
if (!navigator.bluetooth) {
ChromeSamples.setStatus('Web Bluetooth API is not available.\n' +
'Please make sure the Web Bluetooth flag is enabled.');
} else {
if (isWebBluetoothEnabled()) {
ChromeSamples.clearLog();
onButtonClick();
}
});
log = ChromeSamples.log;
</script>

0 comments on commit 55a8f14

Please sign in to comment.