PageSourceSearch

https://thedanplan.com/blog/wp-content/plugins/nextgen-gallery/shutter/shutter-reloaded.js?ver=1.3.3

js thedanplan.com collected 2026-09-24 21:52:05 UTC 9,986 bytes, 277 lines download raw bytes

1/*
2Shutter Reloaded for NextGEN Gallery
3http://www.laptoptips.ca/javascripts/shutter-reloaded/
4Version: 1.3.3
5Copyright (C) 2007-2008  Andrew Ozz (Modification by Alex Rabe)
6Released under the GPL, http://www.gnu.org/copyleft/gpl.html
7
8Acknowledgement: 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
12shutterOnload = function(){shutterReloaded.init('sh');}
13
14if (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
20shutterReloaded = {
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        // If the screen orientation is defined we are in a modern mobile OS
40        t.mobileOS = typeof orientation != 'undefined' ? true : false;
41                
42		for ( i = 0; i < document.links.length; i++ ) {
43			L = document.links[i];
44			ext = ( L.href.indexOf('?') == -1 ) ? L.href.slice(-4).toLowerCase() : L.href.substring( 0, L.href.indexOf('?') ).slice(-4).toLowerCase();
45			if ( ext != '.jpg' && ext != '.png' && ext != '.gif' && ext != 'jpeg' ) continue;
46			if ( a == 'sh' && L.className.toLowerCase().indexOf('shutter') == -1 ) continue;
47			if ( a == 'lb' && L.rel.toLowerCase().indexOf('lightbox') == -1 ) continue;
48
49			if ( L.className.toLowerCase().indexOf('shutterset') != -1 )
50			setid = L.className.replace(/\s/g, '_');			
51			else if ( L.rel.toLowerCase().indexOf('lightbox[') != -1 )
52			setid = L.rel.replace(/\s/g, '_');
53			else setid = 0, inset = -1;
54			
55			if( setid ) {
56				if ( ! shutterSets[setid] ) shutterSets[setid] = [];
57					inset = shutterSets[setid].push(i);
58			}
59			
60			shfile = L.href.slice(L.href.lastIndexOf('/')+1);
61			T = ( L.title && L.title != shfile ) ? L.title : '';
62			
63			shutterLinks[i] = {link:L.href,num:inset,set:setid,title:T}
64			L.onclick = new Function('shutterReloaded.make("' + i + '");return false;');
65		}
66
67		t.settings();
68
69	},
70
71	make : function(ln,fs) {
72		var t = this, prev, next, prevlink = '', nextlink = '', previmg, nextimg, D, S, W, fsarg = -1, imgNum, NavBar;
73
74		if ( ! t.Top ) {
75			if ( typeof window.pageYOffset != 'undefined' ) t.Top = window.pageYOffset;
76			else t.Top = (document.documentElement.scrollTop > 0) ? document.documentElement.scrollTop : document.body.scrollTop;
77		}
78
79		if ( typeof t.pgHeight == 'undefined' )
80			t.pgHeight = Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
81
82		if ( fs ) t.FS = ( fs > 0 ) ? 1 : 0;
83		else t.FS = shutterSettings.FS || 0;
84
85		if ( t.resizing ) t.resizing = null;
86        
87        // resize event if window or orientation changed (i.e. iOS)
88        if(t.mobileOS == true)
89            window.onorientationchange = new Function('shutterReloaded.resize("'+ln+'");');
90        else
91            window.onresize = new Function('shutterReloaded.resize("'+ln+'");');
92
93		document.documentElement.style.overflowX = 'hidden';
94		if ( ! t.VP ) {
95			t._viewPort();
96			t.VP = true;
97		}
98
99		if ( ! (S = t.I('shShutter')) ) {
100			S = document.createElement('div');
101			S.setAttribute('id','shShutter');
102			document.getElementsByTagName('body')[0].appendChild(S);
103			t.hideTags();
104		}
105
106		if ( ! (D = t.I('shDisplay')) ) {
107			D = document.createElement('div');
108			D.setAttribute('id','shDisplay');
109			D.style.top = t.Top + 'px';
110			document.getElementsByTagName('body')[0].appendChild(D);
111		}
112
113		S.style.height = t.pgHeight + 'px';
114
115		var dv = t.textBtns ? ' | ' : '';
116		if ( shutterLinks[ln].num > 1 ) {
117			prev = shutterSets[shutterLinks[ln].set][shutterLinks[ln].num - 2];
118			prevlink = '<a href="#" id="prevpic" onclick="shutterReloaded.make('+prev+');return false">&lt;&lt;</a>'+dv;
119			previmg = new Image();
120			previmg.src = shutterLinks[prev].link;
121		} else {
122			prevlink = '';
123		}
124
125		if ( shutterLinks[ln].num != -1 && shutterLinks[ln].num < (shutterSets[shutterLinks[ln].set].length) ) {
126			next = shutterSets[shutterLinks[ln].set][shutterLinks[ln].num];
127			nextlink = '<a href="#" id="nextpic" onclick="shutterReloaded.make('+next+');return false">&gt;&gt;</a>'+dv;
128			nextimg = new Image();
129			nextimg.src = shutterLinks[next].link;
130		} else {
131			nextlink = '';
132		}
133
134		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>' : '';
135
136		NavBar = '<div id="shTitle"><div id="shPrev">' + prevlink + '</div><div id="shNext">' + nextlink + '</div><div id="shName">' + shutterLinks[ln].title + '</div>' + imgNum + '</div>';
137
138		D.innerHTML = '<div id="shWrap"><img src="'+shutterLinks[ln].link+'" id="shTopImg" title="' + t.msgClose + '" onload="shutterReloaded.showImg();" onclick="shutterReloaded.hideShutter();" />' + NavBar +'</div>';
139		
140		document.onkeydown = function(event){shutterReloaded.handleArrowKeys(event);};
141		//Google Chrome 4.0.249.78 bug for onload attribute
142		document.getElementById('shTopImg').src = shutterLinks[ln].link;
143		
144		window.setTimeout(function(){shutterReloaded.loading();},1000);
145	},
146
147	loading : function() {
148		var t = this, S, WB, W;
149		if ( (W = t.I('shWrap')) && W.style.visibility == 'visible' ) return;
150		if ( ! (S = t.I('shShutter')) ) return;
151		if ( t.I('shWaitBar') ) return;
152		WB = document.createElement('div');
153		WB.setAttribute('id','shWaitBar');
154		WB.style.top = t.Top + 'px';
155        WB.style.marginTop =(t.pgHeight/2) + 'px'
156		WB.innerHTML = t.msgLoading;
157		S.appendChild(WB);
158	},
159
160	hideShutter : function() {
161		var t = this, D, S;
162		if ( D = t.I('shDisplay') ) D.parentNode.removeChild(D);
163		if ( S = t.I('shShutter') ) S.parentNode.removeChild(S);
164		t.hideTags(true);
165		window.scrollTo(0,t.Top);
166		window.onresize = t.FS = t.Top = t.VP = null;
167		document.documentElement.style.overflowX = '';
168		document.onkeydown = null;
169	},
170
171	resize : function(ln) {
172		var t = this;
173
174		if ( t.resizing ) return;
175		if ( ! t.I('shShutter') ) return;
176		var W = t.I('shWrap');
177		if ( W ) W.style.visibility = 'hidden';
178
179		window.setTimeout(function(){shutterReloaded.resizing = null},500);
180		window.setTimeout(new Function('shutterReloaded.VP = null;shutterReloaded.make("'+ln+'");'),100);
181		t.resizing = true;
182	},
183
184	_viewPort : function() {
185		var t = this;
186		var wiH = window.innerHeight ? window.innerHeight : 0;
187		var dbH = document.body.clientHeight ? document.body.clientHeight : 0;
188		var deH = document.documentElement ? document.documentElement.clientHeight : 0;
189
190		if( wiH > 0 ) {
191			t.wHeight = ( (wiH - dbH) > 1 && (wiH - dbH) < 30 ) ? dbH : wiH;
192			t.wHeight = ( (t.wHeight - deH) > 1 && (t.wHeight - deH) < 30 ) ? deH : t.wHeight;
193		} else t.wHeight = ( deH > 0 ) ? deH : dbH;
194
195		var deW = document.documentElement ? document.documentElement.clientWidth : 0;
196		var dbW = window.innerWidth ? window.innerWidth : document.body.clientWidth;
197		t.wWidth = ( deW > 1 ) ? deW : dbW;
198	},
199
200	showImg : function() {
201		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;
202
203		if ( ! S ) return;
204		if ( (W = t.I('shWrap')) && W.style.visibility == 'visible' ) return;
205		if ( WB = t.I('shWaitBar') ) WB.parentNode.removeChild(WB);
206
207		S.style.width = D.style.width = '';
208		T.style.width = (TI.width - 4) + 'px';
209
210		shHeight = t.wHeight - 50;
211
212		if ( t.FS ) {
213			if ( TI.width > (t.wWidth - 10) )
214			S.style.width = D.style.width = TI.width + 10 + 'px';
215			document.documentElement.style.overflowX = '';
216		} else {
217			window.scrollTo(0,t.Top);
218			if ( TI.height > shHeight ) {
219				TI.width = TI.width * (shHeight / TI.height);
220				TI.height = shHeight;
221				resized = 1;
222			}
223			if ( TI.width > (t.wWidth - 16) ) {
224				TI.height = TI.height * ((t.wWidth - 16) / TI.width);
225				TI.width = t.wWidth - 16;
226				resized = 1;
227			}
228			T.style.width = (TI.width - 4) + 'px';
229		}
230
231		maxHeight = t.Top + TI.height + 10;
232		if ( maxHeight > t.pgHeight ) S.style.height = maxHeight + 'px';
233		window.scrollTo(0,t.Top);
234
235		itop = (shHeight - TI.height) * 0.45;
236		mtop = (itop > 3) ? Math.floor(itop) : 3;
237		D.style.top = t.Top + mtop + 'px';
238		W.style.visibility = 'visible';
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	
255	handleArrowKeys : function(e) {
256	    var code = 0;
257	    if (!e) var e = window.event
258	    	if (e.keyCode) code = e.keyCode;
259	    	else if (e.which) code = e.which;
260	    	
261		var nextlink = document.getElementById('prevpic');
262		var prevlink = document.getElementById('nextpic');
263		var closelink = document.getElementById('shTopImg');
264	
265		switch (code) {
266		    case 39:
267			if (prevlink) prevlink.onclick();
268			break;    
269		    case 37:
270			if (nextlink) nextlink.onclick();
271			break;    
272		    case 27:
273			if (closelink) closelink.onclick();
274			break;    
275		 }
276	}
277}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.