Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #210 from ossreleasefeed/multi-tree
Browse files Browse the repository at this point in the history
Fix Bug 936492, implement tree selector for multi tree support
  • Loading branch information
Schalk Neethling committed Dec 18, 2013
2 parents 0fce332 + 60bc698 commit 43e9f86
Show file tree
Hide file tree
Showing 21 changed files with 535 additions and 100 deletions.
28 changes: 18 additions & 10 deletions dxr/static/css/dxr.css
Expand Up @@ -303,17 +303,16 @@ mark {
.path-separator {
margin: 0 .4rem;
}
.file-name {
.file-name,
.top-of-tree {
display: inline-block;
float: left;
margin: 0;
padding: 0;
padding: .5rem 0 1rem 0;
font-size: .9rem;
text-align: left;
}
/* top of tree */
.top-of-tree {
font-size: .8rem;
}
.top-of-tree a:link,
.top-of-tree a:visited,
.file-name a:link,
Expand All @@ -339,7 +338,8 @@ mark {
background: transparent url(/static/icons/folder.png) 0 4px no-repeat;
padding: .5em .5em .5em 1.7em;
}
.folder-content {
.folder-content,
.result {
clear: both;
}
.folder-content .icon {
Expand Down Expand Up @@ -544,13 +544,21 @@ a.c {
background-color: #e0e0e0;
text-decoration: underline;
}
/* user messages */
.user-message {
clear: both;
padding: .5rem;
border-bottom: 3px solid darkgreen;
}
.user-message.info {
background: -webkit-linear-gradient(rgb(129, 188, 46), rgb(101, 147, 36));
background: -moz-linear-gradient(rgb(129, 188, 46), rgb(101, 147, 36));
background: linear-gradient(rgb(129, 188, 46), rgb(101, 147, 36));
color: white;
}
#fetch-results {
display: none;
}
.tree-selector {
position: relative;
float: right;
}
/*http://developer.yahoo.com/blogs/ydn/posts/2012/10/clip-your-hidden-content-for-better-accessibility/*/
.visually-hidden {
position: absolute;
Expand Down
127 changes: 127 additions & 0 deletions dxr/static/css/tree-selector.css
@@ -0,0 +1,127 @@
@font-face {
font-family: 'icons';
src: url('/static/fonts/icons.eot?#iefix2013') format('embedded-opentype'),
url('/static/fonts/icons.woff?2013') format('woff'),
url('/static/fonts/icons.ttf?2013') format('truetype');
font-weight: normal;
font-style: normal;
}

.tree-selector {
display: inline-block;
position: relative;
float: right;
width: auto;
}
.select-options {
display: none;
position: absolute;
right: 0;
}
.ts-select-trigger {
background-color: #e0e0e0;
margin-bottom: .2rem;
padding: .3rem .3rem .5rem .3rem;
border: 1px solid #999;
width: auto;
min-width: 100px;
font-size: .8rem;
border-radius: .2rem;
cursor: pointer;
}
[data-icon]:before {
margin-right: .3rem;
font-family: icons;
font-size: 1.2rem;
content: attr(data-icon);
speak: none;
}
.selector-arrow {
display: inline-block;
position: relative;
padding-right: 1.5rem;
}
[data-icon-arrow]:before {
display: block;
position: absolute;
top: 6px;
right: 0;
font-family: icons;
content: attr(data-icon-arrow);
speak: none;
}
.selected:before {
position: absolute;
margin: 0 0 -15px -25px;
font-family: icons;
content: "\e803";
speak: none;
}
.ts-modal {
border: 1px solid #d4d4d4;
border-radius: 6px;
min-width: 120%;
}
header {
background-color: #e0e0e0;
padding: .6rem .8rem .6rem .8rem;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
font-size: 1rem;
font-weight: bold;
letter-spacing: .5px;
}
/* visibility of the filter field is configurable
and handled by JavaScript using the data-visible
attribute */
.options-filter {
display: none;
padding: .8rem;
}
.options-filter input[type="text"] {
padding: 5px 2%;
border: 1px solid #b2b2b2;
width: 100%;
font-size: .8rem;
border-radius: .2rem;
box-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.options-filter input[type="text"]:focus {
border: 1px solid #42a4e0;
box-shadow: 0 0 0 2px rgba(73, 173, 227, 0.4);
}
.ts-options {
margin: 0;
padding: 0;
font-size: .9rem;
list-style: none;
}
.ts-options a {
display: block;
background-color: white;
color: #000;
padding: .6rem .6rem .6rem 2rem;
text-decoration: none;
white-space: nowrap;
}
.ts-options a:hover {
background-color: #005CB8;
color: #fff;
}
.ts-options li {
border-top: 1px solid #e0e0e0;
}
.ts-options li:first-child {
border-top: none;
}
.ts-options li:last-child a {
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
}
.ts-options li:first-child a {
border-top-right-radius: 6px;
border-top-left-radius: 6px;
}
.ts-option-label {
font-weight: bold;
}
Binary file modified dxr/static/fonts/icons.eot
Binary file not shown.
3 changes: 3 additions & 0 deletions dxr/static/fonts/icons.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dxr/static/fonts/icons.ttf
Binary file not shown.
Binary file modified dxr/static/fonts/icons.woff
Binary file not shown.
30 changes: 20 additions & 10 deletions dxr/static/js/dxr.js
Expand Up @@ -13,7 +13,7 @@ $(function() {
dxr.tree = constants.data('tree');

/**
* Disable and enable event on scroll begin and scroll end.
* Disable and enable pointer events on scroll begin and scroll end.
* @see http://www.thecssninja.com/javascript/pointer-events-60fps
*/
var root = document.documentElement;
Expand Down Expand Up @@ -46,13 +46,13 @@ $(function() {

switch(type) {
case 'info':
messageContainer.setAttribute('class', 'message info');
messageContainer.setAttribute('class', 'user-message info');
break;
case 'warn':
messageContainer.setAttribute('class', 'message warn');
messageContainer.setAttribute('class', 'user-message warn');
break;
case 'error':
messageContainer.setAttribute('class', 'message error');
messageContainer.setAttribute('class', 'user-message error');
break;
default:
console.log('Unrecognized message type. See function documentation for supported types.');
Expand Down Expand Up @@ -187,13 +187,23 @@ $(function() {

displayedRequestNumber = myRequestNumber;

data['wwwroot'] = dxr.wwwroot;
data['tree'] = dxr.tree;
data['top_of_tree'] = dxr.wwwroot + '/' + data['tree'] + '/source/';
data['trees'] = data.trees;

var params = {
q: data.query,
case: data.is_case_sensitive
}
data['query_string'] = $.param(params);

// If no data is returned, inform the user.
if (!data.results.length) {
contentContainer.empty();
setUserMessage('info', contentContainer.data('no-results'), contentContainer);
data['user_message'] = contentContainer.data('no-results');
contentContainer.empty().append(tmpl.render(data));
} else {
data['tree'] = dxr.tree;
data['top_of_tree'] = dxr.wwwroot + '/' + data['tree'] + '/source/';

var results = data.results;

for (var result in results) {
Expand All @@ -219,7 +229,7 @@ $(function() {

// Do a search every time you pause typing for 300ms:
queryField.on('input', querySoon);

// Update the search when the case-sensitive box is toggled, canceling any pending query:
caseSensitiveBox.on('change', queryNow);

Expand All @@ -231,7 +241,7 @@ $(function() {
* return Either the original number or the number prefixed with 0
*/
function addLeadingZero(number) {
return (number < 9) || (number > 0) ? "0" + number : number;
return (number <= 9) || (number === 0) ? "0" + number : number;
}

/**
Expand Down
70 changes: 70 additions & 0 deletions dxr/static/js/tree-selector.js
@@ -0,0 +1,70 @@
$(function() {
var contentContainer = $('#content');
var options = $('.ts-options');

function setSelectedItem(selected) {
var items = options.find('a');

items.each(function() {
$(this).removeClass('selected')
.removeAttr('aria-checked');
});

selected.addClass('selected');
selected.attr('aria-checked', 'true');
}

function hideOptions() {
// Because the tree selector can be injected by a JS
// template, we need to use the selector directly here,
// as the element will not exist on DOM ready.
$('.ts-options').parents('.select-options').hide();
}

// Show/Hide the options
contentContainer.on('click', '.ts-select-trigger', function(event) {
event.stopPropagation();

var optionsFilter = $('.options-filter');
var optionsContainer = $('.tree-selector').find('.select-options');
var expanded = optionsContainer.attr('aria-expanded');

// Show or hide the filter field if active.
if (optionsFilter.data('active')) {
optionsFilter.toggle();
}

optionsContainer.toggle();

// Update ARIA expanded state
optionsContainer.attr('aria-expanded', expanded === 'false' ? 'true' : 'false');
// Move focus to options container if expanded
if (expanded === 'false') {
$('.ts-options', optionsContainer)[0].focus();
}
});

options.on('click', 'a', function(event) {
event.stopPropagation();
setSelectedItem($(this));
// Set the value of the relevant hidden type element to
// the selected value.
$('#ts-value').val($(this).text());
hideOptions();
});

window.addEventListener('click', function() {
hideOptions();
}, false);

window.addEventListener('keyup', function(event) {
// 'key' is the standard but has not been implemented in Gecko
// yet, see https://bugzilla.mozilla.org/show_bug.cgi?id=680830
// so, we check both.
var keyPressed = event.key || event.keyCode;
// esc key pressed.
if (keyPressed === 27 || keyPressed === 'Esc') {
hideOptions();
}
}, false);
});

0 comments on commit 43e9f86

Please sign in to comment.