Giter Site home page Giter Site logo

dommutationobserver's Introduction

DomMutationObserver

Simple wrapper for MutationObserver. MutationObserver needs to handle DOM changes and listen to DOM changes without killing browser performance if this not supported we fall back to simple setInterval action

Supported MutationObserver attributes and every event for these attributes:

  • childList: Set this to true if the element list changed and triggered with appended element.
  • subtree: Set this to true to listen to every children inside this element.
  • attributes: Set this to true if you need to listen to attributes changes.
  • attributeOldValue: Get and store value for changed attributes
  • characterDataOldValue: Get and store value for changed char data

How to use

You can include it on your project and every time you need to define a new instance from it. You can pass your own options and events on init function

var domEventChangesListener = new YDomMutationObserver();

var domEventOptions = {
      attributes: false,
      characterData: true,
      childList: true,
      subtree: true,
      attributeOldValue: false,
      characterDataOldValue: false
};

domEventChangesListener.init(element[0] || jQuery, domEventOptions);
domEventChangesListener.on(YDomMutationObserver.EVENTS.ON_CHARACTER_DATA_CHANGED, domChanged);
domEventChangesListener.on(YDomMutationObserver.EVENTS.ON_CHILD_LIST_CHANGED, domChanged);
domEventChangesListener.on(YDomMutationObserver.EVENTS.ON_CHANGE, harriCallbacks.domChanged)

After that you start listen or observe the changes on your dom.

domEventChangesListener.startListening(500);

To trigger any function manually use the trigger as async call or syncTrigger as sync call function No need to send the record every time if you don't have it you can leave it.

self.trigger('on-attributes-changed', record);

Or

self.syncTrigger('on-attributes-changed', record);

Events

You can use the 'on' function that pass the event name with callback to trigger when DOM changed or you triggered by you self.

  • on-attributes-changed Trigger after the attributes changed with the whole changed object.
  • on-character-data-changed Trigger when char data for this dom changed.
  • on-child-list-changed Trigger when any child list for this dom changed.
  • on-subtree-changed Trigger when children on this dom modified or changed.
  • on-change Trigger for non-support browsers you need to pass it every time to handle default behavior.

For not supported browsers

Trigger the on-change event that triggered by default when the browser not support this

Compatibility

I have tested this on work for HARRI project for auto complete fields that shows a pop list with names to tag them.

dommutationobserver's People

Contributors

yazaabed 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.