diff --git a/Changelog.md b/Changelog.md index 67b85b4c3..595b4b010 100644 --- a/Changelog.md +++ b/Changelog.md @@ -165,6 +165,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a * Added keyboard shortcuts r(reshare), m(expand Post), o(open first link in post) [#5602](https://github.com/diaspora/diaspora/pull/5602) * Dynamically compute minimum and maximum valid year for birthday field [#5639](https://github.com/diaspora/diaspora/pull/5639) * Show hovercard on mentions [#5652](https://github.com/diaspora/diaspora/pull/5652) +* Make help sections linkable [#5667](https://github.com/diaspora/diaspora/pull/5667) # 0.4.1.2 diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index e700c9cfd..d471f9c98 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/:section": "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(section) { app.help = new app.views.Help(); $("#help").prepend(app.help.el); - app.help.render(); + app.help.render(section); }, contacts: function() { diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index 4df60c68f..ffd773b20 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,20 +51,23 @@ 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(){ - var section = app.views.Base.prototype.render.apply(this, arguments); + render: function(section){ + var html = 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; + var elTarget = this.findSection(section); + if(elTarget !== null){ $(elTarget).click(); } + + return html; }, showItems: function(el) { @@ -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} + */ + findSection: function(data){ + var res = this.$('a[data-section=' + data + ']'); + 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 diff --git a/config/.jshint.json b/config/.jshint.json index f4a747e9f..7303e3641 100644 --- a/config/.jshint.json +++ b/config/.jshint.json @@ -58,6 +58,7 @@ "factory", "stubView", "exports", + "spyOn", "app", "Diaspora", 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..c19567d25 100644 --- a/spec/javascripts/app/views/help_view_spec.js +++ b/spec/javascripts/app/views/help_view_spec.js @@ -87,4 +87,51 @@ describe("app.views.Help", function(){ expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy(); }); }); + + describe("findSection", function() { + beforeEach(function() { + this.view.render(); + }); + + it('should return null for an unknown section', function() { + expect(this.view.findSection('you_shall_not_pass')).toBeNull(); + }); + + it('should return the correct section link for existing sections', function() { + var sections = [ + 'account_and_data_management', + 'aspects', + 'pods', + 'keyboard_shortcuts', + 'tags', + 'miscellaneous' + ]; + + var self = this; + _.each(sections, function(section) { + var el = self.view.$el.find('a[data-section=' + section + ']'); + expect(self.view.findSection(section).html()).toBe(el.html()); + }); + }); + }); + + describe("menuClicked", function() { + beforeEach(function() { + this.view.render(); + }); + + it('should rewrite the location', function(){ + var sections = [ + 'account_and_data_management', + 'miscellaneous' + ]; + spyOn(app.router, 'navigate'); + + var self = this; + _.each(sections, function(section) { + self.view.$el.find('a[data-section=' + section + ']').trigger('click'); + expect(app.router.navigate).toHaveBeenCalledWith('help/' + section); + }); + }); + }); });