Add option to show Octotree in non-code page
This commit is contained in:
parent
6d8af8e20e
commit
d523a7731a
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
tmp
|
||||
tmp
|
||||
.idea
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
<div>
|
||||
<label><input type="checkbox" data-store="REMEMBER"> Show sidebar if previously shown</label>
|
||||
</div>
|
||||
<div>
|
||||
<label><input type="checkbox" data-store="NONCODE"> Show in non-code pages</label>
|
||||
</div>
|
||||
<div>
|
||||
<label><input type="checkbox" data-store="LAZYLOAD"> Only load tree when sidebar is open</label>
|
||||
</div>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue