Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2808 rexy 1
/*
2
 * nyroModal - jQuery Plugin
3
 * http://nyromodal.nyrodev.com
4
 *
5
 * Copyright (c) 2010 Cedric Nirousset (nyrodev.com)
6
 * Licensed under the MIT license
7
 *
8
 * $Date: 2010-02-23 (Tue, 23 Feb 2010) $
9
 * $version: 1.6.2+jquery1.8fix+bindfix+ff2fix
10
 */
11
jQuery(function($) {
12
 
13
	// -------------------------------------------------------
14
	// Private Variables
15
	// -------------------------------------------------------
16
 
17
	var userAgent = navigator.userAgent.toLowerCase();
18
	var browserVersion = (userAgent.match(/.+(?:rv|webkit|khtml|opera|msie)[\/: ]([\d.]+)/ ) || [0,'0'])[1];
19
 
20
	var isIE6 = (/msie/.test(userAgent) && !/opera/.test(userAgent) && parseInt(browserVersion) < 7 && (!window.XMLHttpRequest || typeof(XMLHttpRequest) === 'function'));
21
	var body = $('body');
22
 
23
	var currentSettings;
24
	var callingSettings;
25
 
26
	var shouldResize = false;
27
 
28
	var gallery = {};
29
 
30
	// To know if the fix for the Issue 10 should be applied (or has been applied)
31
	var fixFF = false;
32
 
33
	// Used for retrieve the content from an hidden div
34
	var contentElt;
35
	var contentEltLast;
36
 
37
	// Contains info about nyroModal state and all div references
38
	var modal = {
39
		started: false,
40
		ready: false,
41
		dataReady: false,
42
		anim: false,
43
		animContent: false,
44
		loadingShown: false,
45
		transition: false,
46
		resizing: false,
47
		closing: false,
48
		error: false,
49
		blocker: null,
50
		blockerVars: null,
51
		full: null,
52
		bg: null,
53
		loading: null,
54
		tmp: null,
55
		content: null,
56
		wrapper: null,
57
		contentWrapper: null,
58
		scripts: new Array(),
59
		scriptsShown: new Array()
60
	};
61
 
62
	// Indicate of the height or the width was resized, to reinit the currentsettings related to null
63
	var resized = {
64
		width: false,
65
		height: false,
66
		windowResizing: false
67
	};
68
 
69
	var initSettingsSize = {
70
		width: null,
71
		height: null,
72
		windowResizing: true
73
	};
74
 
75
	var windowResizeTimeout;
76
 
77
 
78
	// -------------------------------------------------------
79
	// Public function
80
	// -------------------------------------------------------
81
 
82
	// jQuery extension function. A paramater object could be used to overwrite the default settings
83
	$.fn.nyroModal = function(settings) {
84
		if (!this)
85
			return false;
86
		return this.each(function() {
87
			var me = $(this);
88
			if (this.nodeName.toLowerCase() == 'form') {
89
				me
90
				.off('submit.nyroModal')
91
				.on('submit.nyroModal', function(e) {
92
					if(e.isDefaultPrevented())
93
						return false;
94
					if (me.data('nyroModalprocessing'))
95
						return true;
96
					if (this.enctype == 'multipart/form-data') {
97
						processModal($.extend(settings, {
98
							from: this
99
						}));
100
						return true;
101
					}
102
					e.preventDefault();
103
					processModal($.extend(settings, {
104
						from: this
105
					}));
106
					return false;
107
				});
108
			} else {
109
				me
110
				.off('click.nyroModal')
111
				.on('click.nyroModal', function(e) {
112
					if(e.isDefaultPrevented())
113
						return false;
114
					e.preventDefault();
115
					processModal($.extend(settings, {
116
						from: this
117
					}));
118
					return false;
119
				});
120
			}
121
		});
122
	};
123
 
124
	// jQuery extension function to call manually the modal. A paramater object could be used to overwrite the default settings
125
	$.fn.nyroModalManual = function(settings) {
126
		if (!this.length)
127
			processModal(settings);
128
		return this.each(function(){
129
			processModal($.extend(settings, {
130
				from: this
131
			}));
132
		});
133
	};
134
 
135
	$.nyroModalManual = function(settings) {
136
		processModal(settings);
137
	};
138
 
139
	// Update the current settings
140
	// object settings
141
	// string deep1 first key where overwrite the settings
142
	// string deep2 second key where overwrite the settings
143
	$.nyroModalSettings = function(settings, deep1, deep2) {
144
		setCurrentSettings(settings, deep1, deep2);
145
		if (!deep1 && modal.started) {
146
			if (modal.bg && settings.bgColor)
147
				currentSettings.updateBgColor(modal, currentSettings, function(){});
148
 
149
			if (modal.contentWrapper && settings.title)
150
				setTitle();
151
 
152
			if (!modal.error && (settings.windowResizing || (!modal.resizing && (('width' in settings && settings.width == currentSettings.width) || ('height' in settings && settings.height == currentSettings.height))))) {
153
				modal.resizing = true;
154
				if (modal.contentWrapper)
155
					calculateSize(true);
156
				if (modal.contentWrapper && modal.contentWrapper.is(':visible') && !modal.animContent) {
157
					if (fixFF)
158
						modal.content.css({position: ''});
159
					currentSettings.resize(modal, currentSettings, function() {
160
						currentSettings.windowResizing = false;
161
						modal.resizing = false;
162
						if (fixFF)
163
							modal.content.css({position: 'fixed'});
164
						if ($.isFunction(currentSettings.endResize))
165
							currentSettings.endResize(modal, currentSettings);
166
					});
167
				}
168
			}
169
		}
170
	};
171
 
172
	// Remove the modal function
173
	$.nyroModalRemove = function() {
174
		removeModal();
175
	};
176
 
177
	// Go to the next image for a gallery
178
	// return false if nothing was done
179
	$.nyroModalNext = function() {
180
		var link = getGalleryLink(1);
181
		if (link)
182
			return link.nyroModalManual(getCurrentSettingsNew());
183
		return false;
184
	};
185
 
186
	// Go to the previous image for a gallery
187
	// return false if nothing was done
188
	$.nyroModalPrev = function() {
189
		var link = getGalleryLink(-1);
190
		if (link)
191
			return link.nyroModalManual(getCurrentSettingsNew());
192
		return false;
193
	};
194
 
195
 
196
	// -------------------------------------------------------
197
	// Default Settings
198
	// -------------------------------------------------------
199
 
200
	$.fn.nyroModal.settings = {
201
		debug: false, // Show the debug in the background
202
 
203
		blocker: false, // Element which will be blocked by the modal
204
 
205
		windowResize: true, // indicates if the modal should resize when the window is resized
206
 
207
		modal: false, // Esc key or click backgrdound enabling or not
208
 
209
		type: '', // nyroModal type (form, formData, iframe, image, etc...)
210
		forceType: null, // Used to force the type
211
		from: '', // Dom object where the call come from
212
		hash: '', // Eventual hash in the url
213
 
214
		processHandler: null, // Handler just before the real process
215
 
216
		selIndicator: 'nyroModalSel', // Value added when a form or Ajax is sent with a filter content
217
 
218
		formIndicator: 'nyroModal', // Value added when a form is sent
219
 
220
		content: null, // Raw content if type content is used
221
 
222
		bgColor: '#000000', // Background color
223
 
224
		ajax: {}, // Ajax option (url, data, type, success will be overwritten for a form, url and success only for an ajax call)
225
 
226
		swf: { // Swf player options if swf type is used.
227
			wmode: 'transparent'
228
		},
229
 
230
		width: null, // default Width If null, will be calculate automatically
231
		height: null, // default Height If null, will be calculate automatically
232
 
233
		minWidth: 400, // Minimum width
234
		minHeight: 300, // Minimum height
235
 
236
		resizable: true, // Indicate if the content is resizable. Will be set to false for swf
237
		autoSizable: true, // Indicate if the content is auto sizable. If not, the min size will be used
238
 
239
		padding: 25, // padding for the max modal size
240
 
241
		regexImg: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$', // Regex to find images
242
		addImageDivTitle: false, // Indicate if the div title should be inserted
243
		defaultImgAlt: 'Image', // Default alt attribute for the images
244
		setWidthImgTitle: true, // Set the width to the image title
245
		ltr: true, // Left to Right by default. Put to false for Hebrew or Right to Left language
246
 
247
		gallery: null, // Gallery name if provided
248
		galleryLinks: '<a href="#" class="nyroModalPrev">Prev</a><a href="#"  class="nyroModalNext">Next</a>', // Use .nyroModalPrev and .nyroModalNext to set the navigation link
249
		galleryCounts: galleryCounts, // Callback to show the gallery count
250
		galleryLoop: false, // Indicate if the gallery should loop
251
 
252
		zIndexStart: 100,
253
 
254
		cssOpt: { // Default CSS option for the nyroModal Div. Some will be overwritten or updated when using IE6
255
			bg: {
256
				position: 'absolute',
257
				overflow: 'hidden',
258
				top: 0,
259
				left: 0,
260
				height: '100%',
261
				width: '100%'
262
			},
263
			wrapper: {
264
				position: 'absolute',
265
				top: '50%',
266
				left: '50%'
267
			},
268
			wrapper2: {
269
			},
270
			content: {
271
			},
272
			loading: {
273
				position: 'absolute',
274
				top: '50%',
275
				left: '50%',
276
				marginTop: '-50px',
277
				marginLeft: '-50px'
278
			}
279
		},
280
 
281
		wrap: { // Wrapper div used to style the modal regarding the content type
282
			div: '<div class="wrapper"></div>',
283
			ajax: '<div class="wrapper"></div>',
284
			form: '<div class="wrapper"></div>',
285
			formData: '<div class="wrapper"></div>',
286
			image: '<div class="wrapperImg"></div>',
287
			swf: '<div class="wrapperSwf"></div>',
288
			iframe: '<div class="wrapperIframe"></div>',
289
			iframeForm: '<div class="wrapperIframe"></div>',
290
			manual: '<div class="wrapper"></div>'
291
		},
292
 
293
		closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close"></a>', // Adding automaticly as the first child of #nyroModalWrapper
294
 
295
		title: null, // Modal title
296
		titleFromIframe: true, // When using iframe in the same domain, try to get the title from it
297
 
298
		openSelector: '.nyroModal', // selector for open a new modal. will be used to parse automaticly at page loading
299
		closeSelector: '.nyroModalClose', // selector to close the modal
300
 
301
		contentLoading: '<a href="#" class="nyroModalClose">Cancel</a>', // Loading div content
302
 
303
		errorClass: 'error', // CSS Error class added to the loading div in case of error
304
		contentError: 'The requested content cannot be loaded.<br />Please try again later.<br /><a href="#" class="nyroModalClose">Close</a>', // Content placed in the loading div in case of error
305
 
306
		handleError: null, // Callback in case of error
307
 
308
		showBackground: showBackground, // Show background animation function
309
		hideBackground: hideBackground, // Hide background animation function
310
 
311
		endFillContent: null, // Will be called after filling and wraping the content, before parsing closeSelector and openSelector and showing the content
312
		showContent: showContent, // Show content animation function
313
		endShowContent: null, // Will be called once the content is shown
314
		beforeHideContent: null, // Will be called just before the modal closing
315
		hideContent: hideContent, // Hide content animation function
316
 
317
		showTransition: showTransition, // Show the transition animation (a modal is already shown and a new one is requested)
318
		hideTransition: hideTransition, // Hide the transition animation to show the content
319
 
320
		showLoading: showLoading, // show loading animation function
321
		hideLoading: hideLoading, // hide loading animation function
322
 
323
		resize: resize, // Resize animation function
324
		endResize: null, // Will be called one the content is resized
325
 
326
		updateBgColor: updateBgColor, // Change background color animation function
327
 
328
		endRemove: null // Will be called once the modal is totally gone
329
	};
330
 
331
	// -------------------------------------------------------
332
	// Private function
333
	// -------------------------------------------------------
334
 
335
	// Main function
336
	function processModal(settings) {
337
		if (modal.loadingShown || modal.transition || modal.anim)
338
			return;
339
		debug('processModal');
340
		modal.started = true;
341
		callingSettings = $.extend(true, settings);
342
		setDefaultCurrentSettings(settings);
343
		if (!modal.full)
344
			modal.blockerVars = modal.blocker = null;
345
		modal.error = false;
346
		modal.closing = false;
347
		modal.dataReady = false;
348
		modal.scripts = new Array();
349
		modal.scriptsShown = new Array();
350
 
351
		currentSettings.type = fileType();
352
		if (currentSettings.forceType) {
353
			if (!currentSettings.content)
354
				currentSettings.from = true;
355
			currentSettings.type = currentSettings.forceType;
356
			currentSettings.forceType = null;
357
		}
358
 
359
		if ($.isFunction(currentSettings.processHandler))
360
			currentSettings.processHandler(currentSettings);
361
 
362
		var from = currentSettings.from;
363
		var url = currentSettings.url;
364
 
365
		initSettingsSize.width = currentSettings.width;
366
		initSettingsSize.height = currentSettings.height;
367
 
368
		if (currentSettings.type == 'swf') {
369
			// Swf is transforming as a raw content
370
			setCurrentSettings({overflow: 'visible'}, 'cssOpt', 'content');
371
			currentSettings.content = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+currentSettings.width+'" height="'+currentSettings.height+'"><param name="movie" value="'+url+'"></param>';
372
			var tmp = '';
373
			$.each(currentSettings.swf, function(name, val) {
374
				currentSettings.content+= '<param name="'+name+'" value="'+val+'"></param>';
375
				tmp+= ' '+name+'="'+val+'"';
376
			});
377
			currentSettings.content+= '<embed src="'+url+'" type="application/x-shockwave-flash" width="'+currentSettings.width+'" height="'+currentSettings.height+'"'+tmp+'></embed></object>';
378
		}
379
 
380
		if (from) {
381
			var jFrom = $(from).blur();
382
			if (currentSettings.type == 'form') {
383
				var data = $(from).serializeArray();
384
				data.push({name: currentSettings.formIndicator, value: 1});
385
				if (currentSettings.selector)
386
					data.push({name: currentSettings.selIndicator, value: currentSettings.selector.substring(1)});
387
				showModal();
388
				$.ajax($.extend({}, currentSettings.ajax, {
389
						url: url,
390
						data: data,
391
						type: jFrom.attr('method') ? jFrom.attr('method') : 'get',
392
						success: ajaxLoaded,
393
						error: loadingError
394
					}));
395
				debug('Form Ajax Load: '+jFrom.attr('action'));
396
			} else if (currentSettings.type == 'formData') {
397
				// Form with data. We're using a hidden iframe
398
				initModal();
399
				jFrom.attr('target', 'nyroModalIframe');
400
				jFrom.attr('action', url);
401
				jFrom.prepend('<input type="hidden" name="'+currentSettings.formIndicator+'" value="1" />');
402
				if (currentSettings.selector)
403
					jFrom.prepend('<input type="hidden" name="'+currentSettings.selIndicator+'" value="'+currentSettings.selector.substring(1)+'" />');
404
				modal.tmp.html('<iframe frameborder="0" hspace="0" name="nyroModalIframe" src="javascript:\'\';"></iframe>');
405
				$('iframe', modal.tmp)
406
					.css({
407
						width: currentSettings.width,
408
						height: currentSettings.height
409
					})
410
					.error(loadingError)
411
					.load(formDataLoaded);
412
				debug('Form Data Load: '+jFrom.attr('action'));
413
				showModal();
414
				showContentOrLoading();
415
			} else if (currentSettings.type == 'image') {
416
				debug('Image Load: '+url);
417
				var title = jFrom.attr('title') || currentSettings.defaultImgAlt;
418
				initModal();
419
				modal.tmp.html('<img id="nyroModalImg" />').find('img').attr('alt', title);
420
				modal.tmp.css({lineHeight: 0});
421
				$('img', modal.tmp)
422
					.error(loadingError)
423
					.load(function() {
424
						debug('Image Loaded: '+this.src);
425
						$(this).off('load');
426
						var w = modal.tmp.width();
427
						var h = modal.tmp.height();
428
						modal.tmp.css({lineHeight: ''});
429
						resized.width = w;
430
						resized.height = h;
431
						setCurrentSettings({
432
							width: w,
433
							height: h,
434
							imgWidth: w,
435
							imgHeight: h
436
						});
437
						initSettingsSize.width = w;
438
						initSettingsSize.height = h;
439
						setCurrentSettings({overflow: 'visible'}, 'cssOpt', 'content');
440
						modal.dataReady = true;
441
						if (modal.loadingShown || modal.transition)
442
							showContentOrLoading();
443
					})
444
					.attr('src', url);
445
				showModal();
446
			} else if (currentSettings.type == 'iframeForm') {
447
				initModal();
448
				modal.tmp.html('<iframe frameborder="0" hspace="0" src="javascript:\'\';" name="nyroModalIframe" id="nyroModalIframe"></iframe>');
449
				debug('Iframe Form Load: '+url);
450
				$('iframe', modal.tmp).eq(0)
451
					.css({
452
						width: '100%',
453
						height: $.support.boxModel? '99%' : '100%'
454
					})
455
					.load(iframeLoaded);
456
				modal.dataReady = true;
457
				showModal();
458
			} else if (currentSettings.type == 'iframe') {
459
				initModal();
460
				modal.tmp.html('<iframe frameborder="0" hspace="0" src="javascript:\'\';" name="nyroModalIframe" id="nyroModalIframe"></iframe>');
461
				debug('Iframe Load: '+url);
462
				$('iframe', modal.tmp).eq(0)
463
					.css({
464
						width: '100%',
465
						height: $.support.boxModel? '99%' : '100%'
466
					})
467
					.load(iframeLoaded);
468
				modal.dataReady = true;
469
				showModal();
470
			} else if (currentSettings.type) {
471
				// Could be every other kind of type or a dom selector
472
				debug('Content: '+currentSettings.type);
473
				initModal();
474
				modal.tmp.html(currentSettings.content);
475
				var w = modal.tmp.width();
476
				var h = modal.tmp.height();
477
				var div = $(currentSettings.type);
478
				if (div.length) {
479
					setCurrentSettings({type: 'div'});
480
					w = div.width();
481
					h = div.height();
482
					if (contentElt)
483
						contentEltLast = contentElt;
484
					contentElt = div;
485
					modal.tmp.append(div.contents());
486
				}
487
				initSettingsSize.width = w;
488
				initSettingsSize.height = h;
489
				setCurrentSettings({
490
					width: w,
491
					height: h
492
				});
493
				if (modal.tmp.html())
494
					modal.dataReady = true;
495
				else
496
					loadingError();
497
				if (!modal.ready)
498
					showModal();
499
				else
500
					endHideContent();
501
			} else {
502
				debug('Ajax Load: '+url);
503
				setCurrentSettings({type: 'ajax'});
504
				var data = currentSettings.ajax.data || {};
505
				if (currentSettings.selector) {
506
					if (typeof data == "string") {
507
						data+= '&'+currentSettings.selIndicator+'='+currentSettings.selector.substring(1);
508
					} else {
509
						data[currentSettings.selIndicator] = currentSettings.selector.substring(1);
510
					}
511
				}
512
				showModal();
513
				$.ajax($.extend(true, currentSettings.ajax, {
514
					url: url,
515
					success: ajaxLoaded,
516
					error: loadingError,
517
					data: data
518
				}));
519
			}
520
		} else if (currentSettings.content) {
521
			// Raw content not from a DOM element
522
			debug('Content: '+currentSettings.type);
523
			setCurrentSettings({type: 'manual'});
524
			initModal();
525
			modal.tmp.html($('<div/>').html(currentSettings.content).contents());
526
			if (modal.tmp.html())
527
				modal.dataReady = true;
528
			else
529
				loadingError();
530
			showModal();
531
		} else {
532
			// What should we show here? nothing happen
533
		}
534
	}
535
 
536
	// Update the current settings
537
	// object settings
538
	// string deep1 first key where overwrite the settings
539
	// string deep2 second key where overwrite the settings
540
	function setDefaultCurrentSettings(settings) {
541
		debug('setDefaultCurrentSettings');
542
		currentSettings = $.extend(true, {}, $.fn.nyroModal.settings, settings);
543
		setMargin();
544
	}
545
 
546
	function setCurrentSettings(settings, deep1, deep2) {
547
		if (modal.started) {
548
			if (deep1 && deep2) {
549
				$.extend(true, currentSettings[deep1][deep2], settings);
550
			} else if (deep1) {
551
				$.extend(true, currentSettings[deep1], settings);
552
			} else {
553
				if (modal.animContent) {
554
					if ('width' in settings) {
555
						if (!modal.resizing) {
556
							settings.setWidth = settings.width;
557
							shouldResize = true;
558
						}
559
						delete settings['width'];
560
					}
561
					if ('height' in settings) {
562
						if (!modal.resizing) {
563
							settings.setHeight = settings.height;
564
							shouldResize = true;
565
						}
566
						delete settings['height'];
567
					}
568
				}
569
				$.extend(true, currentSettings, settings);
570
			}
571
		} else {
572
			if (deep1 && deep2) {
573
				$.extend(true, $.fn.nyroModal.settings[deep1][deep2], settings);
574
			} else if (deep1) {
575
				$.extend(true, $.fn.nyroModal.settings[deep1], settings);
576
			} else {
577
				$.extend(true, $.fn.nyroModal.settings, settings);
578
			}
579
		}
580
	}
581
 
582
	// Set the margin for postionning the element. Useful for IE6
583
	function setMarginScroll() {
584
		if (isIE6 && !modal.blocker) {
585
			if (document.documentElement) {
586
				currentSettings.marginScrollLeft = document.documentElement.scrollLeft;
587
				currentSettings.marginScrollTop = document.documentElement.scrollTop;
588
			} else {
589
				currentSettings.marginScrollLeft = document.body.scrollLeft;
590
				currentSettings.marginScrollTop = document.body.scrollTop;
591
			}
592
		} else {
593
			currentSettings.marginScrollLeft = 0;
594
			currentSettings.marginScrollTop = 0;
595
		}
596
	}
597
 
598
	// Set the margin for the content
599
	function setMargin() {
600
		setMarginScroll();
601
		currentSettings.marginLeft = -(currentSettings.width+currentSettings.borderW)/2;
602
		currentSettings.marginTop = -(currentSettings.height+currentSettings.borderH)/2;
603
		if (!modal.blocker) {
604
			currentSettings.marginLeft+= currentSettings.marginScrollLeft;
605
			currentSettings.marginTop+= currentSettings.marginScrollTop;
606
		}
607
	}
608
 
609
	// Set the margin for the current loading
610
	function setMarginLoading() {
611
		setMarginScroll();
612
		var outer = getOuter(modal.loading);
613
		currentSettings.marginTopLoading = -(modal.loading.height() + outer.h.border + outer.h.padding)/2;
614
		currentSettings.marginLeftLoading = -(modal.loading.width() + outer.w.border + outer.w.padding)/2;
615
		if (!modal.blocker) {
616
			currentSettings.marginLeftLoading+= currentSettings.marginScrollLeft;
617
			currentSettings.marginTopLoading+= currentSettings.marginScrollTop;
618
		}
619
	}
620
 
621
	// Set the modal Title
622
	function setTitle() {
623
		var title = $('h1#nyroModalTitle', modal.contentWrapper);
624
		if (title.length)
625
			title.text(currentSettings.title);
626
		else
627
			modal.contentWrapper.prepend('<h1 id="nyroModalTitle">'+currentSettings.title+'</h1>');
628
	}
629
 
630
	// Init the nyroModal div by settings the CSS elements and hide needed elements
631
	function initModal() {
632
		debug('initModal');
633
		if (!modal.full) {
634
			if (currentSettings.debug)
635
				setCurrentSettings({color: 'white'}, 'cssOpt', 'bg');
636
 
637
			var full = {
638
				zIndex: currentSettings.zIndexStart,
639
				position: 'fixed',
640
				top: 0,
641
				left: 0,
642
				width: '100%',
643
				height: '100%'
644
			};
645
 
646
			var contain = body;
647
			var iframeHideIE = '';
648
			if (currentSettings.blocker) {
649
				modal.blocker = contain = $(currentSettings.blocker);
650
				var pos = modal.blocker.offset();
651
				var w = modal.blocker.outerWidth();
652
				var h = modal.blocker.outerHeight();
653
				if (isIE6) {
654
					setCurrentSettings({
655
						height: '100%',
656
						width: '100%',
657
						top: 0,
658
						left: 0
659
					}, 'cssOpt', 'bg');
660
				}
661
				modal.blockerVars = {
662
					top: pos.top,
663
					left: pos.left,
664
					width: w,
665
					height: h
666
				};
667
				var plusTop = (/msie/.test(userAgent) ?0:getCurCSS(body.get(0), 'borderTopWidth'));
668
				var plusLeft = (/msie/.test(userAgent) ?0:getCurCSS(body.get(0), 'borderLeftWidth'));
669
				full = {
670
					position: 'absolute',
671
					top: pos.top + plusTop,
672
					left: pos.left + plusLeft,
673
					width: w,
674
					height: h
675
				};
676
			} else if (isIE6) {
677
				body.css({
678
					marginLeft: 0,
679
					marginRight: 0
680
				});
681
				var w = body.width();
682
				var h = $(window).height()+'px';
683
				if ($(window).height() >= body.outerHeight()) {
684
					h = body.outerHeight()+'px';
685
				} else
686
					w+= 20;
687
				w += 'px';
688
				body.css({
689
					width: w,
690
					height: h,
691
					position: 'static',
692
					overflow: 'hidden'
693
				});
694
				$('html').css({overflow: 'hidden'});
695
				setCurrentSettings({
696
					cssOpt: {
697
						bg: {
698
							position: 'absolute',
699
							zIndex: currentSettings.zIndexStart+1,
700
							height: '110%',
701
							width: '110%',
702
							top: currentSettings.marginScrollTop+'px',
703
							left: currentSettings.marginScrollLeft+'px'
704
						},
705
						wrapper: { zIndex: currentSettings.zIndexStart+2 },
706
						loading: { zIndex: currentSettings.zIndexStart+3 }
707
					}
708
				});
709
 
710
				iframeHideIE = $('<iframe id="nyroModalIframeHideIe" src="javascript:\'\';"></iframe>')
711
								.css($.extend({},
712
									currentSettings.cssOpt.bg, {
713
										opacity: 0,
714
										zIndex: 50,
715
										border: 'none'
716
									}));
717
			}
718
 
719
			contain.append($('<div id="nyroModalFull"><div id="nyroModalBg"></div><div id="nyroModalWrapper"><div id="nyroModalContent"></div></div><div id="nyrModalTmp"></div><div id="nyroModalLoading"></div></div>').hide());
720
 
721
			modal.full = $('#nyroModalFull')
722
				.css(full)
723
				.show();
724
			modal.bg = $('#nyroModalBg')
725
				.css($.extend({
726
						backgroundColor: currentSettings.bgColor
727
					}, currentSettings.cssOpt.bg))
728
				.before(iframeHideIE);
729
			modal.bg.on('click.nyroModal', clickBg);
730
			modal.loading = $('#nyroModalLoading')
731
				.css(currentSettings.cssOpt.loading)
732
				.hide();
733
			modal.contentWrapper = $('#nyroModalWrapper')
734
				.css(currentSettings.cssOpt.wrapper)
735
				.hide();
736
			modal.content = $('#nyroModalContent');
737
			modal.tmp = $('#nyrModalTmp').hide();
738
 
739
			// To stop the mousewheel if the the plugin is available
740
			if ($.isFunction($.fn.mousewheel)) {
741
				modal.content.mousewheel(function(e, d) {
742
					var elt = modal.content.get(0);
743
					if ((d > 0 && elt.scrollTop == 0) ||
744
							(d < 0 && elt.scrollHeight - elt.scrollTop == elt.clientHeight)) {
745
						e.preventDefault();
746
						e.stopPropagation();
747
					}
748
				});
749
			}
750
 
751
			$(document).on('keydown.nyroModal', keyHandler);
752
			modal.content.css({width: 'auto', height: 'auto'});
753
			modal.contentWrapper.css({width: 'auto', height: 'auto'});
754
 
755
			if (!currentSettings.blocker && currentSettings.windowResize) {
756
				$(window).on('resize.nyroModal', function() {
757
					window.clearTimeout(windowResizeTimeout);
758
					windowResizeTimeout = window.setTimeout(windowResizeHandler, 200);
759
				});
760
			}
761
		}
762
	}
763
 
764
	function windowResizeHandler() {
765
		$.nyroModalSettings(initSettingsSize);
766
	}
767
 
768
	// Show the modal (ie: the background and then the loading if needed or the content directly)
769
	function showModal() {
770
		debug('showModal');
771
		if (!modal.ready) {
772
			initModal();
773
			modal.anim = true;
774
			currentSettings.showBackground(modal, currentSettings, endBackground);
775
		} else {
776
			modal.anim = true;
777
			modal.transition = true;
778
			currentSettings.showTransition(modal, currentSettings, function(){endHideContent();modal.anim=false;showContentOrLoading();});
779
		}
780
	}
781
 
782
	// Called when user click on background
783
	function clickBg(e) {
784
		if (!currentSettings.modal)
785
			removeModal();
786
	}
787
 
788
	// Used for the escape key or the arrow in the gallery type
789
	function keyHandler(e) {
790
		if (e.keyCode == 27) {
791
			if (!currentSettings.modal)
792
				removeModal();
793
		} else if (currentSettings.gallery && modal.ready && modal.dataReady && !modal.anim && !modal.transition) {
794
			if (e.keyCode == 39 || e.keyCode == 40) {
795
				e.preventDefault();
796
				$.nyroModalNext();
797
				return false;
798
			} else if (e.keyCode == 37 || e.keyCode == 38) {
799
				e.preventDefault();
800
				$.nyroModalPrev();
801
				return false;
802
			}
803
		}
804
	}
805
 
806
	// Determine the filetype regarding the link DOM element
807
	function fileType() {
808
		var from = currentSettings.from;
809
 
810
		var url;
811
 
812
		if (from && from.nodeName) {
813
			var jFrom = $(from);
814
 
815
			url = jFrom.attr(from.nodeName.toLowerCase() == 'form' ? 'action' : 'href');
816
			if (!url)
817
				url = location.href.substring(window.location.host.length+7);
818
			currentSettings.url = url;
819
 
820
			if (jFrom.attr('rev') == 'modal')
821
				currentSettings.modal = true;
822
 
823
			currentSettings.title = jFrom.attr('title');
824
 
825
			if (from && from.rel && from.rel.toLowerCase() != 'nofollow') {
826
				var indexSpace = from.rel.indexOf(' ');
827
				currentSettings.gallery = indexSpace > 0 ? from.rel.substr(0, indexSpace) : from.rel;
828
			}
829
 
830
			var imgType = imageType(url, from);
831
			if (imgType)
832
				return imgType;
833
 
834
			if (isSwf(url))
835
				return 'swf';
836
 
837
			var iframe = false;
838
			if (from.target && from.target.toLowerCase() == '_blank' || (from.hostname && from.hostname.replace(/:\d*$/,'') != window.location.hostname.replace(/:\d*$/,''))) {
839
				iframe = true;
840
			}
841
			if (from.nodeName.toLowerCase() == 'form') {
842
				if (iframe)
843
					return 'iframeForm';
844
				setCurrentSettings(extractUrlSel(url));
845
				if (jFrom.attr('enctype') == 'multipart/form-data')
846
					return 'formData';
847
				return 'form';
848
			}
849
			if (iframe)
850
				return 'iframe';
851
		} else {
852
			url = currentSettings.url;
853
			if (!currentSettings.content)
854
				currentSettings.from = true;
855
 
856
			if (!url)
857
				return null;
858
 
859
			if (isSwf(url))
860
				return 'swf';
861
 
862
			var reg1 = new RegExp("^http://|https://", "g");
863
			if (url.match(reg1))
864
				return 'iframe';
865
		}
866
 
867
		var imgType = imageType(url, from);
868
		if (imgType)
869
			return imgType;
870
 
871
		var tmp = extractUrlSel(url);
872
		setCurrentSettings(tmp);
873
 
874
		if (!tmp.url)
875
			return tmp.selector;
876
	}
877
 
878
	function imageType(url, from) {
879
		var image = new RegExp(currentSettings.regexImg, 'i');
880
		if (image.test(url)) {
881
			return 'image';
882
		}
883
	}
884
 
885
	function isSwf(url) {
886
		var swf = new RegExp('[^\.]\.(swf)\s*$', 'i');
887
		return swf.test(url);
888
	}
889
 
890
	function extractUrlSel(url) {
891
		var ret = {
892
			url: null,
893
			selector: null
894
		};
895
 
896
		if (url) {
897
			var hash = getHash(url);
898
			var hashLoc = getHash(window.location.href);
899
			var curLoc = window.location.href.substring(0, window.location.href.length - hashLoc.length);
900
			var req = url.substring(0, url.length - hash.length);
901
 
902
			if (req == curLoc || req == $('base').attr('href')) {
903
				ret.selector = hash;
904
			} else {
905
				ret.url = req;
906
				ret.selector = hash;
907
			}
908
		}
909
		return ret;
910
	}
911
 
912
	// Called when the content cannot be loaded or tiemout reached
913
	function loadingError() {
914
		debug('loadingError');
915
 
916
		modal.error = true;
917
 
918
		if (!modal.ready)
919
			return;
920
 
921
		if ($.isFunction(currentSettings.handleError))
922
			currentSettings.handleError(modal, currentSettings);
923
 
924
		modal.loading
925
			.addClass(currentSettings.errorClass)
926
			.html(currentSettings.contentError);
927
		$(currentSettings.closeSelector, modal.loading)
928
			.off('click.nyroModal')
929
			.on('click.nyroModal', removeModal);
930
		setMarginLoading();
931
		modal.loading
932
			.css({
933
				marginTop: currentSettings.marginTopLoading+'px',
934
				marginLeft: currentSettings.marginLeftLoading+'px'
935
			});
936
	}
937
 
938
	// Put the content from modal.tmp to modal.content
939
	function fillContent() {
940
		debug('fillContent');
941
		if (!modal.tmp.html())
942
			return;
943
 
944
		modal.content.html(modal.tmp.contents());
945
		modal.tmp.empty();
946
		wrapContent();
947
 
948
		if (currentSettings.type == 'iframeForm') {
949
			$(currentSettings.from)
950
				.attr('target', 'nyroModalIframe')
951
				.data('nyroModalprocessing', 1)
952
				.submit()
953
				.attr('target', '_blank')
954
				.removeData('nyroModalprocessing');
955
		}
956
 
957
		if (!currentSettings.modal)
958
			modal.wrapper.prepend(currentSettings.closeButton);
959
 
960
		if ($.isFunction(currentSettings.endFillContent))
961
			currentSettings.endFillContent(modal, currentSettings);
962
 
963
		modal.content.append(modal.scripts);
964
 
965
		$(currentSettings.closeSelector, modal.contentWrapper)
966
			.off('click.nyroModal')
967
			.on('click.nyroModal', removeModal);
968
		$(currentSettings.openSelector, modal.contentWrapper).nyroModal(getCurrentSettingsNew());
969
	}
970
 
971
	// Get the current settings to be used in new links
972
	function getCurrentSettingsNew() {
973
		return callingSettings;
974
		/*
975
		var currentSettingsNew = $.extend(true, {}, currentSettings);
976
		if (resized.width)
977
			currentSettingsNew.width = null;
978
		else
979
			currentSettingsNew.width = initSettingsSize.width;
980
		if (resized.height)
981
			currentSettingsNew.height = null;
982
		else
983
			currentSettingsNew.height = initSettingsSize.height;
984
		currentSettingsNew.cssOpt.content.overflow = 'auto';
985
		return currentSettingsNew;
986
		*/
987
	}
988
 
989
	// Wrap the content and update the modal size if needed
990
	function wrapContent() {
991
		debug('wrapContent');
992
 
993
		var wrap = $(currentSettings.wrap[currentSettings.type]);
994
		modal.content.append(wrap.children().remove());
995
		modal.contentWrapper.wrapInner(wrap);
996
 
997
		if (currentSettings.gallery) {
998
			// Set the action for the next and prev button (or remove them)
999
			modal.content.append(currentSettings.galleryLinks);
1000
 
1001
			gallery.links = $('[rel="'+currentSettings.gallery+'"], [rel^="'+currentSettings.gallery+' "]');
1002
			gallery.index = gallery.links.index(currentSettings.from);
1003
 
1004
			if (currentSettings.galleryCounts && $.isFunction(currentSettings.galleryCounts))
1005
				currentSettings.galleryCounts(gallery.index + 1, gallery.links.length, modal, currentSettings);
1006
 
1007
			var currentSettingsNew = getCurrentSettingsNew();
1008
 
1009
			var linkPrev = getGalleryLink(-1);
1010
			if (linkPrev) {
1011
				var prev = $('.nyroModalPrev', modal.contentWrapper)
1012
					.attr('href', linkPrev.attr('href'))
1013
					.click(function(e) {
1014
						e.preventDefault();
1015
						$.nyroModalPrev();
1016
						return false;
1017
					});
1018
				if (isIE6 && currentSettings.type == 'swf') {
1019
					prev.before($('<iframe id="nyroModalIframeHideIeGalleryPrev" src="javascript:\'\';"></iframe>').css({
1020
											position: prev.css('position'),
1021
											top: prev.css('top'),
1022
											left: prev.css('left'),
1023
											width: prev.width(),
1024
											height: prev.height(),
1025
											opacity: 0,
1026
											border: 'none'
1027
										}));
1028
				}
1029
			} else {
1030
				$('.nyroModalPrev', modal.contentWrapper).remove();
1031
			}
1032
			var linkNext = getGalleryLink(1);
1033
			if (linkNext) {
1034
				var next = $('.nyroModalNext', modal.contentWrapper)
1035
					.attr('href', linkNext.attr('href'))
1036
					.click(function(e) {
1037
						e.preventDefault();
1038
						$.nyroModalNext();
1039
						return false;
1040
					});
1041
				if (isIE6 && currentSettings.type == 'swf') {
1042
					next.before($('<iframe id="nyroModalIframeHideIeGalleryNext" src="javascript:\'\';"></iframe>')
1043
									.css($.extend({}, {
1044
											position: next.css('position'),
1045
											top: next.css('top'),
1046
											left: next.css('left'),
1047
											width: next.width(),
1048
											height: next.height(),
1049
											opacity: 0,
1050
											border: 'none'
1051
										})));
1052
				}
1053
			} else {
1054
				$('.nyroModalNext', modal.contentWrapper).remove();
1055
			}
1056
		}
1057
 
1058
		calculateSize();
1059
	}
1060
 
1061
	function getGalleryLink(dir) {
1062
		if (currentSettings.gallery) {
1063
			if (!currentSettings.ltr)
1064
				dir *= -1;
1065
			var index = gallery.index + dir;
1066
			if (index >= 0 && index < gallery.links.length)
1067
				return gallery.links.eq(index);
1068
			else if (currentSettings.galleryLoop) {
1069
				if (index < 0)
1070
					return gallery.links.eq(gallery.links.length-1);
1071
				else
1072
					return gallery.links.eq(0);
1073
			}
1074
		}
1075
		return false;
1076
	}
1077
 
1078
	// Calculate the size for the contentWrapper
1079
	function calculateSize(resizing) {
1080
		debug('calculateSize');
1081
 
1082
		modal.wrapper = modal.contentWrapper.children('div:first');
1083
 
1084
		resized.width = false;
1085
		resized.height = false;
1086
		if (false && !currentSettings.windowResizing) {
1087
			initSettingsSize.width = currentSettings.width;
1088
			initSettingsSize.height = currentSettings.height;
1089
		}
1090
 
1091
		if (currentSettings.autoSizable && (!currentSettings.width || !currentSettings.height)) {
1092
			modal.contentWrapper
1093
				.css({
1094
					opacity: 0,
1095
					width: 'auto',
1096
					height: 'auto'
1097
				})
1098
				.show();
1099
			var tmp = {
1100
				width: 'auto',
1101
				height: 'auto'
1102
			};
1103
			if (currentSettings.width) {
1104
				tmp.width = currentSettings.width;
1105
			} else if (currentSettings.type == 'iframe') {
1106
				tmp.width = currentSettings.minWidth;
1107
			}
1108
 
1109
			if (currentSettings.height) {
1110
				tmp.height = currentSettings.height;
1111
			} else if (currentSettings.type == 'iframe') {
1112
				tmp.height = currentSettings.minHeight;
1113
			}
1114
 
1115
			modal.content.css(tmp);
1116
			if (!currentSettings.width) {
1117
				currentSettings.width = modal.content.outerWidth(true);
1118
				resized.width = true;
1119
			}
1120
			if (!currentSettings.height) {
1121
				currentSettings.height = modal.content.outerHeight(true);
1122
				resized.height = true;
1123
			}
1124
			modal.contentWrapper.css({opacity: 1});
1125
			if (!resizing)
1126
				modal.contentWrapper.hide();
1127
		}
1128
 
1129
		if (currentSettings.type != 'image' && currentSettings.type != 'swf') {
1130
			currentSettings.width = Math.max(currentSettings.width, currentSettings.minWidth);
1131
			currentSettings.height = Math.max(currentSettings.height, currentSettings.minHeight);
1132
		}
1133
 
1134
		var outerWrapper = getOuter(modal.contentWrapper);
1135
		var outerWrapper2 = getOuter(modal.wrapper);
1136
		var outerContent = getOuter(modal.content);
1137
 
1138
		var tmp = {
1139
			content: {
1140
				width: currentSettings.width,
1141
				height: currentSettings.height
1142
			},
1143
			wrapper2: {
1144
				width: currentSettings.width + outerContent.w.total,
1145
				height: currentSettings.height + outerContent.h.total
1146
			},
1147
			wrapper: {
1148
				width: currentSettings.width + outerContent.w.total + outerWrapper2.w.total,
1149
				height: currentSettings.height + outerContent.h.total + outerWrapper2.h.total
1150
			}
1151
		};
1152
 
1153
		if (currentSettings.resizable) {
1154
			var maxHeight = modal.blockerVars? modal.blockerVars.height : $(window).height()
1155
								- outerWrapper.h.border
1156
								- (tmp.wrapper.height - currentSettings.height);
1157
			var maxWidth = modal.blockerVars? modal.blockerVars.width : $(window).width()
1158
								- outerWrapper.w.border
1159
								- (tmp.wrapper.width - currentSettings.width);
1160
			maxHeight-= currentSettings.padding*2;
1161
			maxWidth-= currentSettings.padding*2;
1162
 
1163
			if (tmp.content.height > maxHeight || tmp.content.width > maxWidth) {
1164
				// We're gonna resize the modal as it will goes outside the view port
1165
				if (currentSettings.type == 'image' || currentSettings.type == 'swf') {
1166
					// An image is resized proportionnaly
1167
					var useW = currentSettings.imgWidth?currentSettings.imgWidth : currentSettings.width;
1168
					var useH = currentSettings.imgHeight?currentSettings.imgHeight : currentSettings.height;
1169
					var diffW = tmp.content.width - useW;
1170
					var diffH = tmp.content.height - useH;
1171
						if (diffH < 0) diffH = 0;
1172
						if (diffW < 0) diffW = 0;
1173
					var calcH = maxHeight - diffH;
1174
					var calcW = maxWidth - diffW;
1175
					var ratio = Math.min(calcH/useH, calcW/useW);
1176
					calcW = Math.floor(useW*ratio);
1177
					calcH = Math.floor(useH*ratio);
1178
					tmp.content.height = calcH + diffH;
1179
					tmp.content.width = calcW + diffW;
1180
				} else {
1181
					// For an HTML content, we simply decrease the size
1182
					tmp.content.height = Math.min(tmp.content.height, maxHeight);
1183
					tmp.content.width = Math.min(tmp.content.width, maxWidth);
1184
				}
1185
				tmp.wrapper2 = {
1186
						width: tmp.content.width + outerContent.w.total,
1187
						height: tmp.content.height + outerContent.h.total
1188
					};
1189
				tmp.wrapper = {
1190
						width: tmp.content.width + outerContent.w.total + outerWrapper2.w.total,
1191
						height: tmp.content.height + outerContent.h.total + outerWrapper2.h.total
1192
					};
1193
			}
1194
		}
1195
 
1196
		if (currentSettings.type == 'swf') {
1197
			$('object, embed', modal.content)
1198
				.attr('width', tmp.content.width)
1199
				.attr('height', tmp.content.height);
1200
		} else if (currentSettings.type == 'image') {
1201
			$('img', modal.content).css({
1202
				width: tmp.content.width,
1203
				height: tmp.content.height
1204
			});
1205
		}
1206
 
1207
		modal.content.css($.extend({}, tmp.content, currentSettings.cssOpt.content));
1208
		modal.wrapper.css($.extend({}, tmp.wrapper2, currentSettings.cssOpt.wrapper2));
1209
 
1210
		if (!resizing)
1211
			modal.contentWrapper.css($.extend({}, tmp.wrapper, currentSettings.cssOpt.wrapper));
1212
 
1213
		if (currentSettings.type == 'image' && currentSettings.addImageDivTitle) {
1214
			// Adding the title for the image
1215
			$('img', modal.content).removeAttr('alt');
1216
			var divTitle = $('div', modal.content);
1217
			if (currentSettings.title != currentSettings.defaultImgAlt && currentSettings.title) {
1218
				if (divTitle.length == 0) {
1219
					divTitle = $('<div>'+currentSettings.title+'</div>');
1220
					modal.content.append(divTitle);
1221
				}
1222
				if (currentSettings.setWidthImgTitle) {
1223
					var outerDivTitle = getOuter(divTitle);
1224
					divTitle.css({width: (tmp.content.width + outerContent.w.padding - outerDivTitle.w.total)+'px'});
1225
				}
1226
			} else if (divTitle.length = 0) {
1227
				divTitle.remove();
1228
			}
1229
		}
1230
 
1231
		if (currentSettings.title)
1232
			setTitle();
1233
 
1234
		tmp.wrapper.borderW = outerWrapper.w.border;
1235
		tmp.wrapper.borderH = outerWrapper.h.border;
1236
 
1237
		setCurrentSettings(tmp.wrapper);
1238
		setMargin();
1239
	}
1240
 
1241
	function removeModal(e) {
1242
		debug('removeModal');
1243
		if (e)
1244
			e.preventDefault();
1245
		if (modal.full && modal.ready) {
1246
			$(document).off('keydown.nyroModal');
1247
			if (!currentSettings.blocker)
1248
				$(window).off('resize.nyroModal');
1249
			modal.ready = false;
1250
			modal.anim = true;
1251
			modal.closing = true;
1252
			if (modal.loadingShown || modal.transition) {
1253
				currentSettings.hideLoading(modal, currentSettings, function() {
1254
						modal.loading.hide();
1255
						modal.loadingShown = false;
1256
						modal.transition = false;
1257
						currentSettings.hideBackground(modal, currentSettings, endRemove);
1258
					});
1259
			} else {
1260
				if (fixFF)
1261
					modal.content.css({position: ''}); // Fix Issue #10, remove the attribute
1262
				modal.wrapper.css({overflow: 'hidden'}); // Used to fix a visual issue when hiding
1263
				modal.content.css({overflow: 'hidden'}); // Used to fix a visual issue when hiding
1264
				$('iframe', modal.content).hide(); // Fix issue 359
1265
				if ($.isFunction(currentSettings.beforeHideContent)) {
1266
					currentSettings.beforeHideContent(modal, currentSettings, function() {
1267
						currentSettings.hideContent(modal, currentSettings, function() {
1268
							endHideContent();
1269
							currentSettings.hideBackground(modal, currentSettings, endRemove);
1270
						});
1271
					});
1272
				} else {
1273
					currentSettings.hideContent(modal, currentSettings, function() {
1274
							endHideContent();
1275
							currentSettings.hideBackground(modal, currentSettings, endRemove);
1276
						});
1277
				}
1278
			}
1279
		}
1280
		if (e)
1281
			return false;
1282
	}
1283
 
1284
	function showContentOrLoading() {
1285
		debug('showContentOrLoading');
1286
		if (modal.ready && !modal.anim) {
1287
			if (modal.dataReady) {
1288
				if (modal.tmp.html()) {
1289
					modal.anim = true;
1290
					if (modal.transition) {
1291
						fillContent();
1292
						modal.animContent = true;
1293
						currentSettings.hideTransition(modal, currentSettings, function() {
1294
							modal.loading.hide();
1295
							modal.transition = false;
1296
							modal.loadingShown = false;
1297
							endShowContent();
1298
						});
1299
					} else {
1300
						currentSettings.hideLoading(modal, currentSettings, function() {
1301
								modal.loading.hide();
1302
								modal.loadingShown = false;
1303
								fillContent();
1304
								setMarginLoading();
1305
								setMargin();
1306
								modal.animContent = true;
1307
								currentSettings.showContent(modal, currentSettings, endShowContent);
1308
							});
1309
					}
1310
				}
1311
			} else if (!modal.loadingShown && !modal.transition) {
1312
				modal.anim = true;
1313
				modal.loadingShown = true;
1314
				if (modal.error)
1315
					loadingError();
1316
				else
1317
					modal.loading.html(currentSettings.contentLoading);
1318
				$(currentSettings.closeSelector, modal.loading)
1319
					.off('click.nyroModal')
1320
					.on('click.nyroModal', removeModal);
1321
				setMarginLoading();
1322
				currentSettings.showLoading(modal, currentSettings, function(){modal.anim=false;showContentOrLoading();});
1323
			}
1324
		}
1325
	}
1326
 
1327
	// -------------------------------------------------------
1328
	// Private Data Loaded callback
1329
	// -------------------------------------------------------
1330
 
1331
	function ajaxLoaded(data) {
1332
		debug('AjaxLoaded: '+this.url);
1333
 
1334
		if (currentSettings.selector) {
1335
			var tmp = {};
1336
			var i = 0;
1337
			// Looking for script to store them
1338
			data = data
1339
				.replace(/\r\n/gi,'nyroModalLN')
1340
				.replace(//gi, function(x) {
1341
						tmp[i] = x;
1342
						return '<pre style="display: none" class=nyroModalScript rel="'+(i++)+'"></pre>';
1343
					});
1344
			data = $('<div>'+data+'</div>').find(currentSettings.selector).html()
1345
				.replace(/
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
 
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
 
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
 
1399
1400
1401
1402
1403
 
1404
 
1405
1406
1407
1408
 
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
 
1421
1422
 
1423
1424
 
1425
1426
1427
 
1428
1429
1430
1431
1432
1433
 
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
 
1448
1449
1450
1451
1452
1453
1454
 
1455
1456
1457
1458
1459
1460
1461
 
1462
1463
1464
1465
 
1466
1467
1468
 
1469
1470
1471
 
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
 
1484
 
1485
1486
1487
1488
 
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
 
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
 
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
 
1535
1536
1537
 
1538
1539
1540
 
1541
1542
1543
 
1544
1545
1546
 
1547
1548
1549
1550
1551
1552
1553
 
1554
1555
1556
1557
1558
1559
 
1560
1561
1562
1563
 
1564
1565
1566
1567
 
1568
1569
1570
1571
 
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
 
1585
1586
1587
1588
 
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
 
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
 
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
 
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
 
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
 
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
 
1692
1693
1694
1695
 
1696
1697
 
1698
1699
 
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709