Skip to content

Commit

Permalink
WIP: version compile works, drop down inserted but not functional.
Browse files Browse the repository at this point in the history
[#150449948] https://www.pivotaltracker.com/story/show/150449948
Signed-off-by: Shash Reddy <sreddy@pivotal.io>
  • Loading branch information
6palace committed Aug 29, 2017
1 parent 8dff169 commit 45a392c
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 1 deletion.
2 changes: 1 addition & 1 deletion uaa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ task(slate, type: Exec) {

workingDir file('build/slate')
executable 'bundle'
args 'exec', 'middleman', 'build', '--verbose', '--build-dir=../docs'
args 'exec', 'middleman', 'build', '--verbose', '--build-dir=../docs/version/' + version
// executable 'echo'
// args 'hello', 'world'
}
Expand Down
3 changes: 3 additions & 0 deletions uaa/slate/source/javascripts/all.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
//= require ./all_nosearch
//= require ./app/_search
//= require ./app/_version_dropdown
//= require ./lib/_dropdown

2 changes: 2 additions & 0 deletions uaa/slate/source/javascripts/all_nosearch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//= require ./lib/_energize
//= require ./app/_toc
//= require ./app/_lang
//= require ./app/_version_dropdown
//= require ./lib/_dropdown

$(function() {
loadToc($('#toc'), '.toc-link', '.toc-list-h2, .toc-list-h3', 10);
Expand Down
106 changes: 106 additions & 0 deletions uaa/slate/source/javascripts/app/_version_dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//= require ../lib/_lunr


(function() {
'use strict';

var originalSearchResults, originalDropdownLinks;
var searchResults, dropdownLinks;

var index = new lunr.Index();

index.ref('id');
index.field('title', {boost: 10});
index.field('body');
index.pipeline.add(lunr.trimmer, lunr.stopWordFilter);

$(setupVersionsDropdown);

function captureOriginal() {
originalSearchResults = $('#version-list').clone();
originalDropdownLinks = originalSearchResults.find('.version-link').clone();
}

function bindDropdownPointers() {
dropdownLinks = $('.dropdown-content .version-link');
}

function restoreOriginalContent() {
searchResults.html(originalSearchResults.html());
}

function bindFilter() {
searchResults = $('#version-list');
$('#version-select').on('keyup', filterDropdown);
}

function findMatchingLinkFromOriginal(id) {
var match = originalDropdownLinks.filter("#" + id)[0];
return match;
}

function displaySearchResults(results) {
$.each(results, function (index, result) {
var matchingLink = findMatchingLinkFromOriginal(result.ref);
searchResults.append(matchingLink);
});
}

function populateFilter() {
dropdownLinks.each(function() {
var link = $(this);

index.add({
id: link.prop('id'),
title: link.text(),
href: link.href
});
});
}

function filterDropdown(event) {
// ESC clears the field
if (event.keyCode === 27) this.value = '';

if (this.value) {
var results = index.search(this.value).filter(function(r) {
return r.score > 0.0001;
});
if (results.length) {
searchResults.empty();
displaySearchResults(results);
} else {
searchResults.html('<li>' + 'No Results Found for "' + this.value + '"' + '</li>');
}
} else {
searchResults.empty();
restoreOriginalContent();
populateFilter();
}
}

function setupVersionsDropdown() {
// $.get(
// "/versions.json",
// function(data) {
// var versions = data.versions
var versions =
[
"4.6.0-SNAPSHOT",
"release-candidate"
];
for(var i = 0; i < versions.length; i++) {
var version = versions[i];
if(version == "release-candidate") { continue; }
var li = '<li><a id="version-link-' + version + '"' + ' class="version-link" href="/version/' + version + '">' + version + '</a></li>';
$('#version-list').append(li);
}

captureOriginal();
bindDropdownPointers();
populateFilter();
bindFilter();
// }
// );
}
})();
165 changes: 165 additions & 0 deletions uaa/slate/source/javascripts/lib/_dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* ========================================================================
* Bootstrap: dropdown.js v3.3.6
* http://getbootstrap.com/javascript/#dropdowns
* ========================================================================
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */


+function ($) {
'use strict';

// DROPDOWN CLASS DEFINITION
// =========================

var backdrop = '.dropdown-backdrop'
var toggle = '[data-toggle="dropdown"]'
var Dropdown = function (element) {
$(element).on('click.bs.dropdown', this.toggle)
}

Dropdown.VERSION = '3.3.6'

function getParent($this) {
var selector = $this.attr('data-target')

if (!selector) {
selector = $this.attr('href')
selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}

var $parent = selector && $(selector)

return $parent && $parent.length ? $parent : $this.parent()
}

function clearMenus(e) {
if (e && e.which === 3) return
$(backdrop).remove()
$(toggle).each(function () {
var $this = $(this)
var $parent = getParent($this)
var relatedTarget = { relatedTarget: this }

if (!$parent.hasClass('open')) return

if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return

$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))

if (e.isDefaultPrevented()) return

$this.attr('aria-expanded', 'false')
$parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget))
})
}

Dropdown.prototype.toggle = function (e) {
var $this = $(this)

if ($this.is('.disabled, :disabled')) return

var $parent = getParent($this)
var isActive = $parent.hasClass('open')

clearMenus()

if (!isActive) {
if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
// if mobile we use a backdrop because click events don't delegate
$(document.createElement('div'))
.addClass('dropdown-backdrop')
.insertAfter($(this))
.on('click', clearMenus)
}

var relatedTarget = { relatedTarget: this }
$parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))

if (e.isDefaultPrevented()) return

$this
.trigger('focus')
.attr('aria-expanded', 'true')

$parent
.toggleClass('open')
.trigger($.Event('shown.bs.dropdown', relatedTarget))
}

return false
}

Dropdown.prototype.keydown = function (e) {
if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return

var $this = $(this)

e.preventDefault()
e.stopPropagation()

if ($this.is('.disabled, :disabled')) return

var $parent = getParent($this)
var isActive = $parent.hasClass('open')

if (!isActive && e.which != 27 || isActive && e.which == 27) {
if (e.which == 27) $parent.find(toggle).trigger('focus')
return $this.trigger('click')
}

var desc = ' li:not(.disabled):visible a'
var $items = $parent.find('.dropdown-menu' + desc)

if (!$items.length) return

var index = $items.index(e.target)

if (e.which == 38 && index > 0) index-- // up
if (e.which == 40 && index < $items.length - 1) index++ // down
if (!~index) index = 0

$items.eq(index).trigger('focus')
}


// DROPDOWN PLUGIN DEFINITION
// ==========================

function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.dropdown')

if (!data) $this.data('bs.dropdown', (data = new Dropdown(this)))
if (typeof option == 'string') data[option].call($this)
})
}

var old = $.fn.dropdown

$.fn.dropdown = Plugin
$.fn.dropdown.Constructor = Dropdown


// DROPDOWN NO CONFLICT
// ====================

$.fn.dropdown.noConflict = function () {
$.fn.dropdown = old
return this
}


// APPLY TO STANDARD DROPDOWN ELEMENTS
// ===================================

$(document)
.on('click.bs.dropdown.data-api', clearMenus)
.on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
.on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown)
.on('keydown.bs.dropdown.data-api', '.dropdown-menu', Dropdown.prototype.keydown)

}(jQuery);
34 changes: 34 additions & 0 deletions uaa/slate/source/layouts/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ under the License.
%>
<% language_tabs = current_page.data.language_tabs || [] %>
<% page_content = yield %>
<%
def get_version
version = File.exists?('source/versionfile') ? File.read('source/versionfile') : 'local'
if version =~ /release-candidate/
"Release Candidate"
else
"Version #{version}"
end
end
%>
<%
if current_page.data.includes
current_page.data.includes.each do |include|
Expand Down Expand Up @@ -63,6 +73,30 @@ under the License.
<% end %>
</div>
<% end %>

<div id="version-dropdown">
<div class="dropdown">
<button type="button" id="version-dropdown-button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><%= get_version %><span class="caret">&#x25BE;</span></button>
<ul id="version-dropdown-menu" class="dropdown-menu" role="menu" aria-labelledby="version-dropdown-button">
<div class="dropdown-filter">
<div class="dropdown-search-bar">
<input id="version-select" type="text" placeholder="Filter">
</div>
<div class="dropdown-content">
<ul class="dropdown-list" id="version-list">
</ul>
</div>
<div class="dropdown-footer dropdown-content">
<ul class="dropdown-list">
<li><a id="release-candidate" href="/version/release-candidate">Release Candidate</a></li>
<li><a id="latest-release" href="/">Latest</a></li>
</ul>
</div>
</div>
</ul>
</div>
</div>

<% if current_page.data.search %>
<div class="search">
<input type="text" class="search" id="input-search" placeholder="Search">
Expand Down
Loading

0 comments on commit 45a392c

Please sign in to comment.