Dotclear

source: admin/js/dcToolBar.js @ 326:3138de12835e

Revision 326:3138de12835e, 2.8 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Let's start fresh for a better world

Line 
1(function($){
2     var methods = {
3          init: function(options) {
4               var settings = {
5                    formatter: ''
6               }
7               $.extend(settings,options);
8               
9               if (dcToolBar.getConfig(settings.formatter) == null) {
10                    if (console != 'undefined') {
11                         console.log('No toolbar configuration for formatter ['+ settings.formatter +']');
12                    }
13               }
14               
15               return this.each(function(){
16                    $.data(this,'toolbar',new tinymce.Editor($(this).attr('id'),dcToolBar.getConfig(settings.formatter)));
17                    $(this).data('toolbar').activeFormatter = settings.formatter;
18               });
19         
20          },
21          draw: function() {
22               return this.each(function(){
23                    if ($(this).data('toolbar') == null) {
24                         throw 'Toolbar should be initialize before render it';
25                    }
26                    $(this).data('toolbar').render();
27               });
28          },
29          show: function() {
30               return this.each(function(){
31                    if ($(this).data('toolbar') == null) {
32                         throw 'Toolbar should be initialize before show it';
33                    }
34                    $(this).data('toolbar').show();
35               });
36          },
37          hide: function() {
38               return this.each(function(){
39                    if ($(this).data('toolbar') == null) {
40                         throw 'Toolbar should be initialize before hide it';
41                    }
42                    $(this).data('toolbar').hide();
43               });
44          },
45          toggle: function() {
46               return this.each(function(){
47                    if ($(this).data('toolbar') == null) {
48                         throw 'Toolbar should be initialize before toogle it';
49                    }
50                    if ($(this).data('toolbar').isHidden()) {
51                         $(this).data('toolbar').show();
52                    } else {
53                         $(this).data('toolbar').hide();
54                    }
55               });
56          },
57          destroy: function() {
58               return this.each(function(){
59                    if ($(this).data('toolbar') == null) {
60                         return;
61                    }
62                    $(this).data('toolbar').remove();
63                    $.data(this,'toolbar',null);
64               });
65          },
66          switch: function(formatter) {
67               return this.each(function(){
68                    if ($(this).data('formatter') != formatter) {
69                         var options = {};
70                         options.formatter = formatter;
71                         methods.destroy.apply($(this));
72                         methods.init.apply($(this),[options]);
73                         methods.draw.apply($(this));
74                    }
75               });
76          }
77     };
78     
79     $.fn.dctoolbar = function(method) {
80          try {
81               if (methods[method]) {
82                    return methods[method].apply(this,Array.prototype.slice.call(arguments,1));
83               } else if (typeof method === 'object' || !method) {
84                    return methods.init.apply(this,arguments);
85               } else {
86                    throw 'Method ' + method + ' does not exist on jQuery.dctoolbar';
87               }
88          } catch (e) {
89               $.error('Error happend on jQuery.dctoolbar: ' + e);
90          }
91     };
92})(jQuery);
93
94function dcToolBar() {
95     this.setConfig = function(formatter,config) {
96          this.configurations[formatter] = config;
97     };
98     
99     this.getConfig = function(formatter) {
100          if (this.configurations.hasOwnProperty(formatter)) {
101               return this.configurations[formatter];
102          } else {
103               return null;
104          }
105     };
106}
107
108dcToolBar.prototype = {
109     configurations: {}
110}
Note: See TracBrowser for help on using the repository browser.

Sites map