updated field_group from 1.3 to 7.x-1.4

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 20:06:12 +02:00
parent eeb0df349d
commit 4d3a184a81
10 changed files with 161 additions and 85 deletions

View File

@@ -1,7 +1,7 @@
(function ($) {
/**
* This script transforms a set of wrappers into a stack of multipage pages.
* This script transforms a set of wrappers into a stack of multipage pages.
* Another pane can be entered by clicking next/previous.
*
*/
@@ -24,22 +24,22 @@ Drupal.behaviors.MultiPage = {
// Transform each div.multipage-pane into a multipage with controls.
$panes.each(function () {
$controls = $('<div class="multipage-controls-list clearfix"></div>');
$(this).append($controls);
// Check if the submit button needs to move to the latest pane.
if (Drupal.settings.field_group.multipage_move_submit && $('.form-actions').length) {
$('.form-actions', $form).remove().appendTo($($controls, $panes.last()));
}
var multipageControl = new Drupal.multipageControl({
title: $('> .multipage-pane-title', this).text(),
wrapper: $(this),
has_next: $(this).next().length,
has_previous: $(this).prev().length
});
$controls.append(multipageControl.item);
$(this)
.addClass('multipage-pane')
@@ -48,13 +48,14 @@ Drupal.behaviors.MultiPage = {
if (this.id == focusID) {
paneWithFocus = $(this);
}
});
if (paneWithFocus === undefined) {
// If the current URL has a fragment and one of the tabs contains an
// element that matches the URL fragment, activate that tab.
if (window.location.hash && window.location.hash !== '#' && $(window.location.hash, this).length) {
var hash = window.location.hash.replace(/[=%;,\/]/g, "");
if (hash !== '#' && $(hash, this).length) {
paneWithFocus = $(window.location.hash, this).closest('.multipage-pane');
}
else {
@@ -85,12 +86,12 @@ Drupal.multipageControl = function (settings) {
self.nextPage();
return false;
});
this.previousLink.click(function () {
self.previousPage();
return false;
});
/*
// Keyboard events added:
// Pressing the Enter key will open the tab pane.
@@ -116,7 +117,7 @@ Drupal.multipageControl = function (settings) {
};
Drupal.multipageControl.prototype = {
/**
* Displays the tab's content pane.
*/
@@ -135,7 +136,7 @@ Drupal.multipageControl.prototype = {
$('#active-multipage-control').remove();
this.nextLink.after('<span id="active-multipage-control" class="element-invisible">' + Drupal.t('(active page)') + '</span>');
},
/**
* Continues to the next page or step in the form.
*/
@@ -143,7 +144,7 @@ Drupal.multipageControl.prototype = {
this.wrapper.next().data('multipageControl').focus();
$('html, body').scrollTop(this.wrapper.parents('.field-group-multipage-group-wrapper').offset().top);
},
/**
* Returns to the previous page or step in the form.
*/
@@ -210,22 +211,22 @@ Drupal.theme.prototype.multipage = function (settings) {
var controls = {};
controls.item = $('<span class="multipage-button"></span>');
controls.previousLink = $('<input type="button" class="form-submit multipage-link-previous" value="" />');
controls.previousTitle = Drupal.t('Previous page');
controls.item.append(controls.previousLink.val(controls.previousTitle));
controls.item.append(controls.previousLink.val(controls.previousTitle));
controls.nextLink = $('<input type="button" class="form-submit multipage-link-next" value="" />');
controls.nextTitle = Drupal.t('Next page');
controls.item.append(controls.nextLink.val(controls.nextTitle));
if (!settings.has_next) {
controls.nextLink.hide();
}
if (!settings.has_previous) {
controls.previousLink.hide();
}
return controls;
};
@@ -239,18 +240,18 @@ Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
Drupal.FieldGroup.Effects.processMultipage = {
execute: function (context, settings, type) {
if (type == 'form') {
var $firstErrorItem = false;
// Add required fields mark to any element containing required fields
$('div.multipage-pane').each(function(i){
if ($('.error', $(this)).length) {
// Save first error item, for focussing it.
if (!$firstErrorItem) {
$firstErrorItem = $(this).data('multipageControl');
}
}
Drupal.FieldGroup.setGroupWithfocus($(this));
$(this).data('multipageControl').focus();
}
@@ -260,7 +261,7 @@ Drupal.FieldGroup.Effects.processMultipage = {
if ($firstErrorItem) {
$firstErrorItem.focus();
}
}
}
}