source: extensions/rv_gmaps/trunk/template/nyroModal/jquery.nyroModal-1.6.2.js @ 8029

Last change on this file since 8029 was 8029, checked in by rvelices, 13 years ago

rv_gmaps do not use prototype anymore on the picture page

  • Property svn:eol-style set to LF
File size: 51.1 KB
Line 
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
10 */
11jQuery(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                                .unbind('submit.nyroModal')
91                                .bind('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                                .unbind('click.nyroModal')
111                                .bind('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">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).unbind('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.bind('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).bind('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).bind('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                        .unbind('click.nyroModal')
929                        .bind('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                        .unbind('click.nyroModal')
967                        .bind('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                var currentSettingsNew = $.extend(true, {}, currentSettings);
975                if (resized.width)
976                        currentSettingsNew.width = null;
977                else
978                        currentSettingsNew.width = initSettingsSize.width;
979                if (resized.height)
980                        currentSettingsNew.height = null;
981                else
982                        currentSettingsNew.height = initSettingsSize.height;
983                currentSettingsNew.cssOpt.content.overflow = 'auto';
984                return currentSettingsNew;
985        }
986
987        // Wrap the content and update the modal size if needed
988        function wrapContent() {
989                debug('wrapContent');
990
991                var wrap = $(currentSettings.wrap[currentSettings.type]);
992                modal.content.append(wrap.children().remove());
993                modal.contentWrapper.wrapInner(wrap);
994
995                if (currentSettings.gallery) {
996                        // Set the action for the next and prev button (or remove them)
997                        modal.content.append(currentSettings.galleryLinks);
998
999                        gallery.links = $('[rel="'+currentSettings.gallery+'"], [rel^="'+currentSettings.gallery+' "]');
1000                        gallery.index = gallery.links.index(currentSettings.from);
1001
1002                        if (currentSettings.galleryCounts && $.isFunction(currentSettings.galleryCounts))
1003                                currentSettings.galleryCounts(gallery.index + 1, gallery.links.length, modal, currentSettings);
1004
1005                        var currentSettingsNew = getCurrentSettingsNew();
1006
1007                        var linkPrev = getGalleryLink(-1);
1008                        if (linkPrev) {
1009                                var prev = $('.nyroModalPrev', modal.contentWrapper)
1010                                        .attr('href', linkPrev.attr('href'))
1011                                        .click(function(e) {
1012                                                e.preventDefault();
1013                                                $.nyroModalPrev();
1014                                                return false;
1015                                        });
1016                                if (isIE6 && currentSettings.type == 'swf') {
1017                                        prev.before($('<iframe id="nyroModalIframeHideIeGalleryPrev" src="javascript:\'\';"></iframe>').css({
1018                                                                                        position: prev.css('position'),
1019                                                                                        top: prev.css('top'),
1020                                                                                        left: prev.css('left'),
1021                                                                                        width: prev.width(),
1022                                                                                        height: prev.height(),
1023                                                                                        opacity: 0,
1024                                                                                        border: 'none'
1025                                                                                }));
1026                                }
1027                        } else {
1028                                $('.nyroModalPrev', modal.contentWrapper).remove();
1029                        }
1030                        var linkNext = getGalleryLink(1);
1031                        if (linkNext) {
1032                                var next = $('.nyroModalNext', modal.contentWrapper)
1033                                        .attr('href', linkNext.attr('href'))
1034                                        .click(function(e) {
1035                                                e.preventDefault();
1036                                                $.nyroModalNext();
1037                                                return false;
1038                                        });
1039                                if (isIE6 && currentSettings.type == 'swf') {
1040                                        next.before($('<iframe id="nyroModalIframeHideIeGalleryNext" src="javascript:\'\';"></iframe>')
1041                                                                        .css($.extend({}, {
1042                                                                                        position: next.css('position'),
1043                                                                                        top: next.css('top'),
1044                                                                                        left: next.css('left'),
1045                                                                                        width: next.width(),
1046                                                                                        height: next.height(),
1047                                                                                        opacity: 0,
1048                                                                                        border: 'none'
1049                                                                                })));
1050                                }
1051                        } else {
1052                                $('.nyroModalNext', modal.contentWrapper).remove();
1053                        }
1054                }
1055
1056                calculateSize();
1057        }
1058
1059        function getGalleryLink(dir) {
1060                if (currentSettings.gallery) {
1061                        if (!currentSettings.ltr)
1062                                dir *= -1;
1063                        var index = gallery.index + dir;
1064                        if (index >= 0 && index < gallery.links.length)
1065                                return gallery.links.eq(index);
1066                        else if (currentSettings.galleryLoop) {
1067                                if (index < 0)
1068                                        return gallery.links.eq(gallery.links.length-1);
1069                                else
1070                                        return gallery.links.eq(0);
1071                        }
1072                }
1073                return false;
1074        }
1075
1076        // Calculate the size for the contentWrapper
1077        function calculateSize(resizing) {
1078                debug('calculateSize');
1079
1080                modal.wrapper = modal.contentWrapper.children('div:first');
1081
1082                resized.width = false;
1083                resized.height = false;
1084                if (false && !currentSettings.windowResizing) {
1085                        initSettingsSize.width = currentSettings.width;
1086                        initSettingsSize.height = currentSettings.height;
1087                }
1088
1089                if (currentSettings.autoSizable && (!currentSettings.width || !currentSettings.height)) {
1090                        modal.contentWrapper
1091                                .css({
1092                                        opacity: 0,
1093                                        width: 'auto',
1094                                        height: 'auto'
1095                                })
1096                                .show();
1097                        var tmp = {
1098                                width: 'auto',
1099                                height: 'auto'
1100                        };
1101                        if (currentSettings.width) {
1102                                tmp.width = currentSettings.width;
1103                        } else if (currentSettings.type == 'iframe') {
1104                                tmp.width = currentSettings.minWidth;
1105                        }
1106
1107                        if (currentSettings.height) {
1108                                tmp.height = currentSettings.height;
1109                        } else if (currentSettings.type == 'iframe') {
1110                                tmp.height = currentSettings.minHeight;
1111                        }
1112
1113                        modal.content.css(tmp);
1114                        if (!currentSettings.width) {
1115                                currentSettings.width = modal.content.outerWidth(true);
1116                                resized.width = true;
1117                        }
1118                        if (!currentSettings.height) {
1119                                currentSettings.height = modal.content.outerHeight(true);
1120                                resized.height = true;
1121                        }
1122                        modal.contentWrapper.css({opacity: 1});
1123                        if (!resizing)
1124                                modal.contentWrapper.hide();
1125                }
1126
1127                if (currentSettings.type != 'image' && currentSettings.type != 'swf') {
1128                        currentSettings.width = Math.max(currentSettings.width, currentSettings.minWidth);
1129                        currentSettings.height = Math.max(currentSettings.height, currentSettings.minHeight);
1130                }
1131
1132                var outerWrapper = getOuter(modal.contentWrapper);
1133                var outerWrapper2 = getOuter(modal.wrapper);
1134                var outerContent = getOuter(modal.content);
1135
1136                var tmp = {
1137                        content: {
1138                                width: currentSettings.width,
1139                                height: currentSettings.height
1140                        },
1141                        wrapper2: {
1142                                width: currentSettings.width + outerContent.w.total,
1143                                height: currentSettings.height + outerContent.h.total
1144                        },
1145                        wrapper: {
1146                                width: currentSettings.width + outerContent.w.total + outerWrapper2.w.total,
1147                                height: currentSettings.height + outerContent.h.total + outerWrapper2.h.total
1148                        }
1149                };
1150
1151                if (currentSettings.resizable) {
1152                        var maxHeight = modal.blockerVars? modal.blockerVars.height : $(window).height()
1153                                                                - outerWrapper.h.border
1154                                                                - (tmp.wrapper.height - currentSettings.height);
1155                        var maxWidth = modal.blockerVars? modal.blockerVars.width : $(window).width()
1156                                                                - outerWrapper.w.border
1157                                                                - (tmp.wrapper.width - currentSettings.width);
1158                        maxHeight-= currentSettings.padding*2;
1159                        maxWidth-= currentSettings.padding*2;
1160
1161                        if (tmp.content.height > maxHeight || tmp.content.width > maxWidth) {
1162                                // We're gonna resize the modal as it will goes outside the view port
1163                                if (currentSettings.type == 'image' || currentSettings.type == 'swf') {
1164                                        // An image is resized proportionnaly
1165                                        var useW = currentSettings.imgWidth?currentSettings.imgWidth : currentSettings.width;
1166                                        var useH = currentSettings.imgHeight?currentSettings.imgHeight : currentSettings.height;
1167                                        var diffW = tmp.content.width - useW;
1168                                        var diffH = tmp.content.height - useH;
1169                                                if (diffH < 0) diffH = 0;
1170                                                if (diffW < 0) diffW = 0;
1171                                        var calcH = maxHeight - diffH;
1172                                        var calcW = maxWidth - diffW;
1173                                        var ratio = Math.min(calcH/useH, calcW/useW);
1174                                        calcW = Math.floor(useW*ratio);
1175                                        calcH = Math.floor(useH*ratio);
1176                                        tmp.content.height = calcH + diffH;
1177                                        tmp.content.width = calcW + diffW;
1178                                } else {
1179                                        // For an HTML content, we simply decrease the size
1180                                        tmp.content.height = Math.min(tmp.content.height, maxHeight);
1181                                        tmp.content.width = Math.min(tmp.content.width, maxWidth);
1182                                }
1183                                tmp.wrapper2 = {
1184                                                width: tmp.content.width + outerContent.w.total,
1185                                                height: tmp.content.height + outerContent.h.total
1186                                        };
1187                                tmp.wrapper = {
1188                                                width: tmp.content.width + outerContent.w.total + outerWrapper2.w.total,
1189                                                height: tmp.content.height + outerContent.h.total + outerWrapper2.h.total
1190                                        };
1191                        }
1192                }
1193
1194                if (currentSettings.type == 'swf') {
1195                        $('object, embed', modal.content)
1196                                .attr('width', tmp.content.width)
1197                                .attr('height', tmp.content.height);
1198                } else if (currentSettings.type == 'image') {
1199                        $('img', modal.content).css({
1200                                width: tmp.content.width,
1201                                height: tmp.content.height
1202                        });
1203                }
1204
1205                modal.content.css($.extend({}, tmp.content, currentSettings.cssOpt.content));
1206                modal.wrapper.css($.extend({}, tmp.wrapper2, currentSettings.cssOpt.wrapper2));
1207
1208                if (!resizing)
1209                        modal.contentWrapper.css($.extend({}, tmp.wrapper, currentSettings.cssOpt.wrapper));
1210
1211                if (currentSettings.type == 'image' && currentSettings.addImageDivTitle) {
1212                        // Adding the title for the image
1213                        $('img', modal.content).removeAttr('alt');
1214                        var divTitle = $('div', modal.content);
1215                        if (currentSettings.title != currentSettings.defaultImgAlt && currentSettings.title) {
1216                                if (divTitle.length == 0) {
1217                                        divTitle = $('<div>'+currentSettings.title+'</div>');
1218                                        modal.content.append(divTitle);
1219                                }
1220                                if (currentSettings.setWidthImgTitle) {
1221                                        var outerDivTitle = getOuter(divTitle);
1222                                        divTitle.css({width: (tmp.content.width + outerContent.w.padding - outerDivTitle.w.total)+'px'});
1223                                }
1224                        } else if (divTitle.length = 0) {
1225                                divTitle.remove();
1226                        }
1227                }
1228
1229                if (currentSettings.title)
1230                        setTitle();
1231
1232                tmp.wrapper.borderW = outerWrapper.w.border;
1233                tmp.wrapper.borderH = outerWrapper.h.border;
1234
1235                setCurrentSettings(tmp.wrapper);
1236                setMargin();
1237        }
1238
1239        function removeModal(e) {
1240                debug('removeModal');
1241                if (e)
1242                        e.preventDefault();
1243                if (modal.full && modal.ready) {
1244                        $(document).unbind('keydown.nyroModal');
1245                        if (!currentSettings.blocker)
1246                                $(window).unbind('resize.nyroModal');
1247                        modal.ready = false;
1248                        modal.anim = true;
1249                        modal.closing = true;
1250                        if (modal.loadingShown || modal.transition) {
1251                                currentSettings.hideLoading(modal, currentSettings, function() {
1252                                                modal.loading.hide();
1253                                                modal.loadingShown = false;
1254                                                modal.transition = false;
1255                                                currentSettings.hideBackground(modal, currentSettings, endRemove);
1256                                        });
1257                        } else {
1258                                if (fixFF)
1259                                        modal.content.css({position: ''}); // Fix Issue #10, remove the attribute
1260                                modal.wrapper.css({overflow: 'hidden'}); // Used to fix a visual issue when hiding
1261                                modal.content.css({overflow: 'hidden'}); // Used to fix a visual issue when hiding
1262                                $('iframe', modal.content).hide(); // Fix issue 359
1263                                if ($.isFunction(currentSettings.beforeHideContent)) {
1264                                        currentSettings.beforeHideContent(modal, currentSettings, function() {
1265                                                currentSettings.hideContent(modal, currentSettings, function() {
1266                                                        endHideContent();
1267                                                        currentSettings.hideBackground(modal, currentSettings, endRemove);
1268                                                });
1269                                        });
1270                                } else {
1271                                        currentSettings.hideContent(modal, currentSettings, function() {
1272                                                        endHideContent();
1273                                                        currentSettings.hideBackground(modal, currentSettings, endRemove);
1274                                                });
1275                                }
1276                        }
1277                }
1278                if (e)
1279                        return false;
1280        }
1281
1282        function showContentOrLoading() {
1283                debug('showContentOrLoading');
1284                if (modal.ready && !modal.anim) {
1285                        if (modal.dataReady) {
1286                                if (modal.tmp.html()) {
1287                                        modal.anim = true;
1288                                        if (modal.transition) {
1289                                                fillContent();
1290                                                modal.animContent = true;
1291                                                currentSettings.hideTransition(modal, currentSettings, function() {
1292                                                        modal.loading.hide();
1293                                                        modal.transition = false;
1294                                                        modal.loadingShown = false;
1295                                                        endShowContent();
1296                                                });
1297                                        } else {
1298                                                currentSettings.hideLoading(modal, currentSettings, function() {
1299                                                                modal.loading.hide();
1300                                                                modal.loadingShown = false;
1301                                                                fillContent();
1302                                                                setMarginLoading();
1303                                                                setMargin();
1304                                                                modal.animContent = true;
1305                                                                currentSettings.showContent(modal, currentSettings, endShowContent);
1306                                                        });
1307                                        }
1308                                }
1309                        } else if (!modal.loadingShown && !modal.transition) {
1310                                modal.anim = true;
1311                                modal.loadingShown = true;
1312                                if (modal.error)
1313                                        loadingError();
1314                                else
1315                                        modal.loading.html(currentSettings.contentLoading);
1316                                $(currentSettings.closeSelector, modal.loading)
1317                                        .unbind('click.nyroModal')
1318                                        .bind('click.nyroModal', removeModal);
1319                                setMarginLoading();
1320                                currentSettings.showLoading(modal, currentSettings, function(){modal.anim=false;showContentOrLoading();});
1321                        }
1322                }
1323        }
1324       
1325        // -------------------------------------------------------
1326        // Private Data Loaded callback
1327        // -------------------------------------------------------
1328
1329        function ajaxLoaded(data) {
1330                debug('AjaxLoaded: '+this.url);
1331               
1332                if (currentSettings.selector) {
1333                        var tmp = {};
1334                        var i = 0;
1335                        // Looking for script to store them
1336                        data = data
1337                                .replace(/\r\n/gi,'nyroModalLN')
1338                                .replace(/<script(.|\s)*?\/script>/gi, function(x) {
1339                                                tmp[i] = x;
1340                                                return '<pre style="display: none" class=nyroModalScript rel="'+(i++)+'"></pre>';
1341                                        });
1342                        data = $('<div>'+data+'</div>').find(currentSettings.selector).html()
1343                                .replace(/<pre style="display: none;?" class="?nyroModalScript"? rel="(.?)"><\/pre>/gi, function(x, y, z) {
1344                                        return tmp[y];
1345                                })
1346                                .replace(/nyroModalLN/gi,"\r\n");
1347                }
1348                modal.tmp.html(filterScripts(data));
1349                if (modal.tmp.html()) {
1350                        modal.dataReady = true;
1351                        showContentOrLoading();
1352                } else
1353                        loadingError();
1354        }
1355
1356        function formDataLoaded() {
1357                debug('formDataLoaded');
1358                var jFrom = $(currentSettings.from);
1359                jFrom.attr('action', jFrom.attr('action')+currentSettings.selector);
1360                jFrom.attr('target', '');
1361                $('input[name='+currentSettings.formIndicator+']', currentSettings.from).remove();
1362                var iframe = modal.tmp.children('iframe');
1363                var iframeContent = iframe.unbind('load').contents().find(currentSettings.selector || 'body').not('script[src]');
1364                iframe.attr('src', 'about:blank'); // Used to stop the loading in FF
1365                modal.tmp.html(iframeContent.html());
1366                if (modal.tmp.html()) {
1367                        modal.dataReady = true;
1368                        showContentOrLoading();
1369                } else
1370                        loadingError();
1371        }
1372       
1373        function iframeLoaded() {
1374                if ((window.location.hostname && currentSettings.url.indexOf(window.location.hostname) > -1)
1375                                ||      currentSettings.url.indexOf('http://')) {
1376                        var iframe = $('iframe', modal.full).contents();
1377                        var tmp = {};
1378                        if (currentSettings.titleFromIframe) {
1379                                tmp.title = iframe.find('title').text();
1380                                if (!tmp.title) {
1381                                        // for IE
1382                                        try {
1383                                                tmp.title = iframe.find('title').html();
1384                                        } catch(err) {}
1385                                }
1386                        }
1387                        var body = iframe.find('body');
1388                        if (!currentSettings.height && body.height())
1389                                tmp.height = body.height();
1390                        if (!currentSettings.width && body.width())
1391                                tmp.width = body.width();
1392                        $.extend(initSettingsSize, tmp);
1393                        $.nyroModalSettings(tmp);
1394                }
1395        }
1396
1397        function galleryCounts(nb, total, elts, settings) {
1398                if (total > 1)
1399                        settings.title+= (settings.title?' - ':'') +nb+'/'+total;
1400        }
1401
1402
1403        // -------------------------------------------------------
1404        // Private Animation callback
1405        // -------------------------------------------------------
1406
1407        function endHideContent() {
1408                debug('endHideContent');
1409                modal.anim = false;
1410                if (contentEltLast) {
1411                        contentEltLast.append(modal.content.contents());
1412                        contentEltLast = null;
1413                } else if (contentElt) {
1414                        contentElt.append(modal.content.contents());
1415                        contentElt= null;
1416                }
1417                modal.content.empty();
1418
1419                gallery = {};
1420
1421                modal.contentWrapper.hide().children().remove().empty().attr('style', '').hide();
1422
1423                if (modal.closing || modal.transition)
1424                        modal.contentWrapper.hide();
1425
1426                modal.contentWrapper
1427                        .css(currentSettings.cssOpt.wrapper)
1428                        .append(modal.content);
1429                showContentOrLoading();
1430        }
1431
1432        function endRemove() {
1433                debug('endRemove');
1434                $(document).unbind('keydown', keyHandler);
1435                modal.anim = false;
1436                modal.full.remove();
1437                modal.full = null;
1438                if (isIE6) {
1439                        body.css({height: '', width: '', position: '', overflow: '', marginLeft: '', marginRight: ''});
1440                        $('html').css({overflow: ''});
1441                }
1442                if ($.isFunction(currentSettings.endRemove))
1443                        currentSettings.endRemove(modal, currentSettings);
1444        }
1445
1446        function endBackground() {
1447                debug('endBackground');
1448                modal.ready = true;
1449                modal.anim = false;
1450                showContentOrLoading();
1451        }
1452
1453        function endShowContent() {
1454                debug('endShowContent');
1455                modal.anim = false;
1456                modal.animContent = false;
1457                modal.contentWrapper.css({opacity: ''}); // for the close button in IE
1458                fixFF = /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent) && parseFloat(browserVersion) < 1.9 && currentSettings.type != 'image';
1459
1460                if (fixFF)
1461                        modal.content.css({position: 'fixed'}); // Fix Issue #10
1462                modal.content.append(modal.scriptsShown);
1463
1464                if(currentSettings.type == 'iframe')
1465                        modal.content.find('iframe').attr('src', currentSettings.url);
1466
1467                if ($.isFunction(currentSettings.endShowContent))
1468                        currentSettings.endShowContent(modal, currentSettings);
1469
1470                if (shouldResize) {
1471                        shouldResize = false;
1472                        $.nyroModalSettings({width: currentSettings.setWidth, height: currentSettings.setHeight});
1473                        delete currentSettings['setWidth'];
1474                        delete currentSettings['setHeight'];
1475                }
1476                if (resized.width)
1477                        setCurrentSettings({width: null});
1478                if (resized.height)
1479                        setCurrentSettings({height: null});
1480        }
1481
1482
1483        // -------------------------------------------------------
1484        // Utilities
1485        // -------------------------------------------------------
1486
1487        // Get the selector from an url (as string)
1488        function getHash(url) {
1489                if (typeof url == 'string') {
1490                        var hashPos = url.indexOf('#');
1491                        if (hashPos > -1)
1492                                return url.substring(hashPos);
1493                }
1494                return '';
1495        }
1496
1497        // Filter an html content to remove the script[src]
1498        function filterScripts(data) {
1499                // Removing the body, head and html tag
1500                if (typeof data == 'string')
1501                        data = data.replace(/<\/?(html|head|body)([^>]*)>/gi, '');
1502                var tmp = new Array();
1503                $.each($.clean({0:data}, this.ownerDocument), function() {
1504                        if ($.nodeName(this, "script")) {
1505                                if (!this.src || $(this).attr('rel') == 'forceLoad') {
1506                                        if ($(this).attr('rev') == 'shown')
1507                                                modal.scriptsShown.push(this);
1508                                        else
1509                                                modal.scripts.push(this);
1510                                }
1511                        } else
1512                                tmp.push(this);
1513                });
1514                return tmp;
1515        }
1516
1517        // Get the vertical and horizontal margin, padding and border dimension
1518        function getOuter(elm) {
1519                elm = elm.get(0);
1520                var ret = {
1521                        h: {
1522                                margin: getCurCSS(elm, 'marginTop') + getCurCSS(elm, 'marginBottom'),
1523                                border: getCurCSS(elm, 'borderTopWidth') + getCurCSS(elm, 'borderBottomWidth'),
1524                                padding: getCurCSS(elm, 'paddingTop') + getCurCSS(elm, 'paddingBottom')
1525                        },
1526                        w: {
1527                                margin: getCurCSS(elm, 'marginLeft') + getCurCSS(elm, 'marginRight'),
1528                                border: getCurCSS(elm, 'borderLeftWidth') + getCurCSS(elm, 'borderRightWidth'),
1529                                padding: getCurCSS(elm, 'paddingLeft') + getCurCSS(elm, 'paddingRight')
1530                        }
1531                };
1532
1533                ret.h.outer = ret.h.margin + ret.h.border;
1534                ret.w.outer = ret.w.margin + ret.w.border;
1535
1536                ret.h.inner = ret.h.padding + ret.h.border;
1537                ret.w.inner = ret.w.padding + ret.w.border;
1538
1539                ret.h.total = ret.h.outer + ret.h.padding;
1540                ret.w.total = ret.w.outer + ret.w.padding;
1541
1542                return ret;
1543        }
1544
1545        function getCurCSS(elm, name) {
1546                var ret = parseInt($.curCSS(elm, name, true));
1547                if (isNaN(ret))
1548                        ret = 0;
1549                return ret;
1550        }
1551
1552        // Proxy Debug function
1553        function debug(msg) {
1554                if ($.fn.nyroModal.settings.debug || currentSettings && currentSettings.debug)
1555                        nyroModalDebug(msg, modal, currentSettings || {});
1556        }
1557
1558        // -------------------------------------------------------
1559        // Default animation function
1560        // -------------------------------------------------------
1561
1562        function showBackground(elts, settings, callback) {
1563                elts.bg.css({opacity:0}).fadeTo(500, 0.75, callback);
1564        }
1565
1566        function hideBackground(elts, settings, callback) {
1567                elts.bg.fadeOut(300, callback);
1568        }
1569
1570        function showLoading(elts, settings, callback) {
1571                elts.loading
1572                        .css({
1573                                marginTop: settings.marginTopLoading+'px',
1574                                marginLeft: settings.marginLeftLoading+'px',
1575                                opacity: 0
1576                        })
1577                        .show()
1578                        .animate({
1579                                opacity: 1
1580                        }, {complete: callback, duration: 400});
1581        }
1582
1583        function hideLoading(elts, settings, callback) {
1584                callback();
1585        }
1586
1587        function showContent(elts, settings, callback) {
1588                elts.loading
1589                        .css({
1590                                marginTop: settings.marginTopLoading+'px',
1591                                marginLeft: settings.marginLeftLoading+'px'
1592                        })
1593                        .show()
1594                        .animate({
1595                                width: settings.width+'px',
1596                                height: settings.height+'px',
1597                                marginTop: settings.marginTop+'px',
1598                                marginLeft: settings.marginLeft+'px'
1599                        }, {duration: 350, complete: function() {
1600                                elts.contentWrapper
1601                                        .css({
1602                                                width: settings.width+'px',
1603                                                height: settings.height+'px',
1604                                                marginTop: settings.marginTop+'px',
1605                                                marginLeft: settings.marginLeft+'px'
1606                                        })
1607                                        .show();
1608                                        elts.loading.fadeOut(200, callback);
1609                                }
1610                        });
1611        }
1612
1613        function hideContent(elts, settings, callback) {
1614                elts.contentWrapper
1615                        .animate({
1616                                height: '50px',
1617                                width: '50px',
1618                                marginTop: (-(25+settings.borderH)/2 + settings.marginScrollTop)+'px',
1619                                marginLeft: (-(25+settings.borderW)/2 + settings.marginScrollLeft)+'px'
1620                        }, {duration: 350, complete: function() {
1621                                elts.contentWrapper.hide();
1622                                callback();
1623                        }});
1624        }
1625
1626        function showTransition(elts, settings, callback) {
1627                // Put the loading with the same dimensions of the current content
1628                elts.loading
1629                        .css({
1630                                marginTop: elts.contentWrapper.css('marginTop'),
1631                                marginLeft: elts.contentWrapper.css('marginLeft'),
1632                                height: elts.contentWrapper.css('height'),
1633                                width: elts.contentWrapper.css('width'),
1634                                opacity: 0
1635                        })
1636                        .show()
1637                        .fadeTo(400, 1, function() {
1638                                        elts.contentWrapper.hide();
1639                                        callback();
1640                                });
1641        }
1642
1643        function hideTransition(elts, settings, callback) {
1644                // Place the content wrapper underneath the the loading with the right dimensions
1645                elts.contentWrapper
1646                        .hide()
1647                        .css({
1648                                width: settings.width+'px',
1649                                height: settings.height+'px',
1650                                marginLeft: settings.marginLeft+'px',
1651                                marginTop: settings.marginTop+'px',
1652                                opacity: 1
1653                        });
1654                elts.loading
1655                        .animate({
1656                                width: settings.width+'px',
1657                                height: settings.height+'px',
1658                                marginLeft: settings.marginLeft+'px',
1659                                marginTop: settings.marginTop+'px'
1660                        }, {complete: function() {
1661                                        elts.contentWrapper.show();
1662                                        elts.loading.fadeOut(400, function() {
1663                                                elts.loading.hide();
1664                                                callback();
1665                                        });
1666                                }, duration: 350});
1667        }
1668
1669        function resize(elts, settings, callback) {
1670                elts.contentWrapper
1671                        .animate({
1672                                width: settings.width+'px',
1673                                height: settings.height+'px',
1674                                marginLeft: settings.marginLeft+'px',
1675                                marginTop: settings.marginTop+'px'
1676                        }, {complete: callback, duration: 400});
1677        }
1678
1679        function updateBgColor(elts, settings, callback) {
1680                if (!$.fx.step.backgroundColor) {
1681                        elts.bg.css({backgroundColor: settings.bgColor});
1682                        callback();
1683                } else
1684                        elts.bg
1685                                .animate({
1686                                        backgroundColor: settings.bgColor
1687                                }, {complete: callback, duration: 400});
1688        }
1689
1690        // -------------------------------------------------------
1691        // Default initialization
1692        // -------------------------------------------------------
1693
1694        $($.fn.nyroModal.settings.openSelector).nyroModal();
1695
1696});
1697
1698// Default debug function, to be overwritten if needed
1699//      Be aware that the settings parameter could be empty
1700var tmpDebug = '';
1701function nyroModalDebug(msg, elts, settings) {
1702        if (elts.full && elts.bg) {
1703                elts.bg.prepend(msg+'<br />'+tmpDebug);
1704                tmpDebug = '';
1705        } else
1706                tmpDebug+= msg+'<br />';
1707}
Note: See TracBrowser for help on using the repository browser.