Fixed links on full docs

This commit is contained in:
Sashko Stubailo
2014-10-23 10:50:57 -07:00
parent a629c46543
commit c41269161b
31 changed files with 60 additions and 40 deletions

View File

@@ -15,4 +15,5 @@ simple:markdown-templating
simple:highlight.js
less
chrismbeckett:fontawesome4
iron:location

View File

@@ -22,6 +22,9 @@ html-tools@1.0.2
htmljs@1.0.2
http@1.0.7
id-map@1.0.1
iron:core@1.0.0-pre4
iron:location@1.0.0-pre4
iron:url@1.0.0-pre4
jquery-waypoints@1.0.1
jquery@1.0.1
json@1.0.1

View File

@@ -142,12 +142,12 @@ Template.autoApiBox.helpers({
return signature;
},
link: function () {
if (nameToId[this.longname]) {
if (Session.get("fullApi") && nameToId[this.longname]) {
return nameToId[this.longname];
}
// fallback
return this.longname.replace(".", "-");
return this.longname.replace(/[.#]/g, "-");
},
paramsNoOptions: function () {
return _.reject(this.params, function (param) {

View File

@@ -120,12 +120,12 @@ Template.basicTableOfContents.helpers({
var self = this;
if (self.id) {
return "#b-" + self.id;
return "#" + self.id;
} else if (self.longname) {
return "#b-" + self.longname.replace(/[#.]/g, "-");
return "#" + self.longname.replace(/[#.]/g, "-");
}
},
linkForSection: function () {
return "#b-" + this.id;
return "#" + this.id;
}
});

View File

@@ -1,5 +1,6 @@
<template name="fullApiContent">
{{> introduction }}
{{> concepts }}
{{> api }}
{{> packages }}
</template>

View File

@@ -70,21 +70,8 @@ Meteor.startup(function () {
});
};
$('#main, #nav').delegate("a[href^='#']", 'click', function (evt) {
evt.preventDefault();
var sel = $(this).attr('href');
scrollToSection(sel);
mixpanel.track('docs_navigate_' + sel);
});
// Make external links open in a new tab.
$('a:not([href^="#"])').attr('target', '_blank');
// Hide menu by tapping on background
$('#main').on('click', function () {
hideMenu();
});
});
var hideMenu = function () {

View File

@@ -40,10 +40,3 @@
<h6>{{> UI.contentBlock}}</h6>
{{/if}}
</template>
<template name="basicOrFullSelect">
<select class="basic-or-full">
<option value="basic" selected="{{isBasic}}">Basic Docs</option>
<option value="full" selected="{{isFull}}">Full API</option>
</select>
</template>

View File

@@ -389,19 +389,4 @@ Template.nav_section.helpers({
depthIs: function (n) {
return this.depth === n;
}
});
Template.basicOrFullSelect.events({
"change .basic-or-full": function (event) {
Session.set("fullApi", event.target.value === "full");
}
});
Template.basicOrFullSelect.helpers({
isBasic: function () {
return ! Session.get("fullApi");
},
isFull: function () {
return Session.get("fullApi");
}
});

View File

@@ -49,4 +49,11 @@
<i class="open-sidebar fa fa-bars"></i>
<h1>Meteor 1.0 Docs</h1>
</div>
</template>
<template name="basicOrFullSelect">
<select class="basic-or-full">
<option value="basic" selected="{{isBasic}}">Basic Docs</option>
<option value="full" selected="{{isFull}}">Full API</option>
</select>
</template>

View File

@@ -1,3 +1,19 @@
Template.registerHelper("fullApi", function () {
return Session.get("fullApi");
});
Template.basicOrFullSelect.events({
"change .basic-or-full": function (event) {
Session.set("fullApi", event.target.value === "full");
Iron.Location.go(Session.equals("fullApi", true) ? "/full" : "/basic");
}
});
Template.basicOrFullSelect.helpers({
isBasic: function () {
return ! Session.get("fullApi");
},
isFull: function () {
return Session.get("fullApi");
}
});

27
docs/client/links.js Normal file
View File

@@ -0,0 +1,27 @@
Tracker.autorun(function () {
// returns a "location" like object with all of the url parts
var current = Iron.Location.get();
console.log(current);
if (current.path === "/basic") {
Session.set("fullApi", false);
} else if (current.path === "/full") {
Session.set("fullApi", true);
} else {
if (current.hash) {
// XXX COMPAT WITH old docs
Iron.Location.go("/full");
} else {
Iron.Location.go("/basic");
}
}
Tracker.afterFlush(function () {
setTimeout(function () {
console.log($(".main-content").offset(), $(current.hash).offset());
$(".main-content").animate({
scrollTop: $(".main-content").scrollTop() + $(current.hash).offset().top
}, 1000);
}, 0);
});
});