From 567bcb77d621e4a6605c8438027d5544f9484ece Mon Sep 17 00:00:00 2001 From: Jerry Jalava Date: Thu, 20 Dec 2007 15:01:28 +0200 Subject: [PATCH] Enhanced toolbar items. - Added posiibility add arguments to the callback function - By default the callback receivers toolbar item object which activated the callback - Added hide/show item methods --- js/ajatus.toolbar.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/js/ajatus.toolbar.js b/js/ajatus.toolbar.js index 54b0bf0..c41130d 100644 --- a/js/ajatus.toolbar.js +++ b/js/ajatus.toolbar.js @@ -86,6 +86,7 @@ ]; break; case 3: + case 4: icon = $.ajatus.preferences.client.theme_icons_url + arguments[1]; action = arguments[2]; item_obj['icon'] = icon; @@ -97,11 +98,21 @@ ]; break; } + + var extra_args = [item_obj]; + if (arguments.length == 4) { + $.each(arguments[3], function(i,n){ + extra_args.push(n); + }); + } + item_holder.createAppend( 'li', { className: 'item', id: item_obj.id }, item_content ); - $('li:last', item_holder).bind('click', action); + $('li:last', item_holder).bind('click', function(e){ + action.apply(action, extra_args); + }); if ($.ajatus.toolbar.settings.enable_clone) { var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']); @@ -110,7 +121,9 @@ 'li', { className: 'item', id: item_obj.id+'_clone' }, item_content ); - $('li:last', item_holder).bind('click', action); + $('li:last', item_holder).bind('click', function(e){ + action.apply(action, extra_args); + }); //$.ajatus.toolbar.clone(); } @@ -131,6 +144,24 @@ return true; }); }, + hide_item: function(id) { + var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']); + $('#'+id, item_holder).hide(); + + if ($.ajatus.toolbar.settings.enable_clone) { + var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']); + $('#'+id+'_clone', item_holder).hide(); + } + }, + show_item: function(id) { + var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']); + $('#'+id, item_holder).show(); + + if ($.ajatus.toolbar.settings.enable_clone) { + var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']); + $('#'+id+'_clone', item_holder).show(); + } + }, clear: function() { $('ul.item_holder', $.ajatus.toolbar.objects['main']).html(''); if ($.ajatus.toolbar.settings.enable_clone) { -- 2.11.4.GIT