updated Uikit v2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*! UIkit 2.25.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
||||
/*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
||||
(function(UI) {
|
||||
|
||||
"use strict";
|
||||
@@ -9,30 +9,41 @@
|
||||
$html = UI.$html,
|
||||
Offcanvas = {
|
||||
|
||||
show: function(element) {
|
||||
show: function(element, options) {
|
||||
|
||||
element = UI.$(element);
|
||||
|
||||
if (!element.length) return;
|
||||
|
||||
options = UI.$.extend({mode: 'push'}, options);
|
||||
|
||||
var $body = UI.$('body'),
|
||||
bar = element.find(".uk-offcanvas-bar:first"),
|
||||
rtl = (UI.langdirection == "right"),
|
||||
flip = bar.hasClass("uk-offcanvas-bar-flip") ? -1:1,
|
||||
bar = element.find('.uk-offcanvas-bar:first'),
|
||||
rtl = (UI.langdirection == 'right'),
|
||||
flip = bar.hasClass('uk-offcanvas-bar-flip') ? -1:1,
|
||||
dir = flip * (rtl ? -1 : 1),
|
||||
|
||||
scrollbarwidth = window.innerWidth - $body.width();
|
||||
|
||||
scrollpos = {x: window.pageXOffset, y: window.pageYOffset};
|
||||
|
||||
element.addClass("uk-active");
|
||||
bar.attr('mode', options.mode);
|
||||
element.addClass('uk-active');
|
||||
|
||||
$body.css({"width": window.innerWidth - scrollbarwidth, "height": window.innerHeight}).addClass("uk-offcanvas-page");
|
||||
$body.css((rtl ? "margin-right" : "margin-left"), (rtl ? -1 : 1) * (bar.outerWidth() * dir)).width(); // .width() - force redraw
|
||||
$body.css({width: window.innerWidth - scrollbarwidth, height: window.innerHeight}).addClass('uk-offcanvas-page');
|
||||
|
||||
$html.css('margin-top', scrollpos.y * -1);
|
||||
if (options.mode == 'push' || options.mode == 'reveal') {
|
||||
$body.css((rtl ? 'margin-right' : 'margin-left'), (rtl ? -1 : 1) * (bar.outerWidth() * dir));
|
||||
}
|
||||
|
||||
bar.addClass("uk-offcanvas-bar-show");
|
||||
if (options.mode == 'reveal') {
|
||||
bar.css('clip', 'rect(0, '+bar.outerWidth()+'px, 100vh, 0)');
|
||||
}
|
||||
|
||||
$html.css('margin-top', scrollpos.y * -1).width(); // .width() - force redraw
|
||||
|
||||
|
||||
bar.addClass('uk-offcanvas-bar-show');
|
||||
|
||||
this._initElement(element);
|
||||
|
||||
@@ -45,14 +56,14 @@
|
||||
hide: function(force) {
|
||||
|
||||
var $body = UI.$('body'),
|
||||
panel = UI.$(".uk-offcanvas.uk-active"),
|
||||
rtl = (UI.langdirection == "right"),
|
||||
bar = panel.find(".uk-offcanvas-bar:first"),
|
||||
panel = UI.$('.uk-offcanvas.uk-active'),
|
||||
rtl = (UI.langdirection == 'right'),
|
||||
bar = panel.find('.uk-offcanvas-bar:first'),
|
||||
finalize = function() {
|
||||
$body.removeClass("uk-offcanvas-page").css({"width": "", "height": "", "margin-left": "", "margin-right": ""});
|
||||
panel.removeClass("uk-active");
|
||||
$body.removeClass('uk-offcanvas-page').css({width: '', height: '', marginLeft: '', marginRight: ''});
|
||||
panel.removeClass('uk-active');
|
||||
|
||||
bar.removeClass("uk-offcanvas-bar-show");
|
||||
bar.removeClass('uk-offcanvas-bar-show');
|
||||
$html.css('margin-top', '');
|
||||
window.scrollTo(scrollpos.x, scrollpos.y);
|
||||
bar.trigger('hide.uk.offcanvas', [panel, bar]);
|
||||
@@ -62,15 +73,20 @@
|
||||
};
|
||||
|
||||
if (!panel.length) return;
|
||||
if (bar.attr('mode') == 'none') force = true;
|
||||
|
||||
if (UI.support.transition && !force) {
|
||||
|
||||
$body.one(UI.support.transition.end, function() {
|
||||
finalize();
|
||||
}).css((rtl ? "margin-right" : "margin-left"), "");
|
||||
}).css((rtl ? 'margin-right' : 'margin-left'), '');
|
||||
|
||||
if (bar.attr('mode') == 'reveal') {
|
||||
bar.css('clip', '');
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
bar.removeClass("uk-offcanvas-bar-show");
|
||||
bar.removeClass('uk-offcanvas-bar-show');
|
||||
}, 0);
|
||||
|
||||
} else {
|
||||
@@ -80,17 +96,17 @@
|
||||
|
||||
_initElement: function(element) {
|
||||
|
||||
if (element.data("OffcanvasInit")) return;
|
||||
if (element.data('OffcanvasInit')) return;
|
||||
|
||||
element.on("click.uk.offcanvas swipeRight.uk.offcanvas swipeLeft.uk.offcanvas", function(e) {
|
||||
element.on('click.uk.offcanvas swipeRight.uk.offcanvas swipeLeft.uk.offcanvas', function(e) {
|
||||
|
||||
var target = UI.$(e.target);
|
||||
|
||||
if (!e.type.match(/swipe/)) {
|
||||
|
||||
if (!target.hasClass("uk-offcanvas-close")) {
|
||||
if (target.hasClass("uk-offcanvas-bar")) return;
|
||||
if (target.parents(".uk-offcanvas-bar:first").length) return;
|
||||
if (!target.hasClass('uk-offcanvas-close')) {
|
||||
if (target.hasClass('uk-offcanvas-bar')) return;
|
||||
if (target.parents('.uk-offcanvas-bar:first').length) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,12 +114,12 @@
|
||||
Offcanvas.hide();
|
||||
});
|
||||
|
||||
element.on("click", "a[href*='#']", function(e){
|
||||
element.on('click', 'a[href*="#"]', function(e){
|
||||
|
||||
var link = UI.$(this),
|
||||
href = link.attr("href");
|
||||
href = link.attr('href');
|
||||
|
||||
if (href == "#") {
|
||||
if (href == '#') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,7 +147,7 @@
|
||||
Offcanvas.hide();
|
||||
});
|
||||
|
||||
element.data("OffcanvasInit", true);
|
||||
element.data('OffcanvasInit', true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,14 +156,14 @@
|
||||
boot: function() {
|
||||
|
||||
// init code
|
||||
$html.on("click.offcanvas.uikit", "[data-uk-offcanvas]", function(e) {
|
||||
$html.on('click.offcanvas.uikit', '[data-uk-offcanvas]', function(e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var ele = UI.$(this);
|
||||
|
||||
if (!ele.data("offcanvasTrigger")) {
|
||||
var obj = UI.offcanvasTrigger(ele, UI.Utils.options(ele.attr("data-uk-offcanvas")));
|
||||
if (!ele.data('offcanvasTrigger')) {
|
||||
var obj = UI.offcanvasTrigger(ele, UI.Utils.options(ele.attr('data-uk-offcanvas')));
|
||||
ele.trigger("click");
|
||||
}
|
||||
});
|
||||
@@ -165,16 +181,17 @@
|
||||
var $this = this;
|
||||
|
||||
this.options = UI.$.extend({
|
||||
"target": $this.element.is("a") ? $this.element.attr("href") : false
|
||||
target: $this.element.is('a') ? $this.element.attr('href') : false,
|
||||
mode: 'push'
|
||||
}, this.options);
|
||||
|
||||
this.on("click", function(e) {
|
||||
this.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
Offcanvas.show($this.options.target);
|
||||
Offcanvas.show($this.options.target, $this.options);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
UI.offcanvas = Offcanvas;
|
||||
|
||||
})(UIkit);
|
||||
})(UIkit2);
|
||||
|
Reference in New Issue
Block a user