Skip to content

Commit

Permalink
Merge branch 'feature-disablebtns' of https://github.com/dbartel/ioni…
Browse files Browse the repository at this point in the history
…c-wizard into feature-disablebtns

Conflicts:
	README.md
	example/www/js/controllers.js
  • Loading branch information
arielfaur committed Aug 18, 2015
1 parent d021d7c commit 5d1f812
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 74 deletions.
16 changes: 10 additions & 6 deletions dist/ion-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ angular.module('ionic.wizard', [])
link: function(scope, element, attrs) {
element.addClass('ng-hide');


function checkCondition() {
return (angular.isUndefined(attrs.condition)) ? true : scope.startCondition();
}

element.on('click', function() {
if (angular.isUndefined(attrs.condition)) {
scope.startFn();
} else {
scope.startCondition() && scope.startFn();
}
scope.startFn();
});

scope.$watch(function() {
return checkCondition()
}, function(result) {
element.attr('disabled', !result);
});

scope.$on("slideBox.slideChanged", function(e, index) {
Expand Down
2 changes: 1 addition & 1 deletion dist/ion-wizard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

163 changes: 162 additions & 1 deletion example-storage/www/js/ion-wizard.js
Original file line number Diff line number Diff line change
@@ -1 +1,162 @@
angular.module("ionic.wizard",[]).directive("ionWizardContent",["ionContentDirective",function(n){return angular.extend({},n[0],{scope:!1})}]).directive("ionWizard",["$rootScope","$ionicSlideBoxDelegate",function(n,i){return{restrict:"EA",controller:[function(){var n=[];this.addCondition=function(i){n.push(i)},this.getCondition=function(i){return n[i]}}],link:function(e,o,t,r){var d=0;i.enableSlide(!1),o.css("height","100%"),e.$on("wizard:Previous",function(){var e=r.getCondition(d);e.prev().then(function(){i.previous()},function(){n.$broadcast("wizard:StepFailed",{index:d,direction:"previous"})})}),e.$on("wizard:Next",function(){var e=r.getCondition(d);e.next().then(function(){i.next()},function(){n.$broadcast("wizard:StepFailed",{index:d,direction:"next"})})}),e.$on("slideBox.slideChanged",function(n,i){d=i})}}}]).directive("ionWizardStep",["$q",function(n){return{restrict:"EA",scope:{nextConditionFn:"&nextCondition",prevConditionFn:"&prevCondition"},require:"^^ionWizard",link:function(i,e,o,t){var r=function(){var e=n.defer();return angular.isUndefined(o.nextCondition)?e.resolve():i.nextConditionFn()?e.resolve():e.reject(),e.promise},d=function(){var e=n.defer();return angular.isUndefined(o.prevCondition)?e.resolve():i.prevConditionFn()?e.resolve():e.reject(),e.promise},c={next:r,prev:d};t.addCondition(c)}}}]).directive("ionWizardPrevious",["$rootScope","$ionicSlideBoxDelegate",function(n){return{restrict:"EA",scope:{},link:function(i,e,o,t){e.addClass("ng-hide"),e.on("click",function(){n.$broadcast("wizard:Previous")}),i.$on("slideBox.slideChanged",function(n,i){e.toggleClass("ng-hide",0==i)})}}}]).directive("ionWizardNext",["$rootScope","$ionicSlideBoxDelegate",function(n,i){return{restrict:"EA",scope:{},link:function(e,o,t,r){o.on("click",function(){n.$broadcast("wizard:Next")}),e.$on("slideBox.slideChanged",function(n,e){o.toggleClass("ng-hide",e==i.slidesCount()-1)})}}}]).directive("ionWizardStart",["$ionicSlideBoxDelegate",function(n){return{restrict:"EA",scope:{startFn:"&ionWizardStart"},link:function(i,e){e.addClass("ng-hide"),e.on("click",function(){i.startFn()}),i.$on("slideBox.slideChanged",function(i,o){e.toggleClass("ng-hide",o<n.slidesCount()-1)})}}}]);
angular.module('ionic.wizard', [])
.directive('ionWizardContent', ['ionContentDirective', function(ionContentDirective) {
return angular.extend({}, ionContentDirective[0], { scope: false });
}])
.directive('ionWizard', ['$rootScope', '$ionicSlideBoxDelegate', function($rootScope, $ionicSlideBoxDelegate) {
return{
restrict: 'EA',
controller: [function() {
var conditions = [];

this.addCondition = function(condition) {
conditions.push(condition);
};

this.getCondition = function(index) {
return conditions[index];
};

this.checkNextCondition = function(index) {
return index > (conditions.length - 1)
? false
: conditions[index].next();
};

this.checkPreviousCondition = function(index) {
return index > (conditions.length - 1)
? false
: conditions[index].prev();
};

}],
link: function (scope, element, attrs, controller) {
var currentIndex = 0;

$ionicSlideBoxDelegate.enableSlide(false);

element.css('height', '100%');

scope.$on("wizard:Previous", function() {
$ionicSlideBoxDelegate.previous();
});
scope.$on("wizard:Next", function() {
$ionicSlideBoxDelegate.next();
});

// watch the current index's condition for changes and broadcast the new condition state on change
scope.$watch(function() {
return controller.checkNextCondition(currentIndex) && controller.checkPreviousCondition(currentIndex);
}, function() {
$rootScope.$broadcast("wizard:NextCondition", controller.checkNextCondition(currentIndex));
$rootScope.$broadcast("wizard:PreviousCondition", controller.checkPreviousCondition(currentIndex));
});

scope.$on("slideBox.slideChanged", function(e, index) {
currentIndex = index;
});
}
}

}])
.directive('ionWizardStep', ['$q', function($q) {
return {
restrict: 'EA',
scope: {
nextConditionFn: '&nextCondition',
prevConditionFn: "&prevCondition"
},
require: '^^ionWizard',
link: function(scope, element, attrs, controller) {
var nextFn = function() {
// if there's no condition, just set the condition to true, otherwise evaluate
return angular.isUndefined(attrs.nextCondition)
? true
: scope.nextConditionFn();
};

var prevFn = function() {
return angular.isUndefined(attrs.prevCondition)
? true
: scope.prevConditionFn();
};

var conditions = {
next: nextFn,
prev: prevFn
};

controller.addCondition(conditions);
}
}
}])
.directive('ionWizardPrevious', ['$rootScope', '$ionicSlideBoxDelegate', function($rootScope) {
return{
restrict: 'EA',
scope: {},
link: function(scope, element, attrs, controller) {

element.addClass('ng-hide');

element.on('click', function() {
$rootScope.$broadcast("wizard:Previous");
});

scope.$on("slideBox.slideChanged", function(e, index) {
element.toggleClass('ng-hide', index == 0);
});

scope.$on("wizard:PreviousCondition", function(e, condition) {
element.attr("disabled", !condition);
});
}
}
}])
.directive('ionWizardNext', ['$rootScope', '$ionicSlideBoxDelegate', function($rootScope, $ionicSlideBoxDelegate) {
return{
restrict: 'EA',
scope: {},
link: function(scope, element, attrs, controller) {
element.on('click', function() {
$rootScope.$broadcast("wizard:Next");
});

scope.$on("slideBox.slideChanged", function(e, index) {
element.toggleClass('ng-hide', index == $ionicSlideBoxDelegate.slidesCount() - 1);
});

scope.$on("wizard:NextCondition", function(e, condition) {
element.attr("disabled", !condition);
});
}
}
}])
.directive('ionWizardStart', ['$ionicSlideBoxDelegate', function($ionicSlideBoxDelegate) {
return{
restrict: 'EA',
scope: {
startFn: '&ionWizardStart',
startCondition: '&condition'
},
link: function(scope, element, attrs) {
element.addClass('ng-hide');

function checkCondition() {
return (angular.isUndefined(attrs.condition)) ? true : scope.startCondition();
}

element.on('click', function() {
scope.startFn();
});

scope.$watch(function() {
return checkCondition()
}, function(result) {
element.attr('disabled', !result);
});

scope.$on("slideBox.slideChanged", function(e, index) {
element.toggleClass('ng-hide', index < $ionicSlideBoxDelegate.slidesCount() - 1);
});
}
}
}]);
2 changes: 1 addition & 1 deletion example-storage/www/js/ion-wizard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions example/www/js/ion-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,21 @@ angular.module('ionic.wizard', [])
startFn: '&ionWizardStart',
startCondition: '&condition'
},
link: function(scope, element) {
link: function(scope, element, attrs) {
element.addClass('ng-hide');


function checkCondition() {
return (angular.isUndefined(attrs.condition)) ? true : scope.startCondition();
}

element.on('click', function() {
if (scope.startCondition()) {
scope.startFn();
}
scope.startFn();
});

scope.$watch(function() {
return checkCondition()
}, function(result) {
element.attr('disabled', !result);
});

scope.$on("slideBox.slideChanged", function(e, index) {
Expand Down
Loading

0 comments on commit 5d1f812

Please sign in to comment.