Sha256: 47fe2fd70f7973c725adc27679a34a739975192ecf100dec6e4fe10f5efb9d6a

Contents?: true

Size: 1.28 KB

Versions: 98

Compression:

Stored size: 1.28 KB

Contents

Spotlight.BlockLimits = function(editor) {
  this.editor = editor;
};

Spotlight.BlockLimits.prototype.enforceLimits = function(editor) {
  this.addEditorCallbacks(editor);
  this.checkGlobalBlockTypeLimit()();
};

Spotlight.BlockLimits.prototype.addEditorCallbacks = function(editor) {
  SirTrevor.EventBus.on('block:create:new', this.checkBlockTypeLimitOnAdd());
  SirTrevor.EventBus.on('block:remove', this.checkGlobalBlockTypeLimit());
};

Spotlight.BlockLimits.prototype.checkBlockTypeLimitOnAdd = function() {
  var editor = this.editor;

  return function(block) {
    var control = $(".st-block-controls__button[data-type='" + block.type + "']", editor.blockControls.el);

    control.prop("disabled", !editor.blockManager.canCreateBlock(block.class()));
  };
};

Spotlight.BlockLimits.prototype.checkGlobalBlockTypeLimit = function() {
  // we don't know what type of block was created or removed.. So, try them all.
  var editor = this.editor;

  return function() {
    $.each(editor.blockManager.blockTypes, function(i, type) {
      var block_type = SirTrevor.Blocks[type].prototype;

      var control = $(editor.blockControls.el).find(".st-block-controls__button[data-type='" + block_type.type + "']");
      control.prop("disabled", !editor.blockManager.canCreateBlock(type));
    });
  };
};

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc6 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.rc5 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.rc4 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.rc3 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.rc2 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.rc1 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.10 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.9 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.8 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.7 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.6 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.5 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.4 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.3 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.2 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-3.0.0.alpha.1 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-2.13.0 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-2.12.1 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-2.12.0 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js
blacklight-spotlight-2.11.0 app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js