MediaWiki:Common.js: Difference between revisions

From Wiki PeiP systèmes embarqués
Jump to navigation Jump to search
No edit summary
No edit summary
 
(59 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


var mousestate = 0;
const animdelay = 20;
const animdelta = 1;
const LEDx = 52;
const LEDy = 200;
const LEDs = 15;


function cursormousedown(){ mousestate = 1; }
var ledtimer = null;


function cursormouseup(){ mousestate = 0; }
function flashtimer(){
  var led = document.getElementById('demoLED');
  if ( led.style.opacity == 1 ) led.style.opacity = 0;
  else led.style.opacity = 1;
  }


function cursormove(e){
function launchflash(){
   var slider = document.getElementById('demoslider');
   var uart = document.getElementById('demoUART');
   var bounds = slider.getBoundingClientRect();
   var val = parseInt(uart.innerHTML);
  var x = e.clientX - bounds.left;
   if ( ledtimer != null ){
   if (e.button==0) {
    clearInterval(ledtimer);
     var cursor = document.getElementById('democursor');
     var led = document.getElementById('demoLED');
     cursor.style.left = x;
     led.style.opacity = 0;
console.log(x);
     }
     }
  if ( val > 0 ) ledtimer = setInterval(flashtimer,4*val);
   }
   }


function demoslider(){
function uartanim(){
   var slider = document.getElementById('demoslider');
   var uart = document.getElementById('demoUART');
   if(slider != null){
  var arrow = document.getElementById('arrowUART');
     slider.onmousemove = cursormove;
  var max = arrow.offsetWidth - uart.offsetWidth;
     slider.onmousedown = cursormousedown;
  var cur = parseInt(uart.style.left,10);
     slider.onmouseup = cursormouseup;
   if ( cur < max ) {
     cur += animdelta;
    uart.style.left = cur + 'px';
     setTimeout(uartanim,animdelay);
    }
  else {
    uart.style.left = '0px';
     uart.style.display = 'none';
    launchflash();
     }
     }
   }
   }
Line 29: Line 45:
function httpanim(){
function httpanim(){
   var http = document.getElementById('demoHTTP');
   var http = document.getElementById('demoHTTP');
   http.innerHTML = 'POST';
   var arrow = document.getElementById('arrowHTTP');
  http.style.top = 0;
   var max = arrow.offsetWidth - http.offsetWidth;
  http.style.left = 0;
   var cur = parseInt(http.style.left,10);
  http.style.display = 'flex';
   var max = document.getElementById('demoHTTP').offsetWidth;
   var cur = document.getElementById('demoHTTP').style.top;
   if ( cur < max ) {
   if ( cur < max ) {
     http.style.top = cur + 10;
    cur += animdelta;
     setTimeout(httpanim,200);
     http.style.left = cur + 'px';
     setTimeout(httpanim,animdelay);
     }
     }
   else {
   else {
     http.style.top = 0;
     http.style.left = '0px';
     http.style.display = 'none';
     http.style.display = 'none';
    var uart = document.getElementById('demoUART');
    uart.style.display = 'flex';
    uartanim();
     }
     }
}
  }


function initanim(val){
function initanim(val){
   var http = document.getElementById('demoHTTP');
   var http = document.getElementById('demoHTTP');
   var uart = document.getElementById('demoUART');
   var uart = document.getElementById('demoUART');
   http.style.top = 0;
  var led = document.getElementById('demoLED');
   http.style.left = 0;
   http.style.top = '0px';
   http.style.left = '0px';
   http.innerHTML = 'POST';
   http.innerHTML = 'POST';
   http.style.display = 'flex';
   http.style.display = 'flex';
   uart.style.top = 0;
   uart.style.top = '0px';
   uart.style.left = 0;
   uart.style.left = '0px';
   uart.innerHTML = val;
   uart.innerHTML = val;
   httpanim();
   led.style.top = LEDy + 'px';
  led.style.left = LEDx + 'px';
  led.style.width = LEDs + 'px';
  led.style.height = LEDs + 'px';
  led.style.backgroundColor = 'red';
  led.style.opacity = 0;
  led.style.display = 'flex';
  setTimeout(httpanim,animdelay);
  }
 
function launchanim(){
  var cursor = document.getElementById('democursor');
  var x = parseInt(cursor.style.left,10);
  if ( isNaN(x) ) x = 0;
  initanim(2*x);
  }
 
function cursormove(e){
  var slider = document.getElementById('demoslider');
  var cursor = document.getElementById('democursor');
  var bounds = slider.getBoundingClientRect();
  var x = e.pageX - bounds.left;
  var max = bounds.width - cursor.offsetWidth;
  if ( x > max ) x = max;
  if ( x < 0 ) x = 0;
  if (e.buttons != 0) {
    cursor.style.left = Math.floor(x)+'px';
    }
  }
 
function demoslider(){
  var slider = document.getElementById('demoslider');
  if(slider != null){
    slider.onmousemove = cursormove;
    document.body.onmouseup = launchanim;
    }
   }
   }


demoslider();
demoslider();

Latest revision as of 10:20, 7 July 2023

/* Any JavaScript here will be loaded for all users on every page load. */

const animdelay = 20;
const animdelta = 1;
const LEDx = 52;
const LEDy = 200;
const LEDs = 15;

var ledtimer = null;

function flashtimer(){
  var led = document.getElementById('demoLED');
  if ( led.style.opacity == 1 ) led.style.opacity = 0;
  else led.style.opacity = 1;
  }

function launchflash(){
  var uart = document.getElementById('demoUART');
  var val = parseInt(uart.innerHTML);
  if ( ledtimer != null ){
    clearInterval(ledtimer);
    var led = document.getElementById('demoLED');
    led.style.opacity = 0;
    }
  if ( val > 0 ) ledtimer = setInterval(flashtimer,4*val);
  }

function uartanim(){
  var uart = document.getElementById('demoUART');
  var arrow = document.getElementById('arrowUART');
  var max =	arrow.offsetWidth - uart.offsetWidth;
  var cur =	parseInt(uart.style.left,10);
  if ( cur < max ) {
    cur += animdelta;
    uart.style.left = cur + 'px';
    setTimeout(uartanim,animdelay);
    }
  else {
    uart.style.left = '0px';
    uart.style.display = 'none';
    launchflash();
    }
  }

function httpanim(){
  var http = document.getElementById('demoHTTP');
  var arrow = document.getElementById('arrowHTTP');
  var max =	arrow.offsetWidth - http.offsetWidth;
  var cur =	parseInt(http.style.left,10);
  if ( cur < max ) {
    cur += animdelta;
    http.style.left = cur + 'px';
    setTimeout(httpanim,animdelay);
    }
  else {
    http.style.left = '0px';
    http.style.display = 'none';
    var uart = document.getElementById('demoUART');
    uart.style.display = 'flex';
    uartanim();
    }
  }

function initanim(val){
  var http = document.getElementById('demoHTTP');
  var uart = document.getElementById('demoUART');
  var led = document.getElementById('demoLED');
  http.style.top = '0px';
  http.style.left = '0px';
  http.innerHTML = 'POST';
  http.style.display = 'flex';
  uart.style.top = '0px';
  uart.style.left = '0px';
  uart.innerHTML = val;
  led.style.top = LEDy + 'px';
  led.style.left = LEDx + 'px';
  led.style.width = LEDs + 'px';
  led.style.height = LEDs + 'px';
  led.style.backgroundColor = 'red';
  led.style.opacity = 0;
  led.style.display = 'flex';
  setTimeout(httpanim,animdelay);
  }

function launchanim(){
  var cursor = document.getElementById('democursor');
  var x = parseInt(cursor.style.left,10);
  if ( isNaN(x) ) x = 0;
  initanim(2*x);
  }

function cursormove(e){
  var slider = document.getElementById('demoslider');
  var cursor = document.getElementById('democursor');
  var bounds = slider.getBoundingClientRect();
  var x = e.pageX - bounds.left;
  var max = bounds.width - cursor.offsetWidth;
  if ( x > max ) x = max;
  if ( x < 0 ) x = 0;
  if (e.buttons != 0) {
    cursor.style.left = Math.floor(x)+'px';
    }
  }

function demoslider(){
  var slider = document.getElementById('demoslider');
  if(slider != null){
    slider.onmousemove = cursormove;
    document.body.onmouseup = launchanim;
    }
  }

demoslider();