/[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 52 by dpavlin, Sat Aug 19 12:53:59 2006 UTC revision 53 by dpavlin, Sat Aug 19 23:11:12 2006 UTC
# Line 7  Line 7 
7  var _tag = {  var _tag = {
8          name: new Array(),          name: new Array(),
9          obj: new Array(),          obj: new Array(),
10            tag2i: new Array(),
11          selected: new Array(),          selected: new Array(),
12          entered: {                      // array of entered tags          entered: {                      // array of entered tags
13                  i: new Array(),         // offset to tags                  i: new Array(),         // offset to tags
# Line 14  var _tag = { Line 15  var _tag = {
15          },          },
16    
17          current: null,                  // current selected suggestion          current: null,                  // current selected suggestion
18            last_tags: '',
19    
20          select: function( tag ) {          select: function( tag ) {
21    
# Line 151  var _tag = { Line 153  var _tag = {
153                  _tag.current = to;                  _tag.current = to;
154          },          },
155    
156          last_tag: function() {          parse: function() {
157                  return $('#tags').val().replace(/^([^ ][^ ]* )*/, '');                  $.log.info('re-parse tags');
158    
159                    var t = $('#tags').val().replace(/^  */,'').replace(/  *$/,'').split(/ /);
160    
161                    _tag.entered = {
162                            i: new Array(),
163                            tag: new Array()
164                    };
165    
166                    $('.entered').removeClass('entered');
167    
168                    var ids = '';
169                    for (var i = 0; i < t.length; i++) {
170                            var tag = t[i];
171                            if (_tag.tag2i[ tag ] != null) {
172                                    var tag_i = _tag.tag2i[ tag ];
173                                    _tag.entered.tag[ tag ] =
174                                            _tag.entered.i.push( tag_i ) - 1;
175                                    jQuery.className.add( _tag.obj[ tag_i ], 'entered' );
176                                    ids += i + ':' + tag_i + ' ';
177                            } else {
178                                    ids += i + ':{' + tag + '} ';
179                            }
180                    }
181                    $.log.debug('tags: '+t.join(','), 'ids:'+ids);
182    
183          },          },
184    
185            current_tag: function() {
186                    var tags = $('#tags').val();
187                    if (tags != _tag.last_tags) {
188                            _tag.last_tags = tags;
189                            _tag.parse();
190                    }
191                    return tags.replace(/^([^ ][^ ]* )*/, '');
192            },
193    
194          focus: function() {          focus: function() {
195                  // $('#tags').focus() doesn't work!                  // $('#tags').focus() doesn't work!
196                  document.getElementById('tags').focus();                  document.getElementById('tags').focus();
# Line 167  $(document).ready( function() { Line 204  $(document).ready( function() {
204                  var n = this.firstChild.nodeValue;                  var n = this.firstChild.nodeValue;
205                  _tag.name[i] = n;                  _tag.name[i] = n;
206                  _tag.obj[i] = this;                  _tag.obj[i] = this;
207                    _tag.tag2i[n] = i;
208                  this.onclick = function() {                  this.onclick = function() {
209                          return _tag.tag( n, i );                          return _tag.tag( n, i );
210                  }                  }
# Line 193  $(document).ready( function() { Line 231  $(document).ready( function() {
231                                  if (_tag.current != null) _tag.focus();                                  if (_tag.current != null) _tag.focus();
232                                  e.preventDefault();                                  e.preventDefault();
233                                  return false;                                  return false;
234                            case 8:         // backspace
235                            case 46:        // del
236                                    _tag.parse();
237                                    return false;
238                  }                  }
239    
240    
241                  var t = _tag.last_tag();                  var t = _tag.current_tag();
242    
243                  $.log.debug('tag: ' + t + ' ['+t.length+']');                  $.log.debug('tag: ' + t + ' ['+t.length+']');
244    

Legend:
Removed from v.52  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26