Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kakawait/hugo-tranquilpeak-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/tabbed-codeblocks.js')
-rwxr-xr-xsrc/js/tabbed-codeblocks.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/js/tabbed-codeblocks.js b/src/js/tabbed-codeblocks.js
new file mode 100755
index 0000000..234901a
--- /dev/null
+++ b/src/js/tabbed-codeblocks.js
@@ -0,0 +1,41 @@
+(function($) {
+ 'use strict';
+
+ // Animate tabs of tabbed code blocks
+
+ /**
+ * TabbedCodeBlock
+ * @param {String} elems
+ * @constructor
+ */
+ var TabbedCodeBlock = function(elems) {
+ this.$tabbedCodeBlocs = $(elems);
+ };
+
+ TabbedCodeBlock.prototype = {
+ /**
+ * Run TabbedCodeBlock feature
+ * @return {void}
+ */
+ run: function() {
+ var self = this;
+ self.$tabbedCodeBlocs.find('.tab').click(function() {
+ var $codeblock = $(this).parent().parent().parent();
+ var $tabsContent = $codeblock.find('.tabs-content').children('pre, .highlight');
+ // remove `active` css class on all tabs
+ $(this).siblings().removeClass('active');
+ // add `active` css class on the clicked tab
+ $(this).addClass('active');
+ // hide all tab contents
+ $tabsContent.hide();
+ // show only the right one
+ $tabsContent.eq($(this).index()).show();
+ });
+ }
+ };
+
+ $(document).ready(function() {
+ var tabbedCodeBlocks = new TabbedCodeBlock('.codeblock--tabbed');
+ tabbedCodeBlocks.run();
+ });
+})(jQuery);