|
a |
|
b/docs/pkgdown.js |
|
|
1 |
/* http://gregfranko.com/blog/jquery-best-practices/ */ |
|
|
2 |
(function($) { |
|
|
3 |
$(function() { |
|
|
4 |
|
|
|
5 |
$('.navbar-fixed-top').headroom(); |
|
|
6 |
|
|
|
7 |
$('body').css('padding-top', $('.navbar').height() + 10); |
|
|
8 |
$(window).resize(function(){ |
|
|
9 |
$('body').css('padding-top', $('.navbar').height() + 10); |
|
|
10 |
}); |
|
|
11 |
|
|
|
12 |
$('[data-toggle="tooltip"]').tooltip(); |
|
|
13 |
|
|
|
14 |
var cur_path = paths(location.pathname); |
|
|
15 |
var links = $("#navbar ul li a"); |
|
|
16 |
var max_length = -1; |
|
|
17 |
var pos = -1; |
|
|
18 |
for (var i = 0; i < links.length; i++) { |
|
|
19 |
if (links[i].getAttribute("href") === "#") |
|
|
20 |
continue; |
|
|
21 |
// Ignore external links |
|
|
22 |
if (links[i].host !== location.host) |
|
|
23 |
continue; |
|
|
24 |
|
|
|
25 |
var nav_path = paths(links[i].pathname); |
|
|
26 |
|
|
|
27 |
var length = prefix_length(nav_path, cur_path); |
|
|
28 |
if (length > max_length) { |
|
|
29 |
max_length = length; |
|
|
30 |
pos = i; |
|
|
31 |
} |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
// Add class to parent <li>, and enclosing <li> if in dropdown |
|
|
35 |
if (pos >= 0) { |
|
|
36 |
var menu_anchor = $(links[pos]); |
|
|
37 |
menu_anchor.parent().addClass("active"); |
|
|
38 |
menu_anchor.closest("li.dropdown").addClass("active"); |
|
|
39 |
} |
|
|
40 |
}); |
|
|
41 |
|
|
|
42 |
function paths(pathname) { |
|
|
43 |
var pieces = pathname.split("/"); |
|
|
44 |
pieces.shift(); // always starts with / |
|
|
45 |
|
|
|
46 |
var end = pieces[pieces.length - 1]; |
|
|
47 |
if (end === "index.html" || end === "") |
|
|
48 |
pieces.pop(); |
|
|
49 |
return(pieces); |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
// Returns -1 if not found |
|
|
53 |
function prefix_length(needle, haystack) { |
|
|
54 |
if (needle.length > haystack.length) |
|
|
55 |
return(-1); |
|
|
56 |
|
|
|
57 |
// Special case for length-0 haystack, since for loop won't run |
|
|
58 |
if (haystack.length === 0) { |
|
|
59 |
return(needle.length === 0 ? 0 : -1); |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
for (var i = 0; i < haystack.length; i++) { |
|
|
63 |
if (needle[i] != haystack[i]) |
|
|
64 |
return(i); |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
return(haystack.length); |
|
|
68 |
} |
|
|
69 |
|
|
|
70 |
/* Clipboard --------------------------*/ |
|
|
71 |
|
|
|
72 |
function changeTooltipMessage(element, msg) { |
|
|
73 |
var tooltipOriginalTitle=element.getAttribute('data-original-title'); |
|
|
74 |
element.setAttribute('data-original-title', msg); |
|
|
75 |
$(element).tooltip('show'); |
|
|
76 |
element.setAttribute('data-original-title', tooltipOriginalTitle); |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
if(ClipboardJS.isSupported()) { |
|
|
80 |
$(document).ready(function() { |
|
|
81 |
var copyButton = "<button type='button' class='btn btn-primary btn-copy-ex' type = 'submit' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='tooltip' data-placement='left auto' data-trigger='hover' data-clipboard-copy><i class='fa fa-copy'></i></button>"; |
|
|
82 |
|
|
|
83 |
$(".examples, div.sourceCode").addClass("hasCopyButton"); |
|
|
84 |
|
|
|
85 |
// Insert copy buttons: |
|
|
86 |
$(copyButton).prependTo(".hasCopyButton"); |
|
|
87 |
|
|
|
88 |
// Initialize tooltips: |
|
|
89 |
$('.btn-copy-ex').tooltip({container: 'body'}); |
|
|
90 |
|
|
|
91 |
// Initialize clipboard: |
|
|
92 |
var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { |
|
|
93 |
text: function(trigger) { |
|
|
94 |
return trigger.parentNode.textContent; |
|
|
95 |
} |
|
|
96 |
}); |
|
|
97 |
|
|
|
98 |
clipboardBtnCopies.on('success', function(e) { |
|
|
99 |
changeTooltipMessage(e.trigger, 'Copied!'); |
|
|
100 |
e.clearSelection(); |
|
|
101 |
}); |
|
|
102 |
|
|
|
103 |
clipboardBtnCopies.on('error', function() { |
|
|
104 |
changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); |
|
|
105 |
}); |
|
|
106 |
}); |
|
|
107 |
} |
|
|
108 |
})(window.jQuery || window.$) |