Skip to content

Commit

Permalink
Fixing a couple of the visibility bugs and updating the global search…
Browse files Browse the repository at this point in the history
… to search both private/public classes and modules so the sidebar only needs to deal with public
  • Loading branch information
kevinlacotaco committed Mar 4, 2013
1 parent e7ec1fd commit ca511cf
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 13 deletions.
61 changes: 57 additions & 4 deletions assets/js/yuidoc-bootstrap.js
Expand Up @@ -19,6 +19,7 @@ $(function() {

function setUpWidgets() {
var sideSource = [], navbarSource = [], sidebarSearch, navbarSearch;

$('#sidebar .tab-pane.active li a').each(function(index, elem) {
sideSource.push($(elem).text());
});
Expand All @@ -36,25 +37,77 @@ $(function() {
sidebarSearch.data('typeahead').source = sideSource;

navbarSearch = $('.navbar input');

navbarSearch.typeahead({
source : navbarSearch.data('obj'),
matcher : function(item) {
var regex = new RegExp(this.query, 'ig');

return regex.test(item.split('/')[1]);
},
updater : function(item) {
$('#sidebar .tab-pane a:contains(' + item + ')')[0].click();
return item;
window.location.assign(location.protocol + "//" + location.host + '/' + item + '.html');
}
});
navbarSearch.data('typeahead').source = navbarSource;
}

function bindEventsForPage() {
$('#main-nav li').on('click', function(event) {
console.log('Store the tab in local storage');
localStorage['main-nav'] = $(this).find('a').attr('href');
event.preventDefault();
});
$('#main-nav li').on('shown', function(event) {
setUpWidgets();
event.preventDefault();
});

$('#api-show-protected').on('change', function() {
if($(this).is(':checked')) {
$('.protected').toggle($(this).is(true));
$('.inherited').toggle($('#api-show-inherited').is(':checked'));
$('.deprecated').toggle($('#api-show-deprecated').is(':checked'));
} else {
$('.protected').toggle(false);
}
});

$('#api-show-private').on('change', function() {
if($(this).is(':checked')) {
$('.private').toggle(true);
$('.inherited').toggle($('#api-show-inherited').is(':checked'));
$('.deprecated').toggle($('#api-show-deprecated').is(':checked'));
} else {
$('.private').toggle(false);
}
});

$('#api-show-deprecated').on('change', function() {
if($(this).is(':checked')) {
$('.deprecated').toggle(true);
$('.inherited').toggle($('#api-show-inherited').is(':checked'));
} else {
$('.deprecated').toggle(false);
}
});

$('#api-show-inherited').on('change', function() {
if($(this).is(':checked')) {
$('.inherited').toggle(true);
$('.deprecated').toggle($('#api-show-deprecated').is(':checked'));
$('.private').toggle($('#api-show-private').is(':checked'));
$('.protected').toggle($('#api-show-protected').is(':checked'));
} else {
$('.inherited').toggle(false);
}
});

$('[data-tabid]').on('click', function(event) {
var tabToActivate = $(this).attr('data-tabid'),
anchor = $(this).attr('data-anchor');
event.preventDefault();
$('[data-toggle=tab][href="'+ tabToActivate + '"]').click();
$(document).scrollTop( $(anchor).offset().top );
});
}


Expand Down
40 changes: 40 additions & 0 deletions helpers/helpers.js
@@ -0,0 +1,40 @@
module.exports = {
publicClasses: function(context, options) {
'use strict';
var ret = "";

for(var i=0; i < context.length; i++) {
if(!context[i].itemtype && context[i].access === 'public') {
ret = ret + options.fn(context[i]);
} else if (context[i].itemtype) {
ret = ret + options.fn(context[i]);
}
}

return ret;
},
search : function(classes, modules) {
'use strict';
var ret = '';

for(var i=0; i < classes.length; i++) {
if(i > 0) {
ret += ', ';
}
ret += "\"" + 'classes/' + classes[i].displayName + "\"";
}

if(ret.length > 0 && modules.length > 0) {
ret += ', ';
}

for(var j=0; j < modules.length; j++) {
if(j > 0) {
ret += ', ';
}
ret += "\"" + 'modules/' + modules[j].displayName + "\"";
}

return ret;
}
};
6 changes: 3 additions & 3 deletions layouts/main.handlebars
Expand Up @@ -14,7 +14,7 @@
<body class="yui3-skin-sam" style="padding-top:40px;">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<a class="brand" href="/" style="height:20px;">
<a class="brand" href="/" style="padding: 10px 16px 10px; height: 20px; line-height: 20px; margin-left: 0;">
{{#if projectLogo}}
<img src="{{projectLogo}}" style="height:20px;" title="{{projectName}}">
{{else}}
Expand All @@ -29,8 +29,8 @@
</p>
</li>
</div>
<form class="navbar-form pull-right">
<input type="text" class="search-query" placeholder="Search for classes/modules...">
<form class="navbar-form pull-right" style="line-height: 40px; height: 40px;">
<input style="margin-top: 0;" type="text" class="search-query" placeholder="Search for classes/modules..." data-obj='[{{#search classes allModules}}{{/search}}]'>
</form>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions partials/classes.handlebars
Expand Up @@ -92,7 +92,7 @@
<ul class="index-list methods{{#if extends}} extends{{/if}}">
{{#methods}}
<li class="index-item method{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
<a href="#method_{{name}}">{{name}}</a>
<a href="#" data-tabid="#methods" data-anchor="#method_{{name}}" data-tablink="{{name}}">{{name}}</a>

{{#if static}}
<span class="flag static">static</span>
Expand All @@ -113,7 +113,7 @@
<ul class="index-list properties{{#if extends}} extends{{/if}}">
{{#properties}}
<li class="index-item property{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
<a href="#property_{{name}}">{{name}}</a>
<a href="#" data-tabid="#properties" data-anchor="#property_{{name}}" data-tablink="{{name}}">{{name}}</a>

{{#if static}}
<span class="flag static">static</span>
Expand All @@ -134,7 +134,7 @@
<ul class="index-list attrs{{#if extends}} extends{{/if}}">
{{#attrs}}
<li class="index-item attr{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
<a href="#attr_{{name}}">{{name}}</a>
<a href="#" data-tabid="#attrs" data-anchor="#attr_{{name}}" data-tablink="{{name}}">{{name}}</a>
</li>
{{/attrs}}
</ul>
Expand All @@ -148,7 +148,7 @@
<ul class="index-list events{{#if extends}} extends{{/if}}">
{{#events}}
<li class="index-item event{{#if access}} {{access}}{{/if}}{{#if deprecated}} deprecated{{/if}}{{#if overwritten_from}} inherited{{/if}}{{#if extended_from}} inherited{{/if}}">
<a href="#event_{{name}}">{{name}}</a>
<a href="#" data-tabid="#events" data-anchor="#event_{{name}}" data-tablink="{{name}}">{{name}}</a>

{{#if static}}
<span class="flag static">static</span>
Expand Down
4 changes: 2 additions & 2 deletions partials/sidebar.handlebars
Expand Up @@ -13,9 +13,9 @@
<div class="tab-content" style="border: 1px solid #DDD; border-top:0;">
<div class="tab-pane active" id="classes">
<ul id="api-classes" class="nav nav-list">
{{#classes}}
{{#publicClasses classes}}
<li><a href="{{../projectRoot}}classes/{{name}}.html">{{displayName}}</a></li>
{{/classes}}
{{/publicClasses}}
</ul>
</div>

Expand Down

0 comments on commit ca511cf

Please sign in to comment.