Source Code

for file /AJAXEngine/S05_JSB/wuerfel2.js


// Wuerfel2.js
// 2. version of the Javascript Behaviour for the dice sample control
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// ----- 
// 03.12.2006 created by Matthias Hertel
// 09.01.2007 simpler event handler implementation

var Wuerfel2Behaviour = {
  rolling: 0,
  count: 0,

  maxnumber: 6,

  onclick: function (evt) {
    this.rolling = 50;
    this.count = 0;
    this.rollNext();
  },

  rollNext: function () {
    var o = parseInt(this.innerText);
    // find a random number
    var n = Math.floor(Math.random() * (this.maxnumber - 1)) + 1;
    if (n == o)
      n = (n % this.maxnumber) + 1;
    this.innerText = n;

    this.rolling *= 1.2;
    this.count += 1;
    if (this.count < 10) {
      this.classList.add("rolling")
      window.setTimeout("document.getElementById('" + this.id + "').rollNext()", this.rolling);

    } else {
      this.classList.remove("rolling")
    }
  } // rollNext

}; // Wuerfel2Behaviour


This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.