2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
17 String
.prototype.startsWith
= function(prefix
, caseSensitive
) {
19 return this.toUpperCase().indexOf(prefix
.toUpperCase()) === 0;
21 return this.indexOf(prefix
) === 0;
24 // Compare two strings using Sorensen-Dice Coefficient
25 // see: http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
26 String
.prototype.dice
= function(other
) {
27 var length1
= this.length
- 1;
28 var length2
= other
.length
- 1;
29 if(length1
< 1 || length2
< 1) return 0;
32 for(var i
= 0; i
< length2
; i
++) {
33 bigrams2
.push(other
.substr(i
, 2));
37 for(var i
= 0; i
< length1
; i
++) {
38 var bigram1
= this.substr(i
, 2);
39 for(var j
= 0; j
< length2
; j
++) {
40 if(bigram1
== bigrams2
[j]) {
47 return (2.0 * intersection
) / (length1
+ length2
);
51 delayEvent
: function(handler
, event
) {
52 if(this.delayEvent
.timeout
) {
53 clearTimeout(this.delayEvent
.timeout
);
55 this.delayEvent
.timeout
= setTimeout(function() {
60 scrollTo
: function(target
) {
61 var element
= $
(target
);
63 $
("body, html").animate({
64 scrollTop
: element
.offset().top
- 60
69 openTab
: function(e
) {
71 var url
= document
.location
.toString();
73 var hash
= url
.split('#')[1];
74 var element
= $
('.nav-tabs a[href="#' + hash
+ '"]');
78 Utils
.scrollTo('#' + hash
);
83 var obj
= new URL(url
);
84 var arg
= obj
.searchParams
.get("def");
87 $
('.card.active').removeClass('active');
88 $
(def
).addClass('active');
89 $
(def
).find('.collapse').collapse();
97 window
.addEventListener("hashchange", Utils
.openTab
, false);
99 // Scroll on hash click
100 $
('.summary a[href*=#]').on('click', function(e
) {
102 Utils
.scrollTo(e
.currentTarget
.hash
);
103 history
.pushState({}, '', e
.currentTarget
.hash
);
106 // Change hash for page-reload
107 $
('.nav-tabs a[href]').on('shown.bs.tab', function (e
) {
108 history
.pushState({}, '', e
.target
.hash
)