/[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 50 by dpavlin, Fri Aug 18 23:31:16 2006 UTC
# Line 16  var _tag = { Line 16  var _tag = {
16                  _tag.selected_obj = Array();                  _tag.selected_obj = Array();
17                  var j = 0;                  var j = 0;
18                  var tag_len = tag.length;                  var tag_len = tag.length;
19                  var suggest = '<ul>';                  var suggest = '';
20    
21                  for(var i = 0; i < _tag.name.length; i++) {                  for(var i = 0; i < _tag.name.length; i++) {
22                          var t = _tag.name[i];                          var t = _tag.name[i];
# Line 25  var _tag = { Line 25  var _tag = {
25    
26                                  jQuery.className.add( _tag.obj[i], 'selected' );                                  jQuery.className.add( _tag.obj[i], 'selected' );
27    
28                                  suggest += '<li>' + t + '</li> ';                                  suggest += '<a href="#" onclick="javascript:return _tag.add_tag(\'' + t + '\')">' + t + '</a> ';
29                                  _tag.selected_obj[j] = _tag.obj[i];                                  _tag.selected_obj[j] = _tag.obj[i];
30                                  j++;                                  j++;
31                          }                          }
32                  }                  }
33    
                 suggest += '</ul>';  
   
34                  $('#suggest').html( suggest );                  $('#suggest').html( suggest );
35                  if (j > 0) {                  if (j > 0) {
36                          $('#suggest li:nth(0)').addClass('selected');                          $('#suggest a:nth(0)').addClass('selected');
37                          _tag.current = 0;                          _tag.current = 0;
38                  }                  }
39    
# Line 47  var _tag = { Line 45  var _tag = {
45                  }                  }
46    
47                  var c = _tag.current;                  var c = _tag.current;
48                  if (c == null) return;                  if (c == null) return c;
49    
50                  $('#suggest').html('');                  $('#suggest').html('');
51                  _tag.current = null;                  _tag.current = null;
52    
53                    return c;
54          },          },
55    
56    
57          take_suggested: function() {          take_suggested: function() {
58                  if (_tag.current == null) return;                  var c = _tag.current;
59                  var s = $('#suggest li:nth('+_tag.current+')').html();                  if (c == null) {
60                  $.log.info('take suggestion: '+s);                          $.log.debug('no current, return true');
61                            return true;
62                    }
63    
64                    var s = $('#suggest a:nth('+c+')').html();
65                    if (s == null) {
66                            $.log.debug('no suggest, return true');
67                            return true;
68                    }
69    
70                    _tag.add_tag( s );
71                    return false;
72            },
73    
74            add_tag: function( t ) {
75                    $.log.info('add: '+t);
76                    _tag.clean_selected();
77                    _tag.focus();
78                  $('#tags').val(                  $('#tags').val(
79                          $('#tags').val().replace(                          $('#tags').val().replace(
80                                  /^([^ ][^ ]* )*[^ ]*$/, '$1' + s + ' '                                  /[^ ]*$/, t + ' '
81                          )                          )
82                  );                  );
83                  _tag.focus();                  return false;
84          },          },
85    
86          move_suggested: function( where ) {          move_suggested: function( where ) {
# Line 78  var _tag = { Line 95  var _tag = {
95                          $.log.error('move to invalid element '+to);                          $.log.error('move to invalid element '+to);
96                          return;                          return;
97                  }                  }
98                  var s = '#suggest li:nth('+c+')';                  var s = '#suggest a:nth('+c+')';
99                  $( s ).removeClass('selected');                  $( s ).removeClass('selected');
100                  $.log.debug('remove selected from '+s);                  $.log.debug('remove selected from '+s);
101                  s = '#suggest li:nth('+to+')';                  s = '#suggest a:nth('+to+')';
102                  $( s ).addClass('selected');                  $( s ).addClass('selected');
103                  $.log.debug('add selected to '+s);                  $.log.debug('add selected to '+s);
104                  _tag.current = to;                  _tag.current = to;
# Line 100  var _tag = { Line 117  var _tag = {
117  $(document).ready( function() {  $(document).ready( function() {
118    
119          $('.tag').each( function(i) {          $('.tag').each( function(i) {
120                  _tag.name[i] = this.firstChild.nodeValue;                  var n = this.firstChild.nodeValue;
121                    _tag.name[i] = n;
122                  _tag.obj[i] = this;                  _tag.obj[i] = this;
123                    this.onclick = function() {
124                            return _tag.add_tag( n );
125                    }
126          });          });
127          $.log.info( 'found ' + _tag.name.length + ' tags' );          $.log.info( 'found ' + _tag.name.length + ' tags' );
128    
# Line 115  $(document).ready( function() { Line 136  $(document).ready( function() {
136                                  e.preventDefault();                                  e.preventDefault();
137                                  _tag.move_suggested( -1 );                                  _tag.move_suggested( -1 );
138                                  return false;                                  return false;
                                 break;  
139                          case 40:        // down                          case 40:        // down
140                                  e.preventDefault();                                  e.preventDefault();
141                                  _tag.move_suggested( +1 );                                  _tag.move_suggested( +1 );
142                                  return false;                                  return false;
                                 break;  
143                          case 9:         // tab                          case 9:         // tab
144                          case 13:        // return                          case 13:        // return
145                                    if (_tag.current != null) _tag.focus();
146                                  e.preventDefault();                                  e.preventDefault();
                                 _tag.take_suggested();  
   
147                                  return false;                                  return false;
                                 break;  
148                  }                  }
149    
150    
# Line 146  $(document).ready( function() { Line 163  $(document).ready( function() {
163                  return true;                  return true;
164          }).submit( function() {          }).submit( function() {
165                  $.log.debug('submit');                  $.log.debug('submit');
166                  if (_tag.current == null) {                  return _tag.take_suggested();
                         _tag.clean_selected();  
                         return true;  
                 } else {  
                         return false;  
                 }  
167          }).blur( function() {          }).blur( function() {
168                  $.log.debug('blur');                  $.log.debug('blur');
169                  _tag.clean_selected();                  return _tag.take_suggested();
                 if (_tag.current == null) {  
                         return true;  
                 } else {  
                         _tag.focus();  
                         return false;  
                 }  
170          });          });
171    
172          $.log.toggle();          $.log.toggle();

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

  ViewVC Help
Powered by ViewVC 1.1.26