diff --git a/src/class_manager/template/classTag.html b/src/class_manager/template/classTag.html new file mode 100644 index 000000000..b0e68fe49 --- /dev/null +++ b/src/class_manager/template/classTag.html @@ -0,0 +1 @@ +<%= label %> \ No newline at end of file diff --git a/src/class_manager/view/ClassTagView.js b/src/class_manager/view/ClassTagView.js index 6354e38d9..4297f2fe8 100644 --- a/src/class_manager/view/ClassTagView.js +++ b/src/class_manager/view/ClassTagView.js @@ -1,10 +1,12 @@ -define(['backbone'], - function (Backbone) { +define(['backbone', 'text!./../template/classTag.html'], + function (Backbone, tagTemplate) { /** * @class ClassTagView * */ return Backbone.View.extend({ + template: _.template(tagTemplate), + initialize: function(o) { this.config = o.config || {}; this.pfx = this.config.stylePrefix; @@ -13,7 +15,10 @@ define(['backbone'], /** @inheritdoc */ 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); return this; }, diff --git a/src/class_manager/view/ClassTagsView.js b/src/class_manager/view/ClassTagsView.js index 2f3e09ff9..52a54de13 100644 --- a/src/class_manager/view/ClassTagsView.js +++ b/src/class_manager/view/ClassTagsView.js @@ -74,6 +74,9 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'], * @param {Object} 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){ var cm = this.target.get('ClassManager'); var model = cm.addClass(name); - console.log(model); + + if(this.compTarget){ + this.compTarget.get('classes').add(model); + } + + console.log(this.compTarget); } this.endNewTag(); }, diff --git a/src/commands/view/OpenStyleManager.js b/src/commands/view/OpenStyleManager.js index ec5dec4cf..dab1705ea 100644 --- a/src/commands/view/OpenStyleManager.js +++ b/src/commands/view/OpenStyleManager.js @@ -24,8 +24,8 @@ define(['StyleManager'], function(StyleManager) { // Class Manager container this.clm = em.get('ClassManager'); if(this.clm){ - //this.$clm = this.clm.renderTags(); - //this.$cn2.append(this.$clm); + this.$clm = this.clm.renderTags(); + this.$cn2.append(this.$clm); } // Style Manager manager container diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index c77160541..c3ae55c7e 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -1,5 +1,5 @@ -define(['backbone','./Components'], - function (Backbone, Components) { +define(['backbone','./Components', 'ClassManager/model/ClassTags'], + function (Backbone, Components, ClassTags) { /** * @class Component * */ @@ -25,8 +25,10 @@ define(['backbone','./Components'], initialize: function(o) { this.config = o || {}; this.defaultC = this.config.components || []; + this.defaultCl = this.config.classes || []; this.components = new Components(this.defaultC); this.set('components', this.components); + this.set('classes', new ClassTags(this.defaultCl)); }, /** @@ -34,14 +36,21 @@ define(['backbone','./Components'], */ clone: function() { - var attr = _.clone(this.attributes), - comp = this.get('components'); - attr.components = []; + var attr = _.clone(this.attributes), + comp = this.get('components'), + cls = this.get('classes'); + attr.components = []; + attr.classes = []; if(comp.length){ comp.each(function(md,i){ attr.components[i] = md.clone(); }); } + if(cls.length){ + cls.each(function(md,i){ + attr.classes[i] = md.clone(); + }); + } return new this.constructor(attr); }, diff --git a/src/dom_components/view/ComponentView.js b/src/dom_components/view/ComponentView.js index 761256f9a..a3c531b94 100644 --- a/src/dom_components/view/ComponentView.js +++ b/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:attributes', this.updateAttributes); 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-comp", this.components); }, @@ -109,12 +110,16 @@ define(['backbone', './ComponentsView'], /** * Update classe attribute - * - * @return void * */ updateClasses: function(){ - if(this.classe.length) - this.$el.attr('class', this.classe.join(" ")); + var str = ''; + this.model.get('classes').each(function(model){ + str += model.get('name') + ' '; + }); + this.$el.attr('class',str.trim()); + + // Regenerate status class + this.updateStatus(); }, /** diff --git a/styles/css/main.css b/styles/css/main.css index 8583b1b5f..e4fb5d551 100644 --- a/styles/css/main.css +++ b/styles/css/main.css @@ -2568,7 +2568,7 @@ See http://bgrins.github.io/spectrum/themes/ for instructions. .wte-test::btn { color: '#fff'; } -.opac50 { +.opac50, .wte-clm-tags #wte-clm-close { opacity: 0.5; filter: alpha(opacity=50); } @@ -2587,7 +2587,7 @@ html, body, #wte-app, .wte-editor { .clear { 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; -khtml-user-select: none; -webkit-user-select: none; @@ -3216,6 +3216,9 @@ ol.example li.placeholder:before { clear: both; padding: 5px; margin-bottom: 5px; } + .wte-clm-tags #wte-clm-tags-c { + display: inline-block; + vertical-align: top; } .wte-clm-tags #wte-clm-add-tag { background-color: #535353; border-radius: 2px; @@ -3229,10 +3232,20 @@ ol.example li.placeholder:before { display: none; } .wte-clm-tags .wte-clm-tag { background-color: #804f7b; + border: 1px solid #5a3857; + box-shadow: 1px 1px #9c6196 inset; + text-shadow: 1px 1px #6a4166; display: inline-block; - border-radius: 2px; + border-radius: 3px; margin: 0 3px 3px 0; 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 **********/ /********* Modal dialog **********/ diff --git a/styles/scss/main.scss b/styles/scss/main.scss index cf488cb6e..f2ffcba40 100644 --- a/styles/scss/main.scss +++ b/styles/scss/main.scss @@ -747,6 +747,10 @@ $tagBg: #804f7b; padding: 5px; margin-bottom: 5px; } + ##{$clm-prefix}tags-c{ + display: inline-block; + vertical-align: top; + } ##{$clm-prefix}add-tag{ background-color: $addBtnBg; @@ -766,11 +770,24 @@ $tagBg: #804f7b; .#{$clm-prefix}tag { 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; - border-radius:2px; + border-radius:3px; margin: 0 3px 3px 0; 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 **********/