(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
that is the tab pane. */ Drupal.multipageControl = function (settings) { var self = this; var controls = Drupal.theme('multipage', settings); $.extend(self, settings, controls); this.nextLink.click(function () { self.nextPage(); return false; }); this.previousLink.click(function () { self.previousPage(); return false; }); /* // Keyboard events added: // Pressing the Enter key will open the tab pane. this.nextLink.keydown(function(event) { if (event.keyCode == 13) { self.focus(); // Set focus on the first input field of the visible wrapper/tab pane. $("div.multipage-pane :input:visible:enabled:first").focus(); return false; } }); // Pressing the Enter key lets you leave the tab again. this.wrapper.keydown(function(event) { // Enter key should not trigger inside