Skip to content

Commit

Permalink
Refactor controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnab committed May 19, 2014
1 parent 599d7a2 commit a17e9cf
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 296 deletions.
150 changes: 75 additions & 75 deletions src/remark/api.js
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 === '&lt;' ? '<' : '>';
});

source = source.replace(/&amp;/g, '&');
source = source.replace(/&quot;/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 === '&lt;' ? '<' : '>';
});

source = source.replace(/&amp;/g, '&');
source = source.replace(/&quot;/g, '"');

return source;
}
219 changes: 0 additions & 219 deletions src/remark/controller.js

This file was deleted.

Loading

0 comments on commit a17e9cf

Please sign in to comment.