From d523a7731ab1519f039e37a5decd0e8e82cd996c Mon Sep 17 00:00:00 2001 From: Buu Nguyen Date: Mon, 24 Nov 2014 19:05:03 -0800 Subject: [PATCH] Add option to show Octotree in non-code page --- .gitignore | 3 ++- README.md | 5 +++++ src/adapter.github.js | 17 ++++++++++------- src/constants.js | 2 ++ src/octotree.js | 5 +++-- src/template.html | 3 +++ src/view.help.js | 1 - 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 79eb783..fc89a78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -tmp \ No newline at end of file +tmp +.idea \ No newline at end of file diff --git a/README.md b/README.md index 0972aeb..07b625a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on ## Changelog +### [v1.5](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.5+is%3Aclosed) +* Option to show in non-code pages +* Option to configure tab size +* Bug fixes + ### [v1.4.1](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.4.1+is%3Aclosed) * New header to match new GitHub design * Bug fixes diff --git a/src/adapter.github.js b/src/adapter.github.js index a827b1d..e0b1a2c 100644 --- a/src/adapter.github.js +++ b/src/adapter.github.js @@ -63,7 +63,7 @@ GitHub.prototype.updateLayout = function(sidebarVisible, sidebarWidth) { /** * Returns the repository information if user is at a repository URL. Returns `null` otherwise. */ -GitHub.prototype.getRepoFromPath = function() { +GitHub.prototype.getRepoFromPath = function(showInNonCodePage, currentRepo) { // 404 page, skip if ($(GH_404_SEL).length) return false @@ -75,12 +75,15 @@ GitHub.prototype.getRepoFromPath = function() { if (~GH_RESERVED_USER_NAMES.indexOf(match[1])) return false if (~GH_RESERVED_REPO_NAMES.indexOf(match[2])) return false - // not a code page, skip - if (match[3] && !~['tree', 'blob'].indexOf(match[3])) return false + // skip non-code page or not + if (!showInNonCodePage && match[3] && !~['tree', 'blob'].indexOf(match[3])) return false + + // use selected branch, or previously selected branch, or master + var branch = $(GH_BRANCH_SEL).data('ref') || + ((currentRepo.username === match[1] && currentRepo.reponame === match[2] && currentRepo.branch) + ? currentRepo.branch + : 'master') - // can actually check if *[data-master-branch] exists and remove all the checks above - // but the current approach is less fragile in case of GitHub DOM changes - var branch = $(GH_BRANCH_SEL).data('ref') || $(GH_BRANCH_BTN_SEL).text() || 'master' return { username : match[1], reponame : match[2], @@ -190,7 +193,7 @@ GitHub.prototype.fetchData = function(opts, cb) { var token = opts.token , host = (location.host === 'github.com' ? 'api.github.com' : (location.host + '/api/v3')) , base = location.protocol + '//' + host + '/repos/' + repo.username + '/' + repo.reponame - , cfg = { method: 'GET', url: base + path } + , cfg = { method: 'GET', url: base + path, cache: false } if (token) cfg.headers = { Authorization: 'token ' + token } $.ajax(cfg) diff --git a/src/constants.js b/src/constants.js index 623d0a6..05838ab 100644 --- a/src/constants.js +++ b/src/constants.js @@ -12,6 +12,7 @@ const WIDTH : 'octotree.sidebar_width', POPUP : 'octotree.popup_shown', SHOWN : 'octotree.sidebar_shown', + NONCODE : 'octotree.noncode_shown', } , DEFAULTS = { @@ -30,6 +31,7 @@ const WIDTH : 250, POPUP : false, SHOWN : false, + NONCODE : false, } , EVENT = { diff --git a/src/octotree.js b/src/octotree.js index 1372b72..7e92490 100755 --- a/src/octotree.js +++ b/src/octotree.js @@ -87,11 +87,12 @@ $(document).ready(function() { } function tryLoadRepo(reload) { - var repo = adapter.getRepoFromPath() - , remember = store.get(STORE.REMEMBER) + var remember = store.get(STORE.REMEMBER) + , showInNonCodePage = store.get(STORE.NONCODE) , shown = store.get(STORE.SHOWN) , lazyload = store.get(STORE.LAZYLOAD) , token = store.get(STORE.TOKEN) + , repo = adapter.getRepoFromPath(showInNonCodePage, currRepo) if (repo) { $toggler.show() diff --git a/src/template.html b/src/template.html index 829d025..93d9aa5 100644 --- a/src/template.html +++ b/src/template.html @@ -46,6 +46,9 @@
+
+ +
diff --git a/src/view.help.js b/src/view.help.js index 2ddf95c..ef0ca3a 100644 --- a/src/view.help.js +++ b/src/view.help.js @@ -5,7 +5,6 @@ function HelpPopup($dom, store) { HelpPopup.prototype.show = function() { var $view = this.$view - , $sidebar = this.$sidebar , store = this.store , popupShown = store.get(STORE.POPUP)