-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI/Button/Month: 42413, use month input (#8278)
- Loading branch information
Showing
6 changed files
with
126 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,124 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
il = il || {}; | ||
il.UI = il.UI || {}; | ||
il.UI.button = il.UI.button || {}; | ||
(function($, il) { | ||
il.UI.button = (function($) { | ||
|
||
/* month button */ | ||
var initMonth = function (id) { | ||
$("#" + id).find(".inline-picker").each(function(o) { | ||
$(this).datetimepicker({ | ||
inline: true, | ||
sideBySide: true, | ||
viewMode: "months", | ||
format: "MM/YYYY", | ||
defaultDate: $(this).parent().data("defaultDate"), | ||
locale: $(this).parent().data("lang") | ||
}).on("dp.change", function (ev) { | ||
var i, d, months = []; | ||
var d = new Date(ev.date); | ||
var m = d.getMonth() + 1; | ||
m = ("00" + m).substring(m.toString().length); | ||
|
||
for (i = 1; i <= 12; i++) { | ||
months.push(il.Language.txt("month_" + (("00" + i).substring(i.toString().length)) + "_short")); | ||
} | ||
(function ($, il) { | ||
il.UI.button = (function ($) { | ||
/* month button */ | ||
const initMonth = function (id) { | ||
const btn = document.querySelector(`#${id} > input`); | ||
btn.addEventListener('change', (e) => { | ||
const value = e.srcElement.value.split('-').reverse().join('-'); | ||
const id = e.srcElement.closest('.il-btn-month').getAttribute('id'); | ||
$(`#${id}`).trigger('il.ui.button.month.changed', [id, value]); | ||
}); | ||
}; | ||
|
||
$("#" + id + " span.il-current-month").html(months[d.getMonth()] + " " + d.getFullYear()); | ||
$("#" + id).trigger("il.ui.button.month.changed", [id, m + "-" + d.getFullYear()]); | ||
}); | ||
}); | ||
}; | ||
/* toggle button */ | ||
const handleToggleClick = function (event, id, on_url, off_url, signals) { | ||
const b = $(`#${id}`); | ||
const pressed = b.attr('aria-pressed'); | ||
for (let i = 0; i < signals.length; i++) { | ||
const s = signals[i]; | ||
if (s.event === 'click' | ||
|| (pressed === 'true' && s.event === 'toggle_on') | ||
|| (pressed !== 'true' && s.event === 'toggle_off') | ||
) { | ||
$(b).trigger(s.signal_id, { | ||
id: s.signal_id, | ||
event: s.event, | ||
triggerer: b, | ||
options: s.options, | ||
}); | ||
} | ||
} | ||
|
||
/* toggle button */ | ||
var handleToggleClick = function (event, id, on_url, off_url, signals) { | ||
var b = $("#" + id); | ||
var pressed = b.attr("aria-pressed"); | ||
for (var i = 0; i < signals.length; i++) { | ||
var s = signals[i]; | ||
if (s.event === "click" || | ||
(pressed === "true" && s.event === "toggle_on") || | ||
(pressed !== "true" && s.event === "toggle_off") | ||
) { | ||
$(b).trigger(s.signal_id, { | ||
'id' : s.signal_id, | ||
'event' : s.event, | ||
'triggerer' : b, | ||
'options' : s.options}); | ||
} | ||
} | ||
if (pressed === 'true' && on_url !== '') { | ||
window.location = on_url; | ||
} | ||
|
||
if (pressed === "true" && on_url !== '') { | ||
window.location = on_url; | ||
} | ||
if (pressed !== 'true' && off_url !== '') { | ||
window.location = off_url; | ||
} | ||
|
||
if (pressed !== "true" && off_url !== '') { | ||
window.location = off_url; | ||
} | ||
return false; | ||
}; | ||
|
||
//console.log('handleToggelClick: ' + id); | ||
return false; | ||
}; | ||
const activateLoadingAnimation = function (id) { | ||
const $button = $(`#${id}`); | ||
$button.addClass('il-btn-with-loading-animation'); | ||
$button.addClass('disabled'); | ||
return $button; | ||
}; | ||
|
||
var activateLoadingAnimation = function(id){ | ||
console.log('#'+id); | ||
var $button = $('#'+id); | ||
$button.addClass('il-btn-with-loading-animation'); | ||
$button.addClass('disabled'); | ||
return $button; | ||
}; | ||
const deactivateLoadingAnimation = function (id) { | ||
const $button = $(`#${id}`); | ||
$button.removeClass('il-btn-with-loading-animation'); | ||
$button.removeClass('disabled'); | ||
return $button; | ||
}; | ||
|
||
var deactivateLoadingAnimation = function(id){ | ||
var $button = $('#'+id); | ||
$button.removeClass('il-btn-with-loading-animation'); | ||
$button.removeClass('disabled'); | ||
return $button; | ||
}; | ||
|
||
return { | ||
initMonth: initMonth, | ||
handleToggleClick: handleToggleClick, | ||
activateLoadingAnimation: activateLoadingAnimation, | ||
deactivateLoadingAnimation: deactivateLoadingAnimation | ||
}; | ||
})($); | ||
})($, il); | ||
return { | ||
initMonth, | ||
handleToggleClick, | ||
activateLoadingAnimation, | ||
deactivateLoadingAnimation, | ||
}; | ||
}($)); | ||
}($, il)); | ||
|
||
// toggle init | ||
document.addEventListener("DOMContentLoaded", function() { | ||
|
||
document.querySelectorAll(".il-toggle-button:not(.unavailable)").forEach(button => { | ||
const refreshLabels = (b, toggle = false) => { | ||
let on = b.classList.contains("on"); | ||
if (toggle) { | ||
on = !on; | ||
} | ||
if (b.querySelectorAll(".il-toggle-label-off, .il-toggle-label-on").length > 0) { | ||
b.querySelectorAll(".il-toggle-label-off, .il-toggle-label-on").forEach(l => { | ||
l.style.display = "none"; | ||
}); | ||
if (on) { | ||
b.setAttribute('aria-pressed', true); | ||
b.classList.add("on"); | ||
b.classList.remove("off"); | ||
b.querySelector(".il-toggle-label-on").style.display = ""; | ||
} else { | ||
b.setAttribute('aria-pressed', false); | ||
b.classList.add("off"); | ||
b.classList.remove("on"); | ||
b.querySelector(".il-toggle-label-off").style.display = ""; | ||
} | ||
} else { | ||
if (on) { | ||
b.setAttribute('aria-pressed', true); | ||
b.classList.add("on"); | ||
b.classList.remove("off"); | ||
} else { | ||
b.setAttribute('aria-pressed', false); | ||
b.classList.add("off"); | ||
b.classList.remove("on"); | ||
} | ||
} | ||
} | ||
refreshLabels(button); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('.il-toggle-button:not(.unavailable)').forEach((button) => { | ||
const refreshLabels = (b, toggle = false) => { | ||
let on = b.classList.contains('on'); | ||
if (toggle) { | ||
on = !on; | ||
} | ||
if (b.querySelectorAll('.il-toggle-label-off, .il-toggle-label-on').length > 0) { | ||
b.querySelectorAll('.il-toggle-label-off, .il-toggle-label-on').forEach((l) => { | ||
l.style.display = 'none'; | ||
}); | ||
if (on) { | ||
b.setAttribute('aria-pressed', true); | ||
b.classList.add('on'); | ||
b.classList.remove('off'); | ||
b.querySelector('.il-toggle-label-on').style.display = ''; | ||
} else { | ||
b.setAttribute('aria-pressed', false); | ||
b.classList.add('off'); | ||
b.classList.remove('on'); | ||
b.querySelector('.il-toggle-label-off').style.display = ''; | ||
} | ||
} else if (on) { | ||
b.setAttribute('aria-pressed', true); | ||
b.classList.add('on'); | ||
b.classList.remove('off'); | ||
} else { | ||
b.setAttribute('aria-pressed', false); | ||
b.classList.add('off'); | ||
b.classList.remove('on'); | ||
} | ||
}; | ||
refreshLabels(button); | ||
|
||
button.addEventListener("click", e => { | ||
const b = e.currentTarget; | ||
refreshLabels(b, true); | ||
}); | ||
}); | ||
}); | ||
button.addEventListener('click', (e) => { | ||
const b = e.currentTarget; | ||
refreshLabels(b, true); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
components/ILIAS/UI/src/templates/default/Button/tpl.month.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
<div id="{ID}" class="btn-group il-btn-month"> | ||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> | ||
<span class="il-current-month">{DEFAULT_LABEL}</span> | ||
<span class="caret"></span> | ||
</button> | ||
<div class="dropdown-menu" data-default-date="{DEF_DATE}" data-lang="{LANG}"> | ||
<div class="inline-picker"></div> | ||
</div> | ||
</div> | ||
<input type="month" class="btn btn-default" value="{DEFAULT}" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters