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);
48
Y.log('collapse host height: ' + transitionConfig.height, 'debug', 'navbar-autocomplete');
51
var navbars = Y.all('.ues-navbar');
54
navbars.each(function(node, i) {
56
// the autocomplete wrapper
57
var wrapper = node.one('.autocomplete');
58
// input which has autocomplete plugin
60
// autocomplete boundingbox
64
Y.log('no AutoComplete wrapper in navbar #' + i, 'debug', 'navbar-autocomplete');
68
input = wrapper.one('input[type="search"]');
70
throw new Error('autocomplete is missing input');
74
input.plug(Y.Plugin.AutoComplete, {
75
resultTextLocator: 'text',
76
resultHighlighter: 'phraseMatch',
80
// whenever the autocomplete list node changes in height (or becomes invisible)
81
// we need to change the height of the collapse
82
input.ac.after(['clear', 'results', 'visibleChange'], afterAutoCompleteEvents, window, {
83
collapse: wrapper.collapse,
87
// store collapse height the first time the collapse opens
88
wrapper.collapse.once('open', function (e) {
89
baseCollapseHeight = e.target.get('host').get('scrollHeight');
90
Y.log('baseCollapseHeight: ' + baseCollapseHeight, 'debug', 'navbar-autocomplete');
94
autoCompleteBox = input.ac.get('boundingBox');
95
autoCompleteBox.addClass('ues-autocomplete').addClass('ues-dropdown');
96
autoCompleteBox.one('ul').addClass('ues-dropdown-menu');
98
// make ac control the visibility of the ues-dropdown
99
input.ac.before('visibleChange', function (e) {
100
autoCompleteBox.toggleClass('open', e.newVal);
109
}, '0.0.1', {"requires": ["node", "autocomplete", "autocomplete-highlighters"]});