File: fckplugin.js

package info (click to toggle)
moin 1.9.9-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 76,024 kB
  • sloc: python: 143,896; java: 10,704; php: 2,385; perl: 1,574; xml: 371; makefile: 214; sh: 81; sed: 5
file content (278 lines) | stat: -rw-r--r-- 8,755 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

/* ##########################################################
 * RestrictedNamedCommand
 *  extends FCKNamedCommand
 * ##########################################################
 */
var RestrictedNamedCommand = function(commandName, forbidden)
{
  this.Name = commandName;
  this.forbidden = forbidden;
}

RestrictedNamedCommand.prototype = new FCKNamedCommand();

RestrictedNamedCommand.prototype.GetState = function()
{
  var bState = FCK.GetNamedCommandState(this.Name);
  if (FCKSelection.GetType() == 'Control')
  {
    return bState;
  }
  else if (FCKSelection.CheckForNodeNames(this.forbidden))
  { 
    return FCK_TRISTATE_DISABLED;
  }
  return bState;
}

/* #######################################################
 * RestrictedUniqueNamedFormat
 *  extends RestrictedNamedCommand
 * #######################################################
 */

var RestrictedUniqueNamedFormat = function(commandName, forbidden)
{
  this.Name = commandName;
  this.forbidden = forbidden;
}

RestrictedUniqueNamedFormat.prototype = new RestrictedNamedCommand();

RestrictedUniqueNamedFormat.prototype.Execute = function()
{
  if (FCK.GetNamedCommandState(this.Name)==FCK_TRISTATE_OFF)
    FCK.ExecuteNamedCommand('RemoveFormat');

  FCK.ExecuteNamedCommand(this.Name);
}

/* #######################################################
 * RestrictedFormatBlockCommand
 *  extends FCKFormatBlockCommand
 * #######################################################
 */
var RestrictedFormatBlockCommand = function(forbidden)
{
  this.Name = 'FormatBlock' ;
  this.forbidden = forbidden;
}

RestrictedFormatBlockCommand.prototype = new FCKFormatBlockCommand();

RestrictedFormatBlockCommand.prototype.GetState = function()
{
  if (FCKSelection.CheckForNodeNames(this.forbidden))
    return FCK_TRISTATE_DISABLED;
 else
   return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
}

RestrictedFormatBlockCommand.prototype.Execute = function( formatName )
{
  if ( formatName == null || formatName == '' || formatName == 'P')
    FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' );
  else
  {
    FCK.ExecuteNamedCommand('RemoveFormat');
    FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' );
  }
}

/* ####################################################################
 *  RestrictedStyleCommand
 *    extends FCKStyleCommand
 * ####################################################################
 */

var RestrictedStyleCommand = function(forbidden)
{
  this.forbidden = forbidden;
}

RestrictedStyleCommand.prototype = new FCKStyleCommand();
RestrictedStyleCommand.prototype.GetState =  function()
{
 if (FCKSelection.CheckForNodeNames(this.forbidden))
   return FCK_TRISTATE_DISABLED;
 else
 {
   var oSelection = FCK.EditorDocument.selection;
   if ( FCKSelection.GetType() == 'Control' )
   {
     var e = FCKSelection.GetSelectedElement();
     if (e)
       return this.StylesLoader.StyleGroups[e.tagName] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
     else
       FCK_TRISTATE_OFF;
   }
   else
     return FCK_TRISTATE_OFF;
  }
}

RestrictedStyleCommand.prototype.Execute = function(styleName, styleComboItem )
{
  if ( styleComboItem.Selected )
    styleComboItem.Style.RemoveFromSelection() ;
  else
  {
    if (styleName == "Typewriter")
      FCK.ExecuteNamedCommand('RemoveFormat');

    styleComboItem.Style.ApplyToSelection() ;
  }
  FCK.Focus();
  FCK.Events.FireEvent( "OnSelectionChange" );
}

/* ####################################################################
 * StyleButtonCommand
 * ####################################################################
 */

var StyleButtonCommand = function(stylename, unique)
{
  // using FCK.Style instead of fckstylesloader
  this.style = FCK.Styles.GetStyle(stylename);
  this.unique = unique;
}

StyleButtonCommand.prototype = new FCKStyleCommand();

StyleButtonCommand.prototype.Execute = function()
{
  if (this.GetState()==FCK_TRISTATE_ON)
  {
    this.style.RemoveFromSelection();
  }
  else
  {
    if (this.unique) FCK.ExecuteNamedCommand('RemoveFormat');
    this.style.ApplyToSelection();
  }
  //FCKSelection.GetParentElement().normalize();
  FCK.Focus();
  FCK.Events.FireEvent("OnSelectionChange");
}



/* ####################################################################
 * RestrictedStyleButtonCommand
 * ####################################################################
 */

var RestrictedStyleButtonCommand = function(stylename, forbidden, unique)
{
  this.style = FCK.Styles.GetStyle(stylename);      // using FCK.Style instead of fckstylesloader
  this.forbidden = forbidden;
  this.unique = unique;
}

RestrictedStyleButtonCommand.prototype = new StyleButtonCommand();

RestrictedStyleButtonCommand.prototype.GetState = function()
{
  if (FCKSelection.CheckForNodeNames(this.forbidden))
    return FCK_TRISTATE_DISABLED;
  else
  {
    aStyles = this.GetActiveStyles();
    for (i=0;i<aStyles.length;i++)
      if (aStyles[i] == this.style) return FCK_TRISTATE_ON;
    return FCK_TRISTATE_OFF;
  }
}

// ####################################################################

var noformat = "H1|H2|H3|H4|H5|H6|PRE|A|TT|IMG";
var noextendedformat = noformat + "|SUB|SUPER";
var noFormat = new RegExp("^(?:" + noformat + ")$", "i");
var noExtendedFormat = new RegExp("^(?:" + noextendedformat + ")$", "i");
var noFormatandIndent = new RegExp("^(?:" + noformat + "|TABLE|TR|TD)$", "i");
var noTT = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|IMG)$/i;
var noBlock = /^(?:TABLE|TR|TD|A|IMG)$/i;
var noSmileys = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|TT|SUB|SUPER)$/i;
var noTable = new RegExp("^(?:" + noextendedformat + "|TABLE|UL|OL|DL)$", "i");

// Register some context sensitive commands
// register commands every browser

// formats
FCKCommands.RegisterCommand('Bold', 
 new RestrictedNamedCommand('Bold', noExtendedFormat));
FCKCommands.RegisterCommand('Italic', 
 new RestrictedNamedCommand('Italic', noExtendedFormat));

FCKCommands.RegisterCommand('Underline', 
 new RestrictedNamedCommand('Underline', noExtendedFormat));
FCKCommands.RegisterCommand('StrikeThrough',
 new RestrictedNamedCommand('StrikeThrough', noExtendedFormat));


FCKCommands.RegisterCommand('Small',
 new RestrictedStyleButtonCommand('Small', noExtendedFormat));
FCKCommands.RegisterCommand('Big',
 new RestrictedStyleButtonCommand('Big', noExtendedFormat));


// formats no allowing formats inside
FCKCommands.RegisterCommand('Subscript',
 new RestrictedUniqueNamedFormat('Subscript', noFormat));
FCKCommands.RegisterCommand('Superscript',
 new RestrictedUniqueNamedFormat('Superscript', noFormat));


FCKCommands.RegisterCommand('Typewriter',
 new RestrictedStyleButtonCommand('Typewriter', noTT, true));


// lists, hline
FCKCommands.RegisterCommand('Outdent',
 new RestrictedNamedCommand('Outdent', noFormatandIndent));
FCKCommands.RegisterCommand('Indent',
 new RestrictedNamedCommand('Indent', noFormatandIndent));
FCKCommands.RegisterCommand('InsertOrderedList',
 new RestrictedNamedCommand('InsertOrderedList', noFormatandIndent));
FCKCommands.RegisterCommand('InsertUnorderedList',
 new RestrictedNamedCommand('InsertUnorderedList', noFormatandIndent));
FCKCommands.RegisterCommand('InsertHorizontalRule',
 new RestrictedNamedCommand('InsertHorizontalRule', noFormatandIndent));

// Font formats and styles
FCKCommands.RegisterCommand('FontFormat', 
 new RestrictedFormatBlockCommand(noBlock));
FCKCommands.RegisterCommand('Style', 
 new RestrictedStyleCommand(noFormat));

// misc
FCKCommands.RegisterCommand('Smiley',
  new FCKDialogCommand( 'Smiley', FCKLang.DlgSmileyTitle, 
                        'dialog/fck_smiley.html', FCKConfig.SmileyWindowWidth,
                         FCKConfig.SmileyWindowHeight, 
                         FCKSelection.CheckForNodeNames, noSmileys));
FCKCommands.RegisterCommand('Table', new FCKDialogCommand
 ('Table', FCKLang.DlgTableTitle, 'dialog/fck_table.html', 400, 250,
  FCKSelection.CheckForNodeNames, noTable));

// useless code, this code make each menu's icon disapear.
/*
// Make toolbar items context sensitive
FCKToolbarItems.RegisterItem('Smiley', new FCKToolbarButton
 ('Smiley', FCKLang.InsertSmileyLbl, FCKLang.InsertSmiley, null, false, true));
FCKToolbarItems.RegisterItem('Table', new FCKToolbarButton
 ('Table', FCKLang.InsertTableLbl, FCKLang.InsertTable, null, false, true));
*/

FCKToolbarItems.RegisterItem('Big', new FCKToolbarButton
           ('Big', 'Big>', 'Big', 
            FCK_TOOLBARITEM_ONLYICON, false, true));
  FCKToolbarItems.RegisterItem('Small', new FCKToolbarButton
           ('Small', 'Small', 'Small', 
            FCK_TOOLBARITEM_ONLYICON, false, true));
  FCKToolbarItems.RegisterItem('Typewriter', new FCKToolbarButton
           ('Typewriter', 'Typewriter', 'Typewriter', 
            FCK_TOOLBARITEM_ONLYICON, false, true));