Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.05 KB | None | 0 0
  1. Problem: When hitting the side of an overflow table (RIGHT SIDE HIT) the mousemove function causes the detection to occur rapidly (less than miliseconds), causing the RIGHT SIDE HIT code to be excecuted many times, depending on the mouse movement of the user, before the right edge limit of the window can be increased (scrollRight).
  2.  
  3. Needed solution: When a side is hit the very first time something must prevent the mousemove event for a second, giving the application time to retreive data and increase the scrollRight limit, which I believe will prevent multiple collide detections.
  4.  
  5. // IRRELEVANT I BELIEVE - just informative (look down for relevant)
  6. jQuery.fn.extend({
  7.       clickNScroll: function(options) {
  8.          var ops = $.extend({
  9.             allowHiliting:false,
  10.             stop: 0,
  11.             acceleration:.65,
  12.             deceleration:.85,
  13.             decelRate:64,
  14.             reverse:false,
  15.             rightMouse:false,
  16.             allowThrowing:true,
  17.             throwOnOut:false
  18.          }, options || {});
  19.          return this.each(function(){  
  20.             var $this = $(this).data("options", ops);                                  
  21.             if(!ops.allowHiliting) {
  22.               if (jQuery.browser.msie) {
  23.                  $this.get(0).onselectstart = function () { return false; };
  24.               }
  25.               else {
  26.                   $this.get(0).onmousedown = function(e){e.preventDefault()}
  27.               }  
  28.             }
  29.             $this.mousedown(function(e) {
  30.                $.clickNScroll.mousedown = $this;
  31.             }).mouseup(function(e) {                                  
  32.                if(ops.allowThrowing) sling($(this));  
  33.                $.clickNScroll.mousedown = false;
  34.             }).mouseout(function(e) {
  35.                 var from = e.relatedTarget || e.toElement;
  36.                 if (!from || from.nodeName == "HTML") {
  37.                    if($.clickNScroll.mousedown && ops.allowThrowing && ops.throwOnOut)  sling($(this));  
  38.                    $.clickNScroll.mousedown = false;
  39.                 }
  40.             })  
  41.          });
  42.       }      
  43.    });
  44.  
  45.  
  46. // RELEVANT / ROOT OF BUG I BELIEVE
  47. $(document).mousemove(function(e) {
  48.       if($.clickNScroll.mousedown) {      
  49.          var $this  = $.clickNScroll.mousedown,
  50.              ops    = $this.data("options");
  51.          if(ops.rightMouse && e.button != 2) return;
  52.          else if(!ops.rightMouse && e.button == 2) return;    
  53.          var changeX = e.pageX - $.mouse.x,  
  54.              changeY = e.pageY - $.mouse.y;
  55.          if(!ops.reverse) {
  56.           changeX = 0-changeX;
  57.           changeY = 0-changeY;
  58.          }
  59.              move($this, changeX, changeY);
  60.       }  
  61.       $.mouse = {
  62.          x: e.pageX,
  63.          y: e.pageY
  64.       };                          
  65.    });
  66.  
  67.  
  68. function move($this, changeX, changeY) {
  69.        var ops    = $this.data("options");
  70.          if(($.clickNScroll.emaX < 0 && changeX > 0) || ($.clickNScroll.emaX > 0 && changeX < 0)) $.clickNScroll.emaX = 0;
  71.          if(($.clickNScroll.emaY < 0 && changeY > 0) || ($.clickNScroll.emaY > 0 && changeY < 0)) $.clickNScroll.emaY = 0;
  72.          var ops    = $this.data("options"),                                                                      
  73.              amntX = ops.acceleration * changeX + (1 - ops.acceleration) * $.clickNScroll.emaX,
  74.              amntY = ops.acceleration * changeY + (1 - ops.acceleration) * $.clickNScroll.emaY,
  75.              scrollRight = $this[0].scrollWidth ? $this[0].scrollWidth - $this[0].clientWidth : $this[0].body.scrollWidth - $this[0].body.clientWidth,
  76.              scrollBottom = $this[0].scrollHeight ? $this[0].scrollHeight - $this[0].clientHeight : $this[0].body.scrollHeight - $this[0].body.clientHeight;
  77.  
  78.          if(($this.scrollLeft() <= 0 && changeX < 0)) {
  79.  
  80.              
  81.      } else if ($this.scrollLeft() >= scrollRight && changeX > 0) {
  82.              // RIGHT SIDE HIT
  83.              var extend = 10;
  84.              var x = $('#gamegrid2 tr:first td:last').attr("data-x");
  85.              var y = $('#gamegrid2 tr:first td:last').attr("data-y");
  86.              
  87.              // we dont need to retreive the top right one again, only the next one
  88.              x = parseInt(x)+ 1;
  89.              y = parseInt(y)+ 1;
  90.              var x2 = parseInt(x) + extend;
  91.              var y2 = parseInt(y) + extend;
  92.              
  93.              var form_data = {
  94.                         x1: x,
  95.                         y1: y,
  96.                         x2: x2,
  97.                         y2: y2,
  98.                         ajax: '1'
  99.                 };
  100.                  $.ajax({  
  101.                         url: site_url+"/home2/expand_grid",
  102.                         type: 'GET',
  103.                         data: form_data,
  104.                         success: function(msg) {
  105.                             var data = JSON.parse(msg);
  106.                             //alert(data['entries'][1]['text']);
  107.                             $('#gamegrid2 tr').each(function(index) {
  108.                                  var td = $(this).find("td:last");
  109.                                  var tdid = td.attr("data-gridid");
  110.                                  var x = td.attr("data-x");
  111.                                  var y = td.attr("data-y");
  112.                                  y = parseInt(y);
  113.                                  var nextid = parseInt(tdid);
  114.                                  var extend = 10;
  115.                                  var datastring="";
  116.                                  for (i=1;i<=extend;i++)
  117.                                  {
  118.                                      y = parseInt(y)+ 1;
  119.                                      nextid = parseInt(nextid) + 1;
  120.                                      datastring += '<td data-gridid='+ nextid +' data-x='+ x +' data-y='+ y +' width="100" height="100" STYLE="overflow: hidden;">'+ nextid +'</td>';
  121.                                      scrollRight+=100;
  122.                                      
  123.                                  }
  124.                                  $(this).append(datastring);
  125.                              });
  126.                         }
  127.                     });
  128.              }
  129.              /*
  130.              $('#gamegrid2 tr').each(function(index) {
  131.                  var td = $(this).find("td:last");
  132.                  var tdid = td.attr("data-gridid");
  133.                  var nextid = parseInt(tdid) + 1;
  134.                  $(this).append('<td data-gridid='+ nextid +' width="100" height="100" STYLE="overflow: hidden;">'+ nextid +'</td>');
  135.                  scrollRight+=100;
  136.              });
  137. */
  138.          }  else {
  139.              $this.scrollLeft($this.scrollLeft() + (amntX));
  140.          }
  141.          
  142.          if(($this.scrollTop() <= 0 && changeY <= 0)) {
  143.              //alert("top");
  144.          } else if ($this.scrollTop() >= scrollBottom && changeY >= 0) {
  145.              //alert("bottom");
  146.          } else {
  147.              $this.scrollTop($this.scrollTop() + (amntY));    
  148.          }
  149.          
  150.          $.clickNScroll.emaX = amntX;
  151.          $.clickNScroll.emaY = amntY;
  152.    }
Add Comment
Please, Sign In to add comment