forked from GrapesJS/grapesjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend Style Rules on add instead of simple override
- Loading branch information
Showing
6 changed files
with
291 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
define([ 'backbone', 'require'], | ||
function (Backbone, require) { | ||
function (Backbone, require) { | ||
|
||
return Backbone.Collection.extend({ | ||
return Backbone.Collection.extend({ | ||
|
||
initialize: function(models, opt){ | ||
initialize: function(models, opt){ | ||
|
||
this.on('add', this.onAdd); | ||
this.on('add', this.onAdd); | ||
|
||
this.config = opt && opt.config ? opt.config : null; | ||
this.config = opt && opt.config ? opt.config : null; | ||
|
||
// Inject editor | ||
if(opt && opt.sm) | ||
this.editor = opt.sm; | ||
// Inject editor | ||
if(opt && opt.sm) | ||
this.editor = opt.sm; | ||
|
||
this.model = function(attrs, options) { | ||
var model; | ||
this.model = function(attrs, options) { | ||
var model; | ||
|
||
if(!options.sm && opt && opt.sm) | ||
options.sm = opt.sm; | ||
if(!options.sm && opt && opt.sm) | ||
options.sm = opt.sm; | ||
|
||
if(opt && opt.config) | ||
options.config = opt.config; | ||
if(opt && opt.config) | ||
options.config = opt.config; | ||
|
||
if(opt && opt.defaultTypes) | ||
options.defaultTypes = opt.defaultTypes; | ||
if(opt && opt.defaultTypes) | ||
options.defaultTypes = opt.defaultTypes; | ||
|
||
if(opt && opt.componentTypes) | ||
options.componentTypes = opt.componentTypes; | ||
if(opt && opt.componentTypes) | ||
options.componentTypes = opt.componentTypes; | ||
|
||
var df = opt.defaultTypes; | ||
var df = opt.defaultTypes; | ||
|
||
for (var it = 0; it < df.length; it++) { | ||
var dfId = df[it].id; | ||
if(dfId == attrs.type) { | ||
model = df[it].model; | ||
break; | ||
} | ||
} | ||
for (var it = 0; it < df.length; it++) { | ||
var dfId = df[it].id; | ||
if(dfId == attrs.type) { | ||
model = df[it].model; | ||
break; | ||
} | ||
} | ||
|
||
if(!model) { | ||
// get the last one | ||
model = df[df.length - 1].model; | ||
} | ||
if(!model) { | ||
// get the last one | ||
model = df[df.length - 1].model; | ||
} | ||
|
||
return new model(attrs, options); | ||
}; | ||
return new model(attrs, options); | ||
}; | ||
|
||
}, | ||
|
||
add: function(models, opt){ | ||
if(typeof models === 'string'){ | ||
var parsed = this.editor.get('Parser').parseHtml(models); | ||
models = parsed.html; | ||
}, | ||
|
||
var cssc = this.editor.get('CssComposer'); | ||
if(parsed.css && cssc){ | ||
var added = cssc.addCollection(parsed.css); | ||
} | ||
} | ||
add: function(models, opt){ | ||
if(typeof models === 'string'){ | ||
var parsed = this.editor.get('Parser').parseHtml(models); | ||
models = parsed.html; | ||
|
||
return Backbone.Collection.prototype.add.apply(this, [models, opt]); | ||
}, | ||
var cssc = this.editor.get('CssComposer'); | ||
if(parsed.css && cssc){ | ||
var added = cssc.addCollection(parsed.css, {extend: 1}); | ||
} | ||
} | ||
|
||
onAdd: function(model, c, opts){ | ||
var style = model.get('style'); | ||
return Backbone.Collection.prototype.add.apply(this, [models, opt]); | ||
}, | ||
|
||
if(!_.isEmpty(style) && this.editor){ | ||
var cssC = this.editor.get('CssComposer'); | ||
var newClass = this.editor.get('SelectorManager').add(model.cid); | ||
model.set({style:{}}); | ||
model.get('classes').add(newClass); | ||
var rule = cssC.add(newClass); | ||
rule.set('style', style); | ||
} | ||
onAdd: function(model, c, opts){ | ||
var style = model.get('style'); | ||
|
||
if(!_.isEmpty(style) && this.editor){ | ||
var cssC = this.editor.get('CssComposer'); | ||
var newClass = this.editor.get('SelectorManager').add(model.cid); | ||
model.set({style:{}}); | ||
model.get('classes').add(newClass); | ||
var rule = cssC.add(newClass); | ||
rule.set('style', style); | ||
} | ||
}, | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.