-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new tab button #55
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
59ee8ab
f3647b4
2391d97
1b8e31e
aa33b30
61e7dd6
cba0f08
2e0e66f
33eba30
7590ce3
476d233
7a517d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,19 @@ | |
window.ChromeTabs = factory(window, window.Draggabilly) | ||
} | ||
})(window, (window, Draggabilly) => { | ||
const TAB_CONTENT_MARGIN = 9 | ||
const TAB_CONTENT_MARGIN = 10 | ||
const TAB_CONTENT_OVERLAP_DISTANCE = 1 | ||
|
||
const TAB_OVERLAP_DISTANCE = (TAB_CONTENT_MARGIN * 2) + TAB_CONTENT_OVERLAP_DISTANCE | ||
const TAB_OVERLAP_DISTANCE = | ||
TAB_CONTENT_MARGIN * 2 + TAB_CONTENT_OVERLAP_DISTANCE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change in formatting here? |
||
|
||
const TAB_CONTENT_MIN_WIDTH = 24 | ||
const TAB_CONTENT_MAX_WIDTH = 240 | ||
|
||
const TAB_SIZE_SMALL = 84 | ||
const TAB_SIZE_SMALLER = 60 | ||
const TAB_SIZE_MINI = 48 | ||
const NEW_TAB_BUTTON_AREA = 90 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const noop = _ => {} | ||
|
||
|
@@ -50,6 +52,12 @@ | |
</div> | ||
` | ||
|
||
const newTabButtonTemplate = ` | ||
<div class="new-tab-button-wrapper"> | ||
<button class="new-tab-button">✚</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need an |
||
</div> | ||
` | ||
|
||
const defaultTapProperties = { | ||
title: 'New tab', | ||
favicon: false | ||
|
@@ -73,6 +81,7 @@ | |
this.setupStyleEl() | ||
this.setupEvents() | ||
this.layoutTabs() | ||
this.setupNewTabButton() | ||
this.setupDraggabilly() | ||
} | ||
|
||
|
@@ -99,6 +108,11 @@ | |
if ([this.el, this.tabContentEl].includes(event.target)) this.addTab() | ||
}) | ||
|
||
this.el.addEventListener("click", ({ target }) => { | ||
if (target.classList.contains("new-tab-button")) | ||
this.addTab() | ||
}) | ||
|
||
this.tabEls.forEach((tabEl) => this.setTabCloseEventListener(tabEl)) | ||
} | ||
|
||
|
@@ -112,7 +126,7 @@ | |
|
||
get tabContentWidths() { | ||
const numberOfTabs = this.tabEls.length | ||
const tabsContentWidth = this.tabContentEl.clientWidth | ||
const tabsContentWidth = this.el.clientWidth - NEW_TAB_BUTTON_AREA | ||
const tabsCumulativeOverlappedWidth = (numberOfTabs - 1) * TAB_CONTENT_OVERLAP_DISTANCE | ||
const targetWidth = (tabsContentWidth - (2 * TAB_CONTENT_MARGIN) + tabsCumulativeOverlappedWidth) / numberOfTabs | ||
const clampedTargetWidth = Math.max(TAB_CONTENT_MIN_WIDTH, Math.min(TAB_CONTENT_MAX_WIDTH, targetWidth)) | ||
|
@@ -158,6 +172,7 @@ | |
|
||
layoutTabs() { | ||
const tabContentWidths = this.tabContentWidths | ||
let tabsLen = this.tabEls.length | ||
|
||
this.tabEls.forEach((tabEl, i) => { | ||
const contentWidth = tabContentWidths[i] | ||
|
@@ -182,6 +197,11 @@ | |
` | ||
}) | ||
this.styleEl.innerHTML = styleHTML | ||
|
||
if (this.el.offsetWidth - this.tabContentEl.offsetWidth > NEW_TAB_BUTTON_AREA + (TAB_CONTENT_MARGIN / 2) || tabsLen < 5) { | ||
this.tabContentEl.style.width = `${ (this.tabEls[0] ? this.tabEls[0].offsetWidth * tabsLen : 0) - (tabsLen > 0 ? ((tabsLen * TAB_CONTENT_MARGIN * 2) - TAB_CONTENT_MIN_WIDTH + TAB_CONTENT_MARGIN) : 0) }px` | ||
this.tabContentEl.nextElementSibling.classList.remove('overflow-shadow') | ||
} else this.tabContentEl.nextElementSibling.classList.add('overflow-shadow') | ||
} | ||
|
||
createNewTabEl() { | ||
|
@@ -355,6 +375,11 @@ | |
this.emit('tabReorder', { tabEl, originIndex, destinationIndex }) | ||
this.layoutTabs() | ||
} | ||
|
||
setupNewTabButton() { | ||
this.tabContentEl.insertAdjacentHTML('afterend', newTabButtonTemplate) | ||
this.layoutTabs() | ||
} | ||
} | ||
|
||
return ChromeTabs | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from
9
to10
here?