Git Product home page Git Product logo

vanillajs-browser-helpers's People

Contributors

dependabot[bot] avatar tokimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

coddent

vanillajs-browser-helpers's Issues

'Data' cache storage for elements

Store data associated with the element, that is not compatible with the 'data-' attribute.
Like jQuery.

(could be used by eventPlus)

Add create method

Should create a new element of the desired tag, but should also create it from given CSS selector string (like jQuery)

function inView

La fonction inView vérifie si l'élément est dans le viewport. Il serais intéressant d'avoir une option pour savoir si l’élément est dans la vue et est visible (exemple dans un div avec overflow:hidden, inView renvoi true car l'élément est dans le viewport mais il n'est pas visible)

`delegateHandler` needs event type that includes `delegateTarget`

in a usage I had to hack the type a bit to make TS accept e.delegateTarget:

const onClick = delegateHandler(`.${fileTileContainer}`, (e: Event) => {
  const { delegateTarget: thumb } = e as Event & { delegateTarget: Element };
  dispatch('thumbclick', { thumb });
});

Add `wrap`

to wrap an element in given HTML:

function findEmptyElm (elm) {
  const child = elm && elm.firstElementChild
  return child ? findEmptyElm(next) : elm
}

export default (elm, html) => {
  elm.insertAdjacentHTML('afterend', html)
  const insertElm = findEmptyElm(elm.nextElementSibling)
  insertElm && insertElm.appendChild(elm)
}

Clarify installation

I am having issues getting the module to work. I ran the install code and it installed correctly; however, I can't seem to get the code to work in my browser.

Notification.js
`
import inView from 'vanillajs-browser-helpers/es5/inView.js'; //I tried these classes and the es6 varient
import addClass from 'vanillajs-browser-helpers/es5/addClass.js';
import removeClass from 'vanillajs-browser-helpers/es5/removeClass.js';

let notification = document.getElementById('notification');
let notificationTrigger = document.getElementById('notification-trigger');

if (notification != null && notificationTrigger != null) {

if (inView(notificationTrigger) != true) {
	removeClass(notification, "visible",);
} else {
	addClass(notification, "visible",);
}

}
But when I have<Script src="notification.js" type="module"> </script>` I get an error in the console about relative paths. Maybe it's my limited exposure to javascript or limited understanding of node. But could you build a short sample website to help clarify how to get it running beyond just NPM install?

Detect document visibility

Add a visibility change event and a method to detect document visibility.
With fallback to focus/blur if the other event is not supported

Add `data`

Function to add data linked to dom element (like jQuery.data()):

const _cache = new WeakMap()

function elmData (elm, key, data) {
  let elmCache = _cache.get(elm)

  if (!key) { return elmCache }

  if (data) {
    if (!elmCache) {
      elmCache = {}
      _cache.set(elm, elmCache)
    }

    elmCache[key] = data
  }

  return elmCache && elmCache[key]
}

export default elmData

Optimized on scroll

Optimize by using requestAnimationFrame and by taking idle time into account (cancelling the polling after a certain time)

Optimized resize handler

Use requestAnimationFrame to optimize the resize reaction time and with a idle timer (cancelling the polling)

CJS files are not using 'vanillajs-helpers/cjs' files

Once a CJS file is transpiled all references of vanillajs-helpers will still use the es6 version, thus not avoiding the need for transpilation.

eg for isString the compiled output is:

var _isString = require('vanillajs-helpers/isString');

But optimally it should be

var _isString = require('vanillajs-helpers/cjs/isString').default;

A simpler way to avoid this problem needs to be found.

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.