Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

87 wiersze
2.0 KiB

  1. /**
  2. * CellsByRow example
  3. */
  4. ( function( window, factory ) {
  5. /* jshint strict: false */ /* globals define, module, require */
  6. if ( typeof define == 'function' && define.amd ) {
  7. // AMD
  8. define( [
  9. '../outlayer'
  10. ],
  11. factory );
  12. } else if ( typeof module == 'object' && module.exports ) {
  13. module.exports = factory(
  14. require('../outlayer')
  15. );
  16. } else {
  17. // browser global
  18. window.CellsByRow = factory(
  19. window.Outlayer
  20. );
  21. }
  22. }( window, function factory( Outlayer) {
  23. 'use strict';
  24. var CellsByRow = Outlayer.create( 'cellsByRow', {
  25. columnWidth: 100,
  26. rowHeight: 100
  27. });
  28. CellsByRow.prototype._resetLayout = function() {
  29. this.getSize();
  30. this._getMeasurement( 'columnWidth', 'outerWidth' );
  31. this._getMeasurement( 'rowHeight', 'outerHeight' );
  32. var isHorizontal = this._getOption('horizontal');
  33. if ( isHorizontal ) {
  34. this.rows = Math.floor( this.size.innerHeight / this.rowHeight );
  35. this.rows = Math.max( this.rows, 1 );
  36. } else {
  37. this.cols = Math.floor( this.size.innerWidth / this.columnWidth );
  38. this.cols = Math.max( this.cols, 1 );
  39. }
  40. this.itemIndex = 0;
  41. };
  42. CellsByRow.prototype._getItemLayoutPosition = function( item ) {
  43. item.getSize();
  44. var column, row;
  45. var isHorizontal = this._getOption('horizontal');
  46. if ( isHorizontal ) {
  47. row = this.itemIndex % this.rows;
  48. column = Math.floor( this.itemIndex / this.rows );
  49. } else {
  50. column = this.itemIndex % this.cols;
  51. row = Math.floor( this.itemIndex / this.cols );
  52. }
  53. var x = column * this.columnWidth;
  54. var y = row * this.rowHeight;
  55. this.itemIndex++;
  56. return {
  57. x: x,
  58. y: y
  59. };
  60. };
  61. CellsByRow.prototype._getContainerSize = function() {
  62. var isHorizontal = this._getOption('horizontal');
  63. if ( isHorizontal ) {
  64. return {
  65. width: Math.ceil( this.itemIndex / this.rows ) * this.columnWidth
  66. };
  67. } else {
  68. return {
  69. height: Math.ceil( this.itemIndex / this.cols ) * this.rowHeight
  70. };
  71. }
  72. };
  73. return CellsByRow;
  74. }));