forked from treffynnon/sqlstyle.guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
85 lines (71 loc) · 2.56 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
layout: nil
---
{% include highlight.pack.js %}
hljs.initHighlightingOnLoad();
{% include anchor.min.js %}
anchors.add('h2,h3,h4,h5,h6');
/*
* ScrollTo code
*/
$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var dest = 0;
if(target) {
var $target = $(target);
if($target.length) {
dest = $target.offset().top;
}
}
$('html, body').stop().animate({
'scrollTop': dest
}, 900, 'swing', function () {
window.location.hash = target;
});
});
});
// http://exisweb.net/link-tracking-universal-analytics
(function trackOutbounds() {
var hitCallbackHandler = function(url,win) {
if (win) {
window.open(url, win);
} else {
window.location.href = url;
}
};
var addEvent = function(el, eventName, handler) {
if (el.addEventListener) {
el.addEventListener(eventName, handler);
} else {
el.attachEvent('on' + eventName, function(){
handler.call(el);
});
}
};
if (document.getElementsByTagName) {
var el = document.getElementsByTagName('a');
var getDomain = document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0];
// Look thru each a element
for (var i=0; i < el.length;i++) {
// Extract it's href attribute
var href = (typeof(el[i].getAttribute('href')) == 'string' ) ? el[i].getAttribute('href') : '';
// Query the href for the top level domain (xxxxx.com)
var myDomain = href.match(getDomain);
// If link is outbound and is not to this domain
if ((href.match(/^(https?:|\/\/)/i) && !myDomain) || href.match(/^mailto\:/i)) {
// Add an event to click
addEvent(el[i],'click', function(e) {
var url = this.getAttribute('href'), win = (typeof(this.getAttribute('target')) == 'string') ? this.getAttribute('target') : '';
// Log even to Analytics, once done, go to the link
ga('send', 'event', 'outbound', 'click', url,
{'hitCallback': hitCallbackHandler(url,win)},
{'nonInteraction': 1}
);
e.preventDefault();
});
}
}
}
})();