Permalink
Browse files

Initial service worker support.

  • Loading branch information...
1 parent d180ab9 commit 583432054c3a9487edb056fdce50e4953ff5ebf4 @lgarron lgarron committed Mar 12, 2015
View
@@ -10,4 +10,11 @@ Header always unset Strict-Transport-Security env=!HTTPS
# Redirect to HTTPS first.
RewriteEngine on
RewriteCond %{HTTPS} off
-RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
+RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
+
+<filesMatch "service-worker\.js">
+ FileETag None
+ Header unset ETag
+ Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
+ Header set Pragma "no-cache"
+</filesMatch>
View
@@ -307,7 +307,7 @@ textarea.sharetext {
background: #fff;
}
-#toast, #toastError {
+#toast {
display: flex;
align-items: center;
@@ -328,11 +328,11 @@ textarea.sharetext {
text-align: center;
-box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
+ box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
position: absolute;
+ min-height: 4em;
}
-#toastError {
+#toast.error {
background: rgba(192, 0, 0, 0.8);
- min-height: 4em;
}
View
@@ -632,20 +632,27 @@ algxControllers.controller('algxController', ["$scope", "$location", "debounce",
$scope.algDelayed = (event == "delayed")
}
+ function displayToast(message) {
+ $("#toast").html(message).finish().removeClass("error").fadeIn(100).delay(1000).fadeOut(500);
+ }
+ function displayErrorToast(message) {
+ $("#toast").html(message).finish().addClass("error").fadeIn(100).delay(2000).fadeOut(2500);
+ }
+
$("#copyShort").on("click", function (event) {
clipboard.copy({
"text/plain": $scope.share_forum_short
}).then(
- function(){$("#toast").finish().fadeIn(100).delay(1000).fadeOut(500);},
- function(){$("#toastError").finish().fadeIn(100).delay(2000).fadeOut(2500);}
+ function(){displayToast("The forum link has been copied to your clipboard.");},
+ function(){displayErrorToast("ERROR: Could not copy the forum link.<br>(Your browser might not support web clipboard API yet.)");}
);
});
$("#copyLong").on("click", function (event) {
clipboard.copy({
"text/plain": $scope.share_forum_long
}).then(
- function(){$("#toast").finish().fadeIn(100).delay(1000).fadeOut(500);},
- function(){$("#toastError").finish().fadeIn(100).delay(2000).fadeOut(2500);}
+ function(){displayToast("The forum link has been copied to your clipboard.");},
+ function(){displayErrorToast("ERROR: Could not copy the forum link.<br>(Your browser might not support web clipboard API yet.)");}
);
});
@@ -687,6 +694,39 @@ algxControllers.controller('algxController', ["$scope", "$location", "debounce",
}
}
+ function registerServiceWorker() {
+ navigator.serviceWorker.register("/service-worker.js", {
+ scope: "/"
+ }).then(function(reg) {
+ console.log(":-)", reg);
+ displayToast("Offline support has been enabled.");
+ }, function(err) {
+ console.log(":-(", err);
+ displayErrorToast("Could not enable offline support.");
+ });
+ }
+
+ $scope.toggleServiceWorker = function() {
+ if ('serviceWorker' in navigator) {
+ navigator.serviceWorker.getRegistration().then(function(r) {
+ if (r) {
+ r.unregister().then(function() {
+ displayErrorToast("Offline support has been disabled.");
+ });
+ } else {
+ registerServiceWorker();
+ }
+ }, function(err) {
+ console.log(":-(", err);
+ displayErrorToast("Could not enable offline support.");
+ });
+ } else {
+ console.log(":-(");
+ displayErrorToast("Offline support not available.");
+ }
+ }
+
+
// For debugging.
ss = $scope;
l = $location;
View
@@ -32,8 +32,7 @@
</head>
<body>
- <div id="toast" style="display:none;">The forum link has been copied to your clipboard.</div>
- <div id="toastError" style="display:none;">ERROR: Could not copy the forum link.<br>(Your browser might not support web clipboard API yet.)</div>
+ <div id="toast" style="display:none;">Message.</div>
<div id="display-wrapper" data-ng-class="{'fullscreen': view.fullscreen, 'algDelayed': algDelayed || setupDelayed, 'invalid': algStatus == 'invalid' || setupStatus == 'invalid'}">
@@ -178,7 +177,8 @@ <h2 data-ng-bind="type.setup">Setup</h2>
data-ng-click="mirrorAcrossS();" title="Mirror across S"><i class="fa fa-expand"></i> Mirror (S)</button><br><button
data-ng-click="invert();"><i class="fa fa-backward"></i> Invert</button><button
data-ng-click="removeComments();">Remove Comments</button><br><button
- data-ng-click="image();"><i class="fa fa-image"></i> Image</button>
+ data-ng-click="image();"><i class="fa fa-image"></i> Image</button><button
+ data-ng-click="toggleServiceWorker();"><i class="fa fa-wifi"></i> Offline</button>
<center><div id="canvasPNG"></div></center>
</div>
</div>
Oops, something went wrong.
Binary file not shown.
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 5834320

Please sign in to comment.