1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | ( function( window, factory ) {
|
18 |
|
19 |
|
20 | if ( typeof define == 'function' && define.amd ) {
|
21 |
|
22 | define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
|
23 | return factory( window, jQuery );
|
24 | });
|
25 | } else if ( typeof module == 'object' && module.exports ) {
|
26 |
|
27 | module.exports = factory(
|
28 | window,
|
29 | require('jquery')
|
30 | );
|
31 | } else {
|
32 |
|
33 | window.jQueryBridget = factory(
|
34 | window,
|
35 | window.jQuery
|
36 | );
|
37 | }
|
38 |
|
39 | }( window, function factory( window, jQuery ) {
|
40 | 'use strict';
|
41 |
|
42 |
|
43 |
|
44 | var arraySlice = Array.prototype.slice;
|
45 |
|
46 |
|
47 |
|
48 | var console = window.console;
|
49 | var logError = typeof console == 'undefined' ? function() {} :
|
50 | function( message ) {
|
51 | console.error( message );
|
52 | };
|
53 |
|
54 |
|
55 |
|
56 | function jQueryBridget( namespace, PluginClass, $ ) {
|
57 | $ = $ || jQuery || window.jQuery;
|
58 | if ( !$ ) {
|
59 | return;
|
60 | }
|
61 |
|
62 |
|
63 | if ( !PluginClass.prototype.option ) {
|
64 |
|
65 | PluginClass.prototype.option = function( opts ) {
|
66 |
|
67 | if ( !$.isPlainObject( opts ) ){
|
68 | return;
|
69 | }
|
70 | this.options = $.extend( true, this.options, opts );
|
71 | };
|
72 | }
|
73 |
|
74 |
|
75 | $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
|
76 | if ( typeof arg0 == 'string' ) {
|
77 |
|
78 |
|
79 | var args = arraySlice.call( arguments, 1 );
|
80 | return methodCall( this, arg0, args );
|
81 | }
|
82 |
|
83 | plainCall( this, arg0 );
|
84 | return this;
|
85 | };
|
86 |
|
87 |
|
88 | function methodCall( $elems, methodName, args ) {
|
89 | var returnValue;
|
90 | var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
|
91 |
|
92 | $elems.each( function( i, elem ) {
|
93 |
|
94 | var instance = $.data( elem, namespace );
|
95 | if ( !instance ) {
|
96 | logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
|
97 | pluginMethodStr );
|
98 | return;
|
99 | }
|
100 |
|
101 | var method = instance[ methodName ];
|
102 | if ( !method || methodName.charAt(0) == '_' ) {
|
103 | logError( pluginMethodStr + ' is not a valid method' );
|
104 | return;
|
105 | }
|
106 |
|
107 |
|
108 | var value = method.apply( instance, args );
|
109 |
|
110 | returnValue = returnValue === undefined ? value : returnValue;
|
111 | });
|
112 |
|
113 | return returnValue !== undefined ? returnValue : $elems;
|
114 | }
|
115 |
|
116 | function plainCall( $elems, options ) {
|
117 | $elems.each( function( i, elem ) {
|
118 | var instance = $.data( elem, namespace );
|
119 | if ( instance ) {
|
120 |
|
121 | instance.option( options );
|
122 | instance._init();
|
123 | } else {
|
124 |
|
125 | instance = new PluginClass( elem, options );
|
126 | $.data( elem, namespace, instance );
|
127 | }
|
128 | });
|
129 | }
|
130 |
|
131 | updateJQuery( $ );
|
132 |
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | function updateJQuery( $ ) {
|
139 | if ( !$ || ( $ && $.bridget ) ) {
|
140 | return;
|
141 | }
|
142 | $.bridget = jQueryBridget;
|
143 | }
|
144 |
|
145 | updateJQuery( jQuery || window.jQuery );
|
146 |
|
147 |
|
148 |
|
149 | return jQueryBridget;
|
150 |
|
151 | }));
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | ( function( global, factory ) {
|
162 |
|
163 |
|
164 | if ( typeof define == 'function' && define.amd ) {
|
165 |
|
166 | define( 'ev-emitter/ev-emitter',factory );
|
167 | } else if ( typeof module == 'object' && module.exports ) {
|
168 |
|
169 | module.exports = factory();
|
170 | } else {
|
171 |
|
172 | global.EvEmitter = factory();
|
173 | }
|
174 |
|
175 | }( typeof window != 'undefined' ? window : this, function() {
|
176 |
|
177 |
|
178 |
|
179 | function EvEmitter() {}
|
180 |
|
181 | var proto = EvEmitter.prototype;
|
182 |
|
183 | proto.on = function( eventName, listener ) {
|
184 | if ( !eventName || !listener ) {
|
185 | return;
|
186 | }
|
187 |
|
188 | var events = this._events = this._events || {};
|
189 |
|
190 | var listeners = events[ eventName ] = events[ eventName ] || [];
|
191 |
|
192 | if ( listeners.indexOf( listener ) == -1 ) {
|
193 | listeners.push( listener );
|
194 | }
|
195 |
|
196 | return this;
|
197 | };
|
198 |
|
199 | proto.once = function( eventName, listener ) {
|
200 | if ( !eventName || !listener ) {
|
201 | return;
|
202 | }
|
203 |
|
204 | this.on( eventName, listener );
|
205 |
|
206 |
|
207 | var onceEvents = this._onceEvents = this._onceEvents || {};
|
208 |
|
209 | var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
|
210 |
|
211 | onceListeners[ listener ] = true;
|
212 |
|
213 | return this;
|
214 | };
|
215 |
|
216 | proto.off = function( eventName, listener ) {
|
217 | var listeners = this._events && this._events[ eventName ];
|
218 | if ( !listeners || !listeners.length ) {
|
219 | return;
|
220 | }
|
221 | var index = listeners.indexOf( listener );
|
222 | if ( index != -1 ) {
|
223 | listeners.splice( index, 1 );
|
224 | }
|
225 |
|
226 | return this;
|
227 | };
|
228 |
|
229 | proto.emitEvent = function( eventName, args ) {
|
230 | var listeners = this._events && this._events[ eventName ];
|
231 | if ( !listeners || !listeners.length ) {
|
232 | return;
|
233 | }
|
234 |
|
235 | listeners = listeners.slice(0);
|
236 | args = args || [];
|
237 |
|
238 | var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
|
239 |
|
240 | for ( var i=0; i < listeners.length; i++ ) {
|
241 | var listener = listeners[i]
|
242 | var isOnce = onceListeners && onceListeners[ listener ];
|
243 | if ( isOnce ) {
|
244 |
|
245 |
|
246 | this.off( eventName, listener );
|
247 |
|
248 | delete onceListeners[ listener ];
|
249 | }
|
250 |
|
251 | listener.apply( this, args );
|
252 | }
|
253 |
|
254 | return this;
|
255 | };
|
256 |
|
257 | proto.allOff = function() {
|
258 | delete this._events;
|
259 | delete this._onceEvents;
|
260 | };
|
261 |
|
262 | return EvEmitter;
|
263 |
|
264 | }));
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | ( function( window, factory ) {
|
276 |
|
277 | if ( typeof define == 'function' && define.amd ) {
|
278 |
|
279 | define( 'get-size/get-size',factory );
|
280 | } else if ( typeof module == 'object' && module.exports ) {
|
281 |
|
282 | module.exports = factory();
|
283 | } else {
|
284 |
|
285 | window.getSize = factory();
|
286 | }
|
287 |
|
288 | })( window, function factory() {
|
289 | 'use strict';
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | function getStyleSize( value ) {
|
295 | var num = parseFloat( value );
|
296 |
|
297 | var isValid = value.indexOf('%') == -1 && !isNaN( num );
|
298 | return isValid && num;
|
299 | }
|
300 |
|
301 | function noop() {}
|
302 |
|
303 | var logError = typeof console == 'undefined' ? noop :
|
304 | function( message ) {
|
305 | console.error( message );
|
306 | };
|
307 |
|
308 |
|
309 |
|
310 | var measurements = [
|
311 | 'paddingLeft',
|
312 | 'paddingRight',
|
313 | 'paddingTop',
|
314 | 'paddingBottom',
|
315 | 'marginLeft',
|
316 | 'marginRight',
|
317 | 'marginTop',
|
318 | 'marginBottom',
|
319 | 'borderLeftWidth',
|
320 | 'borderRightWidth',
|
321 | 'borderTopWidth',
|
322 | 'borderBottomWidth'
|
323 | ];
|
324 |
|
325 | var measurementsLength = measurements.length;
|
326 |
|
327 | function getZeroSize() {
|
328 | var size = {
|
329 | width: 0,
|
330 | height: 0,
|
331 | innerWidth: 0,
|
332 | innerHeight: 0,
|
333 | outerWidth: 0,
|
334 | outerHeight: 0
|
335 | };
|
336 | for ( var i=0; i < measurementsLength; i++ ) {
|
337 | var measurement = measurements[i];
|
338 | size[ measurement ] = 0;
|
339 | }
|
340 | return size;
|
341 | }
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 | function getStyle( elem ) {
|
350 | var style = getComputedStyle( elem );
|
351 | if ( !style ) {
|
352 | logError( 'Style returned ' + style +
|
353 | '. Are you running this code in a hidden iframe on Firefox? ' +
|
354 | 'See https://bit.ly/getsizebug1' );
|
355 | }
|
356 | return style;
|
357 | }
|
358 |
|
359 |
|
360 |
|
361 | var isSetup = false;
|
362 |
|
363 | var isBoxSizeOuter;
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 | function setup() {
|
371 |
|
372 | if ( isSetup ) {
|
373 | return;
|
374 | }
|
375 | isSetup = true;
|
376 |
|
377 |
|
378 |
|
379 | |
380 |
|
381 |
|
382 |
|
383 | var div = document.createElement('div');
|
384 | div.style.width = '200px';
|
385 | div.style.padding = '1px 2px 3px 4px';
|
386 | div.style.borderStyle = 'solid';
|
387 | div.style.borderWidth = '1px 2px 3px 4px';
|
388 | div.style.boxSizing = 'border-box';
|
389 |
|
390 | var body = document.body || document.documentElement;
|
391 | body.appendChild( div );
|
392 | var style = getStyle( div );
|
393 |
|
394 | isBoxSizeOuter = Math.round( getStyleSize( style.width ) ) == 200;
|
395 | getSize.isBoxSizeOuter = isBoxSizeOuter;
|
396 |
|
397 | body.removeChild( div );
|
398 | }
|
399 |
|
400 |
|
401 |
|
402 | function getSize( elem ) {
|
403 | setup();
|
404 |
|
405 |
|
406 | if ( typeof elem == 'string' ) {
|
407 | elem = document.querySelector( elem );
|
408 | }
|
409 |
|
410 |
|
411 | if ( !elem || typeof elem != 'object' || !elem.nodeType ) {
|
412 | return;
|
413 | }
|
414 |
|
415 | var style = getStyle( elem );
|
416 |
|
417 |
|
418 | if ( style.display == 'none' ) {
|
419 | return getZeroSize();
|
420 | }
|
421 |
|
422 | var size = {};
|
423 | size.width = elem.offsetWidth;
|
424 | size.height = elem.offsetHeight;
|
425 |
|
426 | var isBorderBox = size.isBorderBox = style.boxSizing == 'border-box';
|
427 |
|
428 |
|
429 | for ( var i=0; i < measurementsLength; i++ ) {
|
430 | var measurement = measurements[i];
|
431 | var value = style[ measurement ];
|
432 | var num = parseFloat( value );
|
433 |
|
434 | size[ measurement ] = !isNaN( num ) ? num : 0;
|
435 | }
|
436 |
|
437 | var paddingWidth = size.paddingLeft + size.paddingRight;
|
438 | var paddingHeight = size.paddingTop + size.paddingBottom;
|
439 | var marginWidth = size.marginLeft + size.marginRight;
|
440 | var marginHeight = size.marginTop + size.marginBottom;
|
441 | var borderWidth = size.borderLeftWidth + size.borderRightWidth;
|
442 | var borderHeight = size.borderTopWidth + size.borderBottomWidth;
|
443 |
|
444 | var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
|
445 |
|
446 |
|
447 | var styleWidth = getStyleSize( style.width );
|
448 | if ( styleWidth !== false ) {
|
449 | size.width = styleWidth +
|
450 |
|
451 | ( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
|
452 | }
|
453 |
|
454 | var styleHeight = getStyleSize( style.height );
|
455 | if ( styleHeight !== false ) {
|
456 | size.height = styleHeight +
|
457 |
|
458 | ( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
|
459 | }
|
460 |
|
461 | size.innerWidth = size.width - ( paddingWidth + borderWidth );
|
462 | size.innerHeight = size.height - ( paddingHeight + borderHeight );
|
463 |
|
464 | size.outerWidth = size.width + marginWidth;
|
465 | size.outerHeight = size.height + marginHeight;
|
466 |
|
467 | return size;
|
468 | }
|
469 |
|
470 | return getSize;
|
471 |
|
472 | });
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | ( function( window, factory ) {
|
483 |
|
484 | 'use strict';
|
485 |
|
486 | if ( typeof define == 'function' && define.amd ) {
|
487 |
|
488 | define( 'desandro-matches-selector/matches-selector',factory );
|
489 | } else if ( typeof module == 'object' && module.exports ) {
|
490 |
|
491 | module.exports = factory();
|
492 | } else {
|
493 |
|
494 | window.matchesSelector = factory();
|
495 | }
|
496 |
|
497 | }( window, function factory() {
|
498 | 'use strict';
|
499 |
|
500 | var matchesMethod = ( function() {
|
501 | var ElemProto = window.Element.prototype;
|
502 |
|
503 | if ( ElemProto.matches ) {
|
504 | return 'matches';
|
505 | }
|
506 |
|
507 | if ( ElemProto.matchesSelector ) {
|
508 | return 'matchesSelector';
|
509 | }
|
510 |
|
511 | var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
|
512 |
|
513 | for ( var i=0; i < prefixes.length; i++ ) {
|
514 | var prefix = prefixes[i];
|
515 | var method = prefix + 'MatchesSelector';
|
516 | if ( ElemProto[ method ] ) {
|
517 | return method;
|
518 | }
|
519 | }
|
520 | })();
|
521 |
|
522 | return function matchesSelector( elem, selector ) {
|
523 | return elem[ matchesMethod ]( selector );
|
524 | };
|
525 |
|
526 | }));
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 | ( function( window, factory ) {
|
536 |
|
537 |
|
538 |
|
539 | if ( typeof define == 'function' && define.amd ) {
|
540 |
|
541 | define( 'fizzy-ui-utils/utils',[
|
542 | 'desandro-matches-selector/matches-selector'
|
543 | ], function( matchesSelector ) {
|
544 | return factory( window, matchesSelector );
|
545 | });
|
546 | } else if ( typeof module == 'object' && module.exports ) {
|
547 |
|
548 | module.exports = factory(
|
549 | window,
|
550 | require('desandro-matches-selector')
|
551 | );
|
552 | } else {
|
553 |
|
554 | window.fizzyUIUtils = factory(
|
555 | window,
|
556 | window.matchesSelector
|
557 | );
|
558 | }
|
559 |
|
560 | }( window, function factory( window, matchesSelector ) {
|
561 |
|
562 |
|
563 |
|
564 | var utils = {};
|
565 |
|
566 |
|
567 |
|
568 |
|
569 | utils.extend = function( a, b ) {
|
570 | for ( var prop in b ) {
|
571 | a[ prop ] = b[ prop ];
|
572 | }
|
573 | return a;
|
574 | };
|
575 |
|
576 |
|
577 |
|
578 | utils.modulo = function( num, div ) {
|
579 | return ( ( num % div ) + div ) % div;
|
580 | };
|
581 |
|
582 |
|
583 |
|
584 | var arraySlice = Array.prototype.slice;
|
585 |
|
586 |
|
587 | utils.makeArray = function( obj ) {
|
588 | if ( Array.isArray( obj ) ) {
|
589 |
|
590 | return obj;
|
591 | }
|
592 |
|
593 | if ( obj === null || obj === undefined ) {
|
594 | return [];
|
595 | }
|
596 |
|
597 | var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
|
598 | if ( isArrayLike ) {
|
599 |
|
600 | return arraySlice.call( obj );
|
601 | }
|
602 |
|
603 |
|
604 | return [ obj ];
|
605 | };
|
606 |
|
607 |
|
608 |
|
609 | utils.removeFrom = function( ary, obj ) {
|
610 | var index = ary.indexOf( obj );
|
611 | if ( index != -1 ) {
|
612 | ary.splice( index, 1 );
|
613 | }
|
614 | };
|
615 |
|
616 |
|
617 |
|
618 | utils.getParent = function( elem, selector ) {
|
619 | while ( elem.parentNode && elem != document.body ) {
|
620 | elem = elem.parentNode;
|
621 | if ( matchesSelector( elem, selector ) ) {
|
622 | return elem;
|
623 | }
|
624 | }
|
625 | };
|
626 |
|
627 |
|
628 |
|
629 |
|
630 | utils.getQueryElement = function( elem ) {
|
631 | if ( typeof elem == 'string' ) {
|
632 | return document.querySelector( elem );
|
633 | }
|
634 | return elem;
|
635 | };
|
636 |
|
637 |
|
638 |
|
639 |
|
640 | utils.handleEvent = function( event ) {
|
641 | var method = 'on' + event.type;
|
642 | if ( this[ method ] ) {
|
643 | this[ method ]( event );
|
644 | }
|
645 | };
|
646 |
|
647 |
|
648 |
|
649 | utils.filterFindElements = function( elems, selector ) {
|
650 |
|
651 | elems = utils.makeArray( elems );
|
652 | var ffElems = [];
|
653 |
|
654 | elems.forEach( function( elem ) {
|
655 |
|
656 | if ( !( elem instanceof HTMLElement ) ) {
|
657 | return;
|
658 | }
|
659 |
|
660 | if ( !selector ) {
|
661 | ffElems.push( elem );
|
662 | return;
|
663 | }
|
664 |
|
665 |
|
666 | if ( matchesSelector( elem, selector ) ) {
|
667 | ffElems.push( elem );
|
668 | }
|
669 |
|
670 | var childElems = elem.querySelectorAll( selector );
|
671 |
|
672 | for ( var i=0; i < childElems.length; i++ ) {
|
673 | ffElems.push( childElems[i] );
|
674 | }
|
675 | });
|
676 |
|
677 | return ffElems;
|
678 | };
|
679 |
|
680 |
|
681 |
|
682 | utils.debounceMethod = function( _class, methodName, threshold ) {
|
683 | threshold = threshold || 100;
|
684 |
|
685 | var method = _class.prototype[ methodName ];
|
686 | var timeoutName = methodName + 'Timeout';
|
687 |
|
688 | _class.prototype[ methodName ] = function() {
|
689 | var timeout = this[ timeoutName ];
|
690 | clearTimeout( timeout );
|
691 |
|
692 | var args = arguments;
|
693 | var _this = this;
|
694 | this[ timeoutName ] = setTimeout( function() {
|
695 | method.apply( _this, args );
|
696 | delete _this[ timeoutName ];
|
697 | }, threshold );
|
698 | };
|
699 | };
|
700 |
|
701 |
|
702 |
|
703 | utils.docReady = function( callback ) {
|
704 | var readyState = document.readyState;
|
705 | if ( readyState == 'complete' || readyState == 'interactive' ) {
|
706 |
|
707 | setTimeout( callback );
|
708 | } else {
|
709 | document.addEventListener( 'DOMContentLoaded', callback );
|
710 | }
|
711 | };
|
712 |
|
713 |
|
714 |
|
715 |
|
716 | utils.toDashed = function( str ) {
|
717 | return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
|
718 | return $1 + '-' + $2;
|
719 | }).toLowerCase();
|
720 | };
|
721 |
|
722 | var console = window.console;
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 | utils.htmlInit = function( WidgetClass, namespace ) {
|
729 | utils.docReady( function() {
|
730 | var dashedNamespace = utils.toDashed( namespace );
|
731 | var dataAttr = 'data-' + dashedNamespace;
|
732 | var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
|
733 | var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
|
734 | var elems = utils.makeArray( dataAttrElems )
|
735 | .concat( utils.makeArray( jsDashElems ) );
|
736 | var dataOptionsAttr = dataAttr + '-options';
|
737 | var jQuery = window.jQuery;
|
738 |
|
739 | elems.forEach( function( elem ) {
|
740 | var attr = elem.getAttribute( dataAttr ) ||
|
741 | elem.getAttribute( dataOptionsAttr );
|
742 | var options;
|
743 | try {
|
744 | options = attr && JSON.parse( attr );
|
745 | } catch ( error ) {
|
746 |
|
747 | if ( console ) {
|
748 | console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
|
749 | ': ' + error );
|
750 | }
|
751 | return;
|
752 | }
|
753 |
|
754 | var instance = new WidgetClass( elem, options );
|
755 |
|
756 | if ( jQuery ) {
|
757 | jQuery.data( elem, namespace, instance );
|
758 | }
|
759 | });
|
760 |
|
761 | });
|
762 | };
|
763 |
|
764 |
|
765 |
|
766 | return utils;
|
767 |
|
768 | }));
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 | ( function( window, factory ) {
|
775 |
|
776 |
|
777 | if ( typeof define == 'function' && define.amd ) {
|
778 |
|
779 | define( 'outlayer/item',[
|
780 | 'ev-emitter/ev-emitter',
|
781 | 'get-size/get-size'
|
782 | ],
|
783 | factory
|
784 | );
|
785 | } else if ( typeof module == 'object' && module.exports ) {
|
786 |
|
787 | module.exports = factory(
|
788 | require('ev-emitter'),
|
789 | require('get-size')
|
790 | );
|
791 | } else {
|
792 |
|
793 | window.Outlayer = {};
|
794 | window.Outlayer.Item = factory(
|
795 | window.EvEmitter,
|
796 | window.getSize
|
797 | );
|
798 | }
|
799 |
|
800 | }( window, function factory( EvEmitter, getSize ) {
|
801 | 'use strict';
|
802 |
|
803 |
|
804 |
|
805 | function isEmptyObj( obj ) {
|
806 | for ( var prop in obj ) {
|
807 | return false;
|
808 | }
|
809 | prop = null;
|
810 | return true;
|
811 | }
|
812 |
|
813 |
|
814 |
|
815 |
|
816 | var docElemStyle = document.documentElement.style;
|
817 |
|
818 | var transitionProperty = typeof docElemStyle.transition == 'string' ?
|
819 | 'transition' : 'WebkitTransition';
|
820 | var transformProperty = typeof docElemStyle.transform == 'string' ?
|
821 | 'transform' : 'WebkitTransform';
|
822 |
|
823 | var transitionEndEvent = {
|
824 | WebkitTransition: 'webkitTransitionEnd',
|
825 | transition: 'transitionend'
|
826 | }[ transitionProperty ];
|
827 |
|
828 |
|
829 | var vendorProperties = {
|
830 | transform: transformProperty,
|
831 | transition: transitionProperty,
|
832 | transitionDuration: transitionProperty + 'Duration',
|
833 | transitionProperty: transitionProperty + 'Property',
|
834 | transitionDelay: transitionProperty + 'Delay'
|
835 | };
|
836 |
|
837 |
|
838 |
|
839 | function Item( element, layout ) {
|
840 | if ( !element ) {
|
841 | return;
|
842 | }
|
843 |
|
844 | this.element = element;
|
845 |
|
846 | this.layout = layout;
|
847 | this.position = {
|
848 | x: 0,
|
849 | y: 0
|
850 | };
|
851 |
|
852 | this._create();
|
853 | }
|
854 |
|
855 |
|
856 | var proto = Item.prototype = Object.create( EvEmitter.prototype );
|
857 | proto.constructor = Item;
|
858 |
|
859 | proto._create = function() {
|
860 |
|
861 | this._transn = {
|
862 | ingProperties: {},
|
863 | clean: {},
|
864 | onEnd: {}
|
865 | };
|
866 |
|
867 | this.css({
|
868 | position: 'absolute'
|
869 | });
|
870 | };
|
871 |
|
872 |
|
873 | proto.handleEvent = function( event ) {
|
874 | var method = 'on' + event.type;
|
875 | if ( this[ method ] ) {
|
876 | this[ method ]( event );
|
877 | }
|
878 | };
|
879 |
|
880 | proto.getSize = function() {
|
881 | this.size = getSize( this.element );
|
882 | };
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 | proto.css = function( style ) {
|
889 | var elemStyle = this.element.style;
|
890 |
|
891 | for ( var prop in style ) {
|
892 |
|
893 | var supportedProp = vendorProperties[ prop ] || prop;
|
894 | elemStyle[ supportedProp ] = style[ prop ];
|
895 | }
|
896 | };
|
897 |
|
898 |
|
899 | proto.getPosition = function() {
|
900 | var style = getComputedStyle( this.element );
|
901 | var isOriginLeft = this.layout._getOption('originLeft');
|
902 | var isOriginTop = this.layout._getOption('originTop');
|
903 | var xValue = style[ isOriginLeft ? 'left' : 'right' ];
|
904 | var yValue = style[ isOriginTop ? 'top' : 'bottom' ];
|
905 | var x = parseFloat( xValue );
|
906 | var y = parseFloat( yValue );
|
907 |
|
908 | var layoutSize = this.layout.size;
|
909 | if ( xValue.indexOf('%') != -1 ) {
|
910 | x = ( x / 100 ) * layoutSize.width;
|
911 | }
|
912 | if ( yValue.indexOf('%') != -1 ) {
|
913 | y = ( y / 100 ) * layoutSize.height;
|
914 | }
|
915 |
|
916 | x = isNaN( x ) ? 0 : x;
|
917 | y = isNaN( y ) ? 0 : y;
|
918 |
|
919 | x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
|
920 | y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
|
921 |
|
922 | this.position.x = x;
|
923 | this.position.y = y;
|
924 | };
|
925 |
|
926 |
|
927 | proto.layoutPosition = function() {
|
928 | var layoutSize = this.layout.size;
|
929 | var style = {};
|
930 | var isOriginLeft = this.layout._getOption('originLeft');
|
931 | var isOriginTop = this.layout._getOption('originTop');
|
932 |
|
933 |
|
934 | var xPadding = isOriginLeft ? 'paddingLeft' : 'paddingRight';
|
935 | var xProperty = isOriginLeft ? 'left' : 'right';
|
936 | var xResetProperty = isOriginLeft ? 'right' : 'left';
|
937 |
|
938 | var x = this.position.x + layoutSize[ xPadding ];
|
939 |
|
940 | style[ xProperty ] = this.getXValue( x );
|
941 |
|
942 | style[ xResetProperty ] = '';
|
943 |
|
944 |
|
945 | var yPadding = isOriginTop ? 'paddingTop' : 'paddingBottom';
|
946 | var yProperty = isOriginTop ? 'top' : 'bottom';
|
947 | var yResetProperty = isOriginTop ? 'bottom' : 'top';
|
948 |
|
949 | var y = this.position.y + layoutSize[ yPadding ];
|
950 |
|
951 | style[ yProperty ] = this.getYValue( y );
|
952 |
|
953 | style[ yResetProperty ] = '';
|
954 |
|
955 | this.css( style );
|
956 | this.emitEvent( 'layout', [ this ] );
|
957 | };
|
958 |
|
959 | proto.getXValue = function( x ) {
|
960 | var isHorizontal = this.layout._getOption('horizontal');
|
961 | return this.layout.options.percentPosition && !isHorizontal ?
|
962 | ( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px';
|
963 | };
|
964 |
|
965 | proto.getYValue = function( y ) {
|
966 | var isHorizontal = this.layout._getOption('horizontal');
|
967 | return this.layout.options.percentPosition && isHorizontal ?
|
968 | ( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px';
|
969 | };
|
970 |
|
971 | proto._transitionTo = function( x, y ) {
|
972 | this.getPosition();
|
973 |
|
974 | var curX = this.position.x;
|
975 | var curY = this.position.y;
|
976 |
|
977 | var didNotMove = x == this.position.x && y == this.position.y;
|
978 |
|
979 |
|
980 | this.setPosition( x, y );
|
981 |
|
982 |
|
983 | if ( didNotMove && !this.isTransitioning ) {
|
984 | this.layoutPosition();
|
985 | return;
|
986 | }
|
987 |
|
988 | var transX = x - curX;
|
989 | var transY = y - curY;
|
990 | var transitionStyle = {};
|
991 | transitionStyle.transform = this.getTranslate( transX, transY );
|
992 |
|
993 | this.transition({
|
994 | to: transitionStyle,
|
995 | onTransitionEnd: {
|
996 | transform: this.layoutPosition
|
997 | },
|
998 | isCleaning: true
|
999 | });
|
1000 | };
|
1001 |
|
1002 | proto.getTranslate = function( x, y ) {
|
1003 |
|
1004 | var isOriginLeft = this.layout._getOption('originLeft');
|
1005 | var isOriginTop = this.layout._getOption('originTop');
|
1006 | x = isOriginLeft ? x : -x;
|
1007 | y = isOriginTop ? y : -y;
|
1008 | return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
|
1009 | };
|
1010 |
|
1011 |
|
1012 | proto.goTo = function( x, y ) {
|
1013 | this.setPosition( x, y );
|
1014 | this.layoutPosition();
|
1015 | };
|
1016 |
|
1017 | proto.moveTo = proto._transitionTo;
|
1018 |
|
1019 | proto.setPosition = function( x, y ) {
|
1020 | this.position.x = parseFloat( x );
|
1021 | this.position.y = parseFloat( y );
|
1022 | };
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 | proto._nonTransition = function( args ) {
|
1033 | this.css( args.to );
|
1034 | if ( args.isCleaning ) {
|
1035 | this._removeStyles( args.to );
|
1036 | }
|
1037 | for ( var prop in args.onTransitionEnd ) {
|
1038 | args.onTransitionEnd[ prop ].call( this );
|
1039 | }
|
1040 | };
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | proto.transition = function( args ) {
|
1051 |
|
1052 | if ( !parseFloat( this.layout.options.transitionDuration ) ) {
|
1053 | this._nonTransition( args );
|
1054 | return;
|
1055 | }
|
1056 |
|
1057 | var _transition = this._transn;
|
1058 |
|
1059 | for ( var prop in args.onTransitionEnd ) {
|
1060 | _transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
|
1061 | }
|
1062 |
|
1063 | for ( prop in args.to ) {
|
1064 | _transition.ingProperties[ prop ] = true;
|
1065 |
|
1066 | if ( args.isCleaning ) {
|
1067 | _transition.clean[ prop ] = true;
|
1068 | }
|
1069 | }
|
1070 |
|
1071 |
|
1072 | if ( args.from ) {
|
1073 | this.css( args.from );
|
1074 |
|
1075 | var h = this.element.offsetHeight;
|
1076 |
|
1077 | h = null;
|
1078 | }
|
1079 |
|
1080 | this.enableTransition( args.to );
|
1081 |
|
1082 | this.css( args.to );
|
1083 |
|
1084 | this.isTransitioning = true;
|
1085 |
|
1086 | };
|
1087 |
|
1088 |
|
1089 |
|
1090 | function toDashedAll( str ) {
|
1091 | return str.replace( /([A-Z])/g, function( $1 ) {
|
1092 | return '-' + $1.toLowerCase();
|
1093 | });
|
1094 | }
|
1095 |
|
1096 | var transitionProps = 'opacity,' + toDashedAll( transformProperty );
|
1097 |
|
1098 | proto.enableTransition = function(/* style */) {
|
1099 |
|
1100 |
|
1101 | if ( this.isTransitioning ) {
|
1102 | return;
|
1103 | }
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 | var duration = this.layout.options.transitionDuration;
|
1116 | duration = typeof duration == 'number' ? duration + 'ms' : duration;
|
1117 |
|
1118 | this.css({
|
1119 | transitionProperty: transitionProps,
|
1120 | transitionDuration: duration,
|
1121 | transitionDelay: this.staggerDelay || 0
|
1122 | });
|
1123 |
|
1124 | this.element.addEventListener( transitionEndEvent, this, false );
|
1125 | };
|
1126 |
|
1127 |
|
1128 |
|
1129 | proto.onwebkitTransitionEnd = function( event ) {
|
1130 | this.ontransitionend( event );
|
1131 | };
|
1132 |
|
1133 | proto.onotransitionend = function( event ) {
|
1134 | this.ontransitionend( event );
|
1135 | };
|
1136 |
|
1137 |
|
1138 | var dashedVendorProperties = {
|
1139 | '-webkit-transform': 'transform'
|
1140 | };
|
1141 |
|
1142 | proto.ontransitionend = function( event ) {
|
1143 |
|
1144 | if ( event.target !== this.element ) {
|
1145 | return;
|
1146 | }
|
1147 | var _transition = this._transn;
|
1148 |
|
1149 | var propertyName = dashedVendorProperties[ event.propertyName ] || event.propertyName;
|
1150 |
|
1151 |
|
1152 | delete _transition.ingProperties[ propertyName ];
|
1153 |
|
1154 | if ( isEmptyObj( _transition.ingProperties ) ) {
|
1155 |
|
1156 | this.disableTransition();
|
1157 | }
|
1158 |
|
1159 | if ( propertyName in _transition.clean ) {
|
1160 |
|
1161 | this.element.style[ event.propertyName ] = '';
|
1162 | delete _transition.clean[ propertyName ];
|
1163 | }
|
1164 |
|
1165 | if ( propertyName in _transition.onEnd ) {
|
1166 | var onTransitionEnd = _transition.onEnd[ propertyName ];
|
1167 | onTransitionEnd.call( this );
|
1168 | delete _transition.onEnd[ propertyName ];
|
1169 | }
|
1170 |
|
1171 | this.emitEvent( 'transitionEnd', [ this ] );
|
1172 | };
|
1173 |
|
1174 | proto.disableTransition = function() {
|
1175 | this.removeTransitionStyles();
|
1176 | this.element.removeEventListener( transitionEndEvent, this, false );
|
1177 | this.isTransitioning = false;
|
1178 | };
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 | proto._removeStyles = function( style ) {
|
1185 |
|
1186 | var cleanStyle = {};
|
1187 | for ( var prop in style ) {
|
1188 | cleanStyle[ prop ] = '';
|
1189 | }
|
1190 | this.css( cleanStyle );
|
1191 | };
|
1192 |
|
1193 | var cleanTransitionStyle = {
|
1194 | transitionProperty: '',
|
1195 | transitionDuration: '',
|
1196 | transitionDelay: ''
|
1197 | };
|
1198 |
|
1199 | proto.removeTransitionStyles = function() {
|
1200 |
|
1201 | this.css( cleanTransitionStyle );
|
1202 | };
|
1203 |
|
1204 |
|
1205 |
|
1206 | proto.stagger = function( delay ) {
|
1207 | delay = isNaN( delay ) ? 0 : delay;
|
1208 | this.staggerDelay = delay + 'ms';
|
1209 | };
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 | proto.removeElem = function() {
|
1215 | this.element.parentNode.removeChild( this.element );
|
1216 |
|
1217 | this.css({ display: '' });
|
1218 | this.emitEvent( 'remove', [ this ] );
|
1219 | };
|
1220 |
|
1221 | proto.remove = function() {
|
1222 |
|
1223 | if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
|
1224 | this.removeElem();
|
1225 | return;
|
1226 | }
|
1227 |
|
1228 |
|
1229 | this.once( 'transitionEnd', function() {
|
1230 | this.removeElem();
|
1231 | });
|
1232 | this.hide();
|
1233 | };
|
1234 |
|
1235 | proto.reveal = function() {
|
1236 | delete this.isHidden;
|
1237 |
|
1238 | this.css({ display: '' });
|
1239 |
|
1240 | var options = this.layout.options;
|
1241 |
|
1242 | var onTransitionEnd = {};
|
1243 | var transitionEndProperty = this.getHideRevealTransitionEndProperty('visibleStyle');
|
1244 | onTransitionEnd[ transitionEndProperty ] = this.onRevealTransitionEnd;
|
1245 |
|
1246 | this.transition({
|
1247 | from: options.hiddenStyle,
|
1248 | to: options.visibleStyle,
|
1249 | isCleaning: true,
|
1250 | onTransitionEnd: onTransitionEnd
|
1251 | });
|
1252 | };
|
1253 |
|
1254 | proto.onRevealTransitionEnd = function() {
|
1255 |
|
1256 |
|
1257 | if ( !this.isHidden ) {
|
1258 | this.emitEvent('reveal');
|
1259 | }
|
1260 | };
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 | proto.getHideRevealTransitionEndProperty = function( styleProperty ) {
|
1268 | var optionStyle = this.layout.options[ styleProperty ];
|
1269 |
|
1270 | if ( optionStyle.opacity ) {
|
1271 | return 'opacity';
|
1272 | }
|
1273 |
|
1274 | for ( var prop in optionStyle ) {
|
1275 | return prop;
|
1276 | }
|
1277 | };
|
1278 |
|
1279 | proto.hide = function() {
|
1280 |
|
1281 | this.isHidden = true;
|
1282 |
|
1283 | this.css({ display: '' });
|
1284 |
|
1285 | var options = this.layout.options;
|
1286 |
|
1287 | var onTransitionEnd = {};
|
1288 | var transitionEndProperty = this.getHideRevealTransitionEndProperty('hiddenStyle');
|
1289 | onTransitionEnd[ transitionEndProperty ] = this.onHideTransitionEnd;
|
1290 |
|
1291 | this.transition({
|
1292 | from: options.visibleStyle,
|
1293 | to: options.hiddenStyle,
|
1294 |
|
1295 | isCleaning: true,
|
1296 | onTransitionEnd: onTransitionEnd
|
1297 | });
|
1298 | };
|
1299 |
|
1300 | proto.onHideTransitionEnd = function() {
|
1301 |
|
1302 |
|
1303 | if ( this.isHidden ) {
|
1304 | this.css({ display: 'none' });
|
1305 | this.emitEvent('hide');
|
1306 | }
|
1307 | };
|
1308 |
|
1309 | proto.destroy = function() {
|
1310 | this.css({
|
1311 | position: '',
|
1312 | left: '',
|
1313 | right: '',
|
1314 | top: '',
|
1315 | bottom: '',
|
1316 | transition: '',
|
1317 | transform: ''
|
1318 | });
|
1319 | };
|
1320 |
|
1321 | return Item;
|
1322 |
|
1323 | }));
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 | ( function( window, factory ) {
|
1332 | 'use strict';
|
1333 |
|
1334 |
|
1335 | if ( typeof define == 'function' && define.amd ) {
|
1336 |
|
1337 | define( 'outlayer/outlayer',[
|
1338 | 'ev-emitter/ev-emitter',
|
1339 | 'get-size/get-size',
|
1340 | 'fizzy-ui-utils/utils',
|
1341 | './item'
|
1342 | ],
|
1343 | function( EvEmitter, getSize, utils, Item ) {
|
1344 | return factory( window, EvEmitter, getSize, utils, Item);
|
1345 | }
|
1346 | );
|
1347 | } else if ( typeof module == 'object' && module.exports ) {
|
1348 |
|
1349 | module.exports = factory(
|
1350 | window,
|
1351 | require('ev-emitter'),
|
1352 | require('get-size'),
|
1353 | require('fizzy-ui-utils'),
|
1354 | require('./item')
|
1355 | );
|
1356 | } else {
|
1357 |
|
1358 | window.Outlayer = factory(
|
1359 | window,
|
1360 | window.EvEmitter,
|
1361 | window.getSize,
|
1362 | window.fizzyUIUtils,
|
1363 | window.Outlayer.Item
|
1364 | );
|
1365 | }
|
1366 |
|
1367 | }( window, function factory( window, EvEmitter, getSize, utils, Item ) {
|
1368 | 'use strict';
|
1369 |
|
1370 |
|
1371 |
|
1372 | var console = window.console;
|
1373 | var jQuery = window.jQuery;
|
1374 | var noop = function() {};
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 | var GUID = 0;
|
1380 |
|
1381 | var instances = {};
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 | function Outlayer( element, options ) {
|
1390 | var queryElement = utils.getQueryElement( element );
|
1391 | if ( !queryElement ) {
|
1392 | if ( console ) {
|
1393 | console.error( 'Bad element for ' + this.constructor.namespace +
|
1394 | ': ' + ( queryElement || element ) );
|
1395 | }
|
1396 | return;
|
1397 | }
|
1398 | this.element = queryElement;
|
1399 |
|
1400 | if ( jQuery ) {
|
1401 | this.$element = jQuery( this.element );
|
1402 | }
|
1403 |
|
1404 |
|
1405 | this.options = utils.extend( {}, this.constructor.defaults );
|
1406 | this.option( options );
|
1407 |
|
1408 |
|
1409 | var id = ++GUID;
|
1410 | this.element.outlayerGUID = id;
|
1411 | instances[ id ] = this;
|
1412 |
|
1413 |
|
1414 | this._create();
|
1415 |
|
1416 | var isInitLayout = this._getOption('initLayout');
|
1417 | if ( isInitLayout ) {
|
1418 | this.layout();
|
1419 | }
|
1420 | }
|
1421 |
|
1422 |
|
1423 | Outlayer.namespace = 'outlayer';
|
1424 | Outlayer.Item = Item;
|
1425 |
|
1426 |
|
1427 | Outlayer.defaults = {
|
1428 | containerStyle: {
|
1429 | position: 'relative'
|
1430 | },
|
1431 | initLayout: true,
|
1432 | originLeft: true,
|
1433 | originTop: true,
|
1434 | resize: true,
|
1435 | resizeContainer: true,
|
1436 |
|
1437 | transitionDuration: '0.4s',
|
1438 | hiddenStyle: {
|
1439 | opacity: 0,
|
1440 | transform: 'scale(0.001)'
|
1441 | },
|
1442 | visibleStyle: {
|
1443 | opacity: 1,
|
1444 | transform: 'scale(1)'
|
1445 | }
|
1446 | };
|
1447 |
|
1448 | var proto = Outlayer.prototype;
|
1449 |
|
1450 | utils.extend( proto, EvEmitter.prototype );
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 | proto.option = function( opts ) {
|
1457 | utils.extend( this.options, opts );
|
1458 | };
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 | proto._getOption = function( option ) {
|
1464 | var oldOption = this.constructor.compatOptions[ option ];
|
1465 | return oldOption && this.options[ oldOption ] !== undefined ?
|
1466 | this.options[ oldOption ] : this.options[ option ];
|
1467 | };
|
1468 |
|
1469 | Outlayer.compatOptions = {
|
1470 |
|
1471 | initLayout: 'isInitLayout',
|
1472 | horizontal: 'isHorizontal',
|
1473 | layoutInstant: 'isLayoutInstant',
|
1474 | originLeft: 'isOriginLeft',
|
1475 | originTop: 'isOriginTop',
|
1476 | resize: 'isResizeBound',
|
1477 | resizeContainer: 'isResizingContainer'
|
1478 | };
|
1479 |
|
1480 | proto._create = function() {
|
1481 |
|
1482 | this.reloadItems();
|
1483 |
|
1484 | this.stamps = [];
|
1485 | this.stamp( this.options.stamp );
|
1486 |
|
1487 | utils.extend( this.element.style, this.options.containerStyle );
|
1488 |
|
1489 |
|
1490 | var canBindResize = this._getOption('resize');
|
1491 | if ( canBindResize ) {
|
1492 | this.bindResize();
|
1493 | }
|
1494 | };
|
1495 |
|
1496 |
|
1497 | proto.reloadItems = function() {
|
1498 |
|
1499 | this.items = this._itemize( this.element.children );
|
1500 | };
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 | proto._itemize = function( elems ) {
|
1509 |
|
1510 | var itemElems = this._filterFindItemElements( elems );
|
1511 | var Item = this.constructor.Item;
|
1512 |
|
1513 |
|
1514 | var items = [];
|
1515 | for ( var i=0; i < itemElems.length; i++ ) {
|
1516 | var elem = itemElems[i];
|
1517 | var item = new Item( elem, this );
|
1518 | items.push( item );
|
1519 | }
|
1520 |
|
1521 | return items;
|
1522 | };
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 | proto._filterFindItemElements = function( elems ) {
|
1530 | return utils.filterFindElements( elems, this.options.itemSelector );
|
1531 | };
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 | proto.getItemElements = function() {
|
1538 | return this.items.map( function( item ) {
|
1539 | return item.element;
|
1540 | });
|
1541 | };
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 | proto.layout = function() {
|
1549 | this._resetLayout();
|
1550 | this._manageStamps();
|
1551 |
|
1552 |
|
1553 | var layoutInstant = this._getOption('layoutInstant');
|
1554 | var isInstant = layoutInstant !== undefined ?
|
1555 | layoutInstant : !this._isLayoutInited;
|
1556 | this.layoutItems( this.items, isInstant );
|
1557 |
|
1558 |
|
1559 | this._isLayoutInited = true;
|
1560 | };
|
1561 |
|
1562 |
|
1563 | proto._init = proto.layout;
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 | proto._resetLayout = function() {
|
1569 | this.getSize();
|
1570 | };
|
1571 |
|
1572 |
|
1573 | proto.getSize = function() {
|
1574 | this.size = getSize( this.element );
|
1575 | };
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 | proto._getMeasurement = function( measurement, size ) {
|
1588 | var option = this.options[ measurement ];
|
1589 | var elem;
|
1590 | if ( !option ) {
|
1591 |
|
1592 | this[ measurement ] = 0;
|
1593 | } else {
|
1594 |
|
1595 | if ( typeof option == 'string' ) {
|
1596 | elem = this.element.querySelector( option );
|
1597 | } else if ( option instanceof HTMLElement ) {
|
1598 | elem = option;
|
1599 | }
|
1600 |
|
1601 | this[ measurement ] = elem ? getSize( elem )[ size ] : option;
|
1602 | }
|
1603 | };
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 | proto.layoutItems = function( items, isInstant ) {
|
1610 | items = this._getItemsForLayout( items );
|
1611 |
|
1612 | this._layoutItems( items, isInstant );
|
1613 |
|
1614 | this._postLayout();
|
1615 | };
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 | proto._getItemsForLayout = function( items ) {
|
1624 | return items.filter( function( item ) {
|
1625 | return !item.isIgnored;
|
1626 | });
|
1627 | };
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 | proto._layoutItems = function( items, isInstant ) {
|
1635 | this._emitCompleteOnItems( 'layout', items );
|
1636 |
|
1637 | if ( !items || !items.length ) {
|
1638 |
|
1639 | return;
|
1640 | }
|
1641 |
|
1642 | var queue = [];
|
1643 |
|
1644 | items.forEach( function( item ) {
|
1645 |
|
1646 | var position = this._getItemLayoutPosition( item );
|
1647 |
|
1648 | position.item = item;
|
1649 | position.isInstant = isInstant || item.isLayoutInstant;
|
1650 | queue.push( position );
|
1651 | }, this );
|
1652 |
|
1653 | this._processLayoutQueue( queue );
|
1654 | };
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 | proto._getItemLayoutPosition = function( /* item */ ) {
|
1662 | return {
|
1663 | x: 0,
|
1664 | y: 0
|
1665 | };
|
1666 | };
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 | proto._processLayoutQueue = function( queue ) {
|
1675 | this.updateStagger();
|
1676 | queue.forEach( function( obj, i ) {
|
1677 | this._positionItem( obj.item, obj.x, obj.y, obj.isInstant, i );
|
1678 | }, this );
|
1679 | };
|
1680 |
|
1681 |
|
1682 | proto.updateStagger = function() {
|
1683 | var stagger = this.options.stagger;
|
1684 | if ( stagger === null || stagger === undefined ) {
|
1685 | this.stagger = 0;
|
1686 | return;
|
1687 | }
|
1688 | this.stagger = getMilliseconds( stagger );
|
1689 | return this.stagger;
|
1690 | };
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 | proto._positionItem = function( item, x, y, isInstant, i ) {
|
1700 | if ( isInstant ) {
|
1701 |
|
1702 | item.goTo( x, y );
|
1703 | } else {
|
1704 | item.stagger( i * this.stagger );
|
1705 | item.moveTo( x, y );
|
1706 | }
|
1707 | };
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 | proto._postLayout = function() {
|
1714 | this.resizeContainer();
|
1715 | };
|
1716 |
|
1717 | proto.resizeContainer = function() {
|
1718 | var isResizingContainer = this._getOption('resizeContainer');
|
1719 | if ( !isResizingContainer ) {
|
1720 | return;
|
1721 | }
|
1722 | var size = this._getContainerSize();
|
1723 | if ( size ) {
|
1724 | this._setContainerMeasure( size.width, true );
|
1725 | this._setContainerMeasure( size.height, false );
|
1726 | }
|
1727 | };
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 | proto._getContainerSize = noop;
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 | proto._setContainerMeasure = function( measure, isWidth ) {
|
1742 | if ( measure === undefined ) {
|
1743 | return;
|
1744 | }
|
1745 |
|
1746 | var elemSize = this.size;
|
1747 |
|
1748 | if ( elemSize.isBorderBox ) {
|
1749 | measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
|
1750 | elemSize.borderLeftWidth + elemSize.borderRightWidth :
|
1751 | elemSize.paddingBottom + elemSize.paddingTop +
|
1752 | elemSize.borderTopWidth + elemSize.borderBottomWidth;
|
1753 | }
|
1754 |
|
1755 | measure = Math.max( measure, 0 );
|
1756 | this.element.style[ isWidth ? 'width' : 'height' ] = measure + 'px';
|
1757 | };
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 | proto._emitCompleteOnItems = function( eventName, items ) {
|
1765 | var _this = this;
|
1766 | function onComplete() {
|
1767 | _this.dispatchEvent( eventName + 'Complete', null, [ items ] );
|
1768 | }
|
1769 |
|
1770 | var count = items.length;
|
1771 | if ( !items || !count ) {
|
1772 | onComplete();
|
1773 | return;
|
1774 | }
|
1775 |
|
1776 | var doneCount = 0;
|
1777 | function tick() {
|
1778 | doneCount++;
|
1779 | if ( doneCount == count ) {
|
1780 | onComplete();
|
1781 | }
|
1782 | }
|
1783 |
|
1784 |
|
1785 | items.forEach( function( item ) {
|
1786 | item.once( eventName, tick );
|
1787 | });
|
1788 | };
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 | proto.dispatchEvent = function( type, event, args ) {
|
1797 |
|
1798 | var emitArgs = event ? [ event ].concat( args ) : args;
|
1799 | this.emitEvent( type, emitArgs );
|
1800 |
|
1801 | if ( jQuery ) {
|
1802 |
|
1803 | this.$element = this.$element || jQuery( this.element );
|
1804 | if ( event ) {
|
1805 |
|
1806 | var $event = jQuery.Event( event );
|
1807 | $event.type = type;
|
1808 | this.$element.trigger( $event, args );
|
1809 | } else {
|
1810 |
|
1811 | this.$element.trigger( type, args );
|
1812 | }
|
1813 | }
|
1814 | };
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 | proto.ignore = function( elem ) {
|
1825 | var item = this.getItem( elem );
|
1826 | if ( item ) {
|
1827 | item.isIgnored = true;
|
1828 | }
|
1829 | };
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 | proto.unignore = function( elem ) {
|
1836 | var item = this.getItem( elem );
|
1837 | if ( item ) {
|
1838 | delete item.isIgnored;
|
1839 | }
|
1840 | };
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 | proto.stamp = function( elems ) {
|
1847 | elems = this._find( elems );
|
1848 | if ( !elems ) {
|
1849 | return;
|
1850 | }
|
1851 |
|
1852 | this.stamps = this.stamps.concat( elems );
|
1853 |
|
1854 | elems.forEach( this.ignore, this );
|
1855 | };
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 | proto.unstamp = function( elems ) {
|
1862 | elems = this._find( elems );
|
1863 | if ( !elems ){
|
1864 | return;
|
1865 | }
|
1866 |
|
1867 | elems.forEach( function( elem ) {
|
1868 |
|
1869 | utils.removeFrom( this.stamps, elem );
|
1870 | this.unignore( elem );
|
1871 | }, this );
|
1872 | };
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 | proto._find = function( elems ) {
|
1880 | if ( !elems ) {
|
1881 | return;
|
1882 | }
|
1883 |
|
1884 | if ( typeof elems == 'string' ) {
|
1885 | elems = this.element.querySelectorAll( elems );
|
1886 | }
|
1887 | elems = utils.makeArray( elems );
|
1888 | return elems;
|
1889 | };
|
1890 |
|
1891 | proto._manageStamps = function() {
|
1892 | if ( !this.stamps || !this.stamps.length ) {
|
1893 | return;
|
1894 | }
|
1895 |
|
1896 | this._getBoundingRect();
|
1897 |
|
1898 | this.stamps.forEach( this._manageStamp, this );
|
1899 | };
|
1900 |
|
1901 |
|
1902 | proto._getBoundingRect = function() {
|
1903 |
|
1904 | var boundingRect = this.element.getBoundingClientRect();
|
1905 | var size = this.size;
|
1906 | this._boundingRect = {
|
1907 | left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
|
1908 | top: boundingRect.top + size.paddingTop + size.borderTopWidth,
|
1909 | right: boundingRect.right - ( size.paddingRight + size.borderRightWidth ),
|
1910 | bottom: boundingRect.bottom - ( size.paddingBottom + size.borderBottomWidth )
|
1911 | };
|
1912 | };
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 | proto._manageStamp = noop;
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 | proto._getElementOffset = function( elem ) {
|
1925 | var boundingRect = elem.getBoundingClientRect();
|
1926 | var thisRect = this._boundingRect;
|
1927 | var size = getSize( elem );
|
1928 | var offset = {
|
1929 | left: boundingRect.left - thisRect.left - size.marginLeft,
|
1930 | top: boundingRect.top - thisRect.top - size.marginTop,
|
1931 | right: thisRect.right - boundingRect.right - size.marginRight,
|
1932 | bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
|
1933 | };
|
1934 | return offset;
|
1935 | };
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 | proto.handleEvent = utils.handleEvent;
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 | proto.bindResize = function() {
|
1947 | window.addEventListener( 'resize', this );
|
1948 | this.isResizeBound = true;
|
1949 | };
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 | proto.unbindResize = function() {
|
1955 | window.removeEventListener( 'resize', this );
|
1956 | this.isResizeBound = false;
|
1957 | };
|
1958 |
|
1959 | proto.onresize = function() {
|
1960 | this.resize();
|
1961 | };
|
1962 |
|
1963 | utils.debounceMethod( Outlayer, 'onresize', 100 );
|
1964 |
|
1965 | proto.resize = function() {
|
1966 |
|
1967 |
|
1968 | if ( !this.isResizeBound || !this.needsResizeLayout() ) {
|
1969 | return;
|
1970 | }
|
1971 |
|
1972 | this.layout();
|
1973 | };
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 | proto.needsResizeLayout = function() {
|
1980 | var size = getSize( this.element );
|
1981 |
|
1982 |
|
1983 | var hasSizes = this.size && size;
|
1984 | return hasSizes && size.innerWidth !== this.size.innerWidth;
|
1985 | };
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 | proto.addItems = function( elems ) {
|
1995 | var items = this._itemize( elems );
|
1996 |
|
1997 | if ( items.length ) {
|
1998 | this.items = this.items.concat( items );
|
1999 | }
|
2000 | return items;
|
2001 | };
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 | proto.appended = function( elems ) {
|
2008 | var items = this.addItems( elems );
|
2009 | if ( !items.length ) {
|
2010 | return;
|
2011 | }
|
2012 |
|
2013 | this.layoutItems( items, true );
|
2014 | this.reveal( items );
|
2015 | };
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | proto.prepended = function( elems ) {
|
2022 | var items = this._itemize( elems );
|
2023 | if ( !items.length ) {
|
2024 | return;
|
2025 | }
|
2026 |
|
2027 | var previousItems = this.items.slice(0);
|
2028 | this.items = items.concat( previousItems );
|
2029 |
|
2030 | this._resetLayout();
|
2031 | this._manageStamps();
|
2032 |
|
2033 | this.layoutItems( items, true );
|
2034 | this.reveal( items );
|
2035 |
|
2036 | this.layoutItems( previousItems );
|
2037 | };
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 | proto.reveal = function( items ) {
|
2044 | this._emitCompleteOnItems( 'reveal', items );
|
2045 | if ( !items || !items.length ) {
|
2046 | return;
|
2047 | }
|
2048 | var stagger = this.updateStagger();
|
2049 | items.forEach( function( item, i ) {
|
2050 | item.stagger( i * stagger );
|
2051 | item.reveal();
|
2052 | });
|
2053 | };
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 | proto.hide = function( items ) {
|
2060 | this._emitCompleteOnItems( 'hide', items );
|
2061 | if ( !items || !items.length ) {
|
2062 | return;
|
2063 | }
|
2064 | var stagger = this.updateStagger();
|
2065 | items.forEach( function( item, i ) {
|
2066 | item.stagger( i * stagger );
|
2067 | item.hide();
|
2068 | });
|
2069 | };
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 | proto.revealItemElements = function( elems ) {
|
2076 | var items = this.getItems( elems );
|
2077 | this.reveal( items );
|
2078 | };
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 | proto.hideItemElements = function( elems ) {
|
2085 | var items = this.getItems( elems );
|
2086 | this.hide( items );
|
2087 | };
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 | proto.getItem = function( elem ) {
|
2096 |
|
2097 | for ( var i=0; i < this.items.length; i++ ) {
|
2098 | var item = this.items[i];
|
2099 | if ( item.element == elem ) {
|
2100 |
|
2101 | return item;
|
2102 | }
|
2103 | }
|
2104 | };
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 | proto.getItems = function( elems ) {
|
2112 | elems = utils.makeArray( elems );
|
2113 | var items = [];
|
2114 | elems.forEach( function( elem ) {
|
2115 | var item = this.getItem( elem );
|
2116 | if ( item ) {
|
2117 | items.push( item );
|
2118 | }
|
2119 | }, this );
|
2120 |
|
2121 | return items;
|
2122 | };
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 | proto.remove = function( elems ) {
|
2129 | var removeItems = this.getItems( elems );
|
2130 |
|
2131 | this._emitCompleteOnItems( 'remove', removeItems );
|
2132 |
|
2133 |
|
2134 | if ( !removeItems || !removeItems.length ) {
|
2135 | return;
|
2136 | }
|
2137 |
|
2138 | removeItems.forEach( function( item ) {
|
2139 | item.remove();
|
2140 |
|
2141 | utils.removeFrom( this.items, item );
|
2142 | }, this );
|
2143 | };
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 | proto.destroy = function() {
|
2149 |
|
2150 | var style = this.element.style;
|
2151 | style.height = '';
|
2152 | style.position = '';
|
2153 | style.width = '';
|
2154 |
|
2155 | this.items.forEach( function( item ) {
|
2156 | item.destroy();
|
2157 | });
|
2158 |
|
2159 | this.unbindResize();
|
2160 |
|
2161 | var id = this.element.outlayerGUID;
|
2162 | delete instances[ id ];
|
2163 | delete this.element.outlayerGUID;
|
2164 |
|
2165 | if ( jQuery ) {
|
2166 | jQuery.removeData( this.element, this.constructor.namespace );
|
2167 | }
|
2168 |
|
2169 | };
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 | Outlayer.data = function( elem ) {
|
2179 | elem = utils.getQueryElement( elem );
|
2180 | var id = elem && elem.outlayerGUID;
|
2181 | return id && instances[ id ];
|
2182 | };
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 | Outlayer.create = function( namespace, options ) {
|
2192 |
|
2193 | var Layout = subclass( Outlayer );
|
2194 |
|
2195 | Layout.defaults = utils.extend( {}, Outlayer.defaults );
|
2196 | utils.extend( Layout.defaults, options );
|
2197 | Layout.compatOptions = utils.extend( {}, Outlayer.compatOptions );
|
2198 |
|
2199 | Layout.namespace = namespace;
|
2200 |
|
2201 | Layout.data = Outlayer.data;
|
2202 |
|
2203 |
|
2204 | Layout.Item = subclass( Item );
|
2205 |
|
2206 |
|
2207 |
|
2208 | utils.htmlInit( Layout, namespace );
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 | if ( jQuery && jQuery.bridget ) {
|
2214 | jQuery.bridget( namespace, Layout );
|
2215 | }
|
2216 |
|
2217 | return Layout;
|
2218 | };
|
2219 |
|
2220 | function subclass( Parent ) {
|
2221 | function SubClass() {
|
2222 | Parent.apply( this, arguments );
|
2223 | }
|
2224 |
|
2225 | SubClass.prototype = Object.create( Parent.prototype );
|
2226 | SubClass.prototype.constructor = SubClass;
|
2227 |
|
2228 | return SubClass;
|
2229 | }
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 | var msUnits = {
|
2235 | ms: 1,
|
2236 | s: 1000
|
2237 | };
|
2238 |
|
2239 |
|
2240 |
|
2241 | function getMilliseconds( time ) {
|
2242 | if ( typeof time == 'number' ) {
|
2243 | return time;
|
2244 | }
|
2245 | var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
|
2246 | var num = matches && matches[1];
|
2247 | var unit = matches && matches[2];
|
2248 | if ( !num.length ) {
|
2249 | return 0;
|
2250 | }
|
2251 | num = parseFloat( num );
|
2252 | var mult = msUnits[ unit ] || 1;
|
2253 | return num * mult;
|
2254 | }
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | Outlayer.Item = Item;
|
2260 |
|
2261 | return Outlayer;
|
2262 |
|
2263 | }));
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 | ( function( window, factory ) {
|
2274 |
|
2275 |
|
2276 | if ( typeof define == 'function' && define.amd ) {
|
2277 |
|
2278 | define( [
|
2279 | 'outlayer/outlayer',
|
2280 | 'get-size/get-size'
|
2281 | ],
|
2282 | factory );
|
2283 | } else if ( typeof module == 'object' && module.exports ) {
|
2284 |
|
2285 | module.exports = factory(
|
2286 | require('outlayer'),
|
2287 | require('get-size')
|
2288 | );
|
2289 | } else {
|
2290 |
|
2291 | window.Masonry = factory(
|
2292 | window.Outlayer,
|
2293 | window.getSize
|
2294 | );
|
2295 | }
|
2296 |
|
2297 | }( window, function factory( Outlayer, getSize ) {
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 | var Masonry = Outlayer.create('masonry');
|
2305 |
|
2306 | Masonry.compatOptions.fitWidth = 'isFitWidth';
|
2307 |
|
2308 | var proto = Masonry.prototype;
|
2309 |
|
2310 | proto._resetLayout = function() {
|
2311 | this.getSize();
|
2312 | this._getMeasurement( 'columnWidth', 'outerWidth' );
|
2313 | this._getMeasurement( 'gutter', 'outerWidth' );
|
2314 | this.measureColumns();
|
2315 |
|
2316 |
|
2317 | this.colYs = [];
|
2318 | for ( var i=0; i < this.cols; i++ ) {
|
2319 | this.colYs.push( 0 );
|
2320 | }
|
2321 |
|
2322 | this.maxY = 0;
|
2323 | this.horizontalColIndex = 0;
|
2324 | };
|
2325 |
|
2326 | proto.measureColumns = function() {
|
2327 | this.getContainerWidth();
|
2328 |
|
2329 | if ( !this.columnWidth ) {
|
2330 | var firstItem = this.items[0];
|
2331 | var firstItemElem = firstItem && firstItem.element;
|
2332 |
|
2333 | this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
|
2334 |
|
2335 | this.containerWidth;
|
2336 | }
|
2337 |
|
2338 | var columnWidth = this.columnWidth += this.gutter;
|
2339 |
|
2340 |
|
2341 | var containerWidth = this.containerWidth + this.gutter;
|
2342 | var cols = containerWidth / columnWidth;
|
2343 |
|
2344 | var excess = columnWidth - containerWidth % columnWidth;
|
2345 |
|
2346 | var mathMethod = excess && excess < 1 ? 'round' : 'floor';
|
2347 | cols = Math[ mathMethod ]( cols );
|
2348 | this.cols = Math.max( cols, 1 );
|
2349 | };
|
2350 |
|
2351 | proto.getContainerWidth = function() {
|
2352 |
|
2353 | var isFitWidth = this._getOption('fitWidth');
|
2354 | var container = isFitWidth ? this.element.parentNode : this.element;
|
2355 |
|
2356 |
|
2357 | var size = getSize( container );
|
2358 | this.containerWidth = size && size.innerWidth;
|
2359 | };
|
2360 |
|
2361 | proto._getItemLayoutPosition = function( item ) {
|
2362 | item.getSize();
|
2363 |
|
2364 | var remainder = item.size.outerWidth % this.columnWidth;
|
2365 | var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
|
2366 |
|
2367 | var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
|
2368 | colSpan = Math.min( colSpan, this.cols );
|
2369 |
|
2370 | var colPosMethod = this.options.horizontalOrder ?
|
2371 | '_getHorizontalColPosition' : '_getTopColPosition';
|
2372 | var colPosition = this[ colPosMethod ]( colSpan, item );
|
2373 |
|
2374 | var position = {
|
2375 | x: this.columnWidth * colPosition.col,
|
2376 | y: colPosition.y
|
2377 | };
|
2378 |
|
2379 | var setHeight = colPosition.y + item.size.outerHeight;
|
2380 | var setMax = colSpan + colPosition.col;
|
2381 | for ( var i = colPosition.col; i < setMax; i++ ) {
|
2382 | this.colYs[i] = setHeight;
|
2383 | }
|
2384 |
|
2385 | return position;
|
2386 | };
|
2387 |
|
2388 | proto._getTopColPosition = function( colSpan ) {
|
2389 | var colGroup = this._getTopColGroup( colSpan );
|
2390 |
|
2391 | var minimumY = Math.min.apply( Math, colGroup );
|
2392 |
|
2393 | return {
|
2394 | col: colGroup.indexOf( minimumY ),
|
2395 | y: minimumY,
|
2396 | };
|
2397 | };
|
2398 |
|
2399 | |
2400 |
|
2401 |
|
2402 |
|
2403 | proto._getTopColGroup = function( colSpan ) {
|
2404 | if ( colSpan < 2 ) {
|
2405 |
|
2406 | return this.colYs;
|
2407 | }
|
2408 |
|
2409 | var colGroup = [];
|
2410 |
|
2411 | var groupCount = this.cols + 1 - colSpan;
|
2412 |
|
2413 | for ( var i = 0; i < groupCount; i++ ) {
|
2414 | colGroup[i] = this._getColGroupY( i, colSpan );
|
2415 | }
|
2416 | return colGroup;
|
2417 | };
|
2418 |
|
2419 | proto._getColGroupY = function( col, colSpan ) {
|
2420 | if ( colSpan < 2 ) {
|
2421 | return this.colYs[ col ];
|
2422 | }
|
2423 |
|
2424 | var groupColYs = this.colYs.slice( col, col + colSpan );
|
2425 |
|
2426 | return Math.max.apply( Math, groupColYs );
|
2427 | };
|
2428 |
|
2429 |
|
2430 | proto._getHorizontalColPosition = function( colSpan, item ) {
|
2431 | var col = this.horizontalColIndex % this.cols;
|
2432 | var isOver = colSpan > 1 && col + colSpan > this.cols;
|
2433 |
|
2434 | col = isOver ? 0 : col;
|
2435 |
|
2436 | var hasSize = item.size.outerWidth && item.size.outerHeight;
|
2437 | this.horizontalColIndex = hasSize ? col + colSpan : this.horizontalColIndex;
|
2438 |
|
2439 | return {
|
2440 | col: col,
|
2441 | y: this._getColGroupY( col, colSpan ),
|
2442 | };
|
2443 | };
|
2444 |
|
2445 | proto._manageStamp = function( stamp ) {
|
2446 | var stampSize = getSize( stamp );
|
2447 | var offset = this._getElementOffset( stamp );
|
2448 |
|
2449 | var isOriginLeft = this._getOption('originLeft');
|
2450 | var firstX = isOriginLeft ? offset.left : offset.right;
|
2451 | var lastX = firstX + stampSize.outerWidth;
|
2452 | var firstCol = Math.floor( firstX / this.columnWidth );
|
2453 | firstCol = Math.max( 0, firstCol );
|
2454 | var lastCol = Math.floor( lastX / this.columnWidth );
|
2455 |
|
2456 | lastCol -= lastX % this.columnWidth ? 0 : 1;
|
2457 | lastCol = Math.min( this.cols - 1, lastCol );
|
2458 |
|
2459 |
|
2460 | var isOriginTop = this._getOption('originTop');
|
2461 | var stampMaxY = ( isOriginTop ? offset.top : offset.bottom ) +
|
2462 | stampSize.outerHeight;
|
2463 | for ( var i = firstCol; i <= lastCol; i++ ) {
|
2464 | this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
|
2465 | }
|
2466 | };
|
2467 |
|
2468 | proto._getContainerSize = function() {
|
2469 | this.maxY = Math.max.apply( Math, this.colYs );
|
2470 | var size = {
|
2471 | height: this.maxY
|
2472 | };
|
2473 |
|
2474 | if ( this._getOption('fitWidth') ) {
|
2475 | size.width = this._getContainerFitWidth();
|
2476 | }
|
2477 |
|
2478 | return size;
|
2479 | };
|
2480 |
|
2481 | proto._getContainerFitWidth = function() {
|
2482 | var unusedCols = 0;
|
2483 |
|
2484 | var i = this.cols;
|
2485 | while ( --i ) {
|
2486 | if ( this.colYs[i] !== 0 ) {
|
2487 | break;
|
2488 | }
|
2489 | unusedCols++;
|
2490 | }
|
2491 |
|
2492 | return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
|
2493 | };
|
2494 |
|
2495 | proto.needsResizeLayout = function() {
|
2496 | var previousWidth = this.containerWidth;
|
2497 | this.getContainerWidth();
|
2498 | return previousWidth != this.containerWidth;
|
2499 | };
|
2500 |
|
2501 | return Masonry;
|
2502 |
|
2503 | }));
|
2504 |
|