Skip to content

Commit

Permalink
#25: Add ready event.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnab committed Sep 17, 2012
1 parent 1abc592 commit 073d1d1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/remark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dom.on('load', function () {

styleDocument();
setupSlideshow(sourceElement, slideshowElement);

api.emit('ready');
});

function assureElementsExist (sourceElement, slideshowElement) {
Expand Down
34 changes: 28 additions & 6 deletions src/remark/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ proxyEvent(dom.document, 'mousewheel');
dom.on('load', updateDimensions);
dom.on('resize', updateDimensions);

function proxyObject (object) {
if (typeof this[object] !== 'undefined') {
object = this[object];
function proxyObject (objectName) {
var object;

if (typeof this[objectName] !== 'undefined') {
object = this[objectName];
}
else {
object = new EventEmitter();
object.addEventListener = object.on;

if (objectName === 'window') {
object.location = {};
}
}

return object;
Expand All @@ -41,17 +47,33 @@ function proxyFunction (element, func) {
dom[func] = function () { return element[func].apply(element, arguments); };
}
else {
if (func === 'createElement') {
if (['createElement', 'getElementById'].indexOf(func) !== -1) {
dom[func] = function () {
return {
style: {}
, appendChild: function () { }
, getElementsByTagName: function () { return []; }
, getElementsByTagName: function () {
return [{
parentNode: {
nodeName: ''
}
, childNodes: []
, className: ''
}];
}
, innerHTML: ''
};
};
}
else if (func === 'getElementsByTagName') {
dom[func] = function () {
return [{
insertBefore: function () {}
}];
};
}
else {
dom[func] = function () { return {}; };
dom[func] = function () { return {}; };
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/remark/api_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var api = require('../../src/remark/api')
, dom = require('../../src/remark/dom')
;

describe('API', function () {
describe('when loading remark', function () {
before(function () {
var remark = require('../../src/remark.js');
});

it('should be exposed', function () {
dom.exports.should.have.property('remark', api);
});

it('should trigger ready event', function (done) {
api.on('ready', function () {
done();
});

dom.emit('load');
});
});
});

0 comments on commit 073d1d1

Please sign in to comment.