bootstrap-wysiwyg / bootstrap3-wysiwyg

Simple, beautiful wysiwyg editor
http://bootstrap-wysiwyg.github.io/bootstrap3-wysiwyg/
MIT License
834 stars 264 forks source link

Selecting heading style throws error "Rangy.saveSelection is not a function" #130

Closed thenitai closed 9 years ago

thenitai commented 9 years ago

Hi there,

Loading your library with require.js. Everything works fine except header selection. Throws above error at line 8835:

// TODO: Figure out a method from following 3 that would work universally
    executeAndRestoreRangy: function(method, restoreScrollPosition) {
      var win = this.doc.defaultView || this.doc.parentWindow,
          sel = rangy.saveSelection(win);

Hope this helps.

atzoya commented 9 years ago

Hi thenitai,

I've been having the same issue you are having, and i think i found why it has been happening. It turns out that the module 'rangy-selectionsaverestore' wasn't loaded in my case, and that's where rangy's method saveSelection is defined.

Try and define the 'rangy-selectionsaverestore' as a dependency to the 'bootstrap.wysihtml5' module and the problem will disappear.

Hope that helps.

thenitai commented 9 years ago

Sounding like a ignorant here, but how to define it as a dependency?

Thank you :-)

atzoya commented 9 years ago

You can do that in the main.js file (where you list all the require.js modules) using the shim http://requirejs.org/docs/api.html#config-shim . Here's an example (your paths probably are different):

require.config({
 paths: {
        'bootstrap.wysihtml5': '../editor/bootstrap3-wysihtml5',
        'rangy': '../editor/rangy-core',
        'rangy-selectionsaverestore': '../editor/rangy-selectionsaverestore',
},
shim: {
 'bootstrap.wysihtml5' : { deps: ['rangy-selectionsaverestore'] }
}

Or you can just add the 'rangy-selectionsaverestore' in the define of the module where you are using the editor itself.

thenitai commented 9 years ago

Ah... I've already had the rangy-core in there, never thought about to add the other one.

Thank you! :+1:

thenitai commented 9 years ago

For the after world here is my config:

 paths: {
        ...
        'rangy': 'rangy-1.3/rangy-core',
        'rangy-selectionsaverestore': 'rangy-1.3/rangy-selectionsaverestore',
        'bootstrap.wysihtml5': 'wysiwyg/amd/bootstrap3-wysihtml5.all',
        'bootstrap.wysihtml5.en-US': 'wysiwyg/locales/bootstrap-wysihtml5.en-US',
        ...
    },
    shim: {
        ...
        'bootstrap.wysihtml5' : { deps: ['rangy','rangy-selectionsaverestore'] },
        ...
    }