2 $.ajatus = $.ajatus || {};
12 $.extend($.ajatus.toolbar, {
13 init: function(settings) {
14 $.ajatus.toolbar.settings = $.extend($.ajatus.toolbar.settings, settings || {});
15 $.ajatus.toolbar.objects = {};
16 $.ajatus.toolbar.items = [];
18 var main_tb = $('#main-page_toolbar', $.ajatus.application_element).hide();
20 main_tb = $.ajatus.toolbar.create_main();
22 $.ajatus.toolbar.prepare_main(main_tb);
25 $.ajatus.toolbar.objects['main'] = main_tb;
27 if ($.ajatus.toolbar.settings.enable_clone) {
28 var clone_tb = $('#clone-page_toolbar', $.ajatus.application_element).hide();
30 clone_tb = $.ajatus.toolbar.create_clone(main_tb);
32 $.ajatus.toolbar.prepare_clone();
34 $.ajatus.toolbar.objects['clone'] = clone_tb;
37 $.ajatus.toolbar.clear();
39 show: function(index) {
40 if (typeof index == 'undefined') {
41 $.each($.ajatus.toolbar.objects, function(i,o){
45 if (typeof($.ajatus.toolbar.objects[index]) != 'undefined') {
46 $.ajatus.toolbar.objects[index].show();
49 $.ajatus.toolbar.visible = true;
51 hide: function(index) {
52 if (typeof index == 'undefined') {
53 $.each($.ajatus.toolbar.objects, function(i,o){
57 if (typeof($.ajatus.toolbar.objects[index]) != 'undefined') {
58 $.ajatus.toolbar.objects[index].hide();
61 $.ajatus.toolbar.visible = false;
63 add_item: function() { // title, settings/icon/action, action, action args, insert after
64 if (arguments.length <= 0) {
68 id: $.ajatus.utils.generate_id(),
77 var item_settings = {};
80 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']);
82 if (arguments.length == 2) {
83 if (typeof arguments[1] == 'object') {
84 $.each($.ajatus.toolbar._parse_settings(arguments[1]), function(key,value){
85 item_obj[key] = value;
87 extra_args = [item_obj];
88 $.each(item_obj['extra_args'], function(i,n){
92 item_obj['action'] = arguments[1];
93 item_obj['content'] = [
99 if (arguments.length >= 3) {
100 item_obj['icon'] = $.ajatus.preferences.client.theme_icons_url + arguments[1];
101 item_obj['action'] = arguments[2];
102 item_obj['content'] = [
104 'img', { src: item_obj['icon'], alt: item_obj['title'], title: item_obj['title'] }, ''
107 } else if (item_obj['icon'] != null) {
108 item_obj['content'] = [
110 'img', { src: item_obj['icon'], alt: item_obj['title'], title: item_obj['title'] }, ''
115 if ( arguments.length >= 4
116 && typeof arguments[3] == 'object'
117 && arguments[3].length > 0)
119 item_obj['extra_args'] = arguments[3];
120 extra_args = [item_obj];
123 if (extra_args.length > 0) {
124 $.each(item_obj['extra_args'], function(i,n){
129 if (arguments.length == 5) {
130 item_obj['insert_after'] = arguments[4];
133 if (item_obj['insert_after'] != null) {
134 var item_elem = $('<li class="item" />').attr({
137 item_elem.insertAfter($('#'+item_obj['insert_after'], item_holder));
138 $('#'+item_obj.id, item_holder).createAppend(item_obj['content'][0], item_obj['content'][1], item_obj['content'][2]);
140 item_holder.createAppend(
141 'li', { className: 'item', id: item_obj.id }, item_obj['content']
145 $('#'+item_obj.id, item_holder).bind('click', function(e){
146 item_obj['action'].apply(item_obj['action'], extra_args);
149 if (item_obj['access_key'] != null) {
150 $.hotkeys.add(item_obj['access_key'], function(){ item_obj['action'].apply(item_obj['action'], extra_args); });
153 if ($.ajatus.toolbar.settings.enable_clone) {
154 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']);
156 if (item_obj['insert_after']) {
157 var item_elem = $('<li class="item" />').attr({
158 id: item_obj.id+'_clone'
160 item_elem.insertAfter($('#'+item_obj['insert_after']+'_clone', item_holder));
161 $('#'+item_obj.id+'_clone', item_holder).createAppend(item_obj['content'][0], item_obj['content'][1], item_obj['content'][2]);
163 item_holder.createAppend(
164 'li', { className: 'item', id: item_obj.id+'_clone' }, item_obj['content']
168 $('#'+item_obj.id, item_holder).bind('click', function(e){
169 item_obj['action'].apply(item_obj['action'], extra_args);
173 $.ajatus.toolbar.items.push(item_obj);
177 remove_item: function(id) {
178 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']);
179 $('#'+id, item_holder).remove();
180 if ($.ajatus.toolbar.settings.enable_clone) {
181 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']);
182 $('#'+id+'_clone', item_holder).remove();
184 $.ajatus.toolbar.items = $.grep($.ajatus.toolbar.items, function(n,i){
186 if (n['access_key'] != null) {
187 $.hotkeys.remove(n['access_key']);
194 hide_item: function(id) {
195 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']);
196 $('#'+id, item_holder).hide();
198 if ($.ajatus.toolbar.settings.enable_clone) {
199 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']);
200 $('#'+id+'_clone', item_holder).hide();
203 show_item: function(id) {
204 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['main']);
205 $('#'+id, item_holder).show();
207 if ($.ajatus.toolbar.settings.enable_clone) {
208 var item_holder = $('ul.item_holder', $.ajatus.toolbar.objects['clone']);
209 $('#'+id+'_clone', item_holder).show();
213 $('ul.item_holder', $.ajatus.toolbar.objects['main']).html('');
214 if ($.ajatus.toolbar.settings.enable_clone) {
215 $('ul.item_holder', $.ajatus.toolbar.objects['clone']).html('');
217 $.ajatus.toolbar.items = [];
219 create_main: function() {
222 create_clone: function() {
225 prepare_main: function(tb) {
226 var tb_content = $('.content', tb);
228 var items_holder = $('<ul class="item_holder"/>');
229 items_holder.appendTo(tb_content);
231 prepare_clone: function(tb) {
232 var tb_content = $('.content', tb);
234 var items_holder = $('<ul class="item_holder"/>');
235 items_holder.appendTo(tb_content);
238 var main_tb_content = $('.content', $.ajatus.toolbar.objects['main']);
239 var clone_tb_content = $('.content', $.ajatus.toolbar.objects['clone']);
240 var main_items = $('ul.item_holder', main_tb_content).html();
241 $('ul.item_holder', clone_tb_content).html(main_items);
243 _parse_settings: function(s) {
245 $.each(s, function(k, v){
246 if ($.inArray(k, ['icon','action','insert_after','access_key','extra_args']) != -1) {
248 v = $.ajatus.preferences.client.theme_icons_url + v;