| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- /** template.js ***/
- /**
- $.imxNotify() - allows to display notification msg
- msg - message to display
- type - a bootstrap alert type message (alert, success, ...)
- **/
- $.imxNotify = function (msg, type) {
- let icon = 'fas fa-exclamation-triangle';
- type = type || 'success';
- switch (type) {
- case 'primary':
- break;
- case 'secondary':
- break;
- case 'success':
- icon = 'fas fa-check';
- break;
- case 'danger':
- break;
- case 'warning':
- icon = 'fas fa-exclamation-circle';
- break;
- case 'info':
- icon = 'fas fa-exclamation';
- break;
- case 'light':
- break;
- case 'dark':
- break;
- default:
- break;
- }
- $.notify({
- // options
- message: msg,
- icon: icon
- }, {
- // settings
- type: type,
- });
- };
- /**
- *
- * imxGetScript - Load a JavaScript file from the server using a GET HTTP request, then execute it.
- * alternative to $.getScript -
- *
- * url : url to the file to load
- * options : jQuery.ajax option - https://api.jquery.com/jQuery.Ajax/
- * eg : {cache:false}
- *
- */
- $.imxGetScript = function (url, options) {
- // Allow user to set any option except for dataType, cache, and url
- options = $.extend(options || { dataType: "script", cache: true }, {
- url: url
- });
- // Use $.ajax() since it is more flexible than $.getScript
- // Return the jqXHR object so we can chain callbacks
- return jQuery.ajax(options);
- };
- /**
- *
- * loadFileOnce - do as $.getScript but manages to load the file only once
- * url : url to the file to load
- * options : jQuery.ajax option - https://api.jquery.com/jQuery.Ajax/
- * eg : {cache:false}
- *
- */
- $.loadFileOnce = (function () {
- let loadedFiles = {};
- let func = function (aUrlFile, options) {
- if (!loadedFiles[aUrlFile])
- loadedFiles[aUrlFile] = $.imxGetScript(aUrlFile, options);
- return loadedFiles[aUrlFile];
- };
- return func;
- })();
- /**
- * show a Loader
- * @param aLoader@type {String} loader name
- * loader available:
- * - 'gooey'
- * - 'sasha'
- */
- var imxLoaderDisplayCalls = 0;
- $.imxLoaderDisplay = function (aLoader) {
- imxLoaderDisplayCalls++;
- $("#waitLoader").addClass('show' + aLoader);
- $("#waitLoader").addClass("display");
- };
- /**
- * hide the wait loader
- */
- $.imxLoaderHide = function (forceReset) {
- imxLoaderDisplayCalls--;
- if (forceReset == null) forceReset = false;// set to false if forceReset is undefined or null
- if (!forceReset && imxLoaderDisplayCalls > 0) return;
- else imxLoaderDisplayCalls = 0; //if for whatever reason imxLoaderDisplayCalls < 0,set it to 0
- $("#waitLoader").removeClass();
- $("#waitLoader").addClass("loader");
- };
- /*** FAVORIS Management ***/
- function addFavoris(idFormation) {
- $.ajax({
- type: 'POST',
- url: '//' + window.location.host + '/assets/templates/php/addFavoris.php',
- data: 'idFormation=' + idFormation,
- success: function (data) {
- if (data == 1) {
- alert("La fiche a bien été ajoutée à vos favoris.");
- }
- else if (data == 2) {
- alert("La fiche existe déjà dans vos favoris.");
- }
- else {
- alert("Erreur lors de l'ajout de votre fiche dans les favoris.");
- }
- }
- });
- };
- /**
- * removeClassRegex - remove every classes of jQuery (dom) element(s) whose class names match with 'regex'
- * @param {*} regex
- * @returns jQuery element(s)
- * @example $('#hello').removeClassRegex(/^color-/)
- */
- $.fn.removeClassRegex = function (regex) {
- return $(this).removeClass(function (index, classes) {
- return classes.split(/\s+/).filter(function (c) {
- return regex.test(c);
- }).join(' ');
- });
- };
- /**
- * removeClassStartingWith - remove every classes of jQuery (dom) element(s) whose class names start with 'filter'
- * @param string filter - a class name start
- * @returns jQuery object
- * @example $('#hello').removeClassStartingWith('color-')
- */
- $.fn.removeClassStartingWith = function removeClassStartingWith_custom(filter) {
- $(this).removeClass(function (index, className) {
- return (className.match(new RegExp("\\S*" + filter + "\\S*", 'g')) || []).join(' ')
- });
- return this;
- };
- /**
- * jQuery alterClass plugin
- *
- * Remove element classes with wildcard matching. Optionally add classes:
- * $( '#foo' ).alterClass( 'foo-* bar-*', 'foobar' )
- *
- * Copyright (c) 2011 Pete Boere (the-echoplex.net)
- * Free under terms of the MIT license: http://www.opensource.org/licenses/mit-license.php
- *
- */
- $.fn.alterClass = function (removals, additions) {
- var self = this;
- if (removals.indexOf('*') === -1) {
- // Use native jQuery methods if there is no wildcard matching
- self.removeClass(removals);
- return !additions ? self : self.addClass(additions);
- }
- var patt = new RegExp('\\s' +
- removals.
- replace(/\*/g, '[A-Za-z0-9-_]+').
- split(' ').
- join('\\s|\\s') +
- '\\s', 'g');
- self.each(function (i, it) {
- var cn = ' ' + it.className + ' ';
- while (patt.test(cn)) {
- cn = cn.replace(patt, ' ');
- }
- it.className = $.trim(cn);
- });
- return !additions ? self : self.addClass(additions);
- };
- /**
- * proxies jQuery functions to emit events on show, hide, and remove events.
- *
- * https://github.com/hypesystem/showandtell.js
- * Copyright (c) 2017 Niels Abildgaard
- * Currently supported hides: hide, fadeOut, slideUp, remove, toggle, fadeToggle, slideToggle,
- * css (display), animate (height: hide, opacity: hide).
- *
- * Examples:
- * $("#myElement").on("showandtell.hide", function() {
- * alert("hide triggered");
- * }
- * $("#myElement").hide(); //Hides element, then triggers hide event
- *
- * Events:
- *
- * "showandtell.hide" on $().hide()
- * "showandtell.remove" on $().remove()
- * "showandtell.show" on $().show()
- * "showandtell.cssHide" on $().css('display:xxx') where xxx != "none"
- * "showandtell.cssShow" on $().css('display:none')
- *
- * Remarks Intersel:
- * - add functions Show() and Hide() called everytime events occur
- */
- (function ($) {
- // For any element that is shown or hidden, do these actions
- // fix chrome pb when a required input is hidden, chrome do not want to validate the form
- // so we remove "required" property on the hidden input, then reset it when shown again
- function Show() {
- // debugger;
- let requiredInput = $(this).find(":input[data-wasrequired=1]");
- requiredInput.prop("required", "required");
- };
- function Hide() {
- // debugger;
- let requiredInput = $(this).find(":input[required]");
- requiredInput.attr("data-wasrequired", "1");
- requiredInput.removeAttr("required");
- };
- function applyIfExistsOrNull(fun, self, args) {
- return typeof fun !== "undefined" ? fun.apply(self, args) : null;
- }
- function proxy$Functions(functionProxies) {
- $.each(functionProxies, function (old_function_name, proxy_settings) {
- var old_function = $.fn[old_function_name];
- $.fn[old_function_name] = function () {
- var pre_result = applyIfExistsOrNull(proxy_settings.pre, this, arguments);
- var result = old_function.apply(this, arguments);
- var postArguments = [result, pre_result, arguments];
- applyIfExistsOrNull(proxy_settings.post, this, postArguments);
- return result;
- }
- });
- }
- function checkIfElementWasHidden() {
- return $(this).map(function () { return $(this).is(":hidden"); });
- }
- //Only register if not already registered
- if (!$.showandtell) {
- //Indicate that showandtell has been registered.
- $.showandtell = true;
- proxy$Functions({
- hide: {
- pre: checkIfElementWasHidden,
- post: function (result, elementWasHidden, old_args) {
- $(this)
- .filter(function (idx) { return !elementWasHidden[idx]; })
- .each(function () {
- $(this).triggerHandler("showandtell.hide");
- Hide.apply(this);
- });
- }
- },
- show: {
- pre: checkIfElementWasHidden,
- post: function (result, elementWasHidden, old_args) {
- $(this)
- .filter(function (idx) { return elementWasHidden[idx]; })
- .each(function () {
- $(this).triggerHandler("showandtell.show");
- Show.apply(this);
- });
- }
- },
- remove: {
- //Remove has to trigger event before removing. After removal, there is no element to
- // trigger the event on.
- pre: function () {
- $(this)
- .each(function () {
- $(this).triggerHandler("showandtell.remove");
- Hide.apply(this);
- });
- }
- },
- css: {
- pre: checkIfElementWasHidden,
- post: function (result, elementWasHidden, old_args) {
- $(this)
- .filter(function (idx) {
- return !elementWasHidden[idx] && old_args[0] == "display" && old_args[1] == "none";
- }).each(function () {
- $(this).triggerHandler("showandtell.cssHide");
- Hide.apply(this);
- });
- $(this)
- .filter(function (idx) {
- return elementWasHidden[idx] && old_args[0] == "display" && old_args[1] != "none";
- }).each(function () {
- $(this).triggerHandler("showandtell.cssShow");
- Show.apply(this);
- });
- }
- }
- });
- }
- })(jQuery);
|