3
// store height of collapse once opened
4
var baseCollapseHeight;
6
// whever something happens with re: to the autocomplete,
7
// we need to change the height of the collapse to match the
9
function afterAutoCompleteEvents (e, args) {
11
// transition config of collapse
13
// height of autocomplete list node
16
var collapse = args.collapse;
17
// input which has autocomplete plugin
18
var input = args.input;
20
// only calculate new height if autocomplete collapse is expanded
21
if(!collapse.get('state')) {
25
// would only happen if collapse did not open properly
26
if(!baseCollapseHeight) {
27
throw new Error('baseCollapseHeight was falsy or 0');
30
// list was made invisible
31
if(e.type === 'autocompleteListPlugin:visibleChange' && !e.newVal) {
34
acListHeight = input.ac.get('listNode').get('scrollHeight');
37
// config from collapse
38
transitionConfig = collapse.getAttrs(['duration', 'easing']);
39
// add height to config, using base value and the current autocomplete list node height
40
transitionConfig.height = baseCollapseHeight + acListHeight + 'px';
42
// transition using created config
43
collapse.get('host').transition(transitionConfig);
45
Y.log('collapse host height: ' + transitionConfig.height, 'debug', 'navbar-autocomplete');
48
var navbars = Y.all('.ues-navbar');
51
navbars.each(function(node, i) {
53
// the autocomplete wrapper
54
var wrapper = node.one('.autocomplete');
55
// input which has autocomplete plugin
57
// autocomplete boundingbox
61
Y.log('no AutoComplete wrapper in navbar #' + i, 'debug', 'navbar-autocomplete');
65
input = wrapper.one('input[type="search"]');
67
throw new Error('autocomplete is missing input');
71
input.plug(Y.Plugin.AutoComplete, {
72
resultTextLocator: 'text',
73
resultHighlighter: 'phraseMatch',
77
// whenever the autocomplete list node changes in height (or becomes invisible)
78
// we need to change the height of the collapse
79
input.ac.after(['clear', 'results', 'visibleChange'], afterAutoCompleteEvents, window, {
80
collapse: wrapper.collapse,
84
// store collapse height the first time the collapse opens
85
wrapper.collapse.once('open', function (e) {
86
baseCollapseHeight = e.target.get('host').get('scrollHeight');
87
Y.log('baseCollapseHeight: ' + baseCollapseHeight, 'debug', 'navbar-autocomplete');
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);