Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
selection-area
Advanced tools
Simple JavaScript seletion area to any DOM container element.
npm
npm install selection-area
yarn
yarn add selection-area
Clone or download zipped source code into node_modules
project folder.
git clone https://github.com/lucasmenendez/selection-area.git <project>/node_modules/selection-area
Import dist version:
<script src="/node_modules/webproletarian/dist/selection-area.js"></script>
or
<script src="https://unpkg.com/selection-area"></script>
Or import with ES6 import
:
import { SelectionArea } from 'selection-area';
Checkout the demo here.
Area class includes all required functions to emulate the area behaviour. Constructor initializes main params of area Element and stores area DOM Element ID
id
string Area Element DOM IDx
number Initial area position on x axis, default 0 (optional, default 0
)y
number Initial area position on y axis, default 0 (optional, default 0
)Instance function creates DOM Element for selection area, assings the ID provided and sets default style to it. The function receives container Element, append created area to it and stores both of them into the current instance.
parent
Element Container Element to append selection areaRecalculates current area dimensions and call uptdate to reset current DOM Element.
Recalculates current area DOM Element position based en current cursor position.
Deletes current DOM Element from parent container.
Calculates if target Element dimensions and current selection area DOM Element dimensions intersects in any side.
target
Element Target DOM Element to check if area is over itReturns any Boolean with intersection result
SelectionArea class listen mouse movements to create and adapt a selection area checking if intersects with any target child element and returns the content of defined property of that childs.
config
Object Config object
config.container
Element DOM Element to make selectableconfig.targetSelector
string DOM selector of selectables childsconfig.areaId
string? DOM ID for selection area to define stylesconfig.property
string? Property to get from selected childsconfig.callback
function? Function to call when selection endsimport { SelectionArea } from 'selection-area';
let container = document.querySelector('.parent');
let targetSelector = '.child';
let callback = selection => {
if (selection.length == 0) console.warn("empty selection");
else console.log(selection);
}
let selectable = new Selectable({ container, targetSelector, callback });
Function stores user callback to invoke it when selection ends.
callback
function Function defined as callback by userFunction that checks if all required configuration are provided as param, extract whole configurayions inside it and stores into current instance.
config
Onject Configuration object definitionSets custom listeners to mouse down, move and up events.
initArea funtion clears current selection, creates new area with ID provided and instances it into current container.
e
MouseEvent 'mousedown' event metadataupdateArea captures current mouse position and updates current selection area with that position, resizing area and moving it.
e
MouseEvent 'mousemove' event metadata.removeArea extract selected items, destroy current selection area and invokes callback passing values of selected items.
e
MouseEvent 'mouseup' event metadata.checkIntersecionts iterates over all posible targets and checks if current selection area intersects with each of them. Stores all included values of user defined child property.
FAQs
Simple JavaScript mouse & touch seletion area to any DOM container element.
The npm package selection-area receives a total of 18 weekly downloads. As such, selection-area popularity was classified as not popular.
We found that selection-area demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.