App-Netdisco
view release on metacpan or search on metacpan
share/public/javascripts/netdisco.js view on Meta::CPAN
// filtering of a function source, so no matcher is needed
$('#nq,#nqbody').autocomplete({
source: function (request, response) {
return $.get( uri_base + '/ajax/data/devicename/typeahead', request, function (data) {
return response(data);
});
}
,delay: 150
,minLength: 3
// the widget these boxes used to run opened with its first row picked out,
// so Enter took the obvious name. jQuery UI selects nothing unless asked, and
// does not write the row into the field: it only does that when a key moved
// the focus.
,autoFocus: true
});
// Both boxes ran that widget, so both are marked and the blue highlight is
// scoped to the mark; the app's other fifteen keep the theme's own.
$('#nq,#nqbody').each(function() {
$(this).autocomplete('widget').addClass('nd_search-suggestions');
});
// The navbar's box opens underneath the bar, and a menu hung at the field's
// own edge starts its first row inside it. Four pixels rather than the three
// that meet the edge exactly, the bar being a fraction taller on some
// platforms. The whole object is restated because it replaces the default
// rather than extending it, and losing collision:none would let the menu flip
// above the field in a short window.
$('#nq').autocomplete('option', 'position',
{ my: 'left top', at: 'left bottom+4', collision: 'none' });
// Its border and padding still reach into the bar, which paints above this
// widget's level, so the border needs lifting too. The menu is appended to the
// document rather than beside its field, so marking the widget here is the only
// way to reach one instance from the stylesheet.
$('#nq').autocomplete('widget').addClass('nd_navbar-suggestions');
// the widget this box used to run bolded the letters it matched, which is how
// the list shows why each row is in it, and jQuery UI offers no equivalent.
// Escaped first and marked second, because this goes in as markup where the
// default went in as text and the names come from the database.
$('#nq,#nqbody').each(function() {
$(this).autocomplete('instance')._renderItem = function(ul, item) {
var label = $('<div/>').text(item.label).html();
var term = $('<div/>').text(this.term).html()
.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
var marked = term.length
? label.replace(new RegExp('(' + term + ')', 'ig'), '<strong>$1</strong>')
: label;
return $('<li/>').append($('<div/>').html(marked)).appendTo(ul);
};
});
// activate tooltips and popovers, delegated from a container so that
// content injected later is covered without re-initialising. bootstrap
// stores one instance per element whatever the component, so the popover
// has to delegate from a different container than the tooltip.
new bootstrap.Tooltip(document.body, { selector: '[rel=tooltip]' });
new bootstrap.Popover(document.documentElement, { selector: '[rel=popover]' });
// Dismiss a tooltip when the pointer leaves, even if the element still holds
// focus. Both frameworks trigger on "hover focus", but the previous one hid
// unconditionally on leave while the replacement keeps the tip up until blur,
// stranding it over the content beside a sidebar field. Deliberately not
// solved by dropping "focus" from the trigger, which would also stop a tooltip
// appearing for someone tabbing through the form.
$(document.body).on('mouseleave', '[rel=tooltip]', function() {
var instance = bootstrap.Tooltip.getInstance(this);
if (instance) { instance.hide(); }
});
// bind submission to the navbar go icon
$('#navsearchgo').click(function() {
$('#navsearchgo').parents('form').submit();
});
$('.nd_navsearchgo-specific').click(function(event) {
event.preventDefault();
if ($('#nqbody').val()) {
$(this).parents('form').append(
$(document.createElement('input')).attr('type', 'hidden')
.attr('name', 'tab')
.attr('value', $(this).data('tab'))
).submit();
return;
}
if ($('#nq').val()) {
$(this).parents('form').append(
$(document.createElement('input')).attr('type', 'hidden')
.attr('name', 'tab')
.attr('value', $(this).data('tab'))
).submit();
return;
}
if ($('#discodevs').val()) {
$(this).parents('form').append(
$(document.createElement('input')).attr('type', 'hidden')
.attr('name', 'timeout')
.attr('value', $(this).data('timeout'))
).append(
$(document.createElement('input')).attr('type', 'hidden')
.attr('name', 'action')
.attr('value', $(this).data('action'))
).submit();
return;
}
});
// fix green background on search checkboxes
// https://github.com/twitter/bootstrap/issues/742
syncCheckBox = function() {
$(this).parents('.input-group-text').toggleClass('active', $(this).is(':checked'));
};
$('.input-group-text :checkbox').each(syncCheckBox).click(syncCheckBox);
// sidebar toggle - pinning
$('.nd_sidebar-pin').click(function() {
$('.nd_sidebar').toggleClass('nd_sidebar-pinned');
$('.nd_sidebar-pin').toggleClass('nd_sidebar-pin-clicked');
// update tooltip note for current state
if ($('.nd_sidebar-pin').hasClass('nd_sidebar-pin-clicked')) {
retitleTooltip($('.nd_sidebar-pin').first(), 'Unpin Sidebar');
}
( run in 0.448 second using v1.01-cache-2.11-cpan-2e0ccfb7a10 )