MDL-46860 filepicker: iframe context aware
authorRyan Wyllie <ryan@moodle.com>
Wed, 22 Jul 2015 07:49:22 +0000 (07:49 +0000)
committerRyan Wyllie <ryan@moodle.com>
Mon, 10 Aug 2015 02:16:30 +0000 (02:16 +0000)
The filepicker now checks if it's within an iframe when
creating the dialogue, if so it will set the dialogue width
to fit within the iframe and disable dragging.

repository/filepicker.js

index 5208c1f..8b7c983 100644 (file)
@@ -1299,17 +1299,25 @@ M.core_filepicker.init = function(Y, options) {
             var client_id = this.options.client_id;
             var fpid = "filepicker-"+ client_id;
             var labelid = 'fp-dialog-label_'+ client_id;
+            var width = 873;
+            var draggable = true;
             this.fpnode = Y.Node.createWithFilesSkin(M.core_filepicker.templates.generallayout).
                 set('id', 'filepicker-'+client_id).set('aria-labelledby', labelid);
+
+            if (this.in_iframe()) {
+                width = Math.floor(window.innerWidth * 0.95);
+                draggable = false;
+            }
+
             this.mainui = new M.core.dialogue({
                 extraClasses : ['filepicker'],
-                draggable    : true,
+                draggable    : draggable,
                 bodyContent  : this.fpnode,
                 headerContent: '<h3 id="'+ labelid +'">'+ M.util.get_string('filepicker', 'repository') +'</h3>',
                 centered     : true,
                 modal        : true,
                 visible      : false,
-                width        : '873px',
+                width        : width+'px',
                 responsiveWidth : 873,
                 height       : '558px',
                 zIndex       : this.options.zIndex
@@ -1947,6 +1955,10 @@ M.core_filepicker.init = function(Y, options) {
                 M.util.set_user_preference('filepicker_' + name, value);
                 this.options.userprefs[name] = value;
             }
+        },
+        in_iframe: function () {
+            // If we're not the top window then we're in an iFrame
+            return window.self !== window.top;
         }
     });
     var loading = Y.one('#filepicker-loading-'+options.client_id);