Opened 9 years ago

Closed 9 years ago

#403 closed defect (fixed)

Patch for prototype.js library compatibility

Reported by: drifter@… Owned by: gogo
Priority: normal Milestone:
Component: Xinha Core Version: trunk
Severity: normal Keywords:
Cc:

Description

The Prototype javascript library (http://prototype.conio.net/) is unfortunately incompatible with the current Xinha. It's a great library for Ajax, and it's fully integrated with the Ruby on Rails framework. I wanted to use both in my Rails project, so I created this patch.

The Prototype library does some of its magic by extending the Object prototype, like so:

Object.prototype.extend = function(object) {

for (property in object) {

this[property] = object[property];

}
return this;

}

This adds an 'extend' function to every object. Elegant for some things, but it can break existing apps when they try to loop over arrays, for instance. Xinha already has type checks in many places, but not everywhere, so this breaks Xinha. I've added some type checks in several places - now it works well, at least the editor shows and all the default buttons work as advertised. I'm attaching a patch against revision 258.

Attachments (3)

htmlarea.diff (15.1 KB) - added by drifter@… 9 years ago.
diff against revision 258
htmlarea-2.diff (4.0 KB) - added by Zoltan 9 years ago.
new diff with cleaner code against revision 278.
about_popup.patch (635 bytes) - added by ray 9 years ago.

Download all attachments as: .zip

Change History (10)

Changed 9 years ago by drifter@…

diff against revision 258

comment:1 Changed 9 years ago by gogo

Rather than this patch, which introduces a lot of spurious changes due to the way it wraps stuff in an if block and reindents, it would be better to use a pattern like

for(var i in x)
{
  if(!x[i].whatever_you_are_expecting) continue;
  ... normal stuff ...
}

that way you only add one line to the offending for block and don't change any indentation.

Also you might be better to use (after examining each case for suitability)

  if(typeof x[i] == 'function') continue;

to simply skip function members of an object.

comment:2 Changed 9 years ago by Zoltan

All right, here's a new one then. Tested on Firefox/Mac? and IE6/Win. I hope it could also increase stability and compatibility with other scripts...

Changed 9 years ago by Zoltan

new diff with cleaner code against revision 278.

comment:3 Changed 9 years ago by Artus

In the about popup htmlarea uses another for ( in ) loop, to iterate over the available plugins.

Adding:

    if (typeof info != 'object' || !info.name || typeof info.name !='string')
        continue;

in initDocument like this:

  for (var i in editor.plugins) 
  {
    var info = editor.plugins[i];
    if (typeof info != 'object' || !info.name || typeof info.name !='string')
        continue;

  ...

should solve the problem.

comment:4 Changed 9 years ago by gogo

Applied in changeset:396

comment:5 Changed 9 years ago by gogo

  • Resolution set to fixed
  • Status changed from new to closed

Changed 9 years ago by ray

comment:6 Changed 9 years ago by ray

  • Resolution fixed deleted
  • Status changed from closed to reopened

It was broken, see the patch

comment:7 Changed 9 years ago by gocher

  • Resolution set to fixed
  • Status changed from reopened to closed

fixed in changeset 441

Note: See TracTickets for help on using tickets.