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')(T)),angular.element(T.body).append(T.box),T.box.removeClass("hidden"),e.when(null)):(T.box.addClass("hidden"),n(function(){T.cleanup()},T.current.tour.config.animationDuration))}function h(t){return d(t).then(p)}function d(t){return T.current.tour.steps[T.current.step].before?T.current.tour.steps[T.current.step].before(t):e.when(null)}function p(){return T.$broadcast("step",T.current.step),e.when(null)}function m(t){return T.current.tour.steps[T.current.step].after?T.current.tour.steps[T.current.step].after(t):e.when(null)}function w(){return T.current.step===T.current.tour.steps.length-1?v().then(function(){return e.reject("No more steps left")}):e.when(null)}function v(){return g(!1).then(function(){return T.current.promise.resolve(),T.current=!1,!0})}function x(){}function b(t,e){var o=!1;return function(){o||(t.call(),o=!0,n(function(){o=!1},e))}}function k(t,e,o){var r;return function(){var n=this,i=arguments,s=function(){r=null,o||t.apply(n,i)},a=o&&!r;clearTimeout(r),r=setTimeout(s,e),a&&t.apply(n,i)}}var T=o.$new();return angular.extend(T,{config:{mask:{visible:!0,visibleOnNoTarget:!1,clickThrough:!1,clickExit:!1,scrollThrough:!0,color:"rgba(0,0,0,.7)"},dark:!1,scrollBox:-1!=navigator.userAgent.indexOf("AppleWebKit")?"body":"html",previousText:"Previous",nextText:"Next",finishText:"Finish",animationDuration:400,placementPriority:["bottom","right","top","left"],disableHotkeys:!1,showPrevious:!0,showNext:!0},current:!1,body:angular.element("body"),box:!1,start:i,stop:s,pause:a,next:l,previous:f,gotoStep:c,throttle:b,debounce:k}),window.nzTour=T,T}]),n.directive("nzTour",["$q",function(t){return{template:['',' ',' ',' {{view.step + 1}}',' {{view.length}}',' ✕',' ',' '," ",' ',' {{view.previousText}}',' {{view.nextText}}'," "," ","",'',' ',' ',' ',' ',' ',""].join(" "),link:function(e,o){function r(t){if(t.which>=49&&t.which<=57)return void e.gotoStep(t.which-48);switch(t.which){case 37:return e.previous(),void l(t);case 39:return e.next(),void l(t);case 27:if(!x.disableEscExit)return e.stop(),void l(t);case 38:case 40:return void R()}}function n(t){return t.stopPropagation(t),t.preventDefault(t),t.returnValue=!1,!1}function i(t){var e=E.masks_top.add(E.masks_right).add(E.masks_bottom).add(E.masks_left);t?(_=!0,e.css("transition","all "+x.animationDuration+"ms ease")):(_=!1,e.css("transition","all 0"))}function s(t){var e=E.wrap.add(E.box).add(E.tip);t?e.css("transition","all "+x.animationDuration+"ms ease"):e.css("transition","all 0")}function a(t){var e;e="DOMMouseScroll"==t.type?-40*t.detail:t.wheelDelta;var o=e>0,r=E.content.scrollTop();return o&&!r?l(t):o||E.innerContent.height()-E.content.height()!=r?void 0:l(t)}function l(t){return t.stopPropagation(t),t.preventDefault(t),t.returnValue=!1,!1}function f(){k||(y=!0,i(!1),L(),g(P).then(h).then(d).then(h).then(m))}function c(){y=!1,i(!0)}function u(t,o){E.target=!1;var r=e.current.tour.steps;return P=o,e.view={step:o,length:r.length,previousText:x.previousText,nextText:o==r.length-1?x.finishText:x.nextText,showNext:void 0===r[o].showNext?x.showNext:r[o].showNext,showPrevious:void 0===r[o].showPrevious?x.showPrevious:r[o].showPrevious},E.innerContent.html(r[o].content),E.content.scrollTop(0),k=!0,g(o).then(h).then(d).then(h).then(m).then(function(){k=!1})}function g(o){var r=t.defer();if(E.target)r.resolve(b);else{var n=angular.element(e.current.tour.steps[o].target);n.length?(E.target=angular.element(n[0]),r.resolve(E.target)):r.resolve(!1)}return r.promise}function h(){return E.target?(M.window={width:E.window.width(),height:E.window.height()},M.scroll={width:E.scroll.outerWidth(),height:E.scroll.outerHeight(),offset:E.scroll.offset(),scroll:{top:E.scroll.scrollTop(),left:E.scroll.scrollLeft()}},angular.forEach(M.scroll.offset,function(t,e){M.scroll.offset[e]=Math.ceil(t)}),M.scroll.height=M.scroll.height+M.scroll.offset.top>M.window.height?M.window.height:M.scroll.height,M.scroll.width=M.scroll.width+M.scroll.offset.left>M.window.width?M.window.width:M.scroll.width,M.scroll.offset.toBottom=M.scroll.height+M.scroll.offset.top,M.scroll.offset.toRight=M.scroll.width+M.scroll.offset.left,M.scroll.offset.fromBottom=M.window.height-M.scroll.offset.top-M.scroll.height,M.scroll.offset.fromRight=M.window.width-M.scroll.offset.left-M.scroll.width,M.target={width:E.target.outerWidth(),height:E.target.outerHeight(),offset:E.target.offset()},("body"==x.scrollBox||"html"==x.scrollBox)&&(M.target.offset.top-=M.scroll.scroll.top),angular.forEach(M.target.offset,function(t,e){M.target.offset[e]=Math.ceil(t)}),M.target.offset.toBottom=M.target.offset.top+M.target.height,M.target.offset.toRight=M.target.offset.left+M.target.width,M.target.offset.fromBottom=M.window.height-M.target.offset.top-M.target.height,M.target.offset.fromRight=M.window.width-M.target.offset.left-M.target.width,M.target.margins={offset:{top:M.target.offset.top-T,left:M.target.offset.left-T,toBottom:M.target.offset.toBottom+T,toRight:M.target.offset.toRight+T,fromBottom:M.target.offset.fromBottom-T,fromRight:M.target.offset.fromRight-T},height:M.target.height+2*T,right:M.target.offset.fromRight+2*T},t.when(null)):t.when(null)}function d(){if(!E.target)return t.when(null);var e=p(),o=t.defer();return e?E.scroll.animate({scrollTop:e},y?0:x.animationDuration,function(){o.resolve()}):o.resolve(),o.promise}function p(){return M.target.margins.height>M.scroll.height?M.target.offset.toBottom-zM.scroll.offset.toBottom?M.scroll.scroll.top+(M.target.offset.top+z-M.scroll.offset.toBottom):!1:M.target.margins.offset.topM.scroll.offset.toBottom?M.scroll.scroll.top+(M.target.margins.offset.toBottom-M.scroll.offset.toBottom):!1}function m(){return t.all([w(),v()])}function w(){function o(){return M.target.margins.offset.fromBottom>z?M.target.width>B?(s("bottom","center"),!0):M.target.offset.fromRight+M.target.width>B?(s("bottom","left"),!0):(s("bottom","right"),!0):!1}function r(){return M.target.margins.offset.fromRight>B?M.target.margins.height>M.scroll.height?M.target.offset.top>M.window.height/2?(a("right","top"),!0):M.target.offset.fromBottom>M.window.height/2?(a("right","bottom"),!0):(a("right","center",!0),!0):M.target.height>z?(a("right","center"),!0):M.target.offset.fromBottom+M.target.height>z?(a("right","top"),!0):(a("right","bottom"),!0):!1}function n(){return M.target.margins.offset.left>B?M.target.margins.height>M.scroll.height?(a("left","center",!0),!0):M.target.height>z?(a("left","center"),!0):M.target.offset.fromBottom+M.target.height>z?(a("left","top"),!0):(a("left","bottom"),!0):!1}function i(){return M.target.margins.offset.top>z?M.target.width>B?(s("top","center"),!0):M.target.offset.fromRight+M.target.width>B?(s("top","left"),!0):(s("top","right"),!0):!1}function s(t,e){var o,r,n,i,s;"top"==t?(o=M.target.margins.offset.top,s="bottom",i="-100%"):(o=M.target.margins.offset.toBottom,s="top",i="0"),"right"==e?(r=M.target.offset.toRight,n="-100%"):"center"==e?(r=M.target.offset.left+M.target.width/2,n="-50%"):(r=M.target.offset.left,n="0"),E.wrap.css({left:r+"px",top:o+"px",transform:"translate("+n+","+i+")"}),E.tip.attr("class","vertical "+s+" "+e)}function a(t,e,o){var r,n,i,s,a;"right"==t?(n=M.target.margins.offset.toRight,a="left",i="0"):(n=M.target.margins.offset.left,a="right",i="-100%"),o?(r=M.window.height/2,s="-50%"):"top"==e?(r=M.target.offset.top,s="0"):"center"==e?(r=M.target.offset.top+M.target.height/2,s="-50%"):(r=M.target.offset.toBottom,s="-100%"),E.wrap.css({left:n+"px",top:r+"px",transform:"translate("+i+","+s+")"}),E.tip.attr("class","horizontal "+a+" "+e)}function l(t,e){var o,r,n,i;"top"==t?(o=M.target.margins.offset.topM.scroll.offset.toBottom?M.scroll.offset.toBottom-T:M.target.offset.toBottom,n="-100%"),"right"==e?(r=M.target.offset.left+M.target.width,i="-100%"):"center"==e?(r=M.target.offset.left+M.target.width/2,i="-50%"):(r=M.target.offset.left,i="0"),E.wrap.css({left:r+"px",top:o+"px",transform:"translate("+i+","+n+")"}),E.tip.attr("class","hidden")}function f(){E.wrap.css({left:"50%",top:"50%",transform:"translate(-50%, -50%)",margin:"0"}),E.tip.attr("class","hidden")}var c=e.current.tour.steps[e.current.step];if(!E.target)return void f();var u={bottom:o,right:r,left:n,top:i},g=!1;return angular.forEach(c.placementPriority||x.placementPriority,function(t){!g&&u[t]()&&(g=!0)}),g||l("bottom","center"),t.when(null)}function v(){if(!E.target)return E.masks_top.css({height:x.mask.visibleOnNoTarget?"100%":"0px"}),E.masks_bottom.css({height:"0px"}),E.masks_left.css({top:"0px",height:"100%",width:"0px"}),E.masks_right.css({top:"0px",height:"100%",width:"0px"}),t.when(null);var e=x.highlightMargin?x.highlightMargin:0;return E.masks_top.css({height:M.target.offset.top-e+"px",top:M.target.offset.top<0?M.target.offset.top+"px":0}),E.masks_bottom.css({height:M.target.offset.fromBottom-e+"px",bottom:M.target.offset.fromBottom<0?M.target.offset.fromBottom+"px":0}),E.masks_left.css({top:M.target.offset.top-e+"px",height:M.target.height+2*e+"px",width:M.target.offset.left-e+"px"}),E.masks_right.css({top:M.target.offset.top-e+"px",height:M.target.height+2*e+"px",width:M.target.offset.fromRight-e+"px"}),x.disableInteraction&&E.masks_center.css({height:M.target.height+2*e+"px",top:M.target.offset.top-e+"px",left:M.target.offset.left-e+"px",right:M.target.offset.fromRight-e+"px",backgroundColor:"transparent"}),t.when(null)}var x=e.current.tour.config,b=!1,k=!1,T=15,z=120,B=250,y=!1,_=!0,P=null,E={window:angular.element(window),wrap:o.find("#nzTour-box-wrap"),box:o.find("#nzTour-box"),tip:o.find("#nzTour-tip"),step:o.find("#nzTour-step"),close:o.find("#nzTour-close"),content:o.find("#nzTour-content"),innerContent:o.find("#nzTour-inner-content"),actions:o.find("#nzTour-actions"),previous:o.find("#nzTour-previous"),next:o.find("#nzTour-next"),masks_wrap:o.find(".nzTour-masks"),masks_top:o.find(".nzTour-masks .top"),masks_right:o.find(".nzTour-masks .right"),masks_bottom:o.find(".nzTour-masks .bottom"),masks_left:o.find(".nzTour-masks .left"),masks_center:o.find(".nzTour-masks .center"),scroll:angular.element(x.scrollBox),target:!1},M={window:{},scroll:{},target:{}};i(!0),s(!0),E.masks_wrap.css("pointer-events",x.mask.clickThrough?"none":"all"),x.dark&&(E.box.addClass("dark-box"),T=7);var D=e.$on("step",u),R=e.throttle(f,16),L=e.debounce(c,100);0==x.disableHotkeys&&(E.window.bind("keydown",r),E.window.bind("resize scroll",R),window.addWheelListener(window,R),E.content.bind("scroll",a),window.addWheelListener(E.content[0],a),x.mask.scrollThrough===!1&&window.addWheelListener(E.masks_wrap[0],n)),e.cleanup=function(){D(),E.window.unbind("keydown",r),E.window.unbind("resize scroll",R),window.removeWheelListener(window,R),E.content.unbind("scroll",a),window.removeWheelListener(E.content[0],a),x.mask.scrollThrough===!1&&window.removeWheelListener(E.masks_wrap[0],n),E={},o.remove()},e.tryStop=function(){x.mask.clickExit&&e.stop()}}}}]),!window.addWheelListener){var i,s,a="";window.addEventListener?(i="addEventListener",_removeEventListener="removeEventListener"):(i="attachEvent",_removeEventListener="detachEvent",a="on"),s="onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll",window.addWheelListener=function(t,e,r){o(t,s,e,r),"DOMMouseScroll"==s&&o(t,"MozMousePixelScroll",e,r)},window.removeWheelListener=function(t,o,r){e(t,s,o,r),"DOMMouseScroll"==s&&e(t,"MozMousePixelScroll",o,r)}}}(); \ No newline at end of file +!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(){var t=T.current.tour.config.onClose;return T.current=!1,t?t():!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')(T)),angular.element(T.body).append(T.box),T.box.removeClass("hidden"),e.when()):(T.box.addClass("hidden"),n(function(){T.cleanup()},T.current.tour.config.animationDuration))}function h(t){return d(t).then(p)}function d(t){return T.current.tour.steps[T.current.step].before?T.current.tour.steps[T.current.step].before(t):e.when(null)}function p(){return T.$broadcast("step",T.current.step),e.when(null)}function m(t){return T.current.tour.steps[T.current.step].after?T.current.tour.steps[T.current.step].after(t):e.when(null)}function w(){return T.current.step===T.current.tour.steps.length-1?v().then(function(){return e.reject("No more steps left")}):e.when(null)}function v(){return g(!1).then(function(){var t=T.current.tour.config.onComplete;return T.current=!1,t?t():!0})}function x(){}function b(t,e){var o=!1;return function(){o||(t.call(),o=!0,n(function(){o=!1},e))}}function k(t,e,o){var r;return function(){var n=this,i=arguments,s=function(){r=null,o||t.apply(n,i)},a=o&&!r;clearTimeout(r),r=setTimeout(s,e),a&&t.apply(n,i)}}var T=o.$new();return angular.extend(T,{config:{mask:{visible:!0,visibleOnNoTarget:!1,clickThrough:!1,clickExit:!1,scrollThrough:!0,color:"rgba(0,0,0,.7)"},dark:!1,scrollBox:-1!=navigator.userAgent.indexOf("AppleWebKit")?"body":"html",previousText:"Previous",nextText:"Next",finishText:"Finish",animationDuration:400,placementPriority:["bottom","right","top","left"],disableHotkeys:!1,showPrevious:!0,showNext:!0},current:!1,body:angular.element("body"),box:!1,start:i,stop:s,pause:a,next:l,previous:f,gotoStep:c,throttle:b,debounce:k}),window.nzTour=T,T}]),n.directive("nzTour",["$q",function(t){return{template:['',' ',' ',' {{view.step + 1}}',' {{view.length}}',' ✕',' ',' '," ",' ',' {{view.previousText}}',' {{view.nextText}}'," "," ","",'',' ',' ',' ',' ',' ',""].join(" "),link:function(e,o){function r(t){if(t.which>=49&&t.which<=57)return void e.gotoStep(t.which-48);switch(t.which){case 37:return e.previous(),void l(t);case 39:return e.next(),void l(t);case 27:if(!x.disableEscExit)return e.stop(),void l(t);case 38:case 40:return void R()}}function n(t){return t.stopPropagation(t),t.preventDefault(t),t.returnValue=!1,!1}function i(t){var e=E.masks_top.add(E.masks_right).add(E.masks_bottom).add(E.masks_left);t?(_=!0,e.css("transition","all "+x.animationDuration+"ms ease")):(_=!1,e.css("transition","all 0"))}function s(t){var e=E.wrap.add(E.box).add(E.tip);t?e.css("transition","all "+x.animationDuration+"ms ease"):e.css("transition","all 0")}function a(t){var e;e="DOMMouseScroll"==t.type?-40*t.detail:t.wheelDelta;var o=e>0,r=E.content.scrollTop();return o&&!r?l(t):o||E.innerContent.height()-E.content.height()!=r?void 0:l(t)}function l(t){return t.stopPropagation(t),t.preventDefault(t),t.returnValue=!1,!1}function f(){k||(y=!0,i(!1),L(),g(P).then(h).then(d).then(h).then(m))}function c(){y=!1,i(!0)}function u(t,o){E.target=!1;var r=e.current.tour.steps;return P=o,e.view={step:o,length:r.length,previousText:x.previousText,nextText:o==r.length-1?x.finishText:x.nextText,showNext:void 0===r[o].showNext?x.showNext:r[o].showNext,showPrevious:void 0===r[o].showPrevious?x.showPrevious:r[o].showPrevious},E.innerContent.html(r[o].content),E.content.scrollTop(0),k=!0,g(o).then(h).then(d).then(h).then(m).then(function(){k=!1})}function g(o){var r=t.defer();if(E.target)r.resolve(b);else{var n=angular.element(e.current.tour.steps[o].target);n.length?(E.target=angular.element(n[0]),r.resolve(E.target)):r.resolve(!1)}return r.promise}function h(){return E.target?(M.window={width:E.window.width(),height:E.window.height()},M.scroll={width:E.scroll.outerWidth(),height:E.scroll.outerHeight(),offset:E.scroll.offset(),scroll:{top:E.scroll.scrollTop(),left:E.scroll.scrollLeft()}},angular.forEach(M.scroll.offset,function(t,e){M.scroll.offset[e]=Math.ceil(t)}),M.scroll.height=M.scroll.height+M.scroll.offset.top>M.window.height?M.window.height:M.scroll.height,M.scroll.width=M.scroll.width+M.scroll.offset.left>M.window.width?M.window.width:M.scroll.width,M.scroll.offset.toBottom=M.scroll.height+M.scroll.offset.top,M.scroll.offset.toRight=M.scroll.width+M.scroll.offset.left,M.scroll.offset.fromBottom=M.window.height-M.scroll.offset.top-M.scroll.height,M.scroll.offset.fromRight=M.window.width-M.scroll.offset.left-M.scroll.width,M.target={width:E.target.outerWidth(),height:E.target.outerHeight(),offset:E.target.offset()},("body"==x.scrollBox||"html"==x.scrollBox)&&(M.target.offset.top-=M.scroll.scroll.top),angular.forEach(M.target.offset,function(t,e){M.target.offset[e]=Math.ceil(t)}),M.target.offset.toBottom=M.target.offset.top+M.target.height,M.target.offset.toRight=M.target.offset.left+M.target.width,M.target.offset.fromBottom=M.window.height-M.target.offset.top-M.target.height,M.target.offset.fromRight=M.window.width-M.target.offset.left-M.target.width,M.target.margins={offset:{top:M.target.offset.top-T,left:M.target.offset.left-T,toBottom:M.target.offset.toBottom+T,toRight:M.target.offset.toRight+T,fromBottom:M.target.offset.fromBottom-T,fromRight:M.target.offset.fromRight-T},height:M.target.height+2*T,right:M.target.offset.fromRight+2*T},t.when(null)):t.when(null)}function d(){if(!E.target)return t.when(null);var e=p(),o=t.defer();return e?E.scroll.animate({scrollTop:e},y?0:x.animationDuration,function(){o.resolve()}):o.resolve(),o.promise}function p(){return M.target.margins.height>M.scroll.height?M.target.offset.toBottom-zM.scroll.offset.toBottom?M.scroll.scroll.top+(M.target.offset.top+z-M.scroll.offset.toBottom):!1:M.target.margins.offset.topM.scroll.offset.toBottom?M.scroll.scroll.top+(M.target.margins.offset.toBottom-M.scroll.offset.toBottom):!1}function m(){return t.all([w(),v()])}function w(){function o(){return M.target.margins.offset.fromBottom>z?M.target.width>B?(s("bottom","center"),!0):M.target.offset.fromRight+M.target.width>B?(s("bottom","left"),!0):(s("bottom","right"),!0):!1}function r(){return M.target.margins.offset.fromRight>B?M.target.margins.height>M.scroll.height?M.target.offset.top>M.window.height/2?(a("right","top"),!0):M.target.offset.fromBottom>M.window.height/2?(a("right","bottom"),!0):(a("right","center",!0),!0):M.target.height>z?(a("right","center"),!0):M.target.offset.fromBottom+M.target.height>z?(a("right","top"),!0):(a("right","bottom"),!0):!1}function n(){return M.target.margins.offset.left>B?M.target.margins.height>M.scroll.height?(a("left","center",!0),!0):M.target.height>z?(a("left","center"),!0):M.target.offset.fromBottom+M.target.height>z?(a("left","top"),!0):(a("left","bottom"),!0):!1}function i(){return M.target.margins.offset.top>z?M.target.width>B?(s("top","center"),!0):M.target.offset.fromRight+M.target.width>B?(s("top","left"),!0):(s("top","right"),!0):!1}function s(t,e){var o,r,n,i,s;"top"==t?(o=M.target.margins.offset.top,s="bottom",i="-100%"):(o=M.target.margins.offset.toBottom,s="top",i="0"),"right"==e?(r=M.target.offset.toRight,n="-100%"):"center"==e?(r=M.target.offset.left+M.target.width/2,n="-50%"):(r=M.target.offset.left,n="0"),E.wrap.css({left:r+"px",top:o+"px",transform:"translate("+n+","+i+")"}),E.tip.attr("class","vertical "+s+" "+e)}function a(t,e,o){var r,n,i,s,a;"right"==t?(n=M.target.margins.offset.toRight,a="left",i="0"):(n=M.target.margins.offset.left,a="right",i="-100%"),o?(r=M.window.height/2,s="-50%"):"top"==e?(r=M.target.offset.top,s="0"):"center"==e?(r=M.target.offset.top+M.target.height/2,s="-50%"):(r=M.target.offset.toBottom,s="-100%"),E.wrap.css({left:n+"px",top:r+"px",transform:"translate("+i+","+s+")"}),E.tip.attr("class","horizontal "+a+" "+e)}function l(t,e){var o,r,n,i;"top"==t?(o=M.target.margins.offset.topM.scroll.offset.toBottom?M.scroll.offset.toBottom-T:M.target.offset.toBottom,n="-100%"),"right"==e?(r=M.target.offset.left+M.target.width,i="-100%"):"center"==e?(r=M.target.offset.left+M.target.width/2,i="-50%"):(r=M.target.offset.left,i="0"),E.wrap.css({left:r+"px",top:o+"px",transform:"translate("+i+","+n+")"}),E.tip.attr("class","hidden")}function f(){E.wrap.css({left:"50%",top:"50%",transform:"translate(-50%, -50%)",margin:"0"}),E.tip.attr("class","hidden")}var c=e.current.tour.steps[e.current.step];if(!E.target)return void f();var u={bottom:o,right:r,left:n,top:i},g=!1;return angular.forEach(c.placementPriority||x.placementPriority,function(t){!g&&u[t]()&&(g=!0)}),g||l("bottom","center"),t.when(null)}function v(){if(!E.target)return E.masks_top.css({height:x.mask.visibleOnNoTarget?"100%":"0px"}),E.masks_bottom.css({height:"0px"}),E.masks_left.css({top:"0px",height:"100%",width:"0px"}),E.masks_right.css({top:"0px",height:"100%",width:"0px"}),t.when(null);var e=x.highlightMargin?x.highlightMargin:0;return E.masks_top.css({height:M.target.offset.top-e+"px",top:M.target.offset.top<0?M.target.offset.top+"px":0}),E.masks_bottom.css({height:M.target.offset.fromBottom-e+"px",bottom:M.target.offset.fromBottom<0?M.target.offset.fromBottom+"px":0}),E.masks_left.css({top:M.target.offset.top-e+"px",height:M.target.height+2*e+"px",width:M.target.offset.left-e+"px"}),E.masks_right.css({top:M.target.offset.top-e+"px",height:M.target.height+2*e+"px",width:M.target.offset.fromRight-e+"px"}),x.disableInteraction&&E.masks_center.css({height:M.target.height+2*e+"px",top:M.target.offset.top-e+"px",left:M.target.offset.left-e+"px",right:M.target.offset.fromRight-e+"px",backgroundColor:"transparent"}),t.when(null)}var x=e.current.tour.config,b=!1,k=!1,T=15,z=120,B=250,y=!1,_=!0,P=null,E={window:angular.element(window),wrap:o.find("#nzTour-box-wrap"),box:o.find("#nzTour-box"),tip:o.find("#nzTour-tip"),step:o.find("#nzTour-step"),close:o.find("#nzTour-close"),content:o.find("#nzTour-content"),innerContent:o.find("#nzTour-inner-content"),actions:o.find("#nzTour-actions"),previous:o.find("#nzTour-previous"),next:o.find("#nzTour-next"),masks_wrap:o.find(".nzTour-masks"),masks_top:o.find(".nzTour-masks .top"),masks_right:o.find(".nzTour-masks .right"),masks_bottom:o.find(".nzTour-masks .bottom"),masks_left:o.find(".nzTour-masks .left"),masks_center:o.find(".nzTour-masks .center"),scroll:angular.element(x.scrollBox),target:!1},M={window:{},scroll:{},target:{}};i(!0),s(!0),E.masks_wrap.css("pointer-events",x.mask.clickThrough?"none":"all"),x.dark&&(E.box.addClass("dark-box"),T=7);var D=e.$on("step",u),R=e.throttle(f,16),L=e.debounce(c,100);0==x.disableHotkeys&&(E.window.bind("keydown",r),E.window.bind("resize scroll",R),window.addWheelListener(window,R),E.content.bind("scroll",a),window.addWheelListener(E.content[0],a),x.mask.scrollThrough===!1&&window.addWheelListener(E.masks_wrap[0],n)),e.cleanup=function(){D(),E.window.unbind("keydown",r),E.window.unbind("resize scroll",R),window.removeWheelListener(window,R),E.content.unbind("scroll",a),window.removeWheelListener(E.content[0],a),x.mask.scrollThrough===!1&&window.removeWheelListener(E.masks_wrap[0],n),E={},o.remove()},e.tryStop=function(){x.mask.clickExit&&e.stop()}}}}]),!window.addWheelListener){var i,s,a="";window.addEventListener?(i="addEventListener",_removeEventListener="removeEventListener"):(i="attachEvent",_removeEventListener="detachEvent",a="on"),s="onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll",window.addWheelListener=function(t,e,r){o(t,s,e,r),"DOMMouseScroll"==s&&o(t,"MozMousePixelScroll",e,r)},window.removeWheelListener=function(t,o,r){e(t,s,o,r),"DOMMouseScroll"==s&&e(t,"MozMousePixelScroll",o,r)}}}(); \ No newline at end of file diff --git a/src/nz-tour.js b/src/nz-tour.js index 3c725a6..8204982 100755 --- a/src/nz-tour.js +++ b/src/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; }); }