Last active
August 29, 2015 14:05
-
-
Save danielmahal/d38d5b8303bf6ef1d541 to your computer and use it in GitHub Desktop.
Simpler components
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
var header = require('./header') | |
var TabBar = require('./TabBar') | |
var $page = $('[data-component=explore-page]') | |
var start = new TabBar($page.find('.tv-channels [data-comonent=tab-bar]')) | |
var premium = new TabBar($page.find('.premium [data-comonent=tab-bar]')) | |
start.on('changeTab', function() { | |
console.log('start changed tabs') | |
}) | |
$(window).on('scroll', function() { | |
header.changeColor('red') | |
}) |
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
var $container = $('[data-component=header]') | |
module.exports = { | |
changeColor: function(color) { | |
$container.css('background', color) | |
} | |
} |
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
var EventEmitter = require('events').EventEmitter | |
var TabBar = function(el, data) { | |
$(el).on('click', 'a', function() { | |
this.changeTab($(this).index()) | |
}.bind(this)) | |
} | |
inherits(TabBar, EventEmitter) | |
TabBar.prototype.changeTab = function(i) { | |
this.emit('changeTab', i) | |
} | |
module.exports = TabBar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment