v 0.2 adds sparkles a bit everywhere where stats apply and fix the style of the graph
[FlickrHacks.git] / _greasemonkey_tools_ / FlickrMenu.js
blobee26ca2dff55814cc74cb62db8896393819c919b
1 //======================================================================
2 //                         Hack the Gamma menus
3 //                         make your own insertion/submenus, etc
4 // 
5 // you will need the FlickrLocaliser for this to work properly.
6 //
7 // see the flickrmoremenus.user.js script for a longuer example.
8 //======================================================================
11 Example:
12 var menutool = new FlickrGammaMenu();
14 //1- insert a menu with subitems:
15 var userID = ...;
16 var yourphotos = 
17                                 menutool.createMenuLink('http://www.flickr.com/photos/'+userId,"Your Photos",false,true)+
18                                 menutool.createMenuLink('http://www.flickr.com/photos/'+userId+'/popular-interesting/',"Interesting Popular",true,false)+
19                                 menutool.insertMenu(yourphotos,'candy_nav_menu_you',"Your Photos",'A Sub Menu ...',true);
21 //2- insert directly a menu item:
22 menutool.insertItem("http://www.flickr.com/people/"+this.userId+"/contacts/rev/",'candy_nav_menu_contacts',"People Search","Reverse Contacts",false,true);
26 //version 0.1
27 //release 14 August 2007
28 //author: Pierre Andrews
30 // --------------------------------------------------------------------
31 // Copyright (C) 2007 Pierre Andrews
32 // This script can be redistributed under the terms of the GNU LGPL, without
33 // modification of this licence and copyright notice. Attribution to the author should be
34 // kept at least in the source of the scripts.
35 // 
36 // This program is free software; you can redistribute it and/or
37 // modify it under the terms of the GNU Lesser General Public License
38 // as published by the Free Software Foundation; either version 2
39 // of the License, or (at your option) any later version.
40 // 
41 // This program is distributed in the hope that it will be useful,
42 // but WITHOUT ANY WARRANTY; without even the implied warranty of
43 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44 // GNU General Public License for more details.
45 // 
46 // The GNU General Public License is available by visiting
47 //   http://www.gnu.org/copyleft/lgpl.html
48 // or by writing to
49 //   Free Software Foundation, Inc.
50 //   51 Franklin Street, Fifth Floor
51 //   Boston, MA  02110-1301
52 //   USA
56 var FlickrGammaMenu = function() {
60 FlickrGammaMenu.prototype = {
61         mapper: new FlickrLocaliser({
62                 'en-us' : {
63                         'Your Photos' : 'Your Photos',
64                                 "Contact List" : "Contact List",
65                                 'People Search' : 'People Search',
66                                 'FlickrMail' : 'FlickrMail',
67                                 'Your Archives' : 'Your Archives',
68                                 'Your Sets' : 'Your Sets',
69                                 'Calendar' : 'Calendar'
70                                 },
71                         'fr-fr' : {
72                                 'Your Photos' : 'Vos photos',
73                                         "Contact List" : "Liste de contacts",
74                                         'People Search' : 'Recherche de personnes',
75                                         'FlickrMail' : 'FlickrMail',
76                                         'Your Archives' : 'Vos archives',
77                                         'Your Sets' : 'Vos albums',
78                                         'Calendar' : 'Calendrier'
79                                         },
80                                 'it-it' : {
81                                         'Your Photos' : 'Le tue foto',
82                                                 "Contact List" : "Lista contatti",
83                                                 'People Search' : 'Ricerca di persone',
84                                                 'FlickrMail' : 'FlickrMail',
85                                                 'Your Archives' : 'I tuoi archivi',
86                                                 'Your Sets' : 'I tuoi set',
87                                                 'Calendar' : 'Calendario'
88                                                 },
89                                         'de-de' : {
90                                                 'Your Photos' : 'Ihre Fotos',
91                                                         "Contact List" : "Kontaktliste",
92                                                         'People Search' : 'Benutzer suchen',
93                                                         'FlickrMail' : 'FlickrMail',
94                                                         'Your Archives' : 'Ihre Archive',
95                                                         'Your Sets' : 'Ihre Alben',
96                                                         'Calendar' : 'Kalender'
97                                                         },
98                                                 'es-us' : {
99                                                         'Your Photos' : 'Tus fotos',
100                                                                 "Contact List" : "Lista de contactos",
101                                                                 'People Search' : 'Búsqueda de personas',
102                                                                 'FlickrMail' : 'Flickrcorreo',
103                                                                 'Your Archives' : 'Tus archivos',
104                                                                 'Your Sets' : 'Tus Ã¡lbumes ',
105                                                                 'Calendar' : 'Calendario'
106                                                                 },
107                                                         'pt-br' : {
108                                                                 'Your Photos' : 'Fotos',
109                                                                         "Contact List" : "Lista de contatos",
110                                                                         'People Search' : 'Busca de pessoas',
111                                                                         'FlickrMail' : 'E-mail do Flickr',
112                                                                         'Your Archives' : 'Arquivos',
113                                                                         'Your Sets' : 'Álbuns',
114                                                                         'Calendar' : 'Calendário'
115                                                                         },
116                                                                 'ko-kr' : {
117                                                                         'Your Photos' : '내 ì‚¬ì§„',
118                                                                                 "Contact List" : "이웃 ëª©ë¡",
119                                                                                 'People Search' : '사람 ì°¾ê¸°',
120                                                                                 'FlickrMail' : 'FlickrMail',
121                                                                                 'Your Archives' : '지난글 ë³´ê¸°',
122                                                                                 'Your Sets' : '세트',
123                                                                                 'Calendar' : '달력'
124                                                                                 },
125                                                                         'zh-hk' : {
126                                                                                 'Your Photos' : '你的相片',
127                                                                                         "Contact List" : "自己人名冊",
128                                                                                         'People Search' : '搜尋用戶',
129                                                                                         'FlickrMail' : 'FlickrMail',
130                                                                                         'Your Archives' : '你的資料庫',
131                                                                                         'Your Sets' : '你的相片集',
132                                                                                         'Calendar' : '日曆',
133                                                                                         },
134                                                                                 defaultLang: 'en-us'
135                                                                                                                  }),
137         //insert a new menu item in on of the main menus
138         // href the link on that element or a javascript function to call
139         // menu is the id of the main menu where to insert the new menu item (e.g. 'candy_nav_menu_you')
140         // item is the item "title" before which to insert the new menu item (or to replacE) (e.g. 'Your Sets')
141         // title is the title of your new item
142         // replace is a boolean to know if we replace 'item' or just add a new one
143         //
144         //returns: the a element created
145         insertItem: function(href,menu,item,title,replace,line_above) {
147                 var menu_you = document.getElementById(menu);
148                 var you_a = menu_you.getElementsByTagName('a');
149                 var your_set = '';      
150                 item = this.mapper.localise(item);
151                 for(var i=0;i<you_a.length;i++) {
152                         if( you_a[i].innerHTML == item ) {
153                                 your_set = you_a[i];
154                                 break;
155                         }
156                 }
158                 if(!your_set) {
159                         GM_log('impossible to find insertion point');
160                         return;
161                 }
163                 var batch = document.createElement('a');
164                 if(typeof(href) == "function") {
165                         batch.addEventListener("click",href,true);
166                         batch.href = 'javascript:;';
167                 } else
168                 batch.href = href;
169                 batch.innerHTML = title;
170                 if(line_above) batch.className = "menu_item_line_above";
171                 your_set.parentNode.insertBefore(batch, your_set);              
172                 if(replace) your_set.parentNode.removeChild(your_set);
173                         
174                 return batch;                   
175         },
177         //remove a menu item
178         // menu is the id of the main menu
179         // item is the item innerHTML
180         //returns: the element removed
181         removeItem: function(menu,item) {
182                 var menu_you = document.getElementById(menu);
183                 var you_a = menu_you.getElementsByTagName('a');
184                 var your_set = '';
185                 for(var i=0;i<you_a.length;i++) {
186                         if( you_a[i].innerHTML == item ) {
187                                 your_set = you_a[i];
188                                 break;
189                         }
190                 }
191                 if(!your_set) {
192                         GM_log('impossible to find insertion point');
193                         return;
194                 }
195                 your_set.parentNode.removeChild(your_set);
196                 return your_set;
197         },
199         createMenuLink: function(href,title,line_above,first) {
200                 return '<a '+((first)?' style="padding-top:3px;"':'')+((line_above)?' class="menu_item_line_above"':'')+'" href="'+href+'">'+title+'</a>\n'
201         },
202                 
203         //insert a new menu:
204         // innerHTML is the content of the menu (you should create that with createMenuLink calls)
205         // menu is the id of the main menu where to insert the new menu item (e.g. 'candy_nav_menu_you')
206         // item is the item "title" before which to insert the new menu item (or to replacE) (e.g. 'Your Sets')
207         // title is the title of your new item
208         // replace is a boolean to know if we replace 'item' or just add a new one
209         insertMenu: function(innerHTML,menu,item,title,replace) {
210                         
211                 // insert pulldown menu, from .CK super batch edit script
212                 var menu_you = document.getElementById(menu);
213                 var you_a = menu_you.getElementsByTagName('a');
214                 var your_set = '';
215                 if(replace) item = this.mapper.localise(item);
216                 for(var i=0;i<you_a.length;i++) {
217                         if( you_a[i].innerHTML == item ) {
218                                 your_set = you_a[i];
219                                 break;
220                         }
221                 }
223                 if(!your_set) {
224                         GM_log('impossible to find insertion point');
225                         return;
226                 }
227                 var onclickHandler1 = function() {
228                         if( batch.clickat == 'body' ) {
229                                 batch.clickat = null;
230                                 return;
231                         }
232                         if( b_menu.style.display == 'none' ) {
233                                 b_menu.style.display = 'inline';
234                         } else {
235                                 b_menu.style.display = 'none';
236                         }
237                 }
238                 var batch = this.insertItem(onclickHandler1,menu,item,title,replace);
239                 var b_menu = document.createElement('div');
240                         
241                 batch.clickat = null;
242                 batch.onclickHandler1 = onclickHandler1;
243                 batch.onclickHandler2 = function() {
244                         batch.removeEventListener('click', batch.onclickHandler2, true);
245                         batch.addEventListener('click', batch.onclickHandler1, true);
246                         b_menu.style.display = 'none';
247                         batch.status = false;
248                 }
249                 batch.onclickHandler3 = function() {
250                         b_menu.style.display = 'none';
251                 }
252                 b_menu.style.display = 'none';
253                 b_menu.style.left = '70px';
254                 b_menu.style.marginTop = '-19px';
255                 b_menu.className = 'candy_menu';
256                 b_menu.innerHTML = innerHTML;
258                 batch.parentNode.insertBefore(b_menu, batch.nextSibling);                       
259                         
260                 document.body.addEventListener('click', 
261                                                                            function() {
262                         if( b_menu.style.display == 'inline' ) {
263                                 b_menu.style.display = 'none';
264                                 batch.clickat = 'body';
265                         } else batch.clickat = null;
266                 }, true);
268         }