klederson / angular-masonry-directive

A very simple and 100% compatible masonry directive for AngularJS ... do you know how to use masonry? Good! You know how to use this
115 stars 68 forks source link

INT value options break the module #22

Open kbaggott opened 9 years ago

kbaggott commented 9 years ago

In trying to add gutter into the options for the masonry today, I noticed that when setting "gutter" the whole module broke. This appears to be because of the way Masonry looks at strings rather than Ints, in your code you get the options via .fromJson which always returns a string. I have put in a quick fix to my code, may be a better way but it works for me. If this is helpful to you then please run with it, great module btw.


//line 7...
      var container = elem[0];
      var options = angular.extend({
           itemSelector: '.item'
      }, angular.fromJson(attrs.masonry));

      // NEW - check for int value options
      angular.forEach(options, function(x, y){
            if (!isNaN(x)) options[y] = parseInt(x);
      });

     var masonry = scope.masonry = new Masonry(container, options);
//line 19...