diff --git a/src/code_manager/model/HtmlGenerator.js b/src/code_manager/model/HtmlGenerator.js
index 888e219d9..5a89a8ffa 100644
--- a/src/code_manager/model/HtmlGenerator.js
+++ b/src/code_manager/model/HtmlGenerator.js
@@ -11,42 +11,7 @@ define(['backbone'],
code = '';
coll.each(function(m){
- var tag = m.get('tagName'), // Tag name
- attr = '', // Attributes string
- attrId = '',
- strCls = '',
- cln = m.get('components'), // Children
- attrs = m.get('attributes'),
- sTag = m.get('void'),
- classes = m.get('classes');
- _.each(attrs,function(value, prop){
- if(prop == 'onmousedown')
- return;
- attr += value && prop!='style' ? ' ' + prop + '="' + value + '"' : '';
- });
-
- if(m.get('type') == 'image'){
- tag = 'img';
- sTag = 1;
- attr += ' src="' + m.get('src') + '"';
- }
-
- if(!_.isEmpty(m.get('style')))
- attrId = ' id="' + m.cid + '" ';
-
- classes.each(function(m){
- strCls += ' ' + m.get('name');
- });
-
- strCls = strCls !== '' ? ' class="' + strCls.trim() + '"' : '';
- code += '<' + tag + strCls + attrId + attr + (sTag ? '/' : '') + '>' + m.get('content');
-
- if(cln.length)
- code += this.build(cln);
-
- if(!sTag)
- code += ''+tag+'>';
-
+ code += m.toHTML();
}, this);
return code;
diff --git a/src/dom_components/model/ComponentVideo.js b/src/dom_components/model/ComponentVideo.js
index c7b3cb9ed..43d79e8d5 100644
--- a/src/dom_components/model/ComponentVideo.js
+++ b/src/dom_components/model/ComponentVideo.js
@@ -6,11 +6,16 @@ define(['./ComponentImage'],
defaults: _.extend({}, Component.prototype.defaults, {
type: 'video',
tagName: 'video',
+ videoId: '',
+ void: 0,
provider: '', // on change of provider, traits are switched
+ ytUrl: 'http://www.youtube.com/embed/',
+ viUrl: 'http://player.vimeo.com/video/',
loop: 0,
muted: 0,
autoplay: 0,
controls: 1,
+ color: '',
sources: [],
}),
@@ -18,6 +23,47 @@ define(['./ComponentImage'],
this.set('traits', this.getSourceTraits());
Component.prototype.initialize.apply(this, arguments);
this.listenTo(this, 'change:provider', this.updateTraits);
+ this.listenTo(this, 'change:videoId', this.updateSrc);
+ },
+
+ /**
+ * Update src on change of video ID
+ * @private
+ */
+ updateSrc: function() {
+ var prov = this.get('provider');
+ switch (prov) {
+ case 'yt':
+ this.set('src',this.getYoutubeSrc());
+ break;
+ case 'vi':
+ this.set('src',this.getVimeoSrc());
+ break;
+ }
+ },
+
+ /**
+ * Returns attributes string in HTML
+ * @return {string}
+ * @private
+ */
+ toAttrHTML: function() {
+ var attr = Component.prototype.toAttrHTML.apply(this, arguments);
+ var prov = this.get('provider');
+
+ switch (prov) {
+ case 'yt': case 'vi':
+ break;
+ default:
+ if(this.get('loop'))
+ attr += ' loop';
+ if(this.get('autoplay'))
+ attr += ' autoplay';
+ if(this.get('controls'))
+ attr += ' controls';
+ }
+
+ return attr;
},
/**
@@ -29,11 +75,15 @@ define(['./ComponentImage'],
var traits = this.getSourceTraits();
switch (prov) {
case 'yt':
+ this.set('tagName', 'iframe');
traits = this.getYoutubeTraits();
break;
case 'vi':
+ this.set('tagName', 'iframe');
traits = this.getVimeoTraits();
break;
+ default:
+ this.set('tagName', 'video');
}
this.loadTraits(traits);
this.sm.trigger('change:selectedComponent');
@@ -73,24 +123,11 @@ define(['./ComponentImage'],
name: 'src',
placeholder: 'eg. ./media/video.mp4',
changeProp: 1,
- },{
- type: 'checkbox',
- label: 'Autoplay',
- name: 'autoplay',
- changeProp: 1,
- },{
- type: 'checkbox',
- label: 'Loop',
- name: 'loop',
- changeProp: 1,
- },{
- type: 'checkbox',
- label: 'Controls',
- name: 'controls',
- changeProp: 1,
- }];
+ },
+ this.getAutoplayTrait(),
+ this.getLoopTrait(),
+ this.getControlsTrait()];
},
-
/**
* Return traits for the source provider
* @return {Array