2 /***************************************************************************
3 Copyright (c) 2005 - 2010 Marcus Campbell
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************/
21 $tagservice =& ServiceFactory::getServiceInstance('TagService');
22 $userservice =& ServiceFactory::getServiceInstance('UserService');
24 $logged_on_userid = $userservice->getCurrentUserId();
26 $userPopularTags =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid);
27 $userAllTags =& $tagservice->getPopularTags($logged_on_userid, 10000, $logged_on_userid);
28 $userPopularTagsCloud =& $tagservice->tagCloud($userPopularTags, 5, 90, 175);
29 $userPopularTagsCount = count($userPopularTags);
31 if ($userPopularTagsCount > 0) {
34 <script type="text/javascript">
35 Array.prototype.contains = function (ele) {
36 for (var i = 0; i < this.length; i++) {
44 Array.prototype.remove = function (ele) {
45 var arr = new Array();
47 for (var i = 0; i < this.length; i++) {
56 function addonload(addition) {
57 var existing = window.onload;
58 window.onload = function () {
66 var taglist = document.getElementById('tags');
67 var tags = taglist.value.split(', ');
69 var populartags = document.getElementById('popularTags').getElementsByTagName('span');
71 for (var i = 0; i < populartags.length; i++) {
72 if (tags.contains(populartags[i].innerHTML)) {
73 populartags[i].className = 'selected';
79 function addTag(ele) {
80 var thisTag = ele.innerHTML;
81 var taglist = document.getElementById('tags');
82 var tags = taglist.value.split(', ');
84 // If tag is already listed, remove it
85 if (tags.contains(thisTag)) {
86 tags = tags.remove(thisTag);
87 ele.className = 'unselected';
91 tags.splice(0, 0, thisTag);
92 ele.className = 'selected';
95 taglist.value = tags.join(', ');
97 document.getElementById('tags').focus();
100 document.write('<div class="collapsible">');
101 document.write('<h3><?php echo T_('Popular Tags'); ?><\/h3>');
102 document.write('<p id="popularTags" class="tags">');
106 foreach(array_keys($userPopularTagsCloud) as $key) {
107 $row =& $userPopularTagsCloud[$key];
108 $entries = T_ngettext('bookmark', 'bookmarks', $row['bCount']);
109 $taglist .= '<span title="'. $row['bCount'] .' '. $entries .'" style="font-size:'. $row['size'] .'" onclick="addTag(this)">'. filter($row['tag']) .'<\/span> ';
113 document.write('<?php echo $taglist ?>');
114 document.write('<\/p>');
115 document.write('<\/div>');
117 var availableTags = [
120 foreach(array_keys($userAllTags) as $key) {
121 print '"'.$userAllTags[$key]['tag'].'",'."\n";
125 function split( val ) {
126 return val.split( /,\s*/ );
128 function extractLast( term ) {
129 return split( term ).pop();
133 // don't navigate away from the field on tab when selecting an item
134 .bind( "keydown", function( event ) {
135 if ( event.keyCode === $.ui.keyCode.TAB &&
136 $( this ).data( "autocomplete" ).menu.active ) {
137 event.preventDefault();
142 source: function( request, response ) {
143 // delegate back to autocomplete, but extract the last term
144 response( $.ui.autocomplete.filter(
145 availableTags, extractLast( request.term ) ) );
148 // prevent value inserted on focus
151 select: function( event, ui ) {
152 var terms = split( this.value );
153 // remove the current input
155 // add the selected item
156 var newterm = ui.item.value;
157 terms.push( newterm );
159 $("#popularTags").children().each(function() {
160 if (this.innerHTML == newterm) {
161 this.className = 'selected';
164 // add placeholder to get the comma-and-space at the end
166 this.value = terms.join( ", " );