function Grid(element, options) {
    var inst = this;
    var settings;
    var items;
    var layoutOnResize;

    // Allow passing element as selector string. Store element for instance.
    element = this._element = typeof element === 'string' ? document.querySelector(element) : element;

    // Throw an error if the container element is not body element or does not
    // exist within the body element.
    if (!document.body.contains(element)) {
      throw new Error('Container element must be an existing DOM element');
    }

    // Create instance settings by merging the options with default options.
    settings = this._settings = mergeSettings(Grid.defaultOptions, options);

    // Sanitize dragSort setting.
    if (typeof settings.dragSort !== 'function') {
      settings.dragSort = !!settings.dragSort;
    }

    // Create instance id and store it to the grid instances collection.
    this._id = createUid();
    gridInstances[this._id] = inst;

    // Destroyed flag.
    this._isDestroyed = false;

    // The layout object (mutated on every layout).
    this._layout = {
      id: 0,
      items: [],
      slots: [],
      setWidth: false,
      setHeight: false,
      width: 0,
      height: 0
    };

    // Create private Emitter instance.
    this._emitter = new Emitter();

    // Add container element's class name.
    addClass(element, settings.containerClass);

    // Create initial items.
    this._items = [];
    items = settings.items;
    if (typeof items === 'string') {
      toArray(element.children).forEach(function(itemElement) {
        if (items === '*' || elementMatches(itemElement, items)) {
          inst._items.push(new Item(inst, itemElement));
        }
      });
    } else if (Array.isArray(items) || isNodeList(items)) {
      this._items = toArray(items).map(function(itemElement) {
        return new Item(inst, itemElement);
      });
    }

    // If layoutOnResize option is a valid number sanitize it and bind the resize
    // handler.
    layoutOnResize = settings.layoutOnResize;
    if (typeof layoutOnResize !== 'number') {
      layoutOnResize = layoutOnResize === true ? 0 : -1;
    }
    if (layoutOnResize >= 0) {
      window.addEventListener(
        'resize',
        (inst._resizeHandler = debounce(function() {
          inst.refreshItems().layout();
        }, layoutOnResize))
      );
    }

    // Layout on init if necessary.
    if (settings.layoutOnInit) {
      this.layout(true);
    }
  }
/**
   * Creates a new Grid instance.
   *
   * @class
   * @param {(HTMLElement|String)} element
   * @param {Object} [options]
   * @param {(?HTMLElement[]|NodeList|String)} [options.items]
   * @param {Number} [options.showDuration=300]
   * @param {String} [options.showEasing="ease"]
   * @param {Object} [options.visibleStyles]
   * @param {Number} [options.hideDuration=300]
   * @param {String} [options.hideEasing="ease"]
   * @param {Object} [options.hiddenStyles]
   * @param {(Function|Object)} [options.layout]
   * @param {Boolean} [options.layout.fillGaps=false]
   * @param {Boolean} [options.layout.horizontal=false]
   * @param {Boolean} [options.layout.alignRight=false]
   * @param {Boolean} [options.layout.alignBottom=false]
   * @param {Boolean} [options.layout.rounding=true]
   * @param {(Boolean|Number)} [options.layoutOnResize=100]
   * @param {Boolean} [options.layoutOnInit=true]
   * @param {Number} [options.layoutDuration=300]
   * @param {String} [options.layoutEasing="ease"]
   * @param {?Object} [options.sortData=null]
   * @param {Boolean} [options.dragEnabled=false]
   * @param {?HtmlElement} [options.dragContainer=null]
   * @param {?Function} [options.dragStartPredicate]
   * @param {Number} [options.dragStartPredicate.distance=0]
   * @param {Number} [options.dragStartPredicate.delay=0]
   * @param {(Boolean|String)} [options.dragStartPredicate.handle=false]
   * @param {?String} [options.dragAxis]
   * @param {(Boolean|Function)} [options.dragSort=true]
   * @param {Number} [options.dragSortInterval=100]
   * @param {(Function|Object)} [options.dragSortPredicate]
   * @param {Number} [options.dragSortPredicate.threshold=50]
   * @param {String} [options.dragSortPredicate.action="move"]
   * @param {Number} [options.dragReleaseDuration=300]
   * @param {String} [options.dragReleaseEasing="ease"]
   * @param {Object} [options.dragHammerSettings={touchAction: "none"}]
   * @param {String} [options.containerClass="muuri"]
   * @param {String} [options.itemClass="muuri-item"]
   * @param {String} [options.itemVisibleClass="muuri-item-visible"]
   * @param {String} [options.itemHiddenClass="muuri-item-hidden"]
   * @param {String} [options.itemPositioningClass="muuri-item-positioning"]
   * @param {String} [options.itemDraggingClass="muuri-item-dragging"]
   * @param {String} [options.itemReleasingClass="muuri-item-releasing"]
   */
Creates a new Grid instance.
Creates a new Grid instance .
function Grid(element, options) {
    var inst = this;
    var settings;
    var items;
    var layoutOnResize;
    element = this._element = typeof element === 'string' ? document.querySelector(element) : element;
    if (!document.body.contains(element)) {
      throw new Error('Container element must be an existing DOM element');
    }
    settings = this._settings = mergeSettings(Grid.defaultOptions, options);
    if (typeof settings.dragSort !== 'function') {
      settings.dragSort = !!settings.dragSort;
    }
    this._id = createUid();
    gridInstances[this._id] = inst;
    this._isDestroyed = false;
    this._layout = {
      id: 0,
      items: [],
      slots: [],
      setWidth: false,
      setHeight: false,
      width: 0,
      height: 0
    };
    this._emitter = new Emitter();
    addClass(element, settings.containerClass);
    this._items = [];
    items = settings.items;
    if (typeof items === 'string') {
      toArray(element.children).forEach(function(itemElement) {
        if (items === '*' || elementMatches(itemElement, items)) {
          inst._items.push(new Item(inst, itemElement));
        }
      });
    } else if (Array.isArray(items) || isNodeList(items)) {
      this._items = toArray(items).map(function(itemElement) {
        return new Item(inst, itemElement);
      });
    }
    layoutOnResize = settings.layoutOnResize;
    if (typeof layoutOnResize !== 'number') {
      layoutOnResize = layoutOnResize === true ? 0 : -1;
    }
    if (layoutOnResize >= 0) {
      window.addEventListener(
        'resize',
        (inst._resizeHandler = debounce(function() {
          inst.refreshItems().layout();
        }, layoutOnResize))
      );
    }
    if (settings.layoutOnInit) {
      this.layout(true);
    }
  }
function Grid ( element , options ) { var inst = this ; var settings ; var items ; var layoutOnResize ; element = this . _element = typeof element === 'string' ? document . querySelector ( element ) : element ; if ( ! document . body . contains ( element ) ) { throw new Error ( 'Container element must be an existing DOM element' ) ; } settings = this . _settings = mergeSettings ( Grid . defaultOptions , options ) ; if ( typeof settings . dragSort !== 'function' ) { settings . dragSort = ! ! settings . dragSort ; } this . _id = createUid ( ) ; gridInstances [ this . _id ] = inst ; this . _isDestroyed = false ; this . _layout = { id : 0 , items : [ ] , slots : [ ] , setWidth : false , setHeight : false , width : 0 , height : 0 } ; this . _emitter = new Emitter ( ) ; addClass ( element , settings . containerClass ) ; this . _items = [ ] ; items = settings . items ; if ( typeof items === 'string' ) { toArray ( element . children ) . forEach ( function ( itemElement ) { if ( items === '*' || elementMatches ( itemElement , items ) ) { inst . _items . push ( new Item ( inst , itemElement ) ) ; } } ) ; } else if ( Array . isArray ( items ) || isNodeList ( items ) ) { this . _items = toArray ( items ) . map ( function ( itemElement ) { return new Item ( inst , itemElement ) ; } ) ; } layoutOnResize = settings . layoutOnResize ; if ( typeof layoutOnResize !== 'number' ) { layoutOnResize = layoutOnResize === true ? 0 : - 1 ; } if ( layoutOnResize >= 0 ) { window . addEventListener ( 'resize' , ( inst . _resizeHandler = debounce ( function ( ) { inst . refreshItems ( ) . layout ( ) ; } , layoutOnResize ) ) ) ; } if ( settings . layoutOnInit ) { this . layout ( true ) ; } }
Creates a new Grid instance.
Creates a new Grid instance .
// Allow passing element as selector string. Store element for instance. // Throw an error if the container element is not body element or does not // exist within the body element. // Create instance settings by merging the options with default options. // Sanitize dragSort setting. // Create instance id and store it to the grid instances collection. // Destroyed flag. // The layout object (mutated on every layout). // Create private Emitter instance. // Add container element's class name. // Create initial items. // If layoutOnResize option is a valid number sanitize it and bind the resize // handler. // Layout on init if necessary.