var alertNbLines = true; function treatFlagKey(flag) { if (flag.values !== undefined) { if (flag.separator) { for (var i = flag.values.length - 1; i >= 0; i--) { if (flag.nb_lines && (flag.values[i] == undefined || !flag.values[i].length)) { if (alertNbLines) { alertNbLines = false; if (!confirm("Lorsque plusieurs flags sont attendus pour une même question, ceux-ci ne sont pas validés un par un. Ils ne sont validés qu'une fois tous les champs remplis correctement. (Sauf mention contraire, l'ordre n'importe pas)")) console.log(flag.values[9999].length); // Launch exception here to avoid form validation } } else if (!flag.values[i].length) { flag.values.splice(i, 1); } } if (flag.ignore_order) flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator; else flag.value = flag.values.join(flag.separator) + flag.separator; if (flag.values.length == 0) flag.values = [""]; } else flag.value = flag.values[0]; } if (flag.found == null && flag.soluce !== undefined) { if (flag.value && flag.soluce) { if (flag.ignore_case) flag.value = flag.value.toLowerCase(); if (flag.capture_regexp) { var re = new RegExp(flag.capture_regexp, flag.ignore_case?'ui':'u'); var match = re.exec(flag.value); match.shift(); flag.value = match.join("+"); } if (flag.soluce == b2sum(flag.value)) flag.found = new Date(); } } return flag.found !== undefined && flag.found !== false; } String.prototype.capitalize = function() { return this .toLowerCase() .replace( /(^|\s|-)([a-z])/g, function(m,p1,p2) { return p1+p2.toUpperCase(); } ); } Array.prototype.inArray = function(v) { return this.reduce(function(presence, current) { return presence || current == v; }, false); } angular.module("FICApp") .directive('autofocus', ['$timeout', function($timeout) { return { restrict: 'A', link : function($scope, $element) { $timeout(function() { $element[0].focus(); }); } } }]) .directive('autocarousel', ['$timeout', function($timeout) { return { restrict: 'A', link : function($scope, $element) { $timeout(function() { $($element[0]).carousel(); }); } } }]); angular.module("FICApp") .filter("escapeURL", function() { return function(input) { return encodeURIComponent(input); } }) .filter("stripHTML", function() { return function(input) { if (!input) return input; return input.replace( /(<([^>]+)>)/ig, "" ); } }) .filter("capitalize", function() { return function(input) { return input.capitalize(); } }) .filter("rankTitle", function() { var itms = { "rank": "Rang", "name": "Équipe", "score": "Score", }; return function(input) { if (itms[input] != undefined) { return itms[input]; } else { return input; } } }) .filter("time", function() { return function(input) { input = Math.floor(input); if (input == undefined) { return "--"; } else if (input >= 10) { return input; } else { return "0" + input; } } }) .filter("timer", function() { return function(input) { input = Math.floor(input / 1000); var res = "" if (input >= 3600) { res += Math.floor(input / 3600) + ":"; input = input % 3600; } if (res || input >= 60) { if (res && Math.floor(input / 60) <= 9) res += "0"; res += Math.floor(input / 60) + "'"; input = input % 60; } return res + (input>9?input:"0"+input) + '"'; } }) .filter("since", function() { return function(passed) { if (passed < 120000) { return "Il y a " + Math.floor(passed/1000) + " secondes"; } else { return "Il y a " + Math.floor(passed/60000) + " minutes"; } } }) .filter("size", function() { var units = [ "o", "kio", "Mio", "Gio", "Tio", "Pio", "Eio", "Zio", "Yio", ] return function(input) { var res = input; var unit = 0; while (res > 1024) { unit += 1; res = res / 1024; } return (Math.round(res * 100) / 100) + " " + units[unit]; } }) .filter("coeff", function() { return function(input) { if (input > 1) { return "+" + Math.floor((input - 1) * 100) + " %" } else if (input < 1) { return "-" + Math.floor((1 - input) * 100) + " %" } else { return ""; } } }) .filter("objectLength", function() { return function(input) { if (input !== undefined) return Object.keys(input).length; else return ""; } }) .filter("bto16", function() { return function(input) { const raw = atob(input); let result = ''; for (let i = 0; i < raw.length; i++) { const hex = raw.charCodeAt(i).toString(16); result += (hex.length === 2 ? hex : '0' + hex); } return result; } }); angular.module("FICApp") .component('flagKey', { bindings: { kid: '=', key: '=', settings: '=', wantchoices: '=', }, controller: function() { this.additem = function(key) { this.key.values.push(""); }; }, template: `