Created
June 27, 2017 15:43
-
-
Save lucprincen/105837804e91fb8c4cce8dc2b2f65950 to your computer and use it in GitHub Desktop.
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
const $ = require('jquery'); | |
class RadioTabs { | |
constructor($component) { | |
this.$component = $component; | |
this.attachEventHandlers(); | |
this.selectTabBasedOnRadioValue(); | |
} | |
/** | |
* Attach event handlers to component | |
* | |
* @return {void} | |
*/ | |
attachEventHandlers() { | |
this.$component.find('input[type="radio"]').on('change', () => this.selectTabBasedOnRadioValue()); | |
} | |
/** | |
* Select the correct source based on the radio value | |
* | |
* @return {void} | |
*/ | |
selectTabBasedOnRadioValue() { | |
let name = this.$component.find('input[type="radio"]:checked').val(); | |
this.selectSource(name); | |
} | |
/** | |
* Show the source for the given name and hide the rest | |
* | |
* @param {string} name | |
* @return {void} | |
*/ | |
selectSource(name) { | |
this.$component.find('[data-tab]').hide(); | |
this.$component.find(`[data-tab="${name}"]`).show(); | |
} | |
} | |
module.exports = RadioTabs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment