<commit_before>/* 17apr14abu
 * (c) Software Lab. <NAME>
 */

function csMouseDn(cvs, event) {
   var r = cvs.getBoundingClientRect();

   cvs.csDn = true;
   cvs.csDnX = event.clientX - r.left;
   cvs.csDnY = event.clientY - r.top;
   cvs.csMv = false;
   return false;
}

function csMouseMv(cvs, event) {
   var r = cvs.getBoundingClientRect();

   if (cvs.curs)
      csCursor(cvs, event.clientX - r.left, event.clientY - r.top);
   if (!cvs.csDn)
      return true;
   if (drawCanvas(cvs.id, -1, cvs.csMv? -1 : 0, cvs.csDnX, cvs.csDnY,
         event.clientX - r.left, event.clientY - r.top ) )
      return true;
   cvs.csMv = true;
   return false;
}

function csMouseOut(cvs) {
   cvs.style.cursor = "";
   cvs.csDn = cvs.csMv = false;
   if (cvs.clicked) {
      clearTimeout(cvs.clicked);
      cvs.clicked = false;
   }
   return drawCanvas(cvs.id, -1);
}

function csMouseUp(cvs) {
   cvs.csDn = false;
   if (cvs.clicked) {
      clearTimeout(cvs.clicked);
      cvs.clicked = false;
      return drawCanvas(cvs.id, -1, 2, cvs.csDnX, cvs.csDnY);
   }
   if (cvs.csMv)
      return drawCanvas(cvs.id, -1);
   cvs.clicked = setTimeout(
      function() {
         cvs.clicked = false;
         drawCanvas(cvs.id, -1, 1, cvs.csDnX, cvs.csDnY);
      },
      200 );
   return false;
}

function drawCanvas(id, dly) {
   var req = new XMLHttpRequest();
   var url = document.getElementsByTagName("BASE")[0].href + SesId + "!jsDraw?" + id + "&+" + dly;
   var len = arguments.length;

   for (var i = 2; i < len; ++i)
      if (typeof arguments[i] === "number")
         url += "&+" + arguments[i];
      else
         url += "&" + arguments[i];
   try {req.open("POST", url);}
   catch (e) {return true;}
   req.responseType = "arraybuffer";
   req.onload = function() {
      var ele = document.getElementById(id);

      renderCanvas(ele, plio(new Uint8Array(req.response)));
      if (ele.post) {
         ele.post = false;
         while (ele = ele.parentNode) {
            if (ele.tagName == "FORM") {
               post(ele, false, null, null);
               break;
            }
         }
      }
      // if (dly == 0)
      //    requestAnimationFrame(function() {drawCanvas(id, dly)});
      // else if (dly > 0)
      //    setTimeout(function() {drawCanvas(id, dly)}, dly);
      if (dly >= 0)
         setTimeout(function() {drawCanvas(id, dly)}, dly);
   }
   try {req.send(null);}
   catch (e) {
      req.abort();
      return true;
   }
   return false;
}<commit_msg>Use requestAnimationFrame()<commit_after>/* 19apr14abu
 * (c) Software Lab. <NAME>
 */

function csMouseDn(cvs, event) {
   var r = cvs.getBoundingClientRect();

   cvs.csDn = true;
   cvs.csDnX = event.clientX - r.left;
   cvs.csDnY = event.clientY - r.top;
   cvs.csMv = false;
   return false;
}

function csMouseMv(cvs, event) {
   var r = cvs.getBoundingClientRect();

   if (cvs.curs)
      csCursor(cvs, event.clientX - r.left, event.clientY - r.top);
   if (!cvs.csDn)
      return true;
   if (drawCanvas(cvs.id, -1, cvs.csMv? -1 : 0, cvs.csDnX, cvs.csDnY,
         event.clientX - r.left, event.clientY - r.top ) )
      return true;
   cvs.csMv = true;
   return false;
}

function csMouseOut(cvs) {
   cvs.style.cursor = "";
   cvs.csDn = cvs.csMv = false;
   if (cvs.clicked) {
      clearTimeout(cvs.clicked);
      cvs.clicked = false;
   }
   return drawCanvas(cvs.id, -1);
}

function csMouseUp(cvs) {
   cvs.csDn = false;
   if (cvs.clicked) {
      clearTimeout(cvs.clicked);
      cvs.clicked = false;
      return drawCanvas(cvs.id, -1, 2, cvs.csDnX, cvs.csDnY);
   }
   if (cvs.csMv)
      return drawCanvas(cvs.id, -1);
   cvs.clicked = setTimeout(
      function() {
         cvs.clicked = false;
         drawCanvas(cvs.id, -1, 1, cvs.csDnX, cvs.csDnY);
      },
      200 );
   return false;
}

function drawCanvas(id, dly) {
   var req = new XMLHttpRequest();
   var url = document.getElementsByTagName("BASE")[0].href + SesId + "!jsDraw?" + id + "&+" + dly;
   var len = arguments.length;

   for (var i = 2; i < len; ++i)
      if (typeof arguments[i] === "number")
         url += "&+" + arguments[i];
      else
         url += "&" + arguments[i];
   try {req.open("POST", url);}
   catch (e) {return true;}
   req.responseType = "arraybuffer";
   req.onload = function() {
      var ele = document.getElementById(id);

      renderCanvas(ele, plio(new Uint8Array(req.response)));
      if (ele.post) {
         ele.post = false;
         while (ele = ele.parentNode) {
            if (ele.tagName == "FORM") {
               post(ele, false, null, null);
               break;
            }
         }
      }
      if (dly == 0)
         requestAnimationFrame(function() {drawCanvas(id, 0)});
      else if (dly > 0)
         setTimeout(function() {drawCanvas(id, dly)}, dly);
   }
   try {req.send(null);}
   catch (e) {
      req.abort();
      return true;
   }
   return false;
}
{'fraction_non_alphanumeric': 0.16021986970684038, 'fraction_numerical': 0.008957654723127036, 'mean_word_length': 2.2216393442622953, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1621541', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1898, 'n_words': 396}