Created
September 10, 2015 00:57
-
-
Save jefersondaniel/fdb40989dd7717d8c8c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angularSlideables', []) | |
.directive('slideable', function () { | |
return { | |
restrict:'C', | |
compile: function (element, attr) { | |
// wrap tag | |
var contents = element.html(); | |
element.html('<div class="slideable_content" style="margin:0 !important; padding:0 !important" >' + contents + '</div>'); | |
return function postLink(scope, element, attrs) { | |
// default properties | |
attrs.duration = (!attrs.duration) ? '1s' : attrs.duration; | |
attrs.easing = (!attrs.easing) ? 'ease-in-out' : attrs.easing; | |
element.css({ | |
'overflow': 'hidden', | |
'height': '0px', | |
'transitionProperty': 'height', | |
'transitionDuration': attrs.duration, | |
'transitionTimingFunction': attrs.easing | |
}); | |
}; | |
} | |
}; | |
}) | |
.directive('slideToggle', function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
var target = document.querySelector(attrs.slideToggle); | |
attrs.expanded = false; | |
element.bind('click', function() { | |
var content = target.querySelector('.slideable_content'); | |
if(!attrs.expanded) { | |
content.style.border = '1px solid rgba(0,0,0,0)'; | |
var y = content.clientHeight; | |
content.style.border = 0; | |
target.style.height = y + 'px'; | |
} else { | |
target.style.height = '0px'; | |
} | |
attrs.expanded = !attrs.expanded; | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @jefersondaniel, could you tell me the license of this gist please ?
I'd like to reuse it on another project if you agree with MIT LICENSE.
Thanks