Free and Open source Web Builder Framework. Next generation tool for building templates without coding
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
1.4 KiB

import Backbone from 'backbone';
module.exports = Backbone.Model.extend({
defaults: {
wrapper: '',
width: '',
height: '',
head: '',
attributes: {}
},
initialize() {
this.set('head', []);
},
getHead() {
return [...this.get('head')];
},
setHead(value) {
return this.set('head', [...value]);
},
addHeadItem(item) {
const head = this.getHead();
head.push(item);
this.setHead(head);
},
getHeadByAttr(attr, value, tag) {
const head = this.getHead();
return head.filter(
item =>
item.attributes &&
item.attributes[attr] == value &&
(!tag || tag === item.tag)
)[0];
},
removeHeadByAttr(attr, value, tag) {
const head = this.getHead();
const item = this.getHeadByAttr(attr, value, tag);
const index = head.indexOf(item);
if (index >= 0) {
head.splice(index, 1);
this.setHead(head);
}
},
addLink(href) {
const tag = 'link';
!this.getHeadByAttr('href', href, tag) &&
this.addHeadItem({
tag,
attributes: {
href,
rel: 'stylesheet'
}
});
},
removeLink(href) {
this.removeHeadByAttr('href', href, 'link');
},
addScript(src) {
const tag = 'script';
!this.getHeadByAttr('src', src, tag) &&
this.addHeadItem({
tag,
attributes: { src }
});
},
removeScript(src) {
this.removeHeadByAttr('src', src, 'script');
}
});