Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/macy.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/macy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import setup from './modules/setup.js'
import calculate from './modules/calculate';
import { imagesLoadedNew } from './helpers/imagesLoaded';
import scopeShim from './helpers/scopeshim';
import foreach from './helpers/foreach';
import { isSupported } from './helpers/is-supported';

if (!Array.from) {
Array.from=n=>{let i=0,a=[];for (;i<n.length;)a.push(n[i++]);return a;}
}


if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}

const defaults = {
columns: 4,
margin: 2,
Expand Down Expand Up @@ -99,7 +102,7 @@ Macy.prototype.recalculate = function (refresh = false, loaded = true) {
Macy.prototype.remove = function () {
window.removeEventListener('resize', this.resizer);

foreach(this.container.children, (child) => {
this.container.children.forEach(child => {
child.removeAttribute('data-macy-complete');
child.removeAttribute('style');
});
Expand Down
3 changes: 1 addition & 2 deletions src/modules/calculate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import $e from './$e';
import {getWidths} from './calculations';
import * as cols from './columns';
import foreach from '../helpers/foreach';

/**
* Calculates the column widths and positions dependant on options.
Expand All @@ -17,7 +16,7 @@ const calculate = (ctx, refresh = false, loaded = true) => {

let eleWidth = getWidths(ctx.options);

foreach(children, (child) => {
children.forEach(child => {
if (refresh) {
child.dataset.macyComplete = 0;
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/calculations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import foreach from '../helpers/foreach';
import { getResponsiveOptions } from '../helpers/getResponsiveOptions';

/**
Expand Down Expand Up @@ -103,7 +102,7 @@ export function setContainerHeight (ctx) {
let largest = 0;
let {container, rows} = ctx;

foreach(rows, (row) => {
rows.forEach(row => {
largest = row > largest ? row : largest;
});

Expand Down
5 changes: 2 additions & 3 deletions src/modules/columns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {getLeftPosition, getCurrentColumns, getCurrentMargin, setContainerHeight} from './calculations';
import prop from '../helpers/prop';
import foreach from '../helpers/foreach';

/**
* Sets up the required data for the shuffle and sort method
Expand Down Expand Up @@ -58,7 +57,7 @@ export function shuffle (ctx, $eles, refresh = false, markasComplete = true) {
let margin = getCurrentMargin(ctx.options).y;
setUpRows(ctx, cols, refresh);

foreach($eles, (ele) => {
$eles.forEach(ele => {
let smallest = 0;
let eleHeight = parseInt(ele.offsetHeight, 10);

Expand Down Expand Up @@ -99,7 +98,7 @@ export function sort (ctx, $eles, refresh = false, markasComplete = true) {
let margin = getCurrentMargin(ctx.options).y;
setUpRows(ctx, cols, refresh);

foreach($eles, (ele) => {
$eles.forEach(ele => {

if (ctx.lastcol === cols) {
ctx.lastcol = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/modules/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import foreach from '../helpers/foreach';

/**
* Event object that will be passed to callbacks
* @param instance {Macy} - Macy instance
Expand Down Expand Up @@ -52,7 +50,7 @@ EventManager.prototype.emit = function (key = false, data = {}) {
}

const evt = new Event(this.instance, data);
foreach(this.events[key], (fn) => fn(evt));
this.events[key].forEach(fn => fn(evt));
};

export default EventManager;
4 changes: 1 addition & 3 deletions src/modules/queue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import foreach from '../helpers/foreach';

/**
* The queue function allows to for recalculate to run one at a time to avoid conflicts.
* @param events {Mixed} a single function or an array of functions
Expand Down Expand Up @@ -35,7 +33,7 @@ Queue.prototype.add = function (event = false) {
}

if (Array.isArray(event)) {
return foreach(event, (evt) => this.add(evt));
return event.forEach(evt => this.add(evt));
}

this.events.push(event);
Expand Down