Skip to content

Commit 469864d

Browse files
committed
Merge pull request OpenTechSchool#22 from Ivoz/master
Add spoilers functionality
2 parents 1a5cb74 + fc6cbb6 commit 469864d

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎docs/en/_static/spoilers.js‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(function ($) {
2+
'use strict';
3+
$.fn.showHide = function (options) {
4+
5+
//default vars for the plugin
6+
var defaults = {
7+
speed: 500,
8+
easing: '',
9+
changeText: true,
10+
showText: 'Show',
11+
hideText: 'Hide'
12+
13+
};
14+
options = $.extend(defaults, options);
15+
16+
$(this).hide().data('hidden', true);
17+
18+
$(this).after('<button class="_show_hide" type="button">' + options.showText + '</button>');
19+
20+
$('._show_hide').click(function () {
21+
var me = $(this);
22+
var el = $(this).prev();
23+
el.slideToggle(options.speed, function() {
24+
if (options.changeText) {
25+
if (el.data('hidden')) {
26+
el.data('hidden', false);
27+
me.text(options.hideText);
28+
} else {
29+
el.data('hidden', true);
30+
me.text(options.showText);
31+
}
32+
}
33+
});
34+
});
35+
};
36+
})(jQuery);
37+
38+
(function ($) {
39+
$(document).ready(function() {
40+
'use strict';
41+
$("h3:contains('Solution')").next().showHide();
42+
});
43+
})(jQuery);

‎docs/en/_templates/layout.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% extends "!layout.html" %}
2+
{% set script_files = script_files + ["_static/spoilers.js"] %}

0 commit comments

Comments
 (0)