/[jquery]/tag_complete/tag_complete.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /tag_complete/tag_complete.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 45 by dpavlin, Fri Aug 18 21:58:54 2006 UTC revision 48 by dpavlin, Fri Aug 18 23:10:48 2006 UTC
# Line 47  var _tag = { Line 47  var _tag = {
47                  }                  }
48    
49                  var c = _tag.current;                  var c = _tag.current;
50                  if (c == null) return;                  if (c == null) return c;
51    
52                  $('#suggest').html('');                  $('#suggest').html('');
53                  _tag.current = null;                  _tag.current = null;
54    
55                    return c;
56          },          },
57    
58    
59          take_suggested: function() {          take_suggested: function() {
60                  if (_tag.current == null) return;                  var c = _tag.current;
61                  var s = $('#suggest li:nth('+_tag.current+')').html();                  if (c == null) {
62                  $.log.info('take suggestion: '+s);                          $.log.debug('no current, return true');
63                            return true;
64                    }
65    
66                    var s = $('#suggest li:nth('+c+')').html();
67                    if (s == null) {
68                            $.log.debug('no suggest, return true');
69                            return true;
70                    }
71    
72                    _tag.add_tag( s );
73                    _tag.clean_selected();
74                    return false;
75            },
76    
77            add_tag: function( t ) {
78                    $.log.info('add: '+t);
79                  $('#tags').val(                  $('#tags').val(
80                          $('#tags').val().replace(                          $('#tags').val().replace(
81                                  /^([^ ][^ ]* )*[^ ]*$/, '$1' + s + ' '                                  /[^ ]*$/, t + ' '
82                          )                          )
83                  );                  );
84                  _tag.focus();                  _tag.focus();
85                    return false;
86          },          },
87    
88          move_suggested: function( where ) {          move_suggested: function( where ) {
# Line 100  var _tag = { Line 119  var _tag = {
119  $(document).ready( function() {  $(document).ready( function() {
120    
121          $('.tag').each( function(i) {          $('.tag').each( function(i) {
122                  _tag.name[i] = this.firstChild.nodeValue;                  var n = this.firstChild.nodeValue;
123                    _tag.name[i] = n;
124                  _tag.obj[i] = this;                  _tag.obj[i] = this;
125                    this.onclick = function() {
126                            return _tag.add_tag( n );
127                    }
128          });          });
129          $.log.info( 'found ' + _tag.name.length + ' tags' );          $.log.info( 'found ' + _tag.name.length + ' tags' );
130    
# Line 115  $(document).ready( function() { Line 138  $(document).ready( function() {
138                                  e.preventDefault();                                  e.preventDefault();
139                                  _tag.move_suggested( -1 );                                  _tag.move_suggested( -1 );
140                                  return false;                                  return false;
                                 break;  
141                          case 40:        // down                          case 40:        // down
142                                  e.preventDefault();                                  e.preventDefault();
143                                  _tag.move_suggested( +1 );                                  _tag.move_suggested( +1 );
144                                  return false;                                  return false;
                                 break;  
145                          case 9:         // tab                          case 9:         // tab
146                          case 13:        // return                          case 13:        // return
147                                    if (_tag.current != null) _tag.focus();
148                                  e.preventDefault();                                  e.preventDefault();
                                 _tag.take_suggested();  
   
149                                  return false;                                  return false;
                                 break;  
150                  }                  }
151    
152    
# Line 146  $(document).ready( function() { Line 165  $(document).ready( function() {
165                  return true;                  return true;
166          }).submit( function() {          }).submit( function() {
167                  $.log.debug('submit');                  $.log.debug('submit');
168                  if (_tag.current == null) {                  return _tag.take_suggested();
                         _tag.clean_selected();  
                         return true;  
                 } else {  
                         return false;  
                 }  
169          }).blur( function() {          }).blur( function() {
170                  $.log.debug('blur');                  $.log.debug('blur');
171                  _tag.clean_selected();                  return _tag.take_suggested();
                 if (_tag.current == null) {  
                         return true;  
                 } else {  
                         _tag.focus();  
                         return false;  
                 }  
172          });          });
173    
174          $.log.toggle();          $.log.toggle();

Legend:
Removed from v.45  
changed lines
  Added in v.48

  ViewVC Help
Powered by ViewVC 1.1.26