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 | $(this).data('toolbar').onPreInit.add(function(ed) { |
---|
19 | tinymce.addI18n(dcToolBar.getI18n()); |
---|
20 | }); |
---|
21 | }); |
---|
22 | |
---|
23 | }, |
---|
24 | draw: function() { |
---|
25 | return this.each(function(){ |
---|
26 | if ($(this).data('toolbar') == null) { |
---|
27 | throw 'Toolbar should be initialize before render it'; |
---|
28 | } |
---|
29 | $(this).data('toolbar').render(); |
---|
30 | }); |
---|
31 | }, |
---|
32 | show: function() { |
---|
33 | return this.each(function(){ |
---|
34 | if ($(this).data('toolbar') == null) { |
---|
35 | throw 'Toolbar should be initialize before show it'; |
---|
36 | } |
---|
37 | var t = $(this).data('toolbar'); |
---|
38 | |
---|
39 | tinymce.dom.show(t.getContainer()); |
---|
40 | t.load(); |
---|
41 | }); |
---|
42 | }, |
---|
43 | hide: function() { |
---|
44 | return this.each(function(){ |
---|
45 | if ($(this).data('toolbar') == null) { |
---|
46 | throw 'Toolbar should be initialize before hide it'; |
---|
47 | } |
---|
48 | var t = $(this).data('toolbar'); |
---|
49 | |
---|
50 | tinymce.dom.hide(t.getContainer()); |
---|
51 | t.load(); |
---|
52 | }); |
---|
53 | }, |
---|
54 | toggle: function() { |
---|
55 | return this.each(function(){ |
---|
56 | if ($(this).data('toolbar') == null) { |
---|
57 | throw 'Toolbar should be initialize before toogle it'; |
---|
58 | } |
---|
59 | var t = $(this).data('toolbar'); |
---|
60 | if (t.isHidden()) { |
---|
61 | t.show(); |
---|
62 | t.load(); |
---|
63 | } |
---|
64 | else { |
---|
65 | t.save(); |
---|
66 | $(t.getContainer()).hide(); |
---|
67 | } |
---|
68 | }); |
---|
69 | }, |
---|
70 | destroy: function() { |
---|
71 | return this.each(function(){ |
---|
72 | if ($(this).data('toolbar') == null) { |
---|
73 | return; |
---|
74 | } |
---|
75 | $(this).data('toolbar').remove(); |
---|
76 | $.data(this,'toolbar',null); |
---|
77 | }); |
---|
78 | }, |
---|
79 | switch: function(formatter) { |
---|
80 | return this.each(function(){ |
---|
81 | if ($(this).data('formatter') != formatter) { |
---|
82 | var options = {}; |
---|
83 | options.formatter = formatter; |
---|
84 | methods.destroy.apply($(this)); |
---|
85 | methods.init.apply($(this),[options]); |
---|
86 | methods.draw.apply($(this)); |
---|
87 | } |
---|
88 | }); |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | $.fn.dctoolbar = function(method) { |
---|
93 | try { |
---|
94 | if (methods[method]) { |
---|
95 | return methods[method].apply(this,Array.prototype.slice.call(arguments,1)); |
---|
96 | } else if (typeof method === 'object' || !method) { |
---|
97 | return methods.init.apply(this,arguments); |
---|
98 | } else { |
---|
99 | throw 'Method ' + method + ' does not exist on jQuery.dctoolbar'; |
---|
100 | } |
---|
101 | } catch (e) { |
---|
102 | $.error('Error happend on jQuery.dctoolbar: ' + e); |
---|
103 | } |
---|
104 | }; |
---|
105 | })(jQuery); |
---|
106 | |
---|
107 | function dcToolBar() { |
---|
108 | this.setConfig = function(formatter,config) { |
---|
109 | this.configurations[formatter] = config; |
---|
110 | }; |
---|
111 | |
---|
112 | this.setI18n = function(i18n) { |
---|
113 | this.i18n = i18n; |
---|
114 | }; |
---|
115 | |
---|
116 | this.getConfig = function(formatter) { |
---|
117 | if (this.configurations.hasOwnProperty(formatter)) { |
---|
118 | return this.configurations[formatter]; |
---|
119 | } else { |
---|
120 | return null; |
---|
121 | } |
---|
122 | }; |
---|
123 | |
---|
124 | this.getI18n = function() { |
---|
125 | return this.i18n == null ? {} : this.i18n; |
---|
126 | }; |
---|
127 | } |
---|
128 | |
---|
129 | dcToolBar.prototype = { |
---|
130 | configurations: {}, |
---|
131 | i18n: null |
---|
132 | } |
---|