Draft text index tree navigator

This commit is contained in:
Fernando Blat
2017-01-19 11:02:45 +01:00
parent 4c5fde956f
commit cba1f8bd9d
3 changed files with 36 additions and 2 deletions

View File

@@ -56,6 +56,7 @@
//= require legislation_allegations
//= require legislation_annotatable
//= require watch_form_changes
//= require tree_navigator
//= require custom
var initialize_modules = function() {
@@ -87,6 +88,7 @@ var initialize_modules = function() {
if ( $(".legislation-annotatable").length )
App.LegislationAnnotatable.initialize();
App.WatchFormChanges.initialize();
App.TreeNavigator.initialize();
};
$(function(){

View File

@@ -0,0 +1,32 @@
App.TreeNavigator =
closeNodes: (nodes) ->
children = nodes.children('ul')
if(children.length == 0)
return
children.each ->
link = $(this).prev('a')
$('<span class="closed"></span>').insertBefore(link)
$(this).hide()
App.TreeNavigator.closeNodes($(this).children())
initialize: ->
elem = $('[data-tree-navigator]')
if(elem.length == 0)
return
ul = elem.find('ul:eq(0)')
if(ul.length && ul.children().length)
App.TreeNavigator.closeNodes(ul.children())
$('[data-tree-navigator] span').on
click: (e) ->
elem = $(this)
if(elem.hasClass('open'))
elem.removeClass('open').addClass('closed')
elem.siblings('ul').hide()
else if(elem.hasClass('closed'))
elem.removeClass('closed').addClass('open')
elem.siblings('ul').show()

View File

@@ -38,9 +38,9 @@
<div class="draft-index-rotated center">
<span class="panel-title"><%= t('.text_toc') %></span>
</div>
<div data-sticky-container>
<div data-sticky data-anchor="sticky-panel" class="draft-index sticky">
<div data-sticky data-anchor="sticky-panel" class="draft-index sticky" data-tree-navigator>
<%= @draft_version.toc_html.html_safe %>
</div>
</div>