Skip to content

Instantly share code, notes, and snippets.

@aesnyder
Created March 25, 2014 15:23
Show Gist options
  • Save aesnyder/9764109 to your computer and use it in GitHub Desktop.
Save aesnyder/9764109 to your computer and use it in GitHub Desktop.
Postrender test case.
# directive to cause elements to have equal heights
# caveat -- they must share the same parent which contains this
# directive and an attribute of matchHeightOf = ".selector"
app.directive 'cssEqualHeight', ($window, $timeout) ->
restrict: 'A'
compile: (el, attrs) ->
$matchables = angular.element(el).find(attrs.matchHeightOf)
@matchHeights = makeHeightMatcher $matchables
angular.element($window).on 'resize', ->
$matchables.height '100%'
@matchHeights()
# the crappy working solution
$timeout @matchHeights, 250
# if only angular made this real.
postRender: @matchHeights
makeHeightMatcher = ($matchables) ->
->
$matchables.height _.max($matchables.map (i, el) -> el.offsetHeight or 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment