Advertisement
Guest User

angularjs grid component

a guest
Jul 4th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module("components", []).directive("grid", function () {
  2.     return {
  3.         replace: true,
  4.         restrict: "AE",
  5.         transclude: true,
  6.         scope: {},
  7.         templateUrl: "../scripts/angularjs/components/templates/grid.html",
  8.         link: function (scope, element, attrs) {
  9.             if(attrs.cols) {
  10.                 var num = element[0].children.length;
  11.                 var i = parseInt(attrs.cols);
  12.                 //if(console) console.log("grid: ", num, i);
  13.                 var added = 0;
  14.                 while(i < num) {
  15.                     var br = document.createElement("br");
  16.                     element[0].insertBefore(br, element[0].children[i+added]);
  17.                     added++;
  18.                     i += parseInt(attrs.cols);
  19.                 }
  20.             }
  21.         }
  22.     };
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement