Code Monkey home page Code Monkey logo

html's Introduction

Frampton Html

Frampton-Html is a library for DOM and CSS manipulations in JavaScript.

Instalation

> npm install --save-dev @frampton/core
> npm install --save-dev @frampton/html

Usage

import * as Html from '@frampton/html';

All exported functions of >1 arguments is curried.

For example the addClass function could be used as such.

import { addClass } from '@frampton/html';

const addActive = addClass('active');
addActive(document.getElementById('my-id'));

addClass

Adds class to element.

import { addClass } from '@frampton/html';

// Add class to element
addClass('my-class', element);

applyStyles

Apply a hash of styles to a given element.

The applyStyles function will apply vendor prefixes if needed for the current browser.

import { addClass } from '@frampton/html';

applyStyles({
  'box-shadow': '1px 1px 5px rgba(0,0,0,0.5)',
  'padding': '10px 20px',
  'color': 'red'
}, element);

closest

Returns the closest parent to given element matching selector.

import { closest } from '@frampton/html';

const closestElement: HTMLElement =
  closest('.my-class', element);

contains

Returns true if the given parent contains the given child.

import { contains } from '@frampton/html';

const doesContain: boolean =
  contains(document.getElementById('parent'), document.getElementById('child'));

containsSelector

Returns a boolean indicating if the given element, or one of its children, matches the given selector.

import { containsSelector } from '@frampton/html';

const doesContain: boolean =
  containsSelector('.my-class', element);

currentValue

Returns the current value of the given CSS property on given element. Uses getComputedStyle under the hood.

import { currentValue } from '@frampton/html';

const currentHeight: string =
  currentValue('height', element);

elementValue

Returns the value of the given element as a string.

import { elementValue } from '@frampton/html';

const value: string =
  elementValue(document.getElementById('my-input'));

hasClass

Returns a boolean indicating if given element has given class.

import { hasClass } from '@frampton/html';

const doesHaveClass: boolean =
  hasClass('my-class', element);

matches

Returns a boolean indicating the element matches the given selector.

import { matches } from '@frampton/html';

const doesMatch: boolean =
  matches('.my-class', element);

removeClass

Removes given class from element.

import { removeClass } from '@frampton/html';

removeClass('my-class', element);

removeElement

Removes the given element.

import { removeElement } from '@frampton/html';

removeElement(document.getElementById('to-remove'));

removeStyle

Removes given style from element.

import { removeStyle } from '@frampton/html';

removeStyle('height', element);

selectorContains

Returns a boolean indicating if the given element is contained inside of an element matching given selector. Returns true if the element itself matches selector.

import { selectorContains } from '@frampton/style';

selectorContains('.my-class', element);

setStyle

Set value of a style on a given element.

import { setStyle } from '@frampton/html';

setStyle('height', '100px', element);

supported

Returns a string indicating the supported version of a given CSS property on the current browser (vendor prefix applied if needed);

import { supported } from '@frampton/html';

const transformOnBrowser: string =
  supported('transform');

supportedProps

Given a hash of CSS name/value pairs returns a new hash where the property names have any needed vendor prefixes applied.

import { supportedProps } from '@frampton/html';

const browserOpenState =
  supportedProps({
    transform: 'translate(100px)',
    opacity: '0.8',
    perspective: '300px'
  });

html's People

Contributors

kevinbgreene avatar

Watchers

James Cloos 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.