Skip to content

Commit

Permalink
Fix accordion issues, for #1285 and for #1311
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Feb 11, 2015
1 parent 09913fb commit db6a2c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
31 changes: 25 additions & 6 deletions app/assets/javascripts/visual/accordion.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ accordion = ->
heightStyle: 'content'
collapsible: true
animate: 400
active: 0
active: false


$accordions
Expand All @@ -28,7 +28,9 @@ accordion = ->
.removeClass('ui-accordion-header-icon ui-icon ui-icon-triangle-1-s')


# Event handler for scrolling
# event handlers

# for scrolling
$accordions
.filter('.Accordion--scrollToActive')
.on('accordionactivate', (event, ui) ->
Expand All @@ -39,10 +41,27 @@ accordion = ->
)


# If there is a fragment identifier that belongs to an .Accordion-item,
# activate it. Scrolling is done via the 'accordionactivate' event.
$target_el = $('.Accordion-item' + window.location.hash)
if window.location.hash and $target_el.length > 0
# Open accordion if anchor link is clicked
# TODO: Refactor both handlers, very similar
$('.accordion-anchor').click ->
$target_el = $($(@).attr('href'))
target_index = $target_el
.siblings('.Accordion-item')
.addBack()
.index($target_el)
$target_el
.closest('.Accordion')
.accordion('option', 'active', target_index)


# Open specific accordion on load, either via fragment identifier
# or if one accordion has a class of .Accordion-item--active (workaround
# for wiselinks)
$target_el = $('.Accordion-item--active')
if $target_el.length is 0 and window.location.hash
$target_el = $('.Accordion-item' + window.location.hash)

if $target_el.length > 0
target_index = $target_el
.siblings('.Accordion-item')
.addBack()
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_accordion_layout.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/ You should have received a copy of the GNU Affero General Public License
/ along with Fairmondo. If not, see <http://www.gnu.org/licenses/>.
/
.Accordion-item id=accordion_name class=accordion_item_class
.Accordion-item id=accordion_name class="#{accordion_item_class}#{params[:active_accordion]==accordion_name ? ' Accordion-item--active' : '' }"
a href="##{accordion_name}" class="Accordion-header #{accordion_header_class}"
- if accordion_arrow
i.icon-arrow
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show/_article_accordion.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

= paginate articles,
link_attributes: { data: {scroll: false} },
params: { anchor: item_name },
params: { active_accordion: item_name },
param_name: "#{item_name}_articles_page"

- if current_user.type == "LegalEntity"
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show/_line_item_group_accordion.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
line_item_group: group
= paginate line_item_groups,
link_attributes: { data: {scroll: false} },
params: { anchor: item_name },
params: { active_accordion: item_name },
param_name: "#{item_name}_page"

/ - if current_user.type == 'LegalEntity' && item_name == 'seller_line_item_groups'
Expand Down

0 comments on commit db6a2c2

Please sign in to comment.