diff --git a/app/tour-controller.js b/app/tour-controller.js index 46782e5..f70c011 100644 --- a/app/tour-controller.js +++ b/app/tour-controller.js @@ -3,7 +3,7 @@ (function (app) { 'use strict'; - app.controller('TourController', ['$q', 'TourConfig', 'uiTourBackdrop', function ($q, TourConfig, uiTourBackdrop) { + app.controller('TourController', ['$q', '$filter', 'TourConfig', 'uiTourBackdrop', function ($q, $filter, TourConfig, uiTourBackdrop) { var self = this, stepList = [], @@ -63,13 +63,8 @@ if (~stepList.indexOf(step)) { return; } - var insertBeforeIndex = 0; - stepList.forEach(function (stepElement, index) { - if (step.order >= stepElement.order) { - insertBeforeIndex = index; - } - }); - stepList.splice(insertBeforeIndex + 1, 0, step); + stepList.push(step); + stepList = $filter('orderBy')(stepList, 'order'); if (resumeWhenFound) { resumeWhenFound(step); } diff --git a/demo/angular-ui-tour.js b/demo/angular-ui-tour.js index 17cd45a..87ef3b3 100644 --- a/demo/angular-ui-tour.js +++ b/demo/angular-ui-tour.js @@ -158,7 +158,7 @@ (function (app) { 'use strict'; - app.controller('TourController', ['$q', 'TourConfig', 'uiTourBackdrop', function ($q, TourConfig, uiTourBackdrop) { + app.controller('TourController', ['$q', '$filter', 'TourConfig', 'uiTourBackdrop', function ($q, $filter, TourConfig, uiTourBackdrop) { var self = this, stepList = [], @@ -218,13 +218,8 @@ if (~stepList.indexOf(step)) { return; } - var insertBeforeIndex = 0; - stepList.forEach(function (stepElement, index) { - if (step.order >= stepElement.order) { - insertBeforeIndex = index; - } - }); - stepList.splice(insertBeforeIndex + 1, 0, step); + stepList.push(step); + stepList = $filter('orderBy')(stepList, 'order'); if (resumeWhenFound) { resumeWhenFound(step); } @@ -471,7 +466,7 @@ //Pass static options through or use defaults var tour = {}, - events = 'onStart onEnd onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '), + events = 'onReady onStart onEnd onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '), properties = 'placement animation popupDelay closePopupDelay trigger enable appendToBody tooltipClass orphan backdrop'.split(' '); //Pass interpolated values through @@ -487,6 +482,9 @@ //Initialize tour scope.tour = ctrl.init(tour); + if (typeof tour.onReady === 'function') { + tour.onReady(); + } } }; diff --git a/dist/angular-ui-tour.js b/dist/angular-ui-tour.js index 720a69b..87ef3b3 100644 --- a/dist/angular-ui-tour.js +++ b/dist/angular-ui-tour.js @@ -158,7 +158,7 @@ (function (app) { 'use strict'; - app.controller('TourController', ['$q', 'TourConfig', 'uiTourBackdrop', function ($q, TourConfig, uiTourBackdrop) { + app.controller('TourController', ['$q', '$filter', 'TourConfig', 'uiTourBackdrop', function ($q, $filter, TourConfig, uiTourBackdrop) { var self = this, stepList = [], @@ -218,13 +218,8 @@ if (~stepList.indexOf(step)) { return; } - var insertBeforeIndex = 0; - stepList.forEach(function (stepElement, index) { - if (step.order >= stepElement.order) { - insertBeforeIndex = index; - } - }); - stepList.splice(insertBeforeIndex + 1, 0, step); + stepList.push(step); + stepList = $filter('orderBy')(stepList, 'order'); if (resumeWhenFound) { resumeWhenFound(step); } diff --git a/dist/angular-ui-tour.min.js b/dist/angular-ui-tour.min.js index 9149aa8..a5d4600 100644 --- a/dist/angular-ui-tour.min.js +++ b/dist/angular-ui-tour.min.js @@ -1 +1 @@ -!function(a){"use strict";a.config(["$uibTooltipProvider",function(a){a.setTriggers({uiTourShow:"uiTourHide"})}])}(angular.module("bm.uiTour",["ngSanitize","ui.bootstrap","smoothScroll"])),function(a){"use strict";a.factory("uiTourBackdrop",["TourConfig","$document","$uibPosition","$window",function(a,b,c,d){function e(){i.addClass("no-scrolling"),i.on("touchmove",k)}function f(){i.removeClass("no-scrolling"),i.off("touchmove",k)}var g,h={},i=angular.element(b[0].body),j=angular.element(b[0].createElement("div")),k=function(a){a.preventDefault()};return function(){var a=".no-scrolling",b="height: 100%; overflow: hidden;",c=document.createElement("style");c.type="text/css",document.getElementsByTagName("head")[0].appendChild(c),c.sheet||c.sheet.insertRule?c.sheet.insertRule(a+"{"+b+"}",0):(c.styleSheet||c.sheet).addRule(a,b)}(),j.css({position:"fixed",top:0,left:0,width:"100%",height:"100%",zIndex:a.get("backdropZIndex"),backgroundColor:"rgba(0, 0, 0, .5)",display:"none"}),i.append(j),h.createForElement=function(b,d,f){var h;g=b.clone(),j.css("display","block"),i.append(g),g.css("zIndex",a.get("backdropZIndex")+1),h=c.offset(b),g.css({position:f?"fixed":"absolute",top:h.top+"px",left:h.left+"px",height:h.height+"px",width:h.width+"px",marginTop:0,marginLeft:0,backgroundColor:i.css("backgroundColor")||"#FFFFFF"}),d&&e()},h.hide=function(){j.css("display","none"),g.remove(),f()},h}])}(angular.module("bm.uiTour")),function(a){"use strict";a.provider("TourConfig",[function(){var a={placement:"top",animation:!0,popupDelay:1,closePopupDelay:0,trigger:"uiTourShow",enable:!0,appendToBody:!1,tooltipClass:"",orphan:!1,backdrop:!1,backdropZIndex:1e4,onStart:null,onEnd:null,onPause:null,onResume:null,onNext:null,onPrev:null,onShow:null,onShown:null,onHide:null,onHidden:null};this.set=function(b,c){a[b]=c},this.$get=[function(){var b={};return b.get=function(b){return a[b]},b.getAll=function(){return angular.copy(a)},b}]}])}(angular.module("bm.uiTour")),function(a){"use strict";a.controller("TourController",["$q","TourConfig","uiTourBackdrop",function(a,b,c){function d(a){var b=a.shift()();return a.forEach(function(a){b=b.then(a)}),b}function e(){var a=h.getCurrentStep(),b=h.getNextStep();return!!(b&&b.enabled||a.nextPath)}function f(){var a=h.getCurrentStep(),b=h.getPrevStep();return!!(b&&b.enabled||a.prevPath)}var g,h=this,i=[],j=null,k={OFF:0,ON:1,PAUSED:2},l=k.OFF,m=b.getAll();h.addStep=function(a){if(!~i.indexOf(a)){var b=0;i.forEach(function(c,d){a.order>=c.order&&(b=d)}),i.splice(b+1,0,a),g&&g(a)}},h.removeStep=function(a){i.splice(i.indexOf(a),1)},h.reorderStep=function(a){h.removeStep(a),h.addStep(a)},h.start=function(){m.onStart&&m.onStart(),j=i[0],l=k.ON,h.showStep(h.getCurrentStep())},h.end=function(){h.getCurrentStep()&&h.hideStep(h.getCurrentStep()),m.onEnd&&m.onEnd(),j=null,l=k.OFF},h.pause=function(){m.onPause&&m.onPause(),l=k.PAUSED,h.hideStep(h.getCurrentStep())},h.resume=function(){m.onResume&&m.onResume(),l=k.ON,h.showStep(h.getCurrentStep())},h.next=function(){var b=h.getCurrentStep();return d([b.onNext||m.onNext||a.resolve,function(){return h.hideStep(b)},function(){return j=h.getNextStep(),h.getCurrentStep()?h.showStep(h.getCurrentStep()):void h.end()}])},h.prev=function(){var b=h.getCurrentStep();return d([b.onPrev||m.onPrev||a.resolve,function(){return h.hideStep(b)},function(){return j=h.getPrevStep(),g?a.resolve():h.getCurrentStep()?h.showStep(h.getCurrentStep()):void h.end()}])},h.showStep=function(b){return d([b.onShow||m.onShow||a.resolve,function(){return(b.backdrop||m.backdrop)&&c.createForElement(b.element,b.preventScrolling,b.fixed),a.resolve()},b.show,b.onShown||m.onShown||a.resolve,function(){return b.isNext=e(),b.isPrev=f(),a.resolve()}])},h.hideStep=function(b){return d([b.onHide||m.onHide||a.resolve,b.hide,function(){return(b.backdrop||m.backdrop)&&c.hide(),a.resolve()},b.onHidden||m.onHidden||a.resolve])},h.getCurrentStep=function(){return j},h.getNextStep=function(){return j?i[i.indexOf(j)+1]:null},h.getPrevStep=function(){return j?i[i.indexOf(j)-1]:null},h.waitFor=function(a){h.pause(),g=function(b){b.stepId===a&&(j=i[i.indexOf(b)],h.resume(),g=null)}},h.init=function(a){return m=angular.extend(m,a),h.options=m,h},h._getSteps=function(){return i},h._getStatus=function(){return l},h._getCurrentStep=function(){return j}}])}(angular.module("bm.uiTour")),function(a){"use strict";a.directive("uiTour",["TourHelpers",function(a){return{restrict:"EA",scope:!0,controller:"TourController",link:function(b,c,d,e){var f={},g="onReady onStart onEnd onShow onShown onHide onHidden onNext onPrev onPause onResume".split(" "),h="placement animation popupDelay closePopupDelay trigger enable appendToBody tooltipClass orphan backdrop".split(" ");a.attachInterpolatedValues(d,f,h,"uiTour"),a.attachEventHandlers(b,d,f,g,"uiTour"),d[a.getAttrName("options")]&&angular.extend(f,b.$eval(d[a.getAttrName("options")])),b.tour=e.init(f),"function"==typeof f.onReady&&f.onReady()}}}])}(angular.module("bm.uiTour")),function(a){"use strict";a.factory("TourHelpers",["$templateCache","$http","$compile","$location","TourConfig","$q",function(a,b,c,d,e,f){function g(a){return"true"===a?!0:"false"===a?!1:a}var h,i={};return h=i.safeApply=function(a,b){var c=a.$$phase;"$apply"===c||"$digest"===c?b&&"function"==typeof b&&b():a.$apply(b)},i.attachEventHandlers=function(a,b,c,d,e){angular.forEach(d,function(d){var g=i.getAttrName(d,e);b[g]&&(c[d]=function(){return f(function(c){h(a,function(){c(a.$eval(b[g]))})})})})},i.attachInterpolatedValues=function(a,b,c,d){angular.forEach(c,function(c){var e=i.getAttrName(c,d);a[e]&&(b[c]=g(a[e]),a.$observe(e,function(a){b[c]=g(a)}))})},i.setRedirect=function(a,b,c,e,g){var h=a[c];a[c]=function(a){return f(function(c){h&&h(a),b.waitFor(g),d.path(e),c()})}},i.getAttrName=function(a,b){return(b||"tourStep")+a.charAt(0).toUpperCase()+a.substr(1)},i}])}(angular.module("bm.uiTour")),function(a){"use strict";a.directive("tourStep",["TourHelpers","$uibTooltip","$q","$sce",function(a,b,c,d){var e=b("tourStep","tourStep","uiTourShow",{popupDelay:1});return{restrict:"EA",scope:!0,require:"^uiTour",compile:function(b,f){f.tourStep||f.$set("tourStep","'PH'");var g=e.compile(b,f);return function(b,e,f,h){var i,j={element:e,stepId:f.tourStep,enabled:!0},k="onShow onShown onHide onHidden onNext onPrev".split(" "),l="content title enabled animation placement backdrop orphan popupDelay popupCloseDelay fixed preventScrolling nextStep prevStep nextPath prevPath".split(" ");a.attachInterpolatedValues(f,j,l),i=f.$observe(a.getAttrName("order"),function(a){j.order=isNaN(1*a)?0:1*a,h.reorderStep(j)}),a.attachEventHandlers(b,f,j,k),f[a.getAttrName("templateUrl")]&&(j.templateUrl=b.$eval(f[a.getAttrName("templateUrl")])),f[a.getAttrName("options")]&&angular.extend(j,b.$eval(f[a.getAttrName("options")])),j.nextPath&&(j.redirectNext=!0,a.setRedirect(j,h,"onNext",j.nextPath,j.nextStep)),j.prevPath&&(j.redirectPrev=!0,a.setRedirect(j,h,"onPrev",j.prevPath,j.prevStep)),j.show=function(){return e.triggerHandler("uiTourShow"),c(function(a){e[0].dispatchEvent(new CustomEvent("uiTourShow")),a()})},j.hide=function(){return c(function(a){e[0].dispatchEvent(new CustomEvent("uiTourHide")),a()})},j.trustedContent=d.trustAsHtml(j.content),h.addStep(j),b.tourStep=j,b.tour=b.tour||h,g(b,e,f),b.$on("$destroy",function(){h.removeStep(j),i()})}}}}]),a.directive("tourStepPopup",["TourConfig","smoothScroll",function(a,b){return{restrict:"EA",replace:!0,scope:{title:"@",content:"@",placement:"@",animation:"&",isOpen:"&",originScope:"&"},templateUrl:"tour-step-popup.html",link:function(c,d){d.css("zIndex",a.get("backdropZIndex")+2),c.originScope().tourStep.fixed&&d.css("position","fixed"),c.$watch("isOpen",function(a){a()&&b(d[0],{offset:100})})}}}])}(angular.module("bm.uiTour")),angular.module("bm.uiTour").run(["$templateCache",function(a){a.put("tour-step-popup.html",'