mirror of https://github.com/artf/grapesjs.git
5 changed files with 68 additions and 1 deletions
@ -0,0 +1,22 @@ |
|||||
|
import Component from './Component'; |
||||
|
|
||||
|
const type = 'iframe'; |
||||
|
|
||||
|
export default Component.extend( |
||||
|
{ |
||||
|
defaults() { |
||||
|
return { |
||||
|
...Component.prototype.defaults, |
||||
|
type, |
||||
|
tagName: type, |
||||
|
droppable: false, |
||||
|
resizable: true, |
||||
|
traits: ['id', 'title', 'src'], |
||||
|
attributes: { frameborder: '0' } |
||||
|
}; |
||||
|
} |
||||
|
}, |
||||
|
{ |
||||
|
isComponent: el => el.tagName === 'IFRAME' |
||||
|
} |
||||
|
); |
||||
@ -0,0 +1,31 @@ |
|||||
|
import ComponentView from './ComponentView'; |
||||
|
import { createEl, find, attrUp } from 'utils/dom'; |
||||
|
|
||||
|
export default ComponentView.extend({ |
||||
|
tagName: 'div', |
||||
|
|
||||
|
initialize(...args) { |
||||
|
ComponentView.prototype.initialize.apply(this, args); |
||||
|
this.listenTo(this.model, 'change:attributes:src', this.updateSrc); |
||||
|
}, |
||||
|
|
||||
|
updateSrc() { |
||||
|
const frame = find(this.el, 'iframe')[0]; |
||||
|
frame && attrUp(frame, { src: this.__getSrc() }); |
||||
|
}, |
||||
|
|
||||
|
render(...args) { |
||||
|
ComponentView.prototype.render.apply(this, args); |
||||
|
const frame = createEl('iframe', { |
||||
|
class: `${this.ppfx}no-pointer`, |
||||
|
style: 'width: 100%; height: 100%; border: none', |
||||
|
src: this.__getSrc() |
||||
|
}); |
||||
|
this.el.appendChild(frame); |
||||
|
return this; |
||||
|
}, |
||||
|
|
||||
|
__getSrc() { |
||||
|
return this.model.getAttributes().src || ''; |
||||
|
} |
||||
|
}); |
||||
Loading…
Reference in new issue