Révision e9f59589
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/field_group/multipage/multipage.js | ||
---|---|---|
1 | 1 |
(function ($) { |
2 | 2 |
|
3 | 3 |
/** |
4 |
* This script transforms a set of wrappers into a stack of multipage pages.
|
|
4 |
* This script transforms a set of wrappers into a stack of multipage pages. |
|
5 | 5 |
* Another pane can be entered by clicking next/previous. |
6 | 6 |
* |
7 | 7 |
*/ |
... | ... | |
24 | 24 |
|
25 | 25 |
// Transform each div.multipage-pane into a multipage with controls. |
26 | 26 |
$panes.each(function () { |
27 |
|
|
27 |
|
|
28 | 28 |
$controls = $('<div class="multipage-controls-list clearfix"></div>'); |
29 | 29 |
$(this).append($controls); |
30 |
|
|
30 |
|
|
31 | 31 |
// Check if the submit button needs to move to the latest pane. |
32 | 32 |
if (Drupal.settings.field_group.multipage_move_submit && $('.form-actions').length) { |
33 | 33 |
$('.form-actions', $form).remove().appendTo($($controls, $panes.last())); |
34 | 34 |
} |
35 |
|
|
35 |
|
|
36 | 36 |
var multipageControl = new Drupal.multipageControl({ |
37 | 37 |
title: $('> .multipage-pane-title', this).text(), |
38 | 38 |
wrapper: $(this), |
39 | 39 |
has_next: $(this).next().length, |
40 | 40 |
has_previous: $(this).prev().length |
41 | 41 |
}); |
42 |
|
|
42 |
|
|
43 | 43 |
$controls.append(multipageControl.item); |
44 | 44 |
$(this) |
45 | 45 |
.addClass('multipage-pane') |
... | ... | |
48 | 48 |
if (this.id == focusID) { |
49 | 49 |
paneWithFocus = $(this); |
50 | 50 |
} |
51 |
|
|
51 |
|
|
52 | 52 |
}); |
53 | 53 |
|
54 | 54 |
if (paneWithFocus === undefined) { |
55 | 55 |
// If the current URL has a fragment and one of the tabs contains an |
56 | 56 |
// element that matches the URL fragment, activate that tab. |
57 |
if (window.location.hash && window.location.hash !== '#' && $(window.location.hash, this).length) { |
|
57 |
var hash = window.location.hash.replace(/[=%;,\/]/g, ""); |
|
58 |
if (hash !== '#' && $(hash, this).length) { |
|
58 | 59 |
paneWithFocus = $(window.location.hash, this).closest('.multipage-pane'); |
59 | 60 |
} |
60 | 61 |
else { |
... | ... | |
85 | 86 |
self.nextPage(); |
86 | 87 |
return false; |
87 | 88 |
}); |
88 |
|
|
89 |
|
|
89 | 90 |
this.previousLink.click(function () { |
90 | 91 |
self.previousPage(); |
91 | 92 |
return false; |
92 | 93 |
}); |
93 |
|
|
94 |
|
|
94 | 95 |
/* |
95 | 96 |
// Keyboard events added: |
96 | 97 |
// Pressing the Enter key will open the tab pane. |
... | ... | |
116 | 117 |
}; |
117 | 118 |
|
118 | 119 |
Drupal.multipageControl.prototype = { |
119 |
|
|
120 |
|
|
120 | 121 |
/** |
121 | 122 |
* Displays the tab's content pane. |
122 | 123 |
*/ |
... | ... | |
135 | 136 |
$('#active-multipage-control').remove(); |
136 | 137 |
this.nextLink.after('<span id="active-multipage-control" class="element-invisible">' + Drupal.t('(active page)') + '</span>'); |
137 | 138 |
}, |
138 |
|
|
139 |
|
|
139 | 140 |
/** |
140 | 141 |
* Continues to the next page or step in the form. |
141 | 142 |
*/ |
... | ... | |
143 | 144 |
this.wrapper.next().data('multipageControl').focus(); |
144 | 145 |
$('html, body').scrollTop(this.wrapper.parents('.field-group-multipage-group-wrapper').offset().top); |
145 | 146 |
}, |
146 |
|
|
147 |
|
|
147 | 148 |
/** |
148 | 149 |
* Returns to the previous page or step in the form. |
149 | 150 |
*/ |
... | ... | |
210 | 211 |
|
211 | 212 |
var controls = {}; |
212 | 213 |
controls.item = $('<span class="multipage-button"></span>'); |
213 |
|
|
214 |
|
|
214 | 215 |
controls.previousLink = $('<input type="button" class="form-submit multipage-link-previous" value="" />'); |
215 | 216 |
controls.previousTitle = Drupal.t('Previous page'); |
216 |
controls.item.append(controls.previousLink.val(controls.previousTitle));
|
|
217 |
|
|
217 |
controls.item.append(controls.previousLink.val(controls.previousTitle)); |
|
218 |
|
|
218 | 219 |
controls.nextLink = $('<input type="button" class="form-submit multipage-link-next" value="" />'); |
219 | 220 |
controls.nextTitle = Drupal.t('Next page'); |
220 | 221 |
controls.item.append(controls.nextLink.val(controls.nextTitle)); |
221 |
|
|
222 |
|
|
222 | 223 |
if (!settings.has_next) { |
223 | 224 |
controls.nextLink.hide(); |
224 | 225 |
} |
225 | 226 |
if (!settings.has_previous) { |
226 | 227 |
controls.previousLink.hide(); |
227 | 228 |
} |
228 |
|
|
229 |
|
|
229 | 230 |
return controls; |
230 | 231 |
}; |
231 | 232 |
|
... | ... | |
239 | 240 |
Drupal.FieldGroup.Effects.processMultipage = { |
240 | 241 |
execute: function (context, settings, type) { |
241 | 242 |
if (type == 'form') { |
242 |
|
|
243 |
|
|
243 | 244 |
var $firstErrorItem = false; |
244 |
|
|
245 |
|
|
245 | 246 |
// Add required fields mark to any element containing required fields |
246 | 247 |
$('div.multipage-pane').each(function(i){ |
247 | 248 |
if ($('.error', $(this)).length) { |
248 |
|
|
249 |
|
|
249 | 250 |
// Save first error item, for focussing it. |
250 | 251 |
if (!$firstErrorItem) { |
251 | 252 |
$firstErrorItem = $(this).data('multipageControl'); |
252 |
}
|
|
253 |
|
|
253 |
} |
|
254 |
|
|
254 | 255 |
Drupal.FieldGroup.setGroupWithfocus($(this)); |
255 | 256 |
$(this).data('multipageControl').focus(); |
256 | 257 |
} |
... | ... | |
260 | 261 |
if ($firstErrorItem) { |
261 | 262 |
$firstErrorItem.focus(); |
262 | 263 |
} |
263 |
|
|
264 |
|
|
264 | 265 |
} |
265 | 266 |
} |
266 | 267 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules