Skip to content

Unable to load modes #3234

@oscarotero

Description

@oscarotero

Hi. I've spend a lot of time trying to load modes dinamically using requirejs but I cannot make it work.

I have this code:

define([
    'jquery',
    'require'
], function ($, require) {
    var module = {
        init: function ($element) {
            var modename = $element.data('mode') || 'htmlmixed';

            require([
                './bower_components/codemirror',
                './bower_components/codemirror/mode/' + modename + '/' + modename
            ], function (codemirror) {
                var editor = codemirror.fromTextArea($element.find('textarea').get(0), {
                    lineNumbers: true,
                    mode: modename
                });
                console.log(editor.getMode().name);
            });
        }
    };

    return module;
});

The console.log always returns "null". I've tried putting editor.setOption("mode", "javascript"); after instantiation but it keeps not working. Requirejs loads codemirror and the mode correctly, but for any reason the mode is not initialized. Maybe I'm doing something wrong? I've tried to follow the manual.

Thank you very much for this great library 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy