Support direct file downloading

This commit is contained in:
Buu Nguyen 2015-08-27 11:05:59 -07:00
parent 5a2d03cce3
commit ac77ac9c5d
12 changed files with 70 additions and 31 deletions

View File

@ -51,6 +51,12 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on
## Changelog
### v1.7.0
* Support direct downloading when hovering a file
### v1.6.4
* Fix bug detecting branch/tag due to GitHub DOM change
### v1.6.3
* Fix bug when switching to branches with slashes in their names
@ -60,36 +66,36 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on
### v1.6.1
* Update buttons' style to match GitHub new button style
### [v1.6](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.6+is%3Aclosed)
### v1.6
* Update all dependencies to latest version
* Allow navigating to commit trees https://github.com/buunguyen/octotree/issues/157
* Support keyboard navigation https://github.com/buunguyen/octotree/issues/158
* Fix bug handling back tick in paths https://github.com/buunguyen/octotree/issues/160
### [v1.5.3](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.5.3+is%3Aclosed)
### v1.5.3
* Fix bug https://github.com/buunguyen/octotree/pull/149
* Fix bug https://github.com/buunguyen/octotree/issues/151
* Fix bug https://github.com/buunguyen/octotree/issues/155
### [v1.5.2](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.5.2+is%3Aclosed)
### v1.5.2
* Fix bug https://github.com/buunguyen/octotree/issues/147
### [v1.5](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.5+is%3Aclosed)
### v1.5
* Option to show in non-code pages
* Option to load tree only when sidebar is visible
* Option to configure tab size
* Bug fixes
### [v1.4.1](https://github.com/buunguyen/octotree/issues?q=milestone%3A1.4.1+is%3Aclosed)
### v1.4.1
* New header to match new GitHub design
* Bug fixes
### [v1.4](https://github.com/buunguyen/octotree/issues?labels=&milestone=4&page=1&state=closed)
### v1.4
* Support GitHub enterprise
* Change default hotkey (`cmd+b` for Safari and `cmd+shift+s` for all other browsers)
* Some other minor changes
### [v1.3](https://github.com/buunguyen/octotree/issues?labels=&milestone=3&page=1&state=closed)
### v1.3
* Setting panel allowing:
* Changing access token
* Changing hotkeys
@ -99,7 +105,7 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on
* More responsive in big repositories
* And bug fixes
### [v1.2](https://github.com/buunguyen/octotree/issues?labels=&milestone=1&page=1&state=closed)
### v1.2
* Hide sidebar by default (upon many user requests)
* Hotkey (`cmd+b`, `ctrl+b`) to toggle sidebar
* Sidebar is now resizable
@ -108,7 +114,7 @@ By default, Octotree only works on `github.com`. To support GitHub Enterprise on
* New sidebar header and progress indicator
* And bug fixes
### [v1.1](https://github.com/buunguyen/octotree/issues?labels=&milestone=2&page=1&state=closed)
### v1.1
* New UI that blends better with GitHub!
* Hide Octotree on non-code pages
* When asking for token, show more detailed message and not fly out automatically

BIN
dist/chrome.crx vendored

Binary file not shown.

BIN
dist/chrome.zip vendored

Binary file not shown.

BIN
dist/firefox.xpi vendored

Binary file not shown.

BIN
dist/opera.nex vendored

Binary file not shown.

View File

@ -1,6 +1,6 @@
{
"name": "octotree",
"version": "1.6.4",
"version": "1.7.0",
"description": "Display GitHub code in tree format",
"main": "inject.js",
"scripts": {

View File

@ -42,10 +42,20 @@ GitHub.prototype.selectSubmodule = function(path) {
window.location.href = path
}
/**
* Downloads the file at the given
*/
GitHub.prototype.downloadFile = function(path, fileName) {
var link = document.createElement('a')
link.setAttribute('href', path.replace(/\/blob\//, '/raw/'))
link.setAttribute('download', fileName)
link.click()
}
/**
* Selects a path.
*/
GitHub.prototype.selectPath = function(path, tabSize) {
GitHub.prototype.selectFile = function(path, tabSize) {
var container = $(GH_PJAX_SEL)
, qs = tabSize ? ('?ts=' + tabSize) : ''

View File

@ -1,6 +1,6 @@
{
"name": "Octotree",
"version": "1.6.4",
"version": "1.7.0",
"manifest_version": 2,
"author": "Buu Nguyen",
"description": "Display GitHub code in tree format",

View File

@ -11,7 +11,7 @@
"icon": "data/icons/icon48.png",
"icon64": "data/icons/icon64.png",
"license": "MIT",
"version": "1.6.4",
"version": "1.7.0",
"permissions": {
"cross-domain-content": ["https://api.github.com", "https://github.com"]
}

View File

@ -108,6 +108,11 @@
content: '\f011';
color: #777;
}
.jstree-node.jstree-leaf:hover {
.jstree-icon.blob:before {
content: '\f00b';
}
}
.jstree-icon.commit:before {
content: '\f017';
color: #777;

View File

@ -13,9 +13,9 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>1.6.4</string>
<string>1.7.0</string>
<key>CFBundleVersion</key>
<string>1.6.4</string>
<string>1.7.0</string>
<key>Chrome</key>
<dict/>
<key>Content</key>

View File

@ -12,9 +12,14 @@ function TreeView($dom, store, adapter) {
})
.on('click', function(event) {
var $target = $(event.target)
var self = this
var download = false
// handle icon click, fix #122
if ($target.is('i.jstree-icon')) $target = $target.parent()
if ($target.is('i.jstree-icon')) {
$target = $target.parent()
download = true
}
if (!$target.is('a.jstree-anchor')) return
@ -23,13 +28,26 @@ function TreeView($dom, store, adapter) {
? $target.children(':first')
: $target.siblings(':first') // handles child links in submodule
// refocus after complete so that keyboard navigation works, fix #158
$(document).one('pjax:success', function () {
$.jstree.reference(this).get_container().focus()
}.bind(this))
if ($icon.hasClass('commit')) {
refocusAfterCompletion()
adapter.selectSubmodule(href)
}
else if ($icon.hasClass('blob')) {
if (download) {
adapter.downloadFile(href, $target.text())
}
else {
refocusAfterCompletion()
adapter.selectFile(href, store.get(STORE.TABSIZE))
}
}
if ($icon.hasClass('commit')) adapter.selectSubmodule(href)
else if ($icon.hasClass('blob')) adapter.selectPath(href, store.get(STORE.TABSIZE))
// refocus after complete so that keyboard navigation works, fix #158
function refocusAfterCompletion() {
$(document).one('pjax:success', function () {
$.jstree.reference(self).get_container().focus()
})
}
})
.jstree({
core : { multiple: false, themes : { responsive : false } },
@ -52,7 +70,7 @@ TreeView.prototype.showHeader = function(repo) {
)
.on('click', 'a[data-pjax]', function(event) {
event.preventDefault()
adapter.selectPath($(this).attr('href') /* a.href always return absolute URL, don't want that */)
adapter.selectFile($(this).attr('href') /* a.href always return absolute URL, don't want that */)
})
}