-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Accordion JS and fix scrollToActive
- Loading branch information
Marc Altmann
committed
Feb 10, 2015
1 parent
6e451cc
commit 35115ec
Showing
5 changed files
with
61 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
accordion = -> | ||
target = 0 | ||
if window.location.hash | ||
target = $(window.location.hash).siblings().andSelf().index($(window.location.hash)) | ||
else | ||
target = $('.Accordion-item--active').index() if $('.Accordion-item--active').length > 0 | ||
target = $(window.location.hash).index() | ||
else if $('.Accordion-item--active').length > 0 | ||
target = $('.Accordion-item--active').index() | ||
|
||
$(".accordion-anchor").click -> | ||
link = $(event.target).attr('href') | ||
target = $(link).index('.Accordion-item') | ||
$(".Accordion--activated").accordion | ||
animate: false | ||
active: target | ||
|
||
$(".Accordion").accordion | ||
header: "a.Accordion-header" | ||
heightStyle: "content" | ||
$('.Accordion:not(.Accordion--activated)').accordion | ||
header: 'a.Accordion-header' | ||
heightStyle: 'content' | ||
collapsible: true | ||
animate: 400 | ||
active: false | ||
|
||
$(".Accordion--activated").accordion | ||
header: "a.Accordion-header" | ||
heightStyle: "content" | ||
$('.Accordion--activated').accordion | ||
header: 'a.Accordion-header' | ||
heightStyle: 'content' | ||
collapsible: true | ||
animate: 400 | ||
active: target | ||
|
||
$(".Accordion--scrollToActive").on "accordionactivate", (event,ui) -> | ||
if ui.newHeader.length isnt 0 && target | ||
$('html, body').animate | ||
scrollTop: ui.newHeader.offset().top | ||
, 100 | ||
$('.Accordion') | ||
.removeClass('ui-accordion ui-widget ui-helper-reset') | ||
$('.Accordion-header') | ||
.removeClass('ui-accordion-header ui-helper-reset ui-state-default ' + | ||
'ui-accordion-header-active ui-corner-top ui-accordion-icons ' + | ||
'ui-state-focus') | ||
$('.Accordion-header span') | ||
.removeClass('ui-accordion-header-icon ui-icon ui-icon-triangle-1-s') | ||
|
||
|
||
$(".Accordion").removeClass("ui-accordion ui-widget ui-helper-reset") | ||
$(".Accordion-header").removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-accordion-header-active ui-corner-top ui-accordion-icons ui-state-focus") | ||
$(".Accordion-header span").removeClass("ui-accordion-header-icon ui-icon ui-icon-triangle-1-s") | ||
# Event handlers | ||
$('.Accordion--scrollToActive').on 'accordionactivate', (event, ui) -> | ||
console.log 'onAccordionactivate' | ||
unless ui.newHeader.length is 0 | ||
$('html, body').animate | ||
scrollTop: ui.newHeader.offset().top | ||
, 400 | ||
|
||
|
||
$(document).on( | ||
'page:done' | ||
(event, $target, status, url, data) -> | ||
accordion() | ||
) | ||
$(document).ready accordion | ||
$(document).on('page:done ready', accordion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
= accordion_item item_name do | ||
= accordion_item item_name do | ||
- if articles.empty? | ||
p | ||
- if local_assigns.has_key? :item_link | ||
strong= t("users.text.no_#{item_name}_html", href: link_to(t("users.text.no_#{item_name}"), item_link )) | ||
strong= t("users.text.no_#{item_name}_html", | ||
href: link_to(t("users.text.no_#{item_name}"), item_link )) | ||
- else | ||
strong= t("users.text.no_#{item_name}") | ||
- else | ||
.ArticleListview | ||
- articles.each do |article| | ||
= render '/articles/shared/listitem', article: article | ||
|
||
= paginate articles, link_attributes: { data: {scroll: false} }, params: { active_accordion: item_name } , param_name: "#{item_name}_articles_page" | ||
= paginate articles, | ||
link_attributes: { data: {scroll: false} }, | ||
params: { active_accordion: item_name }, | ||
param_name: "#{item_name}_articles_page" | ||
|
||
- if current_user.type == "LegalEntity" | ||
p | ||
- unless articles.empty? | ||
= link_to t('mass_uploads.labels.update_articles_via_csv'), new_mass_upload_path, class: "Button" | ||
= link_to t("articles.export.#{item_name}"), exports_show_path(kind_of_article: item_name, format: "csv"), class: "Button" | ||
= link_to t('mass_uploads.labels.update_articles_via_csv'), | ||
new_mass_upload_path, | ||
class: "Button" | ||
= link_to t("articles.export.#{item_name}"), | ||
exports_show_path(kind_of_article: item_name, format: "csv"), | ||
class: "Button" | ||
|