/* 
  	10.06.2016, barwicki@iz.de, this module is intended to provide general helper util services
*/
(function(){

angular.module('iz.util', [])

.directive('afterRender',afterRenderDirective)
.service('UtilServices',UtilServices)


UtilServices.$inject = ['$timeout'];
function UtilServices(){
  	  var chunkArray = function(arr, len) {
		var chunks = [],
			i = 0,
			n = arr.length;
		while (i < n) {
		  chunks.push(arr.slice(i, i += len));
		}
		return chunks;
	  };
  return {
  	chunkArray : chunkArray
  }
}		 
		 
afterRenderDirective.$inject = ['$timeout'];
function afterRenderDirective($timeout) {
  /* 
  	10.06.2016, barwicki@iz.de, this directive allows to 
  	call a function after an element is rendered in DOM
  */
  
    var def = {
        restrict: 'A',
        terminal: true,
        transclude: false,
        link: function (scope, element, attrs) {
		  	//console.log("After render params",scope);
            $timeout(function(){
			  	//console.log(attrs.afterRender,attrs.afterRenderParam);
				scope.$parent[attrs.afterRender](attrs.afterRenderParam);
			}, 0);
        }
    };
    return def;
}
  
}());