View difference between Paste ID: gA9N8ASN and ZrkayNpa
SHOW: | | - or go back to the newest paste.
1-
// Pour comprendre cette fonction, deux solutions : faire alert(dump(window)), ou aller voir la doc PHP de var_dump qui est à peu près pareille.
1+
2-
// Il ne faut pas appeler dump_r() directement, mais bien dump(). Seul le premier argument est obligatoire.
2+
3
	
4
	if(levelmax != 0 && level >= levelmax) return;
5
	
6
	var out = '';
7
	
8
	if(typeof(obj) == "object" || typeof(obj) == "array") {
9
		for (var i in obj) {
10
			for(var j=0; j<level; j++) {
11
				out += "	";
12
			}
13
			if(typeof(obj[i]) == "object" || typeof(obj[i]) == "array") {
14
				out += i + ": (" + typeof(obj[i]) + ")\n";
15
				out += dump_r(obj[i], levelmax, level+1) || '';
16
			}
17
			else {
18
				out += i + ": (" + typeof(obj[i]) +") " + obj[i] + "\n";
19
			}
20
		}
21
	}
22
	else {
23
		out += "(" + typeof(obj) + ") " + obj; 
24
	}
25
26
	return out;
27
}
28
29
function dump(obj, inalert, levelmax) {
30
	levelmax = levelmax || 3;
31
	level_max = levelmax;
32
	
33
	inalert = inalert || false;
34
	
35
	if(!inalert) {
36
		var pop = document.createElement('pre');
37
			pop.style.position = "fixed";
38
			pop.style.left = "0";
39-
			pop.style.position = "absolute";
39+
40
			pop.style.zIndex = "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999";
41
			pop.style.fontSize = "0.8em";
42
			pop.style.fontFamily = "Consolas";
43
			pop.style.width = (window.innerWidth - 10)+"px";
44
			pop.style.height = (window.innerHeight - 10)+"px";
45
			pop.style.overflow = "auto";
46
			pop.style.padding = "5px";
47
			pop.style.background = "white";
48
        	pop.style.color = "black";
49
			pop.style.margin = "0";
50
			pop.ondblclick = function() {
51
				document.body.removeChild(this);
52
			};
53
						
54
			pop.innerHTML = dump_r(obj, levelmax).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;") + '<p style="position:absolute; right:20px;top:0;position:fixed;">Double-cliquez pour fermer</p>';
55-
			pop.innerHTML = escapeHTML(dump_r(obj, levelmax)) + '<p style="position:absolute; right:20px;top:0;position:fixed;">Double-cliquez pour fermer</p>';
55+
56
			document.body.appendChild(pop);
57
	}
58
	else {
59
		alert(dump_r(obj, levelmax));
60
	}
61
}