|
1 | 1 | angulargrid
|
2 | 2 | ===========
|
3 | 3 |
|
4 |
| -Wookmark and pin-interest like dynamic grid system for angular |
| 4 | +Pin-interest and wookmark like responsive dynamic grid system for angular |
5 | 5 |
|
6 |
| -**** Under Development **** |
| 6 | +Demo url : http://ignitersworld.com/lab/angulargrid/demo1.html |
7 | 7 |
|
8 |
| -*Example HTML Format* |
| 8 | +#Usage |
| 9 | +1. Include angulargrid.js |
9 | 10 | ```html
|
10 |
| - <ul class="dynamic-grid" angular-grid="pics" grid-width="250" gutter-size="20"> |
| 11 | + <script src="angulargrid.js"></script> |
| 12 | +``` |
| 13 | + |
| 14 | +2. Inject the module on your app |
| 15 | +```js |
| 16 | + var App = angular.module('demoApp', ['angularGrid']); |
| 17 | +``` |
| 18 | + |
| 19 | +3. Use directive as attribute defining the model you want to listen |
| 20 | +```html |
| 21 | + <ul angular-grid="pics"> |
| 22 | + ..... |
| 23 | + ..... |
| 24 | + </ul> |
| 25 | +``` |
| 26 | +#Example |
| 27 | + |
| 28 | +*HTML* |
| 29 | +```html |
| 30 | + <ul class="dynamic-grid" angular-grid="pics" grid-width="300" gutter-size="10" angular-grid-id="gallery" refresh-on-img-load="false" > |
11 | 31 | <li data-ng-repeat="pic in pics" class="grid">
|
12 |
| - <img src="{{pic.media.m}}" class="grid-img"/> |
| 32 | + <img src="{{pic.media.m}}" class="grid-img" data-actual-width = "{{pic.actualWidth}}" data-actual-height="{{pic.actualHeight}}" /> |
13 | 33 | </li>
|
14 | 34 | </ul>
|
15 | 35 | ```
|
16 | 36 |
|
17 | 37 | In above html angular-grid="pics" defines the model you want to listen, so here its listening for pics
|
18 |
| -grid-width and gutter-size are otional configuration for angular grid. |
| 38 | +grid-width, gutter-size and refresh-on-img-load are otional configuration for angular grid. |
19 | 39 |
|
20 | 40 | *CSS*
|
21 |
| -```css |
22 |
| - .grid { |
23 |
| - border: 1px solid #cccccc; |
24 |
| - position: absolute; |
25 |
| - list-style: none; |
26 |
| - -webkit-box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.3); |
27 |
| - -moz-box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.3); |
28 |
| - box-shadow: 1px 1px 2px 0px rgba(50, 50, 50, 0.3); |
29 |
| - background: #ffffff; |
30 |
| - } |
31 |
| - .grid-img { |
32 |
| - width: 100%; |
33 |
| - vertical-align: middle; |
34 |
| - } |
35 |
| - .grid-img.img-loading { |
36 |
| - display: none; |
37 |
| - } |
| 41 | +```css |
| 42 | + .dynamic-grid{ |
| 43 | + position: relative; |
| 44 | + display: none; |
| 45 | + } |
| 46 | + |
| 47 | + .dynamic-grid.angular-grid{ |
| 48 | + display: block; |
| 49 | + } |
| 50 | + |
| 51 | + .grid { |
| 52 | + border: 1px solid #cccccc; |
| 53 | + position: absolute; |
| 54 | + list-style: none; |
| 55 | + background: #ffffff; |
| 56 | + box-sizing: border-box; |
| 57 | + -moz-box-sizing : border-box; |
| 58 | + -webkit-transition: all 0.6s ease-out; |
| 59 | + transition: all 0.6s ease-out; |
| 60 | + } |
| 61 | + .grid-img { |
| 62 | + width: 100%; |
| 63 | + vertical-align: middle; |
| 64 | + -webkit-transition: opacity 0.6s ease-out; |
| 65 | + transition: opacity 0.6s ease-out; |
| 66 | + background-color: #fff; |
| 67 | + opacity: 0; |
| 68 | + visibility: hidden; |
| 69 | + } |
| 70 | + |
| 71 | + .grid-img.img-loaded{ |
| 72 | + visibility: visible; |
| 73 | + opacity: 1; |
| 74 | + } |
| 75 | + |
| 76 | +``` |
| 77 | + |
| 78 | +*JS* |
| 79 | +```js |
| 80 | +angular.module('demoApp', ['angularGrid']) |
| 81 | + .service('imageService',['$q','$http',function($q,$http){ |
| 82 | + this.loadImages = function(){ |
| 83 | + return $http.jsonp("https://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=JSON_CALLBACK"); |
| 84 | + }; |
| 85 | + }]) |
| 86 | + .controller('demo', ['$scope','imageService','angularGridInstance', function ($scope,imageService,angularGridInstance) { |
| 87 | + imageService.loadImages().then(function(data){ |
| 88 | + data.data.items.forEach(function(obj){ |
| 89 | + var desc = obj.description, |
| 90 | + width = desc.match(/width="(.*?)"/)[1], |
| 91 | + height = desc.match(/height="(.*?)"/)[1]; |
| 92 | + |
| 93 | + obj.actualHeight = height; |
| 94 | + obj.actualWidth = width; |
| 95 | + }); |
| 96 | + $scope.pics = data.data.items; |
| 97 | + |
| 98 | + $scope.refresh = function(){ |
| 99 | + angularGridInstance.gallery.refresh(); |
| 100 | + } |
| 101 | + });; |
| 102 | + }]); |
38 | 103 | ```
|
39 | 104 |
|
40 | 105 | #Options
|
41 | 106 | gridWidth : (Default to 250) minimum width in pixel a coloumn can have, coloumn width will increase above grid width depending on container size to make grids responsive.
|
42 | 107 |
|
43 | 108 | gutterSize : (Default to 10) Spacing between two column
|
| 109 | + |
| 110 | +refreshOnImgLoad : (Default to true) refresh the layout on image load so images does not overlap each other |
| 111 | + |
| 112 | +#Handeling Images |
| 113 | +If your list contains any image inside, as it will load asynchronously, plugin refresh the layout and add following classes to list item and images, so you can handle transitions of image better, |
| 114 | + |
| 115 | +images : |
| 116 | +image-loading : when an image is loading inside list item |
| 117 | +image-loaded : when an image is loaded inside list item |
| 118 | + |
| 119 | +list item |
| 120 | +image-loading : when any of image is loading inside list item |
| 121 | +image-loaded : when all images are loaded inside list item |
| 122 | + |
| 123 | +Optionally if you know dimension of images you can add data-actual-width and data-actual-height attributes, so that it will not refresh the layout when those images are loaded. |
| 124 | + |
| 125 | +#refreshing manually |
| 126 | +To get the refrence of instance you need to define angular-grid-id on the element which you can get back by injecting angularGridInstance to any controller or directive. |
| 127 | +Using your id you can refresh your layout ex : angularGridInstance.gallery.refresh(); |
0 commit comments