diff --git a/.gitignore b/.gitignore index a088b6f..7948123 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules bower_components +*.iml +.idea/ \ No newline at end of file diff --git a/bower.json b/bower.json index 83882dd..4f72d3d 100644 --- a/bower.json +++ b/bower.json @@ -3,10 +3,10 @@ "version": "1.0.0", "description": "An implementation of Bootstrap's scollspy and affix for AngularJS", "dependencies": { - "angular": "~1.2.0" + "angular": "~1.4.0" }, "main":"./dist/ngScrollSpy.js", "devDependencies": { - "angular-mocks": "~1.2.0" + "angular-mocks": "~1.4.0" } } diff --git a/dist/ngScrollSpy.js b/dist/ngScrollSpy.js index 5d8de0e..0dcc907 100755 --- a/dist/ngScrollSpy.js +++ b/dist/ngScrollSpy.js @@ -313,26 +313,30 @@ var state = { this[k] = s[k]; } this.state = true; - this.run(); + //this.run(); }, builder: null, setBuilder: function(builder) { this.builder = builder; - this.run(); + //this.run(); }, + itemsLoader: null, + setItemsLoader: function(itemsLoader) { + this.itemsLoader = itemsLoader; + }, run: function() { if (this.builder && this.state) { this.builder(); - this.builder= null; - this.state= null; + //this.builder = null; + this.state = null; if(this.onRun) { this.onRun(); - this.onRun= null; + this.onRun = null; } } } }; -mod.directive('pageitems', function(ScrollSpy) { +mod.directive('pageitems', function(ScrollSpy, $rootScope, $timeout) { var linkfn = function(scope, elem, attrs) { if (!angular.isDefined(scope.selector)) { void 0; @@ -347,20 +351,20 @@ mod.directive('pageitems', function(ScrollSpy) { }; // Store my state that pagemenu will use to build the menu - getState().store({ - topMargin: function() { - return scope.topmargin | 0; // so that pagemenu can correctly offset scrolling - }, - addSpy: function(spyObj) { - scope.spies[spyObj.id] = spyObj; // each item in menu calls this function to register itself with pageitems - }, - getSpy: function(id) { - return scope.spies[id]; // return the spy associated with id - }, - items: function() { - return scope.spyElems; // return a list of dom items to be used to build menu - } - }); + getState().store({ + topMargin: function() { + return scope.topmargin | 0; // so that pagemenu can correctly offset scrolling + }, + addSpy: function(spyObj) { + scope.spies[spyObj.id] = spyObj; // each item in menu calls this function to register itself with pageitems + }, + getSpy: function(id) { + return scope.spies[id]; // return the spy associated with id + }, + items: function() { + return scope.spyElems; // return a list of dom items to be used to build menu + } + }); var spyElems = scope.spyElems; var topmargin = scope.topmargin | 0; @@ -374,7 +378,7 @@ mod.directive('pageitems', function(ScrollSpy) { var spy = spies[spyElem.id]; spy.clear(); - if (spyElem.getBoundingClientRect().top === undefined) { + if (typeof spyElem.getBoundingClientRect().top === 'undefined') { continue; } @@ -402,7 +406,7 @@ mod.directive('pageitems', function(ScrollSpy) { highlightSpy.set(); scope.$on('destroy', function() { ScrollSpy.removeHandler(scrollHandler); - }); + }); }); }; @@ -413,7 +417,22 @@ mod.directive('pageitems', function(ScrollSpy) { selector: '@', topmargin: '@' }, - link: linkfn + link: function (scope, element, attrs) { + getState().setItemsLoader(function() { + linkfn(scope, element, attrs); + }); + + getState().itemsLoader(); + + scope.$watch(function () { + return attrs.reloadOn; + }, function () { + $timeout(function () { //wait for translate completion + getState().itemsLoader(); + getState().run(); + }, 0); + }); + } }; }); mod.directive('pagemenu', function($compile, $location, $anchorScroll) { @@ -473,38 +492,34 @@ mod.directive('pagemenu', function($compile, $location, $anchorScroll) { lastitem= item.link; return item; }; - - // dom items to build menu from - var items = getState().items(); - var markup = ''; - for (var i = 0; i < items.length; i++) { - var item = itemConstruct(items[i]); - if (item.push) { - // new submenu - markup += '
'; - } - } else if (i !== 0) { - // sibling - markup += ''; - } - - // basic markup - markup += '