Skip to content

Commit

Permalink
Change approach in fixing #151 and #155
Browse files Browse the repository at this point in the history
  • Loading branch information
buunguyen committed Jan 21, 2015
1 parent 45c6cde commit bdb3efd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 44 deletions.
46 changes: 4 additions & 42 deletions src/adapter.github.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/octotree.js
Expand Up @@ -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()
Expand Down

0 comments on commit bdb3efd

Please sign in to comment.