Skip to content

Commit

Permalink
Merge pull request #10 from nhorvath/master
Browse files Browse the repository at this point in the history
Fixing options passing, improving change detection
  • Loading branch information
brandon-barker committed Mar 24, 2016
2 parents 1508520 + 2966784 commit 838a90a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions angular-floatThead.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
var directive = {
require: '?ngModel',
scope: {
floatTheadEnabled: '='
floatThead: '=?',
floatTheadEnabled: '=?'
},
controller: function ($scope, $element, $attrs) {
// default float-thead-enabled to true if not present
if (!$attrs.hasOwnProperty('floatTheadEnabled')) {
$scope.floatTheadEnabled = $attrs.floatTheadEnabled = true;
}
},
link: link,
restrict: 'A'
Expand All @@ -30,23 +37,22 @@
function link(scope, element, attrs, ngModel) {
var isEnabled = (scope.floatTheadEnabled === true);

if (isEnabled) {
jQuery(element).floatThead(scope.$eval(attrs.floatThead));
}

scope.$watch('floatTheadEnabled', function (newVal) {
if (newVal === true) {
jQuery(element).floatThead(scope.$eval(attrs.floatThead));
jQuery(element).floatThead(scope.floatThead);
} else {
jQuery(element).floatThead('destroy');
}
});

if (ngModel) {
// Set $watch to do a deep watch on the ngModel (collection) by specifying true as a 3rd parameter
scope.$watch(attrs.ngModel, function () {
jQuery(element).floatThead('reflow');
}, true);
// hook the model $formatters to get notified when anything changes so we can reflow
ngModel.$formatters.push(function () {
// give time for rerender before reflow
$timeout(function() {
jQuery(element).floatThead('reflow');
});
});
} else {
$log.info('floatThead: ngModel not provided!');
}
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"tests"
],
"dependencies": {
"floatThead": "~1.2.8"
"floatThead": "^1.2.8"
}
}

0 comments on commit 838a90a

Please sign in to comment.