/[jquery]/tag_complete/jquery-tac.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/jquery-tac.js

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

revision 54 by dpavlin, Sun Aug 20 03:35:32 2006 UTC revision 58 by dpavlin, Sun Aug 20 23:23:29 2006 UTC
# Line 33  function tac( Line 33  function tac(
33          this.suggest_selector = '#suggest';          this.suggest_selector = '#suggest';
34          this.tags_input = '#tags';          this.tags_input = '#tags';
35    
36          // tags from previous event          // all tags from previous event
37          this.last_tags = '';          this.last_tags = '';
38            // just last tag
39            this.last_tag = '';
40    
41          // parse all tags from html          // parse all tags from html
42          var obj = this;          var obj = this;
# Line 57  function tac( Line 59  function tac(
59    
60                  $.log.debug('keyup: '+e.keyCode);                  $.log.debug('keyup: '+e.keyCode);
61    
62                    var ret = true;
63    
64                  switch (e.keyCode) {                  switch (e.keyCode) {
65                          case 38:        // up                          case 38:        // up
66                                  e.preventDefault();                                  e.preventDefault();
# Line 67  function tac( Line 71  function tac(
71                                  obj.move_suggested( +1 );                                  obj.move_suggested( +1 );
72                                  return false;                                  return false;
73                          case 9:         // tab                          case 9:         // tab
74                                    obj.focus();
75                                    obj.take_suggested();
76                                    return false;
77                          case 13:        // return                          case 13:        // return
78                                  if (obj.current_selected != null) obj.focus();                                  if (obj.current_selected != null) obj.focus();
79                                  e.preventDefault();                                  return true;
                                 return false;  
80                          case 8:         // backspace                          case 8:         // backspace
81                          case 46:        // del                          case 46:        // del
82                                  obj.parse();                                  ret = false;
83                                  return false;                          case 37:        // left
84                            case 39:        // right
85                                    return true;
86                  }                  }
87    
88    
89                  var t = obj.current_tag();                  var t = obj.current_tag();
90    
91                    if (t == '') return false;
92    
93                  $.log.debug('tag: ' + t + ' ['+t.length+']');                  $.log.debug('tag: ' + t + ' ['+t.length+']');
94    
95                  obj.clean_suggested();                  obj.clean_suggested();
   
                 if (t == '') return false;  
   
96                  obj.suggest(t);                  obj.suggest(t);
97    
98                  return true;                  return ret;
99    
100          }).submit( function() {          }).submit( function() {
101                  $.log.debug('submit');                  $.log.debug('submit');
102                  return obj.take_suggested();                  return obj.take_suggested();
# Line 117  tac.prototype.suggest = function( partia Line 125  tac.prototype.suggest = function( partia
125    
126                          jQuery.className.add( this.t.obj[t], 'suggested' );                          jQuery.className.add( this.t.obj[t], 'suggested' );
127    
128                          suggest += '<a href="#'+i+'"';                          suggest += '<a href="#"';
129                          if (this.suggested.length == 0) suggest += ' class="suggested" ';                          if (this.suggested.length == 0) suggest += ' class="suggested" ';
130                          suggest += ' onclick="javascript:return this.tag(\'' + t + '\')">' +                          suggest += '">' + t + '</a> ';
                                 t + '</a> ';  
131                          this.suggested.push(t);                          this.suggested.push(t);
132                  }                  }
133          }          }
134    
135          $(this.suggest_selector).html( suggest );          $(this.suggest_selector).html( suggest );
136            var obj = this;
137            $(this.suggest_selector+' a').click( function() {
138                    var t = this.firstChild.nodeValue;
139                    $.log.debug('click add: '+ t);
140                    obj.clean_suggested();
141                    obj.add_tag( t );
142            });
143          this.current_suggested = 0;          this.current_suggested = 0;
144          $.log.info('suggested ' + this.suggested.length + ' tags');          $.log.info('suggested ' + this.suggested.length + ' tags');
145    
# Line 161  tac.prototype.take_suggested = function( Line 175  tac.prototype.take_suggested = function(
175          }          }
176    
177          var i = this.suggested[c].i;          var i = this.suggested[c].i;
178          $.log.debug('take_suggested '+i+':'+s);          $.log.debug('take_suggested: '+s);
179          this.add_tag( s );          this.add_tag( s );
180          return false;          return false;
181  }  }
# Line 236  tac.prototype.remove_tag = function( t ) Line 250  tac.prototype.remove_tag = function( t )
250    
251          this.clean_suggested();          this.clean_suggested();
252    
253          var tags = this.entered.ordered.join(' ')+' ';          var tags = this.entered.ordered.join(' ');
254            if (tags.length) tags += ' ';
255          $.log.debug('removed '+o+' left: '+tags);          $.log.debug('removed '+o+' left: '+tags);
256          $(this.tags_input).val( tags );          $(this.tags_input).val( tags );
257          return false;          return false;
# Line 259  tac.prototype.parse = function() { Line 274  tac.prototype.parse = function() {
274    
275          var t = $(this.tags_input).val().replace(/^  */,'').replace(/  *$/,'').split(/ /);          var t = $(this.tags_input).val().replace(/^  */,'').replace(/  *$/,'').split(/ /);
276    
277            if (this.entered.ordered.length) $('.entered').removeClass('entered');
278            this.clean_suggested();
279    
280          this.entered = {          this.entered = {
281                  ordered: new Array(),                  ordered: new Array(),
282                  tag: new Array()                  tag: new Array()
283          };          };
284    
         if (this.entered.ordered.length) $('.entered').removeClass('entered');  
   
285          var debug = '';          var debug = '';
286          for (var i = 0; i < t.length; i++) {          for (var i = 0; i < t.length; i++) {
287                  var tag = t[i];                  var tag = t[i];
# Line 279  tac.prototype.parse = function() { Line 295  tac.prototype.parse = function() {
295                  }                  }
296          }          }
297          $.log.debug('parsed '+debug+' to '+this.entered.ordered.join(','));          $.log.debug('parsed '+debug+' to '+this.entered.ordered.join(','));
   
298  }  }
299    
300  tac.prototype.current_tag = function() {  tac.prototype.current_tag = function() {
# Line 288  tac.prototype.current_tag = function() { Line 303  tac.prototype.current_tag = function() {
303                  this.last_tags = tags;                  this.last_tags = tags;
304                  this.parse();                  this.parse();
305          }          }
306          return tags.replace(/^([^ ][^ ]* )*/, '');          var last_tag = tags.replace(/^([^ ][^ ]* )*/, '');
307            if (last_tag != this.last_tag) {
308                    this.last_tag = last_tag;
309                    return last_tag;
310            } else {
311                    this.parse();
312                    return '';
313            }
314  }  }
315    
316  tac.prototype.focus = function() {  tac.prototype.focus = function() {

Legend:
Removed from v.54  
changed lines
  Added in v.58

  ViewVC Help
Powered by ViewVC 1.1.26