Permalink
Browse files

Fix Xinha.

Update the JavaScript code to only load the editors when they're made visible.
This is a little fragile, since if we change the structure of the HTML at all,
we'll need to make sure that the Xinha code is updated to take advantage of
the new structure. That is, CSS selectors passed to `Element.select()` would
need to be updated.

Not sure if htmlArea or FCKEditor need to be updated, as well. [#217 state:resolved].
  • Loading branch information...
1 parent a87dc58 commit 75b2415f32627ae86aa3807c470d04c7c3b43ea4 @theory theory committed Dec 9, 2010
Showing with 43 additions and 11 deletions.
  1. +1 −1 .gitignore
  2. +11 −5 comp/media/js/lib.js
  3. +4 −2 comp/widgets/profile/displayFormElement.mc
  4. +27 −3 comp/widgets/wysiwyg/xinha.html
View
@@ -1,4 +1,4 @@
Makefile
inst/*.sql
comp/data/
-
+comp/media/wysiwyg
View
@@ -1728,21 +1728,27 @@ var Container = {
},
toggle: function( eid, anchor ) {
- Effect.toggle('element_' + eid, 'blind', {duration: 0.3});
- var hint_element = $('element_' + eid + '_hint');
- if (hint_element) {
- Effect.toggle(hint_element, 'blind', {duration: 0.3});
- }
var displayed = $('container_' + eid + '_displayed');
+ var afterFinish;
if ( displayed.value == '0' ) {
// Display it.
anchor.innerHTML = '▼';
displayed.value = '1';
+ if (typeof Xinha != 'undefined') {
+ // Load Xinha editors. Nasty and fragile. :-(
+ afterFinish = function () { start_xinhas_below('element_' + eid) };
+ }
} else {
// Hide it.
anchor.innerHTML = '▶';
displayed.value = '0';
}
+
+ Effect.toggle('element_' + eid, 'blind', {duration: 0.3, afterFinish: afterFinish});
+ var hint_element = $('element_' + eid + '_hint');
+ if (hint_element) {
+ Effect.toggle(hint_element, 'blind', {duration: 0.3});
+ }
return false;
}
};
@@ -379,11 +379,13 @@ my %formSubs = (
$out .= qq{ <div class="input">\n} if $useTable;
if (!$readOnly) {
+ my $class = 'textArea';
+ $class .= ' wysiwyg' if ENABLE_WYSIWYG;
$js = $js ? " $js" : '';
$out .= qq{ <textarea name="$key" id="$key" rows="$rows" cols="$cols" width="200"}
- . qq{ wrap="soft" class="textArea"$js>$value</textarea><br />\n};
+ . qq{ wrap="soft" class="$class"$js>$value</textarea><br />\n};
- if (ENABLE_WYSIWYG) {
+ if (ENABLE_WYSIWYG && lc WYSIWYG_EDITOR ne 'xinha') {
my $code = lc WYSIWYG_EDITOR eq 'js-quicktags'
? "edToolbarBric('$key');"
: "editors.push('$key');";
@@ -18,10 +18,34 @@
xinha_config = xinha_config ? xinha_config : new Xinha.Config();
xinha_config.toolbar = <% XINHA_TOOLBAR %>;
-
- var xinha_editors = Xinha.makeEditors(editors, xinha_config, xinha_plugins);
- Xinha.startEditors(xinha_editors);
+ // Load visible xinha fields.
+ start_xinhas_below($$('#containerprof > .content > .elements').first().id);
+ }
+
+ function start_xinhas_below(eid) {
+ // Nasty and fragile. We only load Xinha editors when they become visible.
+ // http://www.xinha.org/punbb/viewtopic.php?id=2809
+ // Also called from Container.toggle() in lib.js.
+ // These variables may need to be adjusted if the element structure
+ // changes.
+ var csel = ' > .container > .content > fieldset > .elements';
+ var fsel = ' > li > div > .wysiwyg';
+
+ var containers = $$('#' + eid);
+ while (containers.size() > 0) {
+ var c = containers.shift();
+ var fields = $$('#' + c.id + fsel);
+ if (fields.size() > 0) {
+ Xinha.startEditors(Xinha.makeEditors(fields, xinha_config, xinha_plugins));
+ };
+ // Add any visible subelements to the list.
+ $$('#' + c.id + csel).each(function (e) {
+ if (e.visible()) {
+ containers.push(e);
+ }
+ });
+ }
}
Event.observe(window, "load", xinha_init);

0 comments on commit 75b2415

Please sign in to comment.