/[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 57 by dpavlin, Sun Aug 20 17:25:13 2006 UTC revision 61 by dpavlin, Wed Aug 23 15:58:16 2006 UTC
# Line 16  function tac( Line 16  function tac(
16                  exists: new Array()                  exists: new Array()
17          };          };
18    
19            // all tags indexed by first letter
20          this.all_tags = new Array();          this.all_tags = new Array();
21          this.suggested = new Array();          this.suggested = new Array();
22    
# Line 33  function tac( Line 34  function tac(
34          this.suggest_selector = '#suggest';          this.suggest_selector = '#suggest';
35          this.tags_input = '#tags';          this.tags_input = '#tags';
36    
37          // tags from previous event          // all tags from previous event
38          this.last_tags = '';          this.last_tags = '';
39            // just last tag
40            this.last_tag = '';
41    
42          // parse all tags from html          // parse all tags from html
43          var obj = this;          var obj = this;
44          $( this.tags_selector ).each( function(i) {          $( this.tags_selector ).each( function(i) {
45                  var n = this.firstChild.nodeValue;                  var n = this.firstChild.nodeValue;
46                    var c = n.substr(0,1);
47    
48                  obj.t.obj[n] = this;                  obj.t.obj[n] = this;
49                  obj.t.exists[n] = true;                  obj.t.exists[n] = true;
50                  obj.all_tags.push( n );                  if (obj.all_tags[c] == null) {
51                            obj.all_tags[c] = new Array( n );
52                    } else {
53                            obj.all_tags[c].push( n );
54                    }
55    
56                  this.onclick = function() {                  this.onclick = function() {
57                          return obj.tag( n );                          return obj.tag( n );
58                  }                  }
59                  this.href = '#'+i;      // FIXME debug                  this.href = '#'+i;      // FIXME debug
60          });          });
61          $.log.info( 'found ' + this.all_tags.length + ' tags' );          $.log.info( 'found ' + this.t.obj.length + ' tags' );
62    
63          $.log.info( 'hook onchange to '+this.tags_form );          $.log.info( 'hook onchange to '+this.tags_form );
64          $( this.tags_form ).keyup( function(e) {          $( this.tags_form ).keyup( function(e) {
65    
66                  $.log.debug('keyup: '+e.keyCode);                  $.log.debug('keyup: '+e.keyCode);
67    
68                    var ret = true;
69    
70                  switch (e.keyCode) {                  switch (e.keyCode) {
71                          case 38:        // up                          case 38:        // up
72                                  e.preventDefault();                                  e.preventDefault();
# Line 75  function tac( Line 85  function tac(
85                                  return true;                                  return true;
86                          case 8:         // backspace                          case 8:         // backspace
87                          case 46:        // del                          case 46:        // del
88                                  obj.parse();                                  ret = false;
89                                  return false;                                  break;
90                            case 37:        // left
91                            case 39:        // right
92                                    return true;
93                  }                  }
94    
95    
96                  var t = obj.current_tag();                  var t = obj.current_tag();
97    
98                    if (t == '') return false;
99    
100                  $.log.debug('tag: ' + t + ' ['+t.length+']');                  $.log.debug('tag: ' + t + ' ['+t.length+']');
101    
102                  obj.clean_suggested();                  obj.clean_suggested();
   
                 if (t == '') return false;  
   
103                  obj.suggest(t);                  obj.suggest(t);
104    
105                  return true;                  return ret;
106    
107          }).submit( function() {          }).submit( function() {
108                  $.log.debug('submit');                  $.log.debug('submit');
109                  return obj.take_suggested();                  return obj.take_suggested();
# Line 112  tac.prototype.suggest = function( partia Line 125  tac.prototype.suggest = function( partia
125          var suggest = '';          var suggest = '';
126          this.suggested = new Array();          this.suggested = new Array();
127    
128          for(var i = 0; i < this.all_tags.length; i++) {          var c = partial.substr(0,1);
129                  var t = this.all_tags[i];  
130                  if ( t.substr(0, len) == partial ) {          for(var i = 0; i < this.all_tags[ c ].length; i++) {
131                          $.log.debug('suggested: ' + t );                  var t = this.all_tags[c][i];
132                    if ( t.substr(0, len) == partial && this.entered.tag[ t ] == null) {
133    
134                            //$.log.debug('suggested: ' + t );
135    
136                          jQuery.className.add( this.t.obj[t], 'suggested' );                          jQuery.className.add( this.t.obj[t], 'suggested' );
137    
# Line 268  tac.prototype.parse = function() { Line 284  tac.prototype.parse = function() {
284    
285          var t = $(this.tags_input).val().replace(/^  */,'').replace(/  *$/,'').split(/ /);          var t = $(this.tags_input).val().replace(/^  */,'').replace(/  *$/,'').split(/ /);
286    
287            if (this.entered.ordered.length) $('.entered').removeClass('entered');
288    
289          this.entered = {          this.entered = {
290                  ordered: new Array(),                  ordered: new Array(),
291                  tag: new Array()                  tag: new Array()
292          };          };
293    
         if (this.entered.ordered.length) $('.entered').removeClass('entered');  
   
294          var debug = '';          var debug = '';
295          for (var i = 0; i < t.length; i++) {          for (var i = 0; i < t.length; i++) {
296                  var tag = t[i];                  var tag = t[i];
# Line 288  tac.prototype.parse = function() { Line 304  tac.prototype.parse = function() {
304                  }                  }
305          }          }
306          $.log.debug('parsed '+debug+' to '+this.entered.ordered.join(','));          $.log.debug('parsed '+debug+' to '+this.entered.ordered.join(','));
   
307  }  }
308    
309  tac.prototype.current_tag = function() {  tac.prototype.current_tag = function() {
310          var tags = $(this.tags_input).val();          var tags = $(this.tags_input).val();
311            var t = this;
312          if (tags != this.last_tags) {          if (tags != this.last_tags) {
313                  this.last_tags = tags;                  this.last_tags = tags;
314                  this.parse();                  defer(function() { t.parse() }, 500, 'parse');
315            }
316            var last_tag = tags.replace(/^([^ ][^ ]* )*/, '');
317            if (last_tag != this.last_tag) {
318                    this.last_tag = last_tag;
319                    return last_tag;
320            } else {
321                    defer(function() { t.parse() }, 500, 'parse');
322                    return '';
323          }          }
         return tags.replace(/^([^ ][^ ]* )*/, '');  
324  }  }
325    
326  tac.prototype.focus = function() {  tac.prototype.focus = function() {

Legend:
Removed from v.57  
changed lines
  Added in v.61

  ViewVC Help
Powered by ViewVC 1.1.26