Edgewall Software
Modify

Opened 16 years ago

Closed 12 years ago

Last modified 9 years ago

#7355 closed task (fixed)

Deprecate suggest.js code

Reported by: Pedro Algarvio, aka, s0undt3ch <ufs@…> 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  
    5656
    5757    function hide() {
    5858      if (timeout) clearTimeout(timeout);
    59       input.removeClass("loading");
    6059      if (results) {
    6160        results.fadeOut("fast").remove();
    6261        results = null;
     
    7675    function select(li) {
    7776      if (!li) li = $("<li>");
    7877      else li = $(li);
    79       var val = $.trim(li.text());
     78      var val = $.trim(li.attr('realvalue') || li.text());
    8079      prev = val;
    8180      input.val(val);
    8281      hide();
     
    8887      if (val == prev) return;
    8988      prev = val;
    9089      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
    9294      var params = {};
    9395      params[paramName] = val;
    9496      $.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 Pedro Algarvio, aka, s0undt3ch <ufs@…>, 16 years ago

Sorry, the correct patch is:

  • htdocs/js/suggest.js

    old new  
    5656
    5757    function hide() {
    5858      if (timeout) clearTimeout(timeout);
    59       input.removeClass("loading");
    6059      if (results) {
    6160        results.fadeOut("fast").remove();
    6261        results = null;
     
    7675    function select(li) {
    7776      if (!li) li = $("<li>");
    7877      else li = $(li);
    79       var val = $.trim(li.text());
     78      var val = $.trim(li.attr('realvalue') || li.text());
    8079      prev = val;
    8180      input.val(val);
    8281      hide();
     
    8887      if (val == prev) return;
    8988      prev = val;
    9089      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() {$(input).addClass('loading')});
     92      $(input).ajaxComplete(function() {$(input).removeClass('loading')});
     93
    9294      var params = {};
    9395      params[paramName] = val;
    9496      $.get(url, params, function(data) {

Changed lines are:

$(input).ajaxStart(function() {$(input).addClass('loading')});
$(input).ajaxComplete(function() {$(input).removeClass('loading')});

Callbacks must be attached to input not this, else, all inputs which are suggest enabled, will have their classes tweaked.

comment:2 by Pedro Algarvio, aka, s0undt3ch <ufs@…>, 16 years ago

Final change on patch:

  • htdocs/js/suggest.js

    old new  
    5656
    5757    function hide() {
    5858      if (timeout) clearTimeout(timeout);
    59       input.removeClass("loading");
    6059      if (results) {
    6160        results.fadeOut("fast").remove();
    6261        results = null;
     
    7675    function select(li) {
    7776      if (!li) li = $("<li>");
    7877      else li = $(li);
    79       var val = $.trim(li.text());
     78      var val = $.trim(li.attr('realvalue') || li.text());
    8079      prev = val;
    8180      input.val(val);
    8281      hide();
     
    8988      prev = val;
    9089      if (val.length < minChars) { hide(); return; }
    9190      input.addClass("loading");
     91      input.ajaxComplete( function() { input.removeClass("loading"); });
    9292      var params = {};
    9393      params[paramName] = val;
    9494      $.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 Thijs Triemstra <lists@…>, 13 years ago

Cc: lists@… added
Keywords: review added
Milestone: next-major-0.1X0.12.2
Summary: suggest.js enhancement[PATCH] suggest.js enhancement

This patch needs a review

comment:4 by Christian Boos, 13 years ago

Milestone: 0.12.20.13

I don't think it's adequate to extend the suggest.js code, as this will be replaced by jQueryUI autocomplete (#9643).

So I'd rather not take the patch and mark suggest.js as deprecated in 0.13 and to be removed in 0.14.

comment:5 by Thijs Triemstra <lists@…>, 13 years ago

Keywords: review removed
Severity: trivialminor
Summary: [PATCH] suggest.js enhancementDeprecate suggest.js code
Type: enhancementtask

comment:6 by Thijs Triemstra, 13 years ago

Cc: Thijs Triemstra added; lists@… removed

comment:7 by Remy Blank, 12 years ago

Milestone: 1.01.0-triage

Preparing for 1.0.

comment:8 by Christian Boos, 12 years ago

Milestone: next-stable-1.0.x1.0
Resolution: fixed
Status: newclosed

Deprecation warning added in r11081.

At some point in 1.1.x, we'll use more of jquery-ui…

comment:9 by Christian Boos, 12 years ago

Owner: changed from Jonas Borgström to Christian Boos
Severity: minortrivial

comment:10 by Ryan J Ollos, 9 years ago

Keywords: suggest.js anydiff added

#12169 created for replacing suggest.js.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.