Coder Social home page Coder Social logo

rlugojr / phosphor-domutil Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dwillmer/phosphor-domutil

0.0 2.0 0.0 298 KB

A small library of utilities for working with the DOM.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 10.64% Shell 5.98% CSS 6.96% TypeScript 76.42%

phosphor-domutil's Introduction

phosphor-domutil

Build Status Coverage Status

Utilities for working with the DOM.

API Docs

Package Install

Prerequisites

npm install --save phosphor-domutil

Source Build

Prerequisites

git clone https://github.com/phosphorjs/phosphor-domutil.git
cd phosphor-domutil
npm install

Rebuild

npm run clean
npm run build

Run Tests

Follow the source build instructions first.

# run tests in Firefox
npm test

# run tests in Chrome
npm run test:chrome

# run tests in IE
npm run test:ie

Build Docs

Follow the source build instructions first.

npm run docs

Navigate to docs/index.html.

Supported Runtimes

The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.

  • IE 11+
  • Firefox 32+
  • Chrome 38+

Bundle for the Browser

Follow the package install instructions first.

Any bundler that understands how to require() files with .js and .css extensions can be used with this package.

Usage Examples

Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.

Cursor Override:

import {
  overrideCursor
} from 'phosphor-domutil';


// force the cursor to be 'wait' for the entire document
let override = overrideCursor('wait');

// clear the override by disposing the return value
override.dispose();

Hit Testing:

import {
  hitTest
} from 'phosphor-domutil';


let div = document.createElement('div');
div.style.position = 'absolute';
div.style.left = '0px';
div.style.top = '0px';
div.style.width = '100px';
div.style.height = '100px';
document.body.appendChild(div);

hitTest(div, 50, 50);   // true
hitTest(div, 150, 150); // false

Box Sizing:

import {
  boxSizing
} from 'phosphor-domutil';

let div = document.createElement('div');
div.style.borderTop = 'solid 10px black';
document.body.appendChild(div);

let sizing = boxSizing(div);
sizing.borderTop;    // 10
sizing.paddingLeft;  // 0
// etc...

Size Limits:

import {
  sizeLimits
} from 'phosphor-domutil';

let div = document.createElement('div');
div.style.minWidth = '90px';
document.body.appendChild(div);

let limits = sizeLimits(div);
limits.minWidth;   // 90
limits.maxHeight;  // Infinity
// etc...

Custom Drag Data:

import {
  clearDragData, getDragData, setDragData
} from 'phosphor-domutil';


// pseudo-code
class SomeDragSource {

  evtDragStart(event: DragEvent): void {
    setDragData(event, 'application/x-my-custom-data', { foo: 12, bar: 42 });
  }

  evtDragEnd(event: DragEvent): void {
    clearDragData(event);
  }
}


// pseudo-code
class SomeDropTarget {

  evtDrop(event: DragEvent): void {
    let data = getDragData(event, 'application/x-my-custom-data');
    console.log(data);  // { foo: 12, bar: 42 }
  }
}

phosphor-domutil's People

Contributors

afshin avatar blink1073 avatar dwillmer avatar sccolbert avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.