Skip to content

Commit ae8d4dc

Browse files
committed
Minor additions
1 parent d22b785 commit ae8d4dc

8 files changed

+63
-4
lines changed

Presentation.pptx

626 KB
Binary file not shown.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ The following code gets the latitude and longitutde of the user's location and o
119119
// Display the latitude and longitude on the paragraph
120120
document.getElementById('location').innerHTML = pos.coords.latitude + ", " + pos.coords.longitude;
121121
});
122+
123+
// Check for change in position
124+
id = navigator.geolocation.watchPosition(
125+
// On success
126+
function(pos){
127+
// Do something when the location is changed
128+
console.log('Changed');
129+
},
130+
131+
// On error
132+
function(){
133+
console.log('Error');
134+
}
135+
);
122136
</script>
123137
</html>
124138

@@ -179,6 +193,8 @@ The following code combines the two APIs (Screen Orientation and Vibration) to m
179193
vibration events at any time until the page is refreshed or destroyed.
180194
-->
181195
<button onclick="navigator.vibrate(0);" id="btn">Allow Vibrate</button>
196+
197+
<p id="orient"></p>
182198
</body>
183199
<script>
184200
// Add an event listener to check for a change in the orientation
@@ -188,15 +204,21 @@ The following code combines the two APIs (Screen Orientation and Vibration) to m
188204
// 0 -> Straight/Portrait
189205
// 90 -> Tilted to left
190206
if(window.orientation == -90){
207+
// Display tilt side on webpage
208+
document.getElementById('orient').innerHTML = "Tilted Right";
209+
191210
// Vibrate for 10 seconds
192211
navigator.vibrate(10000);
193212
} else if(window.orientation == 90){
213+
document.getElementById('orient').innerHTML = "Tilted Left";
214+
194215
// Stop the vibration
195216
navigator.vibrate(0);
196217
}
197218
});
198219
</script>
199220
</html>
221+
200222
```
201223

202224
For reference, visit [Screen Orientation API](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Managing_screen_orientation) and [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API).
@@ -463,6 +485,11 @@ The codes below demonstrate how a user's copied text can be stored locally in cl
463485
},
464486
);
465487
}
488+
489+
// Detect when text is copied
490+
document.addEventListener('copy', function(e){
491+
alert('copied');
492+
});
466493
</script>
467494
</html>
468495
```

battery.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ <h3 id="battery_charging"></h3>
2727
document.getElementById('battery_discharge').innerHTML = battery.dischargingTime / 60 / 60; // Get time in hours
2828

2929
// Displays if battery is charging (Yes!) or not (No)
30-
document.getElementById('battery_charging').innerHTML = (battery.charging == true) ? 'Yes!' : 'No';
30+
document.getElementById('battery_charging').innerHTML = battery.charging ? 'Yes!' : 'No';
31+
32+
// Check for a battery level change
33+
battery.addEventListener('levelchange', function(){
34+
// Do something when battery level changes
35+
alert('Changed');
36+
});
3137
});
3238
</script>
33-
</html>
39+
</html>

clipb_db.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@
9999
},
100100
);
101101
}
102+
103+
// Detect when text is copied
104+
document.addEventListener('copy', function(e){
105+
alert('copied');
106+
});
102107
</script>
103108
</html>

dev_motion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
// Draw ellipse
4040
fill(255, 0, 0);
41-
ellipse(xpos, ypos, 25, 25);
41+
ellipse(xpos, ypos, 50, 50);
4242

4343
// Display variables
4444
fill(0);

geoloc.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,19 @@
1212
// Display the latitude and longitude on the paragraph
1313
document.getElementById('location').innerHTML = pos.coords.latitude + ", " + pos.coords.longitude;
1414
});
15+
16+
// Check for change in position
17+
id = navigator.geolocation.watchPosition(
18+
// On success
19+
function(pos){
20+
// Do something when the location is changed
21+
console.log('Changed');
22+
},
23+
24+
// On error
25+
function(){
26+
console.log('Error');
27+
}
28+
);
1529
</script>
1630
</html>

orient.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
vibration events at any time until the page is refreshed or destroyed.
1515
-->
1616
<button onclick="navigator.vibrate(0);" id="btn">Allow Vibrate</button>
17+
18+
<p id="orient"></p>
1719
</body>
1820
<script>
1921
// Add an event listener to check for a change in the orientation
@@ -23,9 +25,14 @@
2325
// 0 -> Straight/Portrait
2426
// 90 -> Tilted to left
2527
if(window.orientation == -90){
28+
// Display tilt side on webpage
29+
document.getElementById('orient').innerHTML = "Tilted Right";
30+
2631
// Vibrate for 10 seconds
2732
navigator.vibrate(10000);
2833
} else if(window.orientation == 90){
34+
document.getElementById('orient').innerHTML = "Tilted Left";
35+
2936
// Stop the vibration
3037
navigator.vibrate(0);
3138
}

visibility.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Check if the tab has gone out of focus or is hidden
1212
if(document.hidden){
1313
// Tab is hidden
14-
document.title = "COME BACK!";
14+
document.title = "COME BACK!";
1515
} else {
1616
// Tab is visible
1717
document.title = "Yay!";

0 commit comments

Comments
 (0)