Browse Source

Add frame to the canvas

pull/36/head
Artur Arseniev 10 years ago
parent
commit
31dd50c377
  1. 45
      src/canvas/main.js
  2. 10
      src/canvas/model/Canvas.js
  3. 14
      src/canvas/model/Frame.js
  4. 23
      src/canvas/view/CanvasView.js
  5. 40
      src/canvas/view/FrameView.js
  6. 10
      src/commands/view/CommandAbstract.js
  7. 3
      src/commands/view/SelectComponent.js
  8. 4
      src/editor/view/EditorView.js
  9. 29
      styles/css/main.css
  10. 20
      styles/scss/main.scss

45
src/canvas/main.js

@ -2,7 +2,7 @@ define(function(require) {
/** /**
* @class Canvas * @class Canvas
* @param {Object} Configurations * @param {Object} Configurations
* *
* @return {Object} * @return {Object}
* */ * */
var Canvas = function(config) var Canvas = function(config)
@ -16,45 +16,56 @@ define(function(require) {
if (!(name in c)) if (!(name in c))
c[name] = defaults[name]; c[name] = defaults[name];
} }
this.canvas = new Canvas(config); this.canvas = new Canvas(config);
var obj = { var obj = {
model : this.canvas, model : this.canvas,
config : c, config : c,
}; };
this.CanvasView = new CanvasView(obj); this.CanvasView = new CanvasView(obj);
}; };
Canvas.prototype = { Canvas.prototype = {
/** /**
* Add wrapper * Add wrapper
* @param {Object} wrp Wrapper * @param {Object} wrp Wrapper
* *
* */ * */
setWrapper : function(wrp) setWrapper: function(wrp) {
{
this.canvas.set('wrapper', wrp); this.canvas.set('wrapper', wrp);
}, },
/** /**
* Get wrapper * Get wrapper
* *
* @return {Object} * @return {Object}
* */ * */
getWrapper : function() getWrapper: function() {
{
return this.canvas.get('wrapper').getComponent(); return this.canvas.get('wrapper').getComponent();
}, },
getFrameWrapperEl: function(){
return this.CanvasView.frame.getWrapper();
},
/**
* Returns body element of the frame
* @return {[type]} [description]
*/
getBody: function(){
return this.CanvasView.frame.el.contentDocument.body;
},
/** /**
* Render canvas * Render canvas
* */ * */
render : function() render: function() {
{ return this.CanvasView.render().el;
return this.CanvasView.render().$el;
}, },
}; };
return Canvas; return Canvas;
}); });

10
src/canvas/model/Canvas.js

@ -1,12 +1,18 @@
define(['backbone'], define(['backbone', './Frame'],
function(Backbone){ function(Backbone, Frame){
return Backbone.Model.extend({ return Backbone.Model.extend({
defaults :{ defaults :{
frame: '',
wrapper: '', wrapper: '',
rulers: false, rulers: false,
}, },
initialize: function(config) {
var conf = this.conf || {};
this.set('frame', new Frame(conf.frame));
},
}); });
}); });

14
src/canvas/model/Frame.js

@ -0,0 +1,14 @@
define(['backbone'],
function(Backbone){
return Backbone.Model.extend({
defaults :{
wrapper: '',
width: '',
height: '',
attributes: {},
},
});
});

23
src/canvas/view/CanvasView.js

@ -1,25 +1,32 @@
define(['backbone'], define(['backbone','./FrameView'],
function(Backbone) { function(Backbone, FrameView) {
/** /**
* @class CanvasView * @class CanvasView
* */ * */
return Backbone.View.extend({ return Backbone.View.extend({
//id: 'canvas',
initialize: function(o) { initialize: function(o) {
this.config = o.config; this.config = o.config;
this.className = this.config.stylePrefix + 'canvas'; this.className = this.config.stylePrefix + 'canvas';
this.frame = new FrameView({
model: this.model.get('frame')
});
}, },
render: function() { render: function() {
this.wrapper = this.model.get('wrapper'); this.wrapper = this.model.get('wrapper');
if(this.wrapper && typeof this.wrapper.render == 'function'){ if(this.wrapper && typeof this.wrapper.render == 'function'){
this.$el.append( this.wrapper.render() ); this.model.get('frame').set('wrapper', this.wrapper);
var wrap = this.wrapper.render();
this.$el.append(this.frame.render().el);
var frame = this.frame;
frame.el.onload = function(){ frame.renderWrapper(); };
} }
this.$el.attr({class: this.className, id: this.config.canvasId}); this.$el.attr({class: this.className, id: this.config.canvasId});
return this; return this;
}, },
}); });
}); });

40
src/canvas/view/FrameView.js

@ -0,0 +1,40 @@
define(['backbone'],
function(Backbone) {
/**
* @class CanvasView
* */
return Backbone.View.extend({
tagName: 'iframe',
attributes: {
src: 'about:blank'
},
getBody: function(){
this.$el.contents().find('body');
},
getWrapper: function(){
return this.$el.contents().find('body div');
},
renderWrapper: function(){
var wrap = this.model.get('wrapper');
if(wrap){
var body = this.$el.contents().find('body');
body.append(wrap.render());
}
},
render: function() {
this.$el.attr({
class: 'testframe',
style: 'width: 50%; display: block; height: 80%; border: medium none; margin: 50px auto 0; background-color: white',
});
return this;
},
});
});

10
src/commands/view/CommandAbstract.js

@ -22,10 +22,20 @@ define(['backbone'],
this.badgeClass = this.pfx + 'badge'; this.badgeClass = this.pfx + 'badge';
this.plhClass = this.pfx + 'placeholder'; this.plhClass = this.pfx + 'placeholder';
this.freezClass = this.ppfx + 'freezed'; this.freezClass = this.ppfx + 'freezed';
if(this.editorModel.get) if(this.editorModel.get)
this.setElement(this.editorModel.get('$editor').find('#'+this.canvasId)); this.setElement(this.editorModel.get('$editor').find('#'+this.canvasId));
//TODO refactor
var fbody = this.editorModel.Canvas.getBody();
this.setElement(fbody);
this.$canvas = this.$el; this.$canvas = this.$el;
this.$wrapper = this.$canvas.find('#'+this.wrapperId); this.$wrapper = this.$canvas.find('#'+this.wrapperId);
//TODO refactor
this.$wrapper = $(fbody.querySelector('#wrapper'));
this.init(this.config); this.init(this.config);
}, },

3
src/commands/view/SelectComponent.js

@ -50,6 +50,9 @@ define(function() {
* */ * */
startSelectComponent: function() { startSelectComponent: function() {
var that = this; var that = this;
// TODO
//this.setElement(this.editorModel.Canvas.getFrameWrapperEl());
//$el should be "canvas"
this.$el.find('*') this.$el.find('*')
.on('mouseover',this.onHover) .on('mouseover',this.onHover)
.on('mouseout', this.onOut) .on('mouseout', this.onOut)

4
src/editor/view/EditorView.js

@ -23,6 +23,8 @@ function(Backbone){
this.model.set('$editor', this.$el); this.model.set('$editor', this.$el);
this.$cont.html(this.$el);
// Canvas // Canvas
if(this.cv) if(this.cv)
this.$el.append(this.cv.render()); this.$el.append(this.cv.render());
@ -37,8 +39,6 @@ function(Backbone){
this.$el.attr('class', this.className); this.$el.attr('class', this.className);
this.$cont.html(this.$el);
if(this.pn) if(this.pn)
this.pn.active(); this.pn.active();

29
styles/css/main.css

@ -2630,6 +2630,7 @@ See http://bgrins.github.io/spectrum/themes/ for instructions.
/************* CANVAS ****************/ /************* CANVAS ****************/
.wte-cv-canvas { .wte-cv-canvas {
background-color: rgba(0, 0, 0, 0.15);
position: absolute; position: absolute;
width: 80%; width: 80%;
height: 100%; height: 100%;
@ -2778,7 +2779,7 @@ ol.example li.placeholder:before {
height: 100%; height: 100%;
width: 3.5%; width: 3.5%;
left: 0; left: 0;
box-shadow: 0 0 5px #333; } box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); }
.wte-pn-panel#wte-pn-options { .wte-pn-panel#wte-pn-options {
min-width: 35px; min-width: 35px;
height: 100%; height: 100%;
@ -2786,12 +2787,6 @@ ol.example li.placeholder:before {
left: 0; left: 0;
bottom: 0; bottom: 0;
height: auto; } height: auto; }
.wte-pn-panel#wte-pn-commands, .wte-pn-panel#wte-pn-options2 {
min-width: 35px;
height: 100%;
width: 3.5%;
left: 0;
box-shadow: 0 0 5px #333; }
.wte-pn-panel#wte-pn-options2 { .wte-pn-panel#wte-pn-options2 {
bottom: 150px; bottom: 150px;
height: auto; } height: auto; }
@ -2810,7 +2805,7 @@ ol.example li.placeholder:before {
right: 0; right: 0;
width: 16.5%; width: 16.5%;
overflow: auto; overflow: auto;
box-shadow: 0 0 5px #333; } box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); }
.wte-pn-btn, .wte-btnt { .wte-pn-btn, .wte-btnt {
box-sizing: border-box; box-sizing: border-box;
@ -2994,11 +2989,11 @@ ol.example li.placeholder:before {
font-size: 11px; font-size: 11px;
font-weight: lighter; font-weight: lighter;
padding: 10px; padding: 10px;
text-shadow: 0 1px 0 #252525; } text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }
.wte-sm-sector, .wte-clm-tags { .wte-sm-sector, .wte-clm-tags {
clear: both; clear: both;
border-bottom: 1px solid #303030; border-bottom: 1px solid rgba(0, 0, 0, 0.15);
color: #eee; color: #eee;
font-weight: lighter; font-weight: lighter;
text-align: left; text-align: left;
@ -3010,13 +3005,13 @@ ol.example li.placeholder:before {
padding-right: 5px; padding-right: 5px;
font-size: 11px; } font-size: 11px; }
.wte-sm-sector .wte-sm-title, .wte-clm-tags .wte-sm-title { .wte-sm-sector .wte-sm-title, .wte-clm-tags .wte-sm-title {
background-color: #3a3a3a; background-color: rgba(0, 0, 0, 0.15);
font-size: 13px; font-size: 13px;
letter-spacing: 1px; letter-spacing: 1px;
padding: 12px 10px 12px 20px; padding: 12px 10px 12px 20px;
text-shadow: 0 1px 0 #252525; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
border-bottom: 1px solid #303030; border-bottom: 1px solid rgba(0, 0, 0, 0.15);
border-top: 1px solid #414141; border-top: 1px solid rgba(255, 255, 255, 0.05);
cursor: pointer; } cursor: pointer; }
.wte-sm-sector .wte-sm-label, .wte-clm-tags .wte-sm-label { .wte-sm-sector .wte-sm-label, .wte-clm-tags .wte-sm-label {
margin: 5px 5px 2px 0; } margin: 5px 5px 2px 0; }
@ -3121,7 +3116,7 @@ ol.example li.placeholder:before {
color: transparent; } color: transparent; }
.wte-sm-sector .wte-sm-list .wte-sm-el, .wte-clm-tags .wte-sm-list .wte-sm-el { .wte-sm-sector .wte-sm-list .wte-sm-el, .wte-clm-tags .wte-sm-list .wte-sm-el {
float: left; float: left;
border-left: 1px solid #252525; border-left: 1px solid rgba(0, 0, 0, 0.3);
text-shadow: 0 1px 0 #232323; text-shadow: 0 1px 0 #232323;
/*232323*/ } /*232323*/ }
.wte-sm-sector .wte-sm-list .wte-sm-el:first-child, .wte-clm-tags .wte-sm-list .wte-sm-el:first-child { .wte-sm-sector .wte-sm-list .wte-sm-el:first-child, .wte-clm-tags .wte-sm-list .wte-sm-el:first-child {
@ -3162,13 +3157,13 @@ ol.example li.placeholder:before {
width: 100%; width: 100%;
padding: 0 5px; } padding: 0 5px; }
.wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box { .wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box {
background-color: #414141; background-color: rgba(255, 255, 255, 0.05);
border-radius: 2px; border-radius: 2px;
margin-top: 5px; margin-top: 5px;
position: relative; position: relative;
overflow: hidden; } overflow: hidden; }
.wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box.wte-sm-show, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box.wte-sm-show { .wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box.wte-sm-show, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box.wte-sm-show {
border: 1px solid #3f3f3f; border: 1px solid rgba(252, 252, 252, 0.05);
padding: 3px 5px; } padding: 3px 5px; }
.wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box #wte-sm-close, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box #wte-sm-close { .wte-sm-sector .wte-sm-property.wte-sm-file #wte-sm-preview-box #wte-sm-close, .wte-clm-tags .wte-sm-property.wte-sm-file #wte-sm-preview-box #wte-sm-close {
display: block; } display: block; }

20
styles/scss/main.scss

@ -118,6 +118,7 @@ $imageCompDim: 50px;
} }
/************* CANVAS ****************/ /************* CANVAS ****************/
.#{$cv-prefix}canvas { .#{$cv-prefix}canvas {
background-color: rgba(0, 0, 0, 0.15);
position: absolute; position: absolute;
width: 80%; width: 80%;
height: 100%; height: 100%;
@ -254,7 +255,7 @@ $leftWidth: 16.5%;
min-width: 35px; min-width: 35px;
height: 100%; height: 100%;
width: 3.5%; left:0; width: 3.5%; left:0;
box-shadow: 0 0 5px #333; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
} }
&##{$pn-prefix}options{ &##{$pn-prefix}options{
@ -265,13 +266,6 @@ $leftWidth: 16.5%;
height: auto; height: auto;
} }
&##{$pn-prefix}commands{
min-width: 35px;
height: 100%;
width: 3.5%; left:0;
box-shadow: 0 0 5px #333;
}
&##{$pn-prefix}options2{ &##{$pn-prefix}options2{
@extend ##{$pn-prefix}commands; @extend ##{$pn-prefix}commands;
bottom: 150px; bottom: 150px;
@ -297,7 +291,7 @@ $leftWidth: 16.5%;
right: 0; right: 0;
width: $leftWidth; width: $leftWidth;
overflow: auto; overflow: auto;
box-shadow: 0 0 5px #333; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
} }
} }
@ -473,9 +467,9 @@ $leftWidth: 16.5%;
/********* Style Manager **********/ /********* Style Manager **********/
$darkBorder: darken($mainDkColor,4%); /*303030*/ $darkBorder: rgba(0, 0, 0, 0.15); /*303030*/
$lightBorder: lighten($mainDkColor,3%); /*414141*/ $lightBorder: rgba(255, 255, 255, 0.05); /*414141*/
$darkTextShadow: darken($mainDkColor,8%); /*#252525*/ $darkTextShadow: rgba(0, 0, 0, 0.3); /*#252525*/
$inputFontColor: darken($fontColor,10%); /*#d5d5d5*/ $inputFontColor: darken($fontColor,10%); /*#d5d5d5*/
$arrowColor: darken($fontColor,24%); /*b1b1b1*/ $arrowColor: darken($fontColor,24%); /*b1b1b1*/
@ -510,7 +504,7 @@ $arrowColor: darken($fontColor,24%); /*b1b1b1*/
} }
.#{$sm-prefix}title{ .#{$sm-prefix}title{
background-color: $mainDkColor; background-color: $darkBorder;
font-size: 13px; font-size: 13px;
letter-spacing: 1px; letter-spacing: 1px;
padding: 12px 10px 12px 20px; padding: 12px 10px 12px 20px;

Loading…
Cancel
Save