item.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Isotope Item
  3. **/
  4. ( function( window, factory ) {
  5. // universal module definition
  6. /* jshint strict: false */ /*globals define, module, require */
  7. if ( typeof define == 'function' && define.amd ) {
  8. // AMD
  9. define( [
  10. 'outlayer/outlayer'
  11. ],
  12. factory );
  13. } else if ( typeof module == 'object' && module.exports ) {
  14. // CommonJS
  15. module.exports = factory(
  16. require('outlayer')
  17. );
  18. } else {
  19. // browser global
  20. window.Isotope = window.Isotope || {};
  21. window.Isotope.Item = factory(
  22. window.Outlayer
  23. );
  24. }
  25. }( window, function factory( Outlayer ) {
  26. 'use strict';
  27. // -------------------------- Item -------------------------- //
  28. // sub-class Outlayer Item
  29. function Item() {
  30. Outlayer.Item.apply( this, arguments );
  31. }
  32. var proto = Item.prototype = Object.create( Outlayer.Item.prototype );
  33. var _create = proto._create;
  34. proto._create = function() {
  35. // assign id, used for original-order sorting
  36. this.id = this.layout.itemGUID++;
  37. _create.call( this );
  38. this.sortData = {};
  39. };
  40. proto.updateSortData = function() {
  41. if ( this.isIgnored ) {
  42. return;
  43. }
  44. // default sorters
  45. this.sortData.id = this.id;
  46. // for backward compatibility
  47. this.sortData['original-order'] = this.id;
  48. this.sortData.random = Math.random();
  49. // go thru getSortData obj and apply the sorters
  50. var getSortData = this.layout.options.getSortData;
  51. var sorters = this.layout._sorters;
  52. for ( var key in getSortData ) {
  53. var sorter = sorters[ key ];
  54. this.sortData[ key ] = sorter( this.element, this );
  55. }
  56. };
  57. var _destroy = proto.destroy;
  58. proto.destroy = function() {
  59. // call super
  60. _destroy.apply( this, arguments );
  61. // reset display, #741
  62. this.css({
  63. display: ''
  64. });
  65. };
  66. return Item;
  67. }));