[ PHPXref.com ] [ Generated: Sun Jul 20 17:09:12 2008 ] [ DAlbum 1.41 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> dalbum.js (source)

   1  /*
   2      This file is a part of DAlbum.  Copyright (c) 2003 Alexei Shamov, DeltaX Inc.
   3  
   4      This program is free software; you can redistribute it and/or modify
   5      it under the terms of the GNU General Public License as published by
   6      the Free Software Foundation; either version 2 of the License, or
   7      (at your option) any later version.
   8  
   9      This program is distributed in the hope that it will be useful,
  10      but WITHOUT ANY WARRANTY; without even the implied warranty of
  11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12      GNU General Public License for more details.
  13  
  14      You should have received a copy of the GNU General Public License
  15      along with this program; if not, write to the Free Software
  16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17  */
  18  
  19  var dalbum_imageErrors=new Array();
  20  
  21  function dalbum_imageError(theImage)
  22  {
  23      var v=theImage.src;
  24  
  25      for (var i=0;i<dalbum_imageErrors.length;++i)
  26      {
  27          if (dalbum_imageErrors[i]===theImage)
  28              return;
  29      }
  30      dalbum_imageErrors.push(theImage);
  31  }
  32  
  33  function dalbum_loadFailedImages()
  34  {
  35      for (var i=0;i<dalbum_imageErrors.length;++i)
  36      {
  37          var v=dalbum_imageErrors[i].src;
  38          dalbum_imageErrors[i].src='';
  39          dalbum_imageErrors[i].src=v;
  40      }
  41  }
  42  
  43  var dalbum_prefetch_image;
  44  var dalbum_prefetch_image_src;
  45  
  46  function dalbum_prefetch(imgsrc)
  47  {
  48      if (imgsrc.length>0 && document.getElementById)
  49      {
  50          dalbum_prefetch_image=new Image();
  51  
  52          // Find Image object and start prefetching once its loaded
  53            if (document.getElementById("Image"))
  54            {
  55                dalbum_prefetch_image_src=imgsrc;
  56              if (document.getElementById("Image").complete)
  57              {
  58                  dalbum_prefetch_image.src=dalbum_prefetch_image_src;
  59              }
  60              else
  61              {
  62                  document.getElementById("Image").onload=new function(e) { dalbum_prefetch_image.src=dalbum_prefetch_image_src; document.getElementById("Image").onload=null;}
  63              }
  64          }
  65      }
  66  }
  67  
  68  function dalbum_setCustomFocus(objName)
  69  {
  70      if (document.getElementById && document.getElementById(objName) && document.getElementById(objName).focus)
  71      {
  72          document.getElementById(objName).focus();
  73      }
  74  }
  75  
  76  
  77  function dalbum_writeFullScreen(buttonFullscreen, buttonClose)
  78  {
  79      if (window.name=='fullscreen' || window.name=='popup')
  80          document.write(buttonClose);
  81      else
  82          document.write(buttonFullscreen);
  83  }
  84  
  85  function dalbum_writeRotateButton(button)
  86  {
  87      if (document.body && document.body.filters)
  88      {
  89          document.write(button);
  90      }
  91  }
  92  
  93  function dalbum_addRotateStyle(objName,rotation)
  94  {
  95      if (document.getElementById && document.getElementById(objName))
  96      {
  97          if (document.getElementById(objName).filters &&
  98              document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'])
  99          {
 100              document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'].enabled=1;
 101              document.getElementById(objName).filters['DXImageTransform.Microsoft.BasicImage'].rotation=rotation;
 102          }
 103  
 104          if (document.getElementById(objName).filters &&
 105              document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'])
 106          {
 107              document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'].enabled=1;
 108              document.getElementById(objName).filters.item['DXImageTransform.Microsoft.BasicImage'].rotation=rotation;
 109          }
 110  
 111      }
 112  }
 113  
 114  
 115  function dalbum_fullScreen()
 116  {
 117      var agt=navigator.userAgent.toLowerCase();
 118         var is_ie   = (agt.indexOf("msie") != -1);
 119      var features;
 120      if (is_ie)
 121      {
 122           features="fullscreen=yes";
 123      }
 124      else
 125      {
 126          features="toolbar=0,scrollbars=1,location=0,border=0,status=0,menubar=0,";
 127          features=features + 'outerHeight=' + screen.availHeight + ',outerWidth=' + (screen.availWidth-2);
 128      }
 129      var w=window.open(location.href,'fullscreen',features);
 130      if (w!=null)
 131      {
 132          if (!is_ie && screen.availLeft!=null && screen.availTop!=null)
 133              w.moveTo(screen.availLeft,screen.availTop);
 134          w.focus();
 135      }
 136  }
 137  
 138  function dalbum_setHideFocus()
 139  {
 140      var agt=navigator.userAgent.toLowerCase();
 141      var is_ie   = (agt.indexOf("msie") != -1);
 142      var is_opera   = (agt.indexOf("opera") != -1);
 143  
 144      if (!is_opera && document.links.length > 0)
 145      {
 146        for (i=0;i<document.links.length;i++)
 147        {
 148           if (document.links[i].className=="buttonLink" && document.links[i].hideFocus!=null)
 149           {
 150              document.links[i].hideFocus=true;
 151           }
 152        }
 153      }
 154  }
 155  
 156  
 157  function dalbum_firstFocus()
 158  {
 159      // If hash  - do not set control
 160      if (window.location.hash.toString().length>0)
 161          return;
 162  
 163      if (document.forms.length > 0)
 164      {
 165            var TForm = document.forms[0];
 166            for (i=0;i<TForm.length;i++)
 167            {
 168               if ((TForm.elements[i].type=="text")||
 169                  (TForm.elements[i].type=="select") ||
 170                  (TForm.elements[i].type=="password") ||
 171                  (TForm.elements[i].type=="textarea")||
 172                  (TForm.elements[i].type.toString().charAt(0)=="s"))
 173               {
 174                   document.forms[0].elements[i].focus();
 175                  break;
 176               }
 177        }
 178      }
 179  }
 180  
 181  function dalbum_followLink(a)
 182  {
 183      if (a.target.length==0)
 184          window.location.href=a.href;
 185  }
 186  
 187  function dalbum_objectDisplay (obj) {
 188          var displayLine;
 189          for (var prop in obj) {
 190                 displayLine = obj.name + "." + prop + " = " + obj[prop];
 191                 document.write(displayLine + "<BR>")
 192          }
 193          document.write("End of object " + obj.name)
 194  }
 195  var dalbumShowImagePage =
 196  {
 197      pageTableObject : null,
 198      imageObject : null,
 199      imagePlaceholder : null,
 200      imageWrap : null,
 201      imageWidth : 0,
 202      imageHeight : 0,
 203      method : "",
 204      rotate: 0,
 205      origWidth :0,
 206      origHeight :0,
 207  
 208  
 209      getWindowHeight : function()
 210      {
 211          if (document.body && document.body.clientHeight)
 212              return document.body.clientHeight;
 213          if (window.innerHeight)
 214              return window.innerHeight;
 215          if (document.documentElement && document.documentElement.clientHeight)
 216              return document.documentElement.clientHeight;
 217  
 218          return -1;
 219      },
 220  
 221      getWindowWidth : function()
 222      {
 223          if (document.body && document.body.clientWidth)
 224              return document.body.clientWidth;
 225          if (window.innerWidth)
 226              return window.innerWidth;
 227          if (document.documentElement && document.documentElement.clientWidth)
 228              return document.documentElement.clientWidth;
 229  
 230          return -1;
 231      },
 232  
 233      onResize : function()
 234      {
 235          if (this.pageTableObject!=null && this.getWindowHeight()!=-1)
 236              this.pageTableObject.style.height=this.getWindowHeight();
 237      },
 238  
 239      resizeImage : function()
 240      {
 241          if (this.imageObject!=null &&
 242              this.imagePlaceholder!=null &&
 243              this.pageTableObject!=null    )
 244          {
 245  
 246                 //
 247                if (this.method=='noresize' || this.method=="" || this.method==null)
 248                     return;
 249  
 250                 // get document body client height
 251              var maxY=this.getWindowHeight();
 252              var maxX=this.getWindowWidth();
 253  
 254              if (maxY==-1 || maxX==-1)
 255              {
 256  
 257                  return;
 258              }
 259  
 260              // calculate maximum boundaries for showImgPane
 261              var footerHeight=(this.pageTableObject.offsetHeight-this.imagePlaceholder.offsetHeight-this.imagePlaceholder.offsetTop);
 262  
 263              maxY=maxY - this.imagePlaceholder.offsetTop - footerHeight;
 264  
 265              // reduce the boundaries by the amount of extra code around the  image
 266              // (such as exif details, borders etc.)
 267              var imageWrapX=this.imageWrap.offsetWidth;
 268              var imageWrapY=this.imageWrap.offsetHeight;
 269  
 270  
 271              // Here goes a HACK to make it work in Konqueror and, quite likely, Safari
 272              if (imageWrapX-0<=0)
 273              {
 274  
 275                  // Our ImageWrap points to table row.
 276                  if (this.imageWrap.offsetParent)
 277                  {
 278                      imageWrapX=this.imageWrap.offsetParent.offsetWidth;
 279                      imageWrapY=this.imageWrap.offsetParent.offsetHeight;
 280                  }
 281              }
 282  
 283  
 284              if (imageWrapX-0<=0 ||
 285                  imageWrapY-0<=0)
 286              {
 287  
 288                  return;
 289              }
 290  
 291              var srcX=this.imageWidth;
 292              var srcY=this.imageHeight;
 293  
 294              maxX-=(imageWrapX-srcX)+10;
 295              maxY-=(imageWrapY-srcY)+10;
 296  
 297              //
 298              if (this.method=='height_fit' ||
 299                  this.method=='height_shrink' ||
 300                  this.method=='height_expand')
 301                  maxX*=50;
 302  
 303              // Now we have maximum image size in maxX,maxY
 304              if (maxY>0 && maxX>0 && srcX>0 && srcY>0)
 305              {
 306                  // calculate ratio and normalize it
 307                  var ratio= Math.min(maxX/srcX,maxY/srcY);
 308                  var f=ratio-Math.floor(ratio);
 309  
 310                  if       (f>3/4) f=3/4;
 311                  else if  (f>2/3) f=2/3;
 312                  else if  (f>1/2) f=1/2;
 313                  else if  (f>1/3) f=1/3;
 314                  else if  (f>1/4) f=1/4;
 315                  else f=0;
 316  
 317                  ratio=Math.floor(ratio)+f;
 318  
 319                  if (ratio<0.1)
 320                      ratio=0.1;
 321  
 322  
 323                  if (this.method.indexOf('shrink')>=0 && ratio>1)
 324                      return;
 325  
 326                  if (this.method.indexOf('expand')>=0  && ratio<1)
 327                      return;
 328  
 329                  var destX = Math.floor(srcX*ratio+0.5);
 330                  var destY = Math.floor(srcY*ratio+0.5);
 331  
 332  /*                alert(
 333                      "max="+maxX.toString() + "x" + maxY.toString() + "\n" +
 334                        "src="+srcX.toString() + "x" + srcY.toString() + "\n" +
 335                        "offsetTopLeft="+this.imageObject.offsetTop.toString() + "x" + this.imageObject.offsetLeft.toString() + "\n" +
 336                      "imageWrap="+imageWrapX.toString() + "x" + imageWrapY.toString() + "\n" +
 337                      "dest="+destX.toString() + "x" + destY.toString() + "\n" +
 338                                                         "");//*/
 339  
 340                  // Change image size
 341                  if (this.rotate%2)
 342                  {
 343                      this.imageObject.width=destY;
 344                      this.imageObject.height=destX;
 345                  }
 346                  else
 347                  {
 348                      this.imageObject.width=destX;
 349                      this.imageObject.height=destY;
 350                  }
 351  
 352              }
 353          }
 354      }
 355  };
 356  
 357  function dalbum_showimg_resize(pageTableName,imageName,imagePlaceholder,imageWrap,width,height,method)
 358  {
 359      if (document.getElementById && document.getElementById(pageTableName))
 360       {
 361  
 362          // We DO NOT support Mozilla below 1,0
 363           if (navigator.userAgent.indexOf("Gecko")!=-1)
 364           {
 365              var n=navigator.userAgent.indexOf("rv:");
 366              if (n!=-1)
 367              {
 368                  var v=parseFloat(navigator.userAgent.substring(n+3));
 369                  if (v<1.0)
 370                      return;
 371              }
 372           }
 373          dalbumShowImagePage.pageTableObject=document.getElementById(pageTableName);
 374  
 375          var nRot=0;
 376          if (imageName!=null && imageName!="")
 377          {
 378              dalbumShowImagePage.imageObject=document.getElementById(imageName);
 379              dalbumShowImagePage.imagePlaceholder=document.getElementById(imagePlaceholder);
 380              dalbumShowImagePage.imageWrap=document.getElementById(imageWrap);
 381              dalbumShowImagePage.method=method;
 382  
 383              var image=dalbumShowImagePage.imageObject;
 384              if (image &&
 385                  image.filters &&
 386                  image.filters.item['DXImageTransform.Microsoft.BasicImage'] &&
 387                  image.filters.item['DXImageTransform.Microsoft.BasicImage'].enabled)
 388              {
 389                  nRot=image.filters.item['DXImageTransform.Microsoft.BasicImage'].rotation;
 390              }
 391              dalbumShowImagePage.rotate=nRot;
 392  
 393              if (image)
 394              {
 395                  if (nRot%2)
 396                  {
 397                      dalbumShowImagePage.imageWidth=height;
 398                      dalbumShowImagePage.imageHeight=width;
 399                  }
 400                  else
 401                  {
 402                      dalbumShowImagePage.imageWidth=width;
 403                      dalbumShowImagePage.imageHeight=height;
 404                  }
 405              }
 406          }
 407  
 408          dalbumShowImagePage.resizeImage();
 409  
 410          dalbumShowImagePage.origWidth=dalbumShowImagePage.getWindowWidth();
 411          dalbumShowImagePage.origHeight=dalbumShowImagePage.getWindowHeight();
 412  
 413          if (nRot%2==0)
 414          {
 415              dalbumShowImagePage.onResize();
 416              window.onresize= function(e)
 417              {
 418                  if (dalbumShowImagePage.origWidth!=dalbumShowImagePage.getWindowWidth() ||
 419                      dalbumShowImagePage.origHeight!=dalbumShowImagePage.getWindowHeight())
 420                  {
 421                      dalbumShowImagePage.origWidth=dalbumShowImagePage.getWindowWidth();
 422                      dalbumShowImagePage.origHeight=dalbumShowImagePage.getWindowHeight();
 423                      dalbumShowImagePage.onResize();
 424  
 425                      if (navigator.userAgent.indexOf("Opera")==-1)
 426                          setTimeout('window.location.reload();',2000);
 427                  }
 428              }
 429          }
 430       }
 431  }


[ Powered by PHPXref - Served by Debian GNU/Linux ]