Comments (4)
Hmm that's a great idea. Never considered more than one plugin
attaching to the same element.
How do you think it could handle potential conflicts though? For example your drag and drop plugin would it also want to update the file name label or would you leave that to the current file plugin to detect the change event, as it currently does?
Your example doesn't seem to exist.
I would appreciate a pull request, would help see what the changes are you propose.
from bulmajs.
Bulma .file
style not support browser default style upload (drag and drop into upload input).
This example support it but can't use along with BulmaJS file plugin.
If attach multi plugins to same class name and same event, it are called in order.
Example:
class FileDragDrop {
/**
* Plugin constructor
* @param {Object} options The options object for this plugin
* @return {this} The newly created plugin instance
*/
constructor(options) {
if(!options.element) {
throw new Error('[BulmaJS] The file component requires an element to function.');
}
/**
* The root file element.
* @type {HTMLElement}
*/
this.root = options.element;
/**
* The element to file input.
* @type {HTMLELement}
*/
this.input = this.root.querySelector('input');
this.registerEvents();
}
/**
* Register all the events this module needs.
* @return {undefined}
*/
registerEvents() {
// add hovered class name
this.root.addEventListener('dragover', (e) => {
e.preventDefault();
this.root.classList.add('is-hovered');
});
// remove hovered class name
this.root.addEventListener('dragleave', (e) => {
e.preventDefault();
this.root.classList.remove('is-hovered');
});
// remove hovered class name and set dragged file
this.root.addEventListener('drop', (e) => {
e.preventDefault();
this.root.classList.remove('is-hovered');
this.input.files = e.dataTransfer.files;
});
}
/**
* Handle parsing the DOMs data attribute API.
* @param {HTMLElement} element The root element for this plugin
* @return {undefined}
*/
static handleDomParsing(element) {
new FileDragDrop({
element: element
});
}
static getRootClass() {
return 'file';
}
}
Bulma.registerPlugin('file-drag-drop', FileDragDrop);
export default FileDragDrop;
from bulmajs.
Looking at your code all I see is the hover class being applied to the file element when dragging and the files property being set to the event dragged files. Is this correct or am I missing something?
If this is correct then I actually think this could be implemented into the core file plugin, rather than being it's own plugin. I'm assuming this doesn't reply on any third party library.
If you would like to create a PR adding this to the core file plugin I'll be more than happy to merge it in.
from bulmajs.
You are right. I think so too.
I will send PR
from bulmajs.
Related Issues (20)
- Additional API methods for Alert
- Additional API methods for Dropdown
- Additional API methods for the file component
- Additional API methods for the message component
- Additional API methods for the Modal component
- Additional API methods for navbar
- Additional API methods for notification
- Additional API methods for the tabs component
- Panel tabs are nor filtered by default (display all on load until manually filtered) HOT 4
- Webpack - Module parse failed: Unexpected token HOT 4
- Multiple Dropdowns HOT 4
- Support tree table HOT 1
- Cannot use import statement outside a module HOT 2
- Window is not defined when using nextjs HOT 5
- Navbar plugin does not work on dynamically inserted content HOT 3
- Trying to use it in electron, imports problems HOT 2
- Uncaught TypeError: this.triggerElement is null HOT 3
- Project alive? HOT 2
- CDN to allow more accessibility regarding installation HOT 1
- Creating modal: A plugin requires a root and/or a parent. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bulmajs.