Skip to content

Commit

Permalink
- Updated demo scripts
Browse files Browse the repository at this point in the history
- Fixed image 'ghosts' on drag
- Fixed unit select inside composite properties
- Added new way to manage default components
  • Loading branch information
artf committed Feb 5, 2016
1 parent bc223d9 commit 85a45db
Show file tree
Hide file tree
Showing 30 changed files with 638 additions and 385 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ style/.sass-cache/
grapes.sublime-project
grapes.sublime-workspace

img/
private/
vendor/
node_modules/
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ var config = {
// Where to render editor (eg. #myId)
container: '',

// Enable/Disable the possibility to copy (ctrl + c) and paste (ctrl + v) elements
copyPaste : true,

// Enable/Disable undo manager
undoManager: true,

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.0.51",
"version": "0.1.0",
"author": "Artur Arseniev",
"homepage": "http://grapesjs.com",
"main": [
Expand Down
2 changes: 1 addition & 1 deletion dist/css/grapes.min.css

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/grapes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.0.51",
"version": "0.1.0",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",
Expand Down
34 changes: 19 additions & 15 deletions src/asset_manager/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ define(function(require) {
/**
* @class AssetManager
* @param {Object} Configurations
*
*
* @return {Object}
* */
var AssetManager = function(config)
Expand All @@ -13,58 +13,62 @@ define(function(require) {
AssetsView = require('./view/AssetsView'),
FileUpload = require('./view/FileUploader');

for (var name in defaults) {
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}

this.assets = new Assets(c.assets);
var obj = {
collection : this.assets,
config : c,
};

this.am = new AssetsView(obj);
this.fu = new FileUpload(obj);
};

AssetManager.prototype = {

/**
* Get collection of assets
*
*
* @return {Object}
* */
getAssets : function(){
return this.assets;
},

/**
* Set new target
* @param {Object} m Model
*
*
* @return void
* */
setTarget : function(m){
this.am.collection.target = m;
},

/**
* Set callback after asset was selected
* @param {Object} f Callback function
*
*
* @return void
* */
onSelect : function(f){
this.am.collection.onSelect = f;
},

render : function(){
if(!this.rendered)

/**
* Render
* @param {Boolean} f Force to render
*/
render : function(f){
if(!this.rendered || f)
this.rendered = this.am.render().$el.add(this.fu.render().$el);
return this.rendered;
},
};

return AssetManager;
});
45 changes: 28 additions & 17 deletions src/code_manager/model/HtmlGenerator.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
define(['backbone'],
define(['backbone'],
function (Backbone) {
/**
* @class HtmlGenerator
* */
return Backbone.Model.extend({

/** @inheritdoc */
getId : function(){
return 'html';
getId : function(){
return 'html';
},

/** @inheritdoc */
build: function(model){
var coll = model.get('components') || model,
code = '';

coll.each(function(m){
var tag = m.get('tagName'), // Tag name
attr = '', // Attributes string
cln = m.get('components'); // Children

var tag = m.get('tagName'), // Tag name
sTag = 0, // Single tag
attr = '', // Attributes string
cln = m.get('components'); // Children

_.each(m.get('attributes'),function(value, prop){
if(prop == 'onmousedown')
return;
attr += value && prop!='style' ? ' ' + prop + '="' + value + '" ' : '';
});

code += '<'+tag+' id="'+m.cid+'"' + attr + '>' + m.get('content');


if(m.get('type') == 'image'){
tag = 'img';
sTag = 1;
attr += 'src="' + m.get('src') + '"';
}

code += '<'+tag+' id="'+m.cid+'"' + attr + (sTag ? '/' : '') + '>' + m.get('content');

if(cln.length)
code += this.build(cln);

code += '</'+tag+'>';

if(!sTag)
code += '</'+tag+'>';

}, this);

return code;
},

});
});
7 changes: 7 additions & 0 deletions src/commands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ define(function(require) {
this.config = c;
this.Abstract = AbsCommands;

// Load commands passed by configuration
for( var k in c.defaults){
var obj = c.defaults[k];
if(obj.id)
this.add(obj.id, obj);
}

this.defaultCommands = {};
this.defaultCommands['select-comp'] = require('./view/SelectComponent');
this.defaultCommands['create-comp'] = require('./view/CreateComponent');
Expand Down
17 changes: 10 additions & 7 deletions src/commands/view/ImageComponent.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
define(['backbone', './InsertCustom'],
function(Backbone, InsertCustom) {
/**
/**
* @class ImageComponent
* */
return _.extend({}, InsertCustom, {

/**
* Trigger before insert
* @param {Object} object
*
*
* */
beforeInsert: function(object){
object.type = 'image';
object.style = {};
object.attributes = {};
if (!this.nearToFloat()) {
object.style.display = 'block';
}
// This allow to avoid 'ghosts' on drag
object.attributes.onmousedown = 'return false';
if (this.config.firstCentered && (this.$wp.get(0) == this.posTargetEl.get(0)) ) {
object.style.margin = '0 auto';
}
},

/**
* Trigger after insert
* @param {Object} model Model created after insert
*
*
* */
afterInsert: function(model){
model.trigger('dblclick');
if(this.sender)
this.sender.set('active', false);
},


});
});
45 changes: 25 additions & 20 deletions src/commands/view/InsertCustom.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,77 @@
define(['backbone', './SelectPosition'],
function(Backbone, SelectPosition) {
/**
/**
* @class InsertCustom
* */
return _.extend({}, SelectPosition, {
/**
* Run method

/**
* Run method
* */
run: function(em, sender){
this.enable();
this.em = em;
this.sender = sender;
this.opt = sender.get('options') || {};
this.opt = sender.get('options') || {};
this.content = this.opt.content;
},

enable: function(){
SelectPosition.enable.apply(this, arguments);
_.bindAll(this,'insertComponent');
this.$wp = this.$wrapper;
this.$wp.on('click', this.insertComponent);
},
/**

/**
* Start insert event
*
*
* @return void
* */
insertComponent: function(){
this.$wp.off('click', this.insertComponent);
this.stopSelectPosition();
this.removePositionPlaceholder();
var object = this.buildContent();
this.beforeInsert(object);
var model = this.posTargetCollection.add(object, { at: this.posIndex, silent:false });
this.beforeInsert(object);
var model = this.posTargetCollection.add(object, { at: this.posIndex, silent:false });
if(this.opt.terminateAfterInsert && this.sender)
this.sender.set('active',false);
else
this.enable();

if(this.em)
this.em.initChildrenComp(model);

this.afterInsert(model, this);
},

/**
* Trigger before insert
* @param {Object} obj
*
*
* @return void
* */
beforeInsert: function(obj){},

/**
* Trigger after insert
* @param {Object} model Model created after insert
*
*
* @return void
* */
afterInsert: function(model){},
/**

/**
* Create different object, based on content, to insert inside canvas
*
*
* @return {Object}
* */
buildContent: function(){
var result = {};
if(typeof this.content === 'string'){
result = {
content : this.content,
result = {
content : this.content,
tagName : 'span',
};
}else if(typeof this.content === 'object'){
Expand Down
9 changes: 5 additions & 4 deletions src/commands/view/OpenLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ define(['Navigator'], function(Layers) {
lyStylePfx = config.layers.stylePrefix || 'nv-';

config.layers.stylePrefix = config.stylePrefix + lyStylePfx;
var layers = new Layers(collection, config.layers);
this.$layers = layers.render();
config.layers.em = em;
var layers = new Layers(collection, config.layers);
this.$layers = layers.render();

// Check if panel exists otherwise crate it
if(!panels.getPanel('views-container'))
this.panel = panels.addPanel({ id: 'views-container'});
this.panel = panels.addPanel({ id: 'views-container'});
else
this.panel = panels.getPanel('views-container');
this.panel = panels.getPanel('views-container');

this.panel.set('appendContent', this.$layers).trigger('change:appendContent');
}
Expand Down
Loading

0 comments on commit 85a45db

Please sign in to comment.