forked from Sixthdim/angular-vertilize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-vertilize.min.js
13 lines (13 loc) · 1.4 KB
/
angular-vertilize.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*!
* angular-vertilize 1.0.0
* Christopher Collins
* https://github.com/Sixthdim/angular-vertilize.git
*
* Shailendra Sharma
* https://github.com/sharma-shailendra
*
* License: MIT
*/
!function(){"use strict";var module=angular.module("angular.vertilize",[]);module.directive("vertilizeContainer",[function(){return{restrict:"EA",controller:["$scope","$window",function($scope,$window){var _this=this;_this.childrenHeights=[],_this.allocateMe=function(){return _this.childrenHeights.push(0),_this.childrenHeights.length-1},_this.updateMyHeight=function(index,height){_this.childrenHeights[index]=height},_this.getTallestHeight=function(){for(var height=0,i=0;i<_this.childrenHeights.length;i+=1)height=Math.max(height,_this.childrenHeights[i]);
return height},angular.element($window).bind("resize",function(){return $scope.$apply()})}]}}]),module.directive("vertilize",[function(){return{restrict:"EA",require:"^vertilizeContainer",link:function(scope,element,attrs,parent){var myIndex=parent.allocateMe(),getMyRealHeight=function(){var originalHeight=element.css("height");element.css({height:""});var realHeight=$(element).outerHeight();return element.css({height:originalHeight}),realHeight};scope.$watch(getMyRealHeight,function(myNewHeight){myNewHeight&&parent.updateMyHeight(myIndex,myNewHeight)
}),scope.$watch(parent.getTallestHeight,function(tallestHeight){tallestHeight&&element.css("height",tallestHeight)})}}}])}();