Skip to content

Commit

Permalink
Refactor Accordion JS and fix scrollToActive
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Feb 10, 2015
1 parent 6e451cc commit 35115ec
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 44 deletions.
55 changes: 25 additions & 30 deletions app/assets/javascripts/visual/accordion.coffee
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)
2 changes: 1 addition & 1 deletion app/views/articles/show/_commendation_label.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

- case label
- when :bike_courier
=<> link_to fa_icon('bicycle'), link, class: "#{commendation_label_classes} accordion-anchor ungrouped_colorbox"
=<> link_to fa_icon('bicycle'), link, class: "#{commendation_label_classes} ungrouped_colorbox"
-else
- if local_assigns.has_key?(:link) && link
=<> link_to t("article.commendations.#{label.to_s}"), link,
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
= link_to t('devise.links.back_to_my_profile'), user_path(@user)
h1= t('common.actions.edit_profile')

.Accordion.user-edit
.Accordion.Accordion--scrollToActive.user-edit
= semantic_form_for(@user, html: {multipart: true, autocomplete: "off", class: 'js-visual-submit'}, as: resource_name, url: registration_path(resource_name), builder: ::Fairtastic::FormBuilder) do |f|
= f.semantic_errors
= f.input_step :account, default_step: true do
Expand Down
28 changes: 21 additions & 7 deletions app/views/users/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,39 @@
/ along with Fairmondo. If not, see <http://www.gnu.org/licenses/>.
/
= render 'header'

- if resource.is? current_user
/ Show own articles, line item groups and templates for user
.Accordion.Accordion--activated.Accordion--scrollToActive
= render '/users/show/article_accordion', item_name: 'active', item_link: new_article_path, articles: active_articles
= render '/users/show/article_accordion', item_name: 'inactive', articles: inactive_articles
= render '/users/show/line_item_group_accordion', item_name: 'seller_line_item_groups', line_item_groups: sold_line_item_groups
= render '/users/show/line_item_group_accordion', item_name: 'buyer_line_item_groups', line_item_groups: bought_line_item_groups
= render '/users/show/article_accordion',
item_name: 'active',
item_link: new_article_path,
articles: active_articles
= render '/users/show/article_accordion',
item_name: 'inactive',
articles: inactive_articles
= render '/users/show/line_item_group_accordion',
item_name: 'seller_line_item_groups',
line_item_groups: sold_line_item_groups
= render '/users/show/line_item_group_accordion',
item_name: 'buyer_line_item_groups',
line_item_groups: bought_line_item_groups
/ TODO change partial names and contents
= accordion_item 'my_article_templates' do
p
= link_to t('article_templates.actions.new'), new_article_template_path, class: 'Button'
= link_to t('article_templates.actions.new'),
new_article_template_path,
class: 'Button'
span.sprite_helper title='Wenn Du einen neuen Artikel einstellst, kannst Du alle Angaben als Vorlage speichen.'
= render "article_templates/table", :article_templates => resource.article_templates
= render "article_templates/table",
article_templates: resource.article_templates
- if resource.is_a?(LegalEntity) && resource.mass_uploads.any?
= accordion_item 'my_mass_uploads' do
= render 'mass_uploads/table'


- else
/ Show user's articles for other visitors
.articles
= render '/articles/shared/articles_grid', articles: @articles
= paginate @articles, param_name: 'active_articles_page'
18 changes: 13 additions & 5 deletions app/views/users/show/_article_accordion.html.slim
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"

0 comments on commit 35115ec

Please sign in to comment.