Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Bookmarks toolbar accepts drops
Browse files Browse the repository at this point in the history
Auditors: @diracdeltas
  • Loading branch information
bbondy committed Feb 17, 2016
1 parent b0d359f commit a4f6d0b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions js/components/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const React = require('react')
const ImmutableComponent = require('./immutableComponent')
const contextMenus = require('../contextMenus')
const WindowActions = require('../actions/windowActions')
const AppActions = require('../actions/appActions')
const siteTags = require('../constants/siteTags')

class BookmarkToolbarButton extends ImmutableComponent {
navigate () {
Expand All @@ -21,8 +23,34 @@ class BookmarkToolbarButton extends ImmutableComponent {
}

class BookmarksToolbar extends ImmutableComponent {
onDrop (e) {
let urls = e.dataTransfer.getData('text/uri-list') ||
e.dataTransfer.getData('text/plain')
urls = urls.split('\n')
.map(x => x.trim())
.filter(x => !x.startsWith('#'))
.forEach(url =>
AppActions.addSite({ location: url }, siteTags.BOOKMARK))
}
onDragEnter (e) {
let intersection = e.dataTransfer.types.filter(x =>
['text/plain', 'text/uri-list'].includes(x))
if (intersection.length > 0) {
e.preventDefault()
}
}
onDragOver (e) {
let intersection = e.dataTransfer.types.filter(x =>
['text/plain', 'text/uri-list'].includes(x))
if (intersection.length > 0) {
e.preventDefault()
}
}
render () {
return <div className='bookmarksToolbar'
onDrop={this.onDrop.bind(this)}
onDragEnter={this.onDragOver.bind(this)}
onDragOver={this.onDragOver.bind(this)}
onContextMenu={contextMenus.onTabsToolbarContextMenu.bind(this, this.props.settings)}>
{
this.props.bookmarks.map(bookmark =>
Expand Down

1 comment on commit a4f6d0b

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++. I found this works with javascript: URLs too, which solves #259.

Please sign in to comment.