Skip to content

Commit

Permalink
Create notes mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnab committed Jun 25, 2013
1 parent 8d161c6 commit 41925c4
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 108 deletions.
281 changes: 179 additions & 102 deletions remark.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions remark.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/remark.less
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,17 @@
position: absolute;
right: 20px;
}

.remark-notes {
background: #e7e8e2;
overflow: hidden;
position: absolute;
display: none;
-webkit-transform-origin: top left;
-moz-transform-origin: top left;
transform-origin: top-left;
}
.remark-notes-content {
display: table-cell;
padding: 1em 4em 1em 4em;
}
3 changes: 3 additions & 0 deletions src/remark/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function addKeyboardEventListeners (events) {
case 'k':
events.emit('gotoPreviousSlide');
break;
case 'n':
events.emit('toggleNotes');
break;
case '?':
events.emit('toggleHelp');
break;
Expand Down
3 changes: 2 additions & 1 deletion src/remark/models/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function Slide (slideNo, slide, template) {
var self = this;

self.properties = slide.properties || {};
self.source = slide.source;
self.source = slide.source || '';
self.notes = slide.notes || '';

self.getSlideNo = function () { return slideNo; };

Expand Down
2 changes: 1 addition & 1 deletion src/remark/resources.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/remark/views/slideView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function SlideView (events, slideshow, slide) {

this.element = createSlideElement();
this.contentElement = createContentElement(events, slideshow, slide.source, slide.properties);
this.notesMarkup = createNotesMarkup(slideshow, slide.notes);

this.element.appendChild(this.contentElement);
}
Expand Down Expand Up @@ -91,6 +92,18 @@ function styleContentElement (slideshow, element, properties) {
setBackgroundFromProperties(element, properties);
}

function createNotesMarkup (slideshow, notes) {
var element = document.createElement('div');
element.className = 'remark-notes-content';

element.innerHTML = converter.convertMarkdown(notes);
element.innerHTML = element.innerHTML.replace(/<p>\s*<\/p>/g, '');

highlightCodeBlocks(element, slideshow);

return element.outerHTML;
}

function setBackgroundFromProperties (element, properties) {
var backgroundImage = properties['background-image'];

Expand Down
61 changes: 59 additions & 2 deletions src/remark/views/slideshowView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function SlideshowView (events, containerElement, slideshow) {
self.dimensions = {};

self.configureContainerElement(containerElement);
self.configureNotesElement();
self.configureSlideshowElement();
self.configurePositionElement();
self.configureOverlayView();
Expand All @@ -34,6 +35,17 @@ function SlideshowView (events, containerElement, slideshow) {
events.on('showSlide', function (slideIndex) {
self.showSlide(slideIndex);
});

events.on('toggleNotes', function () {
self.notesVisible = !!!self.notesVisible;
if (self.notesVisible) {
self.notesElement.style.display = 'table';
}
else {
self.notesElement.style.display = 'none';
}
self.updateDimensions();
});
}

SlideshowView.prototype.isEmbedded = function () {
Expand Down Expand Up @@ -128,6 +140,14 @@ SlideshowView.prototype.configureOverlayView = function () {
self.element.appendChild(self.overlayView.element);
};

SlideshowView.prototype.configureNotesElement = function () {
var self = this;

self.notesElement = document.createElement('div');
self.notesElement.className = 'remark-notes';
self.containerElement.appendChild(self.notesElement);
};

SlideshowView.prototype.updateSlideViews = function () {
var self = this;

Expand Down Expand Up @@ -170,6 +190,7 @@ SlideshowView.prototype.showSlide = function (slideIndex) {
slideView.show();
self.positionElement.innerHTML =
slideIndex + 1 + ' / ' + self.slideViews.length;
self.notesElement.innerHTML = slideView.notesMarkup;
};

SlideshowView.prototype.hideSlide = function (slideIndex) {
Expand All @@ -193,6 +214,11 @@ SlideshowView.prototype.updateDimensions = function () {
this.element.style.width = this.dimensions.width + 'px';
this.element.style.height = this.dimensions.height + 'px';

if (this.notesVisible) {
this.notesElement.style.width = this.element.style.width;
this.notesElement.style.height = this.element.style.height;
}

this.scaleSlideBackgroundImages();
this.scaleToFitContainer();
};
Expand All @@ -206,8 +232,22 @@ SlideshowView.prototype.scaleToFitContainer = function () {
, scaledHeight
, ratio = this.ratio
, dimensions = this.dimensions
, direction
, left
, top
;

if (self.notesVisible) {
if (containerWidth / ratio.width > containerHeight / ratio.height) {
containerWidth /= 2;
direction = 'horizontal';
}
else {
containerHeight /= 2;
direction = 'vertical';
}
}

if (containerWidth / ratio.width > containerHeight / ratio.height) {
scale = containerHeight / dimensions.height;
}
Expand All @@ -218,10 +258,27 @@ SlideshowView.prototype.scaleToFitContainer = function () {
scaledWidth = dimensions.width * scale;
scaledHeight = dimensions.height * scale;

left = (containerWidth - scaledWidth) / 2;
top = (containerHeight - scaledHeight) / 2;

this.element.style['-webkit-transform'] = 'scale(' + scale + ')';
this.element.style.MozTransform = 'scale(' + scale + ')';
this.element.style.left = (containerWidth - scaledWidth) / 2 + 'px';
this.element.style.top = (containerHeight - scaledHeight) / 2 + 'px';
this.element.style.left = left + 'px';
this.element.style.top = top + 'px';

if (self.notesVisible) {
this.notesElement.style['-webkit-transform'] = 'scale(' + scale + ')';
this.notesElement.style.MozTransform = 'scale(' + scale + ')';

if (direction === 'horizontal') {
this.notesElement.style.left = left * 3 + scaledWidth + 'px';
this.notesElement.style.top = top + 'px';
}
else {
this.notesElement.style.left = left + 'px';
this.notesElement.style.top = top * 3 + scaledHeight + 'px';
}
}
};

SlideshowView.prototype.getContainerHeight = function () {
Expand Down

0 comments on commit 41925c4

Please sign in to comment.