[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/js/dynapi/fx/ -> snapx.js (source)

   1  /*
   2      DynAPI Distribution
   3      SnapX Class by Leif Westerlind <warp-9.9 (at) usa (dot) net>
   4  
   5      The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
   6  
   7      requires: DynLayer
   8  */
   9  
  10  SnapX = {}; // used by dynapi.library
  11  
  12  var p = DynLayer.prototype;
  13  p._snapSetLocation = p.setLocation;
  14  p.setLocation  = function(x,y){    
  15      this._snapSetLocation(x,y);
  16  
  17      if (this.isSnapEnabled){
  18          var dirX = '', dirY = '';
  19  
  20          // get direction
  21          if (this._snapX != this.x){
  22              if (this._snapX < this.x){
  23                  dirX="E";
  24              }
  25              else {
  26                  dirX="W";
  27              }
  28          }
  29  
  30          if (this._snapY != this.y){
  31              if (this._snapY < this.y){
  32                  dirY="S";
  33              }
  34              else {
  35                  dirY="N";
  36              }
  37          }
  38  
  39          this._snapX = this.x;
  40          this._snapY = this.y;
  41          this._snapDirection = dirY + dirX;
  42          this._checkForSnap();
  43      }
  44  };
  45  
  46  p.getSnapDirection = function (){
  47      return(this._snapDirection);
  48  };
  49  
  50  /*
  51  INPUT:
  52  
  53      0 args: use defaults
  54      1 arg : snap type [normal|null|sticky|grid]
  55      2 args: snap type [normal|null|sticky|grid],
  56              boundary type [inner|outer|both]
  57      3 args: snap type [normal|null|sticky|grid],
  58              boundary type [inner|outer|both],
  59              boundary
  60      4 args: snap type [normal|null|sticky|grid],
  61              boundary type [inner|outer|both],
  62              boundary,
  63              grid size (if applicable)
  64  */
  65  p.enableSnap = function (){
  66      var a = arguments;
  67      var snapBoundaryDefault = DynLayer._snapBoundaryDefault;
  68  
  69      this.isSnapEnabled = true;
  70      this._snapX = this.x;
  71      this._snapY = this.y;
  72      
  73      if ( a.length >= 0 ){
  74          this.setSnapBoundary();
  75          this.setSnapBoundaryType();
  76      }
  77  
  78      if ( a.length >= 1 ){
  79          if ( a[0] == 'sticky' || a[0] == 'grid' ){
  80              this.setSnapType(a[0]);
  81          }
  82          else if ( a[0] == 'normal' || a[0] == null ){
  83              this.setSnapType();
  84          }
  85      }
  86  
  87      if ( a.length >= 2 ){
  88          if ( a[1] == 'inner' || a[1] == 'outer' || a[1] == 'both' ){
  89              this.setSnapBoundaryType(a[1]);
  90          }
  91          else {
  92              this.setSnapBoundaryType();
  93          }
  94      }
  95  
  96      if ( a.length >= 3 ){
  97          if ( typeof(a[2]) == 'number' ){
  98              this.setSnapBoundary(a[1],a[2]);
  99          }
 100          else {
 101              this.setSnapBoundary(a[1],snapBoundaryDefault);
 102          }
 103      }
 104      
 105      if ( a.length >= 4 ){
 106          if ( typeof(a[3]) == 'number' ){
 107              this.setGridSnapSize(a[3]);
 108          }
 109          else {
 110              this.setGridSnapSize();
 111          }
 112      }
 113  };
 114  p.disableSnap = function(){
 115      this.isSnapEnabled = false;
 116  };
 117  
 118  p.setSnapType = function(t){
 119      var a = arguments;
 120      
 121      if (a.length == 0){
 122          this._snapType = 'normal';
 123      }
 124      else if (a.length == 1 ){
 125          if ( a[0] == 'sticky' ){
 126              this._snapType = a[0];
 127              this.enableStickySnap();
 128          } else if ( a[0] == 'grid' ){
 129              this._snapType = a[0];
 130              this.enableGridSnap();
 131          }
 132          else {
 133              this._snapType = 'normal';
 134          }
 135      }
 136  }
 137  
 138  p.enableStickySnap = function(){
 139      if (arguments.length == 0){
 140          this.isStickySnapEnabled = true;
 141      }
 142      else if (arguments.length == 1 ){
 143          if (arguments[0] === true){
 144              this.isStickySnapEnabled = true;
 145          }
 146          else if (arguments[0] === false){
 147              this.isStickySnapEnabled = false;
 148          }
 149      }
 150  };
 151  p.disableStickySnap = function(){
 152      this.isStickySnapEnabled = false;
 153  };
 154  
 155  p.enableGridSnap = function(){
 156      this.isGridSnapEnabled = true;
 157      this.setGridSnapSize();
 158      this._snapGridX = null;
 159      this._snapGridY = null;
 160  };
 161  p.disableGridSnap = function(){
 162      this.isGridSnapEnabled = false;
 163  };
 164  
 165  DynLayer._snapBoundaryTypeDefault = 'outer';
 166  p.setSnapBoundaryTypeDefault = function(snapBoundaryType){
 167      if (typeof(snapBoundaryType) == 'string') DynLayer._snapBoundaryTypeDefault = snapBoundaryType;
 168  }
 169  p.getSnapBoundaryTypeDefault = function(){
 170      return(DynLayer._snapBoundaryTypeDefault);
 171  }
 172  p.setSnapBoundaryType = function(snapBoundaryType){
 173      if (arguments.length == 0){
 174          this._snapBoundaryType = DynLayer._snapBoundaryTypeDefault;
 175      }
 176      else if (typeof(snapBoundaryType) == 'string'){
 177          this._snapBoundaryType = snapBoundaryType;
 178      }
 179  };
 180  p.getSnapBoundaryType = function(){
 181      return(this._snapBoundaryType);
 182  };
 183  
 184  DynLayer._snapBoundaryDefault = 25;
 185  p.setSnapBoundaryDefault = function(snapBoundary){
 186      if(typeof(snapBoundary) == 'number') DynLayer._snapBoundaryDefault = snapBoundary;
 187  }
 188  p.getSnapBoundaryDefault = function(){
 189      return(DynLayer._snapBoundaryDefault);
 190  }
 191  
 192  DynLayer._snapGridSizeDefault = 10;
 193  p.setGridSnapSizeDefault = function(s){
 194      DynLayer._snapGridSizeDefault = s;
 195  }
 196  p.getGridSnapSizeDefault = function(){
 197      return(DynLayer._snapGridSizeDefault);
 198  }
 199  p.setGridSnapSize = function(){
 200      if (arguments.length == 0){
 201          this._snapGridSize = DynLayer._snapGridSizeDefault;
 202      }
 203      else if (arguments.length == 1 ){
 204          this._snapGridSize = arguments[0];
 205      }
 206  };
 207  
 208  /*
 209     INPUT:
 210         0 args: set snapBoundaryType to snapBoundaryTypeDefault,
 211                 set boundary to snapBoundaryDefault
 212         1 arg : if snapBoundaryType, set boundary to snapBoundaryDefault,
 213                 if boundary, set all sides to boundary
 214                     and snapBoundaryType to snapBoundaryTypeDefault
 215         2 args: if snapBoundaryType,boundary, set type and boundary for all sides
 216                 if N1,N2 set inner to N1 and outer to N2 and
 217                     set snapBoundaryType to both
 218         5 args: snapBoundaryType, t, r, b, l
 219         8 args: ti, ri, bi, li, to, ro, bo, lo
 220  */
 221  
 222  p.setSnapBoundary = function(){
 223      var a = arguments;
 224      var snapBoundaryDefault = DynLayer._snapBoundaryDefault;
 225      
 226      if (a.length == 0){
 227          this.setSnapBoundaryType();
 228          this._snapBndTi = snapBoundaryDefault;
 229          this._snapBndRi = snapBoundaryDefault;
 230          this._snapBndBi = snapBoundaryDefault;
 231          this._snapBndLi = snapBoundaryDefault;
 232          this._snapBndTo = snapBoundaryDefault;
 233          this._snapBndRo = snapBoundaryDefault;
 234          this._snapBndBo = snapBoundaryDefault;
 235          this._snapBndLo = snapBoundaryDefault;
 236      }
 237      if (a.length == 1){
 238          if(a[0] == 'inner' || a[0] == 'outer' || a[0] == 'both'){
 239              this.setSnapBoundaryType(a[0]);
 240              this._snapBndTi = snapBoundaryDefault;
 241              this._snapBndRi = snapBoundaryDefault;
 242              this._snapBndBi = snapBoundaryDefault;
 243              this._snapBndLi = snapBoundaryDefault;
 244              this._snapBndTo = snapBoundaryDefault;
 245              this._snapBndRo = snapBoundaryDefault;
 246              this._snapBndBo = snapBoundaryDefault;
 247              this._snapBndLo = snapBoundaryDefault;
 248          }
 249          else {
 250              this.setSnapBoundaryType();
 251              this._snapBndTi = a[0];
 252              this._snapBndRi = a[0];
 253              this._snapBndBi = a[0];
 254              this._snapBndLi = a[0];
 255              this._snapBndTo = a[0];
 256              this._snapBndRo = a[0];
 257              this._snapBndBo = a[0];
 258              this._snapBndLo = a[0];
 259          }
 260      }
 261      else if (a.length == 2){
 262          if (a[0] == 'inner'){
 263              this.setSnapBoundaryType(a[0]);
 264              this._snapBndTi = a[1];
 265              this._snapBndRi = a[1];
 266              this._snapBndBi = a[1];
 267              this._snapBndLi = a[1];
 268          }
 269          else if (a[0] == 'outer'){
 270              this.setSnapBoundaryType(a[0]);
 271              this._snapBndTo = a[1];
 272              this._snapBndRo = a[1];
 273              this._snapBndBo = a[1];
 274              this._snapBndLo = a[1];
 275          }
 276          else if (a[0] == 'both' || a[0] == null){
 277              this.setSnapBoundaryType('both');
 278              this._snapBndTi = a[1];
 279              this._snapBndRi = a[1];
 280              this._snapBndBi = a[1];
 281              this._snapBndLi = a[1];
 282              this._snapBndTo = a[1];
 283              this._snapBndRo = a[1];
 284              this._snapBndBo = a[1];
 285              this._snapBndLo = a[1];
 286          }
 287          else if (typeof(a[0]) == 'number' && typeof(a[1]) == 'number'){
 288              this.setSnapBoundaryType('both');
 289              this._snapBndTi = a[0];
 290              this._snapBndRi = a[0];
 291              this._snapBndBi = a[0];
 292              this._snapBndLi = a[0];
 293              this._snapBndTo = a[1];
 294              this._snapBndRo = a[1];
 295              this._snapBndBo = a[1];
 296              this._snapBndLo = a[1];
 297          }
 298      }
 299      else if (a.length == 5){
 300          if(a[0] == 'inner' || a[0] == 'outer' || a[0] == 'both'){
 301              this.setSnapBoundaryType(a[0]);
 302          }
 303  
 304          if (this._snapBoundaryType == 'inner'){
 305              this._snapBndTi = a[1];
 306              this._snapBndRi = a[2];
 307              this._snapBndBi = a[3];
 308              this._snapBndLi = a[4];
 309          }
 310          else if (this._snapBoundaryType == 'outer'){
 311              this._snapBndTo = a[1];
 312              this._snapBndRo = a[2];
 313              this._snapBndBo = a[3];
 314              this._snapBndLo = a[4];
 315          }
 316          else if (this._snapBoundaryType == 'both'){
 317              this._snapBndTi = a[1];
 318              this._snapBndRi = a[2];
 319              this._snapBndBi = a[3];
 320              this._snapBndLi = a[4];
 321              this._snapBndTo = a[1];
 322              this._snapBndRo = a[2];
 323              this._snapBndBo = a[3];
 324              this._snapBndLo = a[4];
 325          }
 326      }
 327      else if (a.length == 8){
 328          this.setSnapBoundaryType('both');
 329          this._snapBndTi = a[0];
 330          this._snapBndRi = a[1];
 331          this._snapBndBi = a[2];
 332          this._snapBndLi = a[3];
 333          this._snapBndTo = a[4];
 334          this._snapBndRo = a[5];
 335          this._snapBndBo = a[6];
 336          this._snapBndLo = a[7];
 337      }
 338      else {
 339          this.setSnapBoundaryType();
 340          this._snapBndTi = snapBoundaryDefault;
 341          this._snapBndRi = snapBoundaryDefault;
 342          this._snapBndBi = snapBoundaryDefault;
 343          this._snapBndLi = snapBoundaryDefault;
 344          this._snapBndTo = snapBoundaryDefault;
 345          this._snapBndRo = snapBoundaryDefault;
 346          this._snapBndBo = snapBoundaryDefault;
 347          this._snapBndLo = snapBoundaryDefault;
 348      }
 349  };
 350  p.getSnapBoundary = function(t){
 351      var To,Ro,Bo,Lo,Ti,Ri,Bi,Li,bndAry,X,Y,W,H;
 352  
 353      X = this.x;
 354      Y = this.y;
 355      W = this.w;
 356      H = this.h;
 357  
 358      Ti = Y + this._snapBndTi;
 359      Ri = X + W - this._snapBndRi;
 360      Bi = Y + H - this._snapBndBi;
 361      Li = X + this._snapBndLi;
 362  
 363      To = Y - this._snapBndTo;
 364      Ro = X + W + this._snapBndRo;
 365      Bo = Y + H + this._snapBndBo;
 366      Lo = X - this._snapBndLo;
 367  
 368      if (t==null) bndAry = [Ti,Ri,Bi,Li,To,Ro,Bo,Lo];
 369      else {
 370          if (t=='inner') bndAry = [Ti,Ri,Bi,Li];
 371          else if (t=='outer') bndAry = [To,Ro,Bo,Lo];
 372          else if (t=='both') bndAry = [Ti,Ri,Bi,Li,To,Ro,Bo,Lo];
 373      }
 374      return(bndAry);
 375  };
 376  
 377  p._checkForSnap = function(){
 378      switch (this._snapBoundaryType) {
 379          case 'outer' :
 380              this._checkForSnapOuter();
 381              break;
 382          case 'inner' :
 383              this._checkForSnapInner();
 384              break;
 385          case 'both' :
 386              this._checkForSnapInner();
 387              this._checkForSnapOuter();
 388              break;
 389          default:
 390              return(false);
 391      }
 392  };
 393  
 394  p._checkForSnapInner = function(){
 395      if (!this.parent.children.length>0) return(false);
 396      if (!this.isSnapEnabled==true) return(false);
 397  
 398      var ch,chX1,chY1,chX2,chY2,
 399          chBiX1,chBiY1,chBiX2,chBiY2,
 400          sX1,sY1,sX2,sY2,
 401          chBndAry,sDir,
 402          B1,B2a,B2b,B3,B4a,B4b,B5,B6a,B6b,B7,B8a,B8b,
 403          D1,D2a,D2b,D3,D4a,D4b,D5,D6a,D6b,D7,D8a,D8b,
 404          C1,C2a,C2b,C3,C4a,C4b,C5,C6a,C6b,C7,C8a,C8b;
 405  
 406      sX1  = this.x;
 407      sY1  = this.y;
 408      sW   = this.w;
 409      sH   = this.h;
 410      sX2  = sX1 + sW;
 411      sY2  = sY1 + sH;
 412      sDir = this.getSnapDirection();
 413  
 414      for (var i in this.parent.children){
 415          ch = this.parent.children[i];
 416          if (ch != this && ch.isSnapEnabled == true){
 417              chX1 = ch.x;
 418              chY1 = ch.y;
 419              chX2 = chX1 + ch.w;
 420              chY2 = chY1 + ch.h;
 421              chBndAry = ch.getSnapBoundary('inner');
 422              chBiX1 = chBndAry[3];
 423              chBiY1 = chBndAry[0];
 424              chBiX2 = chBndAry[1];
 425              chBiY2 = chBndAry[2];
 426  
 427              // Cases B1 - B8 test TRUE if source corner is in snap border.
 428              // Cases D1 - D8 test TRUE if the corresponding direction of
 429              //               movement of the corner is towards the boundary.
 430              // Cases C1 - C8 test TRUE if the corresponding B and D cases
 431              //               are true for standard or sticky snap.
 432  
 433              // inner top-left corner, source top-left, move N, NW, W
 434              B1  = (sX1 <= chBiX1 && sX1 >  chX1   && sY1 <= chBiY1 && sY1 > chY1);
 435              D1  = (sDir == 'N' || sDir == 'NW' || sDir == 'W');
 436              C1  = (B1 && (D1 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 437  
 438              // inner top-middle side, source top-left, move NE, N, NW
 439              B2a = (sX1 >  chBiX1 && sX1 <  chBiX2 && sY1 <= chBiY1 && sY1 > chY1);
 440              D2a = (sDir == 'NE' || sDir == 'N' || sDir == 'NW');
 441              C2a = (B2a && (D2a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 442  
 443              // inner top-middle side, source top-right, move NE, N, NW
 444              B2b = (sX2 >  chBiX1 && sX2 <  chBiX2 && sY1 <= chBiY1 && sY1 > chY1);
 445              D2b = (sDir == 'NE' || sDir == 'N' || sDir == 'NW');
 446              C2b = (B2b && (D2b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 447  
 448              // inner top-right corner, source top-right, move E, NE, N
 449              B3  = (sX2 >= chBiX2 && sX2 <  chX2   && sY1 <= chBiY1 && sY1 > chY1);
 450              D3  = (sDir == 'E' || sDir == 'NE' || sDir == 'N');
 451              C3  = (B3 && (D3 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 452  
 453              // inner right-middle side, source top-right, move SE, E, NE
 454              B4a = (sX2 >= chBiX2 && sX2 <  chX2   && sY1 >  chBiY1 && sY1 < chBiY2);
 455              D4a = (sDir == 'SE' || sDir == 'E' || sDir == 'NE');
 456              C4a = (B4a && (D4a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 457  
 458              // inner right-middle side, source bottom-right, move SE, E, NE
 459              B4b = (sX2 >= chBiX2 && sX2 <  chX2   && sY2 >  chBiY1 && sY2 < chBiY2);
 460              D4b = (sDir == 'SE' || sDir == 'E' || sDir == 'NE');
 461              C4b = (B4b && (D4b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 462  
 463              // inner bottom-right corner, source lower-right, move dir E, SE, S
 464              B5  = (sX2 >= chBiX2 && sX2 <  chX2   && sY2 >= chBiY2 && sY2 < chY2);
 465              D5  = (sDir == 'E' || sDir == 'SE' || sDir == 'S');
 466              C5  = (B5 && (D5 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 467  
 468              // inner bottom-middle side, source lower-left, move SW, S, SE
 469              B6a = (sX1 >  chBiX1 && sX1 <  chBiX2 && sY2 >= chBiY2 && sY2 < chY2);
 470              D6a = (sDir == 'SW' || sDir == 'S' || sDir == 'SE');
 471              C6a = (B6a && (D6a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 472  
 473              // inner bottom-middle side, source lower-right, move SW, S, SE
 474              B6b = (sX2 >  chBiX1 && sX2 <  chBiX2 && sY2 >= chBiY2 && sY2 < chY2);
 475              D6b = (sDir == 'SW' || sDir == 'S' || sDir == 'SE');
 476              C6b = (B6b && (D6b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 477  
 478              // inner bottom-left corner, source lower-left, move W, SW, S
 479              B7  = (sX1 <= chBiX1 && sX1 >  chX1   && sY2 >= chBiY2 && sY2 < chY2);
 480              D7  = (sDir == 'W' || sDir == 'SW' || sDir == 'S');
 481              C7  = (B7 && (D7 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 482  
 483              // inner left-middle side, source top-left, move NW, W, SW
 484              B8a = (sX1 <= chBiX1 && sX1 >  chX1   && sY1 >  chBiY1 && sY1 < chBiY2);
 485              D8a = (sDir == 'NW' || sDir == 'W' || sDir == 'SW');
 486              C8a = (B8a && (D8a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 487  
 488              // inner left-middle side, source bottom-left, move NW, W, SW
 489              B8b = (sX1 <= chBiX1 && sX1 >  chX1   && sY2 >  chBiY1 && sY2 < chBiY2);
 490              D8b = (sDir == 'NW' || sDir == 'W' || sDir == 'SW');
 491              C8b = (B8b && (D8b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 492  
 493              if (C1){
 494                  if (this.isGridSnapEnabled){
 495                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 496                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 497                      this._snapSetLocation(tmpX, tmpY);
 498                  }
 499                  else {
 500                      this._snapSetLocation(chX1, chY1);
 501                  }
 502              }
 503              else if (C3){
 504                  if (this.isGridSnapEnabled){
 505                      var tmpX = chX2 - ( Math.floor( ( chX2 - sX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 506                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 507                      this._snapSetLocation(tmpX, tmpY);
 508                  }
 509                  else {
 510                      this._snapSetLocation(chX2-sW, chY1);
 511                  }
 512              }
 513              else if (C5){
 514                  if (this.isGridSnapEnabled){
 515                      var tmpX = chX2 - ( Math.floor( ( chX2 - sX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 516                      var tmpY = chY2 - sH - ( Math.floor( ( chY2 - sY2 ) / this._snapGridSize ) ) * this._snapGridSize;
 517                      this._snapSetLocation(tmpX, tmpY);
 518                  }
 519                  else {
 520                      this._snapSetLocation(chX2-sW, chY2-sH);
 521                  }
 522              }
 523              else if (C7){
 524                  if (this.isGridSnapEnabled){
 525                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 526                      var tmpY = chY2 - sH - ( Math.floor( ( chY2 - sY2 ) / this._snapGridSize ) ) * this._snapGridSize;
 527                      this._snapSetLocation(tmpX, tmpY);
 528                  }
 529                  else {
 530                      this._snapSetLocation(chX1, chY2-sH);
 531                  }
 532              }
 533              else if (C2a || C2b){
 534                  if (this.isGridSnapEnabled){
 535                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 536                      this._snapSetLocation(tmpX, chY1);
 537                  }
 538                  else {
 539                      this._snapSetLocation(sX1, chY1);
 540                  }
 541              }
 542              else if (C4a || C4b){
 543                  if (this.isGridSnapEnabled){
 544                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 545                      this._snapSetLocation(chX2-sW, tmpY);
 546                  }
 547                  else {
 548                      this._snapSetLocation(chX2-sW, sY1);
 549                  }
 550              }
 551              else if (C6a || C6b){
 552                  if (this.isGridSnapEnabled){
 553                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 554                      this._snapSetLocation(tmpX, chY2-sH);
 555                  }
 556                  else {
 557                      this._snapSetLocation(sX1, chY2-sH);
 558                  }
 559              }
 560              else if (C8a || C8b){
 561                  if (this.isGridSnapEnabled){
 562                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 563                      this._snapSetLocation(chX1 , tmpY);
 564                  }
 565                  else {
 566                      this._snapSetLocation(chX1 , sY1);
 567                  }
 568              }
 569  
 570              if (C1 || C2a || C2b || C3 || C4a || C4b || C5 || C6a || C6b || C7 || C8a || C8b){
 571                  this._snapObject=ch;
 572                  this.invokeEvent("snap");
 573                  ch._snapObject=this;
 574                  ch.invokeEvent("snap");
 575              }
 576          }
 577      }
 578  };
 579  
 580  p._checkForSnapOuter = function(){
 581      if (! this.parent.children.length > 0) return(false);
 582      if (! this.isSnapEnabled == true) return(false);
 583  
 584      var ch,chX1,chY1,chX2,chY2,
 585          chBoX1,chBoY1,chBoX2,chBoY2,
 586          sX1,sY1,sX2,sY2,
 587          chBndAry,sDir,
 588          B1,B2a,B2b,B3,B4a,B4b,B5,B6a,B6b,B7,B8a,B8b,
 589          D1,D2a,D2b,D3,D4a,D4b,D5,D6a,D6b,D7,D8a,D8b,
 590          C1,C2a,C2b,C3,C4a,C4b,C5,C6a,C6b,C7,C8a,C8b;
 591  
 592  /*
 593      if(this.isGridSnapEnabled){
 594          if( Math.abs( this._snapX - this._snapGridX ) > this._snapGridSize ) this._snapGridX=null;
 595          if( Math.abs( this._snapY - this._snapGridY ) > this._snapGridSize ) this._snapGridY=null;
 596          this._snapSetLocation( this._snapGridX || this._snapX, this._snapGridY || this._snapY );
 597      }
 598  */
 599  
 600      sX1 = this.x;
 601      sY1 = this.y;
 602      sW  = this.w;
 603      sH  = this.h;
 604      sX2 = sX1 + sW;
 605      sY2 = sY1 + sH;
 606      sDir = this.getSnapDirection();
 607  
 608      for (var i in this.parent.children){
 609          ch = this.parent.children[i];
 610          if (ch != this && ch.isSnapEnabled == true){
 611              chX1 = ch.x;
 612              chY1 = ch.y;
 613              chX2 = chX1 + ch.w;
 614              chY2 = chY1 + ch.h;
 615              chBndAry = ch.getSnapBoundary('outer');
 616              chBoX1 = chBndAry[3];
 617              chBoY1 = chBndAry[0];
 618              chBoX2 = chBndAry[1];
 619              chBoY2 = chBndAry[2];
 620  
 621              // Cases B1 - B8 test TRUE if source corner is in snap border.
 622              // Cases D1 - D8 test TRUE if the corresponding direction of
 623              //               movement of the corner is towards the boundary.
 624              // Cases C1 - C8 test TRUE if the corresponding B and D cases
 625              //               are true for standard, sticky or grid snap.
 626  
 627              // outer top-left corner, source lower-right, move dir E, SE, S
 628              B1  = (sX2 >= chBoX1 && sX2 <  chX1 && sY2 >= chBoY1 && sY2 <  chY1);
 629              D1  = (sDir == 'E' || sDir == 'SE' || sDir == 'S');
 630              C1  = (B1 && (D1 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 631  
 632              // outer top-middle side, source lower-left, move SW, S, SE
 633              B2a = (sX1 >= chX1   && sX1 <= chX2 && sY2 >= chBoY1 && sY2 <  chY1);
 634              D2a = (sDir == 'SW' || sDir == 'S' || sDir == 'SE');
 635              C2a = (B2a && (D2a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 636  
 637              // outer top-middle side, source lower-right, move SW, S, SE
 638              B2b = (sX2 >= chX1   && sX2 <= chX2 && sY2 >= chBoY1 && sY2 <  chY1);
 639              D2b = (sDir == 'SW' || sDir == 'S' || sDir == 'SE');
 640              C2b = (B2b && (D2b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 641  
 642              // outer top-right corner, source lower-left, move W, SW, S
 643              B3  = (sX1 <= chBoX2 && sX1 >  chX2 && sY2 >= chBoY1 && sY2 <  chY1);
 644              D3  = (sDir == 'W' || sDir == 'SW' || sDir == 'S');
 645              C3  = (B3 && (D3 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 646              
 647              // outer right-middle side, source top-left, move NW, W, SW
 648              B4a = (sX1 <= chBoX2 && sX1 >  chX2 && sY1 >= chY1   && sY1 <= chY2);
 649              D4a = (sDir == 'NW' || sDir == 'W' || sDir == 'SW');
 650              C4a = (B4a && (D4a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 651  
 652              // outer right-middle side, source bottom-left, move NW, W, SW
 653              B4b = (sX1 <= chBoX2 && sX1 >  chX2 && sY2 >= chY1   && sY2 <= chY2);
 654              D4b = (sDir == 'NW' || sDir == 'W' || sDir == 'SW');
 655              C4b = (B4b && (D4b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 656  
 657              // outer bottom-right corner, source top-left, move N, NW, W
 658              B5  = (sX1 <= chBoX2 && sX1 >  chX2 && sY1 <= chBoY2 && sY1 >  chY2);
 659              D5  = (sDir == 'N' || sDir == 'NW' || sDir == 'W');
 660              C5  = (B5 && (D5 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 661  
 662              // outer bottom-middle side, source top-left, move NE, N, NW
 663              B6a = (sX1 >= chX1   && sX1 <= chX2 && sY1 <= chBoY2 && sY1 >  chY2);
 664              D6a = (sDir == 'NE' || sDir == 'N' || sDir == 'NW');
 665              C6a = (B6a && (D6a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 666  
 667              // outer bottom-middle side, source top-right, move NE, N, NW
 668              B6b = (sX2 >= chX1   && sX2 <= chX2 && sY1 <= chBoY2 && sY1 >  chY2);
 669              D6b = (sDir == 'NE' || sDir == 'N' || sDir == 'NW');
 670              C6b = (B6b && (D6b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 671  
 672              // outer bottom-left corner, source top-right, move E, NE, N
 673              B7  = (sX2 >= chBoX1 && sX2 <  chX1 && sY1 <= chBoY2 && sY1 >  chY2);
 674              D7  = (sDir == 'E' || sDir == 'NE' || sDir == 'N');
 675              C7  = (B7 && (D7 || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 676  
 677              // outer left-middle side, source top-right, move SE, E, NE
 678              B8a = (sX2 >= chBoX1 && sX2 <  chX1 && sY1 >= chY1  && sY1  <= chY2);
 679              D8a = (sDir == 'SE' || sDir == 'E' || sDir == 'NE');
 680              C8a = (B8a && (D8a || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 681  
 682              // outer left-middle side, source bottom-right, move SE, E, NE
 683              B8b = (sX2 >= chBoX1 && sX2 <  chX1 && sY2 >= chY1  && sY2  <= chY2);
 684              D8b = (sDir == 'SE' || sDir == 'E' || sDir == 'NE');
 685              C8b = (B8b && (D8b || ch.isStickySnapEnabled || ch.isGridSnapEnabled));
 686  
 687              if (C1){
 688                  if (this.isGridSnapEnabled){
 689                      var tmpX = chX1 - ( Math.floor( ( chX1 - sX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 690                      var tmpY = chY1 - ( Math.floor( ( chY1 - sY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 691                      this._snapSetLocation(tmpX, tmpY);
 692                  }
 693                  else {
 694                      this._snapSetLocation(chX1-sW, chY1-sH);
 695                  }
 696              }
 697              else if (C3){
 698                  if (this.isGridSnapEnabled){
 699                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 700                      var tmpY = chY1 - ( Math.floor( ( chY1 - sY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 701                      this._snapSetLocation(tmpX, tmpY);
 702                  }
 703                  else {
 704                      this._snapSetLocation(chX2, chY1-sH);
 705                  }
 706              }
 707              else if (C5){
 708                  if (this.isGridSnapEnabled){
 709                      var tmpX = chX1 + ( Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 710                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 711                      this._snapSetLocation(tmpX, tmpY);
 712                  }
 713                  else {
 714                      this._snapSetLocation(chX2, chY2);
 715                  }
 716              }
 717              else if (C7){
 718                  if (this.isGridSnapEnabled){
 719                      var tmpX = chX1 - ( Math.floor( ( chX1 - sX1 ) / this._snapGridSize ) ) * this._snapGridSize;
 720                      var tmpY = chY1 + ( Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) ) * this._snapGridSize;
 721                      this._snapSetLocation(tmpX, tmpY);
 722                  }
 723                  else {
 724                      this._snapSetLocation(chX1-sW, chY2);
 725                  }
 726              }
 727              else if (C2a || C2b){
 728                  if (this.isGridSnapEnabled){
 729                      //if(!this._snapGridY) this._snapGridY=chY1-sH;
 730                      //this._snapSetLocation(sX1 , this._snapGridY);
 731                      var tmpX = chX1 + Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) * this._snapGridSize;
 732                      this._snapSetLocation(tmpX , chY1-sH);
 733                  }
 734                  else {
 735                      this._snapSetLocation(sX1, chY1-sH);
 736                  }
 737              }
 738              else if (C4a || C4b){
 739                  if (this.isGridSnapEnabled){
 740                      //if(!this._snapGridX) this._snapGridX=chX2;
 741                      //this._snapSetLocation(this._snapGridX, sY1);
 742                      var tmpY = chY1 + Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) * this._snapGridSize;
 743                      this._snapSetLocation(chX2, tmpY);
 744                  }
 745                  else {
 746                      this._snapSetLocation(chX2, sY1);
 747                  }
 748              }
 749              else if (C6a || C6b){
 750                  if (this.isGridSnapEnabled){
 751                      //if(!this._snapGridY) this._snapGridY=chY2;
 752                      //this._snapSetLocation(sX1 , this._snapGridY);
 753                      var tmpX = chX1 + Math.floor( ( sX1 - chX1 ) / this._snapGridSize ) * this._snapGridSize;
 754                      this._snapSetLocation(tmpX , chY2);
 755                  }
 756                  else {
 757                      this._snapSetLocation(sX1, chY2);
 758                  }
 759              }
 760              else if (C8a || C8b){
 761                  if (this.isGridSnapEnabled){
 762                      //if(!this._snapGridX) this._snapGridX=chX1-sW;
 763                      //this._snapSetLocation(chX1-sW , sY1);
 764                      var tmpY = chY1 + Math.floor( ( sY1 - chY1 ) / this._snapGridSize ) * this._snapGridSize;
 765                      this._snapSetLocation(chX1-sW, tmpY);
 766                  }
 767                  else {
 768                      this._snapSetLocation(chX1-sW, sY1);
 769                  }
 770              }
 771  
 772              if (C1 || C2a || C2b || C3 || C4a || C4b || C5 || C6a || C6b || C7 || C8a || C8b){
 773                  this._snapObject=ch;
 774                  this.invokeEvent("snap");
 775                  ch._snapObject=this;
 776                  ch.invokeEvent("snap");
 777              }
 778          }
 779      }
 780  };


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7