| 1 |
<!doctype html> |
| 2 |
|
| 3 |
<html lang="en"> |
| 4 |
<head> |
| 5 |
<meta charset="utf-8"> |
| 6 |
|
| 7 |
<title>Typeahead Navigation_v1 Demo</title> |
| 8 |
<meta name="description" content=""> |
| 9 |
<meta name="author" content=""> |
| 10 |
|
| 11 |
<link rel="stylesheet" href="../../src/jquery.typeahead.css"> |
| 12 |
<link rel="stylesheet" href="navigation_v1.css"> |
| 13 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> |
| 14 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> |
| 15 |
|
| 16 |
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> |
| 17 |
<script src="../../dist/jquery.typeahead.min.js"></script> |
| 18 |
|
| 19 |
</head> |
| 20 |
<body> |
| 21 |
|
| 22 |
<header class="header"></header> |
| 23 |
|
| 24 |
<div class="nav-wrapper"> |
| 25 |
<nav class="nav-container"> |
| 26 |
<div class="typeahead__container"> |
| 27 |
<div class="typeahead__field"> |
| 28 |
<div class="typeahead__query"> |
| 29 |
<input class="js-nav-typeahead-input" name="q" placeholder="Search" |
| 30 |
autocomplete="off"> |
| 31 |
<i class="fa fa-search"></i> |
| 32 |
</div> |
| 33 |
</div> |
| 34 |
</div> |
| 35 |
|
| 36 |
<ul class="main-nav"> |
| 37 |
<li> |
| 38 |
<a><i class="fa fa-home"></i> Home</a> |
| 39 |
</li> |
| 40 |
<li> |
| 41 |
<a><i class="fa fa-tasks"></i> Master Section <i class="fa fa-chevron-left pull-right"></i></a> |
| 42 |
<ul class="sub-nav"> |
| 43 |
<li> |
| 44 |
<a>First Section</a> |
| 45 |
</li> |
| 46 |
<li> |
| 47 |
<a>Second Section</a> |
| 48 |
</li> |
| 49 |
</ul> |
| 50 |
</li> |
| 51 |
<li> |
| 52 |
<a><i class="fa fa-futbol-o"></i> Sports <i class="fa fa-chevron-left pull-right"></i></a> |
| 53 |
<ul class="sub-nav"> |
| 54 |
<li> |
| 55 |
<a>Hockey</a> |
| 56 |
</li> |
| 57 |
<li> |
| 58 |
<a>Baseball</a> |
| 59 |
</li> |
| 60 |
<li> |
| 61 |
<a>Football</a> |
| 62 |
</li> |
| 63 |
<li> |
| 64 |
<a>Golf</a> |
| 65 |
</li> |
| 66 |
<li> |
| 67 |
<a>Soccer</a> |
| 68 |
</li> |
| 69 |
<li> |
| 70 |
<a>Tennis</a> |
| 71 |
</li> |
| 72 |
</ul> |
| 73 |
</li> |
| 74 |
</ul> |
| 75 |
</nav> |
| 76 |
</div> |
| 77 |
|
| 78 |
<div class="main-container"> |
| 79 |
<h1>Navigation_v1 Demo</h1> |
| 80 |
<h4>Edit this demo on <a href="https://jsfiddle.net/runningcoder/ogr7e52r/">JsFiddle</a></h4> |
| 81 |
</div> |
| 82 |
|
| 83 |
<script> |
| 84 |
$(function () { |
| 85 |
|
| 86 |
var element = $('.typeahead__container'), |
| 87 |
listItems = element.closest('.nav-wrapper').find('nav li'), |
| 88 |
data = $.map(listItems, function (v, i) { |
| 89 |
return { |
| 90 |
index: i, |
| 91 |
value: $(v).find('a:first').text().trim() |
| 92 |
} |
| 93 |
}); |
| 94 |
|
| 95 |
$('.nav-container').find('a').on('click', function () { |
| 96 |
if (!$(this).siblings('ul.sub-nav')[0]) return; |
| 97 |
$(this).closest('li').toggleClass('open'); |
| 98 |
}); |
| 99 |
|
| 100 |
typeof $.typeahead === "function" && $.typeahead({ |
| 101 |
input: '.js-nav-typeahead-input', |
| 102 |
minLength: 1, |
| 103 |
display: 'value', |
| 104 |
resultContainer: false, |
| 105 |
source: { |
| 106 |
data: data |
| 107 |
}, |
| 108 |
callback: { |
| 109 |
onSearch: function (node, query) { |
| 110 |
|
| 111 |
this.container.toggleClass('hasText', query.length >= 1); |
| 112 |
|
| 113 |
listItems.toggleClass('hidden', query.length >= 1).removeClass('open'); |
| 114 |
|
| 115 |
}, |
| 116 |
onResult: function (node, query, result, resultCount, resultCountPerGroup) { |
| 117 |
|
| 118 |
var item, |
| 119 |
isSubItem; |
| 120 |
|
| 121 |
for (var i = 0, len = result.length; i < len; ++i) { |
| 122 |
|
| 123 |
item = $(listItems[result[i].index]); |
| 124 |
isSubItem = item.parent().hasClass('sub-nav'); |
| 125 |
|
| 126 |
if (isSubItem) { |
| 127 |
item.parent().closest('li').attr('class', 'open') |
| 128 |
} |
| 129 |
|
| 130 |
item.removeClass('hidden') |
| 131 |
} |
| 132 |
} |
| 133 |
}, |
| 134 |
debug: true |
| 135 |
}); |
| 136 |
|
| 137 |
$(document).on('click', '.typeahead__container.hasText .fa-search', function () { |
| 138 |
$('.js-nav-typeahead-input').val('').trigger('input.typeahead'); |
| 139 |
}); |
| 140 |
|
| 141 |
}) |
| 142 |
</script> |
| 143 |
|
| 144 |
|
| 145 |
</body> |
| 146 |
</html> |