Commit 71b14409 authored by Thibaut Frain's avatar Thibaut Frain

Adding basic image support

parent 3b2e3f40
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
"interface" : "http://www.renderjs.org/interface/editor" "interface" : "http://www.renderjs.org/interface/editor"
}, },
editor_5_dict = { editor_5_dict = {
"path" : "./presentation-editor.html", "path" : "./presentation-editor/index.html",
"title" : "Presentation Editor Gadget", "title" : "Presentation Editor Gadget",
"interface" : "http://www.renderjs.org/interface/editor" "interface" : "http://www.renderjs.org/interface/editor"
}, },
......
/* #slide-list { */
/* margin: 1%; */
/* } */
.block { .block {
display: inline-block; display: inline-block;
float: left; float: left;
...@@ -17,7 +13,7 @@ ...@@ -17,7 +13,7 @@
} }
.block.slide-thumb { .block.slide-thumb {
background-color: #F5F5F6; background-color: white;
box-shadow: 2px 2px 2px 3px #ccc; box-shadow: 2px 2px 2px 3px #ccc;
border: 2px solid grey; border: 2px solid grey;
} }
...@@ -68,9 +64,7 @@ ...@@ -68,9 +64,7 @@
.ui-panel-page-content-open.ui-panel-page-content-position-left.ui-panel-page-content-display-push { .ui-panel-page-content-open.ui-panel-page-content-position-left.ui-panel-page-content-display-push {
padding-right: 35vw; padding-right: 35vw;
} }
/* .ui-panel-page-content-open.ui-panel-page-content-position-right.ui-panel-page-content-display-push { */
/* margin-left: 100px; */
/* } */
.ui-panel-page-content-open.ui-panel-page-content-display-push { .ui-panel-page-content-open.ui-panel-page-content-display-push {
width: auto; width: auto;
} }
...@@ -88,15 +82,16 @@ ...@@ -88,15 +82,16 @@
left: 100%; left: 100%;
} }
/* .ui-panel-animate.ui-panel-position-left.ui-panel-display-overlay, .ui-panel-animate.ui-panel-position-left.ui-panel-display-push { */
/* -webkit-transform: translate3d(100%,0,0); */
/* -moz-transform: translate3d(100%,0,0); */
/* transform: translate3d(100%,0,0); */
/* } */
.ui-panel-animate.ui-panel-page-content-position-left { .ui-panel-animate.ui-panel-page-content-position-left {
-webkit-transform: translate3d(100%,0,0); -webkit-transform: translate3d(100%,0,0);
-moz-transform: translate3d(100%,0,0); -moz-transform: translate3d(100%,0,0);
transform: translate3d(100%,0,0); transform: translate3d(100%,0,0);
} }
} }
#image-preview {
position: relative;
float: right;
width: 24%;
margin: 3%
}
\ No newline at end of file
...@@ -31,28 +31,58 @@ ...@@ -31,28 +31,58 @@
<div data-role="page"> <div data-role="page">
<div id="form-panel" data-role="panel" data-display="push" data-position-fixed="true"> <div id="form-panel" data-role="panel" data-display="push">
<div class="panel-content"> <div class="panel-content page">
<form id="slide-form"> <form id="slide-form">
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<label for="title" >Title:</label> <label for="title" ><strong>Title</strong></label>
<input type="text" name="title" id="title" value="" /> <input type="text" name="title" id="title" placeholder="Type here the slide title" data-clear-btn="true" required/>
</div> </div>
<br/>
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<select name="Type" id="type" data-inline="true"> <label for="type"><strong>Type</strong></label>
<option value="chapter">chapter</option> <fieldset data-role="controlgroup" data-mini="true" id="type">
<option value="illustration">illustration</option> <input type="radio" name="type" id="basic-type" value="" checked="checked" />
</select> <label for="basic-type">basic</label>
<input type="radio" name="type" id="chapter-type" value="chapter" />
<label for="chapter-type">chapter</label>
<input type="radio" name="type" id="screenshot-type" value="screenshot" />
<label for="screenshot-type">screenshot</label>
<input type="radio" name="type" id="illustration-type" value="illustration" />
<label for="illustration-type">illustration</label>
<input type="radio" name="type" id="code-type" value="code" />
<label for="code-type">code</label>
<input type="radio" name="type" id="master-type" value="master" />
<label for="master-type">master</label>
</fieldset>
</div>
<br/>
<div data-role="fieldcontain" id="image-field">
<label for="image"><strong>Image</strong></label>
<input type="file" name="image" id="image-input" class="ui-btn" />
<img id="image-preview" class="ui-shadow ui-corner-all">
</div> </div>
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<label for="content">Content:</label> <label for="content"><strong>Slide text</strong></label>
<textarea name="content" id="content"></textarea> <textarea name="content" id="content" placeholder="This text will appear in the slide"></textarea>
</div> </div>
<input data-inline="true" type="submit" id="submit" value="Add slide"> <div data-role="fieldcontain">
<input data-inline="true" type="button" id="cancel" value="Cancel" data-theme="b"> <label for="details"><strong>Slide details</strong></label>
<textarea name="details" id="details" placeholder="This text will be hidden"></textarea>
</div>
<br/>
<div id="slide-form-buttons" class="ui-grid-a">
<div class="ui-block-a"><input type="button" id="cancel" value="Cancel" data-theme="b"></div>
<div class="ui-block-b"><input type="submit" id="submit" value="Add slide" class="ui-block-b"></div>
</div>
</form> </form>
</div> </div>
</div> </div>
...@@ -80,6 +110,7 @@ ...@@ -80,6 +110,7 @@
<div class="dummy"></div> <div class="dummy"></div>
<div class="slide"> <div class="slide">
<h1></h1> <h1></h1>
<img>
<div class="content"></div> <div class="content"></div>
</div> </div>
</section> </section>
......
/*globals window, document, $, html_beautify */ /*globals window, document, $, html_beautify, FileReader */
/*jslint unparam: true */ /*jslint unparam: true */
$(function () { $(function () {
"use strict"; "use strict";
...@@ -10,6 +10,7 @@ $(function () { ...@@ -10,6 +10,7 @@ $(function () {
formPanel.panel({ beforeclose: function () { formPanel.panel({ beforeclose: function () {
newSlideButton.show(); newSlideButton.show();
slideForm.reset();
}}); }});
function openForm() { function openForm() {
...@@ -36,11 +37,11 @@ $(function () { ...@@ -36,11 +37,11 @@ $(function () {
} else { } else {
this.update(params); this.update(params);
} }
$(this.htmlEditButton()).click(function () { $(this.editBtn()).click(function () {
slideForm.bindToEdit(that); slideForm.bindToEdit(that);
openForm(); openForm();
}); });
$(this.htmlDeleteButton()).click(function () { $(this.deleteBtn()).click(function () {
presentation.deleteSlide(that); presentation.deleteSlide(that);
}); });
} }
...@@ -50,21 +51,11 @@ $(function () { ...@@ -50,21 +51,11 @@ $(function () {
dataTemplate: document.querySelector('template#slide-data').content.firstElementChild, dataTemplate: document.querySelector('template#slide-data').content.firstElementChild,
htmlTemplate: document.querySelector('template#slide-html').content.firstElementChild, htmlTemplate: document.querySelector('template#slide-html').content.firstElementChild,
htmlEditButton: function () { editBtn: function () {return this.html.querySelector("button.edit");},
return this.html.querySelector("button.edit"); deleteBtn: function () {return this.html.querySelector("button.delete");},
}, htmlContent: function () {return this.html.querySelector(".content");},
htmlImage: function () {return this.html.querySelector("img");},
htmlDeleteButton: function () { htmlTitle: function () {return this.html.querySelector("h1");},
return this.html.querySelector("button.delete");
},
htmlContent: function () {
return this.html.querySelector(".content");
},
htmlTitle: function () {
return this.html.querySelector("h1");
},
data: function () { data: function () {
var res = document.importNode(this.dataTemplate, true); var res = document.importNode(this.dataTemplate, true);
...@@ -75,40 +66,134 @@ $(function () { ...@@ -75,40 +66,134 @@ $(function () {
}, },
update: function (params) { update: function (params) {
console.log(params);
$.extend(this, params); $.extend(this, params);
this.htmlTitle().textContent = this.title; this.htmlTitle().textContent = this.title;
this.htmlContent().innerHTML = this.content; this.htmlContent().innerHTML = this.content;
if (this.type === "screenshot" || this.type === "illustration") {
this.htmlImage().src = this.image;
}else{
this.htmlImage().src= "";
}
} }
}; };
function SlideForm() { function SlideForm() {
var that = this;
this.elt = document.querySelector("#slide-form"); this.elt = document.querySelector("#slide-form");
this.bindToAdd(); this.bindToAdd();
$(this.elt).find("#cancel").click(closeForm);
$(this.elt).find('input[type="radio"]').click(function () {
that.updateFieldVisibility();
});
$(this.elt).find('#image-input').change(function (evt) {
var file = evt.target.files[0];
console.log(file);
if (file) {
var reader = new FileReader();
reader.onload = function (e) {
console.log(e.target);
that.attrImageFile(e.target.result);
};
reader.readAsDataURL(file);
}
});
} }
SlideForm.prototype = { SlideForm.prototype = {
attrTextInput: function (inputElt, content) {
if (content !== undefined) {
inputElt.value = content;
}else{
return inputElt.value;
}
},
attrTitle: function(content) {
return this.attrTextInput(this.elt.querySelector('#title'), content);
},
attrContent: function(content) {
return this.attrTextInput(this.elt.querySelector('#content'), content);
},
attrDetails: function(content) {
return this.attrTextInput(this.elt.querySelector('#details'), content);
},
attrType: function(type) {
var radios = $(this.elt).find('input[type="radio"]');
if (type !== undefined) {
radios.prop('checked', false);
if (type === "") {type = "basic";}
radios.filter("#"+type+"-type").prop('checked', true);
radios.checkboxradio('refresh');
this.updateFieldVisibility();
}else{
return radios.filter(':checked').val();
}
},
attrImageFile: function (imageFile) {
var input = this.elt.querySelector('#image-input');
var preview = this.elt.querySelector('#image-preview');
if (imageFile !== undefined) {
input.value = "";
preview.src = imageFile;
}else{
return preview.src;
}
},
attrAll: function (slide) {
if (slide !== undefined) {
this.attrTitle(slide.title);
this.attrType(slide.type);
this.attrContent(slide.content);
this.attrDetails(slide.details);
this.attrImageFile(slide.image);
}else{
return {
title: this.attrTitle(),
type: this.attrType(),
content: this.attrContent(),
details: this.attrDetails(),
image: this.attrImageFile()
};
}
},
updateFieldVisibility: function () {
var type = this.attrType();
if (type === "screenshot" || type === "illustration") {
$(this.elt).find('#image-field').show("blind", {direction: "up"});
}else{
$(this.elt).find('#image-field').hide("blind", {direction: "up"});
}
},
setSubmitLabel: function (label) {
var submit = $(this.elt).find("#submit");
submit.prop("value", label).button('refresh');
},
reset: function () { reset: function () {
this.elt.querySelector('#title').value = ""; this.attrAll({title: "", type: "basic", content: "", details: "", image: ""});
this.elt.querySelector('#type').value = "";
this.elt.querySelector('#content').value = "";
}, },
bindToEdit: function (slide) { bindToEdit: function (slide) {
var that = this; var that = this;
that.currentSlide = slide;
$(this.elt).off(); $(this.elt).off();
this.elt.querySelector('#title').value = slide.title; this.attrAll(slide);
this.elt.querySelector('#type').value = slide.type;
this.elt.querySelector('#content').value = slide.content;
$(this.elt).submit(function (e) { $(this.elt).submit(function (e) {
slide.update({ slide.update(that.attrAll());
title: that.elt.querySelector('#title').value,
type: that.elt.querySelector('#type').value,
content: that.elt.querySelector('#content').value
});
e.preventDefault(); e.preventDefault();
that.currentSlide = null;
slideForm.bindToAdd(); slideForm.bindToAdd();
}); });
this.setSubmitLabel("Save");
}, },
bindToAdd: function () { bindToAdd: function () {
...@@ -116,15 +201,11 @@ $(function () { ...@@ -116,15 +201,11 @@ $(function () {
$(this.elt).off(); $(this.elt).off();
this.reset(); this.reset();
$(this.elt).submit(function (e) { $(this.elt).submit(function (e) {
presentation.addSlide(new Slide({ presentation.addSlide(new Slide(that.attrAll()));
title: that.elt.querySelector('#title').value, that.reset();
type: that.elt.querySelector('#type').value,
content: that.elt.querySelector('#content').value
}));
this.reset();
e.preventDefault(); e.preventDefault();
}); });
$(this.elt).find("#cancel").click(closeForm); this.setSubmitLabel("Add");
} }
}; };
...@@ -149,6 +230,9 @@ $(function () { ...@@ -149,6 +230,9 @@ $(function () {
}, },
deleteSlide: function (slide) { deleteSlide: function (slide) {
if (slideForm.currentSlide === slide) {
slideForm.bindToAdd();
}
var index = this.slides.indexOf(slide); var index = this.slides.indexOf(slide);
this.slides.splice(index, 1); this.slides.splice(index, 1);
slide.html.remove(); slide.html.remove();
......
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