Browse Source

Update Class Manager feature

pull/12/head
Artur Arseniev 11 years ago
parent
commit
e277db7a3c
  1. 1
      src/class_manager/template/classTag.html
  2. 11
      src/class_manager/view/ClassTagView.js
  3. 10
      src/class_manager/view/ClassTagsView.js
  4. 4
      src/commands/view/OpenStyleManager.js
  5. 19
      src/dom_components/model/Component.js
  6. 13
      src/dom_components/view/ComponentView.js
  7. 19
      styles/css/main.css
  8. 19
      styles/scss/main.scss

1
src/class_manager/template/classTag.html

@ -0,0 +1 @@
<%= label %> <span id="<%= pfx %>close">&Cross;</span>

11
src/class_manager/view/ClassTagView.js

@ -1,10 +1,12 @@
define(['backbone'], define(['backbone', 'text!./../template/classTag.html'],
function (Backbone) { function (Backbone, tagTemplate) {
/** /**
* @class ClassTagView * @class ClassTagView
* */ * */
return Backbone.View.extend({ return Backbone.View.extend({
template: _.template(tagTemplate),
initialize: function(o) { initialize: function(o) {
this.config = o.config || {}; this.config = o.config || {};
this.pfx = this.config.stylePrefix; this.pfx = this.config.stylePrefix;
@ -13,7 +15,10 @@ define(['backbone'],
/** @inheritdoc */ /** @inheritdoc */
render : function(){ render : function(){
this.$el.html(this.model.get('name')+': ' + this.model.get('label')); this.$el.html( this.template({
label: this.model.get('label'),
pfx: this.pfx,
}));
this.$el.attr('class', this.className); this.$el.attr('class', this.className);
return this; return this;
}, },

10
src/class_manager/view/ClassTagsView.js

@ -74,6 +74,9 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
* @param {Object} e * @param {Object} e
*/ */
componentChanged: function(e){ componentChanged: function(e){
this.compTarget = this.target.get('selectedComponent');
var models = this.compTarget ? this.compTarget.get('classes').models : [];
this.collection.reset(models);
}, },
/** /**
@ -102,7 +105,12 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
if(this.target){ if(this.target){
var cm = this.target.get('ClassManager'); var cm = this.target.get('ClassManager');
var model = cm.addClass(name); var model = cm.addClass(name);
console.log(model);
if(this.compTarget){
this.compTarget.get('classes').add(model);
}
console.log(this.compTarget);
} }
this.endNewTag(); this.endNewTag();
}, },

4
src/commands/view/OpenStyleManager.js

@ -24,8 +24,8 @@ define(['StyleManager'], function(StyleManager) {
// Class Manager container // Class Manager container
this.clm = em.get('ClassManager'); this.clm = em.get('ClassManager');
if(this.clm){ if(this.clm){
//this.$clm = this.clm.renderTags(); this.$clm = this.clm.renderTags();
//this.$cn2.append(this.$clm); this.$cn2.append(this.$clm);
} }
// Style Manager manager container // Style Manager manager container

19
src/dom_components/model/Component.js

@ -1,5 +1,5 @@
define(['backbone','./Components'], define(['backbone','./Components', 'ClassManager/model/ClassTags'],
function (Backbone, Components) { function (Backbone, Components, ClassTags) {
/** /**
* @class Component * @class Component
* */ * */
@ -25,8 +25,10 @@ define(['backbone','./Components'],
initialize: function(o) { initialize: function(o) {
this.config = o || {}; this.config = o || {};
this.defaultC = this.config.components || []; this.defaultC = this.config.components || [];
this.defaultCl = this.config.classes || [];
this.components = new Components(this.defaultC); this.components = new Components(this.defaultC);
this.set('components', this.components); this.set('components', this.components);
this.set('classes', new ClassTags(this.defaultCl));
}, },
/** /**
@ -34,14 +36,21 @@ define(['backbone','./Components'],
*/ */
clone: function() clone: function()
{ {
var attr = _.clone(this.attributes), var attr = _.clone(this.attributes),
comp = this.get('components'); comp = this.get('components'),
attr.components = []; cls = this.get('classes');
attr.components = [];
attr.classes = [];
if(comp.length){ if(comp.length){
comp.each(function(md,i){ comp.each(function(md,i){
attr.components[i] = md.clone(); attr.components[i] = md.clone();
}); });
} }
if(cls.length){
cls.each(function(md,i){
attr.classes[i] = md.clone();
});
}
return new this.constructor(attr); return new this.constructor(attr);
}, },

13
src/dom_components/view/ComponentView.js

@ -23,6 +23,7 @@ define(['backbone', './ComponentsView'],
this.listenTo(this.model, 'change:style', this.updateStyle); this.listenTo(this.model, 'change:style', this.updateStyle);
this.listenTo(this.model, 'change:attributes', this.updateAttributes); this.listenTo(this.model, 'change:attributes', this.updateAttributes);
this.listenTo(this.model, 'change:status', this.updateStatus); this.listenTo(this.model, 'change:status', this.updateStatus);
this.listenTo(this.model.get('classes'), 'add remove change', this.updateClasses);
this.$el.data("model", this.model); this.$el.data("model", this.model);
this.$el.data("model-comp", this.components); this.$el.data("model-comp", this.components);
}, },
@ -109,12 +110,16 @@ define(['backbone', './ComponentsView'],
/** /**
* Update classe attribute * Update classe attribute
*
* @return void
* */ * */
updateClasses: function(){ updateClasses: function(){
if(this.classe.length) var str = '';
this.$el.attr('class', this.classe.join(" ")); this.model.get('classes').each(function(model){
str += model.get('name') + ' ';
});
this.$el.attr('class',str.trim());
// Regenerate status class
this.updateStatus();
}, },
/** /**

19
styles/css/main.css

@ -2568,7 +2568,7 @@ See http://bgrins.github.io/spectrum/themes/ for instructions.
.wte-test::btn { .wte-test::btn {
color: '#fff'; } color: '#fff'; }
.opac50 { .opac50, .wte-clm-tags #wte-clm-close {
opacity: 0.5; opacity: 0.5;
filter: alpha(opacity=50); } filter: alpha(opacity=50); }
@ -2587,7 +2587,7 @@ html, body, #wte-app, .wte-editor {
.clear { .clear {
clear: both; } clear: both; }
.no-select, .wte-com-no-select, .wte-com-no-select img { .no-select, .wte-com-no-select, .wte-com-no-select img, .wte-clm-tags #wte-clm-close {
-moz-user-select: none; -moz-user-select: none;
-khtml-user-select: none; -khtml-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
@ -3216,6 +3216,9 @@ ol.example li.placeholder:before {
clear: both; clear: both;
padding: 5px; padding: 5px;
margin-bottom: 5px; } margin-bottom: 5px; }
.wte-clm-tags #wte-clm-tags-c {
display: inline-block;
vertical-align: top; }
.wte-clm-tags #wte-clm-add-tag { .wte-clm-tags #wte-clm-add-tag {
background-color: #535353; background-color: #535353;
border-radius: 2px; border-radius: 2px;
@ -3229,10 +3232,20 @@ ol.example li.placeholder:before {
display: none; } display: none; }
.wte-clm-tags .wte-clm-tag { .wte-clm-tags .wte-clm-tag {
background-color: #804f7b; background-color: #804f7b;
border: 1px solid #5a3857;
box-shadow: 1px 1px #9c6196 inset;
text-shadow: 1px 1px #6a4166;
display: inline-block; display: inline-block;
border-radius: 2px; border-radius: 3px;
margin: 0 3px 3px 0; margin: 0 3px 3px 0;
padding: 4px; } padding: 4px; }
.wte-clm-tags #wte-clm-close {
font-size: 20px;
line-height: 0;
cursor: pointer; }
.wte-clm-tags #wte-clm-close:hover {
opacity: 0.7;
filter: alpha(opacity=70); }
/********* END Class manager **********/ /********* END Class manager **********/
/********* Modal dialog **********/ /********* Modal dialog **********/

19
styles/scss/main.scss

@ -747,6 +747,10 @@ $tagBg: #804f7b;
padding: 5px; padding: 5px;
margin-bottom: 5px; margin-bottom: 5px;
} }
##{$clm-prefix}tags-c{
display: inline-block;
vertical-align: top;
}
##{$clm-prefix}add-tag{ ##{$clm-prefix}add-tag{
background-color: $addBtnBg; background-color: $addBtnBg;
@ -766,11 +770,24 @@ $tagBg: #804f7b;
.#{$clm-prefix}tag { .#{$clm-prefix}tag {
background-color: $tagBg; background-color: $tagBg;
border: 1px solid darken($tagBg, 12%);
box-shadow: 1px 1px lighten($tagBg, 9%) inset;
text-shadow: 1px 1px darken($tagBg, 7%);
display: inline-block; display: inline-block;
border-radius:2px; border-radius:3px;
margin: 0 3px 3px 0; margin: 0 3px 3px 0;
padding: 4px; padding: 4px;
} }
##{$clm-prefix}close {
@extend .opac50;
font-size: 20px;
line-height: 0;
cursor:pointer;
@extend .no-select;
&:hover{
@include opacity(0.7);
}
}
} }
/********* END Class manager **********/ /********* END Class manager **********/

Loading…
Cancel
Save