Author: wjohnald
Date: 2010-09-03 15:42:27 +0200 (Fri, 03 Sep 2010)
New Revision: 30817

Modified:
   plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js
Log:
InlineTaggableWidget: performance enhancements, code readability enhancements, 
and moved functionality for unsetting existing popular tags to this script.

Modified: plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js
===================================================================
--- plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js    
2010-09-03 13:37:47 UTC (rev 30816)
+++ plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js    
2010-09-03 13:42:27 UTC (rev 30817)
@@ -138,6 +138,18 @@
        {       
                var popularTags = options['popular-tags'];
                var existingTags = options['existing-tags'];
+
+               // We don't want to display popular tags that we're already 
using
+               var unusedPopulars = {};
+               for (x in popularTags)
+               {
+                       if (typeof(existingTags[x]) == 'undefined')
+                       {
+                               unusedPopulars[x] = popularTags[x];
+                       }
+               }
+               
+               
                var popularsAttributes = {};
                var existingTagsAttributes = {};
                var existingDiv = $('<div />');
@@ -186,6 +198,7 @@
                        
                        link.remove();
                        
+                       // As we have just removed it from the list, we want 
the real deal populars.
                        if (typeof(popularTags[tag]) != 'undefined')
                        {
                                var linkLabel = tag + ' - ' + popularTags[tag];
@@ -208,7 +221,7 @@
                
                        var attributes = {};
                        for (x in tagArray)
-                       {
+                       {       
                                var linkLabel = '';
                                if (linkLabelType == 'add')
                                {
@@ -220,16 +233,7 @@
                                }
                                
                                var new_link = makeLink(linkAttributes, x, 
linkLabel);
-                               
-                               if (linkLabelType == 'add')
-                               {
-                                       new_link.bind('click', function() { 
addTagsToForm($(this));  return false; });
-                               }
-                               else if (linkLabelType == 'remove')
-                               {
-                                       new_link.bind('click', function() { 
removeTagsFromForm($(this));  return false; });
-                               }
-                               
+                                                               
                                tagContainer.append(new_link);
                        }
                        return tagContainer;
@@ -260,9 +264,11 @@
        
 
                existingDiv = makeTagContainer('Existing Tags', existingTags, 
existingTagsAttributes, 'remove');
+               existingDiv.children('a').bind('click', function() { 
removeTagsFromForm($(this));  return false; });
                tagInput.parent().prepend(existingDiv);
                
-               popularsDiv = makeTagContainer('Popular Tags', popularTags, 
popularsAttributes, 'add');
+               popularsDiv = makeTagContainer('Popular Tags', unusedPopulars, 
popularsAttributes, 'add');
+               popularsDiv.children('a').bind('click', function() { 
addTagsToForm($(this));  return false; });
                tagInput.parent().append(popularsDiv);
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to