Guest User

Untitled

a guest
Jun 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. /* This can be helpful in development when testing a site’s GTM container if it runs custom jQuery code */
  2.  
  3. // Overwrite jQuery function with dummy that returns itself
  4. window.jQuery = function() {
  5. console.warn(
  6. "Something attempted to call jQuery but it’s not used this page"
  7. );
  8. return jQuery; // enables chaining
  9. };
  10.  
  11. // Most common jQuery methods (not exhaustive, add anything else you need)
  12. var methods = [
  13. "addClass",
  14. "after",
  15. "append",
  16. "attr",
  17. "before",
  18. "click",
  19. "css",
  20. "data",
  21. "each"
  22. "hide",
  23. "html",
  24. "off",
  25. "on",
  26. "prepend",
  27. "removeClass",
  28. "show",
  29. "text",
  30. "toggle",
  31. "toggleClass",
  32. "val",
  33. ];
  34.  
  35. // Add the above methods to our dummy jQuery function (using ES5 so this code can be inlined without a build step)
  36. for (var i = 0, len = methods.length; i < len; i++) {
  37. window.jQuery[methods[i]] = function() {
  38. return false;
  39. };
  40. }
  41.  
  42. // Create alias
  43. window.$ = window.jQuery;
Add Comment
Please, Sign In to add comment