"orion" is undefined when integrating orion editor in dojo

59 views Asked by At

I am new to dojo and I am trying to integrate orion editor(build downloaded from http://download.eclipse.org/orion/) in dojo but I get the error "orion" is undefined. The code looks like below:

  1. HTML file for placing editor <div data-dojo-attach-point="embeddedEditor"></div>

  2. A JS file

    require([
    "dojo/_base/declare", 
    "dijit/_WidgetBase",
    "editorBuild/code_edit/built-codeEdit-amd",
    "dijit/_TemplatedMixin",
    "dojo/text!orionEditor.html"
    ], function(declare,_WidgetBase,
    codeEditorAmd, _TemplatedMixin,template){
    declare("orionEditor", [_WidgetBase, 
    _TemplatedMixin], {
    
    templateString: template,
    
    postCreate: function(){
          var codeEdit = new orion.codeEdit();
            var contents = '';
                codeEdit.create({parent: this.embeddedEditor, contentType: "application/javascript", contents: contents}).
          then(function(editorViewer) {                         
            if (editorViewer.settings) {
                            editorViewer.settings.contentAssistAutoTrigger = true;
                            editorViewer.settings.showOccurrences = true;
                        }
    
                    });
         }
       });
      });
    
  3. The orion editor build is placed in editorBuild folder.

Standalone orion works fine - http://libingw.github.io/OrionCodeEdit/ When integrating with dojo I am not sure why orion is undefined. Any help would be much appreciated.

1

There are 1 answers

1
barbsan On BEST ANSWER

If you want using orion name in amd module then it has to be defined as parameter in function passed as require's callback.

Check this guide - it has 2 solutions for using orion with amd modules.

Option 1 - define bundles once and use shorter name in all modules you need them:

require.config({
    bundles: {
        "editorBuild/code_edit/built-codeEdit-amd": ["orion/codeEdit", "orion/Deferred"]
    }       
});
require(
    ["orion/codeEdit", "orion/Deferred"], 
    function(mCodeEdit, Deferred) {
        var codeEdit = new mCodeEdit();
        var contents = 'var foo = "bar";'; 
        codeEdit.create({parent: "embeddedEditor"/*editor parent node id*/})
                .then(function(editorViewer) {
                    editorViewer.setContents(contents, "application/javascript");
                });
});

Option 2 - nested require:

require(["editorBuild/code_edit/built-codeEdit-amd"], function() {
    require(["orion/codeEdit", "orion/Deferred"], function(mCodeEdit, Deferred) {
    var codeEdit = new mCodeEdit();
    var contents = 'var foo = "bar";'; 
    codeEdit.create({parent: "embeddedEditor"/*editor parent node id*/})
            .then(function(editorViewer) {
                editorViewer.setContents(contents, "application/javascript");
            });
    });
});

Note: you can replace mCodeEdit with any unique name (That wouldn't shadow other objects/modules)