diff --git a/dist/angular.headroom.js b/dist/angular.headroom.js index 5dc1d75..5269d0b 100644 --- a/dist/angular.headroom.js +++ b/dist/angular.headroom.js @@ -17,20 +17,35 @@ angular.module('headroom', []).directive('headroom', function() { return { restrict: 'EA', - scope: { - tolerance: '=', - offset: '=', - classes: '=', - scroller: '@' - }, - link: function(scope, element) { + scope: false, + link: function(scope, element, attrs) { var options = {}; angular.forEach(Headroom.options, function(value, key) { - options[key] = scope[key] || Headroom.options[key]; + options[key] = attrs[key] || Headroom.options[key]; }); if (options.scroller) { options.scroller = angular.element(options.scroller)[0]; } + if (attrs.onPin) { + options.onPin = function(){ + scope.$apply(attrs.onPin); + }; + } + if (attrs.onUnpin) { + options.onUnpin = function(){ + scope.$apply(attrs.onUnpin); + }; + } + if (attrs.onTop) { + options.onTop = function(){ + scope.$apply(attrs.onPin); + }; + } + if (attrs.onNotTop) { + options.onNotTop = function(){ + scope.$apply(attrs.onUnpin); + }; + } var headroom = new Headroom(element[0], options); headroom.init(); scope.$on('destroy', function() { diff --git a/dist/angular.headroom.min.js b/dist/angular.headroom.min.js index 6b72f34..d397e42 100644 --- a/dist/angular.headroom.min.js +++ b/dist/angular.headroom.min.js @@ -4,4 +4,4 @@ * License: MIT */ -!function(a){a&&a.module("headroom",[]).directive("headroom",function(){return{restrict:"EA",scope:{tolerance:"=",offset:"=",classes:"=",scroller:"@"},link:function(b,c){var d={};a.forEach(Headroom.options,function(a,c){d[c]=b[c]||Headroom.options[c]}),d.scroller&&(d.scroller=a.element(d.scroller)[0]);var e=new Headroom(c[0],d);e.init(),b.$on("destroy",function(){e.destroy()})}}})}(window.angular); \ No newline at end of file +!function(a){a&&a.module("headroom",[]).directive("headroom",function(){return{restrict:"EA",scope:!1,link:function(b,c,d){console.log(d);var e={};a.forEach(Headroom.options,function(a,b){e[b]=d[b]||Headroom.options[b]}),e.scroller&&(e.scroller=a.element(e.scroller)[0]),d.onPin&&(e.onPin=function(){b.$apply(d.onPin)}),d.onUnpin&&(e.onUnpin=function(){b.$apply(d.onUnpin)}),d.onTop&&(e.onTop=function(){b.$apply(d.onPin)}),d.onNotTop&&(e.onNotTop=function(){b.$apply(d.onUnpin)}),console.log(e);var f=new Headroom(c[0],e);f.init(),b.$on("destroy",function(){f.destroy()})}}})}(window.angular); \ No newline at end of file diff --git a/src/angular.headroom.js b/src/angular.headroom.js index 5f126bb..a37a1b3 100644 --- a/src/angular.headroom.js +++ b/src/angular.headroom.js @@ -11,20 +11,37 @@ angular.module('headroom', []).directive('headroom', function() { return { restrict: 'EA', - scope: { - tolerance: '=', - offset: '=', - classes: '=', - scroller: '@' - }, - link: function(scope, element) { + scope: false, + link: function(scope, element, attrs) { + console.log(attrs); var options = {}; angular.forEach(Headroom.options, function(value, key) { - options[key] = scope[key] || Headroom.options[key]; + options[key] = attrs[key] || Headroom.options[key]; }); if (options.scroller) { options.scroller = angular.element(options.scroller)[0]; } + if (attrs.onPin) { + options.onPin = function(){ + scope.$apply(attrs.onPin); + }; + } + if (attrs.onUnpin) { + options.onUnpin = function(){ + scope.$apply(attrs.onUnpin); + }; + } + if (attrs.onTop) { + options.onTop = function(){ + scope.$apply(attrs.onPin); + }; + } + if (attrs.onNotTop) { + options.onNotTop = function(){ + scope.$apply(attrs.onUnpin); + }; + } + console.log(options); var headroom = new Headroom(element[0], options); headroom.init(); scope.$on('destroy', function() {