DrewDahlman / Mason

Mason.js for creating a perfect grid with jQuery.
http://masonjs.com/
MIT License
1.22k stars 183 forks source link

Extening the plugin to remove randomness and adding data layout attributes to HTML #25

Closed tomeralmog closed 9 years ago

tomeralmog commented 10 years ago

HI, Thank you for the plugin. I needed the layout to be predetermined (i.e. I need to know which image to put on a [2,1] layout and on [1,2]. I have extended a bit the plugin to enable that (you might want to include that on your next release): on line 112 I have changed ran = Math.floor(Math.random() * (settings.sizes.length - settings.promoted.length)); to ran = $sel.data("layout"); if(typeof(ran)=='undefined' || !ran){ ran = Math.floor(Math.random() * (settings.sizes.length - settings.promoted.length)); }

Now in the HTML you can add data-layout attribute which corresponds to the index of the sizes in the options: div class='box' data-layout="3">4

div class='box' data-layout="0">5
div class='box' data-layout="1">6 div class='box' data-layout="2">7

I have also changed the randomness of the fillers like this:

line 191 (before the 2 for loops) add var fillerNum = $(settings.filler.itemSelector).length;

and then in line 212 change

ran = Math.floor(Math.random() * $(settings.filler.itemSelector).length);

to

ran = fillerNum -1;

you can probably add another Boolean variable in the option field for random true/false and set it there.

Hope this helps, Thanks for the great plugin! Tomer Almog www.tomeralmog.com

DrewDahlman commented 10 years ago

Hey tom mind doing a fork and pull request?

tomeralmog commented 10 years ago

No Problem brother