diff options
Diffstat (limited to 'js/core/offcanvas.js')
| -rwxr-xr-x | js/core/offcanvas.js | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/js/core/offcanvas.js b/js/core/offcanvas.js deleted file mode 100755 index 9b2c289..0000000 --- a/js/core/offcanvas.js +++ /dev/null | |||
| @@ -1,180 +0,0 @@ | |||
| 1 | /*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ | ||
| 2 | (function(UI) { | ||
| 3 | |||
| 4 | "use strict"; | ||
| 5 | |||
| 6 | var scrollpos = {x: window.scrollX, y: window.scrollY}, | ||
| 7 | $win = UI.$win, | ||
| 8 | $doc = UI.$doc, | ||
| 9 | $html = UI.$html, | ||
| 10 | Offcanvas = { | ||
| 11 | |||
| 12 | show: function(element) { | ||
| 13 | |||
| 14 | element = UI.$(element); | ||
| 15 | |||
| 16 | if (!element.length) return; | ||
| 17 | |||
| 18 | var $body = UI.$('body'), | ||
| 19 | bar = element.find(".uk-offcanvas-bar:first"), | ||
| 20 | rtl = (UI.langdirection == "right"), | ||
| 21 | flip = bar.hasClass("uk-offcanvas-bar-flip") ? -1:1, | ||
| 22 | dir = flip * (rtl ? -1 : 1), | ||
| 23 | |||
| 24 | scrollbarwidth = window.innerWidth - $body.width(); | ||
| 25 | |||
| 26 | scrollpos = {x: window.pageXOffset, y: window.pageYOffset}; | ||
| 27 | |||
| 28 | element.addClass("uk-active"); | ||
| 29 | |||
| 30 | $body.css({"width": window.innerWidth - scrollbarwidth, "height": window.innerHeight}).addClass("uk-offcanvas-page"); | ||
| 31 | $body.css((rtl ? "margin-right" : "margin-left"), (rtl ? -1 : 1) * (bar.outerWidth() * dir)).width(); // .width() - force redraw | ||
| 32 | |||
| 33 | $html.css('margin-top', scrollpos.y * -1); | ||
| 34 | |||
| 35 | bar.addClass("uk-offcanvas-bar-show"); | ||
| 36 | |||
| 37 | this._initElement(element); | ||
| 38 | |||
| 39 | bar.trigger('show.uk.offcanvas', [element, bar]); | ||
| 40 | |||
| 41 | // Update ARIA | ||
| 42 | element.attr('aria-hidden', 'false'); | ||
| 43 | }, | ||
| 44 | |||
| 45 | hide: function(force) { | ||
| 46 | |||
| 47 | var $body = UI.$('body'), | ||
| 48 | panel = UI.$(".uk-offcanvas.uk-active"), | ||
| 49 | rtl = (UI.langdirection == "right"), | ||
| 50 | bar = panel.find(".uk-offcanvas-bar:first"), | ||
| 51 | finalize = function() { | ||
| 52 | $body.removeClass("uk-offcanvas-page").css({"width": "", "height": "", "margin-left": "", "margin-right": ""}); | ||
| 53 | panel.removeClass("uk-active"); | ||
| 54 | |||
| 55 | bar.removeClass("uk-offcanvas-bar-show"); | ||
| 56 | $html.css('margin-top', ''); | ||
| 57 | window.scrollTo(scrollpos.x, scrollpos.y); | ||
| 58 | bar.trigger('hide.uk.offcanvas', [panel, bar]); | ||
| 59 | |||
| 60 | // Update ARIA | ||
| 61 | panel.attr('aria-hidden', 'true'); | ||
| 62 | }; | ||
| 63 | |||
| 64 | if (!panel.length) return; | ||
| 65 | |||
| 66 | if (UI.support.transition && !force) { | ||
| 67 | |||
| 68 | $body.one(UI.support.transition.end, function() { | ||
| 69 | finalize(); | ||
| 70 | }).css((rtl ? "margin-right" : "margin-left"), ""); | ||
| 71 | |||
| 72 | setTimeout(function(){ | ||
| 73 | bar.removeClass("uk-offcanvas-bar-show"); | ||
| 74 | }, 0); | ||
| 75 | |||
| 76 | } else { | ||
| 77 | finalize(); | ||
| 78 | } | ||
| 79 | }, | ||
| 80 | |||
| 81 | _initElement: function(element) { | ||
| 82 | |||
| 83 | if (element.data("OffcanvasInit")) return; | ||
| 84 | |||
| 85 | element.on("click.uk.offcanvas swipeRight.uk.offcanvas swipeLeft.uk.offcanvas", function(e) { | ||
| 86 | |||
| 87 | var target = UI.$(e.target); | ||
| 88 | |||
| 89 | if (!e.type.match(/swipe/)) { | ||
| 90 | |||
| 91 | if (!target.hasClass("uk-offcanvas-close")) { | ||
| 92 | if (target.hasClass("uk-offcanvas-bar")) return; | ||
| 93 | if (target.parents(".uk-offcanvas-bar:first").length) return; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | e.stopImmediatePropagation(); | ||
| 98 | Offcanvas.hide(); | ||
| 99 | }); | ||
| 100 | |||
| 101 | element.on("click", "a[href*='#']", function(e){ | ||
| 102 | |||
| 103 | var link = UI.$(this), | ||
| 104 | href = link.attr("href"); | ||
| 105 | |||
| 106 | if (href == "#") { | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | |||
| 110 | UI.$doc.one('hide.uk.offcanvas', function() { | ||
| 111 | |||
| 112 | var target; | ||
| 113 | |||
| 114 | try { | ||
| 115 | target = UI.$(link[0].hash); | ||
| 116 | } catch (e){ | ||
| 117 | target = ''; | ||
| 118 | } | ||
| 119 | |||
| 120 | if (!target.length) { | ||
| 121 | target = UI.$('[name="'+link[0].hash.replace('#','')+'"]'); | ||
| 122 | } | ||
| 123 | |||
| 124 | if (target.length && UI.Utils.scrollToElement) { | ||
| 125 | UI.Utils.scrollToElement(target, UI.Utils.options(link.attr('data-uk-smooth-scroll') || '{}')); | ||
| 126 | } else { | ||
| 127 | window.location.href = href; | ||
| 128 | } | ||
| 129 | }); | ||
| 130 | |||
| 131 | Offcanvas.hide(); | ||
| 132 | }); | ||
| 133 | |||
| 134 | element.data("OffcanvasInit", true); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | |||
| 138 | UI.component('offcanvasTrigger', { | ||
| 139 | |||
| 140 | boot: function() { | ||
| 141 | |||
| 142 | // init code | ||
| 143 | $html.on("click.offcanvas.uikit", "[data-uk-offcanvas]", function(e) { | ||
| 144 | |||
| 145 | e.preventDefault(); | ||
| 146 | |||
| 147 | var ele = UI.$(this); | ||
| 148 | |||
| 149 | if (!ele.data("offcanvasTrigger")) { | ||
| 150 | var obj = UI.offcanvasTrigger(ele, UI.Utils.options(ele.attr("data-uk-offcanvas"))); | ||
| 151 | ele.trigger("click"); | ||
| 152 | } | ||
| 153 | }); | ||
| 154 | |||
| 155 | $html.on('keydown.uk.offcanvas', function(e) { | ||
| 156 | |||
| 157 | if (e.keyCode === 27) { // ESC | ||
| 158 | Offcanvas.hide(); | ||
| 159 | } | ||
| 160 | }); | ||
| 161 | }, | ||
| 162 | |||
| 163 | init: function() { | ||
| 164 | |||
| 165 | var $this = this; | ||
| 166 | |||
| 167 | this.options = UI.$.extend({ | ||
| 168 | "target": $this.element.is("a") ? $this.element.attr("href") : false | ||
| 169 | }, this.options); | ||
| 170 | |||
| 171 | this.on("click", function(e) { | ||
| 172 | e.preventDefault(); | ||
| 173 | Offcanvas.show($this.options.target); | ||
| 174 | }); | ||
| 175 | } | ||
| 176 | }); | ||
| 177 | |||
| 178 | UI.offcanvas = Offcanvas; | ||
| 179 | |||
| 180 | })(UIkit); | ||
