From a1633163042cb33963919c06297ef5b6ff258d1f Mon Sep 17 00:00:00 2001 From: Birgit Martinelle Date: Thu, 28 Jan 2016 15:15:34 -0500 Subject: [PATCH] added onComplete and onClose callback functions --- README.md | 4 +++- dist/nz-tour.js | 16 ++++++++++++---- dist/nz-tour.min.js | 2 +- src/nz-tour.js | 16 ++++++++++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cb7abce..239818f 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,9 @@ var tour = { dark: false, // Dark mode (Works great with `mask.visible = false`) disableInteraction: false, // Disable interaction with the highlighted elements highlightMargin: 0, // Margin of the highglighted area - disableEscExit: false // Disable end of tour when pressing ESC + disableEscExit: false // Disable end of tour when pressing ESC, + onClose: function() {} //Function called when the tour is closed + onComplete: function(){} //Function called when the tour is completed }, steps: [] } diff --git a/dist/nz-tour.js b/dist/nz-tour.js index 840a737..9e32cca 100755 --- a/dist/nz-tour.js +++ b/dist/nz-tour.js @@ -62,8 +62,9 @@ .then(function() { return startTour(tour); }); + } else { + return startTour(tour); } - return startTour(tour); } function stop() { @@ -72,8 +73,11 @@ return toggleElements(false); }) .then(function() { - service.current.promise.reject(); + var func = service.current.tour.config.onClose; service.current = false; + if(func) { + return func(); + } return true; }); } @@ -164,13 +168,14 @@ service.box = angular.element($compile('')(service)); angular.element(service.body).append(service.box); service.box.removeClass('hidden'); + return $q.when(); } else { service.box.addClass('hidden'); return $timeout(function() { service.cleanup(); }, service.current.tour.config.animationDuration); } - return $q.when(null); + // return $q.when(null); } function doStep(direction) { @@ -210,8 +215,11 @@ function finish() { return toggleElements(false) .then(function() { - service.current.promise.resolve(); + var func = service.current.tour.config.onComplete; service.current = false; + if(func) { + return func(); + } return true; }); } diff --git a/dist/nz-tour.min.js b/dist/nz-tour.min.js index 10eb341..840246e 100644 --- a/dist/nz-tour.min.js +++ b/dist/nz-tour.min.js @@ -1 +1 @@ -!function(){function t(e){return angular.forEach(arguments,function(o){o!==e&&angular.forEach(o,function(o,r){e[r]&&e[r].constructor&&e[r].constructor===Object?t(e[r],o):e[r]=o})}),e}function e(t,e,o,n){t[_removeEventListener](a+e,"wheel"==s?o:r,n||!1)}function o(t,e,o,n){t[i](a+e,"wheel"==s?o:r,n||!1)}function r(t){!t&&(t=window.event);var e={originalEvent:t,target:t.target||t.srcElement,type:"wheel",deltaMode:"MozMousePixelScroll"==t.type?0:1,deltaX:0,deltaZ:0,preventDefault:function(){t.preventDefault?t.preventDefault():t.returnValue=!1}};return"mousewheel"==s?(e.deltaY=-1/40*t.wheelDelta,t.wheelDeltaX&&(e.deltaX=-1/40*t.wheelDeltaX)):e.deltaY=t.detail,callback(e)}var n=angular.module("nzTour",[]);if(n.factory("nzTour",["$q","$rootScope","$compile","$timeout",function(e,o,r,n){function i(t){return t||e.reject("No Tour Specified!"),t.steps.length||e.reject("No steps were found in that tour!"),T.current?s().then(function(){return u(t)}):u(t)}function s(){return m(0).then(function(){return g(!1)}).then(function(){return T.current.promise.reject(),T.current=!1,!0})}function a(){T.current&&x()}function l(){return T.current||T.current.reject(),m(1).then(w).then(function(){return T.current.step++,1}).then(h)}function f(){return m(-1).then(function(){return T.current.step>0?(T.current.step--,-1):e.reject(null)}).then(h)}function c(t){return t>0&&t<=T.current.tour.steps.length?m(0).then(function(){return T.current.step=t-1,0}).then(h):e.reject("Requested step not defined")}function u(o){o.config=t({},T.config,o.config);var r=function(t){if(!angular.isArray(t))return!1;for(var e=0;e