123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
-
- export const extend = ( a, b ) => {
-
- for( let i in b ) {
- a[ i ] = b[ i ];
- }
-
- return a;
-
- }
-
-
- export const queryAll = ( el, selector ) => {
-
- return Array.from( el.querySelectorAll( selector ) );
-
- }
-
-
- export const toggleClass = ( el, className, value ) => {
- if( value ) {
- el.classList.add( className );
- }
- else {
- el.classList.remove( className );
- }
- }
-
-
- export const deserialize = ( value ) => {
-
- if( typeof value === 'string' ) {
- if( value === 'null' ) return null;
- else if( value === 'true' ) return true;
- else if( value === 'false' ) return false;
- else if( value.match( /^-?[\d\.]+$/ ) ) return parseFloat( value );
- }
-
- return value;
-
- }
-
-
- export const distanceBetween = ( a, b ) => {
-
- let dx = a.x - b.x,
- dy = a.y - b.y;
-
- return Math.sqrt( dx*dx + dy*dy );
-
- }
-
-
- export const transformElement = ( element, transform ) => {
-
- element.style.transform = transform;
-
- }
-
-
- export const matches = ( target, selector ) => {
-
- let matchesMethod = target.matches || target.matchesSelector || target.msMatchesSelector;
-
- return !!( matchesMethod && matchesMethod.call( target, selector ) );
-
- }
-
-
- export const closest = ( target, selector ) => {
-
-
- if( typeof target.closest === 'function' ) {
- return target.closest( selector );
- }
-
-
- while( target ) {
- if( matches( target, selector ) ) {
- return target;
- }
-
-
- target = target.parentNode;
- }
-
- return null;
-
- }
-
-
- export const enterFullscreen = element => {
-
- element = element || document.documentElement;
-
-
- let requestMethod = element.requestFullscreen ||
- element.webkitRequestFullscreen ||
- element.webkitRequestFullScreen ||
- element.mozRequestFullScreen ||
- element.msRequestFullscreen;
-
- if( requestMethod ) {
- requestMethod.apply( element );
- }
-
- }
-
-
- export const createSingletonNode = ( container, tagname, classname, innerHTML='' ) => {
-
-
- let nodes = container.querySelectorAll( '.' + classname );
-
-
-
- for( let i = 0; i < nodes.length; i++ ) {
- let testNode = nodes[i];
- if( testNode.parentNode === container ) {
- return testNode;
- }
- }
-
-
- let node = document.createElement( tagname );
- node.className = classname;
- node.innerHTML = innerHTML;
- container.appendChild( node );
-
- return node;
-
- }
-
-
- export const createStyleSheet = ( value ) => {
-
- let tag = document.createElement( 'style' );
- tag.type = 'text/css';
-
- if( value && value.length > 0 ) {
- if( tag.styleSheet ) {
- tag.styleSheet.cssText = value;
- }
- else {
- tag.appendChild( document.createTextNode( value ) );
- }
- }
-
- document.head.appendChild( tag );
-
- return tag;
-
- }
-
-
- export const getQueryHash = () => {
-
- let query = {};
-
- location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, a => {
- query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
- } );
-
-
- for( let i in query ) {
- let value = query[ i ];
-
- query[ i ] = deserialize( unescape( value ) );
- }
-
-
-
- if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
-
- return query;
-
- }
-
-
- export const getRemainingHeight = ( element, height = 0 ) => {
-
- if( element ) {
- let newHeight, oldHeight = element.style.height;
-
-
-
- element.style.height = '0px';
-
-
-
- element.parentNode.style.height = 'auto';
-
- newHeight = height - element.parentNode.offsetHeight;
-
-
- element.style.height = oldHeight + 'px';
-
-
- element.parentNode.style.removeProperty('height');
-
- return newHeight;
- }
-
- return height;
-
- }
-
- const fileExtensionToMimeMap = {
- 'mp4': 'video/mp4',
- 'm4a': 'video/mp4',
- 'ogv': 'video/ogg',
- 'mpeg': 'video/mpeg',
- 'webm': 'video/webm'
- }
-
-
- export const getMimeTypeFromFile = ( filename='' ) => {
- return fileExtensionToMimeMap[filename.split('.').pop()]
- }
-
-
- export const encodeRFC3986URI = ( url='' ) => {
- return encodeURI(url)
- .replace(/%5B/g, "[")
- .replace(/%5D/g, "]")
- .replace(
- /[!'()*]/g,
- (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
- );
- }
|