[Testbot] Plone 5.0 - Python 2.7 - Build # 4190 - Fixed! - 0 failure(s)

jenkins at plone.org jenkins at plone.org
Wed Feb 11 16:15:30 UTC 2015


-------------------------------------------------------------------------------
Plone 5.0 - Python 2.7 - Build # 4190 - Fixed!
-------------------------------------------------------------------------------

http://jenkins.plone.org/job/plone-5.0-python-2.7/4190/


-------------------------------------------------------------------------------
CHANGES
-------------------------------------------------------------------------------

Repository: mockup
Branch: refs/heads/master
Date: 2015-02-11T09:49:27-06:00
Author: vangheem (vangheem) <vangheem at gmail.com>
Commit: https://github.com/plone/mockup/commit/1de2e275dc4b55837968d89c659e1f84960be664

use a more generic iframe implementation that should work better on all browsers. fixes https://github.com/plone/Products.CMFPlone/issues/351

Files changed:
A mockup/patterns/resourceregistry/js/iframe.js
M mockup/patterns/resourceregistry/js/registry.js

diff --git a/mockup/patterns/resourceregistry/js/iframe.js b/mockup/patterns/resourceregistry/js/iframe.js
new file mode 100644
index 0000000..05cf90a
--- /dev/null
+++ b/mockup/patterns/resourceregistry/js/iframe.js
@@ -0,0 +1,109 @@
+/*
+ * much of this code is heavily barrowed from Rok Garbas's iframe
+ * code that has since been removed from mockup
+ */
+
+define([
+  'jquery'
+], function($) {
+  'use strict';
+
+  window.IFrame = function(options) { this.init(options); };
+  window.IFrame.prototype = {
+    defaults: {
+      doctype: '<!doctype html>',
+      title: '',
+      name: '',
+      resources: [],
+      configure: function(){},
+      onLoad: function(){}
+    },
+
+    init: function(options) {
+      var self = this;
+      self.options = $.extend({}, self.defaults, options);
+
+      // register this guy
+      if(!window.iframe){
+        window.iframe = {};
+      }
+      window.iframe[self.options.name] = self;
+
+      self.loaded = false;
+
+      // Create iframe
+      var iframe = window.document.createElement('iframe');
+
+      iframe.setAttribute('id', self.options.name);
+      iframe.setAttribute('name', self.options.name);
+      iframe.setAttribute('style', 'display:none;');
+      iframe.setAttribute('src', 'javascript:false');
+
+      window.document.body.appendChild(iframe);
+      self.el = iframe;
+      self.window = iframe.contentWindow;
+      self.document = self.window.document;
+
+      self.options.configure(self);
+
+      var resourcesData = '';
+      for(var i=0; i<self.options.resources.length; i=i+1){
+        var url = self.options.resources[i];
+        var resource;
+        if (url.slice( -3 ) === '.js') {
+          resource = window.document.createElement('script');
+          resource.src = url;
+          resource.type = 'text/javascript';
+          resource.async = false;
+        } else if (url.slice( -4 ) === '.css') {
+          resource = window.document.createElement('link');
+          resource.href = url;
+          resource.type = 'text/css';
+          resource.rel = 'stylesheet';
+        } else if (url.slice( -5 ) === '.less') {
+          resource = window.document.createElement('link');
+          resource.href = url;
+          resource.type = 'text/css';
+          resource.rel = 'stylesheet/less';
+        }
+        resourcesData += '\n' + resource.outerHTML;
+      }
+
+      self.document.open();
+      self.document.write(
+          self.options.doctype +
+          '<html>' +
+            '<head>' +
+              '<title>' + self.options.title + '</title>' +
+              '<meta http-equiv="X-UA-Compatible" content="IE=edge">' +
+            '</head>' +
+            '<body onload="parent.window.iframe[\'' +
+                self.options.name + '\'].load()">' +
+              resourcesData +
+            '</body>' +
+          '</html>'
+      );
+      self.document.close();
+    },
+
+    load: function() {
+      var self = this;
+
+      // check if already loaded
+      if ( self.loaded === true ) {
+        return;
+      }
+
+      // mark iframe as loaded
+      self.loaded = true;
+
+      self.options.onLoad(self);
+    },
+    destroy: function(){
+      delete window.iframe[this.options.name];
+      window.document.body.removeChild(this.el);
+    }
+  };
+
+  return window.IFrame;
+});
\ No newline at end of file
diff --git a/mockup/patterns/resourceregistry/js/registry.js b/mockup/patterns/resourceregistry/js/registry.js
index acbc147..01c5381 100644
--- a/mockup/patterns/resourceregistry/js/registry.js
+++ b/mockup/patterns/resourceregistry/js/registry.js
@@ -6,8 +6,9 @@ define([
   'mockup-ui-url/views/base',
   'mockup-utils',
   'mockup-patterns-modal',
-  'mockup-patterns-resourceregistry-url/js/fields'
-], function($, _, BaseView, utils, Modal, fields) {
+  'mockup-patterns-resourceregistry-url/js/fields',
+  'mockup-patterns-resourceregistry-url/js/iframe'
+], function($, _, BaseView, utils, Modal, fields, IFrame) {
   'use strict';
 
 
@@ -272,40 +273,25 @@ define([
     };
 
     self._buildCSSBundle = function(config){
-      var $iframe = $('<iframe style="display:none"><html><head></head><body></body></html></iframe>').
-          appendTo('body').on('load', function(){
-      });
-      var iframe = $iframe[0];
-      var win = iframe.contentWindow || iframe;
-      win.lessErrorReporting = function(what, error, href){
-        if(what !== 'remove'){
-          self.addResult('less compilation error on file ' + href + ': ' + error);
+      var iframe = new IFrame({
+        name: 'lessc',
+        resources: config.less.concat([
+          self.rview.options.data.lessConfigUrl,
+          self.rview.options.data.lessUrl]),
+        configure: function(iframe){
+          iframe.window.lessErrorReporting = function(what, error, href){
+            if(what !== 'remove'){
+              self.addResult('less compilation error on file ' + href + ': ' + error);
+            }
+          };
         }
-      };
-      var head = $iframe.contents().find('head')[0];
-      _.each(config.less, function(less){
-        var link = document.createElement('link');
-        link.setAttribute('rel', 'stylesheet/less');
-        link.setAttribute('type', 'text/css');
-        link.setAttribute('href', less);
-        head.appendChild(link); 
       });
-      var script = document.createElement('script');
-      script.setAttribute('type', 'text/javascript');
-      script.setAttribute('src', self.rview.options.data.lessConfigUrl);
-      script.onload = function(){
-        script = document.createElement('script');
-        script.setAttribute('type', 'text/javascript');
-        script.setAttribute('src', self.rview.options.data.lessUrl);
-        head.appendChild(script);
-      };
-      head.appendChild(script);
 
       /* XXX okay, wish there were a better way,
-         but we need to pool to find the */
+         but we need to pool to find the out if it's down loading less */
       self.addResult(config.less.length + ' css files to build');
       var checkFinished = function(){
-        var $styles =  $('style[type="text/css"][id]', head);
+        var $styles =  $('style[type="text/css"][id]', iframe.document);
         for(var i=0; i<$styles.length; i=i+1){
           var $style = $styles.eq(i); 
           if($style.attr('id') === 'less:error-message'){
@@ -320,7 +306,7 @@ define([
             var $el = $(this);
             data['data-' + $el.attr('id')] = $el.html();
           });
-          $iframe.remove();
+          iframe.destroy();
           $.ajax({
             url: self.rview.options.data.manageUrl,
             type: 'POST',
@@ -397,21 +383,17 @@ define([
           }
         });
       };
-      var $iframe = $('<iframe style="display:none"><html><head></head><body></body></html></iframe').appendTo('body');
-      var iframe = $iframe[0];
-      var win = iframe.contentWindow || iframe;
-      var head = $iframe.contents().find('head')[0];
-      var script = document.createElement('script');
-      script.setAttribute('type', 'text/javascript');
-      script.setAttribute('src', self.rview.options.data.rjsUrl);
-      script.onload = function(){
-        win.requirejs.optimize(config, function(combined_files){
-          self.addResult('Saved javascript bundle, Build results: <pre>' + combined_files + '</pre>');
-          self.buildCSSBundle();
-          $iframe.remove();
-        });
-      };
-      head.appendChild(script);
+      new IFrame({
+        name: 'rjs',
+        resources: [self.rview.options.data.rjsUrl],
+        onLoad: function(iframe){
+          iframe.window.requirejs.optimize(config, function(combined_files){
+            self.addResult('Saved javascript bundle, Build results: <pre>' + combined_files + '</pre>');
+            self.buildCSSBundle();
+            iframe.destroy();
+          });
+        }
+      });
     };
 
     return self;




-------------------------------------------------------------------------------


More information about the Testbot mailing list