fix relative link handling

This commit is contained in:
Anton Dyudin 2015-10-21 13:24:29 -07:00
parent 03a885c997
commit 2aec4aba27
2 changed files with 30 additions and 24 deletions

View File

@ -103,17 +103,12 @@ module.exports = query {
$('body').on 'click', CLICK, (e) ->
href = $(@).attr('href')
id = $(@).attr('id')
if href
if not /^https?:\/\//i.test(href)
if href?[0] is "/"
e.preventDefault()
e.stopPropagation()
_this.goTo window.tree.fragpath href
else
e.preventDefault()
e.stopPropagation()
base = window.tree.fragpath(document.location.pathname)
_this.goTo base+"/#{href}"
if href and not /^https?:\/\//i.test(href)
e.preventDefault()
e.stopPropagation()
if href?[0] isnt "/"
href = (document.location.pathname.replace /[^\/]*$/, '') + href
_this.goTo window.tree.fragpath href
if id
window.location.hash = id

View File

@ -35,6 +35,7 @@ module.exports = {
};
},{"../dispatcher/Dispatcher.coffee":14,"../persistence/TreePersistence.coffee":20}],2:[function(require,module,exports){
var BodyComponent, CLICK, Links, TreeActions, TreeStore, a, clas, div, query, reactify, recl, ref;
@ -228,22 +229,16 @@ module.exports = query({
this.interval = setInterval(this.checkURL, 100);
_this = this;
return $('body').on('click', CLICK, function(e) {
var base, href, id;
var href, id;
href = $(this).attr('href');
id = $(this).attr('id');
if (href) {
if (!/^https?:\/\//i.test(href)) {
if ((href != null ? href[0] : void 0) === "/") {
e.preventDefault();
e.stopPropagation();
_this.goTo(window.tree.fragpath(href));
} else {
e.preventDefault();
e.stopPropagation();
base = window.tree.fragpath(document.location.pathname);
_this.goTo(base + ("/" + href));
}
if (href && !/^https?:\/\//i.test(href)) {
e.preventDefault();
e.stopPropagation();
if ((href != null ? href[0] : void 0) !== "/") {
href = (document.location.pathname.replace(/[^\/]*$/, '')) + href;
}
_this.goTo(window.tree.fragpath(href));
}
if (id) {
return window.location.hash = id;
@ -321,6 +316,7 @@ module.exports = query({
}));
},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":21,"./Async.coffee":3,"./BodyComponent.coffee":4,"./Reactify.coffee":11,"classnames":16}],3:[function(require,module,exports){
var TreeActions, TreeStore, _load, code, div, recl, ref, span;
@ -431,6 +427,7 @@ module.exports = function(queries, Child, load) {
};
},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":21,"./LoadComponent.coffee":10}],4:[function(require,module,exports){
var Next, a, div, img, p, query, reactify, recl, ref;
@ -515,6 +512,7 @@ module.exports = query({
}));
},{"./Async.coffee":3,"./Reactify.coffee":11}],5:[function(require,module,exports){
var div, recl, ref, textarea;
@ -538,6 +536,7 @@ module.exports = recl({
});
},{}],6:[function(require,module,exports){
var div, recl;
@ -560,6 +559,7 @@ module.exports = {
};
},{"./CodeMirror.coffee":5,"./EmailComponent.coffee":7,"./KidsComponent.coffee":8,"./ListComponent.coffee":9,"./SearchComponent.coffee":12,"./TocComponent.coffee":13}],7:[function(require,module,exports){
var button, div, input, p, reactify, recl, ref;
@ -640,6 +640,7 @@ module.exports = recl({
});
},{"./Reactify.coffee":11}],8:[function(require,module,exports){
var a, div, hr, li, query, reactify, recl, ref, ul;
@ -711,6 +712,7 @@ module.exports = query({
}));
},{"./Async.coffee":3,"./Reactify.coffee":11}],9:[function(require,module,exports){
var a, clas, div, h1, li, query, reactify, recl, ref, ul;
@ -858,6 +860,7 @@ module.exports = query({
}));
},{"./Async.coffee":3,"./Reactify.coffee":11,"classnames":16}],10:[function(require,module,exports){
var div, input, recl, ref, textarea;
@ -898,6 +901,7 @@ module.exports = recl({
});
},{}],11:[function(require,module,exports){
var Virtual, div, load, reactify, recl, ref, rele, span, walk;
@ -965,6 +969,7 @@ module.exports = _.extend(reactify, {
});
},{"./LoadComponent.coffee":10}],12:[function(require,module,exports){
var a, div, input, query, reactify, recl, ref,
slice = [].slice;
@ -1103,6 +1108,7 @@ module.exports = query({
}));
},{"./Async.coffee":3,"./Reactify.coffee":11}],13:[function(require,module,exports){
var div, query, reactify, recl,
slice = [].slice;
@ -1231,6 +1237,7 @@ module.exports = query({
}));
},{"./Async.coffee":3,"./Reactify.coffee":11}],14:[function(require,module,exports){
var Dispatcher;
@ -1252,6 +1259,7 @@ module.exports = _.extend(new Dispatcher(), {
});
},{"flux":17}],15:[function(require,module,exports){
var rend;
@ -1422,6 +1430,7 @@ $(function() {
});
},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Components.coffee":6,"./persistence/TreePersistence.coffee":20}],16:[function(require,module,exports){
/*!
Copyright (c) 2015 Jed Watson.
@ -1849,6 +1858,7 @@ module.exports = {
};
},{}],21:[function(require,module,exports){
var EventEmitter, MessageDispatcher, QUERIES, TreeStore, _curr, _data, _tree, clog;
@ -2074,6 +2084,7 @@ TreeStore.dispatchToken = MessageDispatcher.register(function(payload) {
module.exports = TreeStore;
},{"../dispatcher/Dispatcher.coffee":14,"events":22}],22:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//