Commit 7ccdeded by Filippo Valsorda

Add support for image items

parent 92d83062
...@@ -35,6 +35,14 @@ var dragAndDrop = (function() { ...@@ -35,6 +35,14 @@ var dragAndDrop = (function() {
'</li>' '</li>'
].join(''); ].join('');
}, },
image_item: function() {
return [
'<li class="option" data-value="<%= id %>"',
'style="width: <%= size.width %>; height: <%= size.height %>">',
'<img src="<%= backgroundImage %>" />',
'</li>'
].join('');
},
zoneInput: function() { zoneInput: function() {
return [ return [
'<div class="zone-row <%= name %>">', '<div class="zone-row <%= name %>">',
...@@ -81,6 +89,10 @@ var dragAndDrop = (function() { ...@@ -81,6 +89,10 @@ var dragAndDrop = (function() {
'</a>', '</a>',
'</div>', '</div>',
'<div class="row">', '<div class="row">',
'<label>Background image URL (alternative to the text)</label>',
'<textarea class="background-image"></textarea>',
'</div>',
'<div class="row">',
'<label>Success Feedback</label>', '<label>Success Feedback</label>',
'<textarea class="success-feedback"></textarea>', '<textarea class="success-feedback"></textarea>',
'</div>', '</div>',
...@@ -89,7 +101,7 @@ var dragAndDrop = (function() { ...@@ -89,7 +101,7 @@ var dragAndDrop = (function() {
'<textarea class="error-feedback"></textarea>', '<textarea class="error-feedback"></textarea>',
'</div>', '</div>',
'<div class="row">', '<div class="row">',
'<label>Width (px)</label>', '<label>Width (px - 0 for auto)</label>',
'<input type="text" class="item-width" value="190"></input>', '<input type="text" class="item-width" value="190"></input>',
'<label>Height (px - 0 for auto)</label>', '<label>Height (px - 0 for auto)</label>',
'<input type="text" class="item-height" value="0"></input>', '<input type="text" class="item-height" value="0"></input>',
...@@ -406,15 +418,19 @@ var dragAndDrop = (function() { ...@@ -406,15 +418,19 @@ var dragAndDrop = (function() {
$form.each( function(i, el) { $form.each( function(i, el) {
var $el = $(el), var $el = $(el),
name = $el.find('.item-text').val(); name = $el.find('.item-text').val(),
backgroundImage = $el.find('.background-image').val();
if (name.length > 0) { if (name.length > 0 || backgroundImage.length > 0) {
var width = $el.find('.item-width').val() + 'px', var width = $el.find('.item-width').val(),
height = $el.find('.item-height').val(); height = $el.find('.item-height').val();
if (height === '0') height = 'auto'; if (height === '0') height = 'auto';
else height = height + 'px'; else height = height + 'px';
if (width === '0') width = 'auto';
else width = width + 'px';
items.push({ items.push({
displayName: name, displayName: name,
zone: $el.find('.zone-select').val(), zone: $el.find('.zone-select').val(),
...@@ -426,7 +442,8 @@ var dragAndDrop = (function() { ...@@ -426,7 +442,8 @@ var dragAndDrop = (function() {
size: { size: {
width: width, width: width,
height: height height: height
} },
backgroundImage: backgroundImage
}); });
} }
}); });
...@@ -545,10 +562,15 @@ var dragAndDrop = (function() { ...@@ -545,10 +562,15 @@ var dragAndDrop = (function() {
draw: function() { draw: function() {
var list = [], var list = [],
items = _fn.data.items, items = _fn.data.items,
tpl = _fn.tpl.item(); tpl = _fn.tpl.item(),
img_tpl = _fn.tpl.image_item();
_.each(items, function(item) { _.each(items, function(item) {
list.push( _.template( tpl, item ) ); if (item.backgroundImage.length > 0) {
list.push( _.template( img_tpl, item ) );
} else {
list.push( _.template( tpl, item ) );
}
}); });
// Update DOM // Update DOM
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment