PageSourceSearch

https://www.puresound-net.co.jp/vendor/uikit/js/components/grid.js

js puresound-net.co.jp collected 2026-10-05 22:51:43 UTC 17,121 bytes, 540 lines download raw bytes

1/*! UIkit 2.27.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2(function(addon) {
3
4    var component;
5
6    if (window.UIkit) {
7        component = addon(UIkit);
8    }
9
10    if (typeof define == 'function' && define.amd) {
11        define('uikit-grid', ['uikit'], function(){
12            return component || addon(UIkit);
13        });
14    }
15
16})(function(UI){
17
18    "use strict";
19
20    UI.component('grid', {
21
22        defaults: {
23            colwidth  : 'auto',
24            animation : true,
25            duration  : 300,
26            gutter    : 0,
27            controls  : false,
28            filter    : false,
29            origin    : UI.langdirection
30        },
31
32        boot:  function() {
33
34            // init code
35            UI.ready(function(context) {
36
37                UI.$('[data-uk-grid]', context).each(function(){
38
39                    var ele = UI.$(this);
40
41                    if(!ele.data('grid')) {
42                        UI.grid(ele, UI.Utils.options(ele.attr('data-uk-grid')));
43                    }
44                });
45            });
46        },
47
48        init: function() {
49
50            var $this = this, gutter = String(this.options.gutter).trim().split(' ');
51
52            this.gutterv  = parseInt(gutter[0], 10);
53            this.gutterh  = parseInt((gutter[1] || gutter[0]), 10);
54
55            // make sure parent element has the right position property
56            this.element.css({'position': 'relative'});
57
58            this.controls = null;
59            this.origin   = this.options.origin;
60
61            if (this.options.controls) {
62
63                this.controls = UI.$(this.options.controls);
64
65                // filter
66                this.controls.on('click', '[data-uk-filter]', function(e){
67                    e.preventDefault();
68                    $this.filter(UI.$(this).attr('data-uk-filter'));
69                });
70
71                // sort
72                this.controls.on('click', '[data-uk-sort]', function(e){
73                    e.preventDefault();
74                    var cmd = UI.$(this).attr('data-uk-sort').split(':');
75                    $this.sort(cmd[0], cmd[1]);
76                });
77            }
78
79            UI.$win.on('load resize orientationchange', UI.Utils.debounce(function(){
80
81                if ($this.currentfilter) {
82                    $this.filter($this.currentfilter);
83                } else {
84                    this.update();
85                }
86
87            }.bind(this), 100));
88
89            this.on('display.uk.check', function(){
90                if ($this.element.is(':visible'))  $this.update();
91            });
92
93            UI.domObserve(this.element, function(e) {
94                $this.update();
95            });
96
97            if (this.options.filter !== false) {
98                this.filter(this.options.filter);
99            } else {
100                this.update();
101            }
102        },
103
104        _prepareElements: function() {
105
106            var children = this.element.children(':not([data-grid-prepared])'), css;
107
108            // exit if no already prepared elements found
109            if (!children.length) {
110                return;
111            }
112
113            css = {
114                position  : 'absolute',
115                boxSizing : 'border-box',
116                width     : this.options.colwidth == 'auto' ? '' : this.options.colwidth
117            };
118
119            if (this.options.gutter) {
120
121                css['padding-'+this.origin] = this.gutterh;
122                css['padding-bottom'] = this.gutterv;
123
124                this.element.css('margin-'+this.origin, this.gutterh * -1);
125            }
126
127            children.attr('data-grid-prepared', 'true').css(css);
128        },
129
130        update: function(elements) {
131
132            var $this = this;
133
134            this._prepareElements();
135
136            elements = elements || this.element.children(':visible');
137
138            var children  = elements,
139                maxwidth  = this.element.width() + (2*this.gutterh) + 2,
140                left      = 0,
141                top       = 0,
142                positions = [],
143
144                item, width, height, pos, posi, i, z, max, size;
145
146            this.trigger('beforeupdate.uk.grid', [children]);
147
148            children.each(function(index){
149
150                size   = getElementSize(this);
151
152                item   = UI.$(this);
153                width  = size.outerWidth;
154                height = size.outerHeight;
155                left   = 0;
156                top    = 0;
157
158                for (i=0,max=positions.length;i<max;i++) {
159
160                    pos = positions[i];
161
162                    if (left <= pos.aX) { left = pos.aX; }
163                    if (maxwidth < (left + width)) { left = 0; }
164                    if (top <= pos.aY) { top = pos.aY; }
165                }
166
167                posi = {
168                    ele    : item,
169                    top    : top,
170                    width  : width,
171                    height : height,
172                    aY     : (top  + height),
173                    aX     : (left + width)
174                };
175
176                posi[$this.origin] = left;
177
178                positions.push(posi);
179            });
180
181            var posPrev, maxHeight = 0, positionto;
182
183            // fix top
184            for (i=0,max=positions.length;i<max;i++) {
185
186                pos = positions[i];
187                top = 0;
188
189                for (z=0;z<i;z++) {
190
191                    posPrev = positions[z];
192
193                    // (posPrev.left + 1) fixex 1px bug when using % based widths
194                    if (pos[this.origin] < posPrev.aX && (posPrev[this.origin] +1) < pos.aX) {
195                        top = posPrev.aY;
196                    }
197                }
198
199                pos.top = top;
200                pos.aY  = top + pos.height;
201
202                maxHeight = Math.max(maxHeight, pos.aY);
203            }
204
205            maxHeight = maxHeight - this.gutterv;
206
207            if (this.options.animation) {
208
209                this.element.stop().animate({'height': maxHeight}, 100);
210
211                positions.forEach(function(pos){
212
213                    positionto = {"top": pos.top, opacity: 1};
214                    positionto[$this.origin] = pos[$this.origin];
215
216                    pos.ele.stop().animate(positionto, this.options.duration);
217                }.bind(this));
218
219            } else {
220
221                this.element.css('height', maxHeight);
222
223                positions.forEach(function(pos){
224                    positionto = {"top": pos.top, opacity: 1};
225                    positionto[$this.origin] = pos[$this.origin];
226                    pos.ele.css(positionto);
227                }.bind(this));
228            }
229
230            // make sure to trigger possible scrollpies etc.
231            setTimeout(function() {
232                UI.$doc.trigger('scrolling.uk.document');
233            }, 2 * this.options.duration * (this.options.animation ? 1:0));
234
235            this.trigger('afterupdate.uk.grid', [children]);
236        },
237
238        filter: function(filter) {
239
240            this.currentfilter = filter;
241
242            filter = filter || [];
243
244            if (typeof(filter) === 'number') {
245                filter = filter.toString();
246            }
247
248            if (typeof(filter) === 'string') {
249                filter = filter.split(/,/).map(function(item){ return item.trim(); });
250            }
251
252            var $this = this, children = this.element.children(), elements = {"visible": [], "hidden": []}, visible, hidden;
253
254            children.each(function(index){
255
256                var ele = UI.$(this), f = ele.attr('data-uk-filter'), infilter = filter.length ? false : true;
257
258                if (f) {
259
260                    f = f.split(/,/).map(function(item){ return item.trim(); });
261
262                    filter.forEach(function(item){
263                        if (f.indexOf(item) > -1) infilter = true;
264                    });
265                }
266
267                elements[infilter ? "visible":"hidden"].push(ele);
268            });
269
270            // convert to jQuery collections
271            elements.hidden  = UI.$(elements.hidden).map(function () {return this[0];});
272            elements.visible = UI.$(elements.visible).map(function () {return this[0];});
273
274            elements.hidden.attr('aria-hidden', 'true').filter(':visible').fadeOut(this.options.duration);
275            elements.visible.attr('aria-hidden', 'false').filter(':hidden').css('opacity', 0).show();
276
277            $this.update(elements.visible);
278
279            if (this.controls && this.controls.length) {
280                this.controls.find('[data-uk-filter]').removeClass('uk-active').filter('[data-uk-filter="'+filter+'"]').addClass('uk-active');
281            }
282        },
283
284        sort: function(by, order){
285
286            order = order || 1;
287
288            // covert from string (asc|desc) to number
289            if (typeof(order) === 'string') {
290                order = order.toLowerCase() == 'desc' ? -1 : 1;
291            }
292
293            var elements = this.element.children();
294
295            elements.sort(function(a, b){
296
297                a = UI.$(a);
298                b = UI.$(b);
299
300                return (b.data(by) || '') < (a.data(by) || '') ? order : (order*-1);
301
302            }).appendTo(this.element);
303
304            this.update(elements.filter(':visible'));
305
306            if (this.controls && this.controls.length) {
307                this.controls.find('[data-uk-sort]').removeClass('uk-active').filter('[data-uk-sort="'+by+':'+(order == -1 ? 'desc':'asc')+'"]').addClass('uk-active');
308            }
309        }
310    });
311
312
313    /*!
314    * getSize v1.2.2
315    * measure size of elements
316    * MIT license
317    * https://github.com/desandro/get-size
318    */
319    function _getSize() {
320
321        var prefixes = 'Webkit Moz ms Ms O'.split(' ');
322        var docElemStyle = document.documentElement.style;
323
324        function getStyleProperty( propName ) {
325            if ( !propName ) {
326                return;
327            }
328
329            // test standard property first
330            if ( typeof docElemStyle[ propName ] === 'string' ) {
331                return propName;
332            }
333
334            // capitalize
335            propName = propName.charAt(0).toUpperCase() + propName.slice(1);
336
337            // test vendor specific properties
338            var prefixed;
339            for ( var i=0, len = prefixes.length; i < len; i++ ) {
340                prefixed = prefixes[i] + propName;
341                if ( typeof docElemStyle[ prefixed ] === 'string' ) {
342                    return prefixed;
343                }
344            }
345        }
346
347        // -------------------------- helpers -------------------------- //
348
349        // get a number from a string, not a percentage
350        function getStyleSize( value ) {
351            var num = parseFloat( value );
352            // not a percent like '100%', and a number
353            var isValid = value.indexOf('%') === -1 && !isNaN( num );
354            return isValid && num;
355        }
356
357        function noop() {}
358
359        var logError = typeof console === 'undefined' ? noop : function( message ) {
360            console.error( message );
361        };
362
363        // -------------------------- measurements -------------------------- //
364
365        var measurements = [
366            'paddingLeft',
367            'paddingRight',
368            'paddingTop',
369            'paddingBottom',
370            'marginLeft',
371            'marginRight',
372            'marginTop',
373            'marginBottom',
374            'borderLeftWidth',
375            'borderRightWidth',
376            'borderTopWidth',
377            'borderBottomWidth'
378        ];
379
380        function getZeroSize() {
381            var size = {
382                width: 0,
383                height: 0,
384                innerWidth: 0,
385                innerHeight: 0,
386                outerWidth: 0,
387                outerHeight: 0
388            };
389            for ( var i=0, len = measurements.length; i < len; i++ ) {
390                var measurement = measurements[i];
391                size[ measurement ] = 0;
392            }
393            return size;
394        }
395
396
397        // -------------------------- setup -------------------------- //
398
399        var isSetup = false;
400        var getStyle, boxSizingProp, isBoxSizeOuter;
401
402        /**
403        * setup vars and functions
404        * do it on initial getSize(), rather than on script load
405        * For Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=548397
406        */
407        function setup() {
408            // setup once
409            if ( isSetup ) {
410                return;
411            }
412            isSetup = true;
413
414            var getComputedStyle = window.getComputedStyle;
415            getStyle = ( function() {
416                var getStyleFn = getComputedStyle ?
417                function( elem ) {
418                    return getComputedStyle( elem, null );
419                } :
420                function( elem ) {
421                    return elem.currentStyle;
422                };
423
424                return function getStyle( elem ) {
425                    var style = getStyleFn( elem );
426                    if ( !style ) {
427                        logError( 'Style returned ' + style +
428                        '. Are you running this code in a hidden iframe on Firefox? ' +
429                        'See http://bit.ly/getsizebug1' );
430                    }
431                    return style;
432                };
433            })();
434
435            // -------------------------- box sizing -------------------------- //
436
437            boxSizingProp = getStyleProperty('boxSizing');
438
439            /**
440            * WebKit measures the outer-width on style.width on border-box elems
441            * IE & Firefox measures the inner-width
442            */
443            if ( boxSizingProp ) {
444                var div = document.createElement('div');
445                div.style.width = '200px';
446                div.style.padding = '1px 2px 3px 4px';
447                div.style.borderStyle = 'solid';
448                div.style.borderWidth = '1px 2px 3px 4px';
449                div.style[ boxSizingProp ] = 'border-box';
450
451                var body = document.body || document.documentElement;
452                body.appendChild( div );
453                var style = getStyle( div );
454
455                isBoxSizeOuter = getStyleSize( style.width ) === 200;
456                body.removeChild( div );
457            }
458
459        }
460
461        // -------------------------- getSize -------------------------- //
462
463        function getSize( elem ) {
464            setup();
465
466            // use querySeletor if elem is string
467            if ( typeof elem === 'string' ) {
468                elem = document.querySelector( elem );
469            }
470
471            // do not proceed on non-objects
472            if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
473                return;
474            }
475
476            var style = getStyle( elem );
477
478            // if hidden, everything is 0
479            if ( style.display === 'none' ) {
480                return getZeroSize();
481            }
482
483            var size = {};
484            size.width = elem.offsetWidth;
485            size.height = elem.offsetHeight;
486
487            var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
488                style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
489
490            // get all measurements
491            for ( var i=0, len = measurements.length; i < len; i++ ) {
492                var measurement = measurements[i];
493                var value = style[ measurement ];
494
495                var num = parseFloat( value );
496                // any 'auto', 'medium' value will be 0
497                size[ measurement ] = !isNaN( num ) ? num : 0;
498            }
499
500            var paddingWidth = size.paddingLeft + size.paddingRight;
501            var paddingHeight = size.paddingTop + size.paddingBottom;
502            var marginWidth = size.marginLeft + size.marginRight;
503            var marginHeight = size.marginTop + size.marginBottom;
504            var borderWidth = size.borderLeftWidth + size.borderRightWidth;
505            var borderHeight = size.borderTopWidth + size.borderBottomWidth;
506
507            var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
508
509            // overwrite width and height if we can get it from style
510            var styleWidth = getStyleSize( style.width );
511            if ( styleWidth !== false ) {
512                size.width = styleWidth +
513                // add padding and border unless it's already including it
514                ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
515            }
516
517            var styleHeight = getStyleSize( style.height );
518            if ( styleHeight !== false ) {
519                size.height = styleHeight +
520                // add padding and border unless it's already including it
521                ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
522            }
523
524            size.innerWidth = size.width - ( paddingWidth + borderWidth );
525            size.innerHeight = size.height - ( paddingHeight + borderHeight );
526
527            size.outerWidth = size.width + marginWidth;
528            size.outerHeight = size.height + marginHeight;
529
530            return size;
531        }
532
533        return getSize;
534
535    }
536
537    function getElementSize(ele) {
538        return _getSize()(ele);
539    }
540});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.