Streber PM PHP Cross Reference Groupware Applications

Source: /js/dragslider.js - 193 lines - 5417 bytes - Summary - Text - Print

   1  /**************************************************

   2   * DragSlider

   3   * 2005-05-16

   4   * thomas@pixtu.de / orignal concept by www.youngpup.net

   5   * sometimes fired off the handle, not the root.

   6   **************************************************/
   7  
   8   /*

   9      Thursday, January 01, 1970 02:00:00

  10  

  11   */
  12   function string2UTC(str) {
  13      var year=2005;
  14      var month=1;
  15      var day=1;
  16      var hour=12;
  17      var min=0;
  18      var sec=0;
  19      var my_date;
  20  
  21      var check=/\b(\d?\d)\.(\d?\d)\.(\d\d\d\d)\b/;
  22      arr=check.exec(str);
  23      if(arr) {
  24          day=1*arr[1];
  25          month=1*arr[2]-1;
  26          year=1*arr[3];
  27          return Date.UTC(year, month, day, hour, min, sec);
  28      }
  29      check=/\b(\d\d\d\d)-(\d\d)-(\d\d)\s*(\d\d):(\d\d):(\d\d)\b/;
  30      arr=check.exec(str);
  31      if(arr) {
  32          year=1*arr[1];
  33          month=1*arr[2]-1;
  34          day=1*arr[3];
  35          hour=1*arr[4];
  36          min=1*arr[5];
  37          sec=1*arr[6];
  38          return Date.UTC(year, month, day, hour, min, sec);
  39      }
  40  
  41      dateObj=new Date(Date.parse(str));
  42      if(!isNaN(1*dateObj)) {
  43          if(dateObj.getSeconds()==0 && dateObj.getMilliseconds()==0 && dateObj.getMinutes()==0 && dateObj.getHours()==0) {
  44              dateObj.setHours(12);
  45          }
  46          return 1*dateObj;
  47      }
  48      return 0;
  49  }
  50  
  51   var DragSlider = {
  52  
  53      obj : null,
  54  
  55      init : function(o, field,type,speed)
  56      {
  57          if(typeof o == 'string') {
  58              o=document.all ? document.all[o] : document.getElementById(o);
  59          }
  60          if(typeof field=='string') {
  61              o.field=document.all ? document.all[field] : document.getElementById(field);
  62          }
  63          o.onmousedown    = DragSlider.start;
  64  
  65          o.type = type && type != null ? type : null; ;
  66          o.root =  o ;
  67          o.speed = speed && speed != null ? speed : 10 ;
  68  
  69          o.root.onDragStart    = new Function();
  70          o.root.onDragEnd    = new Function();
  71          o.root.onDrag        = new Function();
  72      },
  73  
  74      start : function(e)
  75      {
  76          var o = DragSlider.obj = this;
  77          e = DragSlider.fixE(e);
  78          var y = parseInt(o.root.style.top);
  79          var x = parseInt(o.root.style.left);
  80          o.root.onDragStart(x, y);
  81  
  82          o.startMouseX= o.lastMouseX    = e.clientX;
  83          o.startMouseY= o.lastMouseY    = e.clientY;
  84  
  85          document.onmousemove    = DragSlider.drag;
  86          document.onmouseup        = DragSlider.end;
  87          if(o.type=='datetime') {
  88              o.speed=20;
  89              tmpDate=new Date(string2UTC(o.field.value));
  90              tmpDate.setSeconds(0);
  91              tmpDate.setMinutes( Math.floor(tmpDate.getMinutes()/30)*30);
  92  
  93              o.orgValue= 1*tmpDate;
  94              //alert("1# o.orgVlaue="+o.orgValue);

  95          }
  96          else if(o.type=='time') {
  97              o.speed=20;
  98              var str= o.field.value;
  99              var numbers=str.split(":");
 100              var hour=0;
 101              var min=0;
 102              var sec=0;
 103              if(numbers.length==2) {
 104                  hour= 1*numbers[0];
 105                  min=1*numbers[1];
 106              }
 107              else if(numbers.length==3) {
 108                  hour= 1*numbers[0];
 109                  min=1*numbers[1];
 110                  sec=1*numbers[2];
 111              }
 112  
 113              o.orgValue= (hour-1)*60*60*1000+ min*60*1000+ sec*1000;
 114  
 115          }
 116          else {
 117              o.orgValue= o.field ? 1*o.field.value : 0;
 118          }
 119          //alert("2# o.orgValue "+o.orgValue);

 120          return false;
 121      },
 122  
 123      drag : function(e)
 124      {
 125          e = DragSlider.fixE(e);
 126          var o = DragSlider.obj;
 127  
 128          var ey    = e.clientY;
 129          var ex    = e.clientX;
 130          var y = parseInt(o.root.style.top);
 131          var x = parseInt(o.root.style.left);
 132          var nx, ny;
 133  
 134          nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
 135          ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
 136  
 137          DragSlider.obj.lastMouseX    = ex;
 138          DragSlider.obj.lastMouseY    = ey;
 139  
 140          var org_value=0;
 141          if(o.type=='datetime') {
 142              //cur_value= Date.parse(o.field.value);

 143              cur_value=o.orgValue+ Math.floor((o.lastMouseX-o.startMouseX)/o.speed)*1000*30*60;
 144              //alert("cur_value="+cur_value);

 145              var date=new Date(cur_value);
 146              o.field.value=date.toLocaleString();
 147          }
 148          else if(o.type=='time') {
 149  
 150              var mouse_dist=Math.floor((o.lastMouseX-o.startMouseX)/o.speed);
 151              var dyn_factor= (mouse_dist/7)*(mouse_dist/7)+1;
 152              var cur_value=o.orgValue+ mouse_dist*1000*1*60*dyn_factor;
 153              var date=new Date(cur_value);
 154              if(dyn_factor > 6) {
 155                  date.setMinutes(0);
 156              }
 157              //alert("cur_value="+cur_value);

 158              //alert("date="+date);

 159              o.field.value=date.getHours()+":"+date.getMinutes();
 160          }
 161          else {
 162              org_value= o.field ? 1*o.field.value : 0;
 163              o.field.value=org_value+ Math.floor((o.lastMouseX-o.startMouseX)/o.speed);
 164          }
 165  
 166          DragSlider.obj.root.onDrag(nx, ny);
 167          return false;
 168      },
 169  
 170      end : function()
 171      {
 172          var o = DragSlider.obj;
 173  
 174          document.onmousemove = null;
 175          document.onmouseup   = null;
 176          if(o.field.onChange) {
 177              o.field.onChange();
 178          }
 179          DragSlider.obj.root.onDragEnd(    parseInt(DragSlider.obj.root.style.left),
 180                                      parseInt(DragSlider.obj.root.style.top));
 181  
 182          o.field.select();
 183          DragSlider.obj = null;
 184      },
 185  
 186      fixE : function(e)
 187      {
 188          if (typeof e == 'undefined') e = window.event;
 189          if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
 190          if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
 191          return e;
 192      }
 193  };

title

Description

title

Description

title

Description

title

title

Body