0) {
lis.eq(i-1).show();
$(el).siblings('.tab-right').removeClass('disabled');
}
if (i <= 1) {
$(el).addClass('disabled');
}
}
function displayTabsButtons() {
var lis;
var tabsWidth;
var el;
var numHidden;
$('div.tabs').each(function() {
el = $(this);
lis = el.find('ul').children();
tabsWidth = 0;
numHidden = 0;
lis.each(function(){
if ($(this).is(':visible')) {
tabsWidth += $(this).outerWidth(true);
} else {
numHidden++;
}
});
var bw = $(el).find('div.tabs-buttons').outerWidth(true);
if ((tabsWidth < el.width() - bw) && (lis.length === 0 || lis.first().is(':visible'))) {
el.find('div.tabs-buttons').hide();
} else {
el.find('div.tabs-buttons').show().children('button.tab-left').toggleClass('disabled', numHidden == 0);
}
});
}
function setPredecessorFieldsVisibility() {
var relationType = $('#relation_relation_type');
if (relationType.val() == "precedes" || relationType.val() == "follows") {
$('#predecessor_fields').show();
} else {
$('#predecessor_fields').hide();
}
}
function showModal(id, width, title) {
var el = $('#'+id).first();
if (el.length === 0 || el.is(':visible')) {return;}
if (!title) title = el.find('h3.title').text();
// moves existing modals behind the transparent background
$(".modal").css('zIndex',99);
el.dialog({
width: width,
modal: true,
resizable: false,
dialogClass: 'modal',
title: title
}).on('dialogclose', function(){
$(".modal").css('zIndex',101);
});
el.find("input[type=text], input[type=submit]").first().focus();
}
function hideModal(el) {
var modal;
if (el) {
modal = $(el).parents('.ui-dialog-content');
} else {
modal = $('#ajax-modal');
}
modal.dialog("close");
}
function collapseScmEntry(id) {
$('.'+id).each(function() {
if ($(this).hasClass('open')) {
collapseScmEntry($(this).attr('id'));
}
$(this).hide();
});
$('#'+id).removeClass('open');
}
function expandScmEntry(id) {
$('.'+id).each(function() {
$(this).show();
if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
expandScmEntry($(this).attr('id'));
}
});
$('#'+id).addClass('open');
}
function scmEntryClick(id, url) {
var el = $('#'+id);
var expander = el.find('.expander');
var folder = el.find('.icon-folder');
if (el.hasClass('open')) {
collapseScmEntry(id);
el.find('.expander').switchClass('icon-expanded', 'icon-collapsed');
el.addClass('collapsed');
updateSVGIcon(folder[0], 'folder')
toggleExpendCollapseIcon(expander[0]);
return false;
} else if (el.hasClass('loaded')) {
expandScmEntry(id);
el.find('.expander').switchClass('icon-collapsed', 'icon-expanded');
el.removeClass('collapsed');
updateSVGIcon(folder[0], 'folder-open')
toggleExpendCollapseIcon(expander[0]);
return false;
}
if (el.hasClass('loading')) {
return false;
}
el.addClass('loading');
$.ajax({
url: url,
success: function(data) {
el.after(data);
el.addClass('open').addClass('loaded').removeClass('loading');
el.find('.expander').switchClass('icon-collapsed', 'icon-expanded');
updateSVGIcon(folder[0], 'folder-open')
toggleExpendCollapseIcon(expander[0]);
}
});
return true;
}
function randomKey(size) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var key = '';
for (var i = 0; i < size; i++) {
key += chars.charAt(Math.floor(Math.random() * chars.length));
}
return key;
}
function copyToClipboard(text) {
if (navigator.clipboard) {
return navigator.clipboard.writeText(text).catch(() => {
return fallbackClipboardCopy(text);
});
} else {
return fallbackClipboardCopy(text);
}
}
function fallbackClipboardCopy(text) {
const temp = document.createElement('textarea');
temp.value = text;
temp.style.position = 'fixed';
temp.style.left = '-9999px';
document.body.appendChild(temp);
temp.select();
document.execCommand('copy');
document.body.removeChild(temp);
return Promise.resolve();
}
function copyDataClipboardTextToClipboard(target) {
copyToClipboard(target.getAttribute('data-clipboard-text'));
if ($(target).closest('.drdn.expanded').length) {
$(target).closest('.drdn.expanded').removeClass("expanded");
}
return false;
}
function setupCopyButtonsToPreElements() {
document.querySelectorAll('.wiki pre:not(.pre-wrapper pre)').forEach((pre) => {
// Wrap the element with a container and add a copy button
const wrapper = document.createElement("div");
wrapper.classList.add("pre-wrapper");
const copyButton = document.createElement("a");
copyButton.title = rm.I18n.buttonCopy;
copyButton.classList.add("copy-pre-content-link", "icon-only");
copyButton.append(createSVGIcon("copy-pre-content"));
wrapper.appendChild(copyButton);
wrapper.append(pre.cloneNode(true));
pre.replaceWith(wrapper);
// Copy the contents of the pre tag when copyButton is clicked
copyButton.addEventListener("click", (event) => {
event.preventDefault();
let textToCopy = (pre.querySelector("code") || pre).textContent.replace(/\n$/, '');
if (pre.querySelector("code.syntaxhl")) { textToCopy = textToCopy.replace(/ $/, ''); } // Workaround for half-width space issue in Textile's highlighted code
copyToClipboard(textToCopy).then(() => {
updateSVGIcon(copyButton, "checked");
setTimeout(() => updateSVGIcon(copyButton, "copy-pre-content"), 2000);
});
});
});
}
function updateIssueFrom(url, el) {
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
$(this).data('valuebeforeupdate', $(this).val());
});
if (el) {
$("#form_update_triggered_by").val($(el).attr('id'));
}
return $.ajax({
url: url,
type: 'post',
data: $('#issue-form').serialize()
});
}
function replaceIssueFormWith(html){
var replacement = $(html);
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
var object_id = $(this).attr('id');
if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) {
replacement.find('#'+object_id).val($(this).val());
}
});
$('#all_attributes').empty();
$('#all_attributes').prepend(replacement);
}
function updateBulkEditFrom(url) {
$.ajax({
url: url,
type: 'post',
data: $('#bulk_edit_form').serialize()
});
}
function observeAutocompleteField(fieldId, url, options) {
$(document).ready(function() {
$('#'+fieldId).autocomplete($.extend({
source: url,
minLength: 2,
position: {collision: "flipfit"},
search: function(){$('#'+fieldId).addClass('ajax-loading');},
response: function(){$('#'+fieldId).removeClass('ajax-loading');}
}, options));
$('#'+fieldId).addClass('autocomplete');
});
}
function multipleAutocompleteField(fieldId, url, options) {
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$(document).ready(function () {
$('#' + fieldId).autocomplete($.extend({
source: function (request, response) {
$.getJSON(url, {
term: extractLast(request.term)
}, response);
},
minLength: 2,
position: {collision: "flipfit"},
search: function () {
$('#' + fieldId).addClass('ajax-loading');
},
response: function () {
$('#' + fieldId).removeClass('ajax-loading');
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
}, options));
$('#' + fieldId).addClass('autocomplete');
});
}
function observeSearchfield(fieldId, targetId, url) {
$('#'+fieldId).each(function() {
var $this = $(this);
$this.addClass('autocomplete');
$this.attr('data-value-was', $this.val());
var check = function() {
var val = $this.val();
if ($this.attr('data-value-was') != val){
$this.attr('data-value-was', val);
$.ajax({
url: url,
type: 'get',
data: {q: $this.val()},
success: function(data){ if(targetId) $('#'+targetId).html(data); },
beforeSend: function(){ $this.addClass('ajax-loading'); },
complete: function(){ $this.removeClass('ajax-loading'); }
});
}
};
var reset = function() {
if (timer) {
clearInterval(timer);
timer = setInterval(check, 300);
}
};
var timer = setInterval(check, 300);
$this.bind('keyup click mousemove', reset);
});
}
$(document).ready(function(){
$(".drdn .autocomplete").val('');
// This variable is used to focus selected project
var selected;
$(document).on('click', '.drdn-trigger', function(e){
var drdn = $(this).closest(".drdn");
if (drdn.hasClass("expanded")) {
drdn.removeClass("expanded");
} else {
$(".drdn").removeClass("expanded");
drdn.addClass("expanded");
if ($(this).parent('#project-jump').length) {
selected = $('.drdn-items a.selected'); // Store selected project
selected.first().focus(); // Calling focus to scroll to selected project
}
if (!isMobile()) {
drdn.find(".autocomplete").focus();
}
e.stopPropagation();
}
});
$(document).click(function(e){
if ($(e.target).closest(".drdn").length < 1) {
$(".drdn.expanded").removeClass("expanded");
}
});
observeSearchfield('projects-quick-search', null, $('#projects-quick-search').data('automcomplete-url'));
$(".drdn-content").keydown(function(event){
var items = $(this).find(".drdn-items");
// If a project is selected set focused to selected only once
if (selected && selected.length > 0) {
var focused = selected;
selected = undefined;
}
else {
var focused = items.find("a:focus");
}
switch (event.which) {
case 40: //down
if (focused.length > 0) {
focused.nextAll("a").first().focus();;
} else {
items.find("a").first().focus();;
}
event.preventDefault();
break;
case 38: //up
if (focused.length > 0) {
var prev = focused.prevAll("a");
if (prev.length > 0) {
prev.first().focus();
} else {
$(this).find(".autocomplete").focus();
}
event.preventDefault();
}
break;
case 35: //end
if (focused.length > 0) {
focused.nextAll("a").last().focus();
event.preventDefault();
}
break;
case 36: //home
if (focused.length > 0) {
focused.prevAll("a").last().focus();
event.preventDefault();
}
break;
}
});
});
function beforeShowDatePicker(input, inst) {
var default_date = null;
switch ($(input).attr("id")) {
case "issue_start_date" :
if ($("#issue_due_date").length > 0) {
default_date = $("#issue_due_date").val();
}
break;
case "issue_due_date" :
if ($("#issue_start_date").length > 0) {
var start_date = $("#issue_start_date").val();
if (start_date != "") {
start_date = new Date(Date.parse(start_date));
if (start_date > new Date()) {
default_date = $("#issue_start_date").val();
}
}
}
break;
}
$(input).datepickerFallback("option", "defaultDate", default_date);
}
(function($){
$.fn.positionedItems = function(sortableOptions, options){
var settings = $.extend({
firstPosition: 1
}, options );
return this.sortable($.extend({
axis: 'y',
handle: ".sort-handle",
helper: function(event, ui){
ui.children('td').each(function(){
$(this).width($(this).width());
});
return ui;
},
update: function(event, ui) {
var sortable = $(this);
var handle = ui.item.find(".sort-handle").addClass("ajax-loading");
var url = handle.data("reorder-url");
var param = handle.data("reorder-param");
var data = {};
data[param] = {position: ui.item.index() + settings['firstPosition']};
$.ajax({
url: url,
type: 'put',
dataType: 'script',
data: data,
error: function(jqXHR, textStatus, errorThrown){
alert(jqXHR.status);
sortable.sortable("cancel");
},
complete: function(jqXHR, textStatus, errorThrown){
handle.removeClass("ajax-loading");
}
});
},
}, sortableOptions));
}
}( jQuery ));
var warnLeavingUnsavedMessage;
function warnLeavingUnsaved(message) {
warnLeavingUnsavedMessage = message;
$(document).on('submit', 'form', function(){
$('textarea').removeData('changed');
});
$(document).on('change', 'textarea', function(){
$(this).data('changed', 'changed');
});
window.onbeforeunload = function(){
var warn = false;
$('textarea').blur().each(function(){
if ($(this).data('changed')) {
warn = true;
}
});
if (warn) {return warnLeavingUnsavedMessage;}
};
}
function setupAjaxIndicator() {
$(document).bind('ajaxSend', function(event, xhr, settings) {
if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') {
$('#ajax-indicator').show();
}
});
$(document).bind('ajaxStop', function() {
$('#ajax-indicator').hide();
});
}
function setupTabs() {
if($('.tabs').length > 0) {
displayTabsButtons();
$(window).resize(displayTabsButtons);
}
}
function setupFilePreviewNavigation() {
// only bind arrow keys when preview navigation is present
const element = $('.pagination.filepreview').first();
if (element) {
const handleArrowKey = function(selector, e){
const href = $(element).find(selector).attr('href');
if (href) {
window.location = href;
e.preventDefault();
}
};
$(document).keydown(function(e) {
if(e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return;
switch(e.key) {
case 'ArrowLeft':
handleArrowKey('.previous a', e);
break;
case 'ArrowRight':
handleArrowKey('.next a', e);
break;
}
});
}
}
$(document).on('keydown', 'form textarea', function(e) {
// Submit the form with Ctrl + Enter or Command + Return
var targetForm = $(e.target).closest('form');
if(e.keyCode == 13 && ((e.ctrlKey && !e.metaKey) || (!e.ctrlKey && e.metaKey) && targetForm.length)) {
// For ajax, use click() instead of submit() to prevent "Invalid form authenticity token" error
if (targetForm.attr('data-remote') == 'true') {
if (targetForm.find('input[type=submit]').length === 0) { return false; }
targetForm.find('textarea').blur().removeData('changed');
targetForm.find('input[type=submit]').first().click();
} else {
targetForm.find('textarea').blur().removeData('changed');
targetForm.submit();
}
}
});
function hideOnLoad() {
$('.hol').hide();
}
function addFormObserversForDoubleSubmit() {
$('form[method=post]').each(function() {
if (!$(this).hasClass('multiple-submit')) {
$(this).submit(function(form_submission) {
if ($(form_submission.target).attr('data-submitted')) {
form_submission.preventDefault();
} else {
$(form_submission.target).attr('data-submitted', true);
}
});
}
});
}
function defaultFocus(){
if (($('#content :focus').length == 0) && (window.location.hash == '')) {
$('#content input[type=text]:visible, #content textarea:visible').first().focus();
}
}
function blockEventPropagation(event) {
event.stopPropagation();
event.preventDefault();
}
function toggleDisabledOnChange() {
var checked = $(this).is(':checked');
$($(this).data('disables')).attr('disabled', checked);
$($(this).data('enables')).attr('disabled', !checked);
$($(this).data('shows')).toggle(checked);
}
function toggleDisabledInit() {
$('input[data-disables], input[data-enables], input[data-shows]').each(toggleDisabledOnChange);
}
function toggleMultiSelectIconInit() {
$('.toggle-multiselect:not(.icon-toggle-minus):not(.icon-toggle-plus)').each(function(){
let iconType;
if ($(this).siblings('select').find('option:selected').length > 1) {
iconType = 'toggle-minus';
} else {
iconType = 'toggle-plus';
}
$(this).addClass(`icon-${iconType}`);
updateSVGIcon($(this).find('svg')[0], iconType);
});
}
function toggleNewObjectDropdown() {
var dropdown = $('#new-object + ul.menu-children');
if(dropdown.hasClass('visible')){
dropdown.removeClass('visible');
}else{
dropdown.addClass('visible');
}
}
(function ( $ ) {
// detect if native date input is supported
var nativeDateInputSupported = true;
var input = document.createElement('input');
input.setAttribute('type','date');
if (input.type === 'text') {
nativeDateInputSupported = false;
}
var notADateValue = 'not-a-date';
input.setAttribute('value', notADateValue);
if (input.value === notADateValue) {
nativeDateInputSupported = false;
}
$.fn.datepickerFallback = function( options ) {
if (nativeDateInputSupported) {
return this;
} else {
return this.datepicker( options );
}
};
}( jQuery ));
$(document).ready(function(){
$('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange);
toggleDisabledInit();
$('#content').on('click', '.toggle-multiselect', function() {
toggleMultiSelect($(this).siblings('select'));
$(this).toggleClass('icon-toggle-plus icon-toggle-minus');
updateSVGIcon($(this).find('svg')[0], $(this).hasClass('icon-toggle-plus') ? 'toggle-plus' : 'toggle-minus');
});
toggleMultiSelectIconInit();
$('#history .tabs').on('click', 'a', function(e){
var tab = $(e.target).attr('id').replace('tab-','');
document.cookie = 'history_last_tab=' + tab + '; SameSite=Lax'
});
});
$(document).ready(function(){
$('#content').on('click', 'div.jstTabs a.tab-preview', function(event){
var tab = $(event.target);
var url = tab.data('url');
var form = tab.parents('form');
var jstBlock = tab.parents('.jstBlock');
var element = encodeURIComponent(jstBlock.find('.wiki-edit').val());
var attachments = form.find('.attachments_fields input').serialize();
$.ajax({
url: url,
type: 'post',
data: "text=" + element + '&' + attachments,
success: function(data){
jstBlock.find('.wiki-preview').html(data);
setupWikiTableSortableHeader();
}
});
});
});
function keepAnchorOnSignIn(form){
var hash = decodeURIComponent(self.document.location.hash);
if (hash) {
if (hash.indexOf("#") === -1) {
hash = "#" + hash;
}
form.action = form.action + hash;
}
return true;
}
$(function ($) {
$('#auth_source_ldap_mode').change(function () {
$('.ldaps_warning').toggle($(this).val() != 'ldaps_verify_peer');
}).change();
});
function setFilecontentContainerHeight() {
var $filecontainer = $('.filecontent-container');
var fileTypeSelectors = ['.image', 'video'];
if($filecontainer.length > 0 && $filecontainer.find(fileTypeSelectors.join(',')).length === 1) {
var containerOffsetTop = $filecontainer.offset().top;
var containerMarginBottom = parseInt($filecontainer.css('marginBottom'));
var paginationHeight = $filecontainer.next('.pagination').height();
var diff = containerOffsetTop + containerMarginBottom + paginationHeight;
$filecontainer.css('height', 'calc(100vh - ' + diff + 'px)')
}
}
function setupAttachmentDetail() {
setFilecontentContainerHeight();
$(window).resize(setFilecontentContainerHeight);
}
function setupWikiTableSortableHeader() {
if (typeof Tablesort === 'undefined') { return; }
$('div.wiki table').each(function(i, table){
if (table.rows.length < 3) return true;
var tr = $(table.rows).first();
if (tr.find("TH").length > 0) {
tr.attr('data-sort-method', 'none');
tr.find("TD").attr('data-sort-method', 'none');
new Tablesort(table);
}
});
}
function setupHoverTooltips(container) {
$(container || 'body').find("[title]:not(.no-tooltip)").tooltip({
show: {
delay: 400
},
position: {
my: "center bottom-5",
at: "center top"
}
});
}
function removeHoverTooltips(container) {
$(container || 'body').find("[title]:not(.no-tooltip)").tooltip('destroy')
}
$(function() { setupHoverTooltips(); });
function inlineAutoComplete(element) {
'use strict';
// do not attach if Tribute is already initialized
if (element.dataset.tribute === 'true') {return};
const getDataSource = function(entity) {
const dataSources = rm.AutoComplete.dataSources;
if (dataSources[entity]) {
return dataSources[entity];
} else {
return false;
}
}
const remoteSearch = function(url, cb) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function ()
{
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
cb(data);
} else if (xhr.status === 403) {
cb([]);
}
}
};
xhr.open("GET", url, true);
xhr.send();
};
const tribute = new Tribute({
collection: [
{
trigger: '#',
values: function (text, cb) {
if (event.target.type === 'text' && element.getAttribute('autocomplete') != 'off') {
element.setAttribute('autocomplete', 'off');
}
// When triggered with text starting with "##", like "##a", the search term will become "#a",
// causing the SQL query to fail in finding issues with "a" in the subject.
// To avoid this, remove the first "#" from the search term.
if (text) {
text = text.replace(/^#/, '');
}
remoteSearch(getDataSource('issues') + encodeURIComponent(text), function (issues) {
return cb(issues);
});
},
lookup: 'label',
fillAttr: 'label',
requireLeadingSpace: true,
selectTemplate: function (issue) {
let leadingHash = "#"
// keep ## syntax which is a valid issue syntax to show issue with title.
if (this.currentMentionTextSnapshot.charAt(0) === "#") {
leadingHash = "##"
}
return leadingHash + issue.original.id;
},
menuItemTemplate: function (issue) {
return sanitizeHTML(issue.original.label);
}
},
{
trigger: '[[',
values: function (text, cb) {
remoteSearch(getDataSource('wiki_pages') + encodeURIComponent(text), function (wikiPages) {
return cb(wikiPages);
});
},
lookup: 'label',
fillAttr: 'label',
requireLeadingSpace: true,
selectTemplate: function (wikiPage) {
return '[[' + wikiPage.original.value + ']]';
},
menuItemTemplate: function (wikiPage) {
return sanitizeHTML(wikiPage.original.label);
}
},
{
trigger: '@',
lookup: function (user, mentionText) {
return user.name + user.firstname + user.lastname + user.login;
},
values: function (text, cb) {
const url = getDataSource('users');
if (url) {
remoteSearch(url + encodeURIComponent(text), function (users) {
return cb(users);
});
}
},
menuItemTemplate: function (user) {
return user.original.name;
},
selectTemplate: function (user) {
return '@' + user.original.login;
}
}
],
noMatchTemplate: ""
});
tribute.attach(element);
}
// collapsible sidebar jQuery plugin
(function($) {
// main container this is applied to
var main;
// triggers show/hide
var button;
// the key to use in local storage
// this will later be expanded using the current controller and action to
// allow for different sidebar states for different pages
var localStorageKey = 'redmine-sidebar-state';
// true if local storage is available
var canUseLocalStorage = function(){
try {
if('localStorage' in window){
localStorage.setItem('redmine.test.storage', 'ok');
var item = localStorage.getItem('redmine.test.storage');
localStorage.removeItem('redmine.test.storage');
if(item === 'ok') return true;
}
} catch (err) {}
return false;
}();
// function to set current sidebar state
var setState = function(state){
if(canUseLocalStorage){
localStorage.setItem(localStorageKey, state);
}
};
var applyState = function(){
if(main.hasClass('collapsedsidebar')){
updateSVGIcon(document.getElementById('sidebar-switch-button'), 'chevrons-left')
setState('hidden');
} else {
updateSVGIcon(document.getElementById('sidebar-switch-button'), 'chevrons-right')
setState('visible');
}
};
var setupToggleButton = function(){
button = $('#sidebar-switch-button');
button.click(function(e){
main.addClass("animate");
main.toggleClass('collapsedsidebar');
applyState();
e.preventDefault();
return false;
});
applyState();
};
$.fn.collapsibleSidebar = function() {
main = this;
// determine previously stored sidebar state for this page
if(canUseLocalStorage) {
// determine current controller/action pair and use them as storage key
var bodyClass = $('body').attr('class');
if(bodyClass){
try {
localStorageKey += '-' + bodyClass.split(/\s+/).filter(function(s){
return s.match(/(action|controller)-.*/);
}).sort().join('-');
} catch(e) {
// in case of error (probably IE8), continue with the unmodified key
}
}
var storedState = localStorage.getItem(localStorageKey);
main.toggleClass('collapsedsidebar', storedState === 'hidden');
}
// draw the toggle button once the DOM is complete
$(document).ready(setupToggleButton);
};
}(jQuery));
$(document).ready(setupAjaxIndicator);
$(document).ready(hideOnLoad);
$(document).ready(addFormObserversForDoubleSubmit);
$(document).ready(defaultFocus);
$(document).ready(setupAttachmentDetail);
$(document).ready(setupTabs);
$(document).ready(setupFilePreviewNavigation);
$(document).ready(setupWikiTableSortableHeader);
$(document).on('focus', '[data-auto-complete=true]', function(event) {
inlineAutoComplete(event.target);
});
document.addEventListener("DOMContentLoaded", () => { setupCopyButtonsToPreElements(); });