Change approach in fixing and

This commit is contained in:
Buu Nguyen 2015-01-21 14:35:53 -08:00
parent 45c6cde853
commit bdb3efd3cc
3 changed files with 4 additions and 44 deletions

View File

@ -13,26 +13,7 @@ const
, GH_PJAX_SEL = '#js-repo-pjax-container'
, GH_CONTAINERS = 'body > .container, .header > .container, .site > .container, .repohead > .container'
function GitHub() {
// Fix #151 by detecting when page layout is updated.
// In this case, split-diff page has a wider layout, so need to recompute margin.
// In addition, can't do this in response to URL change, since new DOM might not be ready.
var observer = new MutationObserver(function(mutations) {
for (var i = 0, len = mutations.length; i < len; i++) {
var mutation = mutations[i]
if (~mutation.oldValue.indexOf('split-diff') ||
~mutation.target.className.indexOf('split-diff')) {
return $(document).trigger(EVENT.LAYOUT_CHANGE)
}
}
})
observer.observe(document.body, {
attributes: true,
attributeFilter: ['class'],
attributeOldValue: true
})
}
function GitHub() {}
/**
* Selects a submodule.
@ -63,28 +44,9 @@ GitHub.prototype.selectPath = function(path, tabSize) {
*/
GitHub.prototype.updateLayout = function(sidebarVisible, sidebarWidth) {
var $containers = $(GH_CONTAINERS)
, isSplitView = $(document.body).hasClass('split-diff')
, spacing = 10
, autoMarginLeft
, shouldPushLeft
if ($containers.length === 4) {
autoMarginLeft = ($('body').width() - $containers.width()) / 2
if (isSplitView) {
$containers.css('margin-left', 'auto')
if (sidebarVisible) $containers.css('padding-left', sidebarWidth + spacing)
else $containers.css('padding-left', 30)
}
else {
$containers.css('padding-left', 0)
if (sidebarVisible) $containers.css('margin-left', sidebarWidth + spacing)
else $containers.css('margin-left', 'auto')
}
}
// falls-back if GitHub DOM has been updated
else $('html').css('margin-left', sidebarVisible ? sidebarWidth - spacing : 0)
$containers = $containers.length === 4 ? $containers : $('html') // falls-back if GH DOM is changed
if (sidebarVisible) $containers.css('margin-left', sidebarWidth + 10)
else $containers.css('margin-left', 'auto')
}
/**

View File

@ -37,7 +37,6 @@ const
, EVENT = {
TOGGLE : 'octotree:toggle',
LOC_CHANGE : 'octotree:location',
LAYOUT_CHANGE : 'octotree:layout',
REQ_START : 'octotree:start',
REQ_END : 'octotree:end',
OPTS_CHANGE : 'octotree:change',

View File

@ -63,7 +63,6 @@ $(document).ready(function() {
event.preventDefault()
})
.on(EVENT.LOC_CHANGE, tryLoadRepo)
.on(EVENT.LAYOUT_CHANGE, layoutChanged)
.on(EVENT.TOGGLE, layoutChanged)
return tryLoadRepo()