1
YUI.add('navbar-autocomplete', function (Y, NAME) {
6
// store height of collapse once opened
7
var baseCollapseHeight;
9
// whever something happens with re: to the autocomplete,
10
// we need to change the height of the collapse to match the
12
function afterAutoCompleteEvents (e, args) {
14
// transition config of collapse
16
// height of autocomplete list node
19
var collapse = args.collapse;
20
// input which has autocomplete plugin
21
var input = args.input;
23
// only calculate new height if autocomplete collapse is expanded
24
if(!collapse.get('state')) {
28
// would only happen if collapse did not open properly
29
if(!baseCollapseHeight) {
30
throw new Error('baseCollapseHeight was falsy or 0');
33
// list was made invisible
34
if(e.type === 'autocompleteListPlugin:visibleChange' && !e.newVal) {
37
acListHeight = input.ac.get('listNode').get('scrollHeight');
40
// config from collapse
41
transitionConfig = collapse.getAttrs(['duration', 'easing']);
42
// add height to config, using base value and the current autocomplete list node height
43
transitionConfig.height = baseCollapseHeight + acListHeight + 'px';
45
// transition using created config
46
collapse.get('host').transition(transitionConfig);
50
var navbars = Y.all('.ues-navbar');
53
navbars.each(function(node, i) {
55
// the autocomplete wrapper
56
var wrapper = node.one('.autocomplete');
57
// input which has autocomplete plugin
59
// autocomplete boundingbox
66
input = wrapper.one('input[type="search"]');
68
throw new Error('autocomplete is missing input');
72
input.plug(Y.Plugin.AutoComplete, {
73
resultTextLocator: 'text',
74
resultHighlighter: 'phraseMatch',
78
// whenever the autocomplete list node changes in height (or becomes invisible)
79
// we need to change the height of the collapse
80
input.ac.after(['clear', 'results', 'visibleChange'], afterAutoCompleteEvents, window, {
81
collapse: wrapper.collapse,
85
// store collapse height the first time the collapse opens
86
wrapper.collapse.once('open', function (e) {
87
baseCollapseHeight = e.target.get('host').get('scrollHeight');
91
autoCompleteBox = input.ac.get('boundingBox');
92
autoCompleteBox.addClass('ues-autocomplete').addClass('ues-dropdown');
93
autoCompleteBox.one('ul').addClass('ues-dropdown-menu');
95
// make ac control the visibility of the ues-dropdown
96
input.ac.before('visibleChange', function (e) {
97
autoCompleteBox.toggleClass('open', e.newVal);
106
}, '0.0.1', {"requires": ["node", "autocomplete", "autocomplete-highlighters"]});