Merge branch 'extended-cookie'
[scuttle] / templates / dynamictags.inc.php
index 5a85143d0165029a46b673d3e85a539b56575844..d7f094a5d377f79602cd5319671d9dfbde85d5e4 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /***************************************************************************
-Copyright (C) 2005 - 2006 Scuttle project
-http://sourceforge.net/projects/scuttle/
+Copyright (c) 2005 - 2010 Marcus Campbell
 http://scuttle.org/
 
 This program is free software; you can redistribute it and/or modify
@@ -19,13 +18,14 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ***************************************************************************/
 
-$tagservice = & ServiceFactory :: getServiceInstance('TagService');
-$userservice = & ServiceFactory :: getServiceInstance('UserService');
+$tagservice  =& ServiceFactory::getServiceInstance('TagService');
+$userservice =& ServiceFactory::getServiceInstance('UserService');
 
 $logged_on_userid = $userservice->getCurrentUserId();
 
 $userPopularTags        =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid);
-$userPopularTagsCloud   =& $tagservice->tagCloud($userPopularTags, 5, 90, 175); 
+$userAllTags            =& $tagservice->getPopularTags($logged_on_userid, 10000, $logged_on_userid);
+$userPopularTagsCloud   =& $tagservice->tagCloud($userPopularTags, 5, 90, 175);
 $userPopularTagsCount   = count($userPopularTags);
 
 if ($userPopularTagsCount > 0) {
@@ -56,8 +56,8 @@ Array.prototype.remove = function (ele) {
 function addonload(addition) {
     var existing = window.onload;
     window.onload = function () {
-        existing();
-        addition();
+        existing;
+        addition;
     }
 }
 
@@ -113,8 +113,67 @@ foreach(array_keys($userPopularTagsCloud) as $key) {
 document.write('<?php echo $taglist ?>');
 document.write('<\/p>');
 document.write('<\/div>');
-</script>
 
+var availableTags = [
 <?php
+
+foreach(array_keys($userAllTags) as $key) {
+  print '"'.$userAllTags[$key]['tag'].'",'."\n";
+}
+?>
+];
+function split( val ) {
+  return val.split( /,\s*/ );
 }
-?>
\ No newline at end of file
+function extractLast( term ) {
+  return split( term ).pop();
+}
+
+$( "#tags" )
+  // don't navigate away from the field on tab when selecting an item
+  .bind( "keydown", function( event ) {
+    if ( event.keyCode === $.ui.keyCode.TAB &&
+        $( this ).data( "autocomplete" ).menu.active ) {
+      event.preventDefault();
+    }
+  })
+  .autocomplete({
+    minLength: 2,
+    delay: 50,
+    source: function( request, response ) {
+      // if the term is >2 in legth delegate back to autocomplete
+      if (extractLast ( request.term ).length < 3) {
+        response( [] );
+      } else {
+        response( $.ui.autocomplete.filter(
+          availableTags, extractLast( request.term ) ) );
+      }
+    },
+    focus: function() {
+      // prevent value inserted on focus
+      return false;
+    },
+    select: function( event, ui ) {
+      var terms = split( this.value );
+      // remove the current input
+      terms.pop();
+      // add the selected item
+      var newterm = ui.item.value;
+      terms.push( newterm );
+
+      $("#popularTags").children().each(function() {
+        if (this.innerHTML == newterm) {
+          this.className = 'selected';
+        }
+      });
+      // add placeholder to get the comma-and-space at the end
+      terms.push( "" );
+      this.value = terms.join( ", " );
+      return false;
+    }
+});
+
+
+</script>
+
+<?php } ?>

Benjamin Mako Hill || Want to submit a patch?