wok diff wikiss/stuff/plugins/wkp_Calc.php @ rev 25419
Up bzip3 (1.1.4)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Aug 06 11:13:43 2022 +0000 (2022-08-06) |
parents | 136be2b3c085 |
children |
line diff
1.1 --- a/wikiss/stuff/plugins/wkp_Calc.php Thu Nov 28 19:25:13 2013 +0000 1.2 +++ b/wikiss/stuff/plugins/wkp_Calc.php Sat Aug 06 11:13:43 2022 +0000 1.3 @@ -61,6 +61,24 @@ 1.4 alert(data); 1.5 } 1.6 1.7 +function cnt(from,to) { 1.8 + return (to.charCodeAt(0) - from.charCodeAt(0) + 1) * 1.9 + (parseInt(to.substring(1)) - parseInt(from.substring(1)) + 1) 1.10 +} 1.11 + 1.12 +function zone(id,from,to,init,func) { 1.13 + var result=init 1.14 + for (var l=from.charCodeAt(0);;l++) { 1.15 + for (var n=parseInt(from.substring(1)); 1.16 + n <= parseInt(to.substring(1));n++) { 1.17 + var e=document.getElementById(id+String.fromCharCode(l)+n) 1.18 + result=func(result,parseFloat(e.value)) 1.19 + } 1.20 + if (l == to.charCodeAt(0)) break 1.21 + } 1.22 + return result; 1.23 +} 1.24 + 1.25 var DATA={}; 1.26 function buildCalc(id, rows, cols) { 1.27 DATA[id] = {}; 1.28 @@ -77,6 +95,13 @@ 1.29 function(n){var x=1;while(n>1)x*=n--;return x;}; 1.30 DATA[id].fib = DATA[id].FIB = 1.31 function(n){var c=0,p=1;while(n-->0){var x=c;c+=p;p=x};return c;}; 1.32 + DATA[id].sum = DATA[id].SUM = 1.33 + function(a,b){return zone(id,a,b,0,function(a,b){return a+b});}; 1.34 + DATA[id].min = DATA[id].MIN = 1.35 + function(a,b){return zone(id,a,b,Number.MAX_VALUE,Math.min);}; 1.36 + DATA[id].max = DATA[id].MAX = 1.37 + function(a,b){return zone(id,a,b,Number.MIN_VALUE,Math.max);}; 1.38 + DATA[id].cnt = DATA[id].CNT = cnt 1.39 for (var i=0; i<=rows; i++) { 1.40 var row = document.getElementById(id).insertRow(-1); 1.41 for (var j=0; j<=cols && j<=26; j++) { 1.42 @@ -99,7 +124,7 @@ 1.43 function getWidth(s) 1.44 { 1.45 var e = document.getElementById("widthcalc"); 1.46 - e.innerHTML = s+" :"; 1.47 + e.innerHTML = s; 1.48 return (e.offsetWidth < 80 || s.charAt(0) == "=") ? 80 : e.offsetWidth; 1.49 } 1.50 1.51 @@ -145,7 +170,7 @@ 1.52 var value = elm.title || ""; 1.53 if (value.charAt(0) == "=") 1.54 with (DATA[calcid]) return eval(value.substring(1)); 1.55 - else return isNaN(parseFloat(value)) ? value : parseFloat(value); 1.56 + else return (value == "" || isNaN(value)) ? value : parseFloat(value); 1.57 }; 1.58 Object.defineProperty(DATA[calcid], cellid, {get:getter}); 1.59 Object.defineProperty(DATA[calcid], cellid.toLowerCase(), {get:getter});