diff options
Diffstat (limited to 'theme/javascript/core')
-rw-r--r-- | theme/javascript/core/glossary.js | 64 | ||||
-rwxr-xr-x | theme/javascript/core/keyboard.js | 3 | ||||
-rwxr-xr-x | theme/javascript/core/navigation.js | 10 |
3 files changed, 72 insertions, 5 deletions
diff --git a/theme/javascript/core/glossary.js b/theme/javascript/core/glossary.js new file mode 100644 index 0000000..3e80f64 --- /dev/null +++ b/theme/javascript/core/glossary.js @@ -0,0 +1,64 @@ +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(); + } + + 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) { + $el.find("p:contains('"+term.name+"')").each( function( i, element ) { + element = $(element); + + var content = $(element).html(); + content = content.replace(term.name, '<span class="glossary-term" data-glossary-term="' + term.id + '" title="' + term.description + '">' + term.name + '</span>'); + element.html(content); + }); + }; + + 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/keyboard.js b/theme/javascript/core/keyboard.js index 5bbdcf2..22fe953 100755 --- a/theme/javascript/core/keyboard.js +++ b/theme/javascript/core/keyboard.js @@ -33,7 +33,6 @@ define([ }; return { - init: init, - search: search + init: init }; });
\ No newline at end of file diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index 3749419..f5d03df 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -5,8 +5,9 @@ define([ "core/state", "core/progress", "core/loading", - "core/search" -], function($, URL, events, state, progress, loading, search) { + "core/search", + "core/glossary" +], function($, URL, events, state, progress, loading, search, glossary) { var prev, next; var usePushState = (typeof history.pushState !== "undefined"); @@ -80,13 +81,16 @@ define([ // Update navigation position updateNavigationPosition(); + // Set glossary items + glossary.prepare(); + // Reset scroll $pageWrapper.scrollTop(0); // Focus on content $pageWrapper.focus(); - // Send to mixpanel + // Notify events.trigger("page.change"); }; |