Benutzer:J*/Labor/Archiv/Datumswähler.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt.)
 
Zeile 26: Zeile 26:
 
             var dx = x - s.left - 1 ;
 
             var dx = x - s.left - 1 ;
 
             var px = dx / ( s.case.offsetWidth - 2 );
 
             var px = dx / ( s.case.offsetWidth - 2 );
             s.info.innerHTML = dx + " -> " + px;
+
             var date = s.calcTime(px);
 +
            var dateInfo = "";
 +
            dateInfo += date.getDate() + ". ";
 +
            dateInfo += ["Jan.","Feb.","März","Apr.","Mai","Jun.","Jul.","Aug.","Sep.","Okt.","Nov.","Dez."][date.getMonth()] + " ";
 +
            dateInfo += date.getFullYear();
 +
            s.info.innerHTML = dateInfo;
 
             s.slider.style.left = (dx - 1 ) + "px";
 
             s.slider.style.left = (dx - 1 ) + "px";
 
             s.slider.style.display = "block";
 
             s.slider.style.display = "block";
 +
           
 
         }
 
         }
 
         else
 
         else
Zeile 35: Zeile 41:
 
             s.slider.style.display = "none";
 
             s.slider.style.display = "none";
 
         }
 
         }
 +
    },
 +
    calcTime: function (p) {
 +
        return new Date( ( (s.today - s.birth) * p + s.birth ) * 1000 );
 
     }
 
     }
 
}
 
}
  
 
s.init();
 
s.init();
window.onmousemove = s.move;
+
 
 +
function initSlider()
 +
{
 +
    window.onmousemove = s.move;
 +
 
 +
    s.birth = parseInt( $("t_birth").innerHTML );
 +
    s.today = parseInt( $("t_today").innerHTML );
 +
}
 +
 
 +
// später mit onLoadHook
 +
initSlider()

Version vom 20. März 2009, 14:25 Uhr

function getTotalOffset( element, offsetType, sum )
{
    if ( element.offsetParent != null )
        sum += getTotalOffset( element.offsetParent, offsetType, sum );
    return sum + element[offsetType];
}

Node.prototype.getTotalOffsetTop = function () { return getTotalOffset( this, "offsetTop", 0 ); };
Node.prototype.getTotalOffsetLeft = function () { return getTotalOffset( this, "offsetLeft", 0 ); };

var s = {
    init: function () {
        s.info = $("sliderinfo");
        s.case = $("slidercase");
        s.slider = $("slider");
        s.slider2 = $("slider2");
        s.top = s.case.getTotalOffsetTop();
        s.left = s.case.getTotalOffsetLeft();
    },
    move: function (e) {
        var x = document.all ? window.event.clientX : e.pageX;
        var y = document.all ? window.event.clientY : e.pageY;
        if ( x > s.left && x < s.left + s.case.offsetWidth &&
             y > s.top  && y < s.top  + s.case.offsetHeight )
        {
            var dx = x - s.left - 1 ;
            var px = dx / ( s.case.offsetWidth - 2 );
            var date = s.calcTime(px);
            var dateInfo = "";
            dateInfo += date.getDate() + ". ";
            dateInfo += ["Jan.","Feb.","März","Apr.","Mai","Jun.","Jul.","Aug.","Sep.","Okt.","Nov.","Dez."][date.getMonth()] + " ";
            dateInfo += date.getFullYear();
            s.info.innerHTML = dateInfo;
            s.slider.style.left = (dx - 1 ) + "px";
            s.slider.style.display = "block";
            
        }
        else
        {
            s.info.innerHTML = "Kein Datum ausgewählt.";
            s.slider.style.display = "none";
        }
    },
    calcTime: function (p) {
        return new Date( ( (s.today - s.birth) * p + s.birth ) * 1000 );
    }
}

s.init();

function initSlider()
{
    window.onmousemove = s.move;

    s.birth = parseInt( $("t_birth").innerHTML );
    s.today = parseInt( $("t_today").innerHTML );
}

// später mit onLoadHook
initSlider()