Git Product home page Git Product logo

tms-web-core-templatedemo's People

Contributors

500foods avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tms-web-core-templatedemo's Issues

Duplicate addEventListeners

At the moment, when switching Forms or SubForms, the DOMContentLoaded event is fired to try and get the AdminLTE JS to attach itself to whatever new components are on the page. The downside to this is that it wasn't designed for this. As a result, it re-attaches itself to any elements it finds, including those that it was already attached to previously.

As this attachment mechanism - addEventListener - uses anonymous functions rather than named functions, there isn't really any good way to remove the event handlers short of cloning the node in place. However, doing so removes other event handlers, including our own.

The resolution, for now, is to alter their JS code to add a class to the objects they've attached themselves to (the LTE class) and then only add new event listeners if that class is not present. Hack-ish, certainly. But it works. So we end up with an adminlte-custom.js that we use instead. A new function is inserted, and then the existing functions are replaced with references to this new function just by doing search and replace. Another approach would be to override the addEventListener function itself, but that's not very fun and besides, we only want these specific functions overridden.

 /* CUSTOMIZATION
 **
 ** Calling the DomLoaded event repeatedly to "apply" this JS to whatever has changed in the page
 ** results in multiple anonymous addEventListener instances and thus breaks the functionality.
 ** To get around this, an addCUSTOMEventListener function is used, with a search/replace to find
 ** the occurences of the original addEventListener calls.  In this custom version, we just check
 ** if there is an LTE class.  If it does, we skip the event.  If it doesn't, we add the class
 ** and then issue the normal addEventListener call.
 **
 ** search:  btn.addEventListener(
 ** replace: window.addCUSTOMEventListener(btn,
 **
 ** search:  selSidebar.addEventListener(
 ** replace: window.addCUSTOMEventListener(selSidebar,
 **
 ** search:  window.addCUSTOMEventListener(targetContentWrapper,
 ** replace: window.addCUSTOMEventListener(targetContentWrapper,
 */


window.addCUSTOMEventListener = function(element,a,b,c) {
  if (element.classList.contains('LTE')) {
//    console.log(element+'aEV orverride: blocked');
  } else {
//    console.log(element+'aEV orverride: added');
    element.classList.add('LTE');
    element.addEventListener(a,b,c);
  }
};

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.