Merge pull request #44 from Luegg/hideOnNonCode

Hide sidebar when navigating to non-code sites
This commit is contained in:
Buu Nguyen 2014-05-14 16:38:44 -07:00
commit b82045ba94
5 changed files with 30 additions and 10 deletions

View File

@ -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>

View File

@ -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'

View File

@ -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)
@ -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],

17
src/locationChange.js Normal file
View File

@ -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()
})()

View File

@ -29,7 +29,8 @@
"lib/js/jquery.pjax.js",
"lib/js/base64.js",
"lib/js/github.js",
"inject.js"
"inject.js",
"locationChange.js"
]
}
],