From d247560fca437d050d484b684f69fb43888fc21f Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Sat, 20 May 2017 15:24:44 +0200 Subject: [PATCH] Added read more for statements --- Gemfile | 3 +++ Gemfile.lock | 3 +++ app/assets/javascripts/application.js | 1 + app/assets/javascripts/statements.js | 25 +++++++++++++++++++++++++ app/assets/stylesheets/statements.sass | 3 +++ app/views/layouts/application.html.slim | 5 ++++- app/views/pages/statements.de.slim | 2 +- config/locales/de.yml | 3 ++- config/locales/fr.yml | 1 + config/locales/it.yml | 1 + 10 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/statements.js diff --git a/Gemfile b/Gemfile index 2e93b7f..afd2ac4 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,9 @@ gem 'aws-sdk' # A fixtures replacement gem 'factory_girl' +# It's a small library to provide the Rails I18n translations on the JavaScript. +gem "i18n-js" + # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 8a645e8..0b54fca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -119,6 +119,8 @@ GEM tilt heapy (0.1.2) i18n (0.8.1) + i18n-js (3.0.0) + i18n (~> 0.6, >= 0.6.6) jbuilder (2.6.3) activesupport (>= 3.0.0, < 5.2) multi_json (~> 1.2) @@ -345,6 +347,7 @@ DEPENDENCIES factory_girl faker geocoder + i18n-js jbuilder (~> 2.0) jquery-rails kaminari-actionview diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 04c72e7..c4b3a9a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,4 +15,5 @@ //= require bootstrap-sprockets //= require typeahead.bundle //= require markerclusterer_compiled +//= require i18n/translations //= require_tree . diff --git a/app/assets/javascripts/statements.js b/app/assets/javascripts/statements.js new file mode 100644 index 0000000..a3636fc --- /dev/null +++ b/app/assets/javascripts/statements.js @@ -0,0 +1,25 @@ +$(document).ready(function(){ + $('.statement p').each(function(){ + var trimLength = 300; + var trimMargin = 1.2; // don't trim just a couple of words + if($(this).text().length > (trimLength * trimMargin)) { + var text = $(this).text(); + var trimPoint = $(this).text().indexOf(" ", trimLength); + var newContent = text.substring(0, trimPoint)+''+text.substring(trimPoint)+'... ' + I18n.t("pages.statements.read_more"); + + ''; + $(this).html(newContent); + } + }); + $('.toggle a').click(function(e){ + e.preventDefault(); + var para = $(this).closest('p'); + var initialHeight = $(this).closest('p').innerHeight(); + para.find('.read-more').show(); + para.find('.toggle').hide(); + var newHeight = para.innerHeight(); + para.css('max-height', initialHeight+'px'); + para.animate({ maxHeight: newHeight }, 300, function(){ + para.css('max-height', 'none'); + }); + }); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/statements.sass b/app/assets/stylesheets/statements.sass index 92aa1ec..c875275 100644 --- a/app/assets/stylesheets/statements.sass +++ b/app/assets/stylesheets/statements.sass @@ -13,6 +13,9 @@ font-size: $font-size-base margin: 0px display: inline + + .read-more + display: none @media (max-width: 800px) .statement diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 8d33cda..12620e2 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -75,4 +75,7 @@ html lang="#{I18n.locale}" = render 'contact' .col-xs-12.col-sm-2 = render 'address' - \ No newline at end of file + + javascript: + I18n.defaultLocale = "#{I18n.default_locale}"; + I18n.locale = "#{I18n.locale}"; \ No newline at end of file diff --git a/app/views/pages/statements.de.slim b/app/views/pages/statements.de.slim index 4e8c17e..f181ab0 100644 --- a/app/views/pages/statements.de.slim +++ b/app/views/pages/statements.de.slim @@ -8,7 +8,7 @@ h1 = title t('.title') - unless supporter.publicity.organisation.blank? em= ", #{supporter.publicity.organisation}" br - = supporter.publicity.statement + p = supporter.publicity.statement hr.clearfix .text-center = link_to t(".submit_your_own_statement"), new_publicity_path \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index c2778b0..2611e84 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -25,7 +25,7 @@ de: counter: supporters: "Unterstützer:" - amount_of_supporters: Zurzeit haben wir %{amount} Unterstützer. + amount_of_supporters: Zurzeit haben wir %{amount} Unterstützer. input_error: Deine Eingaben konnte nicht gespeichert werden. Überprüfe deine Eingaben. donation: Deine Spende @@ -105,6 +105,7 @@ de: statements: title: Statements von unseren Unterstützern submit_your_own_statement: Veröffentliche dein eigenes Statement... + read_more: das ganze Statement lesen. routes: initiative_text: initiativtext diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3db06ae..d4b0e2a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -102,6 +102,7 @@ fr: statements: title: Les déclarations de nos partisans submit_your_own_statement: Publie tes propres déclaration ... + read_more: lire toute la déclaration. routes: initiative_text: l_initiative_propose diff --git a/config/locales/it.yml b/config/locales/it.yml index a401945..8895254 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -106,6 +106,7 @@ it: statements: title: Dichiarazioni di nostri sostenitori submit_your_own_statement: Pubblica il tuo propria dichiarazione ... + read_more: leggere l'intero. routes: initiative_text: il_testo_dell_iniziativa