Skip to content

Commit

Permalink
Updated tocify
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed May 11, 2016
1 parent c96da83 commit 8ae3a61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
47 changes: 27 additions & 20 deletions resources/js/script.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
;
/*
Copyright 2016 Marcel Pociot
Copyright 2008-2013 Concur Technologies, Inc.
Copyright 2016 Marcel Pociot
Copyright 2008-2013 Concur Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
*/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
*/
(function (global) {
'use strict';
hljs.initHighlightingOnLoad();
Expand Down Expand Up @@ -150,8 +150,22 @@ under the License.
}
}

function slugify(text){
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}

// if we click on a language tab, activate that language
$(function() {

$('h1, h2').each(function(){
$(this).prop('id', slugify($(this).text()));
});

$(".lang-selector a").on("click", function() {
var language = $(this).data("language-name");
pushURL(language);
Expand All @@ -162,20 +176,13 @@ under the License.
activateLanguage(getLanguageFromQueryString());
};
});
})(window);


/**
* TOC
*/
(function (global) {
'use strict';

var closeToc = function() {
$(".tocify-wrapper").removeClass('open');
$("#nav-button").removeClass('open');
};


var makeToc = function() {
global.toc = $("#toc").tocify({
selectors: 'h1, h2',
Expand Down
Loading

0 comments on commit 8ae3a61

Please sign in to comment.