<commit_before>function setTouchHandler(htmlImgElement, touchServerUrl) {
  setTimeout(function () {
    __prepareTouchServer(touchServerUrl, function/*on_ok*/() {
      htmlImgElement.touchServerUrl = touchServerUrl;
      if (!htmlImgElement.didInitEventHandler) {
        htmlImgElement.didInitEventHandler = true;
        __setTouchHandler(htmlImgElement);
      }
    }, 10/*retry times*/);
  }, 100);
}

function __prepareTouchServer(touchServerUrl, on_ok, retryCounter) {
  console.log('prepare touch server');
  $.ajax(touchServerUrl, {timeout: 10 * 1000})
      .done(function (result) {
        console.log('prepare touch server result: ' + result);
        if (result === 'OK') {
          on_ok();
        } else if (result === 'preparing' || result === 'device is not being live viewed') {
          if (retryCounter >= 2) {
            setTimeout(function () {
              __prepareTouchServer(touchServerUrl, on_ok, retryCounter - 1);
            }, 500);
          }
        }
      })
      .fail(function (jqXHR, textStatus) {
        console.log('prepare touch server error: ' + textStatus);
      });
}

function __setTouchHandler(htmlImgElement) {
  var $htmlImgElement = $(htmlImgElement);
  $htmlImgElement
      .on('mousedown', function (e) {
        saveOrSendMouseAction(e);
        $htmlImgElement.mousemove(function (e) {
          saveOrSendMouseAction(e);
        }).mouseout(function (e) {
              saveOrSendMouseAction(e);
              $htmlImgElement.unbind('mousemove').unbind('mouseout');
            });
      })
      .on('mouseup', function (e) {
        saveOrSendMouseAction(e);
        $htmlImgElement.unbind('mousemove').unbind('mouseout');
      })
      .on('dragstart', function () {
        return false; //disable drag
      })
  ;

  var evtAry = [];
  var isFirefox = (navigator.userAgent.match(/Firefox/i) !== null);

  function saveOrSendMouseAction(e) {
    if (e.offsetX === undefined) {
      e.offsetX = e.clientX - $htmlImgElement.offset().left;
    }
    if (e.offsetY === undefined) {
      e.offsetY = e.clientY - $htmlImgElement.offset().top;
    }
    var vw = $htmlImgElement.outerWidth();
    var vh = $htmlImgElement.outerHeight();
    if (isFirefox) {
      if (htmlImgElement.className.split(/ +/).indexOf('rotate270') < 0) {
        if (vw < vh) {
          e.xPer = Math.min(1, Math.max(0, e.offsetX / vw));
          e.yPer = Math.min(1, Math.max(0, e.offsetY / vh));
        } else {
          e.xPer = Math.min(1, Math.max(0, (vh - e.offsetY) / vh));
          e.yPer = Math.min(1, Math.max(0, e.offsetX / vw));
        }
      } else {
        if (vw < vh) {
          e.xPer = Math.min(1, Math.max(0, (vw - e.offsetY) / vw));
          e.yPer = Math.min(1, Math.max(0, e.offsetX / vh));<commit_msg>for firefox: detect html element rotated state by jQuery css('transform') which in turn use getComputedStyle.<commit_after>function setTouchHandler(htmlImgElement, touchServerUrl) {
  setTimeout(function () {
    __prepareTouchServer(touchServerUrl, function/*on_ok*/() {
      htmlImgElement.touchServerUrl = touchServerUrl;
      if (!htmlImgElement.didInitEventHandler) {
        htmlImgElement.didInitEventHandler = true;
        __setTouchHandler(htmlImgElement);
      }
    }, 10/*retry times*/);
  }, 100);
}

function __prepareTouchServer(touchServerUrl, on_ok, retryCounter) {
  console.log('prepare touch server');
  $.ajax(touchServerUrl, {timeout: 10 * 1000})
      .done(function (result) {
        console.log('prepare touch server result: ' + result);
        if (result === 'OK') {
          on_ok();
        } else if (result === 'preparing' || result === 'device is not being live viewed') {
          if (retryCounter >= 2) {
            setTimeout(function () {
              __prepareTouchServer(touchServerUrl, on_ok, retryCounter - 1);
            }, 500);
          }
        }
      })
      .fail(function (jqXHR, textStatus) {
        console.log('prepare touch server error: ' + textStatus);
      });
}

function __setTouchHandler(htmlImgElement) {
  var $htmlImgElement = $(htmlImgElement);
  $htmlImgElement
      .on('mousedown', function (e) {
        saveOrSendMouseAction(e);
        $htmlImgElement.mousemove(function (e) {
          saveOrSendMouseAction(e);
        }).mouseout(function (e) {
              saveOrSendMouseAction(e);
              $htmlImgElement.unbind('mousemove').unbind('mouseout');
            });
      })
      .on('mouseup', function (e) {
        saveOrSendMouseAction(e);
        $htmlImgElement.unbind('mousemove').unbind('mouseout');
      })
      .on('dragstart', function () {
        return false; //disable drag
      })
  ;

  var evtAry = [];
  var isFirefox = (navigator.userAgent.match(/Firefox/i) !== null);

  function saveOrSendMouseAction(e) {
    if (e.offsetX === undefined) {
      e.offsetX = e.clientX - $htmlImgElement.offset().left;
    }
    if (e.offsetY === undefined) {
      e.offsetY = e.clientY - $htmlImgElement.offset().top;
    }
    var vw = $htmlImgElement.outerWidth();
    var vh = $htmlImgElement.outerHeight();
    if (isFirefox) {
      if ($htmlImgElement.css('transform').indexOf('matrix') < 0) {
        if (vw < vh) {
          e.xPer = Math.min(1, Math.max(0, e.offsetX / vw));
          e.yPer = Math.min(1, Math.max(0, e.offsetY / vh));
        } else {
          e.xPer = Math.min(1, Math.max(0, (vh - e.offsetY) / vh));
          e.yPer = Math.min(1, Math.max(0, e.offsetX / vw));
        }
      } else {
        if (vw < vh) {
          e.xPer = Math.min(1, Math.max(0, (vw - e.offsetY) / vw));
          e.yPer = Math.min(1, Math.max(0, e.offsetX / vh));
{'fraction_non_alphanumeric': 0.15271633339231994, 'fraction_numerical': 0.010794549637232349, 'mean_word_length': 2.446341463414634, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '305180', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1821, 'n_words': 344}