Sha256: afbf871f3e2136c87a5c7f1d9b55803033a32e1d04666775eca304f3868b5e01
Contents?: true
Size: 1.31 KB
Versions: 3
Compression:
Stored size: 1.31 KB
Contents
import Spotlight from 'spotlight' 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
3 entries across 3 versions & 1 rubygems