Вход Регистрация
Файл: contao-3.5.8/assets/mootools/datepicker/2.2.0/src/Picker.js
Строк: 474
<?php
/*
---
name: Picker
description: Creates a Picker, which can be used for anything
authors: Arian Stolwijk
requires: [Core/Element.Dimensions, Core/Fx.Tween, Core/Fx.Transitions]
provides: Picker
...
*/


var Picker = new Class({

    Implements: [
OptionsEvents],

    
options: {/*
        onShow: function(){},
        onOpen: function(){},
        onHide: function(){},
        onClose: function(){},*/

        
pickerClass'datepicker',
        
injectnull,
        
animationDuration400,
        
useFadeInOuttrue,
        
positionOffset: {x0y0},
        
pickerPosition'bottom',
        
draggabletrue,
        
showOnInittrue,
        
columns1,
        
footerfalse
    
},

    
initialize: function(options){
        
this.setOptions(options);
        
this.constructPicker();
        if (
this.options.showOnInitthis.show();
    },

    
constructPicker: function(){
        var 
options this.options;

        var 
picker this.picker = new Element('div', {
            
'class'options.pickerClass,
            
styles: {
                
left0,
                
top0,
                
display'none',
                
opacity0
            
}
        }).
inject(options.inject || document.body);
        
picker.addClass('column_' options.columns);

        if (
options.useFadeInOut){
            
picker.set('tween', {
                
durationoptions.animationDuration,
                
link'cancel'
            
});
        }

        
// Build the header
        
var header this.header = new Element('div.header').inject(picker);

        var 
title this.title = new Element('div.title').inject(header);
        var 
titleID this.titleID 'pickertitle-' String.uniqueID();
        
this.titleText = new Element('div', {
            
'role''heading',
            
'class''titleText',
            
'id'titleID,
            
'aria-live''assertive',
            
'aria-atomic''true'
        
}).inject(title);

        
this.closeButton = new Element('div.closeButton[text=x][role=button]')
            .
addEvent('click'this.close.pass(falsethis))
            .
inject(header);

        
// Build the body of the picker
        
var body this.body = new Element('div.body').inject(picker);

        if (
options.footer){
            
this.footer = new Element('div.footer').inject(picker);
            
picker.addClass('footer');
        }

        
// oldContents and newContents are used to slide from the old content to a new one.
        
var slider this.slider = new Element('div.slider', {
            
styles: {
                
position'absolute',
                
top0,
                
left0
            
}
        }).
set('tween', {
            
durationoptions.animationDuration,
            
transitionFx.Transitions.Quad.easeInOut
        
}).inject(body);

        
this.newContents = new Element('div', {
            
styles: {
                
position'absolute',
                
top0,
                
left0
            
}
        }).
inject(slider);

        
this.oldContents = new Element('div', {
            
styles: {
                
position'absolute',
                
top0
            
}
        }).
inject(slider);

        
this.originalColumns options.columns;
        
this.setColumns(options.columns);

        
// IFrameShim for select fields in IE
        
var shim this.shim window['IframeShim'] ? new IframeShim(picker) : null;

        
// Dragging
        
if (options.draggable && typeOf(picker.makeDraggable) == 'function'){
            
this.dragger picker.makeDraggable(shim ? {
                
onDragshim.position.bind(shim)
            } : 
null);
            
picker.setStyle('cursor''move');
        }
    },

    
open: function(noFx){
        if (
this.opened == true) return this;
        
this.opened true;
        var 
self this,
            
picker this.picker.setStyle('display''block').set('aria-hidden''false')
        if (
this.shimthis.shim.show();
        
this.fireEvent('open');
        if (
this.options.useFadeInOut && !noFx){
            
picker.get('tween').start('opacity'1).chain(function(){
                
self.fireEvent('show');
                
this.callChain();
            });
        } else {
            
picker.setStyle('opacity'1);
            
this.fireEvent('show');
        }
        return 
this;
    },

    
show: function(){
        return 
this.open(true);
    },

    
close: function(noFx){
        if (
this.opened == false) return this;
        
this.opened false;
        
this.fireEvent('close');
        var 
self thispicker this.pickerhide = function(){
            
picker.setStyle('display''none').set('aria-hidden''true');
            if (
self.shimself.shim.hide();
            
self.fireEvent('hide');
        };
        if (
this.options.useFadeInOut && !noFx){
            
picker.get('tween').start('opacity'0).chain(hide);
        } else {
            
picker.setStyle('opacity'0);
            
hide();
        }
        return 
this;
    },

    
hide: function(){
        return 
this.close(true);
    },

    
toggle: function(){
        return 
this[this.opened == true 'close' 'open']();
    },

    
destroy: function(){
        
this.picker.destroy();
        if (
this.shimthis.shim.destroy();
    },

    
position: function(xy){
        var 
offset this.options.positionOffset,
            
scroll document.getScroll(),
            
size document.getSize(),
            
pickersize this.picker.getSize();

        if (
typeOf(x) == 'element'){
            var 
element x,
                
where || this.options.pickerPosition;

            var 
elementCoords element.getCoordinates();

            
= (where == 'left') ? elementCoords.left pickersize.x
                
: (where == 'bottom' || where == 'top') ? elementCoords.left
                
elementCoords.right
            y 
= (where == 'bottom') ? elementCoords.bottom
                
: (where == 'top') ? elementCoords.top pickersize.y
                
elementCoords.top;
        }

        
+= offset.* ((where && where == 'left') ? -1);
        
+= offset.* ((where && where == 'top') ? -11);

        if ((
pickersize.x) > (size.scroll.x)) = (size.scroll.x) - pickersize.x;
        if ((
pickersize.y) > (size.scroll.y)) = (size.scroll.y) - pickersize.y;
        if (
00;
        if (
00;

        
this.picker.setStyles({
            
leftx,
            
topy
        
});
        if (
this.shimthis.shim.position();
        return 
this;
    },

    
setBodySize: function(){
        var 
bodysize this.bodysize this.body.getSize();

        
this.slider.setStyles({
            
widthbodysize.x,
            
heightbodysize.y
        
});
        
this.oldContents.setStyles({
            
leftbodysize.x,
            
widthbodysize.x,
            
heightbodysize.y
        
});
        
this.newContents.setStyles({
            
widthbodysize.x,
            
heightbodysize.y
        
});
    },

    
setColumnContent: function(columncontent){
        var 
columnElement this.columns[column];
        if (!
columnElement) return this;

        var 
type typeOf(content);
        if ([
'string''number'].contains(type)) columnElement.set('text'content);
        else 
columnElement.empty().adopt(content);

        return 
this;
    },

    
setColumnsContent: function(contentfx){
        var 
old this.columns;
        
this.columns this.newColumns;
        
this.newColumns old;

        
content.forEach(function(_contenti){
            
this.setColumnContent(i_content);
        }, 
this);
        return 
this.setContent(nullfx);
    },

    
setColumns: function(columns){
        var 
_columns this.columns = new Elements_newColumns this.newColumns = new Elements;
        for (var 
columnsi--;){
            
_columns.push(new Element('div.column').addClass('column_' + (columns i)));
            
_newColumns.push(new Element('div.column').addClass('column_' + (columns i)));
        }

        var 
oldClass 'column_' this.options.columnsnewClass 'column_' columns;
        
this.picker.removeClass(oldClass).addClass(newClass);

        
this.options.columns columns;
        return 
this;
    },

    
setContent: function(contentfx){
        if (
content) return this.setColumnsContent([content], fx);

        
// swap contents so we can fill the newContents again and animate
        
var old this.oldContents;
        
this.oldContents this.newContents;
        
this.newContents old;
        
this.newContents.empty();

        
this.newContents.adopt(this.columns);

        
this.setBodySize();

        if (
fx){
            
this.fx(fx);
        } else {
            
this.slider.setStyle('left'0);
            
this.oldContents.setStyles({left0opacity0});
            
this.newContents.setStyles({left0opacity1});
        }
        return 
this;
    },

    
fx: function(fx){
        var 
oldContents this.oldContents,
            
newContents this.newContents,
            
slider this.slider,
            
bodysize this.bodysize;
        if (
fx == 'right'){
            
oldContents.setStyles({left0opacity1});
            
newContents.setStyles({leftbodysize.xopacity1});
            
slider.setStyle('left'0).tween('left'0, -bodysize.x);
        } else if (
fx == 'left'){
            
oldContents.setStyles({leftbodysize.xopacity1});
            
newContents.setStyles({left0opacity1});
            
slider.setStyle('left', -bodysize.x).tween('left', -bodysize.x0);
        } else if (
fx == 'fade'){
            
slider.setStyle('left'0);
            
oldContents.setStyle('left'0).set('tween', {
                
durationthis.options.animationDuration 2
            
}).tween('opacity'10).get('tween').chain(function(){
                
oldContents.setStyle('left'bodysize.x);
            });
            
newContents.setStyles({opacity0left0}).set('tween', {
                
durationthis.options.animationDuration
            
}).tween('opacity'01);
        }
    },

    
toElement: function(){
        return 
this.picker;
    },

    
setTitle: function(contentfn){
        if (!
fnfn = Function.from;
        
this.titleText.empty().adopt(
            Array.
from(content).map(function(itemi){
                return 
typeOf(item) == 'element'
                    
item
                    
: new Element('div.column', {textfn(itemthis.options)}).addClass('column_' + (1));
            }, 
this)
        );
        return 
this;
    },

    
setTitleEvent: function(fn){
        
this.titleText.removeEvents('click');
        if (
fnthis.titleText.addEvent('click'fn);
        
this.titleText.setStyle('cursor'fn 'pointer' '');
        return 
this;
    }

});
?>
Онлайн: 2
Реклама