mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Merged in AD-679-concept-of-drag-is-nonsensical-fo (pull request #103)
Introduce draganddrop feature detection and add it to FileDragAndDropDialog
This commit is contained in:
commit
e804722c71
@ -4,6 +4,8 @@ import React from 'react';
|
|||||||
import Router from 'react-router';
|
import Router from 'react-router';
|
||||||
|
|
||||||
import { getLangText } from '../../../utils/lang_utils';
|
import { getLangText } from '../../../utils/lang_utils';
|
||||||
|
import { dragAndDropAvailable } from '../../../utils/feature_detection_utils';
|
||||||
|
|
||||||
|
|
||||||
let Link = Router.Link;
|
let Link = Router.Link;
|
||||||
|
|
||||||
@ -24,6 +26,17 @@ let FileDragAndDropDialog = React.createClass({
|
|||||||
|
|
||||||
mixins: [Router.State],
|
mixins: [Router.State],
|
||||||
|
|
||||||
|
getDragDialog(fileClass) {
|
||||||
|
if(dragAndDropAvailable) {
|
||||||
|
return [
|
||||||
|
<p>{getLangText('Drag %s here', fileClass)}</p>,
|
||||||
|
<p>{getLangText('or')}</p>
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const queryParams = this.getQuery();
|
const queryParams = this.getQuery();
|
||||||
|
|
||||||
@ -64,8 +77,7 @@ let FileDragAndDropDialog = React.createClass({
|
|||||||
if(this.props.multipleFiles) {
|
if(this.props.multipleFiles) {
|
||||||
return (
|
return (
|
||||||
<span className="file-drag-and-drop-dialog">
|
<span className="file-drag-and-drop-dialog">
|
||||||
<p>{getLangText('Drag %s here', this.props.fileClassToUpload.plural)}</p>
|
{this.getDragDialog(this.props.fileClassToUpload.plural)}
|
||||||
<p>{getLangText('or')}</p>
|
|
||||||
<span
|
<span
|
||||||
className="btn btn-default"
|
className="btn btn-default"
|
||||||
onClick={this.props.onClick}>
|
onClick={this.props.onClick}>
|
||||||
@ -78,8 +90,7 @@ let FileDragAndDropDialog = React.createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="file-drag-and-drop-dialog">
|
<span className="file-drag-and-drop-dialog">
|
||||||
<p>{getLangText('Drag a %s here', this.props.fileClassToUpload.singular)}</p>
|
{this.getDragDialog(this.props.fileClassToUpload.singular)}
|
||||||
<p>{getLangText('or')}</p>
|
|
||||||
<span
|
<span
|
||||||
className="btn btn-default"
|
className="btn btn-default"
|
||||||
onClick={this.props.onClick}>
|
onClick={this.props.onClick}>
|
||||||
|
26
js/utils/feature_detection_utils.js
Normal file
26
js/utils/feature_detection_utils.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PLEASE
|
||||||
|
*
|
||||||
|
* postfix your function with '-Available'.
|
||||||
|
*
|
||||||
|
* Like this:
|
||||||
|
*
|
||||||
|
* featureNameAvailable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even though it is not recommended to check (and maintain) the used browser,
|
||||||
|
* we're checking the browser's ability to drag and drop with this statement as
|
||||||
|
* there is no other way of detecting it another way.
|
||||||
|
*
|
||||||
|
* See this discussion for clarity:
|
||||||
|
* - https://github.com/Modernizr/Modernizr/issues/57#issuecomment-35831605
|
||||||
|
*
|
||||||
|
* @type {bool} Is drag and drop available on this browser
|
||||||
|
*/
|
||||||
|
export const dragAndDropAvailable = 'draggable' in document.createElement('div') &&
|
||||||
|
!/Mobile|Android|Slick\/|Kindle|BlackBerry|Opera Mini|Opera Mobi/i.test(navigator.userAgent);
|
Loading…
Reference in New Issue
Block a user