Skip to content

Commit

Permalink
Merge pull request #44 from Luegg/hideOnNonCode
Browse files Browse the repository at this point in the history
Hide sidebar when navigating to non-code sites
  • Loading branch information
buunguyen committed May 14, 2014
2 parents 4d5f526 + 248ecdd commit b82045b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<string>lib/js/base64.js</string>
<string>lib/js/github.js</string>
<string>inject.js</string>
<string>locationChange.js</string>
</array>
</dict>
<key>Stylesheets</key>
Expand Down
3 changes: 2 additions & 1 deletion src/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pageMod.PageMod({
data.url('lib/js/jquery.pjax.js'),
data.url('lib/js/base64.js'),
data.url('lib/js/github.js'),
data.url('inject.js')],
data.url('inject.js'),
data.url('locationChange.js')],
contentStyleFile: [data.url('lib/css/jstree.css'),
data.url('inject.css')],
contentScriptWhen: 'start'
Expand Down
16 changes: 8 additions & 8 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@
, $toggler = $('<div class="octotree_toggle">&#9776;</div>')
, $dummy = $('<div/>')
, store = new Storage()
, currentRepo = false

$(document).ready(function() {
loadRepo(true)
})
$(location).bind('change', true, loadRepo)

function loadRepo(initDom) {
var repo = getRepoFromPath()
if (repo) {
, repoChanged = JSON.stringify(currentRepo) != JSON.stringify(repo)

if (repo && repoChanged) {
currentRepo = repo

if (initDom) {
$('body')
.append($sidebar)
Expand All @@ -57,13 +63,7 @@

if (~RESERVED_USER_NAMES.indexOf(match[1])) return false
if (~RESERVED_REPO_NAMES.indexOf(match[2])) return false

// TODO: the intention is to hide the sidebar when users navigate to non-code areas (e.g. Issues, Pulls)
// and show it again when users navigate back to the code area
// the first part is achieved with the next two lines; but need to implement the second part
// before activating the entire feature, PR is welcome
// if match[3] exists, it must be either 'tree' or 'blob'
// if (match[3] && !~['tree', 'blob'].indexOf(match[3])) return false
if (match[3] && !~['tree', 'blob'].indexOf(match[3])) return false

return {
username : match[1],
Expand Down
17 changes: 17 additions & 0 deletions src/locationChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function(){
const INTERVAL = 200
var href = location.href
, hash = location.hash

function checkLocation(){
if(location.href !== href || location.hash != hash){
$(location).trigger('change')
href = location.href
hash = location.hash
}

window.setTimeout(checkLocation, INTERVAL)
}

checkLocation()
})()
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"lib/js/jquery.pjax.js",
"lib/js/base64.js",
"lib/js/github.js",
"inject.js"
"inject.js",
"locationChange.js"
]
}
],
Expand Down

0 comments on commit b82045b

Please sign in to comment.