masonry.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*!
  2. * Masonry layout mode
  3. * sub-classes Masonry
  4. * http://masonry.desandro.com
  5. */
  6. ( function( window, factory ) {
  7. // universal module definition
  8. /* jshint strict: false */ /*globals define, module, require */
  9. if ( typeof define == 'function' && define.amd ) {
  10. // AMD
  11. define( [
  12. '../layout-mode',
  13. 'masonry/masonry'
  14. ],
  15. factory );
  16. } else if ( typeof module == 'object' && module.exports ) {
  17. // CommonJS
  18. module.exports = factory(
  19. require('../layout-mode'),
  20. require('masonry-layout')
  21. );
  22. } else {
  23. // browser global
  24. factory(
  25. window.Isotope.LayoutMode,
  26. window.Masonry
  27. );
  28. }
  29. }( window, function factory( LayoutMode, Masonry ) {
  30. 'use strict';
  31. // -------------------------- masonryDefinition -------------------------- //
  32. // create an Outlayer layout class
  33. var MasonryMode = LayoutMode.create('masonry');
  34. var proto = MasonryMode.prototype;
  35. var keepModeMethods = {
  36. _getElementOffset: true,
  37. layout: true,
  38. _getMeasurement: true
  39. };
  40. // inherit Masonry prototype
  41. for ( var method in Masonry.prototype ) {
  42. // do not inherit mode methods
  43. if ( !keepModeMethods[ method ] ) {
  44. proto[ method ] = Masonry.prototype[ method ];
  45. }
  46. }
  47. var measureColumns = proto.measureColumns;
  48. proto.measureColumns = function() {
  49. // set items, used if measuring first item
  50. this.items = this.isotope.filteredItems;
  51. measureColumns.call( this );
  52. };
  53. // point to mode options for fitWidth
  54. var _getOption = proto._getOption;
  55. proto._getOption = function( option ) {
  56. if ( option == 'fitWidth' ) {
  57. return this.options.isFitWidth !== undefined ?
  58. this.options.isFitWidth : this.options.fitWidth;
  59. }
  60. return _getOption.apply( this.isotope, arguments );
  61. };
  62. return MasonryMode;
  63. }));