2013-11-05 09:17:44 +01:00
|
|
|
//core functionalities, prototypes
|
2013-10-21 14:24:34 +02:00
|
|
|
$.fn.hasAttr = function(name)
|
|
|
|
{
|
2013-10-15 13:14:48 +02:00
|
|
|
return this.attr(name) !== undefined;
|
|
|
|
};
|
|
|
|
|
2013-10-09 00:58:49 +02:00
|
|
|
if ($.when.all === undefined)
|
|
|
|
{
|
|
|
|
$.when.all = function(deferreds)
|
|
|
|
{
|
|
|
|
var deferred = new $.Deferred();
|
|
|
|
$.when.apply($, deferreds).then(function()
|
|
|
|
{
|
|
|
|
deferred.resolve(Array.prototype.slice.call(arguments, 0));
|
|
|
|
}, function()
|
|
|
|
{
|
|
|
|
deferred.fail(Array.prototype.slice.call(arguments, 0));
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred;
|
|
|
|
}
|
|
|
|
}
|
2013-10-14 00:25:40 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
//safety trigger
|
2013-10-14 00:25:40 +02:00
|
|
|
$(function()
|
|
|
|
{
|
|
|
|
$('.safety a').click(function(e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var aDom = $(this);
|
|
|
|
if (aDom.hasClass('inactive'))
|
|
|
|
return;
|
|
|
|
aDom.addClass('inactive');
|
|
|
|
|
|
|
|
var url = $(this).attr('href') + '?json';
|
|
|
|
$.get(url, function(data)
|
|
|
|
{
|
|
|
|
if (data['success'])
|
|
|
|
{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:14:27 +01:00
|
|
|
alert(data['message']);
|
2013-10-14 00:25:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-11-05 09:17:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-10-15 13:14:48 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
//basic event listeners
|
|
|
|
$(function()
|
|
|
|
{
|
|
|
|
$('body').bind('dom-update', function()
|
2013-10-15 13:14:48 +02:00
|
|
|
{
|
2013-11-05 09:17:44 +01:00
|
|
|
function confirmEvent(e)
|
2013-10-15 13:14:48 +02:00
|
|
|
{
|
2013-11-05 09:17:44 +01:00
|
|
|
if (!confirm($(this).attr('data-confirm-text')))
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2013-10-15 13:14:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
$('form[data-confirm-text]').submit(confirmEvent);
|
|
|
|
$('a[data-confirm-text]').click(confirmEvent);
|
2013-10-15 13:14:48 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
$('a.simple-action').click(function(e)
|
|
|
|
{
|
|
|
|
if(e.isPropagationStopped())
|
|
|
|
return;
|
2013-10-15 13:14:48 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
e.preventDefault();
|
2013-10-15 13:14:48 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
var aDom = $(this);
|
|
|
|
if (aDom.hasClass('inactive'))
|
|
|
|
return;
|
|
|
|
aDom.addClass('inactive');
|
2013-10-15 13:14:48 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
var url = $(this).attr('href') + '?json';
|
|
|
|
$.get(url, {submit: 1}, function(data)
|
2013-10-15 13:14:48 +02:00
|
|
|
{
|
2013-11-05 09:17:44 +01:00
|
|
|
if (data['success'])
|
|
|
|
{
|
|
|
|
if (aDom.hasAttr('data-redirect-url'))
|
|
|
|
window.location.href = aDom.attr('data-redirect-url');
|
|
|
|
else
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2013-10-15 13:14:48 +02:00
|
|
|
else
|
2013-11-05 09:17:44 +01:00
|
|
|
{
|
2013-11-16 21:14:27 +01:00
|
|
|
alert(data['message']);
|
2013-11-05 09:17:44 +01:00
|
|
|
aDom.removeClass('inactive');
|
|
|
|
}
|
|
|
|
});
|
2013-10-15 13:14:48 +02:00
|
|
|
});
|
2013-10-17 22:57:32 +02:00
|
|
|
|
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
//attach data from submit buttons to forms before .submit() gets called
|
|
|
|
$(':submit').each(function()
|
2013-10-17 22:57:32 +02:00
|
|
|
{
|
2013-11-05 09:17:44 +01:00
|
|
|
$(this).click(function()
|
|
|
|
{
|
|
|
|
var form = $(this).closest('form');
|
|
|
|
form.find('.faux-submit').remove();
|
|
|
|
var input = $('<input class="faux-submit" type="hidden"/>').attr({
|
|
|
|
name: $(this).attr('name'),
|
|
|
|
value: $(this).val()
|
|
|
|
});
|
|
|
|
form.append(input);
|
2013-10-17 22:57:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-05 09:17:44 +01:00
|
|
|
$('body').trigger('dom-update');
|
2013-10-19 22:56:56 +02:00
|
|
|
});
|
|
|
|
|
2013-10-20 15:55:29 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
|
2013-10-20 15:55:29 +02:00
|
|
|
//modify DOM on small viewports
|
2013-10-19 22:56:56 +02:00
|
|
|
$(window).resize(function()
|
|
|
|
{
|
2013-10-20 15:55:29 +02:00
|
|
|
if ($('body').width() == $('body').data('last-width'))
|
|
|
|
return;
|
2013-10-19 22:56:56 +02:00
|
|
|
$('#inner-content .unit').addClass('bottom-unit');
|
|
|
|
if ($('body').width() < 600)
|
|
|
|
{
|
|
|
|
$('body').addClass('small-screen');
|
|
|
|
$('#sidebar').insertAfter($('#inner-content'));
|
|
|
|
$('#sidebar .unit').removeClass('left-unit').addClass('bottom-unit');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('body').removeClass('small-screen');
|
2013-10-20 15:55:29 +02:00
|
|
|
$('#sidebar').insertBefore($('#inner-content'));
|
2013-10-19 22:56:56 +02:00
|
|
|
$('#sidebar .unit').removeClass('bottom-unit').addClass('left-unit');
|
|
|
|
}
|
2013-10-20 15:55:29 +02:00
|
|
|
$('body').data('last-width', $('body').width());
|
2013-10-14 00:25:40 +02:00
|
|
|
});
|
2013-10-21 14:24:34 +02:00
|
|
|
$(function()
|
|
|
|
{
|
|
|
|
$(window).resize();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
|
2013-10-21 14:24:34 +02:00
|
|
|
//autocomplete
|
|
|
|
function split(val)
|
|
|
|
{
|
|
|
|
return val.split(/\s+/);
|
|
|
|
}
|
|
|
|
|
|
|
|
function extractLast(term)
|
|
|
|
{
|
|
|
|
return split(term).pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function()
|
|
|
|
{
|
2013-10-29 09:04:42 +01:00
|
|
|
$('[data-autocomplete-url]').each(function()
|
|
|
|
{
|
|
|
|
var searchInput = $(this);
|
|
|
|
searchInput
|
2013-10-21 14:24:34 +02:00
|
|
|
// don't navigate away from the field on tab when selecting an item
|
|
|
|
.bind("keydown", function(event)
|
|
|
|
{
|
|
|
|
if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active)
|
|
|
|
{
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}).autocomplete({
|
2013-10-21 15:07:27 +02:00
|
|
|
minLength: 1,
|
2013-10-21 14:24:34 +02:00
|
|
|
source: function(request, response)
|
|
|
|
{
|
|
|
|
var term = extractLast(request.term);
|
2013-10-27 23:14:48 +01:00
|
|
|
if (term != '')
|
|
|
|
$.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term}, function(data)
|
|
|
|
{
|
2013-10-28 11:19:15 +01:00
|
|
|
response($.map(data.tags, function(tag) { return { label: tag.name, value: tag.name }; }));
|
2013-10-27 23:14:48 +01:00
|
|
|
});
|
2013-10-21 14:24:34 +02:00
|
|
|
},
|
|
|
|
focus: function()
|
|
|
|
{
|
|
|
|
// prevent value inserted on focus
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
select: function(event, ui)
|
|
|
|
{
|
|
|
|
var terms = split(this.value);
|
|
|
|
terms.pop();
|
|
|
|
terms.push(ui.item.value);
|
|
|
|
terms.push('');
|
|
|
|
this.value = terms.join(' ');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2013-10-29 09:04:42 +01:00
|
|
|
});
|
2013-10-21 14:24:34 +02:00
|
|
|
});
|
2013-10-21 14:48:28 +02:00
|
|
|
|
|
|
|
function getTagItOptions()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
caseSensitive: false,
|
|
|
|
autocomplete:
|
|
|
|
{
|
|
|
|
source:
|
|
|
|
function(request, response)
|
|
|
|
{
|
|
|
|
var term = request.term.toLowerCase();
|
2013-10-28 11:19:15 +01:00
|
|
|
var tags = $.map(this.options.availableTags, function(a)
|
|
|
|
{
|
|
|
|
return a.name;
|
|
|
|
});
|
|
|
|
var results = $.grep(tags, function(a)
|
2013-10-21 14:48:28 +02:00
|
|
|
{
|
2013-10-21 15:10:25 +02:00
|
|
|
if (term.length < 3)
|
|
|
|
return a.toLowerCase().indexOf(term) == 0;
|
|
|
|
else
|
|
|
|
return a.toLowerCase().indexOf(term) != -1;
|
2013-10-21 14:48:28 +02:00
|
|
|
});
|
2013-10-28 11:19:15 +01:00
|
|
|
results = results.slice(0, 15);
|
2013-10-21 14:48:28 +02:00
|
|
|
if (!this.options.allowDuplicates)
|
|
|
|
results = this._subtractArray(results, this.assignedTags());
|
|
|
|
response(results);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2013-10-25 15:41:09 +02:00
|
|
|
|
2013-11-05 09:17:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
//hotkeys
|
2013-10-25 15:41:09 +02:00
|
|
|
$(function()
|
|
|
|
{
|
2013-10-26 12:39:15 +02:00
|
|
|
Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }, 'keyup');
|
2013-10-25 15:41:09 +02:00
|
|
|
Mousetrap.bind('w', function() { $('body,html').animate({scrollTop: '-=150px'}, 200); });
|
|
|
|
Mousetrap.bind('s', function() { $('body,html').animate({scrollTop: '+=150px'}, 200); });
|
2013-10-28 13:01:49 +01:00
|
|
|
Mousetrap.bind('a', function() { var url = $('.paginator:visible .prev:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup');
|
|
|
|
Mousetrap.bind('d', function() { var url = $('.paginator:visible .next:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup');
|
2013-10-25 15:41:09 +02:00
|
|
|
});
|