From 1561690303e640be2472016213c0efe588b74a90 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 7 Nov 2013 16:54:24 +0100 Subject: [PATCH] moved call to help backbone view init to separate file included only on faq view. extending loaded js locales. cleaned up unused routes. removed some comments. loading help locales only on help view. removed afterRender from backbone views. extended load_javascript_locales method to take a section. --- app/assets/javascripts/app/app.js | 8 -------- app/assets/javascripts/app/views.js | 5 ----- .../javascripts/app/views/faq_question_view.js | 9 +++++++-- .../javascripts/app/views/help_section_view.js | 10 ++++++---- app/assets/javascripts/app/views/help_view.js | 12 +++++++----- app/assets/javascripts/help.js | 5 +++++ app/assets/javascripts/helpers/i18n.js | 2 +- app/helpers/language_helper.rb | 15 ++------------- app/helpers/layout_helper.rb | 13 ++----------- app/views/help/faq.html.haml | 3 +++ app/views/layouts/application.html.haml | 1 - app/views/shared/_right_sections.html.haml | 2 +- config/routes.rb | 2 -- 13 files changed, 34 insertions(+), 53 deletions(-) create mode 100644 app/assets/javascripts/help.js diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 5b723aa9d..04f93abb9 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -39,7 +39,6 @@ var app = { this.setupHeader(); this.setupBackboneLinks(); this.setupGlobalViews(); - this.setupHelpViews(); this.setupDisabledLinks(); }, @@ -104,13 +103,6 @@ var app = { app.sidebar = new app.views.Sidebar(); }, - setupHelpViews: function() { - //TODO RS: Is this the right place from here? - app.help = new app.views.Help(); - $("#help").prepend(app.help.el); - app.help.render(); - }, - /* mixpanel wrapper function */ instrument : function(type, name, object, callback) { if(!window.mixpanel) { return } diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index eefc509e5..4f36dbb04 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -29,7 +29,6 @@ app.views.Base = Backbone.View.extend({ this.renderSubviews() this.renderPluginWidgets() this.removeTooltips() - this.afterRender() return this }, @@ -101,10 +100,6 @@ app.views.Base = Backbone.View.extend({ }); } }, - - afterRender: function(){ - // Do nothing - } }); app.views.StaticContentView = app.views.Base.extend({ diff --git a/app/assets/javascripts/app/views/faq_question_view.js b/app/assets/javascripts/app/views/faq_question_view.js index cec323967..28f68088d 100644 --- a/app/assets/javascripts/app/views/faq_question_view.js +++ b/app/assets/javascripts/app/views/faq_question_view.js @@ -15,10 +15,15 @@ app.views.FaqQuestionView = app.views.Base.extend({ return this.data; }, - afterRender: function(){ - var el = $(this.el) + render: function(){ + var section = app.views.Base.prototype.render.apply(this, arguments); + + // After render actions + var el = $(this.el); el.find('.question.collapsible').removeClass('opened').addClass('collapsed'); el.find('.answer').hide(); + + return section; }, toggled: function(e) { diff --git a/app/assets/javascripts/app/views/help_section_view.js b/app/assets/javascripts/app/views/help_section_view.js index 9b4a8ed48..2860cce4a 100644 --- a/app/assets/javascripts/app/views/help_section_view.js +++ b/app/assets/javascripts/app/views/help_section_view.js @@ -11,14 +11,16 @@ app.views.HelpSectionView = app.views.StaticContentView.extend({ return this; }, - afterRender: function() { - // Hide all questions + render: function(){ + var section = app.views.Base.prototype.render.apply(this, arguments); + + // After render actions $(this.el).find('.question.collapsible').removeClass('opened').addClass('collapsed'); $(this.el).find('.answer.hideable').hide(); - - // Show first question $(this.el).find('.question.collapsible :first').addClass('opened').removeClass('collapsed'); $(this.el).find('.answer.hideable :first').show(); + + return section; }, toggled: function(e) { diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index de35dc1a3..f86e9bab7 100644 --- a/app/assets/javascripts/app/views/help_view.js +++ b/app/assets/javascripts/app/views/help_view.js @@ -1,4 +1,3 @@ -//TODO RS: Would be nice to have #faq as the root elem or something app.views.Help = app.views.StaticContentView.extend({ templateName : "help", @@ -10,14 +9,13 @@ app.views.Help = app.views.StaticContentView.extend({ }, initialize : function(options) { - // TODO RS: Hard coded links are not nice. Should be in a config or something. this.GETTING_HELP_SUBS = { getting_started_a: { tutorial_series: this.linkHtml("http://diasporafoundation.org/getting_started/sign_up", Diaspora.I18n.t( 'getting_started_tutorial' )) }, get_support_a_website: { link: this.linkHtml("https://diasporafoundation.org/", Diaspora.I18n.t( 'foundation_website' ))}, get_support_a_tutorials: { tutorials: this.linkHtml("https://diasporafoundation.org/tutorials", Diaspora.I18n.t( 'tutorials' ))}, get_support_a_wiki: { link: this.linkHtml("https://wiki.diasporafoundation.org/Special:Search", Diaspora.I18n.t( 'wiki' ))}, get_support_a_irc: { irc: this.linkHtml("https://wiki.diasporafoundation.org/How_We_Communicate#IRC", Diaspora.I18n.t( 'irc' ))}, - get_support_a_hashtag: { question: this.linkHtml("/tags/question", "#question")}, // TODO RS: Is this definitely hard coded? + get_support_a_hashtag: { question: this.linkHtml("/tags/question", "#question")}, }; this.POSTS_AND_POSTING_SUBS = { @@ -47,10 +45,14 @@ app.views.Help = app.views.StaticContentView.extend({ return this; }, - afterRender: function() { - this.resetMenu(true); + render: function(){ + var section = app.views.Base.prototype.render.apply(this, arguments); + // After render actions + this.resetMenu(true); this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS); + + return section; }, showItems: function(el) { diff --git a/app/assets/javascripts/help.js b/app/assets/javascripts/help.js new file mode 100644 index 000000000..eae458c7d --- /dev/null +++ b/app/assets/javascripts/help.js @@ -0,0 +1,5 @@ +$(document).ready(function() { + app.help = new app.views.Help(); + $("#help").prepend(app.help.el); + app.help.render(); +}); \ No newline at end of file diff --git a/app/assets/javascripts/helpers/i18n.js b/app/assets/javascripts/helpers/i18n.js index 79906c39f..f675e9624 100644 --- a/app/assets/javascripts/helpers/i18n.js +++ b/app/assets/javascripts/helpers/i18n.js @@ -7,7 +7,7 @@ locale: {}, loadLocale: function(locale, language) { - this.locale = locale; + this.locale = $.extend(this.locale, locale); this.language = language; rule = this.t('pluralization_rule'); if (rule === "") diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index ac4334cdb..318af4088 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -7,8 +7,8 @@ module LanguageHelper options.sort_by { |o| o[0] } end - def get_javascript_strings_for(language) - defaults = I18n.t('javascripts', :locale => DEFAULT_LANGUAGE) + def get_javascript_strings_for(language, section) + defaults = I18n.t(section, :locale => DEFAULT_LANGUAGE) if language != DEFAULT_LANGUAGE translations = I18n.t('javascripts', :locale => language) @@ -20,17 +20,6 @@ module LanguageHelper defaults end - def get_diaspora_section_strings_for(section, language) - defaults = I18n.t(section, :locale => DEFAULT_LANGUAGE) - - if language != DEFAULT_LANGUAGE - translations = I18n.t(section, :locale => language) - defaults.deep_merge!(translations) - end - - defaults - end - def direction_for(string) return '' unless string.respond_to?(:cleaned_is_rtl?) string.cleaned_is_rtl? ? 'rtl' : 'ltr' diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 29b3382f7..a88061df7 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -28,19 +28,10 @@ module LayoutHelper end end - def load_javascript_locales + def load_javascript_locales(section = 'javascripts') content_tag(:script) do <<-JS.html_safe - Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}"); - Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}"; - JS - end - end - - def load_section_javascript_locales(section) - content_tag(:script) do - <<-JS.html_safe - Diaspora.I18n.loadLocale(#{get_diaspora_section_strings_for(section, I18n.locale).to_json}, "#{I18n.locale}"); + Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale, section).to_json}, "#{I18n.locale}"); Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}"; JS end diff --git a/app/views/help/faq.html.haml b/app/views/help/faq.html.haml index d89d2c838..48177a314 100644 --- a/app/views/help/faq.html.haml +++ b/app/views/help/faq.html.haml @@ -2,6 +2,9 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. += load_javascript_locales("help") += javascript_include_tag 'help' + - content_for :page_title do = t('_help') diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1e3070605..cc4f5d82e 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -39,7 +39,6 @@ - unless @landing_page = javascript_include_tag :main, :templates = load_javascript_locales - = load_section_javascript_locales("help") = set_asset_host = translation_missing_warnings diff --git a/app/views/shared/_right_sections.html.haml b/app/views/shared/_right_sections.html.haml index ae86d2c46..4be858650 100644 --- a/app/views/shared/_right_sections.html.haml +++ b/app/views/shared/_right_sections.html.haml @@ -41,7 +41,7 @@ %br %p != t('aspects.index.help.tutorials_and_wiki', - :faq => link_to(t('_help'), faq_getting_help_path), + :faq => link_to(t('_help'), help_path), :tutorial => link_to(t('aspects.index.help.tutorial_link_text'), "https://diasporafoundation.org/tutorials", :target => '_blank'), :wiki => link_to('Wiki','http://wiki.diasporafoundation.org', :target => '_blank'), :target => '_blank') diff --git a/config/routes.rb b/config/routes.rb index df7300c31..37305f948 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -206,8 +206,6 @@ Diaspora::Application.routes.draw do get 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile' # help - get 'help/faq' => 'help#faq', :as => 'faq_getting_help' - get 'help/faq' => 'help#faq', :as => 'faq' get 'help' => 'help#faq', :as => 'help' #Protocol Url