Commit b3ed56cd authored by eric's avatar eric

Basic namespace support in navigation.

parent cf57dbbb
......@@ -211,8 +211,12 @@ nav {
font-size: 13.33px;
}
nav li {
list-style-position: inside;
list-style-type: disc;
list-style-position: outside;
list-style-type: none;
margin-left: 14px;
}
nav > ul > li {
margin-left: 0;
}
nav li#create-pad {
list-style-type: none;
......
$(window).load(function(){
h = $("div#content").height();
$("iframe#ether").height(h);
$(window).load(function() {
h = $("div#content").height();
$("iframe#ether").height(h);
});
// just for testing:
var pads = ["2013::debrief", "2013::general-publication", "2013::introducing-by-couple", "2013::introduction-script", "2013::schedule", "cheat-sheet::git-and-the-command-line", "cheat-sheet::how-to-install-free-software", "cheat-sheet::tex", "cheat-sheet::tracing", "cheat-sheet::using-the-plotter", "cover", "css", "images", "notes::copyright-licenses", "notes::merging", "pedagogy::learning-situations", "pedagogy::references", "relearn::about", "relearn::contact", "relearn::repositories", "relearn::start", "relearn::utrecht", "relearn::welcome", "worksessions::can-it-scale-to-the-universe::introduction", "worksessions::can-it-scale-to-the-universe::notes", "worksessions::gesturing-paths::introduction", "worksessions::gesturing-paths::notes", "worksessions::off-grid::introduction", "worksessions::off-grid::notes", "worksessions::off-grid::xtreme-pattern-methods"];
var navigation = function(padLinks) {
var setupPads = function(padLinks) {
return _.map(padLinks, function(padLink) {
// "/r/cooking-with-epub".replace(/\/[^\/]+\//, '') -> "cooking-with-epub"
var slug = padLink.replace(/\/[^\/]+\//, '');
return {
name : slug,
slug : slug,
href : padLink,
namespaces : slug.split('::')
};
});
};
var obj = {
pads : setupPads(padLinks),
sections : {}
};
console.log(obj);
var unpackPads = function(obj) {
obj.pads = _.uniq(_.compact(_.map(obj.pads, function(pad) {
if (pad.namespaces.length > 1) {
if ( typeof obj.sections[pad.namespaces[0]] === 'undefined') {
obj.sections[pad.namespaces[0]] = {
pads : [],
sections : {}
};
}
obj.sections[pad.namespaces[0]].pads.push({
name : pad.name,
slug : pad.slug,
href : pad.href,
namespaces : pad.namespaces.splice(1)
});
return null;
} else {
return {
name : pad.namespaces[0],
slug : pad.slug,
href : pad.href
};
}
})), true);
_.each(obj.sections, function(section) {
unpackPads(section);
});
return obj;
};
return unpackPads(obj);
};
var padLinks = _.map($('#pads_list li a'), function(padLink) {
return padLink.getAttribute('href');
});
var renderSection = function(section) {
var lis = [];
var lis = lis.concat(_.map(_.keys(section.sections), function(sectionKey) {
return '<li><a class="namespace">' + sectionKey + ' →</a>' + renderSection(section.sections[sectionKey]) + '</li>';
}));
var lis = lis.concat(_.map(section.pads, function(pad) {
return '<li><a href="' + pad.slug + '">' + pad.name + '</a></li>';
}));
return '<ul>' + lis.join('') + '</ul>';
};
var padsList = $(renderSection(navigation(padLinks)));
$("#pads_list").html( padsList.html() );
This diff is collapsed.
......@@ -7,7 +7,7 @@
<link rel="stylesheet" href="{{ STATIC_URL }}css/print.css" media="print" type="text/css" charset="utf-8">
<script src="{{ STATIC_URL }}js/less-1.4.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="{{ STATIC_URL }}js/jquery-1.10.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="{{ STATIC_URL }}js/relearn.js" type="text/javascript" charset="utf-8"></script>
<script src="{{ STATIC_URL }}js/underscore-min.js" type="text/javascript" charset="utf-8"></script>
<title>{{ site_name }}{% if pad %} → {{ pad.display_name }}{% endif %}</title>
......@@ -40,6 +40,8 @@
{% if author %}
<li id="create-pad"><a class="button" href="{% url 'pad-create' author.group.all.0.id %}">Create pad</a></li>
{% endif %}
</ul>
<ul id="pads_list">
{% for pad in pads %}
<li><a href="{% if mode == 'write' %}{% url 'pad-write' slug=pad.display_slug %}{% else %}{% url 'pad-read' slug=pad.display_slug %}{% endif %}" class="pad-link">{{ pad.display_name }}</a></li>
{% endfor %}
......@@ -53,6 +55,7 @@
<h2>The right side</h2>
</div>
</div>
<script src="{{ STATIC_URL }}js/relearn.js" type="text/javascript" charset="utf-8"></script>
{% block scripts %}{% endblock %}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment