Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Merge pull request #232 from jmcarp/feature/glossary-improvements
Browse files Browse the repository at this point in the history
Feature/glossary improvements
  • Loading branch information
Noah Manger committed Jun 3, 2015
2 parents 4311d8e + 1e6030e commit ea3dcff
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"gulp-util": "^3.0.4",
"handlebars": "^2.0.0",
"jquery": "^2.1.4",
"list.js": "git://github.com/slifszyc/list.js.git",
"node-bourbon": "^4.2.2",
"node-neat": "^1.7.1-beta1",
"querystring": "^0.2.0",
Expand Down
32 changes: 29 additions & 3 deletions static/js/modules/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ var $ = require('jquery');

var events = require('./events.js');

var defaultOpts = {
closeAll: false
};

var accordion = {
SLT_HEADER: '.js-accordion_header',
SLT_ITEM: '.js-accordion_item',
Expand All @@ -19,11 +23,13 @@ var accordion = {
* Events
* accordion:active
* @param header {jQuery} The accordion header that is activated to be expanded.
* @param opts {Object} A hash of options to use.
*
* @param $base {jQuery} The container of the accordion.
*/
init: function($base) {
init: function($base, opts) {
var self = this;
this.options = $.extend({}, defaultOpts, opts);
this.$headers = this.findHeaders($base);
this.$items = this.findItems($base);
this.$buttons = this.findButtons(this.$headers);
Expand All @@ -34,15 +40,21 @@ var accordion = {

events.on(this.EV_EXPAND, function(props) {
var $header = $(props.header);
self.hideAll();
if (self.options.closeAll) {
self.hideAll();
}
if ($.inArray($header, self.$headers)) {
self.showHeader($header);
}
});
events.on(this.EV_COLLAPSE, function(props) {
var $header = $(props.header);
if ($.inArray($header, self.$headers)) {
self.hideAll();
if (self.options.closeAll) {
self.hideAll();
} else {
self.hideHeader($header);
}
}
});
},
Expand Down Expand Up @@ -106,6 +118,20 @@ var accordion = {
});
this.$headers.toggleClass(this.CLS_COLLAPSED, true);
},

/**
* Hide all items under the accordion header passed in.
* @param $header {jQuery} The header to hide items under.
*/
hideHeader: function($header) {
var $items = this.findItemsFromHeader($header),
self = this;
$items.each(function() {
self.hide($(this));
});
$header.toggleClass(this.CLS_COLLAPSED, true);
},

/**
* Show all items under the accordion header passed in.
* @param $header {jQuery} The header to show items under.
Expand Down
7 changes: 5 additions & 2 deletions static/js/modules/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ function chartSeries() {
.call(drawScale, scale, dim);

bars.each(function(d) {
d.size = scale(d.value);
// console.log(d.value, '->', d.height);
if (d.value < 0) {
d.size = 0;
} else {
d.size = scale(d.value);
}
})
.style(dim, function(d) {
return d.size + '%';
Expand Down
45 changes: 29 additions & 16 deletions static/js/modules/glossary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var $ = require('jquery');
var _ = require('underscore');
var terms = require('./terms');

require('../vendor/list.min.js');
var List = require('list.js');

var glossaryLink = $('.term'),
glossaryIsOpen = false,
Expand All @@ -19,35 +19,41 @@ var glossaryLink = $('.term'),

// Builds the List in the glossary slide panel
populateList = function(terms) {
var itemTemplate = '<li id="glossary-list-item">'
+ '<div class="js-accordion_header accordion__header">'
+ '<h4 class="glossary-term"></h4>'
+ '<a href="#" class="accordion__button js-accordion_button"></a>'
+ '</div>'
+ '<p class="glossary-definition js-accordion_item"></p>'
+ '</li>';
var itemTemplate = '<li id="glossary-list-item">' +
'<div class="js-accordion_header accordion__header">' +
'<h4 class="glossary-term"></h4>' +
'<a href="#" class="accordion__button js-accordion_button"></a>' +
'</div>' +
'<p class="glossary-definition js-accordion_item"></p>' +
'</li>';
var options = {
item: itemTemplate,
valueNames: ['glossary-term','glossary-definition'],
valueNames: ['glossary-term', 'glossary-definition'],
listClass: 'glossary__list',
searchClass: 'glossary__search',
searchClass: 'glossary__search'
};
glossaryList = new List('glossary',options,terms);
glossaryList = new List('glossary', options, terms);
glossaryList.sort('glossary-term', {order: 'asc'});
}
};

populateList(terms);

// Adding title to all terms
$('.term').attr('title', 'Click to define').attr('tabindex', 0);

findTerm = function(term){
glossaryList.search(term, ['glossary-term']);
$('.glossary__search').val(term);
// Highlight the term and remove other highlights
$('.term--highlight').removeClass('term--highlight');
$('span[data-term="' + term + '"]').addClass('term--highlight');
}
glossaryList.filter(function(item) {
return item._values['glossary-term'] === term;
});
// Hack: Expand text for selected item
_.each(glossaryList.visibleItems, function(item) {
$(item.elm).find('.accordion__button').click();
});
};

// Opens the glossary
showGlossary = function() {
Expand All @@ -56,7 +62,7 @@ showGlossary = function() {
$('#glossary-toggle').addClass('active');
$('#glossary-search').focus();
glossaryIsOpen = true;
}
};

// Hides the glossary
hideGlossary = function() {
Expand All @@ -66,7 +72,7 @@ hideGlossary = function() {
$('#glossary-toggle').removeClass('active');
glossaryIsOpen = false;
clearTerm();
}
};

clearTerm = function() {
$('#glossary-term').html('');
Expand All @@ -91,5 +97,12 @@ module.exports = {
showGlossary();
}
});

// Hack: Remove filters applied by clicking a term on new user input
$('#glossary-search').on('input', function() {
if (glossaryList.filtered) {
glossaryList.filter();
}
});
}
};
4 changes: 1 addition & 3 deletions static/js/modules/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ module.exports = {
window.location = window.location.origin + '/' + datasetName + '/' + datum.id;
});

$('.twitter-typeahead').css({
display: 'flex',
});
$('.twitter-typeahead').addClass('flex-container').css('display','');
},

init: function(){
Expand Down
1 change: 0 additions & 1 deletion static/js/vendor/list.min.js

This file was deleted.

6 changes: 6 additions & 0 deletions static/styles/_base/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ select {
&:focus {
outline: 3px solid $focus;
}

&::-ms-expand {
display: none;
}
}

select[multiple] {
Expand All @@ -123,6 +127,8 @@ select[multiple] {

.input-button-combo {
@include display(flex);
@include align-items(stretch);
@include flex-direction(row);
@include justify-content(center);
height: 4rem;

Expand Down
2 changes: 1 addition & 1 deletion static/styles/_components/_glossary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@

.glossary-term {
margin-bottom: 0;
}
}
2 changes: 1 addition & 1 deletion static/styles/_components/_search-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// Typeahead
.twitter-typeahead {
@include display(flex);
width: 100%;
width: 50%;
}

.tt-dropdown-menu {
Expand Down
4 changes: 4 additions & 0 deletions static/styles/_layout/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ body {
@include span-columns(6);
}

.flex-container {
@include display(flex);
}

// Chunks
// These are common grouping sizes, described by their desktop size

Expand Down
2 changes: 1 addition & 1 deletion templates/committees.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1><img width="32" height="32" class="category-icon" src="/static/img/icon-comm
{% if pagination %}
{% include 'partials/pagination.html' %}
{% endif %}
<button id="filter-toggle" data-slide="left">Filter Results</button>
<button id="filter-toggle" data-slide="left">Show Filters</button>
</div>

<section class="results-content">
Expand Down

0 comments on commit ea3dcff

Please sign in to comment.