muck-contents 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.rdoc +9 -0
  2. data/VERSION +1 -1
  3. data/app/views/tiny_mce/files.html.erb +1 -1
  4. data/app/views/tiny_mce/images.html.erb +1 -1
  5. data/app/views/tiny_mce/links.html.erb +1 -1
  6. data/config/initializers/mce_options.rb +1 -1
  7. data/lib/active_record/acts/muck_content.rb +1 -1
  8. data/muck-contents.gemspec +38 -26
  9. data/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/editor_plugin.js +3 -3
  10. data/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/editor_plugin_src.js +3 -3
  11. data/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/js/functions.js +0 -0
  12. data/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/langs/en_dlg.js +0 -0
  13. data/{test/rails_root/public/javascripts/tiny_mce/plugins/advimagetoo → public/javascripts/tiny_mce/plugins/muckimage}/editor_plugin.js +3 -3
  14. data/{test/rails_root/public/javascripts/tiny_mce/plugins/advimagetoo → public/javascripts/tiny_mce/plugins/muckimage}/editor_plugin_src.js +3 -3
  15. data/public/javascripts/tiny_mce/plugins/{advimagetoo → muckimage}/js/functions.js +0 -0
  16. data/public/javascripts/tiny_mce/plugins/{advimagetoo → muckimage}/langs/en_dlg.js +0 -0
  17. data/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/editor_plugin.js +5 -5
  18. data/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/editor_plugin_src.js +5 -5
  19. data/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/js/functions.js +2 -2
  20. data/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/langs/en_dlg.js +0 -0
  21. data/test/rails_root/config/global_config.yml +2 -0
  22. data/test/rails_root/config/initializers/mce_options.rb +17 -14
  23. data/test/rails_root/public/javascripts/tiny_mce/plugins/bramus_cssextras/editor_plugin.js +649 -0
  24. data/test/rails_root/public/javascripts/tiny_mce/plugins/bramus_cssextras/editor_plugin_src.js +649 -0
  25. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/codehighlighting.htm +50 -0
  26. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/css/codehighlighting.css +32 -0
  27. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/editor_plugin.js +1 -0
  28. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/editor_plugin_src.js +62 -0
  29. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/img/Thumbs.db +0 -0
  30. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/img/codehighlight.gif +0 -0
  31. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/img/codehighlight2.gif +0 -0
  32. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/js/codehighlighting.js +37 -0
  33. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/langs/en.js +12 -0
  34. data/test/rails_root/public/javascripts/tiny_mce/plugins/codehighlighting/langs/en_dlg.js +12 -0
  35. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/editor_plugin.js +3 -3
  36. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/editor_plugin_src.js +3 -3
  37. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/js/functions.js +0 -0
  38. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advfiletoo → muckfile}/langs/en_dlg.js +0 -0
  39. data/{public/javascripts/tiny_mce/plugins/advimagetoo → test/rails_root/public/javascripts/tiny_mce/plugins/muckimage}/editor_plugin.js +3 -3
  40. data/{public/javascripts/tiny_mce/plugins/advimagetoo → test/rails_root/public/javascripts/tiny_mce/plugins/muckimage}/editor_plugin_src.js +3 -3
  41. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advimagetoo → muckimage}/image.htm +0 -0
  42. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advimagetoo → muckimage}/js/functions.js +0 -0
  43. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advimagetoo → muckimage}/langs/en_dlg.js +0 -0
  44. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/editor_plugin.js +5 -5
  45. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/editor_plugin_src.js +5 -5
  46. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/js/functions.js +2 -2
  47. data/test/rails_root/public/javascripts/tiny_mce/plugins/{advlinktoo → mucklink}/langs/en_dlg.js +0 -0
  48. data/test/rails_root/public/stylesheets/tinymce.css +1 -1
  49. metadata +38 -26
@@ -0,0 +1,649 @@
1
+ /**
2
+ * @name bramus_cssextras
3
+ * @version 0.5.0
4
+ *
5
+ * @author Bramus! (Bram Van Damme)
6
+ * @authorURL http://www.bram.us/
7
+ * @infoURL http://www.bram.us/projects/tinymce-plugins/
8
+ *
9
+ * @license Creative Commons Attribution-Share Alike 2.5
10
+ * @licenseURL http://creativecommons.org/licenses/by-sa/2.5/
11
+ *
12
+ * v 0.5.0 - 2007.12.11 - NEW : TinyMCE 3.x Compatibility (TinyMCE 2.x is no longer supported)
13
+ * v 0.4.1 - 2007.11.22 - BUG : didn't work with multiple content_css files specified (@see http://www.bram.us/projects/tinymce-plugins/tinymce-classes-and-ids-plugin-bramus_cssextras/#comment-89820)
14
+ * - BUG : If for example p.test is defined multiple times, show "test" only once in the dropdown.
15
+ * v 0.4.0 - 2007.09.10 - BUG : selection noclass returned "undefined" as class, should be empty
16
+ * - ADD : automatic building of the bramus_cssextras_classesstring and bramus_cssextras_idsstring
17
+ * v 0.3.3 - 2007.07.27 - getInfo returned wrong version. Fixed + version increment.
18
+ * v 0.3.2 - 2007.07.23 - minor change in outputted HTML of the selects
19
+ * v 0.3.1 - 2007.06.28 - ids must be unique, so added a check and confirm thingy ;-)
20
+ * v 0.3 - 2007.06.27 - Plugin changed from bramus_classeslist to bramus_cssextras as it now supports the settings of ids too :-)
21
+ * v 0.2 - 2007.06.22 - added Undo Levels + a few extra comments (should be fully commented now)
22
+ * v 0.1 - 2007.06.19 - initial build
23
+ */
24
+
25
+ (function() {
26
+
27
+ // Load plugin specific language pack
28
+ // tinymce.PluginManager.requireLangPack('bramus_cssextras');
29
+
30
+ tinymce.create('tinymce.plugins.BramusCssExtras', {
31
+
32
+ /**
33
+ * Returns information about the plugin as a name/value array.
34
+ * The current keys are longname, author, authorurl, infourl and version.
35
+ *
36
+ * @return {Object} Name/value array containing information about the plugin.
37
+ */
38
+ getInfo : function() {
39
+ return {
40
+ longname : 'Plugin to support the adding of classes and ids to elements (or their parent element)',
41
+ author : 'Bramus!',
42
+ authorurl : 'http://www.bram.us/',
43
+ infourl : 'http://www.bram.us/projects/tinymce-plugins/',
44
+ version : "0.5.0"
45
+ };
46
+ },
47
+
48
+
49
+ /**
50
+ * Initializes the plugin, this will be executed after the plugin has been created.
51
+ * This call is done before the editor instance has finished it's initialization so use the onInit event
52
+ * of the editor instance to intercept that event.
53
+ *
54
+ * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
55
+ * @param {string} url Absolute URL to where the plugin is located.
56
+ */
57
+ init : function(ed, url) {
58
+ this._init(ed, url);
59
+ },
60
+
61
+
62
+ /**
63
+ * Creates control instances based in the incomming name. This method is normally not
64
+ * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
65
+ * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
66
+ * method can be used to create those.
67
+ *
68
+ * @param {String} n Name of the control to create.
69
+ * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
70
+ * @return {tinymce.ui.Control} New control instance or null if no control was created.
71
+ */
72
+ createControl : function(n, cm) {
73
+ switch (n) {
74
+ case 'bramus_cssextras_classes':
75
+ case 'bramus_cssextras_ids':
76
+ return this._createControl(n, cm);
77
+ break;
78
+ }
79
+
80
+ return null;
81
+ },
82
+
83
+
84
+ /**
85
+ * Internally used variables
86
+ * ---------------------------------------------------------------------------------------------------
87
+ */
88
+
89
+ // Strings that will hold all possible classes/ids /* removed, these are global now */
90
+ // _coreClassesString : null,
91
+ // _coreIdsStrings : null,
92
+
93
+ // Arrays that will hold all possible classes/ids /* removed, these are global now */
94
+ // _coreClassesArray : null,
95
+ // _coreIdsArray : null,
96
+
97
+ // The dropdowns
98
+ _coreClassesDropdown : null,
99
+ _coreIdsDropdown : null,
100
+
101
+ // XHR Object & Response - needed for loading the content_css file(s) if needed
102
+ _xmlhttp : null,
103
+ _xmlhttpresponse : null,
104
+
105
+ // CPU Power Savers : The previous node (don't calculate if nothing changed) and Already loaded (only init this plugin once)
106
+ _previousNode : null,
107
+ // _loaded : null, /* removed, these are global now */
108
+
109
+
110
+ /**
111
+ * Helper Functions
112
+ * ---------------------------------------------------------------------------------------------------
113
+ */
114
+
115
+ // Helper function : trim a string
116
+ _trim : function(str) {
117
+ return str.replace(/^\s+|\s+$/g,"");
118
+ },
119
+
120
+ // Helper function : left trim a string
121
+ _ltrim : function(str) {
122
+ return str.replace(/^\s+/,"");
123
+ },
124
+
125
+ // Helper function : right trim a a string
126
+ _rtrim : function() {
127
+ return this.replace(/\s+$/,"");
128
+ },
129
+
130
+ // Helper function : is element in array (and return position if so)
131
+ _inArray : function(needle, haystack) {
132
+
133
+ // loop all elements of array (haystack)
134
+ for (var i = 0; i < haystack.length; i++){
135
+
136
+ // compare with needle
137
+ if (needle == haystack[i]) {
138
+
139
+ // got hit : return position in array
140
+ return i;
141
+
142
+ }
143
+
144
+ }
145
+ // no hit
146
+ return false;
147
+ },
148
+
149
+ /**
150
+ * Init function
151
+ * ---------------------------------------------------------------------------------------------------
152
+ */
153
+
154
+ _init : function (ed, url) {
155
+
156
+ // if not intialized yet: get the params & build the arrays
157
+ if (tinymce.plugins.BramusCssExtras._loaded == undefined) {
158
+
159
+ // get the params
160
+ tinymce.plugins.BramusCssExtras._coreClassesString = tinyMCE.activeEditor.getParam("bramus_cssextras_classesstring", undefined);
161
+ tinymce.plugins.BramusCssExtras._coreIdsString = tinyMCE.activeEditor.getParam("bramus_cssextras_idsstring", undefined);
162
+
163
+ // one of the params was not set, try to get the content_css over XHR (Ajax)
164
+ if ((tinymce.plugins.BramusCssExtras._coreClassesString == undefined) || (tinymce.plugins.BramusCssExtras._coreIdsString == undefined)) {
165
+ this._loadContentCSS(tinyMCE.activeEditor.getParam("content_css", false));
166
+ }
167
+
168
+ // now that we have the params, process 'm
169
+ tinymce.plugins.BramusCssExtras._coreClassesArray = this._processElementsAndShizzle(tinymce.plugins.BramusCssExtras._coreClassesString.split(';'));
170
+ tinymce.plugins.BramusCssExtras._coreIdsArray = this._processElementsAndShizzle(tinymce.plugins.BramusCssExtras._coreIdsString.split(';'));
171
+
172
+ // debug
173
+ // console.log(tinymce.plugins.BramusCssExtras._coreClassesArray);
174
+ // console.log(tinymce.plugins.BramusCssExtras._coreIdsArray);
175
+
176
+ }
177
+
178
+ // hook plugin to nodeChange event
179
+ ed.onNodeChange.add(this._nodeChange, this);
180
+
181
+ // hook Commands
182
+ ed.addCommand('bceClass', function(ui, v) {
183
+ this._execCommand(ed, v, this._coreClassesDropdown, "class");
184
+ }, this);
185
+
186
+ ed.addCommand('bceId', function(ui, v) {
187
+ this._execCommand(ed, v, this._coreIdsDropdown, "id");
188
+ }, this);
189
+
190
+ // set loaded
191
+ tinymce.plugins.BramusCssExtras._loaded = true;
192
+ },
193
+
194
+ /**
195
+ * loadContentCSS function : loads in the content_css over XHR
196
+ * ---------------------------------------------------------------------------------------------------
197
+ */
198
+
199
+ _loadContentCSS : function(content_css) {
200
+
201
+ // only proceed if content_css is set
202
+ if (content_css == false) {
203
+ return;
204
+ }
205
+
206
+ // create nex XHR object
207
+ if (window.XMLHttpRequest) {
208
+ this._xmlhttp = new XMLHttpRequest();
209
+ } else if (window.ActiveXObject) {
210
+ this._xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
211
+ }
212
+
213
+ // var which will hold all data from all files referred through content_css
214
+ content_css_data = "";
215
+
216
+ // make sure it's an object
217
+ if (typeof(this._xmlhttp) == 'object') {
218
+
219
+ // content_css exists?
220
+ if (content_css && (content_css != null) && (content_css != "")) {
221
+
222
+ // support the referring of multiple classes
223
+ content_css_arr = content_css.split(',');
224
+
225
+ // loop all referred css files
226
+ for (i = 0; i < content_css_arr.length; i++) {
227
+
228
+ // load it in, but <<<< SYNCHRONOUS >>>>
229
+ // this._xmlhttp.onreadystatechange = this._doneLoadContentCSS; // SYNCHRONOUS, no need to set onreadystatechange!
230
+ this._xmlhttp.open('GET', this._trim(content_css_arr[i]), false); // false == SYNCHRONOUS ;-)
231
+ this._xmlhttp.send(null);
232
+
233
+ // wait for it to load
234
+ if (this._xmlhttp.readyState == 4) {
235
+
236
+ // loaded!
237
+ if (this._xmlhttp.status == 200) {
238
+
239
+ // get the responseText
240
+ this._xmlhttpresponse = this._xmlhttp.responseText;
241
+
242
+ // run some prelim regexes on them
243
+ this._xmlhttpresponse = this._xmlhttpresponse.replace(/(\r\n)/g, ""); // get all CSS rules on 1 line per selector : 1 line on whole document
244
+ this._xmlhttpresponse = this._xmlhttpresponse.replace(/(\})/g, "}\n"); // get all CSS rules on 1 line per selector : 1 line per selector
245
+ this._xmlhttpresponse = this._xmlhttpresponse.replace(/\{(.*)\}/g, ""); // strip out css rules themselves
246
+ this._xmlhttpresponse = this._xmlhttpresponse.replace(/\/\*(.*)\*\//g, ""); // strip out comments
247
+ this._xmlhttpresponse = this._xmlhttpresponse.replace(/\t/g, ""); // strip out tabs
248
+
249
+ content_css_data += this._xmlhttpresponse + "\n";
250
+
251
+ // not loaded!
252
+ } else {
253
+ tinyMCE.activeEditor.windowManager.alert("[bramus_cssextras] Error while loading content_css file '" + content_css_arr[i] + "', make sure the path is correct!");
254
+ }
255
+ }
256
+ }
257
+
258
+ // clear the xhr object
259
+ this._xmlhttp = null;
260
+
261
+ }
262
+ }
263
+
264
+ // process the content_css_data (only if the vars are not set yet - viz. don't overwrite)
265
+ if (tinymce.plugins.BramusCssExtras._coreClassesString == undefined) {
266
+ tinymce.plugins.BramusCssExtras._coreClassesString = this._processContentCSSMatches(content_css_data, ".");
267
+ }
268
+
269
+ if (tinymce.plugins.BramusCssExtras._coreIdsString == undefined) {
270
+ tinymce.plugins.BramusCssExtras._coreIdsString = this._processContentCSSMatches(content_css_data, "#");
271
+ }
272
+
273
+
274
+ },
275
+
276
+ /**
277
+ * processContentCSSMatches function : processes the matches loaded over XHR
278
+ * ---------------------------------------------------------------------------------------------------
279
+ */
280
+
281
+ _processContentCSSMatches : function(content_css_data, identifier) {
282
+
283
+ // split da sucker!
284
+ if (identifier == ".") {
285
+ matches = content_css_data.match(/([a-zA-Z0-9])+(\.)([a-zA-Z0-9_\-])+(\b)?/g);
286
+ } else {
287
+ matches = content_css_data.match(/([a-zA-Z0-9])+(\#)([a-zA-Z0-9_\-])+(\b)?/g);
288
+ }
289
+
290
+ // got any matches?
291
+ if (!matches) {
292
+ return "";
293
+ } else {
294
+ arr_selectors = new Array();
295
+ arr_values = new Array();
296
+ }
297
+
298
+ // run matches and build selectors and values arrays.
299
+ for (var i = 0; i < matches.length; i++) {
300
+
301
+ // split on the identifier
302
+ matches[i] = matches[i].split(identifier);
303
+
304
+ var position = this._inArray(((matches[i][0] != "ul")?matches[i][0]:"li") + "::" + ((matches[i][0] != "ul")?"self":matches[i][0]), arr_selectors);
305
+
306
+ // not found : add selector and classes/ids
307
+ if (position === false) {
308
+ arr_selectors.push(((matches[i][0] != "ul")?matches[i][0]:"li") + "::" + ((matches[i][0] != "ul")?"self":matches[i][0]));
309
+ arr_values.push(matches[i][1]);
310
+
311
+ // found, adjust ids on position
312
+ } else {
313
+ // extra check: check if ain't class/id isn't in values yet!
314
+ if (this._inArray(matches[i][1], arr_values[position].split(',')) === false) {
315
+ arr_values[position] = arr_values[position] + "," + matches[i][1];
316
+ }
317
+ }
318
+
319
+ }
320
+
321
+ // build the elmsAndShizzleArray (Shizzle being either Ids or Classes)
322
+ var elmsAndShizzleArray = new Array();
323
+
324
+ for (var i = 0; i < arr_selectors.length; i++) {
325
+ elmsAndShizzleArray.push(arr_selectors[i] + "[" + arr_values[i] + "]");
326
+ }
327
+
328
+ return elmsAndShizzleArray.join(';');
329
+ },
330
+
331
+ /**
332
+ * processMatches
333
+ * ---------------------------------------------------------------------------------------------------
334
+ */
335
+
336
+ _processElementsAndShizzle : function(elmsAndShizzleArray) {
337
+
338
+ // create new array to hold the real stuff
339
+ coreArray = new Array();
340
+
341
+ // if no array passed in, return an empty array!
342
+ if (!elmsAndShizzleArray) {
343
+ return coreArray;
344
+ }
345
+
346
+ // loop the entries of elmsAndClassesArray
347
+ if (elmsAndShizzleArray.length > 0) {
348
+ for (var i = 0; i < elmsAndShizzleArray.length; i++) {
349
+
350
+ // check if syntax is correct and get data from the entry
351
+ var elmAndShizzleString = elmsAndShizzleArray[i];
352
+ var elmAndShizzleArray = elmAndShizzleString.match(/(.*)::(.*)\[(.*)\]/);
353
+
354
+ // got less than 4 matches : invalid entry!
355
+ if ((!elmAndShizzleArray) || (elmAndShizzleArray.length < 4)) {
356
+
357
+ // nothing
358
+
359
+ // found 4 matches : valid entry!
360
+ } else{
361
+
362
+ // get elementNodeName, parentElementNodeName, elementClasses and push them on the arrayz!
363
+ coreArray.push(new Array(elmAndShizzleArray[1], elmAndShizzleArray[2], elmAndShizzleArray[3].split(',')));
364
+ }
365
+ }
366
+ }
367
+
368
+ // return it
369
+ return coreArray;
370
+ },
371
+
372
+ /**
373
+ * createControl function
374
+ * ---------------------------------------------------------------------------------------------------
375
+ */
376
+
377
+ _createControl : function (n, cm) {
378
+
379
+ switch(n) {
380
+
381
+ // bramus_cssextras_classes
382
+ case "bramus_cssextras_classes":
383
+
384
+ // create a dropdown
385
+ ddm = cm.createListBox('bramus_cssextras_classes_dropdown_' + tinyMCE.activeEditor.id, {
386
+ title : '.class',
387
+ cmd : 'bceClass'
388
+ });
389
+
390
+ // keep a reference to it in our own instance!
391
+ this._coreClassesDropdown = ddm;
392
+
393
+ // return it
394
+ return ddm;
395
+
396
+ break;
397
+
398
+ // bramus_cssextras_ids
399
+ case "bramus_cssextras_ids":
400
+
401
+ // create a dropdown
402
+ ddm = cm.createListBox('bramus_cssextras_ids_dropdown_' + tinyMCE.activeEditor.id, {
403
+ title : '#id',
404
+ cmd : 'bceId'
405
+ });
406
+
407
+ // keep a reference to it in our own instance!
408
+ this._coreIdsDropdown = ddm;
409
+
410
+ // return it
411
+ return ddm;
412
+
413
+ break;
414
+
415
+ }
416
+
417
+ return null;
418
+ },
419
+
420
+
421
+ /**
422
+ * nodeChange Function : event which gets triggered when the node has changed
423
+ * ---------------------------------------------------------------------------------------------------
424
+ */
425
+
426
+ _nodeChange : function(ed, cm, n) {
427
+
428
+ // save your energy : check if ed.id equals tinyMCE.activeEditor.id
429
+ if (tinyMCE.activeEditor.id != ed.id) {
430
+ return;
431
+ }
432
+
433
+ // save your energy : no node select : return!
434
+ if (n == null)
435
+ return;
436
+
437
+ // save your energy : check if node differs from previousnode. If not, then we don't need to loop this all again ;-)
438
+ if (n == this._previousNode) {
439
+ return;
440
+ } else {
441
+ this._previousNode = n;
442
+ }
443
+
444
+ // check if current elem has a match in the _coreArrayClasses or _coreArrayIds
445
+ var gotHitClass = this._checkHit(tinymce.plugins.BramusCssExtras._coreClassesArray);
446
+ var gotHitIds = this._checkHit(tinymce.plugins.BramusCssExtras._coreIdsArray);
447
+
448
+ // now do something with that hit and that dropdown!
449
+ this._rebuildDropdown(gotHitClass, this._coreClassesDropdown, "class", ed);
450
+ this._rebuildDropdown(gotHitIds, this._coreIdsDropdown, "id", ed);
451
+
452
+ },
453
+
454
+
455
+ /**
456
+ * checkHit : checks if the current node matches any of the arrays
457
+ * ---------------------------------------------------------------------------------------------------
458
+ */
459
+ _checkHit : function(coreArray) {
460
+
461
+ // correarray not null?
462
+ if (coreArray) {
463
+ for (var i = 0; i < coreArray.length; i++) {
464
+ if (coreArray[i][0].toLowerCase() == this._previousNode.nodeName.toLowerCase()) {
465
+ return coreArray[i];
466
+ }
467
+ }
468
+ }
469
+
470
+ return null;
471
+
472
+ },
473
+
474
+
475
+ /**
476
+ * rebuildDropdown : rebuilds the dropdowns and makes it so that the correct value is selected
477
+ * ---------------------------------------------------------------------------------------------------
478
+ */
479
+ _rebuildDropdown : function(gotHit, selectDropDown, what, ed) {
480
+
481
+ if (gotHit === null) {
482
+
483
+ // only continue if a dropdown is present!
484
+ if (selectDropDown) {
485
+
486
+ // remove existing items
487
+ selectDropDown.items = [];
488
+
489
+ // TinyMCE fix - TIP : Moxiecode should provide a neat way to removing all items!
490
+ selectDropDown.oldID = null;
491
+
492
+ // select nothing
493
+ selectDropDown.select();
494
+
495
+ // disable the dropdown
496
+ selectDropDown.setDisabled(true);
497
+
498
+ }
499
+
500
+ } else {
501
+
502
+ // get params from gotHit
503
+ var elemNodeName = gotHit[0];
504
+ var parentElemNodeName = gotHit[1];
505
+ var elementClasses = gotHit[2];
506
+
507
+ // continue if parentElemNodeName equals self, or if parent node equals parentElemNodeName
508
+ if ((parentElemNodeName == "self") || (ed.dom.getParent(this._previousNode, parentElemNodeName).nodeName.toLowerCase() == parentElemNodeName)) {
509
+
510
+ // remove existing items
511
+ selectDropDown.items = [];
512
+
513
+ // TinyMCE fix - TIP : Moxiecode should provide a neat way to removing all items!
514
+ selectDropDown.oldID = null;
515
+
516
+ // push on the new ones (and enforce first one)
517
+ selectDropDown.add('[ no ' + what + ' ]', parentElemNodeName + "::");
518
+
519
+ // select nothing
520
+ selectDropDown.select();
521
+
522
+ // fill the dropdown with the values
523
+ for (var i = 0; i < elementClasses.length; i++) {
524
+
525
+ selectDropDown.add(elementClasses[i], parentElemNodeName + "::" + elementClasses[i]);
526
+
527
+ // this node or the parent node?
528
+ if (parentElemNodeName == "self") {
529
+ var pNode = this._previousNode;
530
+ } else {
531
+ var pNode = ed.dom.getParent(this._previousNode, parentElemNodeName);
532
+ }
533
+
534
+ // if the instance currently has this class, set this option as selected
535
+ switch(what) {
536
+ case "class":
537
+ if (ed.dom.hasClass(pNode, elementClasses[i])) {
538
+ selectDropDown.select(parentElemNodeName + "::" + elementClasses[i]);
539
+ }
540
+ break;
541
+ case "id":
542
+ if (pNode.id == elementClasses[i]) {
543
+ selectDropDown.select(parentElemNodeName + "::" + elementClasses[i]);
544
+ }
545
+ break;
546
+ }
547
+
548
+ }
549
+
550
+ }
551
+
552
+ // render the selectdropdown
553
+ selectDropDown.renderMenu();
554
+
555
+ // enable the selectbox!
556
+ selectDropDown.setDisabled(false);
557
+
558
+ }
559
+
560
+ },
561
+
562
+ _execCommand : function(ed, listValue, selectDropDown, what) {
563
+
564
+ // this node or the parent node?
565
+ if (listValue.split("::")[0] == "self") {
566
+ var node = ed.selection.getNode();
567
+ } else {
568
+ var node = ed.dom.getParent(ed.selection.getNode(), listValue.split("::")[0]);
569
+ }
570
+
571
+ // begin Undo
572
+ tinyMCE.execCommand('mceBeginUndoLevel');
573
+
574
+ // define what to set class or id to
575
+ toSetTo = (listValue.split("::")[1] != undefined)?listValue.split("::")[1]:"";
576
+
577
+ // set className
578
+ if (what == "class") {
579
+ node.className = toSetTo;
580
+
581
+ // set id
582
+ } else {
583
+
584
+ // toSetTo is not empty : perform a check if an element with that id already exists
585
+ if (toSetTo != "") {
586
+
587
+ // there already exists an element with that id?
588
+ if (ed.getDoc().getElementById(toSetTo)) {
589
+
590
+ // confirm the move of the id
591
+ if (confirm("There already exists an element with that id, ids must be unique.\nPress 'OK' to move the id to the current element.\nPress 'Cancel' to leave unchanged")) {
592
+
593
+ // remove id from current element with that id
594
+ ed.getDoc().getElementById(toSetTo).id = "";
595
+
596
+ // set id on node
597
+ node.id = toSetTo;
598
+
599
+ // not confirmed, set selectedindex of node to the first item
600
+ } else {
601
+
602
+ // select the first item
603
+ selectDropDown.select(listValue.split("::")[0] + '::');
604
+
605
+ // stop the click event
606
+ // console.log(tinymce.dom.Event.events);
607
+ tinymce.dom.Event.cancel(tinymce.dom.Event.events[0]); // BUG! - this ain't workin :-( ... how can I cancel the current event (viz. the click on the item in the ListBox)?
608
+ }
609
+
610
+ // no element with that id exists yet : set the id
611
+ } else {
612
+
613
+ // set id on node
614
+ node.id = toSetTo;
615
+ }
616
+
617
+ // toSetTo is empty : clear the id on the selected element
618
+ } else {
619
+
620
+ // set id on node
621
+ node.id = toSetTo;
622
+ }
623
+ }
624
+
625
+ // endUndo
626
+ tinyMCE.execCommand('mceEndUndoLevel');
627
+
628
+ // repaint the instance
629
+ ed.execCommand('mceRepaint');
630
+
631
+ // This is needed?
632
+ // EditorManager.activeEditor.nodeChanged();
633
+
634
+ },
635
+
636
+
637
+ /**
638
+ * End Of Plugin (EOP)
639
+ * ---------------------------------------------------------------------------------------------------
640
+ */
641
+
642
+ // The last one (so I don't forget to close)
643
+ EOP : true
644
+
645
+ });
646
+
647
+ // Register plugin
648
+ tinymce.PluginManager.add('bramus_cssextras', tinymce.plugins.BramusCssExtras);
649
+ })();