webstaff: add routine for Dojo JS to detect if running in iframe
authorGalen Charlton <gmc@esilibrary.com>
Thu, 27 Aug 2015 22:23:23 +0000 (22:23 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:16 +0000 (15:44 -0400)
Sometimes legacy Dojo interfaces may need to adjust their
behavior if they're embedded in the web staff client. This patch
adds a new utility function, openils.Util.inIFrame(), to detect
if such code is running in an iframe. If so, the presumption
is that iframe belongs to the web staff client.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/web/js/dojo/openils/Util.js

index 804d13c..e3588ae 100644 (file)
@@ -494,5 +494,19 @@ if(!dojo._hasResource["openils.Util"]) {
         );
     };
 
+    /**
+     * Check to see if we're running in an iframe; if we
+     * are, we assume that the iframe is specifically one
+     * used by the web staff client to embed legacy interfaces.
+     */
+    openils.Util.inIframe = function() {
+        /* http://stackoverflow.com/a/326076 */
+        try {
+            return window.self !== window.top;
+        } catch (e) {
+            return true;
+        }
+    };
+
 }