Browse Source

Evolution #90: Ajaxsification des actions

bastien 12 years ago
parent
commit
bf34853042

+ 6 - 1
app/Resources/translations/elements.fr.yml View File

@@ -21,4 +21,9 @@ element:
21 21
   name:
22 22
     who:                (envoyé par <a href="%owner_url%">%owner_name%</a>)
23 23
     whoandgroup:        (envoyé par <a href="%owner_url%">%owner_name%</a> dans le groupe <a href="%group_url%">%group_name%</a>)
24
-  link:                 Ouvrir la page d'origine
24
+  link:                 Ouvrir la page d'origine
25
+  
26
+elements:
27
+  ajax:
28
+    more:
29
+      noelements:       Pas d'autres éléments

+ 79 - 1
src/Muzich/CoreBundle/Controller/SearchController.php View File

@@ -12,12 +12,40 @@ use Symfony\Component\HttpFoundation\Response;
12 12
 class SearchController extends Controller
13 13
 {
14 14
   
15
+  protected function searchElementsMore($elements, $invertcolors)
16
+  {
17
+    
18
+    $end = (($count = count($elements)) < $this->container->getParameter('search_ajax_more'));
19
+    $html = '';
20
+    $message = '';
21
+    if ($count)
22
+    {
23
+      $html = $this->render('MuzichCoreBundle:SearchElement:default.html.twig', array(
24
+        'user'        => $this->getUser(),
25
+        'elements'    => $elements,
26
+        'invertcolor' => $invertcolors
27
+      ))->getContent();
28
+    }
29
+    
30
+    if (!$count || $end)
31
+    {
32
+      $message = $this->trans('elements.ajax.more.noelements', array(), 'elements');
33
+    }
34
+    
35
+    return $this->jsonResponse(array(
36
+      'count'   => $count,
37
+      'message' => $message,
38
+      'html'    => $html,
39
+      'end'     => $end
40
+    ));
41
+  }
42
+  
15 43
   /**
16 44
    * Procédure de recherche, qui met a jour l'objet de recherche (ainsi
17 45
    * que les paramétres en session). 
18 46
    * 
19 47
    */
20
-  public function searchElementsAction()
48
+  public function searchElementsAction($id_limit = null, $invertcolors = false)
21 49
   {
22 50
     $request = $this->getRequest();
23 51
     $search_object = $this->getElementSearcher();
@@ -48,6 +76,14 @@ class SearchController extends Controller
48 76
     if ($this->getRequest()->isXmlHttpRequest())
49 77
     {
50 78
       // template qui apelle doSearchElementsAction 
79
+      $search = $this->getElementSearcher();
80
+      $search->update(array(
81
+        'count'    => $this->container->getParameter('search_ajax_more'),
82
+        'id_limit' => $id_limit
83
+      ));
84
+      $elements = $search->getElements($this->getDoctrine(), $this->getUserId());
85
+      
86
+      return $this->searchElementsMore($elements, $invertcolors);
51 87
     }
52 88
     else
53 89
     {
@@ -55,6 +91,48 @@ class SearchController extends Controller
55 91
     }
56 92
   }
57 93
   
94
+  public function searchElementsShowAction($type, $object_id, $id_limit, $invertcolors)
95
+  {
96
+    if ($this->getRequest()->isXmlHttpRequest())
97
+    {
98
+      $object = null;
99
+      $param_id =  '';
100
+      if ($type == 'user')
101
+      {
102
+        $object = $this->getDoctrine()
103
+          ->getRepository('MuzichCoreBundle:User')
104
+          ->findOneBy(array('id' => $object_id))
105
+        ;
106
+        $param_id = 'user_id';
107
+      }
108
+      elseif ($type == 'group')
109
+      {
110
+        $object = $this->getDoctrine()
111
+          ->getRepository('MuzichCoreBundle:Group')
112
+          ->findOneById($object_id)
113
+        ;
114
+        $param_id = 'group_id';
115
+      }
116
+
117
+      if (!$object)
118
+      { 
119
+        throw new \Exception('Object Unknow');
120
+      }
121
+
122
+      $search = $this->createSearchObject(array(
123
+        $param_id  => $object->getId(),
124
+        'count'    => $this->container->getParameter('search_ajax_more'),
125
+        'id_limit' => $id_limit
126
+      ));
127
+
128
+      $elements = $search->getElements($this->getDoctrine(), $this->getUserId());
129
+      
130
+      return $this->searchElementsMore($elements, $invertcolors);
131
+    }
132
+    
133
+    throw new \Exception('XmlHttpRequest only for this action');
134
+  }
135
+  
58 136
   /**
59 137
    *
60 138
    * @param string $string_search 

+ 26 - 21
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php View File

@@ -62,6 +62,11 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
62 62
     $this->entity_manager->persist($element);
63 63
   }
64 64
   
65
+  protected function dateD($ecal)
66
+  {
67
+    return date('Y-m-d H:i:s', time() - 60 * 60 *24 * $ecal);
68
+  }
69
+  
65 70
   public function load($entity_manager)
66 71
   {
67 72
     $this->entity_manager = $entity_manager;
@@ -84,61 +89,61 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
84 89
     $this->createElement('youtube_heretik_1', 'Heretik System Popof - Resistance', 
85 90
       'http://www.youtube.com/watch?v=tq4DjQK7nsM',
86 91
       $this->getArrayOfTag(array('hardtek')),
87
-    'youtube.com', $bux, null, '2011-12-10 17:35:07');
92
+    'youtube.com', $bux, null, $this->dateD(200));
88 93
     
89 94
     $this->createElement('youtube_dtc_passdrop', 'dtc che passdrop', 
90 95
       'http://www.youtube.com/watch?v=2A4buFCp7qM', 
91 96
       $this->getArrayOfTag(array('hardtek')),
92
-    'youtube.com', $bux, null, '2011-12-10 18:35:07');
97
+    'youtube.com', $bux, null, $this->dateD(199));
93 98
     
94 99
     $this->createElement('youtube_antroppod_1', 'Antropod - Polakatek', 
95 100
       'http://www.youtube.com/watch?v=VvpF3lCh1hk&NR=1', 
96 101
       $this->getArrayOfTag(array('hardtek')),
97
-    'youtube.com', $bux, null, '2011-12-10 19:45:07');
102
+    'youtube.com', $bux, null, $this->dateD(198));
98 103
     
99 104
     $this->createElement('youtube_koinkoin_1', 'koinkOin - H5N1', 
100 105
       'http://www.son2teuf.org/Voir-details/Sons/Lives/Hardtek-_-Tribe/koinkOin-_-H5N1', 
101 106
       $this->getArrayOfTag(array('hardtek', 'electro')),
102
-    'son2teuf.org', $bux, null, '2011-12-10 21:35:07');
107
+    'son2teuf.org', $bux, null, $this->dateD(197));
103 108
     
104 109
     
105 110
     $this->createElement('youtube_djfab_1', 'DJ FAB', 
106 111
       'http://www.jamendo.com/fr/album/42567', 
107 112
       $this->getArrayOfTag(array('hardtek')),
108
-    'jamendo.com', $jean, null, '2011-11-11 17:35:07');
113
+    'jamendo.com', $jean, null, $this->dateD(196));
109 114
     
110 115
     $this->createElement('youtube_djantoine_1', 'dj antoine', 
111 116
       'http://www.jamendo.com/fr/album/75206', 
112 117
       $this->getArrayOfTag(array('hardtek', 'tribe')),
113
-    'jamendo.com', $jean, null, '2011-11-11 19:35:07');
118
+    'jamendo.com', $jean, null, $this->dateD(195));
114 119
     
115 120
     $this->createElement('youtube_acroyek_1', 'Acrotek Hardtek G01', 
116 121
       'http://www.jamendo.com/fr/album/3409', 
117 122
       $this->getArrayOfTag(array('hardtek')),
118
-    'jamendo.com', $jean, null, '2011-12-11 14:35:07');
123
+    'jamendo.com', $jean, null, $this->dateD(194));
119 124
     
120 125
     
121 126
     $this->createElement('jamendo_caio_1', 'All Is Full Of Pain', 
122 127
       'http://soundcloud.com/keytek/all-is-full-of-pain', 
123 128
       $this->getArrayOfTag(array('tribe', 'hardtek')),
124
-    'soundcloud.com', $paul, null, '2011-12-02 01:35:07');
129
+    'soundcloud.com', $paul, null, $this->dateD(193));
125 130
     
126 131
     $this->createElement('jamendo_reverb_1', 'RE-FUCK (ReVeRB_FBC) mix.', 
127 132
       'http://soundcloud.com/reverb-2/re-fuck-reverb_fbc-mix', 
128 133
       $this->getArrayOfTag(array('tribe')),
129
-    'soundcloud.com', $paul, null, '2011-12-04 14:35:07');
134
+    'soundcloud.com', $paul, null, $this->dateD(192));
130 135
     
131 136
     $this->createElement('jamendo_cardio_1', 'CardioT3K - Juggernaut Trap', 
132 137
       'http://soundcloud.com/cardiot3k/cardiot3k-juggernaut-trap', 
133 138
       $this->getArrayOfTag(array('tribe')),
134
-    'soundcloud.com', $paul, null, '2011-12-12 13:35:07');
139
+    'soundcloud.com', $paul, null, $this->dateD(191));
135 140
     
136 141
     $this->createElement('dudeldrum', 'DUDELDRUM', 
137 142
       'http://www.jamendo.com/fr/album/89109', 
138 143
       $this->getArrayOfTag(array('medieval')),
139 144
       'jamendo.com', $joelle,
140 145
       $this->entity_manager->merge($this->getReference('group_dudeldrum'))
141
-      , '2011-12-16 18:11:07'
146
+      , $this->dateD(190)
142 147
     );
143 148
     
144 149
     $this->createElement('infected_psycho', 'Infected Mushroom - Psycho', 
@@ -146,7 +151,7 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
146 151
       $this->getArrayOfTag(array('psytrance')),
147 152
       'youtube.com', $paul,
148 153
       $this->entity_manager->merge($this->getReference('group_fan_de_psytrance'))
149
-      , '2011-12-10 16:11:17'
154
+      , $this->dateD(189)
150 155
     );
151 156
     
152 157
     $this->createElement('infected_muse', 'Infected mushroom - Muse Breaks', 
@@ -154,13 +159,13 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
154 159
       $this->getArrayOfTag(array('psytrance')),
155 160
       'youtube.com', $bob,
156 161
       $this->entity_manager->merge($this->getReference('group_fan_de_psytrance'))
157
-      , '2011-12-08 17:35:07'
162
+      , $this->dateD(188)
158 163
     );
159 164
     
160 165
     $this->createElement('joelle_1', 'Cents Pas - Joëlle', 
161 166
       'http://www.youtube.com/watch?v=bIAFB4vRdGw', 
162 167
       $this->getArrayOfTag(array('chanteuse')),
163
-      'youtube.com', $joelle, null, '2011-12-08 14:21:07'
168
+      'youtube.com', $joelle, null, $this->dateD(187)
164 169
     );
165 170
     
166 171
     $this->createElement('joelle_2', 'Cents Pas - Joëlle (bis)', 
@@ -168,43 +173,43 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
168 173
       $this->getArrayOfTag(array('chanteuse')),
169 174
       'youtube.com', $joelle,
170 175
       $this->entity_manager->merge($this->getReference('group_joelle'))
171
-      , '2011-12-07 14:12:07'
176
+      , $this->dateD(186)
172 177
     );
173 178
     
174 179
     $this->createElement('ukf_1', 'UKF Dubstep Mix - August ', 
175 180
       'http://www.youtube.com/watch?v=SFu2DfPDGeU', 
176 181
       $this->getArrayOfTag(array('dubstep')),
177
-      'youtube.com', $joelle, null, '2011-12-10 00:35:07'
182
+      'youtube.com', $joelle, null, $this->dateD(185)
178 183
     );
179 184
     
180 185
     $this->createElement('beatbox_1', 'Dubstep Beatbox', 
181 186
       'http://www.dailymotion.com/video/xm5omz_dubstep-beatbox_creation', 
182 187
       $this->getArrayOfTag(array('dubstep', 'beatbox')),
183
-      'dailymotion.com', $joelle, null, '2011-12-10 11:11:11'
188
+      'dailymotion.com', $joelle, null, $this->dateD(184)
184 189
     );
185 190
     
186 191
     $this->createElement('soulfly_1', 'SOULFLY - Prophecy', 
187 192
       'http://www.youtube.com/watch?v=zCc_jLctZkA', 
188 193
       $this->getArrayOfTag(array('metal')),
189
-      'youtube.com', $bux, null, '2011-12-12 17:39:07'
194
+      'youtube.com', $bux, null, $this->dateD(183)
190 195
     );
191 196
     
192 197
     $this->createElement('azyd_azylum_1', 'AZYD AZYLUM Live au Café Provisoire', 
193 198
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
194 199
       $this->getArrayOfTag(array('metal')),
195
-      'youtube.com', $bux, null, '2011-11-11 11:11:11'
200
+      'youtube.com', $bux, null, $this->dateD(182)
196 201
     );
197 202
     
198 203
     $this->createElement('babylon_pression_1', 'Babylon Pression - Des Tasers et des Pauvres', 
199 204
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
200 205
       $this->getArrayOfTag(array('metal', 'hardcore')),
201
-      'youtube.com', $bux, null, '2011-12-14 18:35:07'
206
+      'youtube.com', $bux, null, $this->dateD(181)
202 207
     );
203 208
     
204 209
     $this->createElement('ed_cox_1', 'Ed Cox - La fanfare des teuffeurs (Hardcordian)', 
205 210
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
206 211
       $this->getArrayOfTag(array('electro')),
207
-      'youtube.com', $bux, null, '2011-12-15 21:35:07'
212
+      'youtube.com', $bux, null, $this->dateD(180)
208 213
     );
209 214
     
210 215
 

+ 15 - 0
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -81,6 +81,7 @@ class ElementRepository extends EntityRepository
81 81
       . " LEFT JOIN g_.followers gf_"
82 82
       ;
83 83
       $where_network = ($is_where) ? ' AND' : ' WHERE';
84
+      $is_where = true;
84 85
       // Le filtre applique: Soit le proprio fait partis des followeds de l'utilisateur
85 86
       // soit l'element est ajouté dans un groupe que l'utilisateur follow.
86 87
       $where_network .= ' (f_.follower = :userid OR gf_.follower = :useridg)';
@@ -95,6 +96,7 @@ class ElementRepository extends EntityRepository
95 96
     if (($search_user_id = $searcher->getUserId()) && !$searcher->isFavorite())
96 97
     {
97 98
       $where_user = ($is_where) ? ' AND' : ' WHERE';
99
+      $is_where = true;
98 100
       $where_user .= ' e_.owner = :suid';
99 101
       $params_ids['suid'] = $search_user_id;
100 102
     }
@@ -106,6 +108,7 @@ class ElementRepository extends EntityRepository
106 108
     if (($search_group_id = $searcher->getGroupId()) && !$searcher->isFavorite())
107 109
     {
108 110
       $where_group = ($is_where) ? ' AND' : ' WHERE';
111
+      $is_where = true;
109 112
       $where_group .= ' e_.group = :sgid';
110 113
       $params_ids['sgid'] = $search_group_id;
111 114
     }
@@ -116,6 +119,7 @@ class ElementRepository extends EntityRepository
116 119
     if ($searcher->isFavorite())
117 120
     {
118 121
       $where_favorite = ($is_where) ? ' AND' : ' WHERE';
122
+      $is_where = true;
119 123
       if (($favorite_user_id = $searcher->getUserId()) && !$searcher->getGroupId())
120 124
       {
121 125
         // Pas de LEFT JOIN car on ne veut que les elements mis en favoris
@@ -134,6 +138,16 @@ class ElementRepository extends EntityRepository
134 138
       }
135 139
     }
136 140
     
141
+    // Si id_limit est précisé c'est que l'on demande "la suite"
142
+    $where_id_limit = '';
143
+    if (($id_limit = $searcher->getIdLimit()))
144
+    {
145
+      $where_favorite = ($is_where) ? ' AND' : ' WHERE';
146
+      $is_where = true;
147
+      $where_favorite .= " e_.id < :id_limit";
148
+      $params_ids['id_limit'] = $id_limit;
149
+    }
150
+    
137 151
     // Requête qui selectionnera les ids en fonction des critéres
138 152
     $r_ids = $this->getEntityManager()
139 153
       ->createQuery(
@@ -147,6 +161,7 @@ class ElementRepository extends EntityRepository
147 161
         $where_user
148 162
         $where_group
149 163
         $where_favorite
164
+        $where_id_limit
150 165
         GROUP BY e_.id
151 166
         ORDER BY e_.created DESC, e_.id DESC")
152 167
      ->setParameters($params_ids)

+ 26 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml View File

@@ -3,6 +3,32 @@
3 3
 search_elements:
4 4
   pattern:  /search-elements
5 5
   defaults: { _controller: MuzichCoreBundle:Search:searchElements }
6
+  
7
+search_elements_more:
8
+  pattern:  /search-elements/{id_limit}/{invertcolors}
9
+  defaults: { _controller: MuzichCoreBundle:Search:searchElements }
10
+   
11
+#search_elements_show_more_empty:
12
+#  pattern:  /search-elements/show/{type}/{object_id}
13
+#  defaults: 
14
+#    - _controller: MuzichCoreBundle:Search:searchElementsShow
15
+#    - type:        group|user
16
+#    - object_id:   int+
17
+#    
18
+#search_elements_show_more:
19
+#  pattern:  /search-elements/show/{type}/{object_id}/{id_limit}/{invertcolors}
20
+#  defaults: 
21
+#    - _controller: MuzichCoreBundle:Search:searchElementsShow
22
+#    - type:        group|user
23
+#    - object_id:   int+
24
+   
25
+search_elements_show_more_empty:
26
+  pattern:  /search-elements/show/{type}/{object_id}
27
+  defaults: { _controller: MuzichCoreBundle:Search:searchElementsShow }
28
+    
29
+search_elements_show_more:
30
+  pattern:  /search-elements/show/{type}/{object_id}/{id_limit}/{invertcolors}
31
+  defaults: { _controller: MuzichCoreBundle:Search:searchElementsShow }
6 32
    
7 33
 follow:
8 34
   pattern:  /follow/{type}/{id}/{token}

+ 21 - 3
src/Muzich/CoreBundle/Resources/views/SearchElement/default.html.twig View File

@@ -1,8 +1,26 @@
1 1
 
2 2
 {% if elements|length %}
3
-  <ul class="elements">
3
+  {% if not app.request.isXmlHttpRequest %}<ul class="elements">{% endif %}
4 4
     {% for element in elements %} 
5
-      <li class="element {% if loop.index0 is even %}even{% else %}odd{% endif %}" id="element_{{ element.id }}">
5
+      <li class="element 
6
+
7
+{% if loop.index0 is even %}
8
+  {% if invertcolor is not defined %}
9
+    even
10
+  {% elseif invertcolor %}
11
+    odd
12
+  {% else %}
13
+    even
14
+  {% endif %}
15
+{% else %}
16
+  {% if invertcolor is not defined %}
17
+    odd
18
+  {% elseif invertcolor %}
19
+    even
20
+  {% else %}
21
+    odd
22
+  {% endif %}
23
+{% endif %}" id="element_{{ element.id }}">
6 24
              
7 25
         {% if element.getCountFavorite %}
8 26
           <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': user.personalHash }) }}" >
@@ -78,7 +96,7 @@
78 96
 
79 97
       </li>
80 98
     {% endfor %} 
81
-  </ul>
99
+  {% if not app.request.isXmlHttpRequest %}</ul>{% endif %}
82 100
 
83 101
 {% else %}
84 102
 

+ 5 - 0
src/Muzich/CoreBundle/Searcher/ElementSearcher.php View File

@@ -141,6 +141,11 @@ class ElementSearcher extends Searcher implements SearcherInterface
141 141
     return $this->user_id;
142 142
   }
143 143
   
144
+  public function getIdLimit()
145
+  {
146
+    return $this->id_limit;
147
+  }
148
+  
144 149
   public function getGroupId()
145 150
   {
146 151
     return $this->group_id;

+ 2 - 0
src/Muzich/HomeBundle/Resources/config/routing.yml View File

@@ -23,3 +23,5 @@ show_group:
23 23
 show_group_more:
24 24
   pattern: /group/{slug}/more/{count}
25 25
   defaults: { _controller: MuzichHomeBundle:Show:showGroup, count: null }
26
+
27
+  

+ 2 - 1
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

@@ -42,10 +42,11 @@
42 42
   {% if more_count is defined %} 
43 43
   {% if elements|length %}
44 44
      <span class="elements_more">
45
-       <a href="{{ path('home_more', {'count': more_count}) }}" >
45
+       <a href="{{ path('search_elements') }}" class="elements_more">
46 46
          {{ 'more'|trans({}, 'userui') }}
47 47
        </a>
48 48
      </span>
49
+     <img class="elements_more_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
49 50
   {% endif %}
50 51
   {% endif %}
51 52
   

+ 5 - 1
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig View File

@@ -54,10 +54,14 @@
54 54
   {% if more_count is defined %} 
55 55
   {% if elements|length %}
56 56
    <span class="elements_more">
57
-     <a href="{{ path('show_group_more', {'count': more_count, 'slug': group.slug}) }}" >
57
+     <a href="{{ path('search_elements_show_more_empty', {
58
+       'type'     : 'group', 
59
+       'object_id': group.id
60
+     }) }}" class="elements_more" >
58 61
        {{ 'more'|trans({}, 'userui') }}
59 62
      </a>
60 63
    </span>
64
+   <img class="elements_more_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
61 65
   {% endif %}
62 66
   {% endif %}
63 67
   

+ 5 - 1
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig View File

@@ -28,10 +28,14 @@
28 28
   {% if more_count is defined %} 
29 29
   {% if elements|length %}
30 30
    <span class="elements_more">
31
-     <a href="{{ path('show_user_more', {'count': more_count, 'slug': viewed_user.slug}) }}" >
31
+     <a href="{{ path('search_elements_show_more_empty', {
32
+       'type'     : 'user', 
33
+       'object_id': viewed_user.id
34
+     }) }}" class="elements_more" >
32 35
        {{ 'more'|trans({}, 'userui') }}
33 36
      </a>
34 37
    </span>
38
+   <img class="elements_more_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
35 39
   {% endif %}
36 40
   {% endif %}
37 41
   

+ 118 - 30
web/bundles/muzichcore/js/muzich.js View File

@@ -113,41 +113,129 @@ if(typeof(String.prototype.trim) === "undefined")
113 113
     };
114 114
 }
115 115
 
116
+function str_replace (search, replace, subject, count) {
117
+    // Replaces all occurrences of search in haystack with replace  
118
+    // 
119
+    // version: 1109.2015
120
+    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
121
+    // +   improved by: Gabriel Paderni
122
+    // +   improved by: Philip Peterson
123
+    // +   improved by: Simon Willison (http://simonwillison.net)
124
+    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
125
+    // +      input by: Onno Marsman
126
+    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
127
+    // +    tweaked by: Onno Marsman
128
+    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
129
+    // +   input by: Oleg Eremeev
130
+    // +   improved by: Brett Zamir (http://brett-zamir.me)
131
+    // +   bugfixed by: Oleg Eremeev
132
+    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
133
+    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
134
+    // *     returns 1: 'Kevin.van.Zonneveld'
135
+    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
136
+    // *     returns 2: 'hemmo, mars'    var i = 0,
137
+        j = 0,
138
+        temp = '',
139
+        repl = '',
140
+        sl = 0,        fl = 0,
141
+        f = [].concat(search),
142
+        r = [].concat(replace),
143
+        s = subject,
144
+        ra = Object.prototype.toString.call(r) === '[object Array]',        sa = Object.prototype.toString.call(s) === '[object Array]';
145
+    s = [].concat(s);
146
+    if (count) {
147
+        this.window[count] = 0;
148
+    } 
149
+    for (i = 0, sl = s.length; i < sl; i++) {
150
+        if (s[i] === '') {
151
+            continue;
152
+        }for (j = 0, fl = f.length; j < fl; j++) {
153
+            temp = s[i] + '';
154
+            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
155
+            s[i] = (temp).split(f[j]).join(repl);
156
+            if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
157
+            }
158
+        }
159
+    }
160
+    return sa ? s : s[0];
161
+}
162
+
116 163
 $(document).ready(function(){
117 164
   
118
-   // Affichage un/des embed
119
-   $('a.element_embed_open_link').click(function(){
120
-     $(this).parent().parent('li.element').find('a.element_embed_open_link').hide();
121
-     $(this).parent().parent('li.element').find('a.element_embed_close_link').show();
122
-     $(this).parent().parent('li.element').find('div.element_embed').show();
123
-     return false;
124
-   });
125
-
126
-   // Fermeture du embed si demandé
127
-   $('a.element_embed_close_link').click(function(){
128
-     $(this).parent().parent('li.element').find('a.element_embed_open_link').show();
129
-     $(this).parent().parent('li.element').find('a.element_embed_close_link').hide();
130
-     $(this).parent().parent('li.element').find('div.element_embed').hide();
131
-     return false;
132
-   });
165
+  // Bouton de personalisation du filtre
166
+  // pour le moment ce ne sotn que des redirection vers des actions
167
+  $('.tags_prompt input.clear, .filter_clear_url').click(function(){
168
+    $(location).attr('href', $('input.filter_clear_url').val());
169
+  });
170
+  $('.tags_prompt input.mytags').click(function(){
171
+    $(location).attr('href', $('input.filter_mytags_url').val());
172
+  });
173
+  
174
+  // On met les listeners lié aux éléments de façon a pouvoir écouter
175
+  // les événenements des éléments chargés en ajax en appelelant
176
+  // cette fonction après un ptit coup d'ajax
177
+  function init_elements()
178
+  {
179
+  
180
+    // Affichage un/des embed
181
+    $('a.element_embed_open_link').click(function(){
182
+       $(this).parent().parent('li.element').find('a.element_embed_open_link').hide();
183
+       $(this).parent().parent('li.element').find('a.element_embed_close_link').show();
184
+       $(this).parent().parent('li.element').find('div.element_embed').show();
185
+       return false;
186
+    });
187
+
188
+    // Fermeture du embed si demandé
189
+    $('a.element_embed_close_link').click(function(){
190
+       $(this).parent().parent('li.element').find('a.element_embed_open_link').show();
191
+       $(this).parent().parent('li.element').find('a.element_embed_close_link').hide();
192
+       $(this).parent().parent('li.element').find('div.element_embed').hide();
193
+       return false;
194
+    });
195
+
196
+    // Mise en favoris
197
+    $('a.favorite_link').click(function(){
198
+       link = $(this);
199
+       $.getJSON($(this).attr('href'), function(response) {
200
+         img = link.find('img');
201
+         link.attr('href', response.link_new_url);
202
+         img.attr('src', response.img_new_src);
203
+         img.attr('title', response.img_new_title);
204
+       });
205
+       return false;
206
+    });
133 207
    
134
-   // Bouton de personalisation du filtre
135
-   // pour le moment ce ne sotn que des redirection vers des actions
136
-   $('.tags_prompt input.clear, .filter_clear_url').click(function(){
137
-     $(location).attr('href', $('input.filter_clear_url').val());
138
-   });
139
-   $('.tags_prompt input.mytags').click(function(){
140
-     $(location).attr('href', $('input.filter_mytags_url').val());
141
-   });
208
+  }
209
+  
210
+  init_elements();
142 211
    
143
-   // Mise en favoris
144
-   $('a.favorite_link').click(function(){
212
+   // Plus d'éléments
213
+   last_id = null;
214
+   $('a.elements_more').click(function(){
145 215
      link = $(this);
146
-     $.getJSON($(this).attr('href'), function(response) {
147
-       img = link.find('img');
148
-       link.attr('href', response.link_new_url);
149
-       img.attr('src', response.img_new_src);
150
-       img.attr('title', response.img_new_title);
216
+     last_element = $('ul.elements li.element:last-child');
217
+     id_last = str_replace('element_', '', last_element.attr('id'));
218
+     invertcolor = 0;
219
+     if (last_element.hasClass('even'))
220
+     {
221
+       invertcolor = 1;
222
+     }
223
+     $('img.elements_more_loader').show();
224
+     $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
225
+       if (response.count)
226
+       {
227
+         $('ul.elements').append(response.html);
228
+         $('img.elements_more_loader').hide();
229
+         init_elements();
230
+       }
231
+       
232
+       if (response.end || response.count < 1)
233
+       {
234
+         $('img.elements_more_loader').hide();
235
+         $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
236
+           response.message+'</p></div>');
237
+         link.hide();
238
+       }
151 239
      });
152 240
      return false;
153 241
    });