From a17d32f7d407389ec5756b21d09c0f8b8d9d2fa5 Mon Sep 17 00:00:00 2001 From: rdsubhas Date: Sun, 15 Jun 2014 11:09:10 +0300 Subject: [PATCH] Added Edit This Page functionality in plugin --- .../book/edit-this-page.js | 21 +++++++++++++++++++ .../book/{rapidftr.js => guide-dropdown.js} | 0 gitbook-plugin-rapidftr/index.js | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gitbook-plugin-rapidftr/book/edit-this-page.js rename gitbook-plugin-rapidftr/book/{rapidftr.js => guide-dropdown.js} (100%) diff --git a/gitbook-plugin-rapidftr/book/edit-this-page.js b/gitbook-plugin-rapidftr/book/edit-this-page.js new file mode 100644 index 0000000..7da6116 --- /dev/null +++ b/gitbook-plugin-rapidftr/book/edit-this-page.js @@ -0,0 +1,21 @@ +require(["gitbook", "utils/url", "jQuery"], function(gitbook, URL, jQuery) { + + var editBaseUrl = $(".contribute-link").attr("href"); + var bookBaseUrl = URL.join(window.location.pathname, $(".book-header h1 a").attr("href")); + + function updateLink() { + var editPath = window.location.pathname.replace(bookBaseUrl, ""); + + if (editPath.indexOf("/") !== 0) editPath = "/" + editPath; + if (editPath === "/") editPath = editPath + "README.md"; + if (editPath.indexOf("/index.html") >= 0) editPath = editPath.replace("/index.html", "/README.md"); + if (editPath.indexOf(".html") >= 0) editPath = editPath.replace(".html", ".md"); + if (editPath.indexOf(".md", editPath.length - 3) === -1) editPath = editPath + ".md"; + + var editUrl = editBaseUrl.replace("/tree/", "/edit/") + editPath; + $(".contribute-link").attr("href", editUrl); + } + + gitbook.events.bind("page.change", updateLink); + +}); diff --git a/gitbook-plugin-rapidftr/book/rapidftr.js b/gitbook-plugin-rapidftr/book/guide-dropdown.js similarity index 100% rename from gitbook-plugin-rapidftr/book/rapidftr.js rename to gitbook-plugin-rapidftr/book/guide-dropdown.js diff --git a/gitbook-plugin-rapidftr/index.js b/gitbook-plugin-rapidftr/index.js index b153d8b..f67fbb2 100644 --- a/gitbook-plugin-rapidftr/index.js +++ b/gitbook-plugin-rapidftr/index.js @@ -2,7 +2,8 @@ module.exports = { book: { assets: './book', js: [ - 'rapidftr.js' + 'guide-dropdown.js', + 'edit-this-page.js' ] } }