From: Vincent Vanwaelscappel Date: Fri, 30 Sep 2022 06:58:32 +0000 (+0200) Subject: wait #5482 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9320d7836d1700fda5be00ae27430c148be7d080;p=eif-extranet.git wait #5482 @0.5 --- diff --git a/EIF-URW.zip b/EIF-URW.zip index 39ad302..db8c43e 100644 Binary files a/EIF-URW.zip and b/EIF-URW.zip differ diff --git a/js/script.js b/js/script.js index 3c3a4d7..c4e7475 100644 --- a/js/script.js +++ b/js/script.js @@ -1,13 +1,117 @@ -$(function () { +function _updateAfterDomChange() { + initTooltips(); + updateTable(); + updateIcons() + updateSwitchSelection() +} + +// Tables (Selectionner les lignes dont la checkbox est cochée) +function updateTable() { + $('table').each(function () { + $(this).find('td input[type=checkbox]').each(function () { + var checked = $(this).prop('checked'); + var tr = $(this).closest('tr'); + if (checked) { + $(tr).addClass('selected'); + } else { + $(tr).removeClass('selected'); + } + }); + }); +} + + +/** + * Ajouter les symboles SVG dans les élements ayant l'attribut data-icon + * Par défaut, l'icône est ajoutée à la fin de l'élement. + * Si l'attribut data-icon-prepend est présent, l'icône est ajoutée au début de l'élement. + */ +function updateIcons() { + $("[data-icon]").each(function () { + var iconId = 'eif-' + $(this).data('icon'); + // L'icône est déjà en place + if ($(this).children('svg.' + iconId).length) { + return; + } + // Si une autre icône est présente, on la supprime + $(this).children('svg.svg-icon').remove(); + // Puis on ajoute l'icône + var icon = getSpriteIcon(iconId); + if ($(this).is('[data-icon-prepend]')) { + $(this).prepend(icon); + } else { + $(this).append(icon); + } + }); +} + +// Générer le code qui affiche une icône du Sprite SVG +function getSpriteIcon(icon, attrs) { + var a = []; + var iconSymbol = $('svg symbol[id="' + icon + '"]'); + if (iconSymbol.length > 1) { + $('svg symbol[id="' + icon + '"]:not(:last)').remove(); + iconSymbol = $('svg symbol[id="' + icon + '"]'); + } + + if (iconSymbol.length == 0) { + return ''; // Bail out because symbol doesn't exist + } + + if (attrs == undefined) { + attrs = {}; + } + if (attrs.viewBox == null) { + attrs.viewBox = iconSymbol.get(0).attributes.viewBox.value; + } + + if (Modernizr.msie) { + var vb = attrs.viewBox.split(' '); + attrs.width = vb[2]; + attrs.height = vb[3]; + } + + if (attrs.class == null) { + attrs.class = icon; + } else { + attrs.class += ' ' + icon; + } + + attrs.class += ' nav-icon svg-icon'; // Common class for all icons + + $.each(attrs, function (k, v) { + a.push(k + '="' + v + '"'); + }); + return ''; +} + +// Interrupteurs "Afficher tout / ma sélection +function updateSwitchSelection() { + $('.switch label').each(function () { + if ($(this).find('input').prop('checked')) { + $(this).addClass('checked'); + } else { + $(this).removeClass('checked'); + } + }); +} + +// Initialisation des tooltips +function initTooltips() { // Utilisation de tippy pour afficher les tooltips. - $('[data-tooltip]').each(function () { + $('[data-tooltip]:not([data-tooltip-done])').each(function () { tippy(this, {content: $(this).attr('data-tooltip')}); + $(this).attr('data-tooltip-done', '1'); }); // Tooltip du menu (uniquement en mode compact) - $("#menu nav>ul>li>a").each(function () { + $("#menu nav>ul>li>a:not([data-tooltip-done])").each(function () { tippy(this, {content: $(this).find('span').text(), trigger: 'manual', theme: 'menu'}); + $(this).attr('data-tooltip-done', '1'); }); +} + +$(function () { $(document).on('mouseover', '.menu-compact #menu nav>ul>li>a', function () { this._tippy.show(); clearTimeout(this._tippyHideTimeout); @@ -18,32 +122,6 @@ $(function () { }, 50); }); - /** - * Ajouter les symboles SVG dans les élements ayant l'attribut data-icon - * Par défaut, l'icône est ajoutée à la fin de l'élement. - * Si l'attribut data-icon-prepend est présent, l'icône est ajoutée au début de l'élement. - */ - var updateIcons = function () { - $("[data-icon]").each(function () { - var iconId = 'eif-' + $(this).data('icon'); - // L'icône est déjà en place - if ($(this).children('svg.' + iconId).length) { - return; - } - // Si une autre icône est présente, on la supprime - $(this).children('svg.svg-icon').remove(); - // Puis on ajoute l'icône - var icon = getSpriteIcon(iconId); - if ($(this).is('[data-icon-prepend]')) { - $(this).prepend(icon); - } else { - $(this).append(icon); - } - }); - }; - updateIcons(); - - // Menu : afficher le sous-menu au clic sur un élement $(document).on('click', '.open-submenu', function () { var li = $(this).closest('li'); @@ -55,35 +133,10 @@ $(function () { return false; }); - // Interrupteurs "Afficher tout / ma sélection - var updateSwitchSelection = function () { - $('.switch label').each(function () { - if ($(this).find('input').prop('checked')) { - $(this).addClass('checked'); - } else { - $(this).removeClass('checked'); - } - }); - }; $(document).on('change', 'input', function () { updateSwitchSelection(); }); - updateSwitchSelection(); - - // Tables (Selectionner les lignes dont la checkbox est cochée) - var updateTable = function () { - $('table').each(function () { - $(this).find('td input[type=checkbox]').each(function () { - var checked = $(this).prop('checked'); - var tr = $(this).closest('tr'); - if (checked) { - $(tr).addClass('selected'); - } else { - $(tr).removeClass('selected'); - } - }); - }); - } + $(document).on('change', 'input[type=checkbox]', function () { if ($(this).closest('th').length === 1) { var checked = $(this).prop('checked'); @@ -91,7 +144,6 @@ $(function () { } updateTable(); }); - updateTable(); // Lignes cliquables $(document).on('click', 'tr[data-href] td:not(:first-child)', function () { @@ -102,47 +154,8 @@ $(function () { // Menu : passer le menu en mode compact $(document).on('click', '.toggle-menu', function () { $('body').toggleClass('menu-compact'); - resize(); return false; }); -}); - -// Générer le code qui affiche une icône du Sprite SVG -function getSpriteIcon(icon, attrs) { - var a = []; - var iconSymbol = $('svg symbol[id="' + icon + '"]'); - if (iconSymbol.length > 1) { - $('svg symbol[id="' + icon + '"]:not(:last)').remove(); - iconSymbol = $('svg symbol[id="' + icon + '"]'); - } - if (iconSymbol.length == 0) { - return ''; // Bail out because symbol doesn't exist - } - - if (attrs == undefined) { - attrs = {}; - } - if (attrs.viewBox == null) { - attrs.viewBox = iconSymbol.get(0).attributes.viewBox.value; - } - - if (Modernizr.msie) { - var vb = attrs.viewBox.split(' '); - attrs.width = vb[2]; - attrs.height = vb[3]; - } - - if (attrs.class == null) { - attrs.class = icon; - } else { - attrs.class += ' ' + icon; - } - - attrs.class += ' nav-icon svg-icon'; // Common class for all icons - - $.each(attrs, function (k, v) { - a.push(k + '="' + v + '"'); - }); - return ''; -} \ No newline at end of file + _updateAfterDomChange(); +});