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.
- Loading branch information
Showing
9 changed files
with
339 additions
and
296 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 |
---|---|---|
@@ -1,75 +1,75 @@ | ||
var EventEmitter = require('events').EventEmitter | ||
, highlighter = require('./highlighter') | ||
, Slideshow = require('./models/slideshow') | ||
, SlideshowView = require('./views/slideshowView') | ||
, Controller = require('./controller') | ||
, Dom = require('./dom') | ||
; | ||
|
||
module.exports = Api; | ||
|
||
function Api (dom) { | ||
this.dom = dom || new Dom(); | ||
} | ||
|
||
// Expose highlighter to allow enumerating available styles and | ||
// including external language grammars | ||
Api.prototype.highlighter = highlighter; | ||
|
||
// Creates slideshow initialized from options | ||
Api.prototype.create = function (options) { | ||
var events | ||
, slideshow | ||
, slideshowView | ||
, controller | ||
; | ||
|
||
options = applyDefaults(this.dom, options); | ||
|
||
events = new EventEmitter(); | ||
events.setMaxListeners(0); | ||
|
||
slideshow = new Slideshow(events, options); | ||
slideshowView = new SlideshowView(events, this.dom, options.container, slideshow); | ||
controller = options.controller || new Controller(events, this.dom, slideshowView, options.navigation); | ||
|
||
return slideshow; | ||
}; | ||
|
||
function applyDefaults (dom, options) { | ||
var sourceElement; | ||
|
||
options = options || {}; | ||
|
||
if (options.hasOwnProperty('sourceUrl')) { | ||
var req = new dom.XMLHttpRequest(); | ||
req.open('GET', options.sourceUrl, false); | ||
req.send(); | ||
options.source = req.responseText.replace(/\r\n/g, '\n'); | ||
} | ||
else if (!options.hasOwnProperty('source')) { | ||
sourceElement = dom.getElementById('source'); | ||
if (sourceElement) { | ||
options.source = unescape(sourceElement.innerHTML); | ||
sourceElement.style.display = 'none'; | ||
} | ||
} | ||
|
||
if (!(options.container instanceof window.HTMLElement)) { | ||
options.container = dom.getBodyElement(); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
function unescape (source) { | ||
source = source.replace(/&[l|g]t;/g, | ||
function (match) { | ||
return match === '<' ? '<' : '>'; | ||
}); | ||
|
||
source = source.replace(/&/g, '&'); | ||
source = source.replace(/"/g, '"'); | ||
|
||
return source; | ||
} | ||
var EventEmitter = require('events').EventEmitter | ||
, highlighter = require('./highlighter') | ||
, Slideshow = require('./models/slideshow') | ||
, SlideshowView = require('./views/slideshowView') | ||
, DefaultController = require('./controllers/defaultController') | ||
, Dom = require('./dom') | ||
; | ||
|
||
module.exports = Api; | ||
|
||
function Api (dom) { | ||
this.dom = dom || new Dom(); | ||
} | ||
|
||
// Expose highlighter to allow enumerating available styles and | ||
// including external language grammars | ||
Api.prototype.highlighter = highlighter; | ||
|
||
// Creates slideshow initialized from options | ||
Api.prototype.create = function (options) { | ||
var events | ||
, slideshow | ||
, slideshowView | ||
, controller | ||
; | ||
|
||
options = applyDefaults(this.dom, options); | ||
|
||
events = new EventEmitter(); | ||
events.setMaxListeners(0); | ||
|
||
slideshow = new Slideshow(events, options); | ||
slideshowView = new SlideshowView(events, this.dom, options.container, slideshow); | ||
controller = options.controller || new DefaultController(events, this.dom, slideshowView, options.navigation); | ||
|
||
return slideshow; | ||
}; | ||
|
||
function applyDefaults (dom, options) { | ||
var sourceElement; | ||
|
||
options = options || {}; | ||
|
||
if (options.hasOwnProperty('sourceUrl')) { | ||
var req = new dom.XMLHttpRequest(); | ||
req.open('GET', options.sourceUrl, false); | ||
req.send(); | ||
options.source = req.responseText.replace(/\r\n/g, '\n'); | ||
} | ||
else if (!options.hasOwnProperty('source')) { | ||
sourceElement = dom.getElementById('source'); | ||
if (sourceElement) { | ||
options.source = unescape(sourceElement.innerHTML); | ||
sourceElement.style.display = 'none'; | ||
} | ||
} | ||
|
||
if (!(options.container instanceof window.HTMLElement)) { | ||
options.container = dom.getBodyElement(); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
function unescape (source) { | ||
source = source.replace(/&[l|g]t;/g, | ||
function (match) { | ||
return match === '<' ? '<' : '>'; | ||
}); | ||
|
||
source = source.replace(/&/g, '&'); | ||
source = source.replace(/"/g, '"'); | ||
|
||
return source; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.