PageSourceSearch

https://www.nidus.lt/site/js/photoswipe/photoswipe.js

js nidus.lt collected 2026-10-04 19:57:50 UTC 5,773 bytes, 273 lines download raw bytes

1// Copyright (c) %%year%% by Code Computerlove (http://www.codecomputerlove.com)
2// Licensed under the MIT license
3// version: %%version%%
4
5(function(window, Util){
6	
7	
8	Util.registerNamespace('Code.PhotoSwipe');
9	var PhotoSwipe = window.Code.PhotoSwipe;
10	
11	
12	
13	PhotoSwipe.CssClasses = {
14		buildingBody: 'ps-building',
15		activeBody: 'ps-active'
16	};
17	
18	
19	
20	PhotoSwipe.EventTypes = {
21	
22		onBeforeShow: 'PhotoSwipeOnBeforeShow',
23		onShow: 'PhotoSwipeOnShow',
24		onBeforeHide: 'PhotoSwipeOnBeforeHide',
25		onHide: 'PhotoSwipeOnHide',
26		onDisplayImage: 'PhotoSwipeOnDisplayImage',
27		onResetPosition: 'PhotoSwipeOnResetPosition',
28		onSlideshowStart: 'PhotoSwipeOnSlideshowStart',
29		onSlideshowStop: 'PhotoSwipeOnSlideshowStop',
30		onTouch: 'PhotoSwipeOnTouch',
31		onBeforeCaptionAndToolbarShow: 'PhotoSwipeOnBeforeCaptionAndToolbarShow',
32		onCaptionAndToolbarShow: 'PhotoSwipeOnCaptionAndToolbarShow',
33		onBeforeCaptionAndToolbarHide: 'PhotoSwipeOnBeforeCaptionAndToolbarHide',
34		onCaptionAndToolbarHide: 'PhotoSwipeOnCaptionAndToolbarHide',
35		onToolbarTap: 'PhotoSwipeOnToolbarTap',
36		onBeforeZoomPanRotateShow: 'PhotoSwipeOnBeforeZoomPanRotateShow',
37		onZoomPanRotateShow: 'PhotoSwipeOnZoomPanRotateShow',
38		onBeforeZoomPanRotateHide: 'PhotoSwipeOnBeforeZoomPanRotateHide',
39		onZoomPanRotateHide: 'PhotoSwipeOnZoomPanRotateHide',
40		onZoomPanRotateTransform: 'PhotoSwipeOnZoomPanRotateTransform'
41	
42	};
43	
44	
45	
46	PhotoSwipe.instances = [];
47	PhotoSwipe.activeInstances = [];
48	
49	
50	
51	/*
52	 * Function: Code.PhotoSwipe.setActivateInstance
53	 */
54	PhotoSwipe.setActivateInstance = function(instance){
55		
56		// Can only have one instance per target (i.e. window or div)
57		var index = Util.arrayIndexOf(instance.settings.target, PhotoSwipe.activeInstances, 'target');
58		if (index > -1){
59			throw 'Code.PhotoSwipe.activateInstance: Unable to active instance as another instance is already active for this target';
60		}
61		PhotoSwipe.activeInstances.push({
62			target: instance.settings.target,
63			instance: instance
64		});
65			
66	};
67	
68	
69	
70	/*
71	 * Function: Code.PhotoSwipe.unsetActivateInstance
72	 */
73	PhotoSwipe.unsetActivateInstance = function(instance){
74		
75		var index = Util.arrayIndexOf(instance, PhotoSwipe.activeInstances, 'instance');
76		PhotoSwipe.activeInstances.splice(index, 1);
77		
78	};
79	
80	
81	
82	/*
83	 * Function: Code.PhotoSwipe.attach
84	 */
85	PhotoSwipe.attach = function(images, options, id){
86		
87		var i, j, instance, image;
88		
89		instance = PhotoSwipe.createInstance(images, options, id);
90		
91		// Add click event handlers if applicable
92		for (i=0, j=images.length; i<j; i++){
93			
94			image = images[i];
95			if (!Util.isNothing(image.nodeType)){
96				if (image.nodeType === 1){
97					// DOM element
98					image.__photoSwipeClickHandler = PhotoSwipe.onTriggerElementClick.bind(instance);
99					Util.Events.remove(image, 'click', image.__photoSwipeClickHandler);
100					Util.Events.add(image, 'click', image.__photoSwipeClickHandler);
101				}
102			}
103			
104		}
105		
106		return instance;
107		
108	};
109	
110	
111	
112	/*
113	 * jQuery plugin
114	 */
115	if (window.jQuery){
116		
117		window.jQuery.fn.photoSwipe = function(options, id){
118		
119			return PhotoSwipe.attach(this, options, id);
120			
121		};
122		
123		
124	}
125	
126	
127	
128	/*
129	 * Function: Code.PhotoSwipe.detatch
130	 */
131	PhotoSwipe.detatch = function(instance){
132	
133		var i, j, image;
134		
135		// Remove click event handlers if applicable
136		for (i=0, j=instance.originalImages.length; i<j; i++){
137			
138			image = instance.originalImages[i];
139			if (!Util.isNothing(image.nodeType)){
140				if (image.nodeType === 1){
141					// DOM element
142					Util.Events.remove(image, 'click', image.__photoSwipeClickHandler);
143					delete image.__photoSwipeClickHandler;
144				}
145			}
146			
147		}
148		
149		PhotoSwipe.disposeInstance(instance);
150	
151	};
152	
153	
154	
155	/*
156	 * Function: Code.PhotoSwipe.createInstance
157	 */
158	PhotoSwipe.createInstance = function(images, options, id){
159		
160		var i, instance, image;
161		
162		if (Util.isNothing(images)){
163			throw 'Code.PhotoSwipe.attach: No images passed.';
164		}
165		
166		if (!Util.isLikeArray(images)){
167			throw 'Code.PhotoSwipe.createInstance: Images must be an array of elements or image urls.';
168		}
169		
170		if (images.length < 1){
171			throw 'Code.PhotoSwipe.createInstance: No images to passed.';
172		}
173		
174		options = Util.coalesce(options, { });
175		
176		instance = PhotoSwipe.getInstance(id);
177		
178		if (Util.isNothing(instance)){
179			instance = new PhotoSwipe.PhotoSwipeClass(images, options, id);
180			PhotoSwipe.instances.push(instance);
181		}
182		else{
183			throw 'Code.PhotoSwipe.createInstance: Instance with id "' + id +' already exists."';
184		}
185		
186		return instance;
187	
188	};
189	
190	
191	
192	/*
193	 * Function: Code.PhotoSwipe.disposeInstance
194	 */
195	PhotoSwipe.disposeInstance = function(instance){
196		
197		var instanceIndex = PhotoSwipe.getInstanceIndex(instance);
198		
199		if (instanceIndex < 0){
200			throw 'Code.PhotoSwipe.disposeInstance: Unable to find instance to dispose.';
201		}
202		
203		instance.dispose();
204		PhotoSwipe.instances.splice(instanceIndex, 1);
205		instance = null;
206	
207	};
208	
209	
210	
211	/*
212	 * Function: onTriggerElementClick
213	 */
214	PhotoSwipe.onTriggerElementClick = function(e){
215	
216		e.preventDefault();
217		
218		var instance = this;
219		instance.show(e.currentTarget);
220	
221	};
222	
223	
224	
225	/*
226	 * Function: Code.PhotoSwipe.getInstance
227	 */
228	PhotoSwipe.getInstance = function(id){
229		
230		var i, j, instance;
231		
232		for (i=0, j=PhotoSwipe.instances.length; i<j; i++){
233			
234			instance = PhotoSwipe.instances[i];
235			if (instance.id === id){
236				return instance;
237			}
238			
239		}
240		
241		return null;
242		
243	};
244	
245	
246	
247	/*
248	 * Function: Code.PhotoSwipe.getInstanceIndex
249	 */
250	PhotoSwipe.getInstanceIndex = function(instance){
251		
252		var i, j, instanceIndex = -1;
253		
254		for (i=0, j=PhotoSwipe.instances.length; i<j; i++){
255		
256			if (PhotoSwipe.instances[i] === instance){
257				instanceIndex = i;
258				break;
259			}
260		
261		}
262		
263		return instanceIndex;
264		
265	};
266	
267	
268	
269}
270(
271	window, 
272	window.Code.Util
273));

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.