GitbookIO / plugin

Sample plugin for GitBook
Apache License 2.0
66 stars 56 forks source link

Is it possible to load js file at start of the body instead of before end of the body #10

Closed saturngod closed 10 years ago

saturngod commented 10 years ago

I want to add ace editor in markdown. However, ace.js always call at the end of the page.

Example like following,

<body>
.....
<script>
var editor = ace.edit('code');
</script>
....
....
...
<script src="../gitbook/plugins/pywebtest-gitbook/editor/ace.js"></script>
</body>

ace.js at the bottom. So, ace.edit can't use anymore because ace object didn't found.

I try to use with

document.addEventListener('DOMContentLoaded', function(){
var editor = ace.edit('code');
})

It's not working with ajax call. But working with direct URL or refresh the page.

When navigate , ajax call and change the page. So, DOMContentLoaded is not working.

If I can put ace.js after <body> , it will be better and no need DOMContentLoaded any more.

saturngod commented 10 years ago

Fixed base on https://github.com/GitbookIO/plugin-mixpanel code.

I use like following

gitbook.events.bind("page.change", function() {
       load_editor();
    });