PageSourceSearch

https://www.crockpot.pl/modules/ajaxzoom/axZm/extensions/jquery.axZm.imageCropLoad.js

js crockpot.pl collected 2026-09-26 20:35:40 UTC 14,892 bytes, 490 lines download raw bytes

1/*!
2* Plugin: jQuery AJAX-ZOOM, jquery.axZm.imageCropLoad.js
3* Copyright: Copyright (c) 2010-2019 Vadim Jacobi
4* License Agreement: http://www.ajax-zoom.com/index.php?cid=download
5* Extension Version: 2.12
6* Extension Date: 2019-03-09
7* URL: https://www.ajax-zoom.com
8* Example: https://www.ajax-zoom.com/examples/example35_clean.php
9*/
10
11;(function($) {
12	var dta = {};
13
14	var consoleLog = function(msg, err) {
15		if (msg && window.console && window.console.log) {
16			if (err && window.console.error) {
17				window.console.error('AJAX-ZOOM :: ' + msg);
18			} else {
19				window.console.log('AJAX-ZOOM :: ' + msg);
20			}
21		}
22	};
23
24	if (!$.fn || !$.fn.jquery) {
25		consoleLog('Error, jQuery core is not loaded!', 1);
26		return;
27	}
28
29	// Get query string value
30	var getParameterByName = function(name) {
31		name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
32		var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
33		var results = regex.exec(location.search);
34		return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
35	};
36
37	var updateUrlParameter = function(url, param, value) {
38		var regex = new RegExp('('+param+'=)[^\&]+');
39		return url.replace( regex , '$1' + value);
40	};
41
42	$.axZmImageCropLoad = function(o) {
43		// Load json file with some error handling
44		var getJSONdataFromFile = function() {
45			var cropJsonURL = opt.cropJsonURL;
46
47			if (cropJsonURL) {
48				if (dta[cropJsonURL]) {
49					return proceedJSONdata(dta[cropJsonURL]);
50				}
51
52				//var url = cropJsonURL.replace(/[^a-zA-Z0-9-_:\/.?&=]/g, '');
53				//aZcR_jsFileName
54				$.ajax({
55					url: cropJsonURL,
56					dataType: 'json',
57					cache: false,
58					success: function(d) {
59						dta[dta] = d;
60						proceedJSONdata(d);
61					},
62					error: function(a) {
63 						var status = a.status;
64 						var txt = 'Error loading JSON file! ';
65						if (status == '200') {
66							consoleLog(txt + 'Loaded JSON file ('+cropJsonURL+') contains errors');
67						} else {
68							consoleLog(txt + 'An error '+a.status+' occurred while loading JSON from '+cropJsonURL, 1);
69						}
70					}
71				});
72			} else if (opt.cropJson) {
73				proceedJSONdata(opt.cropJson);
74			} else {
75				consoleLog('Error, no JSON data defined for crop thumbnails');
76			}
77		};
78
79		var setRemoveSelect = function() {
80			if ($.axZm) {
81				$.fn.axZm.addCallback('onZoomSpinPanOnce', function() {
82					var sell = opt.sliderID || opt.thumbsContainerID;
83					if (sell) {
84						if (sell.indexOf('#') === 0 || sell.indexOf('.') === 0) {
85							try {
86								$('li', $(sell)).removeClass('selected');
87							} catch(err) {}
88						} else {
89							$('li', $('#'+sell)).removeClass('selected');
90						}
91					}
92				});
93			}
94		};
95
96		// Click on thumb
97		var thumbClick = function(_this) {
98
99			if ($.axZm.spinMod && !$.axZm.spinPreloaded) {
100				if (!$.axZm.spinPreloading && $.axZm.spinNoInit.enabled == true) {
101					$.fn.axZm.spinPreload(function() {
102						$.fn.axZm.spinStop();
103						$('li', _this.parent()).removeClass('selected');
104						_this.addClass('selected');
105						thumbClick(_this);
106					});
107				}
108
109				return;
110			}
111
112			// Read data previously attached to the image
113			var azJcrop = _this.data('crop');
114
115			// handleDescr will be executed after spinTo or zoomTo
116			var handleDescr = function() {
117				if ($.isFunction(opt.handleTexts)) {
118					opt.handleTexts(azJcrop.title, azJcrop.descr, _this);
119					setRemoveSelect();
120				} else if (opt.handleTexts == 'default') {
121					if (!$.isFunction($.axZmEb)) {
122						if (typeof console != 'undefined') {
123							consoleLog('AJAX-ZOOM: jquery.axZm.expButton.js extension is not loaded');
124						}
125
126						return;
127					} else {
128						if (azJcrop.title || azJcrop.descr) {
129							var axZmEbOpt = {
130								title: azJcrop.title,
131								descr: azJcrop.descr,
132								gravity: azJcrop.ebGrav || 'top', // possible values: topLeft, top, topRight, bottomLeft, bottom, bottomRight, center
133								marginY: 5, // vertical margin depending on gravity
134								zoomSpinPanRemove: opt.sliderID || opt.thumbsContainerID, // removes button / layer when there is some action inside AJAX-ZOOM
135								autoOpen: false, // button opens instantly; if no tilte but descr is defined, autoOpen executes instantly
136								removeOnClose: false // removes button when extended state is closed
137							};
138
139							$.axZmEb($.extend(true, {}, axZmEbOpt, opt.cropAxZmEbOpt));
140						} else {
141							setRemoveSelect();
142						}
143					}
144				} else if ((azJcrop.title || azJcrop.descr) && typeof console != 'undefined') {
145					consoleLog('AJAX-ZOOM: no function defined to handle title and desciption');
146				}
147			};
148
149			//if ($('.axZmEb_Descr', $('#axZm_zoomLayer')).length) {
150			$.fn.axZm.tapShow();
151			//}
152
153			// Parameters from JSON as object
154			var zoomToParameters = {
155				x1: azJcrop.crop[0],
156				y1: azJcrop.crop[1],
157				x2: azJcrop.crop[2],
158				y2: azJcrop.crop[3],
159
160				// settings for effects
161				settings: {
162					speedMin: false,
163					zoomSpeed: azJcrop.zoom || opt.zoomToSpeed || $.axZm.zoomSpeed,
164					zoomSpeedMin: azJcrop.zoomMin || opt.zoomToMinSpeed,
165					effect: azJcrop.effect || 0
166				}
167			};
168
169			// Callback for 2D
170			var zoomToCallback = function() {
171				// Trigger AJAX-ZOOM API 
172				// http://www.ajax-zoom.com/index.php?cid=docs#api_zoomTo
173				$.fn.axZm.zoomTo(
174					// Add handleDescr as callback to the options object passed to zoomTo
175					$.extend(true, {}, zoomToParameters, {callback: handleDescr})
176				);
177			};
178
179			// 2D image and same image from gallery selected
180			if ($.axZm.zoomGA[$.axZm.zoomID]['img'] == azJcrop.imgName && !$.axZm.spinMod) {
181				/*$.extend(true, zoomToParameters, {
182					speed: Math.max($.axZm.zoomSpeed, 750),
183					speedZoomed: Math.max($.axZm.zoomSpeed, 750)
184				});*/
185
186				zoomToCallback();
187			} else {
188				// 360 / 3D mode
189				if ($.axZm.spinMod) {
190					$.fn.axZm.removeDragToSpinMsg();
191
192					// Trigger AJAX-ZOOM API 
193					// http://www.ajax-zoom.com/index.php?cid=docs#api_spinTo
194 					$.fn.axZm.spinTo(
195						azJcrop.imgName, 
196						azJcrop.spin || opt.spinToSpeed || 'auto',
197						opt.spinToMotion || null, // easing
198						handleDescr, // callback
199						zoomToParameters
200					);
201
202				} else {
203
204					// Trigger AJAX-ZOOM API 
205					// http://www.ajax-zoom.com/index.php?cid=docs#api_zoomSwitch
206					$.fn.axZm.zoomSwitch(azJcrop.imgName, null, true, null, zoomToCallback);
207				}
208			}
209		};
210
211		var newThumb = function(src) {
212			var newImg = new Image();
213			newImg.error = function() {
214				if (typeof console != 'undefined') {
215					consoleLog('Error loading thumb: '+src);
216				}
217			};
218
219			return $(newImg)
220			.css('visibility', 'hidden')
221			.axZmLoad(function() {
222				$(this)
223				.css({
224					visibility: '',
225					opacity: 0
226				})
227				.removeAttr('width')
228				.removeAttr('height')
229				.stop()
230				.animate({
231						opacity: 1
232					}, {
233						queue: false,
234						duration: 150
235					}
236				);
237			})
238			.attr('src', src);
239		};
240
241		// Process json data after loading
242		var proceedJSONdata = function(d) {
243			var thumbsContainerID;
244			var thumbsContainerUL;
245			var sliderID;
246			if (!$.isArray(d) || d.length == 0) {
247				consoleLog('Error loading crops. JSON passed from url ('+opt.cropJsonURL+') or defined as cropJson is not an array or array is empty');
248				return;
249			}
250
251			var arrCount = d.length; // number of crops from json
252			var i = 0; // counter
253
254			// Checks
255			if (opt.thumbsContainerID) {
256				thumbsContainerID = $('#'+opt.thumbsContainerID);
257				if (!thumbsContainerID.length) {
258					consoleLog('Error loading crops. Element with ID '+opt.thumbsContainerID+' was not found.', 1);
259					return;
260				}
261
262				// Ul present?
263				thumbsContainerUL = $('ul', thumbsContainerID);
264
265				if (!thumbsContainerUL.length) {
266					thumbsContainerUL = $('<ul />')
267					.addClass(opt.thumbsContainerUlClass)
268					.appendTo(thumbsContainerID);
269				}
270
271			} else if (opt.sliderID) {
272				sliderID = $('#'+opt.sliderID);
273
274				if (!sliderID.length) {
275					consoleLog('Error loading crops. Element with ID '+opt.sliderID+' was not found.', 1);
276					return;
277				}
278
279				// Slider not inited ?
280				if (!sliderID.data('axZmThumbSlider')) {
281					if (opt.sliderPar) {
282						sliderID.axZmThumbSlider(opt.sliderPar);
283					} else {
284						consoleLog('Error loading crops. axZmThumbSlider is not initiated, can not add thumbs to the slider!', 1);
285						return;
286					}
287				}
288				
289			}
290
291			$(d).each(function(m, o) {
292				var dataObj = {
293					thumbNumber: m+1,
294					crop: o.crop,
295					url: o.url ? o.url : null,
296					qString: o.qString ? o.qString : null,
297					zoomID: o.zoomID ? o.zoomID : null,
298					imgName: o.imgName,
299					contentLocation: o.contentLocation ? o.contentLocation : null,
300					title: o['title_'+opt.lang] || o.title || null,
301					thumbTitle: o['thumbTitle_'+opt.lang] || o.thumbTitle || null,
302					descr: o['descr_'+opt.lang] || o.descr || null,
303					effect: o.effect ? o.effect : 0,
304					ebGrav: o.ebGrav || 'top',
305					spin: o.spin || '2500',
306					zoom: o.zoom || 250,
307					zoomMin: o.zoomMin || 600
308				};
309
310				var imgCropperPath;
311
312				// Look where to get the croped thumb from
313				if (dataObj.url) {
314					imgCropperPath = dataObj.url;
315					dataObj.qString = imgCropperPath.replace(opt.installPath+'zoomLoad.php?', '')
316				} else if (dataObj.qString) {
317					imgCropperPath = opt.installPath+'zoomLoad.php?'+dataObj.qString;
318					dataObj.url = imgCropperPath;
319				} else if (o.contentLocation) {
320					// directly from cache 
321					imgCropperPath = o.contentLocation;
322				}
323
324				if (jQuery.isPlainObject(opt.cropImgParam)) {
325					$.each(opt.cropImgParam, function(kk, vv) {
326						if (kk && vv) {
327							imgCropperPath = updateUrlParameter(imgCropperPath, kk, vv);
328						}
329					});
330				}
331
332				if (!imgCropperPath) {
333					i++;
334					return;
335				}
336
337				dataObj.imgCropperPath = imgCropperPath;
338
339				// append thumbs to axZmThumbSlider
340				if (opt.sliderID && sliderID.length) {
341
342					// Create li ellement
343					var newLi = $('<li />')
344					// Set data attr to be able to fine it later over selector
345					.attr('data-cropNum', dataObj.thumbNumber)
346					// Crop data
347					.data('crop', dataObj)
348					// Append thumb image to li
349					.append(
350						newThumb(imgCropperPath)
351					);
352
353					// Description
354					if (opt.thumbsContainerLiDescr && dataObj.thumbTitle){
355						$('<div />').addClass('label').html(dataObj.thumbTitle).appendTo(newLi);
356					}
357
358					// Use axZmThumbSlider "appendThumb" API to add the thumb to the slider
359					sliderID.axZmThumbSlider(
360						'appendThumb',
361						newLi,
362						// Click event
363						function() {
364							thumbClick(newLi);
365						}
366					);
367
368				} else if (thumbsContainerID) {
369					// Append thumbs in UL LI structure to the container
370
371					var newLi = $('<li />')
372					// Custom css
373					.css(opt.thumbsContainerLiCss ? opt.thumbsContainerLiCss : {})
374					// Set data attr to be able to fine it later over selector
375					.attr('data-cropNum', dataObj.thumbNumber)
376					// Crop data
377					.data('crop', dataObj)
378					// Append thumb image to li
379					.append(
380						$('<img>')
381						.addClass('thumb')
382						.attr('src', imgCropperPath)
383					)
384					.bind('click', function() {
385						thumbClick(newLi);
386						$('li', thumbsContainerID).removeClass('selected hover');
387						newLi.addClass('selected');
388					})
389					.bind('mouseenter', function() {
390						if (!newLi.hasClass('selected')) {
391							newLi.addClass('hover');
392						}
393					})
394					.bind('mouseleave', function() {
395						if (!newLi.hasClass('selected')) {
396							newLi.removeClass('hover');
397						}
398					});
399
400					// For vertical align
401					$('<span />').text(' ').addClass('vAlign').appendTo(newLi);
402
403					// Description
404					if (opt.thumbsContainerLiDescr && dataObj.thumbTitle) {
405 						$('<div />').addClass('descr').html(dataObj.thumbTitle).appendTo(newLi);
406 					}
407
408					newLi.appendTo(thumbsContainerUL);
409				}
410
411			});
412		};
413
414		var getBrowserLanguage = function() {
415			var nav = window.navigator,
416				ret = 'en';
417
418			if (nav) {
419				if (nav.language) {
420					ret = nav.language;
421				} else if (nav.browserLanguage) {
422					ret = nav.browserLanguage;
423				} else if (nav.systemLanguage) {
424					ret = nav.systemLanguage;
425				} else if (nav.userLanguage) {
426					ret = nav.userLanguage;
427				}
428
429				ret = ret.toLowerCase().substring(0,2);
430			}
431
432			return ret;
433		};
434
435		// Options
436		var opt;
437
438		var def = {
439			installPath: 'auto', //Path to /axZm directory, e.g. /test/axZm/
440			cropJsonURL: '', // url of the json with crop data
441			cropJson: '', // data coming from elsewhere
442			cropImgParam: {
443				width: null,
444				height: null,
445				qual: null
446			},
447			sliderID: null, // ID of axZmThumbSlider
448			sliderPar: null, // Parameters of the thumb slider, see https://www.ajax-zoom.com/axZm/extensions/axZmThumbSlider/
449			lang: getBrowserLanguage(), // Language
450			thumbsContainerID: null, // ID of some container to put thumbs into (no slider)
451			thumbsContainerUlClass: 'azThumbCrop', // class which will be added to the UL element
452			thumbsContainerLiCss: {}, // quickly overwrite css e.g. margin of the li (thumbs)
453			thumbsContainerLiDescr: false, // add title from crop data to the thumb
454			zoomToSpeed: 250, // "base speed" for zooming in and out
455			zoomToMinSpeed: 600, // minimal duration of zoom in or out animation
456
457			// Optionally pass duration of spinning when clicked on the thumb. 
458			// When defined as a string, the value is interpreted as "base speed", 
459			// and it is reduced depending on the difference between the current and the target frame numbers. 
460			// When defined as an integer, the value preserves no matter how many frames are turning.
461			spinToSpeed: '2500',
462
463			spinToMotion: 'easeOutQuad', // optional pass easing type of the spinning animation
464			handleTexts: 'default', // function after spinTo or zoomTo; if defined in JSON title and description are passed as arguments
465			cropAxZmEbOpt: {} // options of the expandable button plugin, see /axZm/extensions/jquery.axZm.expButton.js
466		};
467
468		if (!o.cropJsonURL !== false && (!o.cropJsonURL || o.cropJsonURL == 'auto')) {
469			o.cropJsonURL = getParameterByName('cropJsonURL');
470		}
471
472		if (!o.installPath || o.installPath == 'auto') {
473			o.installPath = $.fn.axZm.installPath();
474		}
475
476		opt = $.extend(true, {}, def, o);
477
478 		if (!opt.installPath || opt.installPath == 'auto') {
479			opt.installPath = $.fn.axZm.installPath();
480			if (!opt.installPath || opt.installPath == 'auto') {
481				consoleLog('The value of the option installPath could not be determined. Please set it manually!', 1);
482				return;
483			}
484		}
485
486		// Proceed
487		getJSONdataFromFile();
488	};
489
490})(window.jQuery || {});

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.