1// ------------------------------------------------------------------------------------------------------------------------------- 2// Fonction reproduisant le var_dump de PHP pour un variable javascript 3function dump(arr, level) 4{ 5 var dumped_text = ""; 6 if( !level ) 7 level = 0; 8 9 //The padding given at the beginning of the line. 10 var level_padding = ""; 11 for( var j=0; j<level+1; j++) 12 level_padding += " "; 13 14 if( typeof(arr) == 'object' ) 15 { 16 //Array/Hashes/Objects 17 for(var item in arr) 18 { 19 var value = arr[item]; 20 if(typeof(value) == 'object') 21 { 22 //If it is an array, 23 dumped_text += level_padding + "'" + item + "' ...\n"; 24 dumped_text += dump(value,level+1); 25 } 26 else 27 { 28 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; 29 } 30 } 31 } 32 else 33 { 34 //Stings/Chars/Numbers etc. 35 dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; 36 } 37 return dumped_text; 38} 39 40// ------------------------------------------------------------------------------------------------------------------ 41// Affiche dans la console le contenu d'un tableau 42function n_print( tableau, nomTableau) 43{ 44 // console.clear(); 45 console.log('==================== ' + nomTableau); 46 console.dir(tableau); 47 jQuery.each(tableau, function(index, val) { 48 console.log(nomTableau + ' : ' + index + ' => ' + val); 49 }); 50} 51 52// ------------------------------------------------------------------------------------------------------------------------------- 53// Genere un tableau serialiser pour etre unserialize par du PHP 54function serialize(mixed_value) 55{ 56 // discuss at: http://phpjs.org/functions/serialize/ 57 // original by: Arpad Ray (mailto:[email protected]) 58 // improved by: Dino 59 // improved by: Le Torbi (http://www.letorbi.de/) 60 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) 61 // bugfixed by: Andrej Pavlovic 62 // bugfixed by: Garagoth 63 // bugfixed by: Russell Walker (http://www.nbill.co.uk/) 64 // bugfixed by: Jamie Beck (http://www.terabit.ca/) 65 // bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) 66 // bugfixed by: Ben (http://benblume.co.uk/) 67 // input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html) 68 // input by: Martin (http://www.erlenwiese.de/) 69 // note: We feel the main purpose of this function should be to ease the transport of data between php & js 70 // note: Aiming for PHP-compatibility, we have to translate objects to arrays 71 // example 1: serialize(['Kevin', 'van', 'Zonneveld']); 72 // returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' 73 // example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}); 74 // returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}' 75 76 var val, key, okey, 77 ktype = '', 78 vals = '', 79 count = 0, 80 _utf8Size = function (str) { 81 var size = 0, 82 i = 0, 83 l = str.length, 84 code = ''; 85 for (i = 0; i < l; i++) 86 { 87 code = str.charCodeAt(i); 88 if (code < 0x0080) 89 { 90 size += 1; 91 } 92 else if (code < 0x0800) 93 { 94 size += 2; 95 } 96 else 97 { 98 size += 3; 99 } 100 } 101 return size; 102 }, 103 _getType = function (inp) { 104 var match, key, cons, types, type = typeof inp; 105 106 if (type === 'object' && !inp) 107 { 108 return 'null'; 109 } 110 111 if (type === 'object') { 112 if (!inp.constructor) 113 { 114 return 'object'; 115 } 116 cons = inp.constructor.toString(); 117 match = cons.match(/(\w+)\(/); 118 if (match) 119 { 120 cons = match[1].toLowerCase(); 121 } 122 types = ['boolean', 'number', 'string', 'array']; 123 for (key in types) 124 { 125 if (cons == types[key]) 126 { 127 type = types[key]; 128 break; 129 } 130 } 131 } 132 return type; 133 }, 134 type = _getType(mixed_value); 135 136 switch (type) 137 { 138 case 'function': 139 val = ''; 140 break; 141 case 'boolean': 142 val = 'b:' + (mixed_value ? '1' : '0'); 143 break; 144 case 'number': 145 val = (Math.round(mixed_value) == mixed_value ? 'i' : 'd') + ':' + mixed_value; 146 break; 147 case 'string': 148 val = 's:' + _utf8Size(mixed_value) + ':"' + mixed_value + '"'; 149 break; 150 case 'array': 151 case 'object': 152 val = 'a'; 153 /* 154 if (type === 'object') { 155 var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/); 156 if (objname == undefined) { 157 return; 158 } 159 objname[1] = this.serialize(objname[1]); 160 val = 'O' + objname[1].substring(1, objname[1].length - 1); 161 } 162 */ 163 164 for (key in mixed_value) 165 { 166 if (mixed_value.hasOwnProperty(key)) 167 { 168 ktype = _getType(mixed_value[key]); 169 if (ktype === 'function') 170 { 171 continue; 172 } 173 174 okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); 175 vals += this.serialize(okey) + this.serialize(mixed_value[key]); 176 count++; 177 } 178 } 179 val += ':' + count + ':{' + vals + '}'; 180 break; 181 case 'undefined': 182 // Fall-through 183 default: 184 // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP 185 val = 'N'; 186 break; 187 } 188 if (type !== 'object' && type !== 'array') 189 { 190 val += ';'; 191 } 192 return val; 193} 194 195// ------------------------------------------------------------------------------------------------------------------------------- 196// Fonction transformant une chaîne de caractère en slug 197// text : le texte à convertir 198 199function slug(text) 200{ 201 return text.toLowerCase().replace(/[èéêë]/g, 'e').replace(/[ç]/g, 'c').replace(/[à âä]/g, 'a').replace(/[ïî]/g, 'i').replace(/[ûùü]/g, 'u').replace(/[ôöó]/g, 'o').replace(/ /g,'').replace(/[^\w-]+/g,''); 202} 203 204// -------------------------------------------------------------------------------------------------------------------------------
205// Fonction convertissant un code hexadécimal en rgba 206 207function fHexaToRGBA(hex, opacity) 208{ 209 hex = hex.replace('#',''); 210 r = parseInt(hex.substring(0,2), 16); 211 g = parseInt(hex.substring(2,4), 16); 212 b = parseInt(hex.substring(4,6), 16); 213 214 result = 'rgba('+r+','+g+','+b+','+opacity+')'; 215 return result; 216} 217 218function fFontAwesomeToUnicode(name) 219{ 220 'use strict'; 221 222 // Create a holding element (they tend to use <i>, so let's do that) 223 var testI = document.createElement('i'); 224 // Create a realistic classname 225 // - maybe one day it will need both, so let's add them 226 testI.className = `fa ${name}`; 227 // We need to append it to the body for it to have 228 // its pseudo element created 229 document.body.appendChild(testI); 230 231 // Get the computed style 232 var char = window.getComputedStyle( 233 testI, ':before' // Add the ':before' to get the pseudo element 234 ).content.replace(/'|"/g, ''); // content wraps things in quotes 235 // which we don't want 236 // Remove the test element 237 testI.remove(); 238 239 240 var codeHex = char.charCodeAt(0).toString(16); 241 while (codeHex.length < 4) { 242 codeHex = "0" + codeHex; 243 } 244 245 return codeHex; 246} 247 248function fStripSlashes( str ) 249{ 250 return str.replace(/\\'/g,'\'').replace(/\"/g,'"').replace(/\\\\/g,'\\').replace(/\\0/g,'\0'); 251}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.