(function ($) { /** * This script transforms a set of wrappers into a stack of multipage pages. * Another pane can be entered by clicking next/previous. * */ Drupal.behaviors.MultiPage = { attach: function (context) { $('.multipage-panes', context).once('multipage', function () { var focusID = $(':hidden.multipage-active-control', this).val(); var paneWithFocus; // Check if there are some wrappers that can be converted to multipages. var $panes = $('> div.field-group-multipage', this); var $form = $panes.parents('form'); if ($panes.length == 0) { return; } // Create the next/previous controls. var $controls; // Transform each div.multipage-pane into a multipage with controls. $panes.each(function () { $controls = $('
'); $(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') .data('multipageControl', multipageControl); 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) { paneWithFocus = $(window.location.hash, this).closest('.multipage-pane'); } else { paneWithFocus = $('multipage-open', this).length ? $('multipage-open', this) : $('> .multipage-pane:first', this); } } if (paneWithFocus !== undefined) { paneWithFocus.data('multipageControl').focus(); } }); } }; /** * The multipagePane object represents a single div as a page. * * @param settings * An object with the following keys: * - title: The name of the tab. * - wrapper: The jQuery object of the