@@ -29,6 +29,16 @@ http://www.famfamfam.com/lab/icons/silk/
29
29
Loader image created at:
30
30
Preloaders.net
31
31
http://preloaders.net/
32
+
33
+ Updates from Inducido
34
+ if I type "postgressql" & in my avaliable list I have "PostgresSQL" (or type "java" vs "Java"),
35
+ I want the autocomplete to add the latter.
36
+ I also added a foolproof behavior (that I got) where "PostgresSQL" is actually "PostgresSQL "
37
+ int the available list (with a space)
38
+
39
+ another update : on top of the "ignorecase" feature, I added a feature like UpdateURL but
40
+ "updateField" instead --> it is meant to automatically update an hidden field using the result
41
+ of getSerializedTags()
32
42
33
43
------------------------------------------------------------------------------
34
44
Description
@@ -118,6 +128,7 @@ getURL URL for retrieving tag lists via ajax {}
118
128
initLoad indicates if all tags should be loaded on init true
119
129
updateData data field with additional info for updtateURL {}
120
130
updateURL URL for saving tags via ajax ''
131
+ updateField URL for saving tags ''
121
132
122
133
Callback options:
123
134
-----------------
@@ -186,6 +197,25 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
186
197
187
198
*/
188
199
200
+
201
+ if ( String . prototype . alltrim == null )
202
+ String . prototype . alltrim = function ( )
203
+ {
204
+ //return this.replace(/(^\s*)|(\s*$)/g,'');
205
+ //bizzarement \s ne remplacais pas les \n en debut de chain alors que
206
+ // \s veut dire espace et \r ou \n en regexp-->balec, je fait bourrin
207
+ //je viens de comprendre: chorme a un trim natif
208
+ return this . replace ( / ( ^ [ \n \s \r ] * ) | ( [ \n \s \r ] * $ ) / g, '' ) ;
209
+ }
210
+
211
+ if ( String . prototype . equalsIgnoreCase == null )
212
+ String . prototype . equalsIgnoreCase = myEqualsIgnoreCase ;
213
+
214
+ function myEqualsIgnoreCase ( arg )
215
+ {
216
+ return ( new String ( this . toLowerCase ( ) ) == ( new String ( arg ) ) . toLowerCase ( ) ) ;
217
+ }
218
+
189
219
( function ( $ ) {
190
220
191
221
// some helper methods
@@ -262,6 +292,88 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
262
292
$ ( "<div />" ) . attr ( { id : tagContainer . id + "_loader" , title : "Saving Tags" } ) . addClass ( "tagLoader" ) . appendTo ( tagContainerObject . parent ( ) ) ;
263
293
}
264
294
295
+ // adds autocomplete functionality for the tag names
296
+ if ( opts . autocomplete && typeof ( $ . fn . autocomplete ) == 'function' && opts . initLoad ) {
297
+ $ ( inputField ) . autocomplete ( {
298
+ source : tags . availableTags ,
299
+ select : function ( event , ui ) {
300
+ var $el = $ ( this ) ;
301
+ if ( ! checkTag ( $ . trim ( ui . item . value ) , tags . assignedTags ) ) {
302
+ if ( opts . maxTags > 0 && tags . assignedTags . length >= opts . maxTags ) {
303
+ alert ( 'Maximum tags allowed: ' + opts . maxTags ) ;
304
+ }
305
+ else {
306
+ var newTag = $ . trim ( ui . item . value ) ;
307
+ var rc = 1 ;
308
+ if ( typeof ( opts . onAdd ) == "function" ) {
309
+ rc = opts . onAdd . call ( this , newTag ) ;
310
+ }
311
+ if ( rc || typeof ( rc ) == "undefined" ) {
312
+ tags = addTag ( this , newTag , tags , opts . sortTags ) ;
313
+ if ( opts . updateURL !== '' && opts . autoUpdate ) {
314
+ saveTags ( tags , opts , tagContainer . id ) ;
315
+ }
316
+ if ( opts . updateField !== '' ) {
317
+ saveTagsToField ( tags , opts , tagContainer . id ) ;
318
+ }
319
+ $ ( inputField ) . autocomplete ( "option" , "source" , tags . availableTags ) ;
320
+ if ( typeof ( opts . afterAdd ) == "function" ) {
321
+ opts . afterAdd . call ( this , newTag ) ;
322
+ }
323
+ }
324
+ }
325
+ $el . focus ( ) ;
326
+ }
327
+ $el . val ( "" ) ;
328
+ return false ;
329
+ } ,
330
+ minLength : opts . minChars
331
+ } ) ;
332
+ }
333
+ // Make an AJAX request to get the list of tags based on typed data
334
+ else if ( opts . autocomplete && typeof ( $ . fn . autocomplete ) == 'function' ) {
335
+ $ ( inputField ) . autocomplete ( {
336
+ source : function ( request , response ) {
337
+ opts . getData [ opts . queryname ] = request . term ;
338
+ var lastXhr = $ . getJSON ( opts . getURL , opts . getData , function ( data , status , xhr ) {
339
+ response ( data . availableTags ) ;
340
+ } ) ;
341
+ } ,
342
+ select : function ( event , ui ) {
343
+ var $el = $ ( this ) ;
344
+ if ( ! checkTag ( $ . trim ( ui . item . value ) , tags . assignedTags ) ) {
345
+ if ( opts . maxTags > 0 && tags . assignedTags . length >= opts . maxTags ) {
346
+ alert ( 'Maximum tags allowed: ' + opts . maxTags ) ;
347
+ }
348
+ else {
349
+ var newTag = $ . trim ( ui . item . value ) ;
350
+ var rc = 1 ;
351
+ if ( typeof ( opts . onAdd ) == "function" ) {
352
+ opts . onAdd . call ( this , newTag ) ;
353
+ }
354
+ if ( rc || typeof ( rc ) == "undefined" ) {
355
+ tags = addTag ( this , $ . trim ( ui . item . value ) , tags , opts . sortTags ) ;
356
+ if ( opts . updateURL !== '' && opts . autoUpdate ) {
357
+ saveTags ( tags , opts , tagContainer . id ) ;
358
+ }
359
+ if ( opts . updateField !== '' ) {
360
+ saveTagsToField ( tags , opts , tagContainer . id ) ;
361
+ }
362
+ if ( typeof ( opts . afterAdd ) == "function" ) {
363
+ opts . afterAdd . call ( this , newTag ) ;
364
+ }
365
+ }
366
+ }
367
+ $el . focus ( ) ;
368
+ }
369
+ $el . val ( '' ) ;
370
+ return false ;
371
+ } ,
372
+ minLength : opts . minChars
373
+ } ) ;
374
+
375
+ }
376
+
265
377
// initializes the tag lists
266
378
// tag lists will be pulled from a URL
267
379
if ( opts . getURL !== '' && opts . initLoad ) {
@@ -349,6 +461,10 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
349
461
if ( opts . updateURL !== '' && opts . autoUpdate ) {
350
462
saveTags ( tags , opts , tagContainer . id ) ;
351
463
}
464
+ if ( opts . updateField !== '' ) {
465
+ saveTagsToField ( tags , opts , tagContainer . id ) ;
466
+ }
467
+
352
468
}
353
469
354
470
if ( typeof ( opts . afterDelete ) == "function" ) {
@@ -392,6 +508,9 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
392
508
if ( opts . updateURL !== '' && opts . autoUpdate ) {
393
509
saveTags ( tags , opts , tagContainer . id ) ;
394
510
}
511
+ if ( opts . updateField !== '' ) {
512
+ saveTagsToField ( tags , opts , tagContainer . id ) ;
513
+ }
395
514
if ( opts . autocomplete && typeof ( $ . fn . autocomplete ) == 'function' && opts . initload ) {
396
515
$ ( inputField ) . autocomplete ( "option" , "source" , tags . availableTags ) ;
397
516
}
@@ -419,6 +538,9 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
419
538
if ( opts . updateURL !== '' && opts . autoUpdate ) {
420
539
saveTags ( tags , opts , tagContainer . id ) ;
421
540
}
541
+ if ( opts . updateField !== '' ) {
542
+ saveTagsToField ( tags , opts , tagContainer . id ) ;
543
+ }
422
544
if ( typeof ( opts . afterDelete ) == "function" ) {
423
545
opts . afterDelete . call ( this , $ . trim ( deleted_tag ) ) ;
424
546
}
@@ -429,81 +551,6 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
429
551
}
430
552
} ) ;
431
553
432
- // adds autocomplete functionality for the tag names
433
- if ( opts . autocomplete && typeof ( $ . fn . autocomplete ) == 'function' && opts . initLoad ) {
434
- $ ( inputField ) . autocomplete ( {
435
- source : tags . availableTags ,
436
- select : function ( event , ui ) {
437
- var $el = $ ( this ) ;
438
- if ( ! checkTag ( $ . trim ( ui . item . value ) , tags . assignedTags ) ) {
439
- if ( opts . maxTags > 0 && tags . assignedTags . length >= opts . maxTags ) {
440
- alert ( 'Maximum tags allowed: ' + opts . maxTags ) ;
441
- }
442
- else {
443
- var newTag = $ . trim ( ui . item . value ) ;
444
- var rc = 1 ;
445
- if ( typeof ( opts . onAdd ) == "function" ) {
446
- rc = opts . onAdd . call ( this , newTag ) ;
447
- }
448
- if ( rc || typeof ( rc ) == "undefined" ) {
449
- tags = addTag ( this , newTag , tags , opts . sortTags ) ;
450
- if ( opts . updateURL !== '' && opts . autoUpdate ) {
451
- saveTags ( tags , opts , tagContainer . id ) ;
452
- }
453
- $ ( inputField ) . autocomplete ( "option" , "source" , tags . availableTags ) ;
454
- if ( typeof ( opts . afterAdd ) == "function" ) {
455
- opts . afterAdd . call ( this , newTag ) ;
456
- }
457
- }
458
- }
459
- $el . focus ( ) ;
460
- }
461
- $el . val ( "" ) ;
462
- return false ;
463
- } ,
464
- minLength : opts . minChars
465
- } ) ;
466
- }
467
- // Make an AJAX request to get the list of tags based on typed data
468
- else if ( opts . autocomplete && typeof ( $ . fn . autocomplete ) == 'function' ) {
469
- $ ( inputField ) . autocomplete ( {
470
- source : function ( request , response ) {
471
- opts . getData [ opts . queryname ] = request . term ;
472
- var lastXhr = $ . getJSON ( opts . getURL , opts . getData , function ( data , status , xhr ) {
473
- response ( data . availableTags ) ;
474
- } ) ;
475
- } ,
476
- select : function ( event , ui ) {
477
- var $el = $ ( this ) ;
478
- if ( ! checkTag ( $ . trim ( ui . item . value ) , tags . assignedTags ) ) {
479
- if ( opts . maxTags > 0 && tags . assignedTags . length >= opts . maxTags ) {
480
- alert ( 'Maximum tags allowed: ' + opts . maxTags ) ;
481
- }
482
- else {
483
- var newTag = $ . trim ( ui . item . value ) ;
484
- var rc = 1 ;
485
- if ( typeof ( opts . onAdd ) == "function" ) {
486
- opts . onAdd . call ( this , newTag ) ;
487
- }
488
- if ( rc || typeof ( rc ) == "undefined" ) {
489
- tags = addTag ( this , $ . trim ( ui . item . value ) , tags , opts . sortTags ) ;
490
- if ( opts . updateURL !== '' && opts . autoUpdate ) {
491
- saveTags ( tags , opts , tagContainer . id ) ;
492
- }
493
- if ( typeof ( opts . afterAdd ) == "function" ) {
494
- opts . afterAdd . call ( this , newTag ) ;
495
- }
496
- }
497
- }
498
- $el . focus ( ) ;
499
- }
500
- $el . val ( '' ) ;
501
- return false ;
502
- } ,
503
- minLength : opts . minChars
504
- } ) ;
505
- }
506
-
507
554
// sets the input field to show the autocomplete list on focus
508
555
// when there is no value
509
556
$ ( inputField ) . focus ( function ( ) {
@@ -555,15 +602,22 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
555
602
queryname : 'q' ,
556
603
sortTags : true ,
557
604
updateData : { } ,
558
- updateURL : ''
605
+ updateURL : '' ,
606
+ updateField : ''
559
607
} ;
560
608
561
609
// checks to to see if a tag is already found in a list of tags
610
+ // now return the correected value
562
611
function checkTag ( value , tags ) {
563
612
var check = false ;
564
613
jQuery . each ( tags , function ( i , e ) {
565
- if ( e === value ) {
566
- check = true ;
614
+
615
+ //alltrim to handle when there's space in the tag list by mistake
616
+ if ( e && e . alltrim ( ) . equalsIgnoreCase ( value ) ) {
617
+ // if ((new String(e.toString())).toLowercase() === (new String(value.toString())).toString().toLowercase()) {
618
+ // if (e === value) {
619
+ // check = true;
620
+ check = e . alltrim ( ) ;
567
621
return false ;
568
622
}
569
623
} ) ;
@@ -574,7 +628,18 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
574
628
// removes a tag from a tag list
575
629
function removeTagFromList ( value , tags ) {
576
630
jQuery . each ( tags , function ( i , e ) {
577
- if ( e === value ) {
631
+
632
+ //if (e === value) {
633
+ //added the ignorecase fonctionality
634
+ //"2G".toLowercase()
635
+ //TypeError: Object 2G has no method 'toLowercase' -- d'ou le new String
636
+ // var se=(new String(e.toString())).toLowercase();
637
+ // var sv=(new String(value.toString())).toLowercase();
638
+ //alltrim to handle when there's space in the tag list by mistake
639
+ if ( e && e . alltrim ( ) . equalsIgnoreCase ( value ) ) {
640
+ // if ((new String(e.toString())).toLowercase() === (new String(value.toString())).toString().toLowercase()) {
641
+ // if (se.toLowercase() === sv.toLowercase()) {
642
+ // if (se === sv) {
578
643
tags . splice ( i , 1 ) ;
579
644
}
580
645
} ) ;
@@ -584,6 +649,10 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
584
649
585
650
// adds a tag to the tag box and the assignedTags list
586
651
function addTag ( tagField , value , tags , sort ) {
652
+ newvalue = checkTag ( $ . trim ( value ) , tags . availableTags ) ;
653
+ if ( newvalue )
654
+ value = newvalue ;
655
+
587
656
tags . assignedTags . push ( value ) ;
588
657
tags . availableTags = removeTagFromList ( value , tags . availableTags ) ;
589
658
$ ( "<li />" ) . addClass ( "tagItem" ) . text ( value ) . insertBefore ( $ ( tagField ) . parent ( ) ) ;
@@ -618,6 +687,17 @@ along with this program. If not, see < http://www.gnu.org/licenses/ >.
618
687
return tags ;
619
688
}
620
689
690
+ // saves the tags to a field
691
+ function saveTagsToField ( tags , opts , tcID ) {
692
+ var sendData = {
693
+ tags : tags . assignedTags
694
+ } ;
695
+ test = $ ( '#' + tcID ) . tagHandler ( "getSerializedTags" ) ;
696
+ // test=getSerializedTags();
697
+ $ ( opts . updateField ) . val ( test ) ;
698
+
699
+ }
700
+
621
701
// saves the tags to the server via ajax
622
702
function saveTags ( tags , opts , tcID ) {
623
703
var sendData = {
0 commit comments