Ditch Inkscape.
[mlpccg.git] / mlpccg.js
index 44ce3c3..87e8ac3 100644 (file)
--- a/mlpccg.js
+++ b/mlpccg.js
@@ -18,6 +18,7 @@ var THEMES = [
     "cadance",
     "celestia",
     "chrysalis",
+    "cmc",
     "dash",
     "discord",
     "fluttershy",
@@ -66,16 +67,14 @@ function iclamp (x, lo, hi) {
 }
 
 function broadcast (data, source) {
-    var origin = (!location.origin || location.origin === "null")
-        ? "*" : location.origin;
     source = source || window;
     if (window.parent && window.parent !== source && window.parent !== window) {
-        window.parent.postMessage(data, origin);
+        window.parent.postMessage(data, "*");
     }
     for (var i = 0; i < window.frames.length; ++i) {
         var w = window.frames[i].window;
         if (w !== source) {
-            w.postMessage(data, origin);
+            w.postMessage(data, "*");
         }
     }
 }
@@ -164,13 +163,16 @@ function open (event) {
     event.preventDefault();
 }
 
-window.addEventListener('DOMContentLoaded', function () {    
-    var links = document.querySelectorAll("a[href]:not([target=_blank])");
-    for (var i = 0; i < links.length; ++i) {
-        links[i].addEventListener('click', open);
+window.addEventListener('DOMContentLoaded', function () {
+    if (navigator.standalone) {
+        var links = document.querySelectorAll("a[href]:not([target=_blank])");
+        for (var i = 0; i < links.length; ++i) {
+            links[i].addEventListener('click', open);
+        }
     }
 
-    FastClick.attach(document.body, { tapDelay: 50 });
+    if (typeof FastClick !== "undefined")
+        FastClick.attach(document.body, { tapDelay: 50 });
     loadTheme();
 });
 
@@ -236,23 +238,14 @@ if (applicationCache && applicationCache.status) {
 }
 
 function dismiss () {
-    var overlay = document.getElementById("overlay");
-    if (overlay)
-        overlay.parentNode.removeChild(overlay);
-    broadcast({ type: "dismiss" });
+    var open = document.querySelectorAll(".dialog.open");
+    for (var i = 0; i < open.length; ++i)
+        open[i].className = "dialog";
 }
 
-function show (id, otherId) {
-    var overlay = document.getElementById("overlay");
-    if (!overlay) {
-        overlay = document.createElement('div');
-        overlay.id = 'overlay';
-    } else {
-        overlay.parentNode.removeChild(overlay);
-    }
+function show (id) {
+    dismiss();
     var target = document.getElementById(id);
-    target.parentNode.insertBefore(overlay, target);
-    if (otherId)
-        broadcast({ type: 'show', id: otherId });
+    target.className += " open";
 }