2
To compress this file you can use Dojo ShrinkSafe compressor at
3
http://alex.dojotoolkit.org/shrinksafe/
9
var foswiki; if (!foswiki) foswiki = {};
10
foswiki.JQueryTwistyPlugin = new function () {
15
Retrieves the name of the twisty from an HTML element id. For example 'demotoggle' will return 'demo'.
16
@param inId : (String) HTML element id
20
this._getName = function (e) {
21
var re = new RegExp("(.*)(hide|show|toggle)", "g");
22
var inId = $(e).attr('id');
23
var m = re.exec(inId);
24
var name = (m && m[1]) ? m[1] : "";
29
Retrieves the type of the twisty from an HTML element id. For example 'demotoggle' will return 'toggle'.
30
@param inId : (String) HTML element id
34
this._getType = function (inId) {
35
var re = new RegExp("(.*)(hide|show|toggle)", "g");
36
var m = re.exec(inId);
37
var type = (m && m[2]) ? m[2] : "";
42
Toggles the collapsed state. Calls _update().
45
this._toggleTwisty = function (ref) {
47
ref.state = (ref.state == foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN) ? foswiki.JQueryTwistyPlugin.CONTENT_SHOWN : foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN;
48
self._update(ref, true);
52
Updates the states of UI trinity 'show', 'hide' and 'content'.
53
Saves new state in a cookie if one of the elements has CSS class 'twistyRememberSetting'.
54
@param ref : (Object) foswiki.JQueryTwistyPlugin.Storage object
57
this._update = function (ref, inMaySave) {
58
var showControl = ref.show;
59
var hideControl = ref.hide;
60
var contentElem = ref.toggle;
61
if (ref.state == foswiki.JQueryTwistyPlugin.CONTENT_SHOWN) {
64
$(contentElem).slideDown({easing:'easeInOutQuad', duration:300});
66
$(contentElem).show();
69
$(showControl).addClass("twistyHidden");
70
$(hideControl).removeClass("twistyHidden");
71
$(contentElem).removeClass("twistyHidden");
75
$(contentElem).slideUp({easing:'easeInOutQuad', duration:300});
77
$(contentElem).hide();
79
$(showControl).removeClass("twistyHidden");
80
$(hideControl).addClass("twistyHidden");
81
$(contentElem).addClass("twistyHidden");
83
if (inMaySave && ref.saveSetting) {
84
foswiki.Pref.setPref(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, ref.state);
86
if (ref.clearSetting) {
87
foswiki.Pref.setPref(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, "");
92
Stores a twisty HTML element (either show control, hide control or content 'toggle').
93
@param e : (Object) HTMLElement
96
this._register = function (e) {
98
var name = self._getName(e);
99
var ref = self._storage[name];
101
ref = new foswiki.JQueryTwistyPlugin.Storage();
103
var classValue = $(e).attr('class');
104
if (classValue.match(/\btwistyRememberSetting\b/))
105
ref.saveSetting = true;
106
if (classValue.match(/\btwistyForgetSetting\b/))
107
ref.clearSetting = true;
108
if (classValue.match(/\btwistyStartShow\b/))
109
ref.startShown = true;
110
if (classValue.match(/\btwistyStartHide\b/))
111
ref.startHidden = true;
112
if (classValue.match(/\btwistyFirstStartShow\b/))
113
ref.firstStartShown = true;
114
if (classValue.match(/\btwistyFirstStartHide\b/))
115
ref.firstStartHidden = true;
118
var type = self._getType(e.id);
120
self._storage[name] = ref;
122
case 'show': // fall through
124
e.onclick = function() {
125
self._toggleTwisty(ref);
134
Key-value set of foswiki.JQueryTwistyPlugin.Storage objects. The value is accessed by twisty id identifier name.
135
@example var ref = self._storage["demo"];
144
foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN = 0;
145
foswiki.JQueryTwistyPlugin.CONTENT_SHOWN = 1;
146
foswiki.JQueryTwistyPlugin.COOKIE_PREFIX = "JQueryTwistyPlugin_";
149
The cached full preference cookie string so the data has to be read only once during init.
151
foswiki.JQueryTwistyPlugin.prefList;
154
Initializes a twisty HTML element (either show control, hide control or content 'toggle') by registering and setting the visible state.
155
Calls _register() and _update().
157
@param inId : (String) id of HTMLElement
158
@return The stored foswiki.JQueryTwistyPlugin.Storage object.
160
foswiki.JQueryTwistyPlugin.init = function(e) {
163
// check if already inited
164
var name = this._getName(e);
165
var ref = this._storage[name];
166
if (ref && ref.show && ref.hide && ref.toggle) return ref;
169
ref = this._register(e);
171
if (ref.show && ref.hide && ref.toggle) {
172
// all Twisty elements present
174
var classValue = $(e).attr('class');
175
if (classValue.match(/\btwistyInited1\b/)) {
176
ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN
177
this._update(ref, false);
180
if (classValue.match(/\btwistyInited0\b/)) {
181
ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN
182
this._update(ref, false);
186
if (foswiki.JQueryTwistyPlugin.prefList == null) {
187
// cache complete cookie string
188
foswiki.JQueryTwistyPlugin.prefList = foswiki.Pref.getPrefList();
190
var cookie = foswiki.Pref.getPrefValueFromPrefList(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, foswiki.JQueryTwistyPlugin.prefList);
191
if (ref.firstStartHidden) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN;
192
if (ref.firstStartShown) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN;
193
// cookie setting may override firstStartHidden and firstStartShown
194
if (cookie && cookie == "0") ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN;
195
if (cookie && cookie == "1") ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN;
196
// startHidden and startShown may override cookie
197
if (ref.startHidden) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN;
198
if (ref.startShown) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN;
200
this._update(ref, false);
205
foswiki.JQueryTwistyPlugin.toggleAll = function(inState) {
207
for (var i in this._storage) {
208
var e = this._storage[i];
210
this._update(e, true);
215
Storage container for properties of a twisty HTML element: show control, hide control or toggle content.
217
foswiki.JQueryTwistyPlugin.Storage = function () {
219
this.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; // Number
220
this.hide; // HTMLElement
221
this.show; // HTMLElement
222
this.toggle; // HTMLElement (content element)
223
this.saveSetting = false; // Boolean; default not saved
224
this.clearSetting = false; // Boolean; default not cleared
225
this.startShown; // Boolean
226
this.startHidden; // Boolean
227
this.firstStartShown; // Boolean
228
this.firstStartHidden; // Boolean
235
$(".twistyTrigger, .twistyContent").
236
removeClass("twistyMakeHidden foswikiMakeHidden foswikiMakeVisible foswikiMakeVisibleBlock foswikiMakeVisibleInline").
237
addClass("twistyHidden").
239
foswiki.JQueryTwistyPlugin.init(this);
241
$(".twistyExpandAll").click(function() {
242
foswiki.JQueryTwistyPlugin.toggleAll(foswiki.JQueryTwistyPlugin.CONTENT_SHOWN);
244
$(".twistyCollapseAll").click(function() {
245
foswiki.JQueryTwistyPlugin.toggleAll(foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN);