Browse Source

enable scripts in iframe head

pull/67/head
tangkikodo 9 years ago
parent
commit
e61f01217b
  1. 3
      src/canvas/config/config.js
  2. 31
      src/canvas/view/CanvasView.js

3
src/canvas/config/config.js

@ -6,5 +6,8 @@ define(function () {
// Coming soon
rulers: false,
// append scripts in head
scripts: []
};
});

31
src/canvas/view/CanvasView.js

@ -30,6 +30,31 @@ function(Backbone, FrameView) {
this.em.trigger('canvasScroll');
},
/**
* Insert scripts into head, it will call renderBody after all scripts loaded or failed
* @private
*/
renderScripts: function () {
var frame = this.frame;
var that = this;
frame.el.onload = function () {
var scripts = that.config.scripts,
counter = 0;
scripts.map(function (scriptUrl) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl;
script.onerror = script.onload = function () {
counter++;
if (counter == scripts.length) that.renderBody();
};
frame.el.contentDocument.head.appendChild(script);
});
};
},
/**
* Render inside frame's body
* @private
@ -198,7 +223,11 @@ function(Backbone, FrameView) {
this.model.get('frame').set('wrapper', this.wrapper);
this.$el.append(this.frame.render().el);
var frame = this.frame;
frame.el.onload = this.renderBody;
if (this.config.scripts.length === 0) {
frame.el.onload = this.renderBody;
} else {
this.renderScripts(); // will call renderBody later
}
}
var ppfx = this.ppfx;
toolsEl = $('<div>', { id: ppfx + 'tools' }).get(0);

Loading…
Cancel
Save