Javascript polyfills which let you use native javascript. Rewrite with ES2015 module.
CSS3 selectors, CSS3 media queries, ES5 extensions and a bunch of DOM utilities.
Tested on IE 8+, Firefox 17+, Chrome 15+, Safari 4+, Opera 10+.
bower install go-native --save
####go-native.ie8
- NWMatcher (for selectivizr)
- selectivizr
- respond.js
- ES5 Array (
every
,filter
,forEach
,indexOf
,lastIndexOf
,map
,reduce
,reduceRight
,some
), Date (now
,parse
,toISOString
,toJSON
), Function (bind
), Object (create
,defineProperties
,defineProperty
,freeze
,getOwnPropertyDescriptor
,getOwnPropertyNames
,getPrototypeOf
,isExtensible
,isFrozen
,isSealed
,keys
,preventExtensions
,seal
) and String (trim
) extensions - Event-related methods:
preventDefault
stopPropagation
- EventTarget methods:
addEventListener
removeEventListener
- Element-related properties:
el.childElementCount
el.firstElementChild
el.lastElementChild
el.nextElementSibling
el.previousElementSibling
- Node-related properties:
node.textContent
- Window-related properties/methods:
window.getComputedStyle
window.innerWidth
window.innerHeight
window.pageXOffset / window.scrollY
window.pageYOffset / window.scrollX
####go-native
- ES5 methods:
Number.isNaN
String.prototype.repeat
- Element-related properties:
el.classList
- Node-related properties:
ChildNode.remove
- Length
- requestAnimationFrame
- optimizedResize
- extend
- isNodeList
- DOM related utilities
- DOM.ready
- isInViewport
- indexOf
- getOuterWidth
- getOuterHeight
- getOffsetLeft
- getOffsetTop
- getSupportedProp
- getClosest
- getParents
- getParentsUntil
- getSiblings
- createElement
- append
- prepend
- wrap
- wrapAll
- unwrap
import
go-native in your script (make sure link to src folder, not dist folder)
import * as gn from "../../src/go-native";
Or add go-native.js and go-native.ie8.js to your page.
<!--[if (lt IE 9)]>
<script src="path/to/go-native.ie8.js"></script>
<![endif]-->
<script src="path/to/go-native.js"></script>
gn.ready(function () {
// do something
// on DOM ready
});
var el = document.querySelector('.element');
if (gn.isInViewport(el)) {
// when element is in viewport
// do something
}
var index,
list = document.querySelectorAll('.list > li'),
current = document.querySelector('.current');
index = gn.indexOf(list, current);
// content + padding + border + margin
var box = document.querySelector('.box'),
boxWidth = gn.getOuterWidth(box);
// content + padding + border + margin
var box = document.querySelector('.box'),
boxHeight = gn.getOuterHeight(box);
// content width
var box = document.querySelector('.box'),
boxWidth = gn.getWidth(box);
// content height
var box = document.querySelector('.box'),
boxHeight = gn.getHeight(box);
var box = document.querySelector('.box'),
boxLeft = gn.getOffsetLeft(box);
var box = document.querySelector('.box'),
boxTop = gn.getOffsetTop(box);
var transitionDuration = gn.getSupportedProp(['transitionDuration', 'WebkitTransitionDuration', 'MozTransitionDuration', 'OTransitionDuration']);
console.log(transitionDuration);
var element = document.querySelector('.element'),
red = gn.getClosest(element, '.red');
var element = document.querySelector('.element'),
red = gn.getParents(element, '.red');
var element = document.querySelector('.element'),
siblings = gn.getSiblings(element);
var el = gn.createElement({
tagName: 'div',
id: 'foo',
className: 'foo',
children: [{
tagName: 'div',
html: '<b>Hello, creatElement</b>',
attributes: {
'am-button': 'primary'
}
}]
});
var container = document.querySelector('.container');
gn.append(container, '<li>Peach</li>');
gn.append(container, el);
var container = document.querySelector('.container');
gn.prepend(container, '<li>Pear</li>');
gn.prepend(container, el);
var p = doc.querySelectorAll('p'),
div = doc.createElement('div');
gn.wrap(p, div);
var p = doc.querySelectorAll('p'),
div = doc.createElement('div');
gn.wrapAll(p, div);
var container = doc.querySelectorAll('.container');
gn.unwrap(container);
NWMatcher
from dperini.
selectivizr
from keithclark.
respond
from scottjehl.
Length
from heygrady.
requestAnimationFrame
from darius.
indexOf
from HubSpot/youmightnotneedjquery.
ES5 Array, Function, Date, Object and String extensions from 280north/narwhal.
preventDefault
, stopPropagation
, addEventListener
, removeEventListener
, node.textContent
and optimizedResize
from the Mozilla Developer Network.
el.classList
, el.childElementCount
, el.firstElementChild
, el.lastElementChild
, el.nextElementSibling
, el.previousElementSibling
, ChildNode.remove
, window.getComputedStyle
, window.innerWidth
, window.innerHeight
, window.pageXOffset
, window.pageYOffset
, Array.isArray
, Number.isNaN
and String.prototype.repeat
from Alhadis.
DOM.ready
, isInViewport
, getClosest
, getParents
, getParentsUntil
and getSiblings
from Chris Ferdinandi.
This project is available under the MIT license.