Вход Регистрация
Файл: gamele.ru/js/SqueezeBox.js
Строк: 506
<?php
/**
 * SqueezeBox - Expandable Lightbox
 * 
 * Allows to open various content as modal,
 * centered and animated box.
 * 
 * Dependencies: MooTools 1.2+ (09/2007)
 * 
 * Inspired by 
 *  ... Lokesh Dhakar    - The original Lightbox v2
 * 
 * @version        1.0rc2
 * 
 * @license        MIT-style license
 * @author        Harald Kirschner <mail [at] digitarald.de>
 * @copyright    Author
 */
var SqueezeBox = {

    
presets: {
        
size: {x600y450},
        
sizeLoading: {x200y150},
        
marginInner: {x20y20},
        
marginImage: {x150y200},
        
handlerfalse,
        
targetnull,
        
closeWithOverlaytrue,
        
zIndex65555,
        
overlayOpacity0.7,
        
classWindow'',
        
classOverlay'',
        
disableFxfalse,
        
onOpen$empty,
        
onClose$empty,
        
onUpdate$empty,
        
onResize$empty,
        
onMove$empty,
        
onShow$empty,
        
onHide$empty,
        
fxOverlayDuration250,
        
fxResizeDuration750,
        
fxResizeTransitionFx.Transitions.Quint.easeOut,
        
fxContentDuration250,
        
ajaxOptions: {}
    },

    
initialize: function(options) {
        if (
this.options) return this;
        
this.presets $merge(this.presetsoptions);
        
this.setOptions(this.presets).build();
        
this.listeners = {
            
windowthis.reposition.bind(this, [null]),
            
closethis.close.bind(this),
            
keythis.onKey.bind(this)
        };
        
this.isOpen this.isLoading false;
        return 
this;
    },

    
build: function() {
        
this.content = new Element('div', {id'sbox-content'});
        
this.btnClose = new Element('a', {id'sbox-btn-close'href'#'});
        
this.overlay = new Element('div', {
            
id'sbox-overlay',
            
styles: {display'none'zIndexthis.options.zIndex}
        }).
inject(document.body);
        
this.win = new Element('div', {
            
id'sbox-window',
            
styles: {display'none'zIndexthis.options.zIndex 2}
        }).
adopt(this.btnClosethis.content).inject(document.body);
        
this.fx = {
            
overlay: new Fx.Style(this.overlay'opacity', {
                
durationthis.options.fxOverlayDuration,
                
waitfalse
            
}).set(0),
            
win: new Fx.Styles(this.win, {
                
durationthis.options.fxResizeDuration,
                
transitionthis.options.fxResizeTransition,
                
waitfalse,
                
unit'px'
            
}),
            
content: new Fx.Style(this.content'opacity', {
                
durationthis.options.fxContentDuration,
                
waitfalse
            
}).set(0)
        };
    },

    
addClick: function(el) {
        return 
el.addEvent('click', function() {
            return !
SqueezeBox.fromElement(this);
        });
    },

    
fromElement: function(eloptions) {
        
this.initialize();
        
this.element = $(el);
        
this.setOptions($merge(this.presetsoptions || {}, (this.element && this.element.rel) ? Json.evaluate(this.element.rel) : {}));
        
this.assignOptions();
        
this.url = ((this.element) ? (this.options.url || this.element.getProperty('href')) : el) || '';
        if (
this.options.handler) {
            var 
handler this.options.handler;
            return 
this.setContent(handlerthis.parsers[handler].call(thistrue));
        }
        var 
res;
        for (var 
key in this.parsers) {
            if ((
res this.parsers[key].call(this))) return this.setContent(keyres);
        }
        return 
false;
    },

    
assignOptions: function() {
        
this.overlay.setProperty('class'this.options.classOverlay);
        
this.win.setProperty('class'this.options.classWindow);
        if (
Client.Engine.ie6this.win.addClass('sbox-window-ie6');
    },

    
close: function(e) {
        if (
e) new Event(e).stop();
        if (!
this.isOpen) return this;
        
this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));
        
this.win.setStyle('display''none');
        
this.trashImage();
        
this.toggleListeners();
        
this.isOpen null;
        
this.fireEvent('onClose', [this.content]).removeEvents();
        
this.options = {};
        
this.setOptions(this.presets).callChain();
        return 
this;
    },

    
onError: function() {
        if (
this.imagethis.trashImage();
        
this.setContent('Error during loading');
    },

    
trashImage: function() {
        if (
this.imagethis.image this.image.onload this.image.onerror this.image.onabort null;
    },

    
setContent: function(handlercontent) {
        if (!
this.handlers[handler]) return false;
        
this.content.setProperty('class''sbox-content-' handler);
        
this.applyTimer this.applyContent.delay(this.fx.overlay.options.durationthisthis.handlers[handler].call(thiscontent));
        if (
this.overlay.$attributes.opacity) return this;
        
this.toggleOverlay(true);
        
this.fx.overlay.start(this.options.overlayOpacity);
        
this.reposition();
        return 
this;
    },

    
applyContent: function(contentsize) {
        
this.applyTimer $clear(this.applyTimer);
        
this.hideContent();
        if (!
contentthis.toggleLoading(true);
        else {
            if (
this.isLoadingthis.toggleLoading(false);
            
this.fireEvent('onUpdate', [this.content], 20);
        }
        
this.content.empty()[['string''array'false].contains($type(content)) ? 'setHTML' 'adopt'](content || '');
        
this.callChain();
        if (!
this.isOpen) {
            
this.toggleListeners(true);
            
this.resize(sizetrue);
            
this.isOpen true;
            
this.fireEvent('onOpen', [this.content]);
        } else 
this.resize(size);
    },

    
resize: function(sizeinstantly) {
        var 
sizes window.getSize();
        
this.size $merge(this.isLoading this.options.sizeLoading this.options.sizesize);
        var 
to = {
            
widththis.size.xheightthis.size.y,
            
left: (sizes.scroll.+ (sizes.size.this.size.this.options.marginInner.x) / 2).toInt(),
            
top: (sizes.scroll.+ (sizes.size.this.size.this.options.marginInner.y) / 2).toInt()
        };
        
$clear(this.showTimer || null);
        
this.hideContent();
        if (!
instantly) {
            
this.fx.win.start(to).chain(this.showContent.bind(this));
        } else {
            
this.win.setStyles(to).setStyle('display''');
            
this.showTimer this.showContent.delay(50this);
        }
        return 
this.reposition(sizes);
    },

    
toggleListeners: function(state) {
        var 
task state 'addEvent' 'removeEvent';
        
this.btnClose[task]('click'this.listeners.close);
        if (
this.options.closeWithOverlaythis.overlay[task]('click'this.listeners.close);
        
document[task]('keydown'this.listeners.key);
        
window[task]('resize'this.listeners.window);
        
window[task]('scroll'this.listeners.window);
    },

    
toggleLoading: function(state) {
        
this.isLoading state;
        
this.win[state 'addClass' 'removeClass']('sbox-loading');
        if (
statethis.fireEvent('onLoading', [this.win]);
    },

    
toggleOverlay: function(state) {
        
this.overlay.setStyle('display'state '' 'none');
        
document.body[state 'addClass' 'removeClass']('body-overlayed');
    },

    
showContent: function() {
        if (
this.content.$attributes.opacitythis.fireEvent('onShow', [this.win]);
        
this.fx.content.start(1);
    },

    
hideContent: function() {
        if (!
this.content.$attributes.opacitythis.fireEvent('onHide', [this.win]);
        
this.fx.content.set(0);
    },

    
onKey: function(e) {
        switch (
e.key) {
            case 
'esc':
                
this.close();
                break;
        }
    },

    
reposition: function(sizes) {
        
sizes sizes || window.getSize();
        
this.overlay.setStyles({
            
leftsizes.scroll.xtopsizes.scroll.y,
            
widthsizes.size.xheightsizes.size.y
        
});
        
this.win.setStyles({
            
left: (sizes.scroll.+ (sizes.size.this.win.offsetWidth) / 2).toInt(),
            
top: (sizes.scroll.+ (sizes.size.this.win.offsetHeight) / 2).toInt()
        });
        return 
this.fireEvent('onMove', [this.overlaythis.winsizes]);
    },

    
removeEvents: function(type){
        if (!
this.$events) return this;
        if (!
typethis.$events null;
        else if (
this.$events[type]) this.$events[type] = null;
        return 
this;
    },

    
parsers: {
        
'image': function(preset) {
            return (
preset || this.url.test(/.(jpg|jpeg|png|gif|bmp)$/i)) ? this.url false;
        },
        
'clone': function(preset) {
            if ($(
this.options.target)) return $(this.options.target);
            if (
preset || (this.element && !this.element.parentNode)) return this.element;
            var 
bits this.url.match(/#([w-]+)$/);
            
return (bits) ? $(bits[1]) : false;
        },
        
'url': function(preset) {
            return (
preset || (this.url && !this.url.test(/^javascript:/i))) ? this.urlfalse;
        },
        
'iframe': function(preset) {
            return (
preset || this.url) ? this.url false;
        },
        
'string': function(preset) {
            return 
true;
        }
    },

    
handlers: {
        
'image': function(url) {
            var 
sizetmp = new Image();
            
this.image null;
            
tmp.onload tmp.onabort tmp.onerror = (function() {
                
tmp.onload tmp.onabort tmp.onerror null;
                if (!
tmp.width) {
                    
this.onError.delay(10this);
                    return;
                }
                var 
win = {xwindow.getWidth() - this.options.marginImage.xywindow.getHeight() - this.options.marginImage.y};
                
size = {xtmp.widthytmp.height};
                for (var 
2i--;) {
                    if (
size.win.x) {
                        
size.*= win.size.x;
                        
size.win.x;
                    } else if (
size.win.y) {
                        
size.*= win.size.y;
                        
size.win.y;
                    }
                }
                
size.size.x.toInt();
                
size.size.y.toInt();
                
this.image = (Client.Engine.webkit419) ? new Element('img', {srcthis.image.src}) : $(tmp);
                
tmp null;
                
this.image.setProperties({widthsize.xheightsize.y});
                if (
this.isOpenthis.applyContent(this.imagesize);
            }).
bind(this);
            
tmp.src url;
            if (
tmp && tmp.onload && tmp.completetmp.onload();
            return (
this.image) ? [this.imagesize] : null;
        },
        
'clone': function(el) {
            return 
el.clone();
        },
        
'adopt': function(el) {
            return 
el;
        },
        
'url': function(url) {
            
this.ajax = new Ajax(urlthis.options.ajaxOptions);
            
this.ajax.addEvents({
                
'onSuccess': function(resp) {
                    
this.applyContent(resp);
                    
this.ajax null;
                }.
bind(this),
                
'onFailure'this.onError.bind(this)
            }).
request.delay(10this.ajax);
        },
        
'iframe': function(url) {
            return new 
Element('iframe', {
                
srcurl,
                
frameBorder0,
                
widththis.options.size.x,
                
heightthis.options.size.y
            
});
        },
        
'string': function(str) {
            return 
str;
        }
    },

    
extend$extend
};

SqueezeBox.parsers.adopt SqueezeBox.parsers.clone;

SqueezeBox.extend(Events.prototype).extend(Options.prototype).extend(Chain.prototype);
?>
Онлайн: 1
Реклама