Last active
December 18, 2015 17:19
-
-
Save morningtoast/5817632 to your computer and use it in GitHub Desktop.
Scratch work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Tiny selector - Callback is passed all matching elements | |
| // $m(parent, tagName, [className,] callback) | |
| function $m(p, tn, cn, cb) { | |
| if (typeof p === "string") { var p = document.getElementById(p); } | |
| var l = p.getElementsByTagName(tn); | |
| for (a=0; a < l.length; a++) { | |
| if (typeof cn === "function") { | |
| cn(l[a]); | |
| } else { | |
| if (l[a].className.indexOf(cn) >= 0) { | |
| cb(l[a]); | |
| } | |
| } | |
| } | |
| } | |
| // Settings | |
| var container = document.getElementById("layout-content") | |
| var utm = "utm_source=morningtoast.com&utm_medium=contentlink&utm_campaign=none"; | |
| // Remove inline dimensions from article images | |
| $m(container, "img", function(el) { | |
| el.removeAttribute("height"); | |
| el.removeAttribute("width"); | |
| }); | |
| // Remove inline dimensions from WP wrapper elements | |
| $m(container, "div", "wp-caption", function(el) { | |
| el.removeAttribute("style"); | |
| }); | |
| // Add UTM strings to all outbound links | |
| $m(container, "a", function(el) { | |
| var href = el.getAttribute("href"); | |
| var newHref = href; | |
| var size = href.split('?'); | |
| if (size.length > 1) { | |
| newHref = href+"&"+utm; | |
| } else { | |
| newHref = href+"?"+utm; | |
| } | |
| el.setAttribute("href",newHref); | |
| }); | |
| // Click bind for main menu | |
| document.getElementById("menu").onclick = function() { | |
| if (this.className == "active") { | |
| this.className = "inactive"; | |
| } else { | |
| this.className = "active"; | |
| } | |
| return false; | |
| }; | |
| // | |
| // Google analytics | |
| var _gaq = _gaq || []; | |
| _gaq.push(['_setAccount', 'UA-319068-1']); | |
| _gaq.push(['_trackPageview']); | |
| (function() { | |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment