3 require('./utils/font-setup');
5 var appEvents
= require('./utils/appevents');
6 var onready
= require('./utils/onready');
7 var toggleClass
= require('./utils/toggle-class');
8 var ExploreView
= require('./views/explore/explore-view');
10 require('./utils/tracking');
12 require('@gitterhq/styleguide/css/components/buttons.css');
13 require('@gitterhq/styleguide/css/components/headings.css');
17 el
: '.explore-page-wrap'
19 //exploreView.render();
21 var tagPillElements
= document
.querySelectorAll('.js-explore-tag-pill');
22 var roomCardElements
= document
.querySelectorAll('.js-explore-room-card');
23 var showMoreElemnts
= document
.querySelectorAll('.js-explore-show-more-tag-pills');
24 var tagPillListElements
= document
.querySelectorAll('.js-explore-tag-pills-list');
26 Array
.prototype.forEach
.call(roomCardElements
, function(roomItemElement
) {
27 roomItemElement
.addEventListener('click', function() {
29 appEvents
.trigger('track-event', 'explore_room_click');
33 var activeClass
= 'is-active';
35 var updateRoomCardListVisibility = function() {
36 // Grab the active tags
38 Array
.prototype.filter
39 .call(tagPillElements
, function(tagPillElement
) {
40 return tagPillElement
.classList
.contains(activeClass
);
42 .forEach(function(tagPillElement
) {
43 (tagPillElement
.getAttribute('data-tags') || '').split(',').forEach(function(tag
) {
44 activeTags
[tag
] = true;
48 Array
.prototype.forEach
.call(roomCardElements
, function(roomItemElement
) {
49 (roomItemElement
.getAttribute('data-tags') || '').split(',').some(function(roomTag
) {
50 var hasActiveTag
= activeTags
[roomTag
];
51 toggleClass(roomItemElement
, 'is-hidden', !hasActiveTag
);
57 updateRoomCardListVisibility();
60 // Hook up our pills to update the card list
61 var toggleTagPillActive = function(el, state) {
62 toggleClass(el, activeClass, state);
63 el.setAttribute('aria-selected', state);
65 Array.prototype.forEach.call(tagPillElements, function(tagPillElement) {
66 tagPillElement.addEventListener('click', function() {
67 // Redirect to new page (we don't have a API to query client-side yet)
68 //window.location.href = tagPillElement.getAttribute('href');
70 // Only one tag can be selected at a time so
71 // unselect all of the tags
72 Array.prototype.forEach.call(tagPillElements, function(tagPillElement) {
73 toggleTagPillActive(tagPillElement, false);
75 // Select the tag we just clicked
76 toggleTagPillActive(tagPillElement, true);
78 updateRoomCardListVisibility();
81 appEvents.trigger('track-event', 'explore_pills_click', {
82 tag: tagPillElement.textContent.toLowerCase()
88 // Expand/Collapse tag pill list
89 Array
.prototype.forEach
.call(showMoreElemnts
, function(showMoreElement
) {
90 showMoreElement
.addEventListener('click', function() {
91 var state
= toggleClass(showMoreElement
, 'is-expanded');
93 Array
.prototype.forEach
.call(tagPillListElements
, function(pillListElement
) {
94 toggleClass(pillListElement
, 'is-expanded', state
);
95 pillListElement
.setAttribute('aria-selected', state
);