Forum: Rails Spinoffs (closed, excessive spam) Extend element with Prototype's functions

Posted by AlannY (Guest)
on 2008-07-01 15:51
(Received via mailing list)
Hi there. I have very specific problem with Prototype.

I'm getting selection of document and make a range from it. It's
simple. But I'm receiving not extended elements from
<range.startContainer>. Ok. That's fine. I would like to add
prototype's functions to this element.

var container = range.startContainer;
container = Element.extend(container); // NOT WORKS!
// container still not have Prototype function, like childElements ;-(

How to extend DOM element with Prototype properly?

P.S. In any case, I can live without this feature, but, as for me,
it's better to use Prototype anywhere ;-) but not browser specific
features ;-)
Posted by Frederick Polgardy (Guest)
on 2008-07-01 16:04
(Received via mailing list)
What is range.startContainer?  Are you sure it's an element?

-Fred

On Tue, Jul 1, 2008 at 8:50 AM, AlannY <m@alanny.ru> wrote:

>
> Hi there. I have very specific problem with Prototype.
>
> I'm getting selection of document and make a range from it. It's
> simple. But I'm receiving not extended elements from
> <range.startContainer>. Ok. That's fine. I would like to add
> prototype's functions to this element.



--
Science answers questions; philosophy questions answers.
Posted by AlannY (Guest)
on 2008-07-01 17:39
(Received via mailing list)
Yes, it's an element

var container = range.startContainer;
alert(container.tagName); // OK

This elements from iframe, where Prototype is not loaded, so, I want
to extend element manually ;-)
Posted by kangax (Guest)
on 2008-07-01 21:54
(Received via mailing list)
This should work in browsers which expose "prototype" of host objects
(e.g. any recent gecko, webkit, etc.):

var r = document.createRange();
var proto = r.startContainer.constructor.prototype;

for (var prop in Element.Methods) {
  if (!Object.isFunction(Element.Methods[prop])) continue;
  proto[prop] = Element.Methods[prop].methodize();
}

-- kangax
Posted by AlannY (Guest)
on 2008-07-02 13:32
(Received via mailing list)
Thanks, will try soon ;-)
This topic is locked and can not be replied to.