diff options
| author | Pascal Szewczyk <ps@elektrowecker.de> | 2016-07-18 23:23:54 +0200 |
|---|---|---|
| committer | Pascal Szewczyk <ps@elektrowecker.de> | 2016-07-18 23:23:54 +0200 |
| commit | c94fb32c7a3c28b18a27460aa2447eeec1fac1de (patch) | |
| tree | e3bb35d57f90256698135c722eadeb784b47992c /js/core/nav.js | |
| parent | 89685742de42cb8e54ebdbaf7a207cfe16fa62b8 (diff) | |
uikit added
Diffstat (limited to 'js/core/nav.js')
| -rwxr-xr-x | js/core/nav.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/js/core/nav.js b/js/core/nav.js new file mode 100755 index 0000000..a6157ab --- /dev/null +++ b/js/core/nav.js | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ | ||
| 2 | (function(UI) { | ||
| 3 | |||
| 4 | "use strict"; | ||
| 5 | |||
| 6 | UI.component('nav', { | ||
| 7 | |||
| 8 | defaults: { | ||
| 9 | "toggle": ">li.uk-parent > a[href='#']", | ||
| 10 | "lists": ">li.uk-parent > ul", | ||
| 11 | "multiple": false | ||
| 12 | }, | ||
| 13 | |||
| 14 | boot: function() { | ||
| 15 | |||
| 16 | // init code | ||
| 17 | UI.ready(function(context) { | ||
| 18 | |||
| 19 | UI.$("[data-uk-nav]", context).each(function() { | ||
| 20 | var nav = UI.$(this); | ||
| 21 | |||
| 22 | if (!nav.data("nav")) { | ||
| 23 | var obj = UI.nav(nav, UI.Utils.options(nav.attr("data-uk-nav"))); | ||
| 24 | } | ||
| 25 | }); | ||
| 26 | }); | ||
| 27 | }, | ||
| 28 | |||
| 29 | init: function() { | ||
| 30 | |||
| 31 | var $this = this; | ||
| 32 | |||
| 33 | this.on("click.uk.nav", this.options.toggle, function(e) { | ||
| 34 | e.preventDefault(); | ||
| 35 | var ele = UI.$(this); | ||
| 36 | $this.open(ele.parent()[0] == $this.element[0] ? ele : ele.parent("li")); | ||
| 37 | }); | ||
| 38 | |||
| 39 | this.find(this.options.lists).each(function() { | ||
| 40 | var $ele = UI.$(this), | ||
| 41 | parent = $ele.parent(), | ||
| 42 | active = parent.hasClass("uk-active"); | ||
| 43 | |||
| 44 | $ele.wrap('<div style="overflow:hidden;height:0;position:relative;"></div>'); | ||
| 45 | parent.data("list-container", $ele.parent()[active ? 'removeClass':'addClass']('uk-hidden')); | ||
| 46 | |||
| 47 | // Init ARIA | ||
| 48 | parent.attr('aria-expanded', parent.hasClass("uk-open")); | ||
| 49 | |||
| 50 | if (active) $this.open(parent, true); | ||
| 51 | }); | ||
| 52 | |||
| 53 | }, | ||
| 54 | |||
| 55 | open: function(li, noanimation) { | ||
| 56 | |||
| 57 | var $this = this, element = this.element, $li = UI.$(li), $container = $li.data('list-container'); | ||
| 58 | |||
| 59 | if (!this.options.multiple) { | ||
| 60 | |||
| 61 | element.children('.uk-open').not(li).each(function() { | ||
| 62 | |||
| 63 | var ele = UI.$(this); | ||
| 64 | |||
| 65 | if (ele.data('list-container')) { | ||
| 66 | ele.data('list-container').stop().animate({height: 0}, function() { | ||
| 67 | UI.$(this).parent().removeClass('uk-open').end().addClass('uk-hidden'); | ||
| 68 | }); | ||
| 69 | } | ||
| 70 | }); | ||
| 71 | } | ||
| 72 | |||
| 73 | $li.toggleClass('uk-open'); | ||
| 74 | |||
| 75 | // Update ARIA | ||
| 76 | $li.attr('aria-expanded', $li.hasClass('uk-open')); | ||
| 77 | |||
| 78 | if ($container) { | ||
| 79 | |||
| 80 | if ($li.hasClass('uk-open')) { | ||
| 81 | $container.removeClass('uk-hidden'); | ||
| 82 | } | ||
| 83 | |||
| 84 | if (noanimation) { | ||
| 85 | |||
| 86 | $container.stop().height($li.hasClass('uk-open') ? 'auto' : 0); | ||
| 87 | |||
| 88 | if (!$li.hasClass('uk-open')) { | ||
| 89 | $container.addClass('uk-hidden'); | ||
| 90 | } | ||
| 91 | |||
| 92 | this.trigger('display.uk.check'); | ||
| 93 | |||
| 94 | } else { | ||
| 95 | |||
| 96 | $container.stop().animate({ | ||
| 97 | height: ($li.hasClass('uk-open') ? getHeight($container.find('ul:first')) : 0) | ||
| 98 | }, function() { | ||
| 99 | |||
| 100 | if (!$li.hasClass('uk-open')) { | ||
| 101 | $container.addClass('uk-hidden'); | ||
| 102 | } else { | ||
| 103 | $container.css('height', ''); | ||
| 104 | } | ||
| 105 | |||
| 106 | $this.trigger('display.uk.check'); | ||
| 107 | }); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| 111 | }); | ||
| 112 | |||
| 113 | |||
| 114 | // helper | ||
| 115 | |||
| 116 | function getHeight(ele) { | ||
| 117 | var $ele = UI.$(ele), height = "auto"; | ||
| 118 | |||
| 119 | if ($ele.is(":visible")) { | ||
| 120 | height = $ele.outerHeight(); | ||
| 121 | } else { | ||
| 122 | var tmp = { | ||
| 123 | position: $ele.css("position"), | ||
| 124 | visibility: $ele.css("visibility"), | ||
| 125 | display: $ele.css("display") | ||
| 126 | }; | ||
| 127 | |||
| 128 | height = $ele.css({position: 'absolute', visibility: 'hidden', display: 'block'}).outerHeight(); | ||
| 129 | |||
| 130 | $ele.css(tmp); // reset element | ||
| 131 | } | ||
| 132 | |||
| 133 | return height; | ||
| 134 | } | ||
| 135 | |||
| 136 | })(UIkit); | ||
