Repository navigation
Expand file tree
/
Copy pathspoiler.js
More file actions
49 lines (49 loc) · 2.01 KB
/
Copy pathspoiler.js
File metadata and controls
49 lines (49 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Verpackt die selektierten Elemente in einen auf- und zuklappbaren Spoiler.
* @param options Objekt mit den Optionen:
showtext: Buttontext zum Anzeigen.
hidetext: Buttontext zum Verbergen
show: Callback zum Anzeigen des Spoilers. Bekommt das Spoiler-Element als Parameter.
hide: Callback zum Verstecken des Spoilers. Siehe show.
wrapper: HTML-Tag, in den Spoilertext und Button eingebettet werden.
buttonattributes: Objekt mit Attributen für den Spoiler-Button
hidden: Ob der Spoiler zu Beginn versteckt werden soll
*/
(function($){
$.fn.spoiler = function(options){
var defaults = {
"showtext": "Anzeigen",
"hidetext": "Verbergen",
"show": function(obj){$(obj).slideDown();},
"hide": function(obj){$(obj).slideUp();},
"wrapper": '<div class="spoiler-wrapper" />',
"buttonattributes": {},
"hidden": true,
};
options = $.extend({}, defaults, options);
var spoilers = this.wrap(options.wrapper).before('<input type="button"/>');
spoilers.prev().each(function(){
$.extend(this, options.buttonattributes);
this.value = options.hidden ? options.showtext : options.hidetext;
this.visible = options.hidden ? false : true;
}).click(function(){
if(this.visible)
{
$(this).next().each(function(){
options.hide(this);
});
}
else
{
$(this).next().each(function(){
options.show(this);
});
}
this.visible = !this.visible;
this.value = this.visible ? options.hidetext : options.showtext;
});
if(options.hidden)
spoilers.hide();
return this;
};
})(jQuery);