Run ui-codemirror in JSBin

155 views Asked by At

I want to move this code in Plnkr to JSBin. It does not work, and DevTools shows Error: ui-codemirror needs CodeMirror to work... (o rly?).

It seems that Plnkr has some dependency management that JSBin does not have. I would like to know what Plnkr did behind the screen, and run this code in JSBin, does anyone know how to modify the links and sources to make it work?

<!DOCTYPE html>
<html ng-app="x">    
  <head>
    <meta charset="utf-8" />
    <title>UI.Codemirror : demo </title>

    <!-- Le css -->
    <link rel="stylesheet" type="text/css" href="http://codemirror.net/lib/codemirror.css"/>
    <link rel="stylesheet" type="text/css" href="http://codemirror.net/theme/twilight.css"/>
  </head>
  <body>

    <!-- Le content... -->
    <section>
      <div ui-codemirror="{
          lineNumbers: true,
          theme:'twilight',
          readOnly: 'nocursor',
          lineWrapping : true,
          mode: 'xml'
        }" >&lt;html style=&quot;color: green&quot;&gt;
        &lt;!-- this is a comment --&gt;
        &lt;head&gt;
        &lt;title&gt;HTML Example&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
        The indentation tries to be &lt;em&gt;somewhat &amp;quot;do what
        I mean&amp;quot;&lt;/em&gt;... but might not match your style.
        &lt;/body&gt;
        &lt;/html&gt;</div>
    </section>

    <!-- Le vendor... -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
    <script src="http://codemirror.net/lib/codemirror.js"></script>
    <script src="http://codemirror.net/mode/xml/xml.js"></script>
    <script src="https://rawgithub.com/angular-ui/ui-codemirror/bower/ui-codemirror.min.js"></script>
    <script src="app.js"></script>
  </body>
</html>

JavaScript:

var app = angular.module('x', ['ui.codemirror']);
2

There are 2 answers

0
Ouroborus On BEST ANSWER

If your page is loaded over HTTPS, the browser will usually refuse to also load active content assets (javascript, .woff fonts) over HTTP. (This will show as an error in the browser's development console.)

There are several forms of urls and they should be preferred in this order:

  • document-relative url (app.js)
  • root-relative url (/app.js)
  • protocol-relative url (//codemirror.net/lib/codemirror.js)
  • fully qualified url (https://codemirror.net/lib/codemirror.js)

For third party assets on servers that support both HTTP and HTTPS, that gives us protocol-relative urls. This type of url uses whatever protocol (HTTP: or HTTPS:) the page used. (A minor problem with this type of url is that they fail when loading the page directly from the file system as the browser attempts to load the third-party resource using the FILE: protocol. To solve this, development should always be done in conjunction with a web server, local or otherwise.)

The servers of the third party assets you've included support both HTTP and HTTPS so using protocol-relative urls for those assets is preferred:

//codemirror.net/lib/codemirror.css
//codemirror.net/theme/twilight.css
//ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js
//codemirror.net/lib/codemirror.js
//codemirror.net/mode/xml/xml.js
//rawgithub.com/angular-ui/ui-codemirror/bower/ui-codemirror.min.js
0
Serg Chernata On

In your jsbin, you're loading codemirror files over http instead of https and thus they're being blocked.

https://gist.github.com/anonymous/2c0c41530b3da4a44b301b36bee922f6

I had to change both, js and css to be loaded over https.