public this repo is viewable by everyone
Clone URL: git://github.com/robbyrussell/rubyurl.git
Updating js files from Rails, and a few items in script/, spec_helper
Robby Russell (author)
2 months ago
commit  f7fd211defe7227b53aa0ac6a05a0894b588ae0e
tree    2df056fa762f97565403149e910ae39c1dcf15a6
parent  ecbc90102fe92306a6bd5a8880e5fe952c558682
...
1
 
 
2
3
4
 
5
6
7
8
9
 
 
 
 
 
 
 
 
10
11
12
 
 
 
 
 
 
 
 
 
 
 
13
14
15
16
17
18
 
 
 
 
19
20
21
22
 
 
 
 
23
24
25
26
 
 
 
 
 
 
27
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
40
 
 
 
 
 
 
 
 
 
41
42
43
44
45
 
 
 
...
 
1
2
3
 
 
4
5
 
 
 
 
6
7
8
9
10
11
12
13
14
 
 
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
27
28
29
30
31
 
 
 
32
33
34
35
36
 
 
 
37
38
39
40
41
42
43
 
 
 
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
 
 
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
 
95
96
97
98
99
100
101
102
103
104
105
 
 
106
107
108
109
0
@@ -1,45 +1,109 @@
0
-# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
0
+# Don't change this file!
0
+# Configure your app in config/environment.rb and config/environments/*.rb
0
 
0
-unless defined?(RAILS_ROOT)
0
- root_path = File.join(File.dirname(__FILE__), '..')
0
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
0
 
0
- unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
0
- require 'pathname'
0
- root_path = Pathname.new(root_path).cleanpath(true).to_s
0
- end
0
+module Rails
0
+ class << self
0
+ def boot!
0
+ unless booted?
0
+ preinitialize
0
+ pick_boot.run
0
+ end
0
+ end
0
 
0
- RAILS_ROOT = root_path
0
-end
0
+ def booted?
0
+ defined? Rails::Initializer
0
+ end
0
+
0
+ def pick_boot
0
+ (vendor_rails? ? VendorBoot : GemBoot).new
0
+ end
0
+
0
+ def vendor_rails?
0
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
0
+ end
0
 
0
-unless defined?(Rails::Initializer)
0
- if File.directory?("#{RAILS_ROOT}/vendor/rails")
0
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
- else
0
- require 'rubygems'
0
+ # FIXME : Ruby 1.9
0
+ def preinitialize
0
+ load(preinitializer_path) if File.exists?(preinitializer_path)
0
+ end
0
 
0
- environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
0
- environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
0
- rails_gem_version = $1
0
+ def preinitializer_path
0
+ "#{RAILS_ROOT}/config/preinitializer.rb"
0
+ end
0
+ end
0
 
0
- if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
0
- # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
0
- rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
0
+ class Boot
0
+ def run
0
+ load_initializer
0
+ Rails::Initializer.run(:set_load_path)
0
+ end
0
+ end
0
 
0
- if rails_gem
0
- gem "rails", "=#{rails_gem.version.version}"
0
- require rails_gem.full_gem_path + '/lib/initializer'
0
+ class VendorBoot < Boot
0
+ def load_initializer
0
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
+ end
0
+ end
0
+
0
+ class GemBoot < Boot
0
+ def load_initializer
0
+ self.class.load_rubygems
0
+ load_rails_gem
0
+ require 'initializer'
0
+ end
0
+
0
+ def load_rails_gem
0
+ if version = self.class.gem_version
0
+ gem 'rails', version
0
       else
0
- STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
0
- Install the missing gem with 'gem install -v=#{version} rails', or
0
- change environment.rb to define RAILS_GEM_VERSION with your desired version.
0
- )
0
+ gem 'rails'
0
+ end
0
+ rescue Gem::LoadError => load_error
0
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
0
+ exit 1
0
+ end
0
+
0
+ class << self
0
+ def rubygems_version
0
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
0
+ end
0
+
0
+ def gem_version
0
+ if defined? RAILS_GEM_VERSION
0
+ RAILS_GEM_VERSION
0
+ elsif ENV.include?('RAILS_GEM_VERSION')
0
+ ENV['RAILS_GEM_VERSION']
0
+ else
0
+ parse_gem_version(read_environment_rb)
0
+ end
0
+ end
0
+
0
+ def load_rubygems
0
+ require 'rubygems'
0
+
0
+ unless rubygems_version >= '0.9.4'
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
0
+ exit 1
0
+ end
0
+
0
+ rescue LoadError
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
0
         exit 1
0
       end
0
- else
0
- gem "rails"
0
- require 'initializer'
0
+
0
+ def parse_gem_version(text)
0
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
0
+ end
0
+
0
+ private
0
+ def read_environment_rb
0
+ File.read("#{RAILS_ROOT}/config/environment.rb")
0
+ end
0
     end
0
   end
0
-
0
- Rails::Initializer.run(:set_load_path)
0
 end
0
+
0
+# All that for this:
0
+Rails.boot!
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,29 +0,0 @@
0
-# This file is autogenerated. Instead of editing this file, please use the
0
-# migrations feature of ActiveRecord to incrementally modify your database, and
0
-# then regenerate this schema definition.
0
-
0
-ActiveRecord::Schema.define(:version => 2) do
0
-
0
- create_table "links", :force => true do |t|
0
- t.column "website_url", :text
0
- t.column "token", :string
0
- t.column "permalink", :string
0
- t.column "ip_address", :string
0
- t.column "created_at", :datetime
0
- t.column "updated_at", :datetime
0
- end
0
-
0
- add_index "links", ["token"], :name => "index_links_on_token"
0
-
0
- create_table "visits", :force => true do |t|
0
- t.column "link_id", :integer
0
- t.column "referral_link", :text
0
- t.column "flagged", :string
0
- t.column "ip_address", :text
0
- t.column "created_at", :datetime
0
- end
0
-
0
- add_index "visits", ["flagged"], :name => "index_visits_on_flagged"
0
- add_index "visits", ["link_id"], :name => "index_visits_on_link_id"
0
-
0
-end
...
1
2
3
 
 
 
4
5
6
...
37
38
39
40
41
42
 
 
43
44
 
 
45
46
47
48
49
50
 
51
52
53
54
55
 
56
57
58
...
74
75
76
 
 
 
77
78
79
...
81
82
83
84
85
 
 
86
87
88
89
90
91
92
 
93
94
95
...
139
140
141
142
 
143
144
145
146
147
 
148
149
150
151
152
 
153
154
155
...
195
196
197
198
199
200
201
...
238
239
240
241
 
242
243
244
245
246
247
248
249
 
 
 
 
250
251
252
 
253
254
255
 
256
257
258
...
296
297
298
 
299
300
301
302
303
304
305
 
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
326
 
327
328
 
 
 
 
 
 
 
 
 
329
330
331
 
332
333
334
...
338
339
340
341
 
 
 
342
343
344
...
346
347
348
349
 
350
351
352
353
354
355
356
357
358
359
...
391
392
393
394
395
 
396
397
398
...
448
449
450
451
 
452
453
454
455
456
457
 
 
458
459
460
...
465
466
467
468
469
470
 
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
 
 
 
 
 
 
 
 
 
513
514
515
 
516
517
518
519
520
521
522
523
 
 
 
524
525
526
527
528
529
530
531
532
533
534
535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
 
 
 
 
 
612
613
614
615
616
 
617
618
619
620
621
622
623
624
625
626
627
628
 
 
 
629
630
631
 
 
 
 
 
 
 
632
633
634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
 
 
 
 
 
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
704
705
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
708
709
710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
712
 
713
714
715
716
 
 
 
717
718
719
720
721
 
 
 
722
723
724
725
726
727
728
729
730
 
 
 
 
 
 
 
731
732
733
734
735
736
737
738
739
740
741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
 
743
744
745
746
747
748
749
750
751
 
 
 
 
 
 
 
 
 
752
753
754
755
756
 
757
758
759
760
 
 
 
 
 
 
 
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
777
778
 
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
799
800
801
802
803
804
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805
 
 
 
 
 
 
806
807
808
 
 
 
 
809
810
811
812
813
814
 
815
816
817
...
830
831
832
833
 
...
 
 
 
1
2
3
4
5
6
...
37
38
39
 
 
 
40
41
42
 
43
44
45
46
47
48
49
50
51
52
53
54
55
 
56
57
58
59
...
75
76
77
78
79
80
81
82
83
...
85
86
87
 
 
88
89
90
91
92
93
94
 
 
95
96
97
98
...
142
143
144
 
145
146
147
148
149
 
150
151
152
153
154
 
155
156
157
158
...
198
199
200
 
201
202
203
...
240
241
242
 
243
244
245
246
247
 
 
 
 
248
249
250
251
252
253
 
254
255
256
257
258
259
260
261
...
299
300
301
302
303
 
304
305
306
307
308
309
310
311
312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
 
331
332
 
333
334
335
336
337
338
339
340
341
342
 
 
343
344
345
346
...
350
351
352
 
353
354
355
356
357
358
...
360
361
362
 
363
364
365
366
367
368
369
 
370
371
372
...
404
405
406
 
 
407
408
409
410
...
460
461
462
 
463
464
465
466
 
 
 
467
468
469
470
471
...
476
477
478
 
 
 
479
480
481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
483
484
485
486
487
488
489
490
491
 
 
492
493
 
 
 
 
 
 
 
494
495
496
497
 
 
 
 
 
 
 
 
 
 
 
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
538
539
540
541
542
 
 
 
 
543
544
 
 
 
 
 
 
 
 
 
 
 
545
546
547
548
 
 
549
550
551
552
553
554
555
556
 
 
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
610
611
612
613
614
 
615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
 
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
 
 
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
 
723
724
 
 
 
725
726
727
728
 
 
 
 
729
730
731
732
733
 
 
 
 
 
 
 
734
735
736
737
738
739
740
741
 
 
 
 
 
 
 
 
 
 
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
 
 
 
 
 
 
 
 
791
792
793
794
795
796
797
798
799
800
 
 
 
 
801
802
 
 
 
803
804
805
806
807
808
809
810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
 
848
849
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
 
 
 
 
 
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
 
 
944
945
946
947
...
960
961
962
 
963
0
@@ -1,6 +1,6 @@
0
-// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
0
-// (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
0
-// (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
0
+// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
0
+// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
0
+// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
0
 // Contributors:
0
 // Richard Livsey
0
 // Rahul Bhargava
0
@@ -37,22 +37,23 @@
0
 if(typeof Effect == 'undefined')
0
   throw("controls.js requires including script.aculo.us' effects.js library");
0
 
0
-var Autocompleter = {}
0
-Autocompleter.Base = function() {};
0
-Autocompleter.Base.prototype = {
0
+var Autocompleter = { }
0
+Autocompleter.Base = Class.create({
0
   baseInitialize: function(element, update, options) {
0
- this.element = $(element);
0
+ element = $(element)
0
+ this.element = element;
0
     this.update = $(update);
0
     this.hasFocus = false;
0
     this.changed = false;
0
     this.active = false;
0
     this.index = 0;
0
     this.entryCount = 0;
0
+ this.oldElementValue = this.element.value;
0
 
0
     if(this.setOptions)
0
       this.setOptions(options);
0
     else
0
- this.options = options || {};
0
+ this.options = options || { };
0
 
0
     this.options.paramName = this.options.paramName || this.element.name;
0
     this.options.tokens = this.options.tokens || [];
0
@@ -74,6 +75,9 @@ Autocompleter.Base.prototype = {
0
 
0
     if(typeof(this.options.tokens) == 'string')
0
       this.options.tokens = new Array(this.options.tokens);
0
+ // Force carriage returns as token delimiters anyway
0
+ if (!this.options.tokens.include('\n'))
0
+ this.options.tokens.push('\n');
0
 
0
     this.observer = null;
0
     
0
@@ -81,15 +85,14 @@ Autocompleter.Base.prototype = {
0
 
0
     Element.hide(this.update);
0
 
0
- Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
0
- Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
0
+ Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
0
+ Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
0
   },
0
 
0
   show: function() {
0
     if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
0
     if(!this.iefix &&
0
- (navigator.appVersion.indexOf('MSIE')>0) &&
0
- (navigator.userAgent.indexOf('Opera')<0) &&
0
+ (Prototype.Browser.IE) &&
0
       (Element.getStyle(this.update, 'position')=='absolute')) {
0
       new Insertion.After(this.update,
0
        '<iframe id="' + this.update.id + '_iefix" '+
0
@@ -139,17 +142,17 @@ Autocompleter.Base.prototype = {
0
        case Event.KEY_UP:
0
          this.markPrevious();
0
          this.render();
0
- if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
0
+ Event.stop(event);
0
          return;
0
        case Event.KEY_DOWN:
0
          this.markNext();
0
          this.render();
0
- if(navigator.appVersion.indexOf('AppleWebKit')>0) Event.stop(event);
0
+ Event.stop(event);
0
          return;
0
       }
0
      else
0
        if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
0
- (navigator.appVersion.indexOf('AppleWebKit') > 0 && event.keyCode == 0)) return;
0
+ (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
0
 
0
     this.changed = true;
0
     this.hasFocus = true;
0
@@ -195,7 +198,6 @@ Autocompleter.Base.prototype = {
0
         this.index==i ?
0
           Element.addClassName(this.getEntry(i),"selected") :
0
           Element.removeClassName(this.getEntry(i),"selected");
0
-
0
       if(this.hasFocus) {
0
         this.show();
0
         this.active = true;
0
@@ -238,21 +240,22 @@ Autocompleter.Base.prototype = {
0
     }
0
     var value = '';
0
     if (this.options.select) {
0
- var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
0
+ var nodes = $(selectedElement).select('.' + this.options.select) || [];
0
       if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
0
     } else
0
       value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
0
     
0
- var lastTokenPos = this.findLastToken();
0
- if (lastTokenPos != -1) {
0
- var newValue = this.element.value.substr(0, lastTokenPos + 1);
0
- var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
0
+ var bounds = this.getTokenBounds();
0
+ if (bounds[0] != -1) {
0
+ var newValue = this.element.value.substr(0, bounds[0]);
0
+ var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
0
       if (whitespace)
0
         newValue += whitespace[0];
0
- this.element.value = newValue + value;
0
+ this.element.value = newValue + value + this.element.value.substr(bounds[1]);
0
     } else {
0
       this.element.value = value;
0
     }
0
+ this.oldElementValue = this.element.value;
0
     this.element.focus();
0
     
0
     if (this.options.afterUpdateElement)
0
@@ -296,39 +299,48 @@ Autocompleter.Base.prototype = {
0
 
0
   onObserverEvent: function() {
0
     this.changed = false;
0
+ this.tokenBounds = null;
0
     if(this.getToken().length>=this.options.minChars) {
0
- this.startIndicator();
0
       this.getUpdatedChoices();
0
     } else {
0
       this.active = false;
0
       this.hide();
0
     }
0
+ this.oldElementValue = this.element.value;
0
   },
0
 
0
   getToken: function() {
0
- var tokenPos = this.findLastToken();
0
- if (tokenPos != -1)
0
- var ret = this.element.value.substr(tokenPos + 1).replace(/^\s+/,'').replace(/\s+$/,'');
0
- else
0
- var ret = this.element.value;
0
-
0
- return /\n/.test(ret) ? '' : ret;
0
- },
0
-
0
- findLastToken: function() {
0
- var lastTokenPos = -1;
0
-
0
- for (var i=0; i<this.options.tokens.length; i++) {
0
- var thisTokenPos = this.element.value.lastIndexOf(this.options.tokens[i]);
0
- if (thisTokenPos > lastTokenPos)
0
- lastTokenPos = thisTokenPos;
0
+ var bounds = this.getTokenBounds();
0
+ return this.element.value.substring(bounds[0], bounds[1]).strip();
0
+ },
0
+
0
+ getTokenBounds: function() {
0
+ if (null != this.tokenBounds) return this.tokenBounds;
0
+ var value = this.element.value;
0
+ if (value.strip().empty()) return [-1, 0];
0
+ var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
0
+ var offset = (diff == this.oldElementValue.length ? 1 : 0);
0
+ var prevTokenPos = -1, nextTokenPos = value.length;
0
+ var tp;
0
+ for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
0
+ tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
0
+ if (tp > prevTokenPos) prevTokenPos = tp;
0
+ tp = value.indexOf(this.options.tokens[index], diff + offset);
0
+ if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
0
     }
0
- return lastTokenPos;
0
+ return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
0
   }
0
-}
0
+});
0
+
0
+Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
0
+ var boundary = Math.min(newS.length, oldS.length);
0
+ for (var index = 0; index < boundary; ++index)
0
+ if (newS[index] != oldS[index])
0
+ return index;
0
+ return boundary;
0
+};
0
 
0
-Ajax.Autocompleter = Class.create();
0
-Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
0
+Ajax.Autocompleter = Class.create(Autocompleter.Base, {
0
   initialize: function(element, update, url, options) {
0
     this.baseInitialize(element, update, options);
0
     this.options.asynchronous = true;
0
@@ -338,7 +350,9 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
0
   },
0
 
0
   getUpdatedChoices: function() {
0
- entry = encodeURIComponent(this.options.paramName) + '=' +
0
+ this.startIndicator();
0
+
0
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
0
       encodeURIComponent(this.getToken());
0
 
0
     this.options.parameters = this.options.callback ?
0
@@ -346,14 +360,13 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
0
 
0
     if(this.options.defaultParams)
0
       this.options.parameters += '&' + this.options.defaultParams;
0
-
0
+
0
     new Ajax.Request(this.url, this.options);
0
   },
0
 
0
   onComplete: function(request) {
0
     this.updateChoices(request.responseText);
0
   }
0
-
0
 });
0
 
0
 // The local array autocompleter. Used when you'd prefer to
0
@@ -391,8 +404,7 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
0
 // In that case, the other options above will not apply unless
0
 // you support them.
0
 
0
-Autocompleter.Local = Class.create();
0
-Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
0
+Autocompleter.Local = Class.create(Autocompleter.Base, {
0
   initialize: function(element, update, array, options) {
0
     this.baseInitialize(element, update, options);
0
     this.options.array = array;
0
@@ -448,13 +460,12 @@ Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
0
           ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
0
         return "<ul>" + ret.join('') + "</ul>";
0
       }
0
- }, options || {});
0
+ }, options || { });
0
   }
0
 });
0
 
0
-// AJAX in-place editor
0
-//
0
-// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
0
+// AJAX in-place editor and collection editor
0
+// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
0
 
0
 // Use this if you notice weird scrolling problems on some browsers,
0
 // the DOM might be a bit confused when this gets called so do this
0
@@ -465,353 +476,472 @@ Field.scrollFreeActivate = function(field) {
0
   }, 1);
0
 }
0
 
0
-Ajax.InPlaceEditor = Class.create();
0
-Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
0
-Ajax.InPlaceEditor.prototype = {
0
+Ajax.InPlaceEditor = Class.create({
0
   initialize: function(element, url, options)