1/*! 2 * Packery layout mode PACKAGED v1.1.3 3 * sub-classes Packery 4 * http://packery.metafizzy.co 5 */ 6 7/*! 8 * classie v1.0.1 9 * class helper functions 10 * from bonzo https://github.com/ded/bonzo 11 * MIT license 12 * 13 * classie.has( elem, 'my-class' ) -> true/false 14 * classie.add( elem, 'my-new-class' ) 15 * classie.remove( elem, 'my-unwanted-class' ) 16 * classie.toggle( elem, 'my-class' ) 17 */ 18 19/*jshint browser: true, strict: true, undef: true, unused: true */ 20/*global define: false, module: false */ 21 22( function( window ) { 23 24 25 26// class helper functions from bonzo https://github.com/ded/bonzo 27 28 function classReg( className ) { 29 return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); 30 } 31 32// classList support for class management 33// altho to be fair, the api sucks because it won't accept multiple classes at once 34 var hasClass, addClass, removeClass; 35 36 if ( 'classList' in document.documentElement ) { 37 hasClass = function( elem, c ) { 38 return elem.classList.contains( c ); 39 }; 40 addClass = function( elem, c ) { 41 elem.classList.add( c ); 42 }; 43 removeClass = function( elem, c ) { 44 elem.classList.remove( c ); 45 }; 46 } 47 else { 48 hasClass = function( elem, c ) { 49 return classReg( c ).test( elem.className ); 50 }; 51 addClass = function( elem, c ) { 52 if ( !hasClass( elem, c ) ) { 53 elem.className = elem.className + ' ' + c; 54 } 55 }; 56 removeClass = function( elem, c ) { 57 elem.className = elem.className.replace( classReg( c ), ' ' ); 58 }; 59 } 60 61 function toggleClass( elem, c ) { 62 var fn = hasClass( elem, c ) ? removeClass : addClass; 63 fn( elem, c ); 64 } 65 66 var classie = { 67 // full names 68 hasClass: hasClass, 69 addClass: addClass, 70 removeClass: removeClass, 71 toggleClass: toggleClass, 72 // short names 73 has: hasClass, 74 add: addClass, 75 remove: removeClass, 76 toggle: toggleClass 77 }; 78 79// transport 80 if ( typeof define === 'function' && define.amd ) { 81 // AMD 82 define( 'classie/classie',classie ); 83 } else if ( typeof exports === 'object' ) { 84 // CommonJS 85 module.exports = classie; 86 } else { 87 // browser global 88 window.classie = classie; 89 } 90 91})( window ); 92 93/** 94 * Rect 95 * low-level utility class for basic geometry 96 */ 97 98( function( window, factory ) { 99 100 // universal module definition 101 if ( typeof define == 'function' && define.amd ) { 102 // AMD 103 define( 'packery/js/rect',factory ); 104 } else if ( typeof exports == 'object' ) { 105 // CommonJS 106 module.exports = factory(); 107 } else { 108 // browser global 109 window.Packery = window.Packery || {}; 110 window.Packery.Rect = factory(); 111 } 112 113}( window, function factory() { 114 115 116// -------------------------- Packery -------------------------- // 117 118// global namespace 119 var Packery = window.Packery = function() {}; 120 121// -------------------------- Rect -------------------------- // 122 123 function Rect( props ) { 124 // extend properties from defaults 125 for ( var prop in Rect.defaults ) { 126 this[ prop ] = Rect.defaults[ prop ]; 127 } 128 129 for ( prop in props ) { 130 this[ prop ] = props[ prop ]; 131 } 132 133 } 134 135// make available 136 Packery.Rect = Rect; 137 138 Rect.defaults = { 139 x: 0, 140 y: 0, 141 width: 0, 142 height: 0 143 }; 144 145 /** 146 * Determines whether or not this rectangle wholly encloses another rectangle or point. 147 * @param {Rect} rect 148 * @returns {Boolean} 149 **/ 150 Rect.prototype.contains = function( rect ) { 151 // points don't have width or height 152 var otherWidth = rect.width || 0; 153 var otherHeight = rect.height || 0; 154 return this.x <= rect.x && 155 this.y <= rect.y && 156 this.x + this.width >= rect.x + otherWidth && 157 this.y + this.height >= rect.y + otherHeight; 158 }; 159 160 /** 161 * Determines whether or not the rectangle intersects with another. 162 * @param {Rect} rect 163 * @returns {Boolean} 164 **/ 165 Rect.prototype.overlaps = function( rect ) { 166 var thisRight = this.x + this.width; 167 var thisBottom = this.y + this.height; 168 var rectRight = rect.x + rect.width; 169 var rectBottom = rect.y + rect.height; 170 171 // http://stackoverflow.com/a/306332 172 return this.x < rectRight && 173 thisRight > rect.x && 174 this.y < rectBottom && 175 thisBottom > rect.y; 176 }; 177 178 /** 179 * @param {Rect} rect - the overlapping rect 180 * @returns {Array} freeRects - rects representing the area around the rect 181 **/ 182 Rect.prototype.getMaximalFreeRects = function( rect ) { 183 184 // if no intersection, return false 185 if ( !this.overlaps( rect ) ) { 186 return false;
vendor: 4,293 bytes, lines 187-348
187 } 188 189 var freeRects = []; 190 var freeRect; 191 192 var thisRight = this.x + this.width; 193 var thisBottom = this.y + this.height; 194 var rectRight = rect.x + rect.width; 195 var rectBottom = rect.y + rect.height; 196 197 // top 198 if ( this.y < rect.y ) { 199 freeRect = new Rect({ 200 x: this.x, 201 y: this.y, 202 width: this.width, 203 height: rect.y - this.y 204 }); 205 freeRects.push( freeRect ); 206 } 207 208 // right 209 if ( thisRight > rectRight ) { 210 freeRect = new Rect({ 211 x: rectRight, 212 y: this.y, 213 width: thisRight - rectRight, 214 height: this.height 215 }); 216 freeRects.push( freeRect ); 217 } 218 219 // bottom 220 if ( thisBottom > rectBottom ) { 221 freeRect = new Rect({ 222 x: this.x, 223 y: rectBottom, 224 width: this.width, 225 height: thisBottom - rectBottom 226 }); 227 freeRects.push( freeRect ); 228 } 229 230 // left 231 if ( this.x < rect.x ) { 232 freeRect = new Rect({ 233 x: this.x, 234 y: this.y, 235 width: rect.x - this.x, 236 height: this.height 237 }); 238 freeRects.push( freeRect ); 239 } 240 241 return freeRects; 242 }; 243 244 Rect.prototype.canFit = function( rect ) { 245 return this.width >= rect.width && this.height >= rect.height; 246 }; 247 248 return Rect; 249 250})); 251 252/** 253 * Packer 254 * bin-packing algorithm 255 */ 256 257( function( window, factory ) { 258 259 // universal module definition 260 if ( typeof define == 'function' && define.amd ) { 261 // AMD 262 define( 'packery/js/packer',[ './rect' ], factory ); 263 } else if ( typeof exports == 'object' ) { 264 // CommonJS 265 module.exports = factory( 266 require('./rect') 267 ); 268 } else { 269 // browser global 270 var Packery = window.Packery = window.Packery || {}; 271 Packery.Packer = factory( Packery.Rect ); 272 } 273 274}( window, function factory( Rect ) { 275 276 277// -------------------------- Packer -------------------------- // 278 279 /** 280 * @param {Number} width 281 * @param {Number} height 282 * @param {String} sortDirection 283 * topLeft for vertical, leftTop for horizontal 284 */ 285 function Packer( width, height, sortDirection ) { 286 this.width = width || 0; 287 this.height = height || 0; 288 this.sortDirection = sortDirection || 'downwardLeftToRight'; 289 290 this.reset(); 291 } 292 293 Packer.prototype.reset = function() { 294 this.spaces = []; 295 this.newSpaces = []; 296 297 var initialSpace = new Rect({ 298 x: 0, 299 y: 0, 300 width: this.width, 301 height: this.height 302 }); 303 304 this.spaces.push( initialSpace ); 305 // set sorter 306 this.sorter = sorters[ this.sortDirection ] || sorters.downwardLeftToRight; 307 }; 308 309// change x and y of rect to fit with in Packer's available spaces 310 Packer.prototype.pack = function( rect ) { 311 for ( var i=0, len = this.spaces.length; i < len; i++ ) { 312 var space = this.spaces[i]; 313 if ( space.canFit( rect ) ) { 314 this.placeInSpace( rect, space ); 315 break; 316 } 317 } 318 }; 319 320 Packer.prototype.placeInSpace = function( rect, space ) { 321 // place rect in space 322 rect.x = space.x; 323 rect.y = space.y; 324 325 this.placed( rect ); 326 }; 327 328// update spaces with placed rect 329 Packer.prototype.placed = function( rect ) { 330 // update spaces 331 var revisedSpaces = []; 332 for ( var i=0, len = this.spaces.length; i < len; i++ ) { 333 var space = this.spaces[i]; 334 var newSpaces = space.getMaximalFreeRects( rect ); 335 // add either the original space or the new spaces to the revised spaces 336 if ( newSpaces ) { 337 revisedSpaces.push.apply( revisedSpaces, newSpaces ); 338 } else { 339 revisedSpaces.push( space ); 340 } 341 } 342 343 this.spaces = revisedSpaces; 344 345 this.mergeSortSpaces(); 346 }; 347 348 Packer.prototype.mergeSortSpaces = function() {
349 // remove redundant spaces 350 Packer.mergeRects( this.spaces ); 351 this.spaces.sort( this.sorter ); 352 }; 353 354// add a space back 355 Packer.prototype.addSpace = function( rect ) { 356 this.spaces.push( rect ); 357 this.mergeSortSpaces(); 358 }; 359 360// -------------------------- utility functions -------------------------- // 361 362 /** 363 * Remove redundant rectangle from array of rectangles 364 * @param {Array} rects: an array of Rects 365 * @returns {Array} rects: an array of Rects 366 **/ 367 Packer.mergeRects = function( rects ) { 368 for ( var i=0, len = rects.length; i < len; i++ ) { 369 var rect = rects[i]; 370 // skip over this rect if it was already removed 371 if ( !rect ) { 372 continue; 373 } 374 // clone rects we're testing, remove this rect 375 var compareRects = rects.slice(0); 376 // do not compare with self 377 compareRects.splice( i, 1 ); 378 // compare this rect with others 379 var removedCount = 0; 380 for ( var j=0, jLen = compareRects.length; j < jLen; j++ ) { 381 var compareRect = compareRects[j]; 382 // if this rect contains another, 383 // remove that rect from test collection 384 var indexAdjust = i > j ? 0 : 1; 385 if ( rect.contains( compareRect ) ) { 386 // console.log( 'current test rects:' + testRects.length, testRects ); 387 // console.log( i, j, indexAdjust, rect, compareRect ); 388 rects.splice( j + indexAdjust - removedCount, 1 ); 389 removedCount++; 390 } 391 } 392 } 393 394 return rects; 395 }; 396 397 398// -------------------------- sorters -------------------------- // 399 400// functions for sorting rects in order 401 var sorters = { 402 // top down, then left to right 403 downwardLeftToRight: function( a, b ) { 404 return a.y - b.y || a.x - b.x; 405 }, 406 // left to right, then top down 407 rightwardTopToBottom: function( a, b ) { 408 return a.x - b.x || a.y - b.y; 409 } 410 }; 411 412 413// -------------------------- -------------------------- // 414 415 return Packer; 416 417})); 418/** 419 * Packery Item Element 420 **/ 421 422( function( window, factory ) { 423 424 // universal module definition 425 426 if ( typeof define == 'function' && define.amd ) { 427 // AMD 428 define( 'packery/js/item',[ 429 'get-style-property/get-style-property', 430 'outlayer/outlayer', 431 './rect' 432 ], 433 factory ); 434 } else if ( typeof exports == 'object' ) { 435 // CommonJS 436 module.exports = factory( 437 require('desandro-get-style-property'), 438 require('outlayer'), 439 require('./rect') 440 ); 441 } else { 442 // browser global 443 window.Packery.Item = factory( 444 window.getStyleProperty, 445 window.Outlayer, 446 window.Packery.Rect 447 ); 448 } 449 450}( window, function factory( getStyleProperty, Outlayer, Rect ) { 451 452 453// -------------------------- Item -------------------------- // 454 455 var transformProperty = getStyleProperty('transform'); 456 457// sub-class Item 458 var Item = function PackeryItem() { 459 Outlayer.Item.apply( this, arguments ); 460 }; 461 462 Item.prototype = new Outlayer.Item(); 463 464 var protoCreate = Item.prototype._create; 465 Item.prototype._create = function() { 466 // call default _create logic 467 protoCreate.call( this ); 468 this.rect = new Rect(); 469 // rect used for placing, in drag or Packery.fit() 470 this.placeRect = new Rect(); 471 }; 472 473// -------------------------- drag -------------------------- // 474 475 Item.prototype.dragStart = function() { 476 this.getPosition(); 477 this.removeTransitionStyles(); 478 // remove transform property from transition 479 if ( this.isTransitioning && transformProperty ) { 480 this.element.style[ transformProperty ] = 'none'; 481 }
482 this.getSize(); 483 // create place rect, used for position when dragged then dropped 484 // or when positioning 485 this.isPlacing = true; 486 this.needsPositioning = false; 487 this.positionPlaceRect( this.position.x, this.position.y ); 488 this.isTransitioning = false; 489 this.didDrag = false; 490 }; 491 492 /** 493 * handle item when it is dragged 494 * @param {Number} x - horizontal position of dragged item 495 * @param {Number} y - vertical position of dragged item 496 */ 497 Item.prototype.dragMove = function( x, y ) { 498 this.didDrag = true; 499 var packerySize = this.layout.size; 500 x -= packerySize.paddingLeft; 501 y -= packerySize.paddingTop; 502 this.positionPlaceRect( x, y ); 503 }; 504 505 Item.prototype.dragStop = function() { 506 this.getPosition(); 507 var isDiffX = this.position.x != this.placeRect.x; 508 var isDiffY = this.position.y != this.placeRect.y; 509 // set post-drag positioning flag 510 this.needsPositioning = isDiffX || isDiffY; 511 // reset flag 512 this.didDrag = false; 513 }; 514 515// -------------------------- placing -------------------------- // 516 517 /** 518 * position a rect that will occupy space in the packer 519 * @param {Number} x 520 * @param {Number} y 521 * @param {Boolean} isMaxYContained 522 */ 523 Item.prototype.positionPlaceRect = function( x, y, isMaxYOpen ) { 524 this.placeRect.x = this.getPlaceRectCoord( x, true ); 525 this.placeRect.y = this.getPlaceRectCoord( y, false, isMaxYOpen ); 526 }; 527 528 /** 529 * get x/y coordinate for place rect 530 * @param {Number} coord - x or y 531 * @param {Boolean} isX 532 * @param {Boolean} isMaxOpen - does not limit value to outer bound 533 * @returns {Number} coord - processed x or y 534 */ 535 Item.prototype.getPlaceRectCoord = function( coord, isX, isMaxOpen ) { 536 var measure = isX ? 'Width' : 'Height'; 537 var size = this.size[ 'outer' + measure ]; 538 var segment = this.layout[ isX ? 'columnWidth' : 'rowHeight' ]; 539 var parentSize = this.layout.size[ 'inner' + measure ]; 540 541 // additional parentSize calculations for Y 542 if ( !isX ) { 543 parentSize = Math.max( parentSize, this.layout.maxY ); 544 // prevent gutter from bumping up height when non-vertical grid 545 if ( !this.layout.rowHeight ) { 546 parentSize -= this.layout.gutter; 547 } 548 } 549 550 var max; 551 552 if ( segment ) { 553 segment += this.layout.gutter; 554 // allow for last column to reach the edge 555 parentSize += isX ? this.layout.gutter : 0; 556 // snap to closest segment 557 coord = Math.round( coord / segment ); 558 // contain to outer bound 559 // contain non-growing bound, allow growing bound to grow 560 var mathMethod; 561 if ( this.layout.options.isHorizontal ) { 562 mathMethod = !isX ? 'floor' : 'ceil'; 563 } else { 564 mathMethod = isX ? 'floor' : 'ceil'; 565 } 566 var maxSegments = Math[ mathMethod ]( parentSize / segment ); 567 maxSegments -= Math.ceil( size / segment ); 568 max = maxSegments; 569 } else { 570 max = parentSize - size; 571 } 572
573 coord = isMaxOpen ? coord : Math.min( coord, max ); 574 coord *= segment || 1; 575 576 return Math.max( 0, coord ); 577 }; 578 579 Item.prototype.copyPlaceRectPosition = function() { 580 this.rect.x = this.placeRect.x; 581 this.rect.y = this.placeRect.y; 582 }; 583 584// ----- ----- // 585 586// remove element from DOM 587 Item.prototype.removeElem = function() { 588 this.element.parentNode.removeChild( this.element ); 589 // add space back to packer 590 this.layout.packer.addSpace( this.rect ); 591 this.emitEvent( 'remove', [ this ] ); 592 }; 593 594// ----- ----- // 595 596 return Item; 597 598})); 599 600/*! 601 * Packery v1.4.1 602 * bin-packing layout library 603 * 604 * Licensed GPLv3 for open source use 605 * or Flickity Commercial License for commercial use 606 * 607 * http://packery.metafizzy.co 608 * Copyright 2015 Metafizzy 609 */ 610 611( function( window, factory ) { 612 613 // universal module definition 614 if ( typeof define == 'function' && define.amd ) { 615 // AMD 616 define( 'packery/js/packery',[ 617 'classie/classie', 618 'get-size/get-size', 619 'outlayer/outlayer', 620 './rect', 621 './packer', 622 './item' 623 ], 624 factory ); 625 } else if ( typeof exports == 'object' ) { 626 // CommonJS 627 module.exports = factory( 628 require('desandro-classie'), 629 require('get-size'), 630 require('outlayer'), 631 require('./rect'), 632 require('./packer'), 633 require('./item') 634 ); 635 } else { 636 // browser global 637 window.Packery = factory( 638 window.classie, 639 window.getSize, 640 window.Outlayer, 641 window.Packery.Rect, 642 window.Packery.Packer, 643 window.Packery.Item 644 ); 645 } 646 647}( window, function factory( classie, getSize, Outlayer, Rect, Packer, Item ) { 648 649 650// ----- Rect ----- // 651 652// allow for pixel rounding errors IE8-IE11 & Firefox; #227 653 Rect.prototype.canFit = function( rect ) { 654 return this.width >= rect.width - 1 && this.height >= rect.height - 1; 655 }; 656 657// -------------------------- Packery -------------------------- // 658 659// create an Outlayer layout class 660 var Packery = Outlayer.create('packery'); 661 Packery.Item = Item; 662 663 Packery.prototype._create = function() { 664 // call super 665 Outlayer.prototype._create.call( this ); 666 667 // initial properties 668 this.packer = new Packer(); 669 670 // Left over from v1.0 671 this.stamp( this.options.stamped ); 672 673 // create drag handlers 674 var _this = this; 675 this.handleDraggabilly = { 676 dragStart: function() { 677 _this.itemDragStart( this.element ); 678 }, 679 dragMove: function() { 680 _this.itemDragMove( this.element, this.position.x, this.position.y ); 681 }, 682 dragEnd: function() { 683 _this.itemDragEnd( this.element ); 684 } 685 }; 686 687 this.handleUIDraggable = { 688 start: function handleUIDraggableStart( event ) { 689 _this.itemDragStart( event.currentTarget ); 690 }, 691 drag: function handleUIDraggableDrag( event, ui ) { 692 _this.itemDragMove( event.currentTarget, ui.position.left, ui.position.top ); 693 }, 694 stop: function handleUIDraggableStop( event ) { 695 _this.itemDragEnd( event.currentTarget ); 696 } 697 }; 698 699 }; 700 701 702// ----- init & layout ----- // 703 704 /** 705 * logic before any new layout 706 */ 707 Packery.prototype._resetLayout = function() {
708 this.getSize(); 709 710 this._getMeasurements(); 711 712 // reset packer 713 var packer = this.packer; 714 // packer settings, if horizontal or vertical 715 if ( this.options.isHorizontal ) { 716 packer.width = Number.POSITIVE_INFINITY; 717 packer.height = this.size.innerHeight + this.gutter; 718 packer.sortDirection = 'rightwardTopToBottom'; 719 } else { 720 packer.width = this.size.innerWidth + this.gutter; 721 packer.height = Number.POSITIVE_INFINITY; 722 packer.sortDirection = 'downwardLeftToRight'; 723 } 724 725 packer.reset(); 726 727 // layout 728 this.maxY = 0; 729 this.maxX = 0; 730 }; 731 732 /** 733 * update columnWidth, rowHeight, & gutter 734 * @private 735 */ 736 Packery.prototype._getMeasurements = function() { 737 this._getMeasurement( 'columnWidth', 'width' ); 738 this._getMeasurement( 'rowHeight', 'height' ); 739 this._getMeasurement( 'gutter', 'width' ); 740 }; 741 742 Packery.prototype._getItemLayoutPosition = function( item ) { 743 this._packItem( item ); 744 return item.rect; 745 }; 746 747 748 /** 749 * layout item in packer 750 * @param {Packery.Item} item 751 */ 752 Packery.prototype._packItem = function( item ) { 753 this._setRectSize( item.element, item.rect ); 754 // pack the rect in the packer 755 this.packer.pack( item.rect ); 756 this._setMaxXY( item.rect ); 757 }; 758 759 /** 760 * set max X and Y value, for size of container 761 * @param {Packery.Rect} rect 762 * @private 763 */ 764 Packery.prototype._setMaxXY = function( rect ) { 765 this.maxX = Math.max( rect.x + rect.width, this.maxX ); 766 this.maxY = Math.max( rect.y + rect.height, this.maxY ); 767 }; 768 769 /** 770 * set the width and height of a rect, applying columnWidth and rowHeight 771 * @param {Element} elem 772 * @param {Packery.Rect} rect 773 */ 774 Packery.prototype._setRectSize = function( elem, rect ) { 775 var size = getSize( elem ); 776 var w = size.outerWidth; 777 var h = size.outerHeight; 778 // size for columnWidth and rowHeight, if available 779 // only check if size is non-zero, #177 780 if ( w || h ) { 781 w = this._applyGridGutter( w, this.columnWidth ); 782 h = this._applyGridGutter( h, this.rowHeight ); 783 } 784 // rect must fit in packer 785 rect.width = Math.min( w, this.packer.width ); 786 rect.height = Math.min( h, this.packer.height ); 787 }; 788 789 /** 790 * fits item to columnWidth/rowHeight and adds gutter 791 * @param {Number} measurement - item width or height 792 * @param {Number} gridSize - columnWidth or rowHeight 793 * @returns measurement 794 */ 795 Packery.prototype._applyGridGutter = function( measurement, gridSize ) { 796 // just add gutter if no gridSize 797 if ( !gridSize ) { 798 return measurement + this.gutter; 799 } 800 gridSize += this.gutter; 801 // fit item to columnWidth/rowHeight 802 var remainder = measurement % gridSize; 803 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil'; 804 measurement = Math[ mathMethod ]( measurement / gridSize ) * gridSize; 805 return measurement; 806 }; 807 808 Packery.prototype._getContainerSize = function() { 809 if ( this.options.isHorizontal ) { 810 return { 811 width: this.maxX - this.gutter 812 }; 813 } else { 814 return { 815 height: this.maxY - this.gutter 816 }; 817 } 818 }; 819 820 821// -------------------------- stamp -------------------------- // 822 823 /** 824 * makes space for element 825 * @param {Element} elem 826 */ 827 Packery.prototype._manageStamp = function( elem ) { 828 829 var item = this.getItem( elem ); 830 var rect; 831 if ( item && item.isPlacing ) { 832 rect = item.placeRect; 833 } else { 834 var offset = this._getElementOffset( elem ); 835 rect = new Rect({ 836 x: this.options.isOriginLeft ? offset.left : offset.right, 837 y: this.options.isOriginTop ? offset.top : offset.bottom 838 }); 839 } 840 841 this._setRectSize( elem, rect ); 842 // save its space in the packer 843 this.packer.placed( rect ); 844 this._setMaxXY( rect ); 845 }; 846 847// -------------------------- methods -------------------------- // 848 849 function verticalSorter( a, b ) { 850 return a.position.y - b.position.y || a.position.x - b.position.x; 851 } 852 853 function horizontalSorter( a, b ) { 854 return a.position.x - b.position.x || a.position.y - b.position.y; 855 } 856
857 Packery.prototype.sortItemsByPosition = function() { 858 var sorter = this.options.isHorizontal ? horizontalSorter : verticalSorter; 859 this.items.sort( sorter ); 860 }; 861 862 /** 863 * Fit item element in its current position 864 * Packery will position elements around it 865 * useful for expanding elements 866 * 867 * @param {Element} elem 868 * @param {Number} x - horizontal destination position, optional 869 * @param {Number} y - vertical destination position, optional 870 */ 871 Packery.prototype.fit = function( elem, x, y ) { 872 var item = this.getItem( elem ); 873 if ( !item ) { 874 return; 875 } 876 877 // prepare internal properties 878 this._getMeasurements(); 879 880 // stamp item to get it out of layout 881 this.stamp( item.element ); 882 // required for positionPlaceRect 883 item.getSize(); 884 // set placing flag 885 item.isPlacing = true; 886 // fall back to current position for fitting 887 x = x === undefined ? item.rect.x: x; 888 y = y === undefined ? item.rect.y: y; 889 890 // position it best at its destination 891 item.positionPlaceRect( x, y, true ); 892 893 this._bindFitEvents( item ); 894 item.moveTo( item.placeRect.x, item.placeRect.y ); 895 // layout everything else 896 this.layout(); 897 898 // return back to regularly scheduled programming 899 this.unstamp( item.element ); 900 this.sortItemsByPosition(); 901 // un set placing flag, back to normal 902 item.isPlacing = false; 903 // copy place rect position 904 item.copyPlaceRectPosition(); 905 }; 906 907 /** 908 * emit event when item is fit and other items are laid out 909 * @param {Packery.Item} item 910 * @private 911 */ 912 Packery.prototype._bindFitEvents = function( item ) { 913 var _this = this; 914 var ticks = 0; 915 function tick() { 916 ticks++; 917 if ( ticks != 2 ) { 918 return; 919 } 920 _this.emitEvent( 'fitComplete', [ item ] ); 921 } 922 // when item is laid out 923 item.on( 'layout', function() { 924 tick(); 925 return true; 926 }); 927 // when all items are laid out 928 this.on( 'layoutComplete', function() { 929 tick(); 930 return true; 931 }); 932 }; 933 934// -------------------------- resize -------------------------- // 935 936// debounced, layout on resize 937 Packery.prototype.resize = function() { 938 // don't trigger if size did not change 939 var size = getSize( this.element ); 940 // check that this.size and size are there 941 // IE8 triggers resize on body size change, so they might not be 942 var hasSizes = this.size && size; 943 var innerSize = this.options.isHorizontal ? 'innerHeight' : 'innerWidth'; 944 if ( hasSizes && size[ innerSize ] == this.size[ innerSize ] ) { 945 return; 946 } 947 948 this.layout(); 949 }; 950 951// -------------------------- drag -------------------------- // 952 953 /** 954 * handle an item drag start event 955 * @param {Element} elem 956 */ 957 Packery.prototype.itemDragStart = function( elem ) { 958 this.stamp( elem ); 959 var item = this.getItem( elem ); 960 if ( item ) { 961 item.dragStart(); 962 } 963 }; 964 965 /** 966 * handle an item drag move event 967 * @param {Element} elem 968 * @param {Number} x - horizontal change in position 969 * @param {Number} y - vertical change in position 970 */ 971 Packery.prototype.itemDragMove = function( elem, x, y ) { 972 var item = this.getItem( elem ); 973 if ( item ) { 974 item.dragMove( x, y ); 975 } 976 977 // debounce 978 var _this = this; 979 // debounce triggering layout 980 function delayed() { 981 _this.layout(); 982 delete _this.dragTimeout; 983 } 984 985 this.clearDragTimeout(); 986 987 this.dragTimeout = setTimeout( delayed, 40 ); 988 }; 989 990 Packery.prototype.clearDragTimeout = function() { 991 if ( this.dragTimeout ) { 992 clearTimeout( this.dragTimeout ); 993 } 994 }; 995 996 /** 997 * handle an item drag end event 998 * @param {Element} elem 999 */ 1000 Packery.prototype.itemDragEnd = function( elem ) { 1001 var item = this.getItem( elem ); 1002 var itemDidDrag; 1003 if ( item ) { 1004 itemDidDrag = item.didDrag; 1005 item.dragStop(); 1006 } 1007 // if elem didn't move, or if it doesn't need positioning 1008 // unignore and unstamp and call it a day 1009 if ( !item || ( !itemDidDrag && !item.needsPositioning ) ) { 1010 this.unstamp( elem ); 1011 return; 1012 } 1013 // procced with dragged item 1014 1015 classie.add( item.element, 'is-positioning-post-drag' ); 1016 1017 // save this var, as it could get reset in dragStart 1018 var onLayoutComplete = this._getDragEndLayoutComplete( elem, item ); 1019 1020 if ( item.needsPositioning ) { 1021 item.on( 'layout', onLayoutComplete ); 1022 item.moveTo( item.placeRect.x, item.placeRect.y ); 1023 } else if ( item ) { 1024 // item didn't need placement 1025 item.copyPlaceRectPosition(); 1026 } 1027 1028 this.clearDragTimeout(); 1029 this.on( 'layoutComplete', onLayoutComplete ); 1030 this.layout(); 1031 1032 }; 1033 1034 /** 1035 * get drag end callback 1036 * @param {Element} elem 1037 * @param {Packery.Item} item 1038 * @returns {Function} onLayoutComplete 1039 */ 1040 Packery.prototype._getDragEndLayoutComplete = function( elem, item ) { 1041 var itemNeedsPositioning = item && item.needsPositioning; 1042 var completeCount = 0; 1043 var asyncCount = itemNeedsPositioning ? 2 : 1; 1044 var _this = this; 1045 1046 return function onLayoutComplete() { 1047 completeCount++; 1048 // don't proceed if not complete 1049 if ( completeCount != asyncCount ) { 1050 return true; 1051 } 1052 // reset item 1053 if ( item ) { 1054 classie.remove( item.element, 'is-positioning-post-drag' ); 1055 item.isPlacing = false;
1056 item.copyPlaceRectPosition(); 1057 } 1058 1059 _this.unstamp( elem ); 1060 // only sort when item moved 1061 _this.sortItemsByPosition(); 1062 1063 // emit item drag event now that everything is done 1064 if ( itemNeedsPositioning ) { 1065 _this.emitEvent( 'dragItemPositioned', [ item ] ); 1066 } 1067 // listen once 1068 return true; 1069 }; 1070 }; 1071 1072 /** 1073 * binds Draggabilly events 1074 * @param {Draggabilly} draggie 1075 */ 1076 Packery.prototype.bindDraggabillyEvents = function( draggie ) { 1077 draggie.on( 'dragStart', this.handleDraggabilly.dragStart ); 1078 draggie.on( 'dragMove', this.handleDraggabilly.dragMove ); 1079 draggie.on( 'dragEnd', this.handleDraggabilly.dragEnd ); 1080 }; 1081 1082 /** 1083 * binds jQuery UI Draggable events 1084 * @param {jQuery} $elems 1085 */ 1086 Packery.prototype.bindUIDraggableEvents = function( $elems ) { 1087 $elems 1088 .on( 'dragstart', this.handleUIDraggable.start ) 1089 .on( 'drag', this.handleUIDraggable.drag ) 1090 .on( 'dragstop', this.handleUIDraggable.stop ); 1091 }; 1092 1093 Packery.Rect = Rect; 1094 Packery.Packer = Packer; 1095 1096 return Packery; 1097 1098})); 1099 1100/*! 1101 * Packery layout mode v1.1.3 1102 * sub-classes Packery 1103 * http://packery.metafizzy.co 1104 */ 1105 1106/*jshint browser: true, strict: true, undef: true, unused: true */ 1107 1108( function( window, factory ) { 1109 1110 // universal module definition 1111 if ( typeof define == 'function' && define.amd ) { 1112 // AMD 1113 define( [ 1114 'isotope/js/layout-mode', 1115 'packery/js/packery', 1116 'get-size/get-size' 1117 ], 1118 factory ); 1119 } else if ( typeof exports == 'object' ) { 1120 // CommonJS 1121 module.exports = factory( 1122 require('isotope-layout/js/layout-mode'), 1123 require('packery'), 1124 require('get-size') 1125 ); 1126 } else { 1127 // browser global 1128 factory( 1129 window.Isotope.LayoutMode, 1130 window.Packery, 1131 window.getSize 1132 ); 1133 } 1134 1135}( window, function factor( LayoutMode, Packery, getSize ) { 1136 1137 1138// -------------------------- helpers -------------------------- // 1139 1140// extend objects 1141 function extend( a, b ) { 1142 for ( var prop in b ) { 1143 a[ prop ] = b[ prop ]; 1144 } 1145 return a; 1146 } 1147 1148// -------------------------- masonryDefinition -------------------------- // 1149 1150 // create an Outlayer layout class 1151 var PackeryMode = LayoutMode.create('packery'); 1152 1153 // save on to these methods 1154 var _getElementOffset = PackeryMode.prototype._getElementOffset; 1155 // var layout = PackeryMode.prototype.layout; 1156 var _getMeasurement = PackeryMode.prototype._getMeasurement; 1157 1158 // sub-class Masonry 1159 extend( PackeryMode.prototype, Packery.prototype ); 1160 1161 // set back, as it was overwritten by Packery 1162 PackeryMode.prototype._getElementOffset = _getElementOffset; 1163 // PackeryMode.prototype.layout = layout; 1164 PackeryMode.prototype._getMeasurement = _getMeasurement; 1165 1166 // set packery in _resetLayout 1167 var _resetLayout = PackeryMode.prototype._resetLayout; 1168 PackeryMode.prototype._resetLayout = function() { 1169 this.packer = this.packer || new Packery.Packer(); 1170 _resetLayout.apply( this, arguments ); 1171 }; 1172 1173 var _getItemLayoutPosition = PackeryMode.prototype._getItemLayoutPosition; 1174 PackeryMode.prototype._getItemLayoutPosition = function( item ) { 1175 // set packery rect 1176 item.rect = item.rect || new Packery.Rect(); 1177 return _getItemLayoutPosition.call( this, item ); 1178 }; 1179 1180 // HACK copy over isOriginLeft/Top options 1181 var _manageStamp = PackeryMode.prototype._manageStamp; 1182 PackeryMode.prototype._manageStamp = function() { 1183 this.options.isOriginLeft = this.isotope.options.isOriginLeft; 1184 this.options.isOriginTop = this.isotope.options.isOriginTop; 1185 _manageStamp.apply( this, arguments ); 1186 }; 1187 1188 PackeryMode.prototype.needsResizeLayout = function() { 1189 // don't trigger if size did not change 1190 var size = getSize( this.element ); 1191 // check that this.size and size are there 1192 // IE8 triggers resize on body size change, so they might not be 1193 var hasSizes = this.size && size;
1194 var innerSize = this.options.isHorizontal ? 'innerHeight' : 'innerWidth'; 1195 return hasSizes && size[ innerSize ] != this.size[ innerSize ]; 1196 }; 1197 1198 return PackeryMode; 1199}));
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.