The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 4431a215 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Break common document-ready into smaller functions.

parent 962789ad
Branches
Tags
No related merge requests found
...@@ -229,8 +229,8 @@ function ajaxLogin(form) { ...@@ -229,8 +229,8 @@ function ajaxLogin(form) {
}); });
} }
$(document).ready(function() { // Ready functions
// Off canvas function setupOffcanvas() {
if($('.sidebar').length > 0) { if($('.sidebar').length > 0) {
$('[data-toggle="offcanvas"]').click(function () { $('[data-toggle="offcanvas"]').click(function () {
$('body.offcanvas').toggleClass('active'); $('body.offcanvas').toggleClass('active');
...@@ -246,12 +246,9 @@ $(document).ready(function() { ...@@ -246,12 +246,9 @@ $(document).ready(function() {
} else { } else {
$('[data-toggle="offcanvas"]').addClass('hidden'); $('[data-toggle="offcanvas"]').addClass('hidden');
} }
}
// support "jump menu" dropdown boxes function bindBacklink(i, elem) {
$('select.submit-on-select').change(function(){ $(this).parent('form').submit(); }); $(elem)
// Highlight previous links, grey out following
$('.backlink')
.mouseover(function() { .mouseover(function() {
// Underline back // Underline back
var t = $(this); var t = $(this);
...@@ -280,42 +277,55 @@ $(document).ready(function() { ...@@ -280,42 +277,55 @@ $(document).ready(function() {
t = t.next(); t = t.next();
} while(t.length > 0); } while(t.length > 0);
}); });
}
// Search autocomplete function bindAutocomplete(i, element) {
$('.autocomplete').each(function (i, element) { $(element).typeahead(
$(element).typeahead( {
{ highlight: true,
highlight: true, minLength: 3
minLength: 3 }, {
}, { displayKey:'val',
displayKey:'val', source: function(query, cb) {
source: function(query, cb) { var searcher = extractClassParams(element);
var searcher = extractClassParams(element); $.ajax({
$.ajax({ url: path + '/AJAX/JSON',
url: path + '/AJAX/JSON', data: {
data: { q:query,
q:query, method:'getACSuggestions',
method:'getACSuggestions', searcher:searcher['searcher'],
searcher:searcher['searcher'], type:searcher['type'] ? searcher['type'] : $('#searchForm_type').val()
type:searcher['type'] ? searcher['type'] : $('#searchForm_type').val() },
}, dataType:'json',
dataType:'json', success: function(json) {
success: function(json) { if (json.status == 'OK' && json.data.length > 0) {
if (json.status == 'OK' && json.data.length > 0) { var datums = [];
var datums = []; for (var i=0;i<json.data.length;i++) {
for (var i=0;i<json.data.length;i++) { datums.push({val:json.data[i]});
datums.push({val:json.data[i]});
}
cb(datums);
} else {
cb([]);
} }
cb(datums);
} else {
cb([]);
} }
}); }
} });
} }
); }
}); );
}
$(document).ready(function() {
// Off canvas
setupOffcanvas();
// support "jump menu" dropdown boxes
$('select.submit-on-select').change(function(){ $(this).parent('form').submit(); });
// Highlight previous links, grey out following
$('.backlink').each(bindBacklink);
// Search autocomplete
$('.autocomplete').each(bindAutocomplete);
// Refresh suggestions when search type changed
$('#searchForm_type').change(function() { $('#searchForm_type').change(function() {
var query = $('#searchForm_lookfor').val(); var query = $('#searchForm_lookfor').val();
$('#searchForm_lookfor').focus().typeahead('val', '').typeahead('val', query); $('#searchForm_lookfor').focus().typeahead('val', '').typeahead('val', query);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment