1
|
/*! UIkit 2.27.5 | 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, options) {
|
13
|
|
14
|
element = UI.$(element);
|
15
|
|
16
|
if (!element.length) return;
|
17
|
|
18
|
options = UI.$.extend({mode: 'push'}, options);
|
19
|
|
20
|
var $body = UI.$('body'),
|
21
|
bar = element.find('.uk-offcanvas-bar:first'),
|
22
|
rtl = (UI.langdirection == 'right'),
|
23
|
flip = bar.hasClass('uk-offcanvas-bar-flip') ? -1:1,
|
24
|
dir = flip * (rtl ? -1 : 1),
|
25
|
|
26
|
scrollbarwidth = window.innerWidth - $body.width();
|
27
|
|
28
|
scrollpos = {x: window.pageXOffset, y: window.pageYOffset};
|
29
|
|
30
|
bar.attr('mode', options.mode);
|
31
|
element.addClass('uk-active');
|
32
|
|
33
|
$body.css({width: window.innerWidth - scrollbarwidth, height: window.innerHeight}).addClass('uk-offcanvas-page');
|
34
|
|
35
|
if (options.mode == 'push' || options.mode == 'reveal') {
|
36
|
$body.css((rtl ? 'margin-right' : 'margin-left'), (rtl ? -1 : 1) * (bar.outerWidth() * dir));
|
37
|
}
|
38
|
|
39
|
if (options.mode == 'reveal') {
|
40
|
bar.css('clip', 'rect(0, '+bar.outerWidth()+'px, 100vh, 0)');
|
41
|
}
|
42
|
|
43
|
$html.css('margin-top', scrollpos.y * -1).width(); // .width() - force redraw
|
44
|
|
45
|
|
46
|
bar.addClass('uk-offcanvas-bar-show');
|
47
|
|
48
|
this._initElement(element);
|
49
|
|
50
|
bar.trigger('show.uk.offcanvas', [element, bar]);
|
51
|
|
52
|
// Update ARIA
|
53
|
element.attr('aria-hidden', 'false');
|
54
|
},
|
55
|
|
56
|
hide: function(force) {
|
57
|
|
58
|
var $body = UI.$('body'),
|
59
|
panel = UI.$('.uk-offcanvas.uk-active'),
|
60
|
rtl = (UI.langdirection == 'right'),
|
61
|
bar = panel.find('.uk-offcanvas-bar:first'),
|
62
|
finalize = function() {
|
63
|
$body.removeClass('uk-offcanvas-page').css({width: '', height: '', marginLeft: '', marginRight: ''});
|
64
|
panel.removeClass('uk-active');
|
65
|
|
66
|
bar.removeClass('uk-offcanvas-bar-show');
|
67
|
$html.css('margin-top', '');
|
68
|
window.scrollTo(scrollpos.x, scrollpos.y);
|
69
|
bar.trigger('hide.uk.offcanvas', [panel, bar]);
|
70
|
|
71
|
// Update ARIA
|
72
|
panel.attr('aria-hidden', 'true');
|
73
|
};
|
74
|
|
75
|
if (!panel.length) return;
|
76
|
if (bar.attr('mode') == 'none') force = true;
|
77
|
|
78
|
if (UI.support.transition && !force) {
|
79
|
|
80
|
$body.one(UI.support.transition.end, function() {
|
81
|
finalize();
|
82
|
}).css((rtl ? 'margin-right' : 'margin-left'), '');
|
83
|
|
84
|
if (bar.attr('mode') == 'reveal') {
|
85
|
bar.css('clip', '');
|
86
|
}
|
87
|
|
88
|
setTimeout(function(){
|
89
|
bar.removeClass('uk-offcanvas-bar-show');
|
90
|
}, 0);
|
91
|
|
92
|
} else {
|
93
|
finalize();
|
94
|
}
|
95
|
},
|
96
|
|
97
|
_initElement: function(element) {
|
98
|
|
99
|
if (element.data('OffcanvasInit')) return;
|
100
|
|
101
|
element.on('click.uk.offcanvas swipeRight.uk.offcanvas swipeLeft.uk.offcanvas', function(e) {
|
102
|
|
103
|
var target = UI.$(e.target);
|
104
|
|
105
|
if (e.type.match(/swipe/)) {
|
106
|
if (target.parents('.uk-offcanvas-bar:first').length) return;
|
107
|
} else {
|
108
|
|
109
|
if (!target.hasClass('uk-offcanvas-close')) {
|
110
|
if (target.hasClass('uk-offcanvas-bar')) return;
|
111
|
if (target.parents('.uk-offcanvas-bar:first').length) return;
|
112
|
}
|
113
|
}
|
114
|
|
115
|
e.stopImmediatePropagation();
|
116
|
Offcanvas.hide();
|
117
|
});
|
118
|
|
119
|
element.on('click', 'a[href*="#"]', function(e){
|
120
|
|
121
|
var link = UI.$(this),
|
122
|
href = link.attr('href');
|
123
|
|
124
|
if (href == '#') {
|
125
|
return;
|
126
|
}
|
127
|
|
128
|
UI.$doc.one('hide.uk.offcanvas', function() {
|
129
|
|
130
|
var target;
|
131
|
|
132
|
try {
|
133
|
target = UI.$(link[0].hash);
|
134
|
} catch (e){
|
135
|
target = '';
|
136
|
}
|
137
|
|
138
|
if (!target.length) {
|
139
|
target = UI.$('[name="'+link[0].hash.replace('#','')+'"]');
|
140
|
}
|
141
|
|
142
|
if (target.length && UI.Utils.scrollToElement) {
|
143
|
UI.Utils.scrollToElement(target, UI.Utils.options(link.attr('data-uk-smooth-scroll') || '{}'));
|
144
|
} else {
|
145
|
window.location.href = href;
|
146
|
}
|
147
|
});
|
148
|
|
149
|
Offcanvas.hide();
|
150
|
});
|
151
|
|
152
|
element.data('OffcanvasInit', true);
|
153
|
}
|
154
|
};
|
155
|
|
156
|
UI.component('offcanvasTrigger', {
|
157
|
|
158
|
boot: function() {
|
159
|
|
160
|
// init code
|
161
|
$html.on('click.offcanvas.uikit', '[data-uk-offcanvas]', function(e) {
|
162
|
|
163
|
e.preventDefault();
|
164
|
|
165
|
var ele = UI.$(this);
|
166
|
|
167
|
if (!ele.data('offcanvasTrigger')) {
|
168
|
var obj = UI.offcanvasTrigger(ele, UI.Utils.options(ele.attr('data-uk-offcanvas')));
|
169
|
ele.trigger("click");
|
170
|
}
|
171
|
});
|
172
|
|
173
|
$html.on('keydown.uk.offcanvas', function(e) {
|
174
|
|
175
|
if (e.keyCode === 27) { // ESC
|
176
|
Offcanvas.hide();
|
177
|
}
|
178
|
});
|
179
|
},
|
180
|
|
181
|
init: function() {
|
182
|
|
183
|
var $this = this;
|
184
|
|
185
|
this.options = UI.$.extend({
|
186
|
target: $this.element.is('a') ? $this.element.attr('href') : false,
|
187
|
mode: 'push'
|
188
|
}, this.options);
|
189
|
|
190
|
this.on('click', function(e) {
|
191
|
e.preventDefault();
|
192
|
Offcanvas.show($this.options.target, $this.options);
|
193
|
});
|
194
|
}
|
195
|
});
|
196
|
|
197
|
UI.offcanvas = Offcanvas;
|
198
|
|
199
|
})(UIkit2);
|