gridstack-8.x-2.5/js/gridstack.load.js

js/gridstack.load.js
/**
 * @file
 * Provides loader for js-driven layout using GridStack JS library.
 */

(function (Drupal, _, GridStack, _db) {

  'use strict';

  Drupal.gridstack = Drupal.gridstack || {};

  /**
   * GridStack front-end public methods.
   *
   * @namespace
   */
  Drupal.gridstack.gs = _db.extend({}, Drupal.gridstack.fe || {}, {
    fixAspectRatio: function () {
      var me = this;
      var ok = me.cellHeight >= me.options.cellHeight && me.cellHeight < (me.options.cellHeight * 2);
      var vm = me.options.verticalMargin > 0 ? me.options.verticalMargin : 0;

      // Requires to determine the correct aspect ratio.
      if (!_.isNull(me.$sizer) && me.isEnabled()) {
        me.$sizer.style.height = me.cellHeight + 'px';
        me.$sizer.style.width = me.cellHeight + 'px';

        me.cellHeight = ok ? (me.cellHeight - vm) : me.options.cellHeight;
        me.options.cellHeight = me.cellHeight;
      }
    },

    preUpdateGrid: function () {
      var me = this;
      me.$instance.column(me.column);
    },

    updateAttribute: function (box, item) {
      var me = this;
      // Params: el, x, y, width, height.
      me.$instance.update(box, item[0], item[1], item[2], item[3]);
    },

    destroy: function () {
      var me = this;

      if (!_.isNull(me.$instance)) {
        me.$instance.destroy(false);
      }

      me.$el.classList.add('gridstack--destroyed');
      me.$el.removeAttribute('style');
    }

  });

  /**
   * GridStack utility functions.
   *
   * @param {HTMLElement} elm
   *   The GridStack HTML element.
   */
  function doGridStack(elm) {
    var me = Drupal.gridstack.gs;

    me.init(elm);

    me.$instance = GridStack.init(me.options, elm);
    me.buildOut();
    me.cleanUp();

    if (!_.isNull(me.$sizer)) {
      me.$instance.removeWidget(me.$sizer);
    }
    elm.classList.add('gridstack--gs--on');
  }

  /**
   * Attaches behavior to HTML element identified by .gridstack--gs.
   *
   * @type {Drupal~behavior}
   */
  Drupal.behaviors.gridstack = {
    attach: function (context) {
      if ('length' in context) {
        context = context[0];
      }

      var elms = context.querySelectorAll('.gridstack--gs:not(.gridstack--gs--on)');
      if (elms.length > 0) {
        _db.once(_db.forEach(elms, doGridStack, context));
      }
    }
  };

})(Drupal, _, GridStack, dBlazy);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc