[Rt-commit] rt branch, 4.2/autocomplete-bind-on-demand, created. rt-4.1.19-7-g0f4e331

Thomas Sibley trs at bestpractical.com
Thu Aug 8 16:25:26 EDT 2013


The branch, 4.2/autocomplete-bind-on-demand has been created
        at  0f4e3314acd927b2955e39e1645dc7f9b916f5ec (commit)

- Log -----------------------------------------------------------------
commit f4fd1f2e8c800acf4f60b5f567dc8d26fc680ed7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 8 13:21:39 2013 -0700

    Add a CSS autocomplete class for Tickets
    
    … and a note to the regex so that it isn't missed in the future.
    
    This should have been part of 6375cfb.

diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index 21099c3..3524a66 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -2,7 +2,8 @@ jQuery(function() {
 
     var cssClassMap = {
         Users: 'user',
-        Groups: 'group'
+        Groups: 'group',
+        Tickets: 'tickets'
     };
 
     jQuery("input[data-autocomplete]").each(function(){
@@ -10,7 +11,7 @@ jQuery(function() {
         var what  = input.attr("data-autocomplete");
         var wants = input.attr("data-autocomplete-return");
 
-        if (!what || !what.match(/^(Users|Groups|Tickets)$/))
+        if (!what || !what.match(/^(Users|Groups|Tickets)$/)) // Did you update cssClassMap above?
             return;
 
         var queryargs = [];

commit 0f4e3314acd927b2955e39e1645dc7f9b916f5ec
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 8 13:23:09 2013 -0700

    Bestow the name of RT.Autocomplete.bind to the autocomplete registration function
    
    Dynamically added elements can have autocomplete inputs properly bound
    by calling:
    
        RT.Autocomplete.bind($containing_element)
    
    after they're added to the DOM.  At some point we may want to do this
    automatically, but for now manual binding is enough rope.

diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index 3524a66..3742a23 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -1,12 +1,14 @@
-jQuery(function() {
+if (!window.RT)              window.RT = {}
+if (!window.RT.Autocomplete) window.RT.Autocomplete = {}
 
+window.RT.Autocomplete.bind = function(from) {
     var cssClassMap = {
         Users: 'user',
         Groups: 'group',
         Tickets: 'tickets'
     };
 
-    jQuery("input[data-autocomplete]").each(function(){
+    jQuery("input[data-autocomplete]", from).each(function(){
         var input = jQuery(this);
         var what  = input.attr("data-autocomplete");
         var wants = input.attr("data-autocomplete-return");
@@ -14,6 +16,10 @@ jQuery(function() {
         if (!what || !what.match(/^(Users|Groups|Tickets)$/)) // Did you update cssClassMap above?
             return;
 
+        // Don't re-bind the autocompleter
+        if (input.data("ui-autocomplete"))
+            return;
+
         var queryargs = [];
         var options = {
             source: RT.Config.WebHomePath + "/Helpers/Autocomplete/" + what
@@ -79,4 +85,5 @@ jQuery(function() {
                     .appendTo( ul );
             };
     });
-});
+};
+jQuery(function(){ RT.Autocomplete.bind(document) });

-----------------------------------------------------------------------


More information about the Rt-commit mailing list