joseph / Monocle

A silky, tactile browser-based ebook JavaScript library.
http://monocle.inventivelabs.com.au
MIT License
743 stars 200 forks source link

Stencil opening links outside of reader in version 3.1.0 #180

Open lmvco opened 11 years ago

lmvco commented 11 years ago

Hi,

Doing tests to stencil test page of 3.1.0 version (http://test.monoclejs.com/test/stencil/index.html), I realized that links are not opening inside current reader instance but, instead, they are being opened in a new browser tab/window with the component contents (even in good links).

Doing tests to previous versions (e.g 3.0.1), I cannot repro this issue.

Was stencil changed recently?

arthurdarcet commented 11 years ago

In addition to this issue, stencil discard the anchor part of the link, so it cannot support href="#footnote" kind of links. A quick fix for this is :

Monocle.Events.listen('reader', 'monocle:componentchange', function(evt) {
    var doc = evt.m.page.m.activeFrame.contentDocument;
    $(doc).find('a').each(function(i){
        this.onclick = function(e){
            if (this.getAttribute('href')[0] == '#') {
                // this.href return the completely specified url
                var name = this.getAttribute('href').substring(1);
                App.reader.moveTo({selector: 'a[name="' + name + '"]'});
                return false;
            }
        };
    });
});

I think a proper fix for this issue would be to replace the skipToChapter here : https://github.com/joseph/Monocle/blob/master/src/controls/stencil.js#L317 by a moveTo({component:, selector:});

Arthur