MCPcopy Create free account
hub / github.com/unconed/TermKit / updateState

Function updateState

HTML/tokenfield/autocomplete.js:79–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

77
78 // Update state.
79 function updateState() {
80 // Highlight active line, if any,
81 if (that.items.length) {
82 // Remove token badge.
83 that.token.style = '';
84
85 // Insert lines into box.
86 var prefix = that.prefix;
87 $e.empty();
88 $.each(that.items, function () {
89 $e.append($('<span>').addClass("line").addClass("style-" + this.type).html('<span class="prefix">' + escapeText(prefix) +'</span><span>'+ escapeText(this.label.substring(prefix.length)) +'</span>'));
90 });
91 $e.show();
92
93 that.selected = (that.selected + that.items.length) % that.items.length;
94 var $line = $($e.find('.line')[that.selected]);
95
96 // Move caret element to active line.
97 var offsetY = -$line.addClass('active').position().top;
98 //this.caret.$element.find('input').css('marginTop', offsetY);
99 that.$element.stop().css({
100 marginTop: that.animateTarget,
101 })
102 .animate({ 'marginTop': offsetY }, {
103 duration: 40 + Math.max(Math.abs(offsetY - that.animateTarget) / 10, 0),
104 queue: false,
105 });
106 that.animateTarget = offsetY;
107
108 // Style caret to match line.
109 that.caret && that.caret.$input.removeClass().addClass('style-' + that.items[that.selected].type);
110 }
111 else {
112 $e.empty().hide();
113 }
114
115 // No matches, remove..
116 if (that.items.length == 0) {
117 that.token.style = '';
118 that.remove();
119 }
120 // Instant-apply single item popup if it matches what was typed.
121 else if (that.items.length == 1 && that.items[0].label == prefix) {
122 that.onComplete(event || {}, true);
123 }
124 }
125
126 // Get list of suggestions.
127 if (!local && this.handler && this.token) {

Callers 1

autocomplete.jsFile · 0.85

Calls 2

$Function · 0.85
escapeTextFunction · 0.85

Tested by

no test coverage detected