Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Sep 23rd, 2018 64 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. function fireCustomEvent(eventType) {
  2.     if ( document.dispatchEvent ) { // DOM browser
  3.         var e = document.createEvent("UIEvents");
  4.         e.initEvent(eventType, false, false);
  5.         document.dispatchEvent(e);
  6.     } else if ( document.attachEvent ) { // IE
  7.         if ( !document.documentElement[eventType] )
  8.             document.documentElement[eventType] = 1;
  9.         else
  10.             document.documentElement[eventType] += 1;
  11.     }
  12. };
  13.  
  14. $.listenCustomEvent = function(eventType, callback) {
  15.     $(document).on(eventType, callback);
  16.     $(document.documentElement).on('propertychange', function(e) {
  17.         if (e.originalEvent.propertyName == eventType)
  18.             callback();
  19.     });
  20. };
  21.  
  22. // Use case
  23. $.listenCustomEvent('wa-test', function() {
  24.     alert('It\'s worked!');
  25. });
  26.  
  27. fireCustomEvent('wa-test');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top