enmi12/glossaire/_posts/docs/2010-12-10-adding-items.mdown
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 0 d970ebf37754
permissions -rwxr-xr-x
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
---
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
title: Adding items
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
category: docs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
layout: default
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
toc:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
  - { title: addItems method, anchor: additems_method }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
  - { title: insert method, anchor: insert_method }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
  - { title: appended method, anchor: appended_method }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
  - { title: Prepending, anchor: prepending }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  - { title: Recommended CSS, anchor: recommended_css }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
---
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
If your application dynamically adds new content, Isotope provides several methods to add items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
[**See Demo: Adding items**](../demos/adding-items.html).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
## addItems method
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
The [`addItems` method](methods.html#additems) adds new content to an Isotope container. This applies the proper styles to the items so they can be positioned and any sorting data is retrieved. But that's it. The new content will _not_ be filtered, sorted, or positioned properly, nor will it be appended to the container element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
{% highlight javascript %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
$('#container').append( $newItems ).isotope( 'addItems', $newItems );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
{% endhighlight %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
## insert method
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
More likely, you want to use the [`insert` method](methods.html#insert), which does everything that `addItems` misses. `insert` will append the content to the container, filter the new content, sort all the content, then trigger a `reLayout` so all item elements are properly laid out.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
{% highlight javascript %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
$('#container').isotope( 'insert', $newItems );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
{% endhighlight %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
## appended method
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
The [`appended` method](methods.html#appended) is a convenience method triggers `addItems` on new content, then lays out _only the new content_ at the end of the layout. This method is useful if you know you only want to add new content to the end, and **not** use filtering or sorting.  `appended` is the best method to use with Infinite Scroll.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
[**See Demo: Infinite Scroll**](../demos/infinite-scroll.html).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
See also [Infinite Scroll with filtering or sorting](help.html#infinite_scroll_with_filtering_or_sorting)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
## Prepending
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
Because of Isotope's sorting functionality, prepending isn't as straight forward as might expect. However, it can be replicated fairly easy.  After prepending new content to the container, you can re-collect all the item elements and update their sorting order with the [`reloadItems` method](methods.html#reloaditems). Then trigger a re-layout, with the original DOM order.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
{% highlight javascript %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
$('#container').prepend( $newItems)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
  .isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
{% endhighlight %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
## Recommended CSS
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
You'll need these styles in your CSS for the reveal animation when adding items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
{% highlight css %}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
/**** disabling Isotope CSS3 transitions ****/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
.isotope.no-transition,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
.isotope.no-transition .isotope-item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
.isotope .isotope-item.no-transition {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
  -webkit-transition-duration: 0s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
     -moz-transition-duration: 0s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
      -ms-transition-duration: 0s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
       -o-transition-duration: 0s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
          transition-duration: 0s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
{% endhighlight %}