How to use the medium-editor.util function in medium-editor

To help you get started, we’ve selected a few medium-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dperetti / Django-wagtailmedium / src / wagtailmedium / LinkPreview.js View on Github external
handleEditableMouseover: function (event) {
    const target = MediumEditor.util.getClosestTag(event.target, 'a');

    if (target === false) {
      return null
    }
    // Detect empty href attributes
    // The browser will make href="" or href="#top"
    // into absolute urls when accessed as event.target.href, so check the html
    if (!this.showOnEmptyLinks && (!/href=["']\S+["']/.test(target.outerHTML) || /href=["']#\S+["']/.test(target.outerHTML))) {
      return true
    }
    // only show when toolbar is not present
    const toolbar = this.base.getExtensionByName('toolbar');
    if (!this.showWhenToolbarIsVisible && toolbar && toolbar.isDisplayed && toolbar.isDisplayed()) {
      return true
    }
    // detach handler for other anchor in case we hovered multiple anchors quickly
github getlackey / lackey-cms / modules / cms / client / js / wysiwyg.js View on Github external
})
        };

        if (insertButtons.length) {
            options.extensions.insertMedia = new InsertMedia();
            options.extensions.insert = new Insert({
                buttons: insertButtons
            });
        }

        self._lock = true;
        let editor = new MediumEditor(this._element, options);

        // allows use of section for editing to function properly
        MediumEditor.util.blockContainerElementNames.splice(MediumEditor.util.blockContainerElementNames.indexOf('section'), 1);

        editor.subscribe('editableKeydownEnter', function (event) {
            if (event.shiftKey) {
                //var node = MediumEditor.selection.getSelectionStart(editor.options.ownerDocument);
                MediumEditor.util.insertHTMLCommand(editor.options.ownerDocument, '[BR]');
                self._element.innerHTML = self._element.innerHTML.replace(/\[BR\]/g, '<br>');
                self._element.dispatchEvent(new Event('change'));
                event.preventDefault();
            } else if (self._element.hasAttribute('data-lky-singleline')) {
                event.preventDefault();
            }
        });

        Array.prototype.slice
            .call(this._element.querySelectorAll('img, video'))
            .forEach(element =&gt; Wysiwyg.initInTextMedia(new Media(element, true)));
github getlackey / lackey-cms / modules / cms / client / js / wysiwyg.js View on Github external
editor.subscribe('editableKeydownEnter', function (event) {
            if (event.shiftKey) {
                //var node = MediumEditor.selection.getSelectionStart(editor.options.ownerDocument);
                MediumEditor.util.insertHTMLCommand(editor.options.ownerDocument, '[BR]');
                self._element.innerHTML = self._element.innerHTML.replace(/\[BR\]/g, '<br>');
                self._element.dispatchEvent(new Event('change'));
                event.preventDefault();
            } else if (self._element.hasAttribute('data-lky-singleline')) {
                event.preventDefault();
            }
        });