wok rev 17794

wikiss: update wkp_Calc from tazwikiss
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Mar 17 18:44:10 2015 +0100 (2015-03-17)
parents 73858bb3d112
children d11fd3e3b9d3
files wikiss/stuff/plugins/wkp_Calc.css wikiss/stuff/plugins/wkp_Calc.php
line diff
     1.1 --- a/wikiss/stuff/plugins/wkp_Calc.css	Mon Mar 16 13:06:40 2015 +0100
     1.2 +++ b/wikiss/stuff/plugins/wkp_Calc.css	Tue Mar 17 18:44:10 2015 +0100
     1.3 @@ -9,7 +9,7 @@
     1.4  .inputcalc {
     1.5      border: none;
     1.6      width: 80px;
     1.7 -    font-size: 14px;
     1.8 +    font-size: inherit;
     1.9      padding: 2px;
    1.10  }
    1.11  
    1.12 @@ -28,4 +28,5 @@
    1.13  .cellcalc {
    1.14      border: 1px solid #999;
    1.15      padding: 0;
    1.16 +    font-size: 14px;
    1.17  }
     2.1 --- a/wikiss/stuff/plugins/wkp_Calc.php	Mon Mar 16 13:06:40 2015 +0100
     2.2 +++ b/wikiss/stuff/plugins/wkp_Calc.php	Tue Mar 17 18:44:10 2015 +0100
     2.3 @@ -61,6 +61,24 @@
     2.4      alert(data);
     2.5  }
     2.6  
     2.7 +function cnt(from,to) {
     2.8 +    return (to.charCodeAt(0) - from.charCodeAt(0) + 1) *
     2.9 +           (parseInt(to.substring(1)) - parseInt(from.substring(1)) + 1)
    2.10 +}
    2.11 +
    2.12 +function zone(id,from,to,init,func) {
    2.13 +    var result=init
    2.14 +    for (var l=from.charCodeAt(0);;l++) {
    2.15 +        for (var n=parseInt(from.substring(1));
    2.16 +        	 n <= parseInt(to.substring(1));n++) {
    2.17 +            var e=document.getElementById(id+String.fromCharCode(l)+n)
    2.18 +            result=func(result,parseFloat(e.value))
    2.19 +        }
    2.20 +        if (l == to.charCodeAt(0)) break
    2.21 +    }
    2.22 +    return result;
    2.23 +}
    2.24 +
    2.25  var DATA={};
    2.26  function buildCalc(id, rows, cols) {
    2.27      DATA[id] = {};
    2.28 @@ -77,6 +95,13 @@
    2.29  	function(n){var x=1;while(n>1)x*=n--;return x;};
    2.30      DATA[id].fib  = DATA[id].FIB  = 
    2.31  	function(n){var c=0,p=1;while(n-->0){var x=c;c+=p;p=x};return c;};
    2.32 +    DATA[id].sum  = DATA[id].SUM  =
    2.33 +	function(a,b){return zone(id,a,b,0,function(a,b){return a+b});};
    2.34 +    DATA[id].min  = DATA[id].MIN  =
    2.35 +	function(a,b){return zone(id,a,b,Number.MAX_VALUE,Math.min);};
    2.36 +    DATA[id].max  = DATA[id].MAX  =
    2.37 +	function(a,b){return zone(id,a,b,Number.MIN_VALUE,Math.max);};
    2.38 +    DATA[id].cnt  = DATA[id].CNT  = cnt
    2.39      for (var i=0; i<=rows; i++) {
    2.40          var row = document.getElementById(id).insertRow(-1);
    2.41          for (var j=0; j<=cols && j<=26; j++) {
    2.42 @@ -99,7 +124,7 @@
    2.43  function getWidth(s)
    2.44  {
    2.45  	var e = document.getElementById("widthcalc");
    2.46 -	e.innerHTML = s+" :";
    2.47 +	e.innerHTML = s;
    2.48  	return (e.offsetWidth < 80 || s.charAt(0) == "=") ? 80 : e.offsetWidth;
    2.49  }
    2.50  
    2.51 @@ -145,7 +170,7 @@
    2.52          var value = elm.title || "";
    2.53          if (value.charAt(0) == "=")
    2.54  		with (DATA[calcid]) return eval(value.substring(1));
    2.55 -        else return isNaN(parseFloat(value)) ? value : parseFloat(value);
    2.56 +        else return (value == "" || isNaN(value)) ? value : parseFloat(value);
    2.57      };
    2.58      Object.defineProperty(DATA[calcid], cellid, {get:getter});
    2.59      Object.defineProperty(DATA[calcid], cellid.toLowerCase(), {get:getter});