Giter VIP home page Giter VIP logo

ember-masonry-grid's Introduction

ember-masonry-grid

This ember-cli addon imports the Masonry library and allows you to quickly and easily build masonry grid views.

Build Status Ember Observer Score

Installation

ember install ember-masonry-grid

That's it! The Masonry library will automatically be imported in your app, and the masonry-grid component will be available to all of your templates.

Basic Usage

The masonry-grid component accepts all of the options that Masonry exposes. The naming is the same, and any option not specified will use the Masonry default.

For example, if we wanted to a basic masonry layout, we'd set up the following in our controller.

import Ember from 'ember';

export default Ember.Controller.extend({
  items: Ember.A([
    { name: 'Item 1' },
    { name: 'Item 2' },
    { name: 'Item 3' }
  ]);
});

And in our template:

{{#masonry-grid items=items as |item|}}
  {{item.name}}
{{/masonry-grid}}

If we wanted to redefine the itemSelector for Masonry, we'd write the following:

{{#masonry-grid items=items itemSelector=".piece" as |item|}}
  {{item.name}}
{{/masonry-grid}}

This would also change the classes for the underlying masonry-item components.

For a full list of options that are exposed, please see the Masonry options.

Custom Layouts

If you want more control over the each masonry-item, you can supply a custom layout to masonry-grid.

{{#masonry-grid items=items customLayout=true as |item index grid|}}
  {{#masonry-item item=item grid=grid }}
    {{item.name}}
  {{/masonry-item}}
{{/masonry-grid}}

Adding and Removing Items from a Masonry Layout

While Masonry exposes prepend, append, and remove methods, we don't have to worry about them. You can add and remove items from your items array and it will have the same effect.

Every time items is updated, Masonry will account for it and generate a new layout.

Available Actions

The following actions are made available by masonry-grid.

  • onLayoutComplete (layout)
    Triggered each time Masonry finishes a layout

  • onItemClick (event, item)
    Triggered when a click event occurs (or bubbles) on a masonry-item

Contributing

If you find an issue or missing functionality, please don't hesistate to open a pull request.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • npm test

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-masonry-grid's People

Contributors

codepreneur avatar ember-tomster avatar greenkeeperio-bot avatar homu avatar ifiokjr avatar josepjaume avatar tomdale avatar turbo87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-masonry-grid's Issues

Images loaded not working on initial load

I've tried and tried again, manually adding images-loaded.js in conjunction with this plugin, and the result is always the same. Masonry always activates before images are loaded on initial load, causing overlap.

Add meaningful tests

Currently, this addon ships with the base Ember addon tests (I was more excited to release something for Ember). These aren't very helpful. Let's make something better.

Helper issue

I've installed the addon per the directions: running ember install ember-masonry-grid.

My issue is that it's not working as expected, thus I'm getting a strange error which is the following: Uncaught Error: Assertion Failed: A helper named masonry-grid could not be found
(from the console)

This is the template I used to test it out:

http://notepad.cc/hijepu57

Update to [email protected]

There are some nice features that have come with ember-cli since 0.1.4. This addon should be brought up-to-date with ember-cli. Most of the effort (besides diffing configuration) will come with removing the use of prototype extensions (as of [email protected]). In our case, this is only Function.prototype.observes and Function.prototype.on.

Error: Package imagesLoaded not found

I tried to install the addon. I am facing this issue.

ember install:addon ember-masonry-grid
version: 0.2.0
A new version of ember-cli is available (0.2.1). To install it, type ember update.
Installing browser packages via Bower...
  cached git://github.com/desandro/masonry.git#3.2.2
Package imagesLoaded not found
Error: Package imagesLoaded not found

New release

Hi, could you push a new release? Could use the fastboot fix. Thank you :)

Can't Run Tests

I can't figure out how to run the tests for this repo. I've tried ember test and npm test but neither work. When running ember test --server I get
Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". at http://localhost:7357/assets/vendor.js, line 17726 ReferenceError: Can't find variable: QUnit at http://localhost:7357/assets/test-support.js, line 1756
I'm sure I must be missing something obvious.

Error when used with Ember 2.0 Application

The following error is seen when using this component in a Ember 2.0 application

Uncaught Error: Assertion Failed: Depending on arrays using a dependent key ending with @each is no longer supported. Please refactor from Ember.observer('items.@each', function() {}); to Ember.observer('items.[]', function() {}).

Looks like the following line in masonry-grid.js is causing the error.

layoutMasonry: Ember['default'].observer('items.@each', function () {....});

infinite scrolling

do you support infinite scrolling? I have seen that the list of items is observed, but are they added in a nice way or the whole library is reset?

Thanks

How can I trigger layout() from onClick?

I have a component that uses masonry. When a user clicks on a masonry item, I catch an onClick event, I set item.active to true which will then expand the item. Now that the item is larger I need masonry to layout, but I don't know how I'm supposed to get the masonry-grid reference to masonry. I end triggering it myself with:

export default Ember.Component.extend({
  actions: {
    onItemClick(event, item){
      item.set('active', true);
      Ember.run.next(this, ()=>{
        Ember.$(event.target).parent().masonry();
      });
    }
  }
});

In my hbs:

{{#masonry-grid items=model customLayout=true as |item index grid|}}
  {{#masonry-item item=item grid=grid onItemClick=(action 'onItemClick') class=(if item.active 'expanded')}}
    {{item.caption}}
  {{/masonry-item}}
{{/masonry-grid}}

But that causes the layout to snap in place, presumably because masonry gets re-initialized. How are people expected to handle resizing masonry-items with ember-masonry-grid?

Fix breaking changes in FastBoot 1.0

The current ember-cli-fastboot releases (1.0.0-rc.1 and above) introduce breaking changes. These will most likely break your current FastBoot implementation.

See ember-fastboot/ember-cli-fastboot#387 for more information and a guide on how to fix your addon. Also you may want to visit the -fastboot Slack channel to get help from other users.

Note: this issue has been created automatically, by searching for certain patterns in your code. If you think this has been falsely created, feel free to close!

Doesn't work on hard page refresh or landing on the page directly...

Hello, just tried using this and although it works if I navigate from one route into the page using the masonry (gallery page), if I land on that page directly or hard refresh it doesn't work...

http://i.imgur.com/QQU06Pb.png

http://i.imgur.com/oLumwg5.png

Any ideas?

          {{#masonry-grid items=content}}
          {{#each content as |gallery|}}
          <div class="col-md-3 gallery">
            {{#link-to 'galleries.gallery' gallery class="no-margin"}}
              <img src="{{gallery.cover.url}}"/>
              {{#if gallery.description}}
              <span>{{gallery.description}}</span>
              {{else}}
              <span>View Gallery</span>
              {{/if}}
            {{/link-to}}
            {{#link-to 'galleries.gallery' gallery}}
              <h3>{{gallery.name}}</h3>
            {{/link-to}}
          </div>
          {{/each}}
          {{/masonry-grid}}

Masonry layout becomes one column when navigating within the same template

We have a set of users and a bunch of cards for each user in Fixtures. Whenever you navigate from one user to another, the masonry becomes one column. Same thing happens whenever you make updates to the user model (even when modifying a property that's not related to the cards): the layout switches to a single column.

Problem with acceptance tests with PhantomJS

Hi,
First of all, thanks for great component ๐Ÿ‘ It saves a lot of time!
After installing ember-masonry-grid and adding component to template I've got randomly failing PhantomJS acceptance test. It shows:

        actual: >
            null
        message: >
            TypeError: 'undefined' is not an object (evaluating '_this.$().masonry')
        Log: |

It looks like sometimes (completety random) masonry is not being initializated for some reason or is initialized too late. Could you take a look at this please?

Best regards

option to ignore `imagesLoaded`

imagesLoaded can quickly add a couple of seconds to aligning your lists. In some cases it is not necessary.

I'd like to see an option specified to the helper (that defaults to true for backwards compatibility reasons) to skip waiting for images to load. E.g.:

{{#masonry-grid
    items=model
    customLayout=true
    imagesLoaded=false
    onLayoutComplete=(action 'onLayoutComplete')
    as |item index grid|}}

A helper named "masonry-grid" could not be found

After running ember install ember-masonry-grid, the actual helpers are not available and I'm getting this error message:

A helper named "masonry-grid" could not be found

This issue seems to be the same as #19 but that one was closed immediately after it was opened, so @gmurphey won't see it in the issue list.

Ember      : 2.7.0
Ember Data : 2.7.0
jQuery     : 2.2.4

@antulik suggested this might have something to do with ember-cli/ember-cli#2768

Error after installation: `Unknown option`

After installing ember-masonry-grid via ember install ember-masonry-grid, I receive the following error when I run ember serve:

The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-masonry-grid) ] failed with:
ReferenceError: [BABEL] ember-masonry-grid/components/masonry-grid/component.js: Unknown option: /Users/jacob/Desktop/photo-browser/package.json.presets

Full output:

'instrument' is imported from external module 'ember-data/-debug' but never used
The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-masonry-grid) ] failed with:
ReferenceError: [BABEL] ember-masonry-grid/components/masonry-grid/component.js: Unknown option: /Users/jacob/Desktop/photo-browser/package.json.presets
    at Logger.error (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
    at OptionManager.mergeOptions (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
    at OptionManager.addConfig (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10)
    at OptionManager.findConfigs (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/options/option-manager.js:171:32)
    at OptionManager.init (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12)
    at File.initOptions (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/index.js:147:75)
    at new File (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/file/index.js:137:22)
    at Pipeline.transform (/Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at /Users/jacob/Desktop/photo-browser/node_modules/ember-masonry-grid/node_modules/broccoli-babel-transpiler/lib/parallel-api.js:102:26
    at initializePromise (/Users/jacob/Desktop/photo-browser/node_modules/rsvp/dist/rsvp.js:567:5)

The broccoli plugin was instantiated at: 
    at BroccoliMergeTrees.Plugin (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/node_modules/broccoli-plugin/index.js:7:31)
    at new BroccoliMergeTrees (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:16:10)
    at Function.BroccoliMergeTrees [as _upstreamMergeTrees] (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:10:53)
    at mergeTrees (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/broccoli/merge-trees.js:85:33)
    at Class.compileAddon (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/models/addon.js:1084:12)
    at Class.treeForAddon (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/models/addon.js:738:26)
    at Class._treeFor (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/models/addon.js:551:33)
    at Class.treeFor (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/models/addon.js:511:21)
    at project.addons.map.addon (/Users/jacob/Desktop/photo-browser/node_modules/ember-cli/lib/broccoli/ember-app.js:557:22)
    at Array.map (native)

Fails to build after install

Hi,
Just tried installing this in the root of my ember-cli project, with npm install --save-dev ember-masonry-grid and getting the following when running ember server:

Path or pattern "bower_components/jquery-masonry/dist/masonry.pkgd.min.js" did not match any files

Is there something else I need to do?

Update:

Surprise, surprise; bower install jquery-masonry --save fixed that. Maybe that should be in the readme for idiots like me ? :p

Observe properties of individual items

Currently, we only observe the length of the items array. We should switch to using items.@each as our observer parameter to track all properties on each item. Thanks to @lucacorti for pointing this out in #2.

Custom CSS transition property on a masonry element stutters the animation

Setting a transition property on a masonry element makes the transition animation stutter on window resize. It appears as if both transitions compete with each other: the card animates into its new place, but then halfway through the transition restarts, making it a much less delightful experience...

I wonder if there's a way to detect if there's a transition set on the element and not add a secondary one?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.