Last active
December 30, 2015 20:19
-
-
Save anthonyshort/7879409 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Stream of dots from the integrations browser | |
*/ | |
var dots = new IntegrationStream({ | |
el: document.querySelector('.js-integration-stream') | |
}); | |
/** | |
* Create a stream | |
* | |
* @type {[type]} | |
*/ | |
var logos = new LogoStream(document.querySelector('.hiw-logos')); | |
/** | |
* Stream of actions from the browser | |
*/ | |
var actions = new ActionStream({ | |
el: document.querySelector('.js-action-stream') | |
}); | |
/** | |
* Touches on the browser | |
*/ | |
var touches = new TouchStream({ | |
el: document.querySelector('.js-touch-stream'), | |
interval: 3000, | |
positions: [ | |
[400,90], | |
[600,100], | |
[490,140] | |
] | |
}); | |
/** | |
* Pipe all the streams together | |
*/ | |
touches | |
.pipe(actions) | |
.pipe(dots) | |
.pipe(logos); | |
/** | |
* Starting touching... ooooooh yeah. | |
*/ | |
touches.resume(); |
This file contains hidden or 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
/** | |
* Create touches on an element | |
* | |
* @param {Element} el | |
* @param {Object} options | |
*/ | |
function Touches(options) { | |
if( !(this instanceof Touches) ) return new Touches(options); | |
this.positions = options.positions || []; | |
this.interval = options.interval || 5000; | |
this.attach(options.el); | |
} | |
/** | |
* So it can emit events | |
*/ | |
emitter(Touches.prototype); | |
/** | |
* Pipe this stream into another stream | |
* | |
* @param {Stream} stream | |
* @return {Stream} | |
*/ | |
Touches.prototype.pipe = function(stream) { | |
this.on('data', stream.write.bind(stream)); | |
return stream; | |
}; | |
/** | |
* Add a new touch on the interval | |
* | |
* @api private | |
* @return {void} | |
*/ | |
Touches.prototype.tick = function(){ | |
if(!this.el.parentNode) return this.detach(); | |
var position = this.position(); | |
var touch = new Touch(position); | |
this.el.appendChild(touch); | |
this.emit('data', touch); | |
}; |
This file contains hidden or 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
/** | |
* Create touches on an element | |
* | |
* @param {Object} options | |
*/ | |
function Stream(options) { | |
this.el = options.el; | |
} | |
/** | |
* So it can emit events | |
*/ | |
emitter(Stream.prototype); | |
/** | |
* Add a new touch on the interval | |
* | |
* @api private | |
* @return {void} | |
*/ | |
Stream.prototype.write = function(){ | |
var position = this.position(); | |
var el = new Item(position); | |
this.el.appendChild(el); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment