Advertisement
Guest User

Untitled

a guest
Apr 18th, 2011
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Shutter Reloaded for NextGEN Gallery
  3. http://www.laptoptips.ca/javascripts/shutter-reloaded/
  4. Version: 1.3.1
  5. Copyright (C) 2007-2008  Andrew Ozz
  6. Released under the GPL, http://www.gnu.org/copyleft/gpl.html
  7.  
  8. Acknowledgement: some ideas are from: Shutter by Andrew Sutherland - http://code.jalenack.com, WordPress - http://wordpress.org, Lightbox by Lokesh Dhakar - http://www.huddletogether.com, the icons are from Crystal Project Icons, Everaldo Coelho, http://www.everaldo.com
  9.  
  10. */
  11.  
  12. shutterOnload = function(){shutterReloaded.init('sh');}
  13.  
  14. if (typeof shutterOnload == 'function') {
  15.     if ('undefined' != typeof jQuery) jQuery(document).ready(function(){shutterOnload();});
  16.     else if( typeof window.onload != 'function' ) window.onload = shutterOnload;
  17.     else {oldonld = window.onload;window.onload = function(){if(oldonld){oldonld();};shutterOnload();}};
  18. }
  19.  
  20. shutterReloaded = {
  21.  
  22.     I : function (a) {
  23.         return document.getElementById(a);
  24.     },
  25.  
  26.     settings : function() {
  27.         var t = this, s = shutterSettings;
  28.  
  29.         t.imageCount = s.imageCount || 0;
  30.         t.msgLoading = s.msgLoading || 'l o a d i n g . . .';
  31.         t.msgClose = s.msgClose || 'Click to Close';
  32.     },
  33.  
  34.     init : function (a) {
  35.         var t = this, L, T, ext, i, m, setid, inset, shfile, shMenuPre, k, img;
  36.         shutterLinks = {}, shutterSets = {};
  37.         if ( 'object' != typeof shutterSettings ) shutterSettings = {};
  38.  
  39.         for ( i = 0; i < document.links.length; i++ ) {
  40.             L = document.links[i];
  41.             ext = ( L.href.indexOf('?') == -1 ) ? L.href.slice(-4).toLowerCase() : L.href.substring( 0, L.href.indexOf('?') ).slice(-4).toLowerCase();
  42.             if ( ext != '.jpg' && ext != '.png' && ext != '.gif' && ext != 'jpeg' ) continue;
  43.             if ( a == 'sh' && L.className.toLowerCase().indexOf('shutter') == -1 ) continue;
  44.             if ( a == 'lb' && L.rel.toLowerCase().indexOf('lightbox') == -1 ) continue;
  45.  
  46.             if ( L.className.toLowerCase().indexOf('shutterset') != -1 )
  47.             setid = L.className.replace(/\s/g, '_');            
  48.             else if ( L.rel.toLowerCase().indexOf('lightbox[') != -1 )
  49.             setid = L.rel.replace(/\s/g, '_');
  50.             else setid = 0, inset = -1;
  51.            
  52.             if( setid ) {
  53.                 if ( ! shutterSets[setid] ) shutterSets[setid] = [];
  54.                     inset = shutterSets[setid].push(i);
  55.             }
  56.            
  57.             shfile = L.href.slice(L.href.lastIndexOf('/')+1);
  58.             T = ( L.title && L.title != shfile ) ? L.title : '';
  59.            
  60.             shutterLinks[i] = {link:L.href,num:inset,set:setid,title:T}
  61.             L.onclick = new Function('shutterReloaded.make("' + i + '");return false;');
  62.         }
  63.  
  64.         t.settings();
  65.  
  66.     },
  67.  
  68.     make : function(ln,fs) {
  69.         var t = this, prev, next, prevlink = '', nextlink = '', previmg, nextimg, D, S, W, fsarg = -1, imgNum, NavBar;
  70.  
  71.         if ( ! t.Top ) {
  72.             if ( typeof window.pageYOffset != 'undefined' ) t.Top = window.pageYOffset;
  73.             else t.Top = (document.documentElement.scrollTop > 0) ? document.documentElement.scrollTop : document.body.scrollTop;
  74.         }
  75.  
  76.         if ( typeof t.pgHeight == 'undefined' )
  77.             t.pgHeight = Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
  78.  
  79.         if ( fs ) t.FS = ( fs > 0 ) ? 1 : 0;
  80.         else t.FS = shutterSettings.FS || 0;
  81.  
  82.         if ( t.resizing ) t.resizing = null;
  83.         window.onresize = new Function('shutterReloaded.resize("'+ln+'");');
  84.  
  85.        document.documentElement.style.overflow = 'hidden';
  86.         if ( ! t.VP ) {
  87.             t._viewPort();
  88.             t.VP = true;
  89.         }
  90.  
  91.         if ( ! (S = t.I('shShutter')) ) {
  92.             S = document.createElement('div');
  93.             S.setAttribute('id','shShutter');
  94.             document.getElementsByTagName('body')[0].appendChild(S);
  95.             t.hideTags();
  96.         }
  97.  
  98.         if ( ! (D = t.I('shDisplay')) ) {
  99.             D = document.createElement('div');
  100.             D.setAttribute('id','shDisplay');
  101.             D.style.top = t.Top + 'px';
  102.             document.getElementsByTagName('body')[0].appendChild(D);
  103.         }
  104.  
  105.         S.style.height = t.pgHeight + 'px';
  106.  
  107.         var dv = t.textBtns ? ' | ' : '';
  108.         if ( shutterLinks[ln].num > 1 ) {
  109.             prev = shutterSets[shutterLinks[ln].set][shutterLinks[ln].num - 2];
  110.             prevlink = '<a href="#" onclick="shutterReloaded.make('+prev+');return false">&lt;&lt;</a>'+dv;
  111.             previmg = new Image();
  112.             previmg.src = shutterLinks[prev].link;
  113.         } else {
  114.             prevlink = '';
  115.         }
  116.  
  117.         if ( shutterLinks[ln].num != -1 && shutterLinks[ln].num < (shutterSets[shutterLinks[ln].set].length) ) {
  118.             next = shutterSets[shutterLinks[ln].set][shutterLinks[ln].num];
  119.             nextlink = '<a href="#" onclick="shutterReloaded.make('+next+');return false">&gt;&gt;</a>'+dv;
  120.             nextimg = new Image();
  121.             nextimg.src = shutterLinks[next].link;
  122.         } else {
  123.             nextlink = '';
  124.         }
  125.  
  126.         // close button creator
  127.        
  128.         closebtn = '<a href="#" onclick="shutterReloaded.hideShutter();"><img src="http://www.mrsherskin.com/image-assets/close_button.gif" alt="Click to close" /></a>';
  129.        
  130.         imgNum = ( (shutterLinks[ln].num > 0) && t.imageCount ) ? '<div id="shCount">&nbsp;(&nbsp;' + shutterLinks[ln].num + '&nbsp;/&nbsp;' + shutterSets[shutterLinks[ln].set].length + '&nbsp;)&nbsp;</div>' : '';
  131.  
  132.         NavBar = '<div id="shTitle"><div id="shPrev">' + prevlink + '</div><div id="shNext">' + nextlink + '</div><div id="shName">' + shutterLinks[ln].title + '</div>' + imgNum + '</div>';
  133.  
  134.         // modified for close button and click-close removed
  135.        
  136.     D.innerHTML = '<div id="shWrap"><div id="imgContainer"><div id="clbtn">' + closebtn + '</div><img src="'+shutterLinks[ln].link+'" id="shTopImg" onload="shutterReloaded.showImg();" /></div>' + NavBar +'</div>';
  137.        
  138.        
  139.         //Google Chrome 4.0.249.78 bug for onload attribute
  140.         document.getElementById('shTopImg').src = shutterLinks[ln].link;
  141.        
  142.         window.setTimeout(function(){shutterReloaded.loading();},2000);
  143.     },
  144.  
  145.     loading : function() {
  146.         var t = this, S, WB, W;
  147.         if ( (W = t.I('shWrap')) && W.style.visibility == 'visible' ) return;
  148.         if ( ! (S = t.I('shShutter')) ) return;
  149.         if ( t.I('shWaitBar') ) return;
  150.         WB = document.createElement('div');
  151.         WB.setAttribute('id','shWaitBar');
  152.         WB.style.top = t.Top + 'px';
  153.         WB.innerHTML = t.msgLoading + ' . . .';
  154.         S.appendChild(WB);
  155.     },
  156.  
  157.     hideShutter : function() {
  158.         var t = this, D, S;
  159.         if ( D = t.I('shDisplay') ) D.parentNode.removeChild(D);
  160.         if ( S = t.I('shShutter') ) S.parentNode.removeChild(S);
  161.         t.hideTags(true);
  162.         window.scrollTo(0,t.Top);
  163.         window.onresize = t.FS = t.Top = t.VP = null;
  164.         document.documentElement.style.overflow = '';
  165.     },
  166.  
  167.     resize : function(ln) {
  168.         var t = this;
  169.  
  170.         if ( t.resizing ) return;
  171.         if ( ! t.I('shShutter') ) return;
  172.         var W = t.I('shWrap');
  173.         if ( W ) W.style.visibility = 'hidden';
  174.  
  175.         window.setTimeout(function(){shutterReloaded.resizing = null},500);
  176.         window.setTimeout(new Function('shutterReloaded.VP = null;shutterReloaded.make("'+ln+'");'),100);
  177.         t.resizing = true;
  178.     },
  179.  
  180.     _viewPort : function() {
  181.         var t = this;
  182.         var wiH = window.innerHeight ? window.innerHeight : 0;
  183.         var dbH = document.body.clientHeight ? document.body.clientHeight : 0;
  184.         var deH = document.documentElement ? document.documentElement.clientHeight : 0;
  185.  
  186.         if( wiH > 0 ) {
  187.             t.wHeight = ( (wiH - dbH) > 1 && (wiH - dbH) < 30 ) ? dbH : wiH;
  188.             t.wHeight = ( (t.wHeight - deH) > 1 && (t.wHeight - deH) < 30 ) ? deH : t.wHeight;
  189.         } else t.wHeight = ( deH > 0 ) ? deH : dbH;
  190.  
  191.         var deW = document.documentElement ? document.documentElement.clientWidth : 0;
  192.         var dbW = window.innerWidth ? window.innerWidth : document.body.clientWidth;
  193.         t.wWidth = ( deW > 1 ) ? deW : dbW;
  194.     },
  195.  
  196.     showImg : function() {
  197.         var t = this, S = t.I('shShutter'), D = t.I('shDisplay'), TI = t.I('shTopImg'), T = t.I('shTitle'), NB = t.I('shNavBar'), W, WB, wHeight, wWidth, shHeight, maxHeight, itop, mtop, resized = 0;
  198.  
  199.         if ( ! S ) return;
  200.         if ( (W = t.I('shWrap')) && W.style.visibility == 'visible' ) return;
  201.         if ( WB = t.I('shWaitBar') ) WB.parentNode.removeChild(WB);
  202.  
  203.         S.style.width = D.style.width = '';
  204.         T.style.width = (TI.width - 4) + 'px';
  205.  
  206.         shHeight = t.wHeight - 50;
  207.  
  208.         if ( t.FS ) {
  209.             if ( TI.width > (t.wWidth - 10) )
  210.             S.style.width = D.style.width = TI.width + 10 + 'px';
  211.             document.documentElement.style.overflow = 'hidden';
  212.         } else {
  213.             window.scrollTo(0,t.Top);
  214.             if ( TI.height > shHeight ) {
  215.                 TI.width = TI.width * (shHeight / TI.height);
  216.                 TI.height = shHeight;
  217.                 resized = 1;
  218.             }
  219.             if ( TI.width > (t.wWidth - 16) ) {
  220.                 TI.height = TI.height * ((t.wWidth - 16) / TI.width);
  221.                 TI.width = t.wWidth - 16;
  222.                 resized = 1;
  223.             }
  224.             T.style.width = (TI.width - 4) + 'px';
  225.         }
  226.  
  227.         maxHeight = t.Top + TI.height + 10;
  228.         if ( maxHeight > t.pgHeight ) S.style.height = maxHeight + 'px';
  229.         window.scrollTo(0,t.Top);
  230.  
  231.         itop = (shHeight - TI.height) * 0.45;
  232.         mtop = (itop > 3) ? Math.floor(itop) : 3;
  233.         D.style.top = t.Top + mtop + 'px';
  234.         W.style.visibility = 'visible';
  235.        
  236.         //init zoom
  237.         jQuery(TI).addpowerzoom(
  238.         { defaultpower:2, powerrange: [2, 5], magnifiersize: [300,300] } );
  239.     },
  240.  
  241.     hideTags : function(arg) {
  242.         var sel = document.getElementsByTagName('select');
  243.         var obj = document.getElementsByTagName('object');
  244.         var emb = document.getElementsByTagName('embed');
  245.         var ifr = document.getElementsByTagName('iframe');
  246.  
  247.         var vis = ( arg ) ? 'visible' : 'hidden';
  248.  
  249.         for (i = 0; i < sel.length; i++) sel[i].style.visibility = vis;
  250.         for (i = 0; i < obj.length; i++) obj[i].style.visibility = vis;
  251.         for (i = 0; i < emb.length; i++) emb[i].style.visibility = vis;
  252.         for (i = 0; i < ifr.length; i++) ifr[i].style.visibility = vis;
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement