Migrate from node-webkit to NW.js.
[pwl6.git] / src / yuu / core.js
index 8b16707..e770f86 100644 (file)
@@ -7,6 +7,10 @@
 (function (yuu) {
     "use strict";
 
+    yuu.isSafari = function (ua) {
+        return /^((?!chrome).)*safari/i.test(ua || navigator.userAgent)
+            || navigator.standalone;
+    };
 
     yuu.require = function (m) {
         try { return require(m); }
@@ -70,6 +74,9 @@
         /** Initialize Yuu and call all registered hooks
          */
 
+        document.body.className += (navigator.standalone || gui)
+            ? " standalone" : " browser";
+
         if (gui) {
             var win = gui.Window.get();
             var nativeMenuBar = new gui.Menu({ type: "menubar" });
                 wkdoc.hidden = false;
                 wkdoc.dispatchEvent(ev);
             });
+            win.on('new-win-policy', function (frame, url, policy) {
+                if (url.startsWith('chrome')) {
+                    policy.forceNewPopup();
+                } else {
+                    policy.ignore();
+                    gui.Shell.openExternal(url);
+                }
+            });
         }
 
         return new Promise(function (resolve) {
             initOptions = options || {};
             yuu.log("messages", "Initializing Yuu engine.");
             var promises = [];
-            yf.each(function (hook) {
-                promises.push(hook.call(yuu, initOptions));
-            }, initHooks);
+            // initHooks can be pushed to while iterating, so iterate
+            // by index, not a foreach loop.
+            for (var i = 0; i < initHooks.length; ++i)
+                promises.push(initHooks[i].call(yuu, initOptions));
             initHooks = null; // Bust future registerInitHook calls.
             yuu.log("messages", "Initialization hooks complete.");
             if (gui) {
                 req[k] = params[k];
             req.onload = function () {
                 var status = this.status;
-                // status === 0 is given by node-webkit for success.
+                // status === 0 is given by NW.js for success.
                 if ((status >= 200 && status < 300) || status === 0)
                     resolve(this.response);
                 else