~ubuntu-it-wiki/wiki-ubuntu-it/wiki-repo

« back to all changes in this revision

Viewing changes to applets/moinFCKplugins/restrict_actions/fckplugin.js

  • Committer: Leo Iannacone
  • Date: 2011-06-02 15:05:37 UTC
  • Revision ID: l3on@ubuntu.com-20110602150537-ycrnf58qf67uf593
Added applets for gui editor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* ##########################################################
 
3
 * RestrictedNamedCommand
 
4
 *  extends FCKNamedCommand
 
5
 * ##########################################################
 
6
 */
 
7
var RestrictedNamedCommand = function(commandName, forbidden)
 
8
{
 
9
  this.Name = commandName;
 
10
  this.forbidden = forbidden;
 
11
}
 
12
 
 
13
RestrictedNamedCommand.prototype = new FCKNamedCommand();
 
14
 
 
15
RestrictedNamedCommand.prototype.GetState = function()
 
16
{
 
17
  var bState = FCK.GetNamedCommandState(this.Name);
 
18
  if (FCKSelection.GetType() == 'Control')
 
19
  {
 
20
    return bState;
 
21
  }
 
22
  else if (FCKSelection.CheckForNodeNames(this.forbidden))
 
23
  { 
 
24
    return FCK_TRISTATE_DISABLED;
 
25
  }
 
26
  return bState;
 
27
}
 
28
 
 
29
/* #######################################################
 
30
 * RestrictedUniqueNamedFormat
 
31
 *  extends RestrictedNamedCommand
 
32
 * #######################################################
 
33
 */
 
34
 
 
35
var RestrictedUniqueNamedFormat = function(commandName, forbidden)
 
36
{
 
37
  this.Name = commandName;
 
38
  this.forbidden = forbidden;
 
39
}
 
40
 
 
41
RestrictedUniqueNamedFormat.prototype = new RestrictedNamedCommand();
 
42
 
 
43
RestrictedUniqueNamedFormat.prototype.Execute = function()
 
44
{
 
45
  if (FCK.GetNamedCommandState(this.Name)==FCK_TRISTATE_OFF)
 
46
    FCK.ExecuteNamedCommand('RemoveFormat');
 
47
 
 
48
  FCK.ExecuteNamedCommand(this.Name);
 
49
}
 
50
 
 
51
/* #######################################################
 
52
 * RestrictedFormatBlockCommand
 
53
 *  extends FCKFormatBlockCommand
 
54
 * #######################################################
 
55
 */
 
56
var RestrictedFormatBlockCommand = function(forbidden)
 
57
{
 
58
  this.Name = 'FormatBlock' ;
 
59
  this.forbidden = forbidden;
 
60
}
 
61
 
 
62
RestrictedFormatBlockCommand.prototype = new FCKFormatBlockCommand();
 
63
 
 
64
RestrictedFormatBlockCommand.prototype.GetState = function()
 
65
{
 
66
  if (FCKSelection.CheckForNodeNames(this.forbidden))
 
67
    return FCK_TRISTATE_DISABLED;
 
68
 else
 
69
   return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
 
70
}
 
71
 
 
72
RestrictedFormatBlockCommand.prototype.Execute = function( formatName )
 
73
{
 
74
  if ( formatName == null || formatName == '' || formatName == 'P')
 
75
    FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' );
 
76
  else
 
77
  {
 
78
    FCK.ExecuteNamedCommand('RemoveFormat');
 
79
    FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' );
 
80
  }
 
81
}
 
82
 
 
83
/* ####################################################################
 
84
 *  RestrictedStyleCommand
 
85
 *    extends FCKStyleCommand
 
86
 * ####################################################################
 
87
 */
 
88
 
 
89
var RestrictedStyleCommand = function(forbidden)
 
90
{
 
91
  this.forbidden = forbidden;
 
92
}
 
93
 
 
94
RestrictedStyleCommand.prototype = new FCKStyleCommand();
 
95
RestrictedStyleCommand.prototype.GetState =  function()
 
96
{
 
97
 if (FCKSelection.CheckForNodeNames(this.forbidden))
 
98
   return FCK_TRISTATE_DISABLED;
 
99
 else
 
100
 {
 
101
   var oSelection = FCK.EditorDocument.selection;
 
102
   if ( FCKSelection.GetType() == 'Control' )
 
103
   {
 
104
     var e = FCKSelection.GetSelectedElement();
 
105
     if (e)
 
106
       return this.StylesLoader.StyleGroups[e.tagName] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
 
107
     else
 
108
       FCK_TRISTATE_OFF;
 
109
   }
 
110
   else
 
111
     return FCK_TRISTATE_OFF;
 
112
  }
 
113
}
 
114
 
 
115
RestrictedStyleCommand.prototype.Execute = function(styleName, styleComboItem )
 
116
{
 
117
  if ( styleComboItem.Selected )
 
118
    styleComboItem.Style.RemoveFromSelection() ;
 
119
  else
 
120
  {
 
121
    if (styleName == "Typewriter")
 
122
      FCK.ExecuteNamedCommand('RemoveFormat');
 
123
 
 
124
    styleComboItem.Style.ApplyToSelection() ;
 
125
  }
 
126
  FCK.Focus();
 
127
  FCK.Events.FireEvent( "OnSelectionChange" );
 
128
}
 
129
 
 
130
/* ####################################################################
 
131
 * StyleButtonCommand
 
132
 * ####################################################################
 
133
 */
 
134
 
 
135
var StyleButtonCommand = function(stylename, unique)
 
136
{
 
137
  // using FCK.Style instead of fckstylesloader
 
138
  this.style = FCK.Styles.GetStyle(stylename);
 
139
  this.unique = unique;
 
140
}
 
141
 
 
142
StyleButtonCommand.prototype = new FCKStyleCommand();
 
143
 
 
144
StyleButtonCommand.prototype.Execute = function()
 
145
{
 
146
  if (this.GetState()==FCK_TRISTATE_ON)
 
147
  {
 
148
    this.style.RemoveFromSelection();
 
149
  }
 
150
  else
 
151
  {
 
152
    if (this.unique) FCK.ExecuteNamedCommand('RemoveFormat');
 
153
    this.style.ApplyToSelection();
 
154
  }
 
155
  //FCKSelection.GetParentElement().normalize();
 
156
  FCK.Focus();
 
157
  FCK.Events.FireEvent("OnSelectionChange");
 
158
}
 
159
 
 
160
 
 
161
 
 
162
/* ####################################################################
 
163
 * RestrictedStyleButtonCommand
 
164
 * ####################################################################
 
165
 */
 
166
 
 
167
var RestrictedStyleButtonCommand = function(stylename, forbidden, unique)
 
168
{
 
169
  this.style = FCK.Styles.GetStyle(stylename);      // using FCK.Style instead of fckstylesloader
 
170
  this.forbidden = forbidden;
 
171
  this.unique = unique;
 
172
}
 
173
 
 
174
RestrictedStyleButtonCommand.prototype = new StyleButtonCommand();
 
175
 
 
176
RestrictedStyleButtonCommand.prototype.GetState = function()
 
177
{
 
178
  if (FCKSelection.CheckForNodeNames(this.forbidden))
 
179
    return FCK_TRISTATE_DISABLED;
 
180
  else
 
181
  {
 
182
    aStyles = this.GetActiveStyles();
 
183
    for (i=0;i<aStyles.length;i++)
 
184
      if (aStyles[i] == this.style) return FCK_TRISTATE_ON;
 
185
    return FCK_TRISTATE_OFF;
 
186
  }
 
187
}
 
188
 
 
189
// ####################################################################
 
190
 
 
191
var noformat = "H1|H2|H3|H4|H5|H6|PRE|A|TT|IMG";
 
192
var noextendedformat = noformat + "|SUB|SUPER";
 
193
var noFormat = new RegExp("^(?:" + noformat + ")$", "i");
 
194
var noExtendedFormat = new RegExp("^(?:" + noextendedformat + ")$", "i");
 
195
var noFormatandIndent = new RegExp("^(?:" + noformat + "|TABLE|TR|TD)$", "i");
 
196
var noTT = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|IMG)$/i;
 
197
var noBlock = /^(?:TABLE|TR|TD|A|IMG)$/i;
 
198
var noSmileys = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|TT|SUB|SUPER)$/i;
 
199
var noTable = new RegExp("^(?:" + noextendedformat + "|TABLE|UL|OL|DL)$", "i");
 
200
 
 
201
// Register some context sensitive commands
 
202
// register commands every browser
 
203
 
 
204
// formats
 
205
FCKCommands.RegisterCommand('Bold', 
 
206
 new RestrictedNamedCommand('Bold', noExtendedFormat));
 
207
FCKCommands.RegisterCommand('Italic', 
 
208
 new RestrictedNamedCommand('Italic', noExtendedFormat));
 
209
 
 
210
FCKCommands.RegisterCommand('Underline', 
 
211
 new RestrictedNamedCommand('Underline', noExtendedFormat));
 
212
FCKCommands.RegisterCommand('StrikeThrough',
 
213
 new RestrictedNamedCommand('StrikeThrough', noExtendedFormat));
 
214
 
 
215
 
 
216
FCKCommands.RegisterCommand('Small',
 
217
 new RestrictedStyleButtonCommand('Small', noExtendedFormat));
 
218
FCKCommands.RegisterCommand('Big',
 
219
 new RestrictedStyleButtonCommand('Big', noExtendedFormat));
 
220
 
 
221
 
 
222
// formats no allowing formats inside
 
223
FCKCommands.RegisterCommand('Subscript',
 
224
 new RestrictedUniqueNamedFormat('Subscript', noFormat));
 
225
FCKCommands.RegisterCommand('Superscript',
 
226
 new RestrictedUniqueNamedFormat('Superscript', noFormat));
 
227
 
 
228
 
 
229
FCKCommands.RegisterCommand('Typewriter',
 
230
 new RestrictedStyleButtonCommand('Typewriter', noTT, true));
 
231
 
 
232
 
 
233
// lists, hline
 
234
FCKCommands.RegisterCommand('Outdent',
 
235
 new RestrictedNamedCommand('Outdent', noFormatandIndent));
 
236
FCKCommands.RegisterCommand('Indent',
 
237
 new RestrictedNamedCommand('Indent', noFormatandIndent));
 
238
FCKCommands.RegisterCommand('InsertOrderedList',
 
239
 new RestrictedNamedCommand('InsertOrderedList', noFormatandIndent));
 
240
FCKCommands.RegisterCommand('InsertUnorderedList',
 
241
 new RestrictedNamedCommand('InsertUnorderedList', noFormatandIndent));
 
242
FCKCommands.RegisterCommand('InsertHorizontalRule',
 
243
 new RestrictedNamedCommand('InsertHorizontalRule', noFormatandIndent));
 
244
 
 
245
// Font formats and styles
 
246
FCKCommands.RegisterCommand('FontFormat', 
 
247
 new RestrictedFormatBlockCommand(noBlock));
 
248
FCKCommands.RegisterCommand('Style', 
 
249
 new RestrictedStyleCommand(noFormat));
 
250
 
 
251
// misc
 
252
FCKCommands.RegisterCommand('Smiley',
 
253
  new FCKDialogCommand( 'Smiley', FCKLang.DlgSmileyTitle, 
 
254
                        'dialog/fck_smiley.html', FCKConfig.SmileyWindowWidth,
 
255
                         FCKConfig.SmileyWindowHeight, 
 
256
                         FCKSelection.CheckForNodeNames, noSmileys));
 
257
FCKCommands.RegisterCommand('Table', new FCKDialogCommand
 
258
 ('Table', FCKLang.DlgTableTitle, 'dialog/fck_table.html', 400, 250,
 
259
  FCKSelection.CheckForNodeNames, noTable));
 
260
 
 
261
// useless code, this code make each menu's icon disapear.
 
262
/*
 
263
// Make toolbar items context sensitive
 
264
FCKToolbarItems.RegisterItem('Smiley', new FCKToolbarButton
 
265
 ('Smiley', FCKLang.InsertSmileyLbl, FCKLang.InsertSmiley, null, false, true));
 
266
FCKToolbarItems.RegisterItem('Table', new FCKToolbarButton
 
267
 ('Table', FCKLang.InsertTableLbl, FCKLang.InsertTable, null, false, true));
 
268
*/
 
269
 
 
270
FCKToolbarItems.RegisterItem('Big', new FCKToolbarButton
 
271
           ('Big', 'Big>', 'Big', 
 
272
            FCK_TOOLBARITEM_ONLYICON, false, true));
 
273
  FCKToolbarItems.RegisterItem('Small', new FCKToolbarButton
 
274
           ('Small', 'Small', 'Small', 
 
275
            FCK_TOOLBARITEM_ONLYICON, false, true));
 
276
  FCKToolbarItems.RegisterItem('Typewriter', new FCKToolbarButton
 
277
           ('Typewriter', 'Typewriter', 'Typewriter', 
 
278
            FCK_TOOLBARITEM_ONLYICON, false, true));