caph-list

caph.ui. caph-list

An element directive which provides a high performance scrollable list component. This directive creates container and wrapper element to arrange the item view, and calculates the item view count per a page to fit container size, and then creates current, previous and next page. The item views in each page are updated by the given template view and item data, and then they are arranged to the corresponding position on each page. This directive updates the item views in each page when moving to the previous or next page by scrolling the wrapper element to previous or next position.

You can create it easily by only setting options and template view. Note that the template view should be a focusable.

At first, prepare data to the corresponding scope. Usually use AJAX to request the data. So $http service will help you. (Refer to the details in https://code.angularjs.org/1.3.15/docs/api/ng/service/$http.)

 $http.get('/someUrl').success(function(response) {
     $scope.items = response.items;
 });

And then, create a 'caph-list' using the received data on the scope.

 <caph-list items="item in items">
     <div class="item" focusable>{{$index}}</div> <!-- you can also use each object of array throughout 'item' variable. e.g. {{item.title}} -->
 </caph-list>

The 'items' option consists of repeat expression. The expression indicating how to enumerate a collection. This format is currently supported:

format description
variable in expression where variable is the user defined loop variable and expression is a scope expression giving the collection to enumerate.

This directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index is set to the item index. Special properties are exposed on the local scope of each template instance, including:

type variable description
number $index iterator offset of the repeated element (0..length-1).
boolean $first true if the repeated element is first in the iterator.
boolean $last true if the repeated element is last in the iterator.
boolean $even true if the iterator position $index is even (otherwise false).
boolean $odd true if the iterator position $index is odd (otherwise false).

The above example creates a list with the following structure.

 <div class="caph-list-container"> <!-- container -->
     <div class="caph-list-wrapper> <!-- wrapper -->
         <div class="item" focusable>0</div> <!-- template view -->
         <div class="item" focusable>1</div> <!-- template view -->
         <div class="item" focusable>2</div> <!-- template view -->
         ...
     </div>
 </div>

By default, the scroll direction is 'horizontal'. If you want to change the scroll direction to vertical, set the 'direction' option to 'vertical'.

 <caph-list direction="vertical" ... >
     ...
 </caph-list>

You can also change the class name of container and wrapper.

 <caph-list container-class="container" wrapper-class="wrapper" ... >
     ...
 </caph-list>

Then, you can see a list with the following structure.

 <div class="container"> <!-- container -->
     <div class="wrapper> <!-- wrapper -->
         ...
     </div>
 </div>

Note that container and template view should have their own size such as width and height. Because this directive arranges the views based on that sizes. Suppose that style is defined like below.

 .container {
     width: 1000px;
     height: 600px;
 }

 .item {
     width: 100px;
     height: 200px;
 }

If you create a 'caph-list' like below, its row count will be 3 and column count will be 10.

 <caph-list container-class="container" ... >
     <div class="item" ... > ... </div>
 </caph-list>

So if your data count is greater than 30, you can scroll the list horizontally after reaching the last column.

You can change the scroll effect by setting 'duration' and 'ease' option. These option values are same as CSS3 transition value. Refer to the 'transition-duration' and 'transition-timing-function' in http://www.w3schools.com/css/css3_transitions.asp.

The followings are all available options.

type option description
Object[] items The data to be decorated to the views. Note that it can't be used together with item-loader option.
string item-loader The item loader to request required data to be decorated to the views. You can specify the item loader name which is registered to the caph.ui.listItemLoaderProvider. Each template instance gets its own scope, where the 'item' variable is set to the current collection item. Special properties are exposed on the local scope of each template instance like using items option. Note that it can't be used together with items option.
string direction The scroll direction such as 'horizontal' and 'vertical'. Default value is 'horizontal'.
string container-class The container element's class name. Default value is 'caph-list-container'. You have to set the size such as 'width' and 'height'.
string wrapper-class The wrapper element's class name. Default value is 'caph-list-wrapper'.
string duration The scroll duration. Default value is '0.5s'. Refer to the details in http://www.w3schools.com/cssref/css3_pr_transition-duration.asp.
string ease The scroll timing function. Default value is 'ease-out'. Refer to the details in http://www.w3schools.com/cssref/css3_pr_transition-timing-function.asp.
boolean loop The continuous circular loop mode. Default value is false. If this option is set to true, move to the first item view when moving to the next item view on the last item view. The opposite situation is same. This option can't be used with item-loader option.
number delay The millisecond which indicates the scroll delay time. Default value is 100.
number initial-item-index The initial item index. Default value is 0. This value should be less than the item count.
number mouse-scroll-area-size The mouse scroll area pixel size. Default value is 20. If the mouse pointer is located from the edge of the list container up to as much as mouse scroll area pixel size, the list is scrolled to the corresponding direction.
number page-buffer-size The page buffer size. One page consists of the number of visible item views. It prepares the previous and next page just as much as the given page buffer size to scroll wrapper smoothly. Default value is 1.
Function on-decorate-item-view The callback handler which is called after decorating an item view using template. This callback handler receives one '$itemView' parameter which contains each item view's element and scope.
Function on-focus-item-view The callback handler which is called when an item view is focused. This callback handler receives one '$context' parameter which contains current list indices such as item index, row index, column index, page index, maximum page index, item count and item view count per page.
Function on-reach-start The callback handler which is called when reaching the item view at the very left or top. This callback handler receives one '$context' parameter which contains current list indices such as item index, row index, column index, page index, maximum page index, item count and item view count per page.
Function on-reach-end The callback handler which is called when reaching the item view at the very right or bottom. This callback handler receives one '$context' parameter which contains current list indices such as item index, row index, column index, page index, maximum page index, item count and item view count per page.
Function on-scroll-start The callback handler which is called when the scroll is started. This callback handler receives one '$context' parameter which contains current list indices such as item index, row index, column index, page index, maximum page index, item count and item view count per page.
Function on-scroll-finish The callback handler which is called when the scroll is finished. This callback handler receives one '$context' parameter which contains current list indices such as item index, row index, column index, page index, maximum page index, item count and item view count per page.

If you create 'caph-list' successfully, you can control it directly by sending event.

 jQuery('caph-list').eq(0).trigger('resize');

The followings are all available events.

event description
reload Update the entire item views. By default, when appending new data to collection or removing the existing data from the tail of collection, the visible item views will be updated only if necessary. So if you change the all or some(excluding default case) data of collection, you should trigger this event to update item views.
resize If you change the list size manually, you should send this event. The window's resize event is processed automatically.
moveleft Move to the left item.
moveright Move to the right item.
moveup Move to the up item.
movedown Move to the down item.