Browse Source

Fix parser for chrome

pull/36/head
Artur Arseniev 10 years ago
parent
commit
7378b66733
  1. 2
      bower.json
  2. 30
      dist/grapes.min.js
  3. 2
      package.json
  4. 78
      src/asset_manager/main.js
  5. 10
      src/asset_manager/model/Asset.js
  6. 22
      src/asset_manager/model/AssetImage.js
  7. 24
      src/asset_manager/model/Assets.js
  8. 3
      src/asset_manager/view/AssetsView.js
  9. 1
      src/commands/view/Preview.js
  10. 9
      src/editor/main.js
  11. 2
      src/parser/model/ParserCss.js
  12. 60
      test/specs/asset_manager/main.js
  13. 14
      test/specs/asset_manager/model/Asset.js
  14. 2
      test/specs/asset_manager/model/AssetImage.js
  15. 2
      test/specs/asset_manager/view/AssetImageView.js

2
bower.json

@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.3.7",
"version": "0.3.8",
"author": "Artur Arseniev",
"homepage": "http://grapesjs.com",
"main": [

30
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.3.7",
"version": "0.3.8",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",

78
src/asset_manager/main.js

@ -1,32 +1,55 @@
/**
* * [add](#add)
* * [get](#get)
* * [getAll](#getall)
* * [render](#render)
*
* Before using methods you should get first the module from the editor instance, in this way:
*
* ```js
* var assetManager = editor.AssetManager;
* ```
*
* @module AssetManager
* @param {Object} config Configurations
* @param {Array<Object>} [config.blocks=[]] Default blocks
* @example
* ...
* assetManager: {
* assets: [
* {src:'path/to/image.png'},
* ...
* ],
* }
* ...
*/
define(function(require) {
var AssetManager = function(config) {
var c = config || {},
defaults = require('./config/config'),
Assets = require('./model/Assets'),
AssetsView = require('./view/AssetsView'),
FileUpload = require('./view/FileUploader');
return function(config) {
var c = config || {},
defaults = require('./config/config'),
Assets = require('./model/Assets'),
AssetsView = require('./view/AssetsView'),
FileUpload = require('./view/FileUploader');
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,
var assets = new Assets(c.assets);
var obj = {
collection: assets,
config: c,
};
this.am = new AssetsView(obj);
this.fu = new FileUpload(obj);
};
AssetManager.prototype = {
var am = new AssetsView(obj);
var fu = new FileUpload(obj);
return {
/**
* Add new asset/s to the collection. URLs are supposed to be unique
* @param {string|Object|Array<string>|Array<Object>} assets URL strings or an objects representing the resource.
* @param {string|Object|Array<string>|Array<Object>} asset URL strings or an objects representing the resource.
* @return {this}
* @example
* // In case of strings, would be interpreted as images
@ -48,19 +71,19 @@ define(function(require) {
* type: 'image',
* }]);
*/
add: function(assets){
return this;
add: function(asset){
return assets.add(asset);
},
/**
* Return the asset by URL
* @param {string} id URL of the asset
* @param {string} src URL of the asset
* @return {Object} Object representing the asset
* @example
* var asset = assetManager.get('http://img.jpg');
*/
get: function(id){
return {};
get: function(src){
return assets.where({src: src})[0];
},
/**
@ -106,7 +129,7 @@ define(function(require) {
* @return {Object}
* */
getAssets : function(){
return this.assets;
return assets;
},
/**
@ -116,7 +139,7 @@ define(function(require) {
* @return void
* */
setTarget : function(m){
this.am.collection.target = m;
am.collection.target = m;
},
/**
@ -126,7 +149,7 @@ define(function(require) {
* @return void
* */
onSelect : function(f){
this.am.collection.onSelect = f;
am.collection.onSelect = f;
},
/**
@ -135,10 +158,9 @@ define(function(require) {
*/
render : function(f){
if(!this.rendered || f)
this.rendered = this.am.render().$el.add(this.fu.render().$el);
this.rendered = am.render().$el.add(fu.render().$el);
return this.rendered;
},
}
};
};
return AssetManager;
});

10
src/asset_manager/model/Asset.js

@ -5,13 +5,11 @@ define(['backbone'],
* */
return Backbone.Model.extend({
defaults: {
type: 'none', //Type of the asset
src: '', //Location
},
idAttribute: 'src',
initialize: function(options) {
this.options = options || {};
defaults: {
type: '',
src: '',
},
/**

22
src/asset_manager/model/AssetImage.js

@ -1,18 +1,16 @@
define(['backbone', './Asset'],
define(['backbone', './Asset'],
function (Backbone, Asset) {
/**
* @class AssetImage
* */
return Asset.extend({
defaults: _.extend({},Asset.prototype.defaults,
{
type: 'image',
unitDim: 'px',
height: 0,
width: 0,
}
),
return Asset.extend({
defaults: _.extend({}, Asset.prototype.defaults, {
type: 'image',
unitDim: 'px',
height: 0,
width: 0,
}),
});
});

24
src/asset_manager/model/Assets.js

@ -1,11 +1,24 @@
define(['backbone','./Asset'],
function (Backbone, Asset) {
define(['backbone', './Asset', './AssetImage'],
function (Backbone, Asset, AssetImage) {
/**
* @class Assets
* */
return Backbone.Collection.extend({
model: Asset,
model: AssetImage,
initialize: function(models, opt){
this.model = function(attrs, options) {
var model;
switch(attrs.type){
default:
model = new AssetImage(attrs, options);
}
return model;
};
},
/**
* Add new image asset to the collection
@ -24,6 +37,7 @@ define(['backbone','./Asset'],
/**
* Prevent inserting assets with the same 'src'
* Seems like idAttribute is not working with dynamic model assignament
* @private
*/
add: function(models, opt) {
@ -33,6 +47,9 @@ define(['backbone','./Asset'],
for (var i = 0, len = models.length; i < len; i++) {
var model = models[i];
if(typeof model === 'string')
model = {src: model, type: 'image'};
if(!model || !model.src)
continue;
@ -48,5 +65,6 @@ define(['backbone','./Asset'],
return Backbone.Collection.prototype.add.apply(this, [mods, opt]);
},
});
});

3
src/asset_manager/view/AssetsView.js

@ -142,7 +142,8 @@ define(['backbone', './AssetView', './AssetImageView', './FileUploader', 'text!.
fragment.appendChild( rendered );
}else{
var assetsEl = this.getAssetsEl();
assetsEl.insertBefore(rendered, assetsEl.firstChild);
if(assetsEl)
assetsEl.insertBefore(rendered, assetsEl.firstChild);
}
return rendered;

1
src/commands/view/Preview.js

@ -40,6 +40,7 @@ define(function() {
stop: function(editor, sender) {
var panels = this.getPanels(editor);
editor.runCommand('sw-visibility');
editor.getModel().runDefault();
panels.style.display = 'block';
var canvas = editor.Canvas.getElement();
canvas.setAttribute('style', '');

9
src/editor/main.js

@ -362,6 +362,15 @@ define(function (require){
return editorView.el;
},
/**
* Returns editor model
* @return {Model}
* @private
*/
getModel: function(){
return em;
},
/**
* Render editor
* @return {HTMLElement}

2
src/parser/model/ParserCss.js

@ -46,7 +46,7 @@ define(function(require) {
// It's a CSSMediaRule
if(node.cssRules){
var subRules = this.parseNode(node);
var width = node.conditionText.match(/-width:(.*)\)/i)[1];
var width = node.media.mediaText.match(/-width:(.*)\)/i)[1];
for(var s = 0, lens = subRules.length; s < lens; s++){
var subRule = subRules[s];
subRule.maxWidth = width ? width.trim() : '';

60
test/specs/asset_manager/main.js

@ -4,15 +4,67 @@ define(['AssetManager'],
describe('Asset Manager', function() {
describe('Main', function() {
var obj;
var imgObj;
beforeEach(function () {
imgObj = {
src: 'path/to/image',
width: 101,
height: 102,
};
obj = new AssetManager();
});
afterEach(function () {
delete obj;
});
it('Object exists', function() {
AssetManager.should.be.exist;
obj.should.be.exist;
});
it('No assets inside', function() {
var obj = new AssetManager();
obj.getAssets().length.should.be.empty;
obj.getAll().length.should.be.empty;
});
it('Add new asset', function() {
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
it('Added asset has correct data', function() {
obj.add(imgObj);
var asset = obj.get(imgObj.src);
asset.get('width').should.equal(imgObj.width);
asset.get('height').should.equal(imgObj.height);
asset.get('type').should.equal('image');
});
it('Add asset with src', function() {
obj.add(imgObj.src);
var asset = obj.get(imgObj.src);
asset.get('type').should.equal('image');
asset.get('src').should.equal(imgObj.src);
});
it('Add asset with more src', function() {
obj.add([imgObj.src, imgObj.src + '2']);
obj.getAll().length.should.equal(2);
var asset1 = obj.getAll().at(0);
var asset2 = obj.getAll().at(1);
asset1.get('src').should.equal(imgObj.src);
asset2.get('src').should.equal(imgObj.src + '2');
});
it('Src is unique', function() {
obj.add(imgObj);
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
/*
it('AssetsView exists and is an instance of Backbone.View', function() {
var obj = new AssetManager();
obj.am.should.be.exist;
@ -51,7 +103,7 @@ define(['AssetManager'],
obj.fu.render.calledOnce.should.equal(true);
obj.rendered.should.not.be.empty;
});
*/
});
});
});

14
test/specs/asset_manager/model/Asset.js

@ -1,35 +1,35 @@
define(['AssetManager/model/Asset'],
function(Asset) {
describe('Asset Manager', function() {
describe('Asset', function() {
it('Object exists', function() {
Asset.should.be.exist;
});
it('Has default values', function() {
var obj = new Asset({});
obj.get('type').should.equal("none");
obj.get('type').should.equal("");
obj.get('src').should.equal("");
obj.getExtension().should.be.empty;
obj.getFilename().should.be.empty;
});
it('Test getFilename', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getFilename().should.equal('t.e.s.t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc'});
obj.getFilename().should.equal('1234abc');
});
it('Test getExtension', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getExtension().should.equal('t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc.'});
obj.getExtension().should.equal('');
});
});
});
});

2
test/specs/asset_manager/model/AssetImage.js

@ -9,7 +9,7 @@ define(['AssetManager/model/AssetImage'],
});
it('Has default values', function() {
var obj = new AssetImage({});
var obj = new AssetImage({});
obj.get('type').should.equal("image");
obj.get('src').should.equal("");
obj.get('unitDim').should.equal("px");

2
test/specs/asset_manager/view/AssetImageView.js

@ -22,7 +22,7 @@ define(['AssetManager/view/AssetImageView', 'AssetManager/model/AssetImage', 'As
});
afterEach(function () {
this.view.model.destroy();
delete this.view;
});
after(function () {

Loading…
Cancel
Save