diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index e700c9cfd..d55b6a27d 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,6 +2,8 @@ app.Router = Backbone.Router.extend({ routes: { + "help/:topic": "help", + "help/": "help", "help": "help", "contacts": "contacts", "conversations": "conversations", @@ -36,10 +38,10 @@ app.Router = Backbone.Router.extend({ this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet"); }, - help: function() { + help: function(topic) { app.help = new app.views.Help(); $("#help").prepend(app.help.el); - app.help.render(); + app.help.render(topic); }, contacts: function() { diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index 4df60c68f..a6b0d4d3c 100644 --- a/app/assets/javascripts/app/views/help_view.js +++ b/app/assets/javascripts/app/views/help_view.js @@ -9,7 +9,7 @@ app.views.Help = app.views.StaticContentView.extend({ "click .faq-link-sharing" : "sharing", "click .faq-link-posts-and-posting" : "postsAndPosting", "click .faq-link-tags": "tags", - "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts", + "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts" }, initialize : function() { @@ -19,19 +19,19 @@ app.views.Help = app.views.StaticContentView.extend({ 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")}, + get_support_a_hashtag: { question: this.linkHtml("/tags/question", "#question")} }; this.POSTS_AND_POSTING_SUBS = { format_text_a: { markdown: this.linkHtml("http://diasporafoundation.org/formatting", Diaspora.I18n.t( 'markdown' )), - here: this.linkHtml("http://daringfireball.net/projects/markdown/syntax", Diaspora.I18n.t( 'here' )), + here: this.linkHtml("http://daringfireball.net/projects/markdown/syntax", Diaspora.I18n.t( 'here' )) } }; this.TAGS_SUBS = { filter_tags_a: { - third_party_tools: this.linkHtml("https://wiki.diasporafoundation.org/Tools_to_use_with_Diaspora", Diaspora.I18n.t( 'third_party_tools' )), + third_party_tools: this.linkHtml("https://wiki.diasporafoundation.org/Tools_to_use_with_Diaspora", Diaspora.I18n.t( 'third_party_tools' )) } }; @@ -51,19 +51,22 @@ app.views.Help = app.views.StaticContentView.extend({ title_sharing: Diaspora.I18n.t( 'sharing.title' ), title_tags: Diaspora.I18n.t( 'tags.title' ), title_keyboard_shortcuts: Diaspora.I18n.t( 'keyboard_shortcuts.title' ), - title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ), + title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ) }; return this; }, - render: function(){ + render: function(topic){ 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); + var elTarget = this.findTopic(topic); + if(elTarget != null){ $(elTarget).click(); } + return section; }, @@ -107,8 +110,12 @@ app.views.Help = app.views.StaticContentView.extend({ menuClicked: function(e) { this.resetMenu(); + $(e.target).hide(); $(e.target).next().show(); + + var data = $(e.target).data('section'); + app.router.navigate('help/' + data); }, clearItems: function() { @@ -133,6 +140,18 @@ app.views.Help = app.views.StaticContentView.extend({ this.$('#faq').append(help_section.render().el); }, + /** + * Returns The section title whose data-section property equals the given query + * Returns null if nothing found + * @param dataValue Value for the data-section to find + * @returns {jQuery} + */ + findTopic: function(dataValue){ + var res = this.$('a[data-section=' + dataValue + ']'); + if(res.length == 0){ return null; } + return res; + }, + gettingHelp: function(e) { this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS); this.menuClicked(e); @@ -170,6 +189,6 @@ app.views.Help = app.views.StaticContentView.extend({ linkHtml: function(url, text) { return "" + text + ""; - }, + } }); -// @license-end +// @license-end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1c245599b..8aa59a909 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,6 +223,7 @@ Diaspora::Application.routes.draw do # Help get 'help' => 'help#faq', :as => 'help' + get 'help/:topic' => 'help#faq' #Protocol Url get 'protocol' => redirect("http://wiki.diasporafoundation.org/Federation_Protocol_Overview") diff --git a/spec/javascripts/app/views/help_view_spec.js b/spec/javascripts/app/views/help_view_spec.js index 9561f998f..0ab8e1a26 100644 --- a/spec/javascripts/app/views/help_view_spec.js +++ b/spec/javascripts/app/views/help_view_spec.js @@ -86,5 +86,39 @@ describe("app.views.Help", function(){ this.view.$el.find('a[data-section=miscellaneous]').trigger('click'); expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy(); }); + + it('should not find any topic', function(){ + expect(this.view.findTopic('you_shall_not_pass')).toBeNull(); + }); + + it('should find the miscellaneous topic', function(){ + var topic = this.view.$el.find('a[data-section=miscellaneous]'); + expect(this.view.findTopic('miscellaneous').html()).toBe(topic.html()); + }); + + it('should find the keyboard_shortcuts topic', function(){ + var topic = this.view.$el.find('a[data-section=keyboard_shortcuts]'); + expect(this.view.findTopic('keyboard_shortcuts').html()).toBe(topic.html()); + }); + + it('should find the miscellaneous topic', function(){ + var topic = this.view.$el.find('a[data-section=tags]'); + expect(this.view.findTopic('tags').html()).toBe(topic.html()); + }); + + it('should rewrite route to help/tags', function(){ + this.view.$el.find('a[data-section=tags]').trigger('click'); + expect(window.location.href.toString().endsWith("help/tags")).toBeTruthy(); + }); + + it('should rewrite route to help/keyboard_shortcuts', function(){ + this.view.$el.find('a[data-section=keyboard_shortcuts]').trigger('click'); + expect(window.location.href.toString().endsWith("help/keyboard_shortcuts")).toBeTruthy(); + }); + + it('should rewrite route to help/sharing', function(){ + this.view.$el.find('a[data-section=sharing]').trigger('click'); + expect(window.location.href.toString().endsWith("help/sharing")).toBeTruthy(); + }); }); -}); +}); \ No newline at end of file