[Proto-Scripty] findElements querySelectorAll error

2009-05-20 Thread pmac

i'm call the down function but am getting an invalid argument using
1.6.1_rc2

here's the html snippet:

TR id=00214A class=activeRow searchResultsDisplayOver
conceptID=001KIU
TD
DIV class=gridRowWrapper
SPAN class=SynDescAsymmetric breasts/SPAN
DIV class=buttonWrapper
SPAN class=btnAddFav title=Add to Favoritesnbsp;/
SPAN
/DIV
/DIV
/TD
/TR

here's the code:
var description = row.down('span.SynDesc').innerHTML;

row is a dom reference to the tr element.

the prototype is appending a # then the id of the tr element:

findElements: function(root) {
root = root || document;
var e = this.expression, results;

switch (this.mode) {
  case 'selectorsAPI':
if (root !== document) {
  var oldId = root.id, id = $(root).identify();
  id = id.replace(/[\.:]/g, \\$0);
  e = # + id +   + e;
}

results = $A(root.querySelectorAll(e)).map(Element.extend);
-- e = #00214A span.SynDesc
root.id = oldId;

return results;
  case 'xpath':
return document._getElementsByXPath(this.xpath, root);
  default:
   return this.matcher(root);
}

i get an invalid argument error?

if i put a breakpoint before the offending line and change e to be
equal to span.SynDesc it works fine.

help. :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] fatal error on the page under IE7 when a script can't run till its end = scriptaculous scripts stop to work

2009-05-20 Thread itkin

Hello,

I'm deseperately looking for the solution of a weird behavior on IE7.

I've this function, executed dynamically from a rjs (ror) template.
Basically it slides down a list of produts labels, one after this
other, in a wave maner.

function slideLabelsDown(labelsContainer){
Effect.multiple($(labelsContainer).select('.sale_item_label'),
Effect.SlideDown, {
transition:Effect.Transitions.spring,
speed:0.25,
duration:5});
$('top_sale_item_labels_ajax_wrapper').fade({delay:0.3,duration:
0.2});
}

Well the duration of this script is supposed to be 5 seconds, but when
you click on some other link before the function ends, you got the
following error only on IE :

Line 699
Char 7
'element.down()' is null or not an object

As far as I understand it doesn't find the current element to slide
down because it has been dynamically removed with all the page sub
content

So the error raises and then scipt aculous framework just stop
working. This is really problematic for me since i use its functions
intensivelly in quite every ajax call .

Does anybody know how to prevent or handle this kind exception?? try
{} catch(){} doesn't work ..

Thanks in advance !!


Nicolas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Observe onmouseover and onmouseout with IE6

2009-05-20 Thread Dravis

I have this bit of code in my webpage's header.  It simply pulls all
the li elements from the mainmenu and attaches onmouseover and
onmouseout event observers to them to toggle the drop down effects of
the menu.  It works perfectly in IE7 and Firefox but when I mouse over
the menu in IE6 I get nothing.  Anyone have any ideas?

document.observe(dom:loaded, function() {
$$('#mainmenu li').each(function(item) {
$(item).observe(onmouseover, function() {
$(this).addClassName(sfhover);
}.bind(this));
$(item).observe(onmouseout, function() {
$(this).removeClassName(sfhover);
}.bind(this));
});
});

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Problem with this binding in class function

2009-05-20 Thread T.J. Crowder

Hi,

 I think I need to use .bind(this) somewhere...

Yup, exactly right.  When you're passing around a reference to a
method for something else to call later, you'll need to bind it to the
instance -- otherwise, it will have the wrong context (this will be
wrong within the function call).  So for instance, instead of:

$(document.body).descendants().invoke
('stopObserving','click',this.outside);

...you'd want

$(document.body).descendants().invoke
('stopObserving','click',this.outside.bind(this));

(You probably will never have need to use bindAsEventListener, details
here[1].)

There's nothing magic about what bind does, it just returns a function
that, when called, calls the original function in a way that sets the
context correctly.

Here's[2] a ueful page from the unofficial Prototype  script.aculo.us
wiki on this.  It also has some links at the end to useful articles
discussing this and context, so you know what's going on under the
covers.

[1] 
http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener
[2] 
http://proto-scripty.wikidot.com/prototype:tip-using-an-instance-method-as-a-callback-or-event-handler

BTW, a terminology point:  In your subject line you talked about a
class function and in your note you talked about class variables.
In each case, looking at your note and code you meant instance
rather than class.  An instance method or variable is one you call
or use on *instances* of a class, whereas a class method or variable
is one you call or use on the class itself.  For example,
Element#observe is an instance method, because you call it on
*instances* of the Element class:

$('someid').observe(...);

But Class.create (for example) is a class method, because you only
call it on the Class class itself:

var MyClass = Class.create(...);

Just FWIW.

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 20, 6:27 am, Dave L dly...@gmail.com wrote:
 I am trying to use pre-existing functions in a new prototype class but
 am having some trouble with binding.  When I call a function within a
 function it says that one of my class variables is undefined.  I have
 defined the class variable correctly I think:

   var DropDown = Class.create({
     initialize: function(date, appt_counter, times, edit_or_add) {
       this.start_drop_id = start_drop_ + date + _ + appt_counter;
     })

 Then in the following outside function, start_drop_id is errored as
 being undefined:

     DropDown.prototype.show_block = function(element_id, element)
 {
       if(document.getElementById(element_id).style.display == block)
 {
         outsideOf = null;
         $(document.body).descendants().invoke
 ('stopObserving','click',this.outside); //stopObserving the outside
 request as we have finished
           document.getElementById(element_id).style.display = none;
       } else {
        outsideOf = element_id;
        document.getElementById(element_id).style.display =
 block;
        $(document.body).descendants().invoke
 ('observe','click',this.outside);
         element.stopObserving('click',this.outside) //need to then
 stop this from observing the outside - ie requires it at least
       };
     };

     DropDown.prototype.outside = function(event) {
       //alert(this.outsideOf)
       this.element = event.element();
       //alert(this.element.id)
       if( outsideOf == null ) {           //this shouldnt happen, but
 just incase
         $(document.body).descendants().invoke
 ('stopObserving','click',this.outside);
         return;
       };
       this.element = Event.element(event);
       if( this.element.descendantOf( $(outsideOf) ) !== true) {
         outsideOf = null;
         $(document.body).descendants().invoke
 ('stopObserving','click',this.outside);

         document.getElementById(this.start_drop_id).style.display =
 none;  //it says this is null
       };
     };

 I think I need to use .bind(this) somewhere or maybe
 bindAsEventListener?  I'm not sure.  This is my first time writing a
 prototype class so I am bit lost.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] AJAX request to XML-RPC webservice

2009-05-20 Thread kfrancoi

Hello everyone,

This is my first intervention in this mailing list.  I have been
looking for a few days on how to call an XML-RPC webservice from a
JavaScript client.

I found a JS librarie (XOAP_Request : http://dsone.nl/xoap/usage.html)
that depend on prototype and that build the XML message to be send
with AJAX.Request().

My webservice is running on port 8000 on my server. My web page is
running on port 80 of the same server.

When I launch the AJAXX request using FireFox, I get the following JS
warning, and nothing happen next :
**
Security Error: Content at http://XXX.XXX.XXX.XXX/client2.html may not
load data from http://XXX.XXX.XXX.XXX:8000/.
**

When I launch the same request using Safari, the request access the
server but it generate an error 501 (message Unsupported method
OPTION).

Using anything else (PHP, Python, ...)  to call my webservice make it
work.

Does someone have a clue of what the problem could be ?

Thank a lot for any help !!

Kevin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: AJAX request to XML-RPC webservice

2009-05-20 Thread T.J. Crowder

Hi,

You're running into something called the Same Origin Policy, details
here.[1]  Basically, you can't use the XmlHttpRequest object to
request resources from a different origin than the page in which the
script is running, and origin includes the port.

[1] http://en.wikipedia.org/wiki/Same_origin_policy

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On May 20, 10:38 am, kfrancoi kfran...@gmail.com wrote:
 Hello everyone,

 This is my first intervention in this mailing list.  I have been
 looking for a few days on how to call an XML-RPC webservice from a
 JavaScript client.

 I found a JS librarie (XOAP_Request :http://dsone.nl/xoap/usage.html)
 that depend on prototype and that build the XML message to be send
 with AJAX.Request().

 My webservice is running on port 8000 on my server. My web page is
 running on port 80 of the same server.

 When I launch the AJAXX request using FireFox, I get the following JS
 warning, and nothing happen next :
 **
 Security Error: Content athttp://XXX.XXX.XXX.XXX/client2.htmlmay not
 load data fromhttp://XXX.XXX.XXX.XXX:8000/.
 **

 When I launch the same request using Safari, the request access the
 server but it generate an error 501 (message Unsupported method
 OPTION).

 Using anything else (PHP, Python, ...)  to call my webservice make it
 work.

 Does someone have a clue of what the problem could be ?

 Thank a lot for any help !!

 Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: IE throws in extra unknown element (!)

2009-05-20 Thread Maarten

Hi guys,

Sorry for having to answer my own question (and so quickly) but I just
found a fix already:

http://code.google.com/p/ie7-js/source/browse/trunk/src/ie7-overflow.js?r=2
A JavaScript library to make MSIE behave like a standards-compliant
browser.

This script seems to clear the styles applied to the element IE7 threw
in.

It seems at first that Prototype was the guilty party, so it's good to
know I can now blame IE ;)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Mouse coods

2009-05-20 Thread david

Hi jk,

this is prototype's work, it always keep the 'this' reference to the
element receiving the event.
Because in JS without prototype, the context is the 'window' object.

--
david

On 19 mai, 23:22, jk jk.lists.questi...@gmail.com wrote:
 How is that we don't loose context in some of those nested callbacks?
 Thanks. --jk
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread ColinFine



On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:
 On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

  This is a case when you really truly want just the facilities that
  Javascript provides (prototypes rather than classes), and using
  (pretend) classes makes it harder not easier.

 Yes, although some may argue that it is better to create a new object
 that has the required methods and leverages the methods of Date,
 rather than modifying a built-in object prototype,

Fair comment. But you are still talking about using Javascript's
prototype, rather than inventing classes. That was my point.
(I wouldn't have made this remark before I read Crockford's
Javascript: The Good Parts - that's opened my eyes to the strengths
that JS has. )

Colin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: script.aculo.us Draggable event priority

2009-05-20 Thread ColinFine



On May 20, 2:59 am, jk jk.lists.questi...@gmail.com wrote:
 Is there a way to make any events registered by Draggable have the
 lowest possible priority?  I have tried to execute new Draggable at
 the last moment, but it still seems to commandeer mousedown event.
 Thanks. --jk

Unfortunately the Level 2 Event system *explicitly* does not define
the order in which different event handlers are evoked on a single
element.

Wwhat I've done in this sort of case (and it's very unsatisfactory) is
to have a state variable which tells me whether another handler is
already working or not, and do the scheduling between them in that
way.

Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Observe onmouseover and onmouseout with IE6

2009-05-20 Thread david

Hi,

Here is the same code that work in FF3.0 and IE6 (could not test other
browser):
document.observe(dom:loaded, function() {
$$('#mainmenu li').each(function(item) {
item.observe(mouseover, function() {
this.addClassName(sfhover);
});
item.observe(mouseout, function() {
this.removeClassName(sfhover);
});
})
});


What are the difference:
- First, your event is for IE only, on+eventName works only on IE, and
prototype help you by appending the 'on' prefix for IE. So I removed
it.
- Next, you'll bind the function to this inside each Observe method.
The 'this' context is forced by prototype to the DOM element the event
happend to, so no need to bind it (or if you need to bind the function
to OTHER specific context).
- Last, I suppress the $(this) by simply this. Prototype is loaded
before the DOM is created, and each element are automatically
extended. It could have a different behaviour if prototype is loaded
after the DOM, but in that case inside the event manipulation,
prototype internally call the $() function to exend the element.
-Finally, there is à }) missing, but I think this is a cut/paste
manipulation error (I'm probably the world champion oif cut/paste
trouble :)) ).

So try the function I gave you,  if you still experience trouble, just
paste the whole code including HTML.

--
david




On 20 mai, 07:54, Dravis plu...@gmail.com wrote:
 I have this bit of code in my webpage's header.  It simply pulls all
 the li elements from the mainmenu and attaches onmouseover and
 onmouseout event observers to them to toggle the drop down effects of
 the menu.  It works perfectly in IE7 and Firefox but when I mouse over
 the menu in IE6 I get nothing.  Anyone have any ideas?

 document.observe(dom:loaded, function() {
         $$('#mainmenu li').each(function(item) {
                 $(item).observe(onmouseover, function() {
                         $(this).addClassName(sfhover);
                 }.bind(this));
                 $(item).observe(onmouseout, function() {
                         $(this).removeClassName(sfhover);
                 }.bind(this));
         });

 });
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: findElements querySelectorAll error

2009-05-20 Thread ColinFine

It might help if you included enough of your code to make sense of.
Since you have not told us anything about this.expression or
this.mode, it's hard to have any idea what might be going on,
especially since 'description' (which is what you are apparently
asking about) doesn't occur anywhere else in what you posted.


Colin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: findElements querySelectorAll error

2009-05-20 Thread pmac

Thanks Colin for your response.

I found the issue. IE8 does not like html element ids to start with
numbers. If I prepend an X_ to the id, it works fine.

On May 20, 7:04 am, ColinFine colin.f...@pace.com wrote:
 It might help if you included enough of your code to make sense of.
 Since you have not told us anything about this.expression or
 this.mode, it's hard to have any idea what might be going on,
 especially since 'description' (which is what you are apparently
 asking about) doesn't occur anywhere else in what you posted.

 Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Droppable double click and onUpdate problem in firefox and ie

2009-05-20 Thread terry-5-

I did my research, but couldn't find anything helpful to this specific
double click problem.
I would appreciat your help very much. Is it just a glitch?
Here is also the css:

#page{
margin:0 -20px 0 0 ;
}

.ex_instr{
position:fixed;
padding:0 0 0 10px ;
width:320px;
height:90px;
top:135px;
color: #999;
line-height:14px;
background-color: #000;
z-index:1200;
border-bottom: 2px solid #777;
margin: 0 0 0 -8px;
/*ie7 fix*/
#margin:0 0 0 -10px ;
#padding:0 0 0 10px ;
#height:95px;
/*ie6 fix*/
_margin:-30px 0 0 -10px ;
_height:90px;
}
#wordbank{
border: 0px;
_margin:-30px 0 0 -10px ;
min-width:220px;
z-index:1200;
}

.lineitem{
/*position: absolute;
top: 0;
background-color: #000;
float: left;*/
padding: 10px 20px 10px 0px;
cursor: move;
width: 110px;
color:#999;
/*z-index:400;*/
}

.section {
border: 1px solid #777;
margin: 5px;
padding: 0 5px 0 20px;
}

.dr_par{
line-height:20px;
width:300px;
padding: 0 0 10px 0;
}

.section1 {
text-align:left;
}

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: findElements querySelectorAll error

2009-05-20 Thread Walter Lee Davis

Just to beat one of my favorite drums -- the W3C doesn't allow IDs to  
begin with numbers. An ID may begin with an alphabetical character or  
an underscore. Period. Full stop. Numbers after that first character  
are just dandy.

Walter

On May 20, 2009, at 10:17 AM, pmac wrote:

 I found the issue. IE8 does not like html element ids to start with
 numbers. If I prepend an X_ to the id, it works fine.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Changing href in onclick function

2009-05-20 Thread P. Douglas Reeder

To put what RobG said concretely, why can't you use:

$('ph').observe('click', function(event) {
if($('ph').href.endsWith('#')) {
event.preventDefault();
new Ajax.Request(geturl.php,
{
onComplete: function
(request) {
$('ph').href =
request.responseText;
location.href
=  request.responseText;
}.bind(this)
});
} else {
// allow normal
click function
}

});



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread P. Douglas Reeder

You may want to use Crockford's factory pattern, rather than using any
sort of constructor:

function specialDateFactory() {
var that = new Date();

that.isEaster = function () {return ...},
that.isLaborDay = function () {return ...},

return that;
}

You can get more sophisticated - creating a prototype object for
special dates, with the functions defined on it, and using closures to
protect it, but I can't write that off the top of my head...



On May 20, 7:50 am, ColinFine colin.f...@pace.com wrote:
 On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:

  On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

   This is a case when you really truly want just the facilities that
   Javascript provides (prototypes rather than classes), and using
   (pretend) classes makes it harder not easier.

  Yes, although some may argue that it is better to create a new object
  that has the required methods and leverages the methods of Date,
  rather than modifying a built-in object prototype,

 Fair comment. But you are still talking about using Javascript's
 prototype, rather than inventing classes. That was my point.
 (I wouldn't have made this remark before I read Crockford's
 Javascript: The Good Parts - that's opened my eyes to the strengths
 that JS has. )

 Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread joe t.

T.J.,
i think my last post was at least somewhat in line with your
suggestion. i just hadn't fully read and absorbed yours yet.

i will try using that factory approach. If i'm reading it right, it
handles the two-line requirement of creating the native Date, then
calling the ApplySpecialProps method.

As always, thanks for the help!
-joe

On May 20, 12:23 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 Heya,

  You may want to use Crockford's factory pattern, rather than using any
  sort of constructor:

  function specialDateFactory() {
      var that = new Date();

      that.isEaster = function () {return ...},
      that.isLaborDay = function () {return ...},

      return that;

  }

 The problem with that as written is that it creates separate isEaster
 and isLaborDay functions for every single instance you create, each of
 which eats memory:

 var a = specialDateFactory();
 var b = specialDateFactory();

 alert(a.isEaster === b.isEaster); // false

 You can avoid that:

 var MoreDateFunctions = {
     isEaster:   function () {return ...},
     isLaborDay: function () {return ...}};

 function specialDateFactory() {

     return Object.extend(new Date(), MoreDateFunctions);
     // Or, without Prototype's Object.extend:
     // var fname, that;
     // that = new Date();
     // for (fname in MoreDateFunctions) {
     //     that[fname] = MoreDateFunctions[fname];
     // }
     // return that;

 }

 ...but I'm not seeing much benefit at that point.  I suppose it means
 you haven't modified the Date prototype.

 (BTW:  Anyone tempted to create an ExtendedDate object using a Date
 object as its prototype, think again, for some reason the spec
 specifically disallows it in Section 15.9.5, and Firefox [and probably
 others] implements the limitation.)
 --
 T.J. Crowder
 tj / crowder software / com
 Independent Software Engineer, consulting services available

 On May 20, 4:07 pm, P. Douglas Reeder reeder...@gmail.com wrote:

  You may want to use Crockford's factory pattern, rather than using any
  sort of constructor:

  function specialDateFactory() {
      var that = new Date();

      that.isEaster = function () {return ...},
      that.isLaborDay = function () {return ...},

      return that;

  }

  You can get more sophisticated - creating a prototype object for
  special dates, with the functions defined on it, and using closures to
  protect it, but I can't write that off the top of my head...

  On May 20, 7:50 am, ColinFine colin.f...@pace.com wrote:

   On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:

On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

 This is a case when you really truly want just the facilities that
 Javascript provides (prototypes rather than classes), and using
 (pretend) classes makes it harder not easier.

Yes, although some may argue that it is better to create a new object
that has the required methods and leverages the methods of Date,
rather than modifying a built-in object prototype,

   Fair comment. But you are still talking about using Javascript's
   prototype, rather than inventing classes. That was my point.
   (I wouldn't have made this remark before I read Crockford's
   Javascript: The Good Parts - that's opened my eyes to the strengths
   that JS has. )

   Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread joe t.

Thanks to all for your feedback. i think though, that some of the
focus has remained on adding new *methods* to the Date object. That's
easy enough, as in my first sample. However, i'm trying to add
properties to the object that obtain a value when a new Date is
constructed.

var myDate = new Date();
alert(myDate.isEaster); // Alerts 'true' or 'false'
alert(myDate.isLaborDay); // Alerts 'true' or 'false'
etc.

i realize that these property values would still need to be obtained
from return values of functions. That's why my second sample includes
the _isEaster methods, but also has this.isEaster receiving the
return value of the _isEaster method.

Consider:
if (myDate.isEaster){alert('Happy Easter');
vs
if (myDate.isEaster()){alert('Happy Easter');

Any time i want to utilize, compare, etc. that the date is or is not
Easter, i can either have a quick-access boolean property, or a
lengthy calculation from a method.

Obviously these are simplified examples, but when applied to the
bigger concept of reserved dates, and that these reservations could
overlap (isEaster  isMyBirthday, for instance), property testing
could reduce some decent calculation overhead.

However, if it can't be done, it can't be done. i suppose i can simply
add a second line after constructing a new Date:
Date.prototype.ApplySpecialDateProps = function(){
  this.isEaster = (function(d){
// Calculate something from d
return ... })(this),
  this.isLaborDay = (function(d){
// Calculate something from d
return ... })(this),
  ...
}
var myDate = new Date();
myDate.ApplySpecialDateProps();

i was just hoping to get the special properties to be part of the Date
object's construction.
-joe

On May 20, 12:23 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 Heya,

  You may want to use Crockford's factory pattern, rather than using any
  sort of constructor:

  function specialDateFactory() {
      var that = new Date();

      that.isEaster = function () {return ...},
      that.isLaborDay = function () {return ...},

      return that;

  }

 The problem with that as written is that it creates separate isEaster
 and isLaborDay functions for every single instance you create, each of
 which eats memory:

 var a = specialDateFactory();
 var b = specialDateFactory();

 alert(a.isEaster === b.isEaster); // false

 You can avoid that:

 var MoreDateFunctions = {
     isEaster:   function () {return ...},
     isLaborDay: function () {return ...}};

 function specialDateFactory() {

     return Object.extend(new Date(), MoreDateFunctions);
     // Or, without Prototype's Object.extend:
     // var fname, that;
     // that = new Date();
     // for (fname in MoreDateFunctions) {
     //     that[fname] = MoreDateFunctions[fname];
     // }
     // return that;

 }

 ...but I'm not seeing much benefit at that point.  I suppose it means
 you haven't modified the Date prototype.

 (BTW:  Anyone tempted to create an ExtendedDate object using a Date
 object as its prototype, think again, for some reason the spec
 specifically disallows it in Section 15.9.5, and Firefox [and probably
 others] implements the limitation.)
 --
 T.J. Crowder
 tj / crowder software / com
 Independent Software Engineer, consulting services available

 On May 20, 4:07 pm, P. Douglas Reeder reeder...@gmail.com wrote:

  You may want to use Crockford's factory pattern, rather than using any
  sort of constructor:

  function specialDateFactory() {
      var that = new Date();

      that.isEaster = function () {return ...},
      that.isLaborDay = function () {return ...},

      return that;

  }

  You can get more sophisticated - creating a prototype object for
  special dates, with the functions defined on it, and using closures to
  protect it, but I can't write that off the top of my head...

  On May 20, 7:50 am, ColinFine colin.f...@pace.com wrote:

   On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:

On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

 This is a case when you really truly want just the facilities that
 Javascript provides (prototypes rather than classes), and using
 (pretend) classes makes it harder not easier.

Yes, although some may argue that it is better to create a new object
that has the required methods and leverages the methods of Date,
rather than modifying a built-in object prototype,

   Fair comment. But you are still talking about using Javascript's
   prototype, rather than inventing classes. That was my point.
   (I wouldn't have made this remark before I read Crockford's
   Javascript: The Good Parts - that's opened my eyes to the strengths
   that JS has. )

   Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 

[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread T.J. Crowder

Heya,

 You may want to use Crockford's factory pattern, rather than using any
 sort of constructor:

 function specialDateFactory() {
 var that = new Date();

 that.isEaster = function () {return ...},
 that.isLaborDay = function () {return ...},

 return that;

 }

The problem with that as written is that it creates separate isEaster
and isLaborDay functions for every single instance you create, each of
which eats memory:

var a = specialDateFactory();
var b = specialDateFactory();

alert(a.isEaster === b.isEaster); // false

You can avoid that:

var MoreDateFunctions = {
isEaster:   function () {return ...},
isLaborDay: function () {return ...}
};
function specialDateFactory() {

return Object.extend(new Date(), MoreDateFunctions);
// Or, without Prototype's Object.extend:
// var fname, that;
// that = new Date();
// for (fname in MoreDateFunctions) {
// that[fname] = MoreDateFunctions[fname];
// }
// return that;
}

...but I'm not seeing much benefit at that point.  I suppose it means
you haven't modified the Date prototype.

(BTW:  Anyone tempted to create an ExtendedDate object using a Date
object as its prototype, think again, for some reason the spec
specifically disallows it in Section 15.9.5, and Firefox [and probably
others] implements the limitation.)
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 20, 4:07 pm, P. Douglas Reeder reeder...@gmail.com wrote:
 You may want to use Crockford's factory pattern, rather than using any
 sort of constructor:

 function specialDateFactory() {
     var that = new Date();

     that.isEaster = function () {return ...},
     that.isLaborDay = function () {return ...},

     return that;

 }

 You can get more sophisticated - creating a prototype object for
 special dates, with the functions defined on it, and using closures to
 protect it, but I can't write that off the top of my head...

 On May 20, 7:50 am, ColinFine colin.f...@pace.com wrote:

  On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:

   On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

This is a case when you really truly want just the facilities that
Javascript provides (prototypes rather than classes), and using
(pretend) classes makes it harder not easier.

   Yes, although some may argue that it is better to create a new object
   that has the required methods and leverages the methods of Date,
   rather than modifying a built-in object prototype,

  Fair comment. But you are still talking about using Javascript's
  prototype, rather than inventing classes. That was my point.
  (I wouldn't have made this remark before I read Crockford's
  Javascript: The Good Parts - that's opened my eyes to the strengths
  that JS has. )

  Colin


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding properties to native objects

2009-05-20 Thread joe t.

One last note barring any huge revelations:

T.J.'s factory suggestion was almost exactly right. His code as-is
adds the methods to my customized Date. However, since i want
properties of the same name that receive the return values of those
methods, i MUST use the non-Object#extend version, as such:

var SpecialDateProps = {
  isEaster:function(){ return ... },
  etc.
};
function DateFactory(){
  var fName, that = new Date();
  for (fName in SpecialDateProps)
that[fName] = SpecialDateProps[fName](); // Note calling the
fName's function.
  return that;
}

Thanks again!
-joe t.

On May 20, 1:12 pm, joe t. thooke...@gmail.com wrote:
 T.J.,
 i think my last post was at least somewhat in line with your
 suggestion. i just hadn't fully read and absorbed yours yet.

 i will try using that factory approach. If i'm reading it right, it
 handles the two-line requirement of creating the native Date, then
 calling the ApplySpecialProps method.

 As always, thanks for the help!
 -joe

 On May 20, 12:23 pm, T.J. Crowder t...@crowdersoftware.com wrote:

  Heya,

   You may want to use Crockford's factory pattern, rather than using any
   sort of constructor:

   function specialDateFactory() {
       var that = new Date();

       that.isEaster = function () {return ...},
       that.isLaborDay = function () {return ...},

       return that;

   }

  The problem with that as written is that it creates separate isEaster
  and isLaborDay functions for every single instance you create, each of
  which eats memory:

  var a = specialDateFactory();
  var b = specialDateFactory();

  alert(a.isEaster === b.isEaster); // false

  You can avoid that:

  var MoreDateFunctions = {
      isEaster:   function () {return ...},
      isLaborDay: function () {return ...}};

  function specialDateFactory() {

      return Object.extend(new Date(), MoreDateFunctions);
      // Or, without Prototype's Object.extend:
      // var fname, that;
      // that = new Date();
      // for (fname in MoreDateFunctions) {
      //     that[fname] = MoreDateFunctions[fname];
      // }
      // return that;

  }

  ...but I'm not seeing much benefit at that point.  I suppose it means
  you haven't modified the Date prototype.

  (BTW:  Anyone tempted to create an ExtendedDate object using a Date
  object as its prototype, think again, for some reason the spec
  specifically disallows it in Section 15.9.5, and Firefox [and probably
  others] implements the limitation.)
  --
  T.J. Crowder
  tj / crowder software / com
  Independent Software Engineer, consulting services available

  On May 20, 4:07 pm, P. Douglas Reeder reeder...@gmail.com wrote:

   You may want to use Crockford's factory pattern, rather than using any
   sort of constructor:

   function specialDateFactory() {
       var that = new Date();

       that.isEaster = function () {return ...},
       that.isLaborDay = function () {return ...},

       return that;

   }

   You can get more sophisticated - creating a prototype object for
   special dates, with the functions defined on it, and using closures to
   protect it, but I can't write that off the top of my head...

   On May 20, 7:50 am, ColinFine colin.f...@pace.com wrote:

On May 20, 12:16 am, RobG rg...@iinet.net.au wrote:

 On May 19, 9:26 pm, ColinFine colin.f...@pace.com wrote:

  This is a case when you really truly want just the facilities that
  Javascript provides (prototypes rather than classes), and using
  (pretend) classes makes it harder not easier.

 Yes, although some may argue that it is better to create a new object
 that has the required methods and leverages the methods of Date,
 rather than modifying a built-in object prototype,

Fair comment. But you are still talking about using Javascript's
prototype, rather than inventing classes. That was my point.
(I wouldn't have made this remark before I read Crockford's
Javascript: The Good Parts - that's opened my eyes to the strengths
that JS has. )

Colin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: fatal error on the page under IE7 when a script can't run till its end = scriptaculous scripts stop to work

2009-05-20 Thread itkin

To complete my previous post , it seeam that  when you use
Effect.multiple([elt_id, ...]) and when one of the elt_id is not found
on the page a fatal js error is thrown on IE. This error on the page
disable all other scriptaculous functions you could launch after that
on the same webpage.

Doesn't occur on Firefox. Any help appreciated :-) !!

Nico



On 20 mai, 04:08, itkin nicolas.pa...@gmail.com wrote:
 Hello,

 I'm deseperately looking for the solution of a weird behavior on IE7.

 I've this function, executed dynamically from a rjs (ror) template.
 Basically it slides down a list of produts labels, one after this
 other, in a wave maner.

 function slideLabelsDown(labelsContainer){
         Effect.multiple($(labelsContainer).select('.sale_item_label'),
 Effect.SlideDown, {
                 transition:Effect.Transitions.spring,
                 speed:0.25,
                 duration:5});
         $('top_sale_item_labels_ajax_wrapper').fade({delay:0.3,duration:
 0.2});

 }

 Well the duration of this script is supposed to be 5 seconds, but when
 you click on some other link before the function ends, you got the
 following error only on IE :

 Line 699
 Char 7
 'element.down()' is null or not an object

 As far as I understand it doesn't find the current element to slide
 down because it has been dynamically removed with all the page sub
 content

 So the error raises and then scipt aculous framework just stop
 working. This is really problematic for me since i use its functions
 intensivelly in quite every ajax call .

 Does anybody know how to prevent or handle this kind exception?? try
 {} catch(){} doesn't work ..

 Thanks in advance !!

 Nicolas
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---