diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-22 22:36:59 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-22 22:36:59 +0100 |
commit | 66841b1bb742498b6805b018cac74c4c94b98a72 (patch) | |
tree | 5bf6e3bc5c849520c0d5502c2a931cf1c7ae7df2 /theme/javascript/core | |
parent | 74ea419c530921374ffbe893f01b6a4695995349 (diff) | |
download | gitbook-66841b1bb742498b6805b018cac74c4c94b98a72.zip gitbook-66841b1bb742498b6805b018cac74c4c94b98a72.tar.gz gitbook-66841b1bb742498b6805b018cac74c4c94b98a72.tar.bz2 |
Remove glossary from theme js
Diffstat (limited to 'theme/javascript/core')
-rw-r--r-- | theme/javascript/core/glossary.js | 117 | ||||
-rwxr-xr-x | theme/javascript/core/navigation.js | 8 |
2 files changed, 2 insertions, 123 deletions
diff --git a/theme/javascript/core/glossary.js b/theme/javascript/core/glossary.js deleted file mode 100644 index 44ebab1..0000000 --- a/theme/javascript/core/glossary.js +++ /dev/null @@ -1,117 +0,0 @@ -define([ - "jQuery", - "lodash", - "core/state" -], function($, _, state) { - var index = null; - - // Use a specific idnex - var useIndex = function(data) { - index = data; - }; - - // Load complete index - var loadIndex = function() { - return $.getJSON(state.basePath+"/glossary_index.json") - .then(useIndex); - }; - - // Get index and return a promise - var getIndex = function() { - var d = $.Deferred(); - - if (index) { - d.resolve(index); - } else { - loadIndex().done(function(){ - d.resolve(index); - }).fail(d.reject); - } - - return d.promise(); - } - - $.fn.replaceText = function( search, replace, text_only ) { - return this.each(function(){ - var node = this.firstChild, - val, - new_val, - - // Elements to be removed at the end. - remove = []; - - // Only continue if firstChild exists. - if ( node ) { - - // Loop over all childNodes. - do { - - // Only process text nodes. - if ( node.nodeType === 3 ) { - - // The original node value. - val = node.nodeValue; - - // The new value. - new_val = val.replace( search, replace ); - - // Only replace text if the new value is actually different! - if ( new_val !== val ) { - - if ( !text_only && /</.test( new_val ) ) { - // The new value contains HTML, set it in a slower but far more - // robust way. - $(node).before( new_val ); - - // Don't remove the node yet, or the loop will lose its place. - remove.push( node ); - } else { - // The new value contains no HTML, so it can be set in this - // very fast, simple way. - node.nodeValue = new_val; - } - } - } - - } while ( node = node.nextSibling ); - } - - // Time to remove those elements! - remove.length && $(remove).remove(); - }); - }; - - var pregQuote = function( str ) { - return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1"); - }; - - var init = function() { - // Bind click on glossary item - $(document).on("click", ".book-body .page-wrapper .page-inner .glossary-term", function(e) { - e.preventDefault(); - - location.href = state.basePath+"/GLOSSARY.html#"+$(e.currentTarget).data("glossary-term"); - }); - }; - - var replaceTerm = function($el, term) { - var r = new RegExp( "\\b(" + pregQuote(term.name.toLowerCase()) + ")\\b" , 'gi' ); - - $el.find("*").replaceText(r, function(match) { - return "<span class='glossary-term' data-glossary-term='"+term.id+"' title='"+term.description+"'>"+match+"</span>"; - }); - - }; - - var prepare = function() { - getIndex() - .done(function() { - _.each(index, _.partial(replaceTerm, $(".book-body .page-wrapper .page-inner"))); - }); - }; - - return { - init: init, - prepare: prepare - }; -});
\ No newline at end of file diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index f5d03df..947f4db 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -5,9 +5,8 @@ define([ "core/state", "core/progress", "core/loading", - "core/search", - "core/glossary" -], function($, URL, events, state, progress, loading, search, glossary) { + "core/search" +], function($, URL, events, state, progress, loading, search) { var prev, next; var usePushState = (typeof history.pushState !== "undefined"); @@ -81,9 +80,6 @@ define([ // Update navigation position updateNavigationPosition(); - // Set glossary items - glossary.prepare(); - // Reset scroll $pageWrapper.scrollTop(0); |