I try to instantiate a class when the page loads, but when I happened
on most browsers, I can not do it in Internet Explorer 7 or 6
I call the script in my template, like this:
<script type="text/javascript" src="/js/veicoli-random.class.js"></
script>
<script type="text/javascript">
new VeicoliRandom('wrap-cont_veicoli_random',
'cont_veicoli_random', '{$url_pagina}');
</script>
And the script contains:
Random = Class.create();
Random.prototype = {
wrap : null,
nomeWrap : null,
container : null,
nomeContainer : null,
url : null,
initialize : function(wrap, container, url)
{
this.wrap = $(wrap);
this.nomeWrap = wrap;
this.container = $(container);
this.nomeContainer = container;
this.url = url;
if ( this.url == '' )
this.url = '/';
if (!this.container || !this.wrap)
return;
this.arrotola.bind(this).delay(10);
},
arrotola : function()
{
// nascondo la scritta sold, per IE
var ElementiNIE = $$('#' + this.nomeContainer + ' div.timbro-venduto-
random');
ElementiNIE.each( function(div) {
div.addClassName('invisibileIE');
});
// arrotolo su
Effect.BlindUp(this.wrap, { duration: 3 });
this.aggiorna.bind(this).delay(5);
},
aggiorna : function ()
{
// aggiorno
var options = {onComplete : this.srotola.bind(this).delay(1)};
new Ajax.Updater(this.container, this.url, options);
},
srotola : function()
{
this.wrap.setStyle({ display: 'none' });
// srotolo giù
Effect.BlindDown(this.wrap, { duration: 3 });
this.arrotola.bind(this).delay(15);
},
};
Object.extend(document, {
isDocReady: false,
isDocLoaded: false,
ready: function(fn) { Event.observe(document, "doc:ready", fn); },
load: function(fn) { Event.observe(document, "doc:loaded", fn); }
});
Event.observe(document, "dom:loaded", function() {
Event.fire(document, "doc:ready");
document.isDocReady = true;
if (document.isDocLoaded)
Event.fire(document, "doc:loaded");
});
Event.observe(window, "load", function() {
document.isDocLoaded = true;
if (!document.isDocReady) return;
Event.fire(document, "doc:loaded");
});
// fa partire la vera classe al load della pagina
VeicoliRandom = Class.create();
VeicoliRandom.prototype = {
initialize : function(wrap, container, url)
{
// Event.observe(window, 'load', new Random(wrap, container, url));
//document.observe('dom:loaded', new Random(wrap, container, url));
document.load( a = new Random(wrap, container, url) );
},
};
I can not understand why the class called "random" is not instantiated
or otherwise IE does nothing.
While with fire-fox or other browsers, seems to work properly.
What could be my mistake?
Thank you for your attention.
Regards Loris
I think that your trouble is normal, because IE don't allow to
instantiate method on native object.
Generally it's not a good idea to extend native objects because your
not sure that another JS will not use the same method name !!
--
david
On Dec 23, 4:17 am, david <david.brill...@gmail.com> wrote:
> Hi Loris,
>
> I think that your trouble is normal, because IE don't allow to
> instantiate method on native object.
You might need to re-think that statement. From ECMA-262:
"Native Object
"A native object is any object supplied by an ECMAScript
implementation independent of the host environment. Standard native
objects are defined in this specification. Some native objects are
built-in;others may be constructed during the course of execution of
an ECMAScript program."
Can you imagine the ramifications of IE not allowing native objects to
have methods? :-)
Perhaps you meant host object. But if that were true, most of
Prototype.js would not work at all in IE.
> Generally it's not a good idea to extend native objects because your
> not sure that another JS will not use the same method name !!
Perhaps you did mean host object. Yes, it's a bad idea to add *non-
standard* properties to host objects. How do you reconcile that notion
with the use of Prototype.js's $() function?
--
Rob
Thanks to point it out, all should read HOST OBJECT :))
> Can you imagine the ramifications of IE not allowing native objects to
> have methods? :-)
No, I prefer not thinking to that. IE have so much pain for developper
that it didn't need this one.
--
david