Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"name": "angularjs-utilities",

"version": "0.0.9",
"version": "0.0.10",

"homepage": "https://github.com/realcrowd/angularjs-utilities",

Expand Down
99 changes: 51 additions & 48 deletions src/modules/rcWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,92 +14,92 @@
* Configures the specified element as a wizard. Uses the jQuery Bootstrap Wizard Plug-in
*
* @element ANY
* @param {name} Specifies the name of the wizard which can be used to look at state
* @param {name} Specifies the name of the wizard which can be used to look at state
* information on the scope.
*/
var rcWizardDirective = {
'rcWizard': function () {
return {
restrict: 'A',
controller: ['$scope', function ($scope) {

var self;
var wizardElement;
var wizardOptions = {};
var steps = [];

this.currentIndex = 0;
this.firstIndex = 0;
this.navigationLength = 0;

this.addStep = function (step) {

steps.push(step);

if (!step.element || !step.submitController) return;
// if a rcSubmitController is being used, automatically add a _hidden_
// submit button so that
// in order to place an submit button that is still functional it
// has to technically be visible, so instead we place it way off

// if a rcSubmitController is being used, automatically add a _hidden_
// submit button so that

// in order to place an submit button that is still functional it
// has to technically be visible, so instead we place it way off
// screen
jQuery(step.element)
.append('<input type="submit" tabindex="-1" style="position: absolute; left: -9999px; width: 1px; height: 1px;" />')
.attr('action', 'javascript:void(0);');
// bind to the submit complete event on the rcSubmitController and

// bind to the submit complete event on the rcSubmitController and
// if the action was successful, trigger a next on the wizard.
step.submitController.onSubmitComplete(function (evt) {
if (evt.success) {
onForward(step);
}
});
};

this.forward = function () {

if (steps.length)

var currentStep = (steps.length > self.currentIndex) ? steps[self.currentIndex] : null;

if (0 < steps.length && !currentStep) return;

if (0 < steps.length && currentStep.submitController) {
currentStep.submitController.submit();
} else {
onForward(currentStep);
}
};

var onForward = function(currentStep) {
if (0 < steps.length &&
currentStep.formController &&

if (0 < steps.length &&
currentStep.formController &&
currentStep.formController.$invalid) return;

wizardElement.bootstrapWizard('next');
};

this.backward = function () {
wizardElement.bootstrapWizard('previous');
};

var onTabChange = function (activeTab, navigation, currentIndex, nextTab) {

self.currentIndex = nextTab;
self.firstIndex = wizardElement.bootstrapWizard('firstIndex');
self.navigationLength = wizardElement.bootstrapWizard('navigationLength');

if (!$scope.$$phase) $scope.$apply();
};

var onTabClick = function (activeTab, navigation, currentIndex, clickedIndex) {
return false;
};

var onTabShow = function (activeTab, navigation, currentIndex) {

if (currentIndex > 0) {
wizardElement
.find('.nav li:gt(' + (currentIndex - 1) + ')')
Expand All @@ -109,31 +109,34 @@ var rcWizardDirective = {
} else {
wizardElement.find('.nav li').removeClass("success");
}
// if a rcStep is being used on the current tab,

// if a rcStep is being used on the current tab,
// automatically focus on the first input of the current tab. This
// allows for easier keyboard-ony navigation.
if (steps.length > currentIndex && steps[currentIndex].element) {
steps[currentIndex].element.find('input').first().focus();
steps[currentIndex].element.find(':input').first().focus();
}

// scroll page to top
$window.scrollTo(0,0);
};

var updateWizard = function (options) {

wizardOptions = options;

if (wizardElement) {
wizardElement.bootstrapWizard(options);
self.currentIndex = wizardElement.bootstrapWizard('currentIndex');
self.firstIndex = wizardElement.bootstrapWizard('firstIndex');
self.navigationLength = wizardElement.bootstrapWizard('navigationLength');

if (!$scope.$$phase) $scope.$apply();
}
};

this.setWizardElement = function (element) {

wizardElement = element;
self = this;
updateWizard({
Expand All @@ -146,7 +149,7 @@ var rcWizardDirective = {
compile: function (cElement, cAttributes, transclude) {
return {
pre: function (scope, formElement, attributes, wizardController) {
// put a reference to the wizardcontroller on the scope so we can
// put a reference to the wizardcontroller on the scope so we can
// use some of the properties in the markup
scope.rc = scope.rc || {};
scope.rc[attributes.rcWizard] = wizardController;
Expand Down Expand Up @@ -179,17 +182,17 @@ var rcWizardStepDirective = {
restrict: 'A',
require: ['^rcWizard', '?form', '?rcSubmit'],
link: function (scope, element, attributes, controllers) {

var wizardController = controllers[0];

// find all the optional controllers for the step
var formController = controllers.length > 1 ? controllers[1] : null;
var submitController = controllers.length > 2 ? controllers[2] : null;

// add the step to the wizard controller
var step = wizardController.addStep({
'element': element,
'attributes': attributes,
var step = wizardController.addStep({
'element': element,
'attributes': attributes,
'formController': formController,
'submitController': submitController });
}
Expand All @@ -200,4 +203,4 @@ var rcWizardStepDirective = {
angular.module('rcWizard', ['ng'])

.directive(rcWizardDirective)
.directive(rcWizardStepDirective);
.directive(rcWizardStepDirective);