Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This can be helpful in development when testing a site’s GTM container if it runs custom jQuery code */
- // Overwrite jQuery function with dummy that returns itself
- window.jQuery = function() {
- console.warn(
- "Something attempted to call jQuery but it’s not used this page"
- );
- return jQuery; // enables chaining
- };
- // Most common jQuery methods (not exhaustive, add anything else you need)
- var methods = [
- "addClass",
- "after",
- "append",
- "attr",
- "before",
- "click",
- "css",
- "data",
- "each"
- "hide",
- "html",
- "off",
- "on",
- "prepend",
- "removeClass",
- "show",
- "text",
- "toggle",
- "toggleClass",
- "val",
- ];
- // Add the above methods to our dummy jQuery function (using ES5 so this code can be inlined without a build step)
- for (var i = 0, len = methods.length; i < len; i++) {
- window.jQuery[methods[i]] = function() {
- return false;
- };
- }
- // Create alias
- window.$ = window.jQuery;
Add Comment
Please, Sign In to add comment