Browse Source

js: Mise en gras lors de la recherche de tag: gére les espaces

bastien 13 years ago
parent
commit
4403e7e135
2 changed files with 49 additions and 3 deletions
  1. 2 0
      web/bundles/muzichcore/css/main.css
  2. 47 3
      web/bundles/muzichcore/js/muzich.js

+ 2 - 0
web/bundles/muzichcore/css/main.css View File

636
   -webkit-box-shadow: #666 0px 2px 3px;
636
   -webkit-box-shadow: #666 0px 2px 3px;
637
   -moz-box-shadow: #666 0px 2px 3px;
637
   -moz-box-shadow: #666 0px 2px 3px;
638
   box-shadow: #666 0px 2px 3px;
638
   box-shadow: #666 0px 2px 3px;
639
+  
640
+  z-index: 1;
639
 }
641
 }
640
 
642
 
641
 div.search_tag_list span.info
643
 div.search_tag_list span.info

+ 47 - 3
web/bundles/muzichcore/js/muzich.js View File

190
     return sa ? s : s[0];
190
     return sa ? s : s[0];
191
 }
191
 }
192
 
192
 
193
+function explode (delimiter, string, limit) {
194
+    // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
195
+    // 
196
+    // version: 1109.2015
197
+    // discuss at: http://phpjs.org/functions/explode    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
198
+    // +     improved by: kenneth
199
+    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
200
+    // +     improved by: d3x
201
+    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     example 1: explode(' ', 'Kevin van Zonneveld');
202
+    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
203
+    // *     example 2: explode('=', 'a=bc=d', 2);
204
+    // *     returns 2: ['a', 'bc=d']
205
+    var emptyArray = {        0: ''
206
+    };
207
+ 
208
+    // third argument is not required
209
+    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {        return null;
210
+    }
211
+ 
212
+    if (delimiter === '' || delimiter === false || delimiter === null) {
213
+        return false;    }
214
+ 
215
+    if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
216
+        return emptyArray;
217
+    } 
218
+    if (delimiter === true) {
219
+        delimiter = '1';
220
+    }
221
+     if (!limit) {
222
+        return string.toString().split(delimiter.toString());
223
+    }
224
+    // support for limit argument
225
+    var splitted = string.toString().split(delimiter.toString());    var partA = splitted.splice(0, limit - 1);
226
+    var partB = splitted.join(delimiter.toString());
227
+    partA.push(partB);
228
+    return partA;
229
+}
230
+
193
 $(document).ready(function(){
231
 $(document).ready(function(){
194
     
232
     
195
   
233
   
553
               {
591
               {
554
                 var tag_name = tags[i]['name'];
592
                 var tag_name = tags[i]['name'];
555
                 var tag_id = tags[i]['id'];
593
                 var tag_id = tags[i]['id'];
594
+                var t_string = tag_name
556
                 // On construit un li
595
                 // On construit un li
557
-                var sstr = $.trim(input.val());
558
-                var re = new RegExp(sstr, "i") ;
559
-                var t_string = tag_name.replace(re,"<strong>" + sstr + "</strong>");
560
                 
596
                 
597
+                string_exploded = explode(' ', $.trim(input.val()));
598
+                for (n in string_exploded)
599
+                {
600
+                  r_string = string_exploded[n];
601
+                  var re = new RegExp(r_string, "i") ;
602
+                  t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
603
+                }
604
+                                
561
                 li_tag = 
605
                 li_tag = 
562
                   $('<li>').append(
606
                   $('<li>').append(
563
                     $('<a>').attr('href','#'+tag_id+'#'+tag_name)
607
                     $('<a>').attr('href','#'+tag_id+'#'+tag_name)