Вход Регистрация
Файл: tyde/www/web/js/core/dropdown.js
Строк: 408
<?php
/*! UIkit 2.24.3 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
(function(UI) {

    
"use strict";

    var 
active falsehoverIdleflips = {
        
'x': {
            
"bottom-left"   'bottom-right',
            
"bottom-right"  'bottom-left',
            
"bottom-center" 'bottom-right',
            
"top-left"      'top-right',
            
"top-right"     'top-left',
            
"top-center"    'top-right',
            
"left-top"      'right',
            
"left-bottom"   'right-bottom',
            
"left-center"   'right-center',
            
"right-top"     'left',
            
"right-bottom"  'left-bottom',
            
"right-center"  'left-center'
        
},
        
'y': {
            
"bottom-left"   'top-left',
            
"bottom-right"  'top-right',
            
"bottom-center" 'top-center',
            
"top-left"      'bottom-left',
            
"top-right"     'bottom-right',
            
"top-center"    'bottom-center',
            
"left-top"      'top-left',
            
"left-bottom"   'left-bottom',
            
"left-center"   'top-left',
            
"right-top"     'top-left',
            
"right-bottom"  'bottom-left',
            
"right-center"  'top-left'
        
},
        
'xy': {

        }
    };

    
UI.component('dropdown', {

        
defaults: {
           
'mode'            'hover',
           
'pos'             'bottom-left',
           
'offset'          0,
           
'remaintime'      800,
           
'justify'         false,
           
'boundary'        UI.$win,
           
'delay'           0,
           
'dropdownSelector''.uk-dropdown,.uk-dropdown-blank',
           
'hoverDelayIdle'  250,
           
'preventflip'     false
        
},

        
remainIdlefalse,

        
boot: function() {

            var 
triggerevent UI.support.touch "click" "mouseenter";

            
// init code
            
UI.$html.on(triggerevent+".dropdown.uikit""[data-uk-dropdown]", function(e) {

                var 
ele UI.$(this);

                if (!
ele.data("dropdown")) {

                    var 
dropdown UI.dropdown(eleUI.Utils.options(ele.attr("data-uk-dropdown")));

                    if (
triggerevent=="click" || (triggerevent=="mouseenter" && dropdown.options.mode=="hover")) {
                        
dropdown.element.trigger(triggerevent);
                    }

                    if (
dropdown.element.find(dropdown.options.dropdownSelector).length) {
                        
e.preventDefault();
                    }
                }
            });
        },

        
init: function() {

            var 
$this this;

            
this.dropdown     this.find(this.options.dropdownSelector);
            
this.offsetParent this.dropdown.parents().filter(function() {
                return 
UI.$.inArray(UI.$(this).css('position'), ['relative''fixed''absolute']) !== -1;
            }).
slice(0,1);

            
this.centered  this.dropdown.hasClass('uk-dropdown-center');
            
this.justified this.options.justify UI.$(this.options.justify) : false;

            
this.boundary  UI.$(this.options.boundary);

            if (!
this.boundary.length) {
                
this.boundary UI.$win;
            }

            
// legacy DEPRECATED!
            
if (this.dropdown.hasClass('uk-dropdown-up')) {
                
this.options.pos 'top-left';
            }
            if (
this.dropdown.hasClass('uk-dropdown-flip')) {
                
this.options.pos this.options.pos.replace('left','right');
            }
            if (
this.dropdown.hasClass('uk-dropdown-center')) {
                
this.options.pos this.options.pos.replace(/(left|right)/,'center');
            }
            
//-- end legacy

            // Init ARIA
            
this.element.attr('aria-haspopup''true');
            
this.element.attr('aria-expanded'this.element.hasClass("uk-open"));

            if (
this.options.mode == "click" || UI.support.touch) {

                
this.on("click.uikit.dropdown", function(e) {

                    var 
$target UI.$(e.target);

                    if (!
$target.parents($this.options.dropdownSelector).length) {

                        if (
$target.is("a[href='#']") || $target.parent().is("a[href='#']") || ($this.dropdown.length && !$this.dropdown.is(":visible")) ){
                            
e.preventDefault();
                        }

                        
$target.blur();
                    }

                    if (!
$this.element.hasClass('uk-open')) {

                        
$this.show();

                    } else {

                        if (!
$this.dropdown.find(e.target).length || $target.is(".uk-dropdown-close") || $target.parents(".uk-dropdown-close").length) {
                            
$this.hide();
                        }
                    }
                });

            } else {

                
this.on("mouseenter", function(e) {

                    
$this.trigger('pointerenter.uk.dropdown', [$this]);

                    if (
$this.remainIdle) {
                        
clearTimeout($this.remainIdle);
                    }

                    if (
hoverIdle) {
                        
clearTimeout(hoverIdle);
                    }

                    if (
active && active == $this) {
                        return;
                    }

                    
// pseudo manuAim
                    
if (active && active != $this) {

                        
hoverIdle setTimeout(function() {
                            
hoverIdle setTimeout($this.show.bind($this), $this.options.delay);
                        }, 
$this.options.hoverDelayIdle);

                    } else {

                        
hoverIdle setTimeout($this.show.bind($this), $this.options.delay);
                    }

                }).
on("mouseleave", function() {

                    if (
hoverIdle) {
                        
clearTimeout(hoverIdle);
                    }

                    
$this.remainIdle setTimeout(function() {
                        if (
active && active == $this$this.hide();
                    }, 
$this.options.remaintime);

                    
$this.trigger('pointerleave.uk.dropdown', [$this]);

                }).
on("click", function(e){

                    var 
$target UI.$(e.target);

                    if (
$this.remainIdle) {
                        
clearTimeout($this.remainIdle);
                    }

                    if (
active && active == $this) {
                        if (!
$this.dropdown.find(e.target).length || $target.is(".uk-dropdown-close") || $target.parents(".uk-dropdown-close").length) {
                            
$this.hide();
                        }
                        return;
                    }

                    if (
$target.is("a[href='#']") || $target.parent().is("a[href='#']")){
                        
e.preventDefault();
                    }

                    
$this.show();
                });
            }
        },

        
show: function(){

            
UI.$html.off("click.outer.dropdown");

            if (
active && active != this) {
                
active.hide(true);
            }

            if (
hoverIdle) {
                
clearTimeout(hoverIdle);
            }

            
this.trigger('beforeshow.uk.dropdown', [this]);

            
this.checkDimensions();
            
this.element.addClass('uk-open');

            
// Update ARIA
            
this.element.attr('aria-expanded''true');

            
this.trigger('show.uk.dropdown', [this]);

            
UI.Utils.checkDisplay(this.dropdowntrue);
            
active this;

            
this.registerOuterClick();
        },

        
hide: function(force) {

            
this.trigger('beforehide.uk.dropdown', [thisforce]);

            
this.element.removeClass('uk-open');

            if (
this.remainIdle) {
                
clearTimeout(this.remainIdle);
            }

            
this.remainIdle false;

            
// Update ARIA
            
this.element.attr('aria-expanded''false');

            
this.trigger('hide.uk.dropdown', [thisforce]);

            if (
active == thisactive false;
        },

        
registerOuterClick: function(){

            var 
$this this;

            
UI.$html.off("click.outer.dropdown");

            
setTimeout(function() {

                
UI.$html.on("click.outer.dropdown", function(e) {

                    if (
hoverIdle) {
                        
clearTimeout(hoverIdle);
                    }

                    var 
$target UI.$(e.target);

                    if (
active == $this && !$this.element.find(e.target).length) {
                        
$this.hide(true);
                        
UI.$html.off("click.outer.dropdown");
                    }
                });
            }, 
10);
        },

        
checkDimensions: function() {

            if (!
this.dropdown.length) return;

            
// reset
            
this.dropdown.removeClass('uk-dropdown-top uk-dropdown-bottom uk-dropdown-left uk-dropdown-right uk-dropdown-stack').css({
                
'top-left':'',
                
'left':'',
                
'margin-left' :'',
                
'margin-right':''
            
});

            if (
this.justified && this.justified.length) {
                
this.dropdown.css("min-width""");
            }

            var 
$this          this,
                
pos            UI.$.extend({}, this.offsetParent.offset(), {widththis.offsetParent[0].offsetWidthheightthis.offsetParent[0].offsetHeight}),
                
posoffset      this.options.offset,
                
dropdown       this.dropdown,
                
offset         dropdown.show().offset() || {left0top0},
                
width          dropdown.outerWidth(),
                
height         dropdown.outerHeight(),
                
boundarywidth  this.boundary.width(),
                
boundaryoffset this.boundary[0] !== window && this.boundary.offset() ? this.boundary.offset(): {top:0left:0},
                
dpos           this.options.pos;

            var 
variants =  {
                    
"bottom-left"   : {toppos.height posoffsetleft0},
                    
"bottom-right"  : {toppos.height posoffsetleftpos.width width},
                    
"bottom-center" : {toppos.height posoffsetleftpos.width width 2},
                    
"top-left"      : {topheight posoffsetleft0},
                    
"top-right"     : {topheight posoffsetleftpos.width width},
                    
"top-center"    : {topheight posoffsetleftpos.width width 2},
                    
"left-top"      : {top0leftwidth posoffset},
                    
"left-bottom"   : {toppos.height heightleftwidth posoffset},
                    
"left-center"   : {toppos.height height 2leftwidth posoffset},
                    
"right-top"     : {top0leftpos.width posoffset},
                    
"right-bottom"  : {toppos.height heightleftpos.width posoffset},
                    
"right-center"  : {toppos.height height 2leftpos.width posoffset}
                },
                
css = {},
                
pp;

            
pp dpos.split('-');
            
css variants[dpos] ? variants[dpos] : variants['bottom-left'];

            
// justify dropdown
            
if (this.justified && this.justified.length) {
                
justify(dropdown.css({left:0}), this.justifiedboundarywidth);
            } else {

                if (
this.options.preventflip !== true) {

                    var 
fdpos;

                    switch(
this.checkBoundary(pos.left css.leftpos.top css.topwidthheightboundarywidth)) {
                        case 
"x":
                            if(
this.options.preventflip !=='x'fdpos flips['x'][dpos] || 'right-top';
                            break;
                        case 
"y":
                            if(
this.options.preventflip !=='y'fdpos flips['y'][dpos] || 'top-left';
                            break;
                        case 
"xy":
                            if(!
this.options.preventflipfdpos flips['xy'][dpos] || 'right-bottom';
                            break;
                    }

                    if (
fdpos) {

                        
pp  fdpos.split('-');
                        
css variants[fdpos] ? variants[fdpos] : variants['bottom-left'];

                        
// check flipped
                        
if (this.checkBoundary(pos.left css.leftpos.top css.topwidthheightboundarywidth)) {
                            
pp  dpos.split('-');
                            
css variants[dpos] ? variants[dpos] : variants['bottom-left'];
                        }
                    }
                }
            }

            if (
width boundarywidth) {
                
dropdown.addClass("uk-dropdown-stack");
                
this.trigger('stack.uk.dropdown', [this]);
            }

            
dropdown.css(css).css("display""").addClass('uk-dropdown-'+pp[0]);
        },

        
checkBoundary: function(lefttopwidthheightboundarywidth) {

            var 
axis "";

            if (
left || ((left UI.$win.scrollLeft())+width) > boundarywidth) {
               
axis += "x";
            }

            if ((
top UI.$win.scrollTop()) < || ((top UI.$win.scrollTop())+height) > window.innerHeight) {
               
axis += "y";
            }

            return 
axis;
        }
    });


    
UI.component('dropdownOverlay', {

        
defaults: {
           
'justify' false,
           
'cls'     '',
           
'duration'200
        
},

        
boot: function() {

            
// init code
            
UI.ready(function(context) {

                
UI.$("[data-uk-dropdown-overlay]"context).each(function() {
                    var 
ele UI.$(this);

                    if (!
ele.data("dropdownOverlay")) {
                        
UI.dropdownOverlay(eleUI.Utils.options(ele.attr("data-uk-dropdown-overlay")));
                    }
                });
            });
        },

        
init: function() {

            var 
$this this;

            
this.justified this.options.justify UI.$(this.options.justify) : false;
            
this.overlay   this.element.find('uk-dropdown-overlay');

            if (!
this.overlay.length) {
                
this.overlay UI.$('<div class="uk-dropdown-overlay"></div>').appendTo(this.element);
            }

            
this.overlay.addClass(this.options.cls);

            
this.on({

                
'beforeshow.uk.dropdown': function(edropdown) {
                    
$this.dropdown dropdown;

                    if (
$this.justified && $this.justified.length) {
                        
justify($this.overlay.css({'display':'block''margin-left':'','margin-right':''}), $this.justified$this.justified.outerWidth());
                    }
                },

                
'show.uk.dropdown': function(edropdown) {

                    var 
$this.dropdown.dropdown.outerHeight(true);

                    
$this.dropdown.element.removeClass('uk-open');

                    
$this.overlay.stop().css('display''block').animate({heighth}, $this.options.duration, function() {

                       
$this.dropdown.dropdown.css('visibility''');
                       
$this.dropdown.element.addClass('uk-open');

                       
UI.Utils.checkDisplay($this.dropdown.dropdowntrue);
                    });

                    
$this.pointerleave false;
                },

                
'hide.uk.dropdown': function() {
                    
$this.overlay.stop().animate({height0}, $this.options.duration);
                },

                
'pointerenter.uk.dropdown': function(edropdown) {
                    
clearTimeout($this.remainIdle);
                },

                
'pointerleave.uk.dropdown': function(edropdown) {
                    
$this.pointerleave true;
                }
            });


            
this.overlay.on({

                
'mouseenter': function() {
                    if (
$this.remainIdle) {
                        
clearTimeout($this.dropdown.remainIdle);
                        
clearTimeout($this.remainIdle);
                    }
                },

                
'mouseleave': function(){

                    if (
$this.pointerleave && active) {

                        
$this.remainIdle setTimeout(function() {
                           if(
activeactive.hide();
                        }, 
active.options.remaintime);
                    }
                }
            })
        }

    });


    function 
justify(elejustifyToboundarywidthoffset) {

        
ele           UI.$(ele);
        
justifyTo     UI.$(justifyTo);
        
boundarywidth boundarywidth || window.innerWidth;
        
offset        offset || ele.offset();

        if (
justifyTo.length) {

            var 
jwidth justifyTo.outerWidth();

            
ele.css("min-width"jwidth);

            if (
UI.langdirection == 'right') {

                var 
right1   boundarywidth - (justifyTo.offset().left jwidth),
                    
right2   boundarywidth - (ele.offset().left ele.outerWidth());

                
ele.css("margin-right"right1 right2);

            } else {
                
ele.css("margin-left"justifyTo.offset().left offset.left);
            }
        }
    }

})(
UIkit);
?>
Онлайн: 0
Реклама