From 35c3974d0d257a37172242bc378702277663c385 Mon Sep 17 00:00:00 2001 From: Galen Wolfe-Pauly Date: Wed, 5 Aug 2015 18:59:57 -0700 Subject: [PATCH] sorting the anchor --- .../src/js/components/AnchorComponent.coffee | 8 +++++++- pub/tree/src/js/main.js | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pub/tree/src/js/components/AnchorComponent.coffee b/pub/tree/src/js/components/AnchorComponent.coffee index 5250925e67..2574448bc6 100644 --- a/pub/tree/src/js/components/AnchorComponent.coffee +++ b/pub/tree/src/js/components/AnchorComponent.coffee @@ -20,7 +20,13 @@ Links = React.createFactory query { displayName: "Links" render: -> div {className:'links'}, @props.children, @_render() _render: -> - keys = _(@props.kids).keys().sort() + sorted = true + keys = [] + for k,v of @props.kids + if not v.meta.sort then sorted = false + keys[Number(v.meta.sort)] = k + if sorted isnt true + keys = _(@props.kids).keys().sort() style = {marginTop: -24 * (keys.indexOf @props.curr) + "px"} div {id:"sibs",style}, keys.map (key) => href = window.tree.basepath @props.path+"/"+key diff --git a/pub/tree/src/js/main.js b/pub/tree/src/js/main.js index 8f3afe4d57..893b74c8c4 100644 --- a/pub/tree/src/js/main.js +++ b/pub/tree/src/js/main.js @@ -91,8 +91,20 @@ Links = React.createFactory(query({ }, this.props.children, this._render()); }, _render: function() { - var keys, style; - keys = _(this.props.kids).keys().sort(); + var k, keys, ref1, sorted, style, v; + sorted = true; + keys = []; + ref1 = this.props.kids; + for (k in ref1) { + v = ref1[k]; + if (!v.meta.sort) { + sorted = false; + } + keys[Number(v.meta.sort)] = k; + } + if (sorted !== true) { + keys = _(this.props.kids).keys().sort(); + } style = { marginTop: -24 * (keys.indexOf(this.props.curr)) + "px" };