forked from gnab/remark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract slide number into component.
- Loading branch information
Showing
4 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = SlideNumberViewModel; | ||
|
||
function SlideNumberViewModel (slide, slideshow) { | ||
var self = this; | ||
|
||
self.slide = slide; | ||
self.slideshow = slideshow; | ||
|
||
self.element = document.createElement('div'); | ||
self.element.className = 'remark-slide-number'; | ||
self.element.innerHTML = formatSlideNumber(self.slide, self.slideshow); | ||
} | ||
|
||
function formatSlideNumber (slide, slideshow) { | ||
var format = slideshow.getSlideNumberFormat() | ||
, current = slide.number | ||
, total = slideshow.getSlides().length | ||
; | ||
|
||
if (typeof format === 'function') { | ||
return format(current, total); | ||
} | ||
|
||
return format | ||
.replace('%current%', current) | ||
.replace('%total%', total); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var SlideNumber = require('components/slide-number'); | ||
|
||
describe('Slide number', function () { | ||
var slideNumber; | ||
|
||
it('should display according to format', function () { | ||
var slide = { number: 2 } | ||
, slideshow = { | ||
getSlideNumberFormat: function () { | ||
return '%current% / %total%'; | ||
} | ||
, getSlides: function () { return [1,2,3]; } | ||
}; | ||
|
||
slideNumber = new SlideNumber(slide, slideshow); | ||
|
||
slideNumber.element.innerHTML.should.equal('2 / 3'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters