Вход Регистрация
Файл: usr/tpl/admin/js/moodalbox.js
Строк: 613
<?php
/**
 * SqueezeBox - Expandable Lightbox
 *
 * Allows to open various content as modal,
 * centered and animated box.
 *
 * Dependencies: MooTools 1.2
 *
 * Inspired by
 *  ... Lokesh Dhakar    - The original Lightbox v2
 *
 * @version        1.1 rc4
 *
 * @license        MIT-style license
 * @author        Harald Kirschner <mail [at] digitarald.de>
 * @copyright    Author
 */

var SqueezeBox = {

    
presets: {
        
onOpen$empty,
        
onClose$empty,
        
onUpdate$empty,
        
onResize$empty,
        
onMove$empty,
        
onShow$empty,
        
onHide$empty,
        
size: {x600y450},
        
sizeLoading: {x200y150},
        
marginInner: {x20y20},
        
marginImage: {x50y75},
        
handlerfalse,
        
targetnull,
        
closabletrue,
        
closeBtntrue,
        
zIndex65555,
        
overlayOpacity0.7,
        
classWindow'',
        
classOverlay'',
        
overlayFx: {},
        
resizeFx: {},
        
contentFx: {},
        
parsefalse// 'rel'
        
parseSecurefalse,
        
shadowtrue,
        
documentnull,
        
ajaxOptions: {}
    },

    
initialize: function(presets) {
        if (
this.options) return this;

        
this.presets $merge(this.presetspresets);
        
this.doc this.presets.document || document;
        
this.options = {};
        
this.setOptions(this.presets).build();
        
this.bound = {
            
windowthis.reposition.bind(this, [null]),
            
scrollthis.checkTarget.bind(this),
            
closethis.close.bind(this),
            
keythis.onKey.bind(this)
        };
        
this.isOpen this.isLoading false;
        return 
this;
    },

    
build: function() {
        
this.overlay = new Element('div', {
            
id'sbox-overlay',
            
styles: {display'none'zIndexthis.options.zIndex}
        });
        
this.win = new Element('div', {
            
id'sbox-window',
            
styles: {display'none'zIndexthis.options.zIndex 2}
        });
        if (
this.options.shadow) {
            if (
Browser.Engine.webkit420) {
                
this.win.setStyle('-webkit-box-shadow''0 0 10px rgba(0, 0, 0, 0.7)');
            } else if (!
Browser.Engine.trident4) {
                var 
shadow = new Element('div', {'class''sbox-bg-wrap'}).inject(this.win);
                var 
relay = function(e) {
                    
this.overlay.fireEvent('click', [e]);
                }.
bind(this);
                [
'n''ne''e''se''s''sw''w''nw'].each(function(dir) {
                    new 
Element('div', {'class''sbox-bg sbox-bg-' dir}).inject(shadow).addEvent('click'relay);
                });
            }
        }
        
this.content = new Element('div', {id'sbox-content'}).inject(this.win);
        
this.closeBtn = new Element('a', {id'sbox-btn-close'href'#'}).inject(this.win);
        
this.fx = {
            
overlay: new Fx.Tween(this.overlay$merge({
                
property'opacity',
                
onStartEvents.prototype.clearChain,
                
duration250,
                
link'cancel'
            
}, this.options.overlayFx)).set(0),
            
win: new Fx.Morph(this.win$merge({
                
onStartEvents.prototype.clearChain,
                
unit'px',
                
duration750,
                
transitionFx.Transitions.Quint.easeOut,
                
link'cancel',
                
unit'px'
            
}, this.options.resizeFx)),
            
content: new Fx.Tween(this.content$merge({
                
property'opacity',
                
duration250,
                
link'cancel'
            
}, this.options.contentFx)).set(0)
        };
        $(
this.doc.body).adopt(this.overlaythis.win);
    },

    
assign: function(tooptions) {
        return ($(
to) || $$(to)).addEvent('click', function() {
            return !
SqueezeBox.fromElement(thisoptions);
        });
    },
    
    
open: function(subjectoptions) {
        
this.initialize();

        if (
this.element != nullthis.trash();
        
this.element = $(subject) || false;
        
        
this.setOptions($merge(this.presetsoptions || {}));
        
        if (
this.element && this.options.parse) {
            var 
obj this.element.getProperty(this.options.parse);
            if (
obj && (obj JSON.decode(objthis.options.parseSecure))) this.setOptions(obj);
        }
        
this.url = ((this.element) ? (this.element.get('href')) : subject) || this.options.url || '';

        
this.assignOptions();
        
        var 
handler handler || this.options.handler;
        if (
handler) return this.setContent(handlerthis.parsers[handler].call(thistrue));
        var 
ret false;
        return 
this.parsers.some(function(parserkey) {
            var 
content parser.call(this);
            if (
content) {
                
ret this.setContent(keycontent);
                return 
true;
            }
            return 
false;
        }, 
this);
    },
    
    
fromElement: function(fromoptions) {
        return 
this.open(fromoptions);
    },

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

    
close: function(e) {
        var 
stoppable = ($type(e) == 'event');
        if (
stoppablee.stop();
        if (!
this.isOpen || (stoppable && !$lambda(this.options.closable).call(thise))) return this;
        
this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));
        
this.win.setStyle('display''none');
        
this.fireEvent('onClose', [this.content]);
        
this.trash();
        
this.toggleListeners();
        
this.isOpen false;
        return 
this;
    },

    
trash: function() {
        
this.element this.asset null;
        
this.content.empty();
        
this.options = {};
        
this.removeEvents().setOptions(this.presets).callChain();
    },

    
onError: function() {
        
this.asset null;
        
this.setContent('string'this.options.errorMsg || 'An error occurred');
    },

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

    
applyContent: function(contentsize) {
        if (!
this.isOpen && !this.applyTimer) return;
        
this.applyTimer $clear(this.applyTimer);
        
this.hideContent();
        if (!
content) {
            
this.toggleLoading(true);
        } else {
            if (
this.isLoadingthis.toggleLoading(false);
            
this.fireEvent('onUpdate', [this.content], 20);
        }
        if (
content) {
            if ([
'string''array'].contains($type(content))) this.content.set('html'content);
            else if (!
this.content.hasChild(content)) this.content.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) {
        
this.showTimer $clear(this.showTimer || null);
        var 
box this.doc.getSize(), scroll this.doc.getScroll();
        
this.size $merge((this.isLoading) ? this.options.sizeLoading this.options.sizesize);
        var 
to = {
            
widththis.size.x,
            
heightthis.size.y,
            
left: (scroll.+ (box.this.size.this.options.marginInner.x) / 2).toInt(),
            
top: (scroll.+ (box.this.size.this.options.marginInner.y) / 2).toInt()
        };
        
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();
    },

    
toggleListeners: function(state) {
        var fn = (
state) ? 'addEvent' 'removeEvent';
        
this.closeBtn[fn]('click'this.bound.close);
        
this.overlay[fn]('click'this.bound.close);
        
this.doc[fn]('keydown'this.bound.key)[fn]('mousewheel'this.bound.scroll);
        
this.doc.getWindow()[fn]('resize'this.bound.window)[fn]('scroll'this.bound.window);
    },

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

    
toggleOverlay: function(state) {
        var 
full this.doc.getSize().x;
        
this.overlay.setStyle('display', (state) ? '' 'none');
        
this.doc.body[(state) ? 'addClass' 'removeClass']('body-overlayed');
        if (
state) {
            
this.scrollOffset this.doc.getWindow().getSize().full;
            
this.doc.body.setStyle('margin-right'this.scrollOffset);
        } else {
            
this.doc.body.setStyle('margin-right''');
        }
    },

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

    
hideContent: function() {
        if (!
this.content.get('opacity')) this.fireEvent('onHide', [this.win]);
        
this.fx.content.cancel().set(0);
    },

    
onKey: function(e) {
        switch (
e.key) {
            case 
'esc'this.close(e);
            case 
'up': case 'down': return false;
        }
    },

    
checkTarget: function(e) {
        return 
this.content.hasChild(e.target);
    },

    
reposition: function() {
        var 
size this.doc.getSize(), scroll this.doc.getScroll(), ssize this.doc.getScrollSize();
        
this.overlay.setStyles({
            
widthssize.'px',
            
heightssize.'px'
        
});
        
this.win.setStyles({
            
left: (scroll.+ (size.this.win.offsetWidth) / this.scrollOffset).toInt() + 'px',
            
top: (scroll.+ (size.this.win.offsetHeight) / 2).toInt() + 'px'
        
});
        return 
this.fireEvent('onMove', [this.overlaythis.win]);
    },

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

    
extend: function(properties) {
        return 
$extend(thisproperties);
    },

    
handlers: new Hash(),

    
parsers: new Hash()

};

SqueezeBox.extend(new Events($empty)).extend(new Options($empty)).extend(new Chain($empty));

SqueezeBox.parsers.extend({

    
image: function(preset) {
        return (
preset || (/.(?:jpg|png|gif)$/i).test(this.url)) ? this.url false;
    },

    clone: function(
preset) {
        if ($(
this.options.target)) return $(this.options.target);
        if (
this.element && !this.element.parentNode) return this.element;
        var 
bits this.url.match(/#([w-]+)$/);
        
return (bits) ? $(bits[1]) : (preset this.element false);
    },

    
ajax: function(preset) {
        return (
preset || (this.url && !(/^(?:javascript|#)/i).test(this.url))) ? this.url : false;
    
},

    
iframe: function(preset) {
        return (
preset || this.url) ? this.url false;
    },

    
string: function(preset) {
        return 
true;
    }
});

SqueezeBox.handlers.extend({

    
image: function(url) {
        var 
sizetmp = new Image();
        
this.asset null;
        
tmp.onload tmp.onabort tmp.onerror = (function() {
            
tmp.onload tmp.onabort tmp.onerror null;
            if (!
tmp.width) {
                
this.onError.delay(10this);
                return;
            }
            var 
box this.doc.getSize();
            
box.-= this.options.marginImage.x;
            
box.-= this.options.marginImage.y;
            
size = {xtmp.widthytmp.height};
            for (var 
2i--;) {
                if (
size.box.x) {
                    
size.*= box.size.x;
                    
size.box.x;
                } else if (
size.box.y) {
                    
size.*= box.size.y;
                    
size.box.y;
                }
            }
            
size.size.x.toInt();
            
size.size.y.toInt();
            
this.asset = $(tmp);
            
tmp null;
            
this.asset.width size.x;
            
this.asset.height size.y;
            
this.applyContent(this.assetsize);
        }).
bind(this);
        
tmp.src url;
        if (
tmp && tmp.onload && tmp.completetmp.onload();
        return (
this.asset) ? [this.assetsize] : null;
    },

    clone: function(
el) {
        if (
el) return el.clone();
        return 
this.onError();
    },

    
adopt: function(el) {
        if (
el) return el;
        return 
this.onError();
    },

    
ajax: function(url) {
        var 
options this.options.ajaxOptions || {};
        
this.asset = new Request.HTML($merge({
            
method'get',
            
evalScriptsfalse
        
}, this.options.ajaxOptions)).addEvents({
            
onSuccess: function(resp) {
                
this.applyContent(resp);
                if (
options.evalScripts !== null && !options.evalScripts$exec(this.asset.response.javascript);
                
this.fireEvent('onAjax', [respthis.asset]);
                
this.asset null;
            }.
bind(this),
            
onFailurethis.onError.bind(this)
        });
        
this.asset.send.delay(10this.asset, [{urlurl}]);
    },

    
iframe: function(url) {
        
this.asset = new Element('iframe'$merge({
            
srcurl,
            
frameBorder0,
            
widththis.options.size.x,
            
heightthis.options.size.y
        
}, this.options.iframeOptions));
        if (
this.options.iframePreload) {
            
this.asset.addEvent('load', function() {
                
this.applyContent(this.asset.setStyle('display'''));
            }.
bind(this));
            
this.asset.setStyle('display''none').inject(this.content);
            return 
false;
        }
        return 
this.asset;
    },

    
string: function(str) {
        return 
str;
    }

});

SqueezeBox.handlers.url SqueezeBox.handlers.ajax;
SqueezeBox.parsers.url SqueezeBox.parsers.ajax;
SqueezeBox.parsers.adopt SqueezeBox.parsers.clone;
?>
Онлайн: 2
Реклама