Add option to show Octotree in non-code page

This commit is contained in:
Buu Nguyen 2014-11-24 19:05:03 -08:00
parent 6d8af8e20e
commit d523a7731a
7 changed files with 25 additions and 11 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules node_modules
tmp tmp
.idea

View File

@ -51,6 +51,11 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on
## Changelog ## 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) ### [v1.4.1](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.4.1+is%3Aclosed)
* New header to match new GitHub design * New header to match new GitHub design
* Bug fixes * Bug fixes

View File

@ -63,7 +63,7 @@ GitHub.prototype.updateLayout = function(sidebarVisible, sidebarWidth) {
/** /**
* Returns the repository information if user is at a repository URL. Returns `null` otherwise. * 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 // 404 page, skip
if ($(GH_404_SEL).length) return false 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_USER_NAMES.indexOf(match[1])) return false
if (~GH_RESERVED_REPO_NAMES.indexOf(match[2])) return false if (~GH_RESERVED_REPO_NAMES.indexOf(match[2])) return false
// not a code page, skip // skip non-code page or not
if (match[3] && !~['tree', 'blob'].indexOf(match[3])) return false 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 { return {
username : match[1], username : match[1],
reponame : match[2], reponame : match[2],
@ -190,7 +193,7 @@ GitHub.prototype.fetchData = function(opts, cb) {
var token = opts.token var token = opts.token
, host = (location.host === 'github.com' ? 'api.github.com' : (location.host + '/api/v3')) , host = (location.host === 'github.com' ? 'api.github.com' : (location.host + '/api/v3'))
, base = location.protocol + '//' + host + '/repos/' + repo.username + '/' + repo.reponame , 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 } if (token) cfg.headers = { Authorization: 'token ' + token }
$.ajax(cfg) $.ajax(cfg)

View File

@ -12,6 +12,7 @@ const
WIDTH : 'octotree.sidebar_width', WIDTH : 'octotree.sidebar_width',
POPUP : 'octotree.popup_shown', POPUP : 'octotree.popup_shown',
SHOWN : 'octotree.sidebar_shown', SHOWN : 'octotree.sidebar_shown',
NONCODE : 'octotree.noncode_shown',
} }
, DEFAULTS = { , DEFAULTS = {
@ -30,6 +31,7 @@ const
WIDTH : 250, WIDTH : 250,
POPUP : false, POPUP : false,
SHOWN : false, SHOWN : false,
NONCODE : false,
} }
, EVENT = { , EVENT = {

View File

@ -87,11 +87,12 @@ $(document).ready(function() {
} }
function tryLoadRepo(reload) { function tryLoadRepo(reload) {
var repo = adapter.getRepoFromPath() var remember = store.get(STORE.REMEMBER)
, remember = store.get(STORE.REMEMBER) , showInNonCodePage = store.get(STORE.NONCODE)
, shown = store.get(STORE.SHOWN) , shown = store.get(STORE.SHOWN)
, lazyload = store.get(STORE.LAZYLOAD) , lazyload = store.get(STORE.LAZYLOAD)
, token = store.get(STORE.TOKEN) , token = store.get(STORE.TOKEN)
, repo = adapter.getRepoFromPath(showInNonCodePage, currRepo)
if (repo) { if (repo) {
$toggler.show() $toggler.show()

View File

@ -46,6 +46,9 @@
<div> <div>
<label><input type="checkbox" data-store="REMEMBER"> Show sidebar if previously shown</label> <label><input type="checkbox" data-store="REMEMBER"> Show sidebar if previously shown</label>
</div> </div>
<div>
<label><input type="checkbox" data-store="NONCODE"> Show in non-code pages</label>
</div>
<div> <div>
<label><input type="checkbox" data-store="LAZYLOAD"> Only load tree when sidebar is open</label> <label><input type="checkbox" data-store="LAZYLOAD"> Only load tree when sidebar is open</label>
</div> </div>

View File

@ -5,7 +5,6 @@ function HelpPopup($dom, store) {
HelpPopup.prototype.show = function() { HelpPopup.prototype.show = function() {
var $view = this.$view var $view = this.$view
, $sidebar = this.$sidebar
, store = this.store , store = this.store
, popupShown = store.get(STORE.POPUP) , popupShown = store.get(STORE.POPUP)