function Grid(element, options) {

    var inst = this;
    var settings;
    var items;
    var layoutOnResize;

    // Muuri can be loaded inside the head tag also, but in that case Muuri can
    // not cache body element and run the initial DOM tests. So, if we detect
    // that body element could not be fetched on init we do it here once and
    // also run the DOM tests. If the Grid is instantiated before body is ready
    // you are doing it wrong ;)
    if (!body) {
      body = document.body;
      transformLeaksFixed = doesTransformLeakFixed();
    }

    // Allow passing element as selector string. Store element for instance.
    element = inst._element = typeof element === typeString ? doc.querySelector(element) : element;

    // Throw an error if the container element is not body element or does not
    // exist within the body element.
    if (!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 = inst._settings = mergeSettings(Grid.defaultOptions, options);

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

    // Create instance id and store it to the grid instances collection.
    gridInstances[inst._id = ++uuid] = inst;

    // Destroyed flag.
    inst._isDestroyed = false;

    // Reference to the currently used Layout instance.
    inst._layout = null;

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

    // Setup grid's show/hide animation handler for items.
    inst._itemShowHandler = getItemVisibilityHandler('show', settings);
    inst._itemHideHandler = getItemVisibilityHandler('hide', settings);

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

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

    // Sanitize layoutOnResize option and bind debounced resize handler if the
    // layoutOnResize option a valid number.
    layoutOnResize = settings.layoutOnResize;
    layoutOnResize = layoutOnResize === true ? 0 : typeof layoutOnResize === typeNumber ? layoutOnResize : -1;
    if (layoutOnResize >= 0) {
      global.addEventListener('resize', inst._resizeHandler = debounce(function () {
        inst.refreshItems().layout();
      }, layoutOnResize));
    }

    // Layout on init if necessary.
    if (settings.layoutOnInit) {
      inst.layout(true);
    }

  }
/**
   * Creates a new Grid instance.
   *
   * @public
   * @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;
    if (!body) {
      body = document.body;
      transformLeaksFixed = doesTransformLeakFixed();
    }
    element = inst._element = typeof element === typeString ? doc.querySelector(element) : element;
    if (!body.contains(element)) {
      throw new Error('Container element must be an existing DOM element');
    }
    settings = inst._settings = mergeSettings(Grid.defaultOptions, options);
    if (typeof settings.dragSort !== typeFunction) {
      settings.dragSort = !!settings.dragSort;
    }
    gridInstances[inst._id = ++uuid] = inst;
    inst._isDestroyed = false;
    inst._layout = null;
    inst._emitter = new Grid.Emitter();
    inst._itemShowHandler = getItemVisibilityHandler('show', settings);
    inst._itemHideHandler = getItemVisibilityHandler('hide', settings);
    addClass(element, settings.containerClass);
    inst._items = [];
    items = settings.items;
    if (typeof items === typeString) {
      nodeListToArray(inst._element.children).forEach(function (itemElement) {
        if (items === '*' || elementMatches(itemElement, items)) {
          inst._items.push(new Grid.Item(inst, itemElement));
        }
      });
    }
    else if (Array.isArray(items) || isNodeList(items)) {
      inst._items = nodeListToArray(items).map(function (itemElement) {
        return new Grid.Item(inst, itemElement);
      });
    }
    layoutOnResize = settings.layoutOnResize;
    layoutOnResize = layoutOnResize === true ? 0 : typeof layoutOnResize === typeNumber ? layoutOnResize : -1;
    if (layoutOnResize >= 0) {
      global.addEventListener('resize', inst._resizeHandler = debounce(function () {
        inst.refreshItems().layout();
      }, layoutOnResize));
    }
    if (settings.layoutOnInit) {
      inst.layout(true);
    }
  }
function Grid ( element , options ) { var inst = this ; var settings ; var items ; var layoutOnResize ; if ( ! body ) { body = document . body ; transformLeaksFixed = doesTransformLeakFixed ( ) ; } element = inst . _element = typeof element === typeString ? doc . querySelector ( element ) : element ; if ( ! body . contains ( element ) ) { throw new Error ( 'Container element must be an existing DOM element' ) ; } settings = inst . _settings = mergeSettings ( Grid . defaultOptions , options ) ; if ( typeof settings . dragSort !== typeFunction ) { settings . dragSort = ! ! settings . dragSort ; } gridInstances [ inst . _id = ++ uuid ] = inst ; inst . _isDestroyed = false ; inst . _layout = null ; inst . _emitter = new Grid . Emitter ( ) ; inst . _itemShowHandler = getItemVisibilityHandler ( 'show' , settings ) ; inst . _itemHideHandler = getItemVisibilityHandler ( 'hide' , settings ) ; addClass ( element , settings . containerClass ) ; inst . _items = [ ] ; items = settings . items ; if ( typeof items === typeString ) { nodeListToArray ( inst . _element . children ) . forEach ( function ( itemElement ) { if ( items === '*' || elementMatches ( itemElement , items ) ) { inst . _items . push ( new Grid . Item ( inst , itemElement ) ) ; } } ) ; } else if ( Array . isArray ( items ) || isNodeList ( items ) ) { inst . _items = nodeListToArray ( items ) . map ( function ( itemElement ) { return new Grid . Item ( inst , itemElement ) ; } ) ; } layoutOnResize = settings . layoutOnResize ; layoutOnResize = layoutOnResize === true ? 0 : typeof layoutOnResize === typeNumber ? layoutOnResize : - 1 ; if ( layoutOnResize >= 0 ) { global . addEventListener ( 'resize' , inst . _resizeHandler = debounce ( function ( ) { inst . refreshItems ( ) . layout ( ) ; } , layoutOnResize ) ) ; } if ( settings . layoutOnInit ) { inst . layout ( true ) ; } }
Creates a new Grid instance.
Creates a new Grid instance .
// Muuri can be loaded inside the head tag also, but in that case Muuri can // not cache body element and run the initial DOM tests. So, if we detect // that body element could not be fetched on init we do it here once and // also run the DOM tests. If the Grid is instantiated before body is ready // you are doing it wrong ;) // 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. // Reference to the currently used Layout instance. // Create private Emitter instance. // Setup grid's show/hide animation handler for items. // Add container element's class name. // Create initial items. // Sanitize layoutOnResize option and bind debounced resize handler if the // layoutOnResize option a valid number. // Layout on init if necessary.