#7355 closed task (fixed)
Deprecate suggest.js code
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | lowest | Milestone: | 1.0 |
Component: | general | Version: | 0.12dev |
Severity: | trivial | Keywords: | suggest.js anydiff |
Cc: | Thijs Triemstra | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Although, trac itself does not make use of such a feature, I propose the following changes on suggest.js
:
-
htdocs/js/suggest.js
old new 56 56 57 57 function hide() { 58 58 if (timeout) clearTimeout(timeout); 59 input.removeClass("loading");60 59 if (results) { 61 60 results.fadeOut("fast").remove(); 62 61 results = null; … … 76 75 function select(li) { 77 76 if (!li) li = $("<li>"); 78 77 else li = $(li); 79 var val = $.trim(li. text());78 var val = $.trim(li.attr('realvalue') || li.text()); 80 79 prev = val; 81 80 input.val(val); 82 81 hide(); … … 88 87 if (val == prev) return; 89 88 prev = val; 90 89 if (val.length < minChars) { hide(); return; } 91 input.addClass("loading"); 90 // Attach the input class tweaks right into the ajax callbacks 91 $(input).ajaxStart(function() {$(this).addClass('loading')}); 92 $(input).ajaxComplete(function() {$(this).removeClass('loading')}); 93 92 94 var params = {}; 93 95 params[paramName] = val; 94 96 $.get(url, params, function(data) {
What the following allows is to pass several html elements to display additional info while still allowing a specific value to the put on the input element.
Consider the following <ul>
:
<ul> <li realvalue="pt_PT"> <b>pt_PT</b><br/> <em>português (Portugal) (Portugal)<br/> Portuguese (Portugal)</em> </li> <li realvalue="pt"> <b>pt</b><br/> <em>português<br/> Portuguese</em> </li> <li realvalue="pt_BR"> <b>pt_BR</b><br/> <em>português (Brasil)<br/> Portuguese (Brazil)</em> </li> </ul>
What's added to the <input/>
is realvalue
, yet, what's shown to the user has additional info.
Also, with this patch, the css class tweaking is attached to jQuery's ajax callbacks, providing additional and removal of class on the actual ajax calls, not somewhere near(in time).
I also started by saying that trac does not yet make use of this, but a plug I'm coding needs this; it's just a matter of not loading yet another js file in future releases, and providing some js also useful for plugins and not just trac.
Attachments (0)
Change History (10)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Final change on patch:
-
htdocs/js/suggest.js
old new 56 56 57 57 function hide() { 58 58 if (timeout) clearTimeout(timeout); 59 input.removeClass("loading");60 59 if (results) { 61 60 results.fadeOut("fast").remove(); 62 61 results = null; … … 76 75 function select(li) { 77 76 if (!li) li = $("<li>"); 78 77 else li = $(li); 79 var val = $.trim(li. text());78 var val = $.trim(li.attr('realvalue') || li.text()); 80 79 prev = val; 81 80 input.val(val); 82 81 hide(); … … 89 88 prev = val; 90 89 if (val.length < minChars) { hide(); return; } 91 90 input.addClass("loading"); 91 input.ajaxComplete( function() { input.removeClass("loading"); }); 92 92 var params = {}; 93 93 params[paramName] = val; 94 94 $.get(url, params, function(data) {
Why? Because if you have more than a single input where suggest is enabled, when sugest has run for more than one input, afterwards, all those inputs will have their classes tweaked. So, now, we add the classes ourselves, but removal works ok if attached to the callbacks, only attaching to .ajaxStart
or .ajaxSend
does not work, or I did not do it correctly.
comment:3 by , 14 years ago
Cc: | added |
---|---|
Keywords: | review added |
Milestone: | next-major-0.1X → 0.12.2 |
Summary: | suggest.js enhancement → [PATCH] suggest.js enhancement |
This patch needs a review
comment:4 by , 14 years ago
Milestone: | 0.12.2 → 0.13 |
---|
comment:5 by , 14 years ago
Keywords: | review removed |
---|---|
Severity: | trivial → minor |
Summary: | [PATCH] suggest.js enhancement → Deprecate suggest.js code |
Type: | enhancement → task |
comment:6 by , 14 years ago
Cc: | added; removed |
---|
comment:8 by , 13 years ago
Milestone: | next-stable-1.0.x → 1.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Deprecation warning added in r11081.
At some point in 1.1.x, we'll use more of jquery-ui…
comment:9 by , 13 years ago
Owner: | changed from | to
---|---|
Severity: | minor → trivial |
comment:10 by , 9 years ago
Keywords: | suggest.js anydiff added |
---|
#12169 created for replacing suggest.js
.
Sorry, the correct patch is:
htdocs/js/suggest.js
input.removeClass("loading");text());Changed lines are:
Callbacks must be attached to
input
notthis
, else, all inputs which are suggest enabled, will have their classes tweaked.