mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
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.
62 lines
1.7 KiB
62 lines
1.7 KiB
define(['backbone'], function (Backbone) {
|
|
|
|
return Backbone.Model.extend({
|
|
|
|
mapModel: function (model) {
|
|
var code = '';
|
|
var script = model.get('script');
|
|
var type = model.get('type');
|
|
var comps = model.get('components');
|
|
var id = model.cid;
|
|
|
|
if (script) {
|
|
// If the component has scripts we need to expose his ID
|
|
var attr = model.get('attributes');
|
|
attr = _.extend({}, attr, {id: id});
|
|
model.set('attributes', attr);
|
|
|
|
var scrStr = 'function(){' + script + '}';
|
|
scrStr = typeof script == 'function' ? script.toString() : scrStr;
|
|
|
|
// If the script was updated, I'll put its code in a separate container
|
|
if (model.get('scriptUpdated')) {
|
|
this.mapJs[type+'-'+id] = {ids: [id], code: scrStr};
|
|
} else {
|
|
var mapType = this.mapJs[type];
|
|
|
|
if(mapType) {
|
|
mapType.ids.push(id);
|
|
} else {
|
|
this.mapJs[type] = {ids: [id], code: scrStr};
|
|
}
|
|
}
|
|
}
|
|
|
|
comps.each(function(model) {
|
|
code += this.mapModel(model);
|
|
}, this);
|
|
|
|
return code;
|
|
},
|
|
|
|
build: function(model) {
|
|
this.mapJs = {};
|
|
this.mapModel(model);
|
|
|
|
var code = '';
|
|
|
|
for(var type in this.mapJs) {
|
|
var mapType = this.mapJs[type];
|
|
var ids = '#' + mapType.ids.join(', #');
|
|
code += 'var items = document.querySelectorAll("'+ids+'");' +
|
|
'for (var i = 0, len = items.length; i < len; i++) {'+
|
|
'(' + mapType.code + '.bind(items[i]))();' +
|
|
'}';
|
|
}
|
|
|
|
|
|
return code;
|
|
},
|
|
|
|
});
|
|
});
|
|
|