diff options
Diffstat (limited to 'js/core/utility.js')
-rwxr-xr-x | js/core/utility.js | 319 |
1 files changed, 0 insertions, 319 deletions
diff --git a/js/core/utility.js b/js/core/utility.js deleted file mode 100755 index 0090b8c..0000000 --- a/js/core/utility.js +++ /dev/null | |||
@@ -1,319 +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 stacks = []; | ||
7 | |||
8 | UI.component('stackMargin', { | ||
9 | |||
10 | defaults: { | ||
11 | cls: 'uk-margin-small-top', | ||
12 | rowfirst: false, | ||
13 | observe: false | ||
14 | }, | ||
15 | |||
16 | boot: function() { | ||
17 | |||
18 | // init code | ||
19 | UI.ready(function(context) { | ||
20 | |||
21 | UI.$("[data-uk-margin]", context).each(function() { | ||
22 | |||
23 | var ele = UI.$(this); | ||
24 | |||
25 | if (!ele.data("stackMargin")) { | ||
26 | UI.stackMargin(ele, UI.Utils.options(ele.attr("data-uk-margin"))); | ||
27 | } | ||
28 | }); | ||
29 | }); | ||
30 | }, | ||
31 | |||
32 | init: function() { | ||
33 | |||
34 | var $this = this; | ||
35 | |||
36 | UI.$win.on('resize orientationchange', (function() { | ||
37 | |||
38 | var fn = function() { | ||
39 | $this.process(); | ||
40 | }; | ||
41 | |||
42 | UI.$(function() { | ||
43 | fn(); | ||
44 | UI.$win.on("load", fn); | ||
45 | }); | ||
46 | |||
47 | return UI.Utils.debounce(fn, 20); | ||
48 | })()); | ||
49 | |||
50 | this.on("display.uk.check", function(e) { | ||
51 | if (this.element.is(":visible")) this.process(); | ||
52 | }.bind(this)); | ||
53 | |||
54 | if (this.options.observe) { | ||
55 | |||
56 | UI.domObserve(this.element, function(e) { | ||
57 | if ($this.element.is(":visible")) $this.process(); | ||
58 | }); | ||
59 | } | ||
60 | |||
61 | stacks.push(this); | ||
62 | }, | ||
63 | |||
64 | process: function() { | ||
65 | |||
66 | var $this = this, columns = this.element.children(); | ||
67 | |||
68 | UI.Utils.stackMargin(columns, this.options); | ||
69 | |||
70 | if (!this.options.rowfirst || !columns.length) { | ||
71 | return this; | ||
72 | } | ||
73 | |||
74 | // Mark first column elements | ||
75 | var group = {}, minleft = false; | ||
76 | |||
77 | columns.removeClass(this.options.rowfirst).each(function(offset, $ele){ | ||
78 | |||
79 | $ele = UI.$(this); | ||
80 | |||
81 | if (this.style.display != 'none') { | ||
82 | offset = $ele.offset().left; | ||
83 | ((group[offset] = group[offset] || []) && group[offset]).push(this); | ||
84 | minleft = minleft === false ? offset : Math.min(minleft, offset); | ||
85 | } | ||
86 | }); | ||
87 | |||
88 | UI.$(group[minleft]).addClass(this.options.rowfirst); | ||
89 | |||
90 | return this; | ||
91 | } | ||
92 | |||
93 | }); | ||
94 | |||
95 | |||
96 | // responsive element e.g. iframes | ||
97 | |||
98 | (function(){ | ||
99 | |||
100 | var elements = [], check = function(ele) { | ||
101 | |||
102 | if (!ele.is(':visible')) return; | ||
103 | |||
104 | var width = ele.parent().width(), | ||
105 | iwidth = ele.data('width'), | ||
106 | ratio = (width / iwidth), | ||
107 | height = Math.floor(ratio * ele.data('height')); | ||
108 | |||
109 | ele.css({'height': (width < iwidth) ? height : ele.data('height')}); | ||
110 | }; | ||
111 | |||
112 | UI.component('responsiveElement', { | ||
113 | |||
114 | defaults: {}, | ||
115 | |||
116 | boot: function() { | ||
117 | |||
118 | // init code | ||
119 | UI.ready(function(context) { | ||
120 | |||
121 | UI.$("iframe.uk-responsive-width, [data-uk-responsive]", context).each(function() { | ||
122 | |||
123 | var ele = UI.$(this), obj; | ||
124 | |||
125 | if (!ele.data("responsiveElement")) { | ||
126 | obj = UI.responsiveElement(ele, {}); | ||
127 | } | ||
128 | }); | ||
129 | }); | ||
130 | }, | ||
131 | |||
132 | init: function() { | ||
133 | |||
134 | var ele = this.element; | ||
135 | |||
136 | if (ele.attr('width') && ele.attr('height')) { | ||
137 | |||
138 | ele.data({ | ||
139 | |||
140 | 'width' : ele.attr('width'), | ||
141 | 'height': ele.attr('height') | ||
142 | |||
143 | }).on('display.uk.check', function(){ | ||
144 | check(ele); | ||
145 | }); | ||
146 | |||
147 | check(ele); | ||
148 | |||
149 | elements.push(ele); | ||
150 | } | ||
151 | } | ||
152 | }); | ||
153 | |||
154 | UI.$win.on('resize load', UI.Utils.debounce(function(){ | ||
155 | |||
156 | elements.forEach(function(ele){ | ||
157 | check(ele); | ||
158 | }); | ||
159 | |||
160 | }, 15)); | ||
161 | |||
162 | })(); | ||
163 | |||
164 | |||
165 | |||
166 | // helper | ||
167 | |||
168 | UI.Utils.stackMargin = function(elements, options) { | ||
169 | |||
170 | options = UI.$.extend({ | ||
171 | 'cls': 'uk-margin-small-top' | ||
172 | }, options); | ||
173 | |||
174 | elements = UI.$(elements).removeClass(options.cls); | ||
175 | |||
176 | var min = false; | ||
177 | |||
178 | elements.each(function(offset, height, pos, $ele){ | ||
179 | |||
180 | $ele = UI.$(this); | ||
181 | |||
182 | if ($ele.css('display') != 'none') { | ||
183 | |||
184 | offset = $ele.offset(); | ||
185 | height = $ele.outerHeight(); | ||
186 | pos = offset.top + height; | ||
187 | |||
188 | $ele.data({ | ||
189 | 'ukMarginPos': pos, | ||
190 | 'ukMarginTop': offset.top | ||
191 | }); | ||
192 | |||
193 | if (min === false || (offset.top < min.top) ) { | ||
194 | |||
195 | min = { | ||
196 | top : offset.top, | ||
197 | left : offset.left, | ||
198 | pos : pos | ||
199 | }; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | }).each(function($ele) { | ||
204 | |||
205 | $ele = UI.$(this); | ||
206 | |||
207 | if ($ele.css('display') != 'none' && $ele.data('ukMarginTop') > min.top && $ele.data('ukMarginPos') > min.pos) { | ||
208 | $ele.addClass(options.cls); | ||
209 | } | ||
210 | }); | ||
211 | }; | ||
212 | |||
213 | UI.Utils.matchHeights = function(elements, options) { | ||
214 | |||
215 | elements = UI.$(elements).css('min-height', ''); | ||
216 | options = UI.$.extend({ row : true }, options); | ||
217 | |||
218 | var matchHeights = function(group){ | ||
219 | |||
220 | if (group.length < 2) return; | ||
221 | |||
222 | var max = 0; | ||
223 | |||
224 | group.each(function() { | ||
225 | max = Math.max(max, UI.$(this).outerHeight()); | ||
226 | }).each(function() { | ||
227 | |||
228 | var element = UI.$(this), | ||
229 | height = max - (element.css('box-sizing') == 'border-box' ? 0 : (element.outerHeight() - element.height())); | ||
230 | |||
231 | element.css('min-height', height + 'px'); | ||
232 | }); | ||
233 | }; | ||
234 | |||
235 | if (options.row) { | ||
236 | |||
237 | elements.first().width(); // force redraw | ||
238 | |||
239 | setTimeout(function(){ | ||
240 | |||
241 | var lastoffset = false, group = []; | ||
242 | |||
243 | elements.each(function() { | ||
244 | |||
245 | var ele = UI.$(this), offset = ele.offset().top; | ||
246 | |||
247 | if (offset != lastoffset && group.length) { | ||
248 | |||
249 | matchHeights(UI.$(group)); | ||
250 | group = []; | ||
251 | offset = ele.offset().top; | ||
252 | } | ||
253 | |||
254 | group.push(ele); | ||
255 | lastoffset = offset; | ||
256 | }); | ||
257 | |||
258 | if (group.length) { | ||
259 | matchHeights(UI.$(group)); | ||
260 | } | ||
261 | |||
262 | }, 0); | ||
263 | |||
264 | } else { | ||
265 | matchHeights(elements); | ||
266 | } | ||
267 | }; | ||
268 | |||
269 | (function(cacheSvgs){ | ||
270 | |||
271 | UI.Utils.inlineSvg = function(selector, root) { | ||
272 | |||
273 | var images = UI.$(selector || 'img[src$=".svg"]', root || document).each(function(){ | ||
274 | |||
275 | var img = UI.$(this), | ||
276 | src = img.attr('src'); | ||
277 | |||
278 | if (!cacheSvgs[src]) { | ||
279 | |||
280 | var d = UI.$.Deferred(); | ||
281 | |||
282 | UI.$.get(src, {nc: Math.random()}, function(data){ | ||
283 | d.resolve(UI.$(data).find('svg')); | ||
284 | }); | ||
285 | |||
286 | cacheSvgs[src] = d.promise(); | ||
287 | } | ||
288 | |||
289 | cacheSvgs[src].then(function(svg) { | ||
290 | |||
291 | var $svg = UI.$(svg).clone(); | ||
292 | |||
293 | if (img.attr('id')) $svg.attr('id', img.attr('id')); | ||
294 | if (img.attr('class')) $svg.attr('class', img.attr('class')); | ||
295 | if (img.attr('style')) $svg.attr('style', img.attr('style')); | ||
296 | |||
297 | if (img.attr('width')) { | ||
298 | $svg.attr('width', img.attr('width')); | ||
299 | if (!img.attr('height')) $svg.removeAttr('height'); | ||
300 | } | ||
301 | |||
302 | if (img.attr('height')){ | ||
303 | $svg.attr('height', img.attr('height')); | ||
304 | if (!img.attr('width')) $svg.removeAttr('width'); | ||
305 | } | ||
306 | |||
307 | img.replaceWith($svg); | ||
308 | }); | ||
309 | }); | ||
310 | }; | ||
311 | |||
312 | // init code | ||
313 | UI.ready(function(context) { | ||
314 | UI.Utils.inlineSvg('[data-uk-svg]', context); | ||
315 | }); | ||
316 | |||
317 | })({}); | ||
318 | |||
319 | })(UIkit); | ||