public
Description: Plug-in / filter for Frog CMS: WYMeditor
Homepage:
Clone URL: git://github.com/them/frog_wymeditor.git
them (author)
Fri Jul 17 11:35:03 -0700 2009
commit  77d596704d311f737f6030e5b6f89c1c522459bc
tree    e27ab2dd66dab45b6ba34ebbcbea40b7bdeef693
parent  5bcaa56618e830f09d4ac366d150f1914c068349
frog_wymeditor / frog_wymeditor.js
100644 74 lines (62 sloc) 3.25 kb
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
// Preserve the Frog backend function. This plug-in is going to overwrite this function,
// but the original function will be called after a custom functio is called.
var origin_function = setTextAreaToolbar;
 
// This function replaces the Frog 'setTextAreaToolbar' if the editor is used.
// Cleans up the WYMeditor. Later the original Frog function is called.
wymeditor_setTextAreaToolbar = function(textarea, filter) {
  jQuery.each(WYMeditor.INSTANCES, function() {
    // Check if the editor is still active
    if (this && this._doc && this._element.attr('id') == textarea && filter != "wymeditor") {
      // Remove the editor
      this.update();
      $(this._box).remove();
      delete this;
    }
  });
 
  // call origin function, but keep this function maybe there is more than one instance
  origin_function(textarea, filter);
};
 
// Forces all instances of the editor to update their content to the Frog text fields.
wymeditor_update_all = function() {
  jQuery.each(WYMeditor.INSTANCES, function() {
    // Only if editor is still there, store the content to the origin textarea
    if (this._doc) {
      this.update();
    }
  });
};
 
// Fix for wymeditor. Frog uses the <base href=""/>, but the wymeditor does not use this feature.
// TODO: raise a defect against the original wymeditor code base, then remove this workaround
 
// 1. get the base path from the current page
var wymeditor_frog_base = jQuery('base').attr('href') || "";
 
// 2. store the wymeditor fuctions
var wymeditor_origin_computeBasePath = WYMeditor.editor.prototype.computeBasePath;
var wymeditor_origin_computeWymPath = WYMeditor.editor.prototype.computeWymPath;
var wymeditor_origin_computeJqueryPath = WYMeditor.editor.prototype.computeJqueryPath;
var wymeditor_origin_computeCssPath = WYMeditor.editor.prototype.computeCssPath;
 
// 3. route the function to the new destination
WYMeditor.editor.prototype.computeBasePath = function() { return wymeditor_frog_base + wymeditor_origin_computeBasePath();};
WYMeditor.editor.prototype.computeWymPath = function() { return wymeditor_frog_base + wymeditor_origin_computeWymPath(); };
WYMeditor.editor.prototype.computeJqueryPath = function() { return wymeditor_frog_base + wymeditor_origin_computeJqueryPath(); };
WYMeditor.editor.prototype.computeCssPath = function() { return wymeditor_frog_base + wymeditor_origin_computeCssPath(); };
 
// Frog backend function to activate the WYMeditor. Used the Prototype JS library.
Control.TextArea.ToolBar.Wymeditor = Class.create();
Object.extend(Control.TextArea.ToolBar.Wymeditor.prototype,{
  toolbar: false,
 
  initialize: function(textarea, options) {
    // We do not use the frog infrastructure
    this.toolbar = { container: {} };
 
    // Overwrite change function to hook in a 'destroy' function
    setTextAreaToolbar = wymeditor_setTextAreaToolbar;
 
    // Create the editor
    jQuery('#'+textarea).wymeditor({
      // The language is set from the backend
      lang: frog_wymeditor_language,
      skin: 'frog',
      stylesheet: frog_wymeditor_stylesheet
    });
    
    // Register update event, could be added more than once (multiple page parts),
    // but this should be no problem
    jQuery('form:first').bind('submit', wymeditor_update_all);
  }
});