Clean up & fix bug reloading repo not taking into account new token key
This commit is contained in:
parent
b82045ba94
commit
64a541cb59
|
@ -31,7 +31,6 @@
|
|||
<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>
|
||||
|
|
|
@ -9,8 +9,7 @@ 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('locationChange.js')],
|
||||
data.url('inject.js')],
|
||||
contentStyleFile: [data.url('lib/css/jstree.css'),
|
||||
data.url('inject.css')],
|
||||
contentScriptWhen: 'start'
|
||||
|
|
|
@ -31,25 +31,41 @@
|
|||
, $toggler = $('<div class="octotree_toggle">☰</div>')
|
||||
, $dummy = $('<div/>')
|
||||
, store = new Storage()
|
||||
, currentRepo = false
|
||||
, domInitialized = false
|
||||
, currentRepo = false
|
||||
|
||||
$(document).ready(function() {
|
||||
loadRepo(true)
|
||||
loadRepo()
|
||||
|
||||
// When navigating from non-code pages (i.e. Pulls, Issues) to code page
|
||||
// GitHub doesn't reload the page but use pjax. Need to de
|
||||
var href = location.href
|
||||
, hash = location.hash
|
||||
function detectLocationChange() {
|
||||
if (location.href !== href || location.hash != hash) {
|
||||
href = location.href
|
||||
hash = location.hash
|
||||
loadRepo()
|
||||
}
|
||||
window.setTimeout(detectLocationChange, 200)
|
||||
}
|
||||
detectLocationChange()
|
||||
})
|
||||
$(location).bind('change', true, loadRepo)
|
||||
|
||||
function loadRepo(initDom) {
|
||||
function loadRepo(reload) {
|
||||
var repo = getRepoFromPath()
|
||||
, repoChanged = JSON.stringify(currentRepo) != JSON.stringify(repo)
|
||||
, repoChanged = JSON.stringify(repo) !== JSON.stringify(currentRepo)
|
||||
|
||||
if (repo && repoChanged) {
|
||||
if (repo && (repoChanged || reload)) {
|
||||
currentRepo = repo
|
||||
|
||||
if (initDom) {
|
||||
if (!domInitialized) {
|
||||
$('body')
|
||||
.append($sidebar)
|
||||
.append($toggler.click(toggleSidebar))
|
||||
domInitialized = true
|
||||
}
|
||||
|
||||
fetchData(repo, function(err, tree) {
|
||||
if (err) return onFetchError(err)
|
||||
renderTree(repo, tree)
|
||||
|
@ -181,8 +197,8 @@
|
|||
}
|
||||
|
||||
// Shows sidebar when:
|
||||
// 1. first time extension is used
|
||||
// 2. if it was previously shown
|
||||
// 1. First time after extension is installed
|
||||
// 2. If it was previously shown (TODO: many seem not to like it)
|
||||
if (store.get(SHOWN) !== false) {
|
||||
$html.addClass(PREFIX)
|
||||
store.set(SHOWN, true)
|
||||
|
@ -206,7 +222,7 @@
|
|||
return $error.text('Token is required')
|
||||
}
|
||||
store.set(TOKEN, token)
|
||||
loadRepo()
|
||||
loadRepo(true)
|
||||
}
|
||||
|
||||
function sanitize(str) {
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
(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()
|
||||
})()
|
|
@ -29,8 +29,7 @@
|
|||
"lib/js/jquery.pjax.js",
|
||||
"lib/js/base64.js",
|
||||
"lib/js/github.js",
|
||||
"inject.js",
|
||||
"locationChange.js"
|
||||
"inject.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue