[Proto-Scripty] Re: using with statement

2010-04-30 Thread T.J. Crowder
Hi,

 is there a way that I can get rid of all these usages of this

No. `this` is different in Javascript than in some other languages
with the same keyword, in several ways. One of these is that
unqualified references like your _div (without anything in front of
it) are not automatically resolved against property names on `this`;
all identifier resolution in Javascript is lexically-based, using the
concept of a scope chain (more below if you're interested). So you
have to explicitly type `this.` when accessing the properties on
`this` (just as you have to type `foo.` to access the properties on
`foo`), or as you've found, you can use `with`. Be aware that using
`with` has some gotchas that are not obvious. Douglas Crockford
lists many of these in his with Statement Considered Harmful[1]
article (I'm not a fan of Considered Harmful articles[2], but
Crockford lays out the issues fairly well). My point isn't don't use
it, it's be sure you understand the gotchas when using it.

About the scope chain and identifier resolution: One of the things I
love about Javascript is that basically *everything* is an object,
even if some of the objects are hidden behind the scenes. One of these
behind-the-scenes objects is the variable object (the binding
object of the variable environment in the latest spec -- yikes). When
you declare a variable using `var`, you're adding a *property* to the
variable object for the current scope. The variable object has
properties for all `var`s, all functions declared in the scope, and
(if the scope relates to a function) all named arguments to the
function. When the step-by-step code within the scope is executing,
that scope's variable object is at the beginning of the scope chain.
All unqualified references are first checked against that variable
object to see if they match a property on it. If they do, that
property is used; if not, the next variable object in the chain is
checked; etc.

Example:

var x = 1;

function foo() {
var y = 2;

function bar() {
var z = 3;

alert(x);
alert(y);
alert(z);
}
}

We have three scopes there: Global scope, `foo`'s scope, and `bar`'s
scope. Consequently, we have three variable objects. When code within
`bar` is being executed, the scope chain consists of `bar`'s variable
object, followed by `foo`'s, followed by the global variable object.
When `bar` references `z`, the `z` property is found on the first
variable object and used. When `bar` references `y`, it's not on the
first variable object but it is on the second one, so it's used from
there. Accessing `x` involves going back two variable objects to the
global one.

As you can see, `this` doesn't come into it -- it's nowhere on the
scope chain unless you insert it, which is exactly what `with` does:
Puts the object you specify at the beginning of the scope chain.

Now, I called the variable object a behind-the-scenes object. That's
usually true, but there's an exception: The variable object for the
global scope is the global object, which on browsers is `window` (more
accurately, on browsers the global object has a property, `window`, it
points to itself with). That's why when you declare variables and
functions at global scope, they magically show up as properties on
`window`.

[1] http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
[2] http://meyerweb.com/eric/comment/chech.html

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Apr 29, 9:17 am, Ran Berenfeld berenfeld...@gmail.com wrote:
 Hi all
 I have written a class using prototype Class object
 and after playing it for a while, I saw that I need to use the with
 keyword in the class members,
 so I can access its members

 here is the relevant part of the class : (the member is _div)

 var JSClass = Class.create ({
      initialize: function(initParams) {

         if (initParams.div)
         {
             *this*._div = $(initParams.div);
         }
         else
         {
             *this*._div = new Element(div);
         }
      },
      // an example of a member function
     setComment: function(msg)
     {
         *with(this)*
 *        {*
 *              *_div.innerHTML = msg;
 *        }*
     }

 });

 is there a way that I can get rid of all these usages of this

 Thanks
 Ran

 --
 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-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to 
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
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-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 

[Proto-Scripty] Drag and Drop Problem

2010-04-30 Thread Sarbjeet Singh
Hi All,

I have a drag and drop functionality developed where I have multiple
dragables and multiple dropables.  Where the Dragable is Droped on a
Dropable.

I also need to have the functionality where I should be able to revert
the dragable that means once the dragable is on dropable i should be
able to place the dragable to its orignal place. Just like the revert
happens when I try to place the dragable to a non dropable area

Thanks
Sarbjeet

-- 
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-scriptacul...@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.



Re: [Proto-Scripty] Do I stop observing events on element with Ajax.Autocompleter using Event.stopObserving()

2010-04-30 Thread Sébastien Gruhier
Hi

I'll add a Ajax.Autocompleter#release method like this.

Ajax.Autocompleter.addMethods({
  release: function() {
this.element.stopObserving();
  }
});

http://gist.github.com/384853

On Apr 29, 2010, at 7:29 PM, kimbaudi wrote:

 Hi, I have a form with multiple text inputs (i.e. input type=text
 name=list_1 id=list_1 ... input type=text name=list_5
 id=list_5) which all have Ajax.Autocompleter initialized. Now when
 I remove any of these autocompleting text inputs from the DOM, I want
 to stop observing events on these elements. However, Scriptaculous
 does not provide a way to unregister all the events that are handling
 the Ajax.Autocompleter for a particular element.
 
 I want to know if I should unregister all the events that are handling
 the Ajax.Autocompleter for a particular element by using
 Event.stopObserving() on that element or some other method?
 
 I don't want to resort to modifying Prototype or Scriptaculous and
 would prefer not to have to extend Ajax.Autocompleter class just for
 this task.
 
 Thanks.
 
 -- 
 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-scriptacul...@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.
 

-- 
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-scriptacul...@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: Can we use Prototype 1.7.1 RC1 with Rails 3 beta

2010-04-30 Thread Joshua Partogi
Hi all,

A quick update from me about Rails 3 beta and Prototype. I've just
tried Rails 3 beta with Prototype 1.6 and it doesn't work. Infact it
works with Prototype 1.7.1. So I guess Rails 3 beta is built against
Prototype 1.7


Kind regards,
Joshua

--
http://twitter.com/scrum8


On Apr 26, 8:06 pm, Joshua Partogi jpart...@scrum8.com wrote:
 Hi all,

 I will be using the prototype helper's from Rails 3 beta, will it work
 with Prototype 1.7.1.RC1? Does the API still the same with 1.6.1?

 Thank you for the insights and your time.

 Kind regards,
 Joshua

-- 
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-scriptacul...@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.



Re: [Proto-Scripty] Re: using with statement

2010-04-30 Thread Ran Berenfeld
Thanks a lot for your reply T.J
I was partially familiar with this mechanism, and now I know more :)
anyway, let me re-phrase my question
we all know that an event received on a DOM element (i.e button onclick
event for example)
will have the this equals to the DOM element

my question is simple : isn't there a way do define the class member
functions in such a way
that the scope (this) will refer to the object instance ?

Thanks
Ran B

On Fri, Apr 30, 2010 at 9:31 AM, T.J. Crowder t...@crowdersoftware.comwrote:

 Hi,

  is there a way that I can get rid of all these usages of this

 No. `this` is different in Javascript than in some other languages
 with the same keyword, in several ways. One of these is that
 unqualified references like your _div (without anything in front of
 it) are not automatically resolved against property names on `this`;
 all identifier resolution in Javascript is lexically-based, using the
 concept of a scope chain (more below if you're interested). So you
 have to explicitly type `this.` when accessing the properties on
 `this` (just as you have to type `foo.` to access the properties on
 `foo`), or as you've found, you can use `with`. Be aware that using
 `with` has some gotchas that are not obvious. Douglas Crockford
 lists many of these in his with Statement Considered Harmful[1]
 article (I'm not a fan of Considered Harmful articles[2], but
 Crockford lays out the issues fairly well). My point isn't don't use
 it, it's be sure you understand the gotchas when using it.

 About the scope chain and identifier resolution: One of the things I
 love about Javascript is that basically *everything* is an object,
 even if some of the objects are hidden behind the scenes. One of these
 behind-the-scenes objects is the variable object (the binding
 object of the variable environment in the latest spec -- yikes). When
 you declare a variable using `var`, you're adding a *property* to the
 variable object for the current scope. The variable object has
 properties for all `var`s, all functions declared in the scope, and
 (if the scope relates to a function) all named arguments to the
 function. When the step-by-step code within the scope is executing,
 that scope's variable object is at the beginning of the scope chain.
 All unqualified references are first checked against that variable
 object to see if they match a property on it. If they do, that
 property is used; if not, the next variable object in the chain is
 checked; etc.

 Example:

 var x = 1;

 function foo() {
var y = 2;

function bar() {
var z = 3;

alert(x);
alert(y);
alert(z);
}
 }

 We have three scopes there: Global scope, `foo`'s scope, and `bar`'s
 scope. Consequently, we have three variable objects. When code within
 `bar` is being executed, the scope chain consists of `bar`'s variable
 object, followed by `foo`'s, followed by the global variable object.
 When `bar` references `z`, the `z` property is found on the first
 variable object and used. When `bar` references `y`, it's not on the
 first variable object but it is on the second one, so it's used from
 there. Accessing `x` involves going back two variable objects to the
 global one.

 As you can see, `this` doesn't come into it -- it's nowhere on the
 scope chain unless you insert it, which is exactly what `with` does:
 Puts the object you specify at the beginning of the scope chain.

 Now, I called the variable object a behind-the-scenes object. That's
 usually true, but there's an exception: The variable object for the
 global scope is the global object, which on browsers is `window` (more
 accurately, on browsers the global object has a property, `window`, it
 points to itself with). That's why when you declare variables and
 functions at global scope, they magically show up as properties on
 `window`.

 [1] http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
 [2] http://meyerweb.com/eric/comment/chech.html

 HTH,
 --
 T.J. Crowder
 Independent Software Consultant
 tj / crowder software / com
 www.crowdersoftware.com

 On Apr 29, 9:17 am, Ran Berenfeld berenfeld...@gmail.com wrote:
  Hi all
  I have written a class using prototype Class object
  and after playing it for a while, I saw that I need to use the with
  keyword in the class members,
  so I can access its members
 
  here is the relevant part of the class : (the member is _div)
 
  var JSClass = Class.create ({
   initialize: function(initParams) {
 
  if (initParams.div)
  {
  *this*._div = $(initParams.div);
  }
  else
  {
  *this*._div = new Element(div);
  }
   },
   // an example of a member function
  setComment: function(msg)
  {
  *with(this)*
  *{*
  *  *_div.innerHTML = msg;
  *}*
  }
 
  });
 
  is there a way that I can get rid of all these usages of this
 
  Thanks
  Ran
 
  --
  You received 

Re: [Proto-Scripty] Do I stop observing events on element with Ajax.Autocompleter using Event.stopObserving()

2010-04-30 Thread Paul Kim
Thank you for your solution. Now my form removes Ajax.Autocompleter when I
remove a form element.

On Thu, Apr 29, 2010 at 11:49 PM, Sébastien Gruhier sgruh...@gmail.comwrote:

 Hi

 I'll add a Ajax.Autocompleter#release method like this.

 Ajax.Autocompleter.addMethods({
  release: function() {
this.element.stopObserving();
  }
 });

 http://gist.github.com/384853

 On Apr 29, 2010, at 7:29 PM, kimbaudi wrote:

  Hi, I have a form with multiple text inputs (i.e. input type=text
  name=list_1 id=list_1 ... input type=text name=list_5
  id=list_5) which all have Ajax.Autocompleter initialized. Now when
  I remove any of these autocompleting text inputs from the DOM, I want
  to stop observing events on these elements. However, Scriptaculous
  does not provide a way to unregister all the events that are handling
  the Ajax.Autocompleter for a particular element.
 
  I want to know if I should unregister all the events that are handling
  the Ajax.Autocompleter for a particular element by using
  Event.stopObserving() on that element or some other method?
 
  I don't want to resort to modifying Prototype or Scriptaculous and
  would prefer not to have to extend Ajax.Autocompleter class just for
  this task.
 
  Thanks.
 
  --
  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-scriptacul...@googlegroups.com.
  To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
  For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.
 

 --
 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-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



-- 
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-scriptacul...@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] Carousel prototype problem from 1.6.1 to 1.7_rc1

2010-04-30 Thread F.Buratti
I'm using the script by Victor Stanciu (http://code.google.com/p/
prototype-carousel/) but I can not get it to work correctly with the
new release candidate of Prototype 1.7.

the problem is that the carousel stops and do not see the last two
slides, I'm trying but have not yet found the bug

I would appreciate 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-scriptacul...@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] Getting the value of a form field

2010-04-30 Thread Shane McCarron
I am sure this is just ignorance on my part, but...

I would really like to $F('formField') to get the value of whatever field I
am interested in.  However, it seems formField needs to be the field's ID,
not its Name.  That's cool, except when I have Radio Buttons or Check
Boxes.  You aren't allowed to have multiple elements with the same ID and
still be valid.  What's the right way to do this?

-- 
Shane McCarron
halindr...@gmail.com

-- 
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-scriptacul...@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.



RE: [Proto-Scripty] Getting the value of a form field

2010-04-30 Thread Jonathan Rosenberg
I think this might work.  You could wrap it up into a function, of course,
with name as a parameter.

 

 
$$('input[type=radio][name=whatever]').find(function(radio)
   { return radio.checked; }).value;

 

--
Jonathan Rosenberg
Founder  Executive Director, Tabby's Place
http://www.tabbysplace.org/

 

 

From: prototype-scriptaculous@googlegroups.com
[mailto:prototype-scriptacul...@googlegroups.com] On Behalf Of Shane
McCarron
Sent: Friday, April 30, 2010 1:32 PM
To: prototype-scriptaculous@googlegroups.com
Subject: [Proto-Scripty] Getting the value of a form field

 

I am sure this is just ignorance on my part, but...

I would really like to $F('formField') to get the value of whatever field I
am interested in.  However, it seems formField needs to be the field's ID,
not its Name.  That's cool, except when I have Radio Buttons or Check Boxes.
You aren't allowed to have multiple elements with the same ID and still be
valid.  What's the right way to do this?


-- 
Shane McCarron
halindr...@gmail.com

-- 
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-scriptacul...@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.

-- 
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-scriptacul...@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] outside the IFRAME

2010-04-30 Thread Hariz Soleminio
Hello,

Is this possible I inserted an IFRAME in a page. the i frame i inserted 
contains HTML with protoype/javascript codes. 

below is the javascript code
Event.observe(document, 'keyup', keyupcheck, false);

im observing the window in any keyup events. however it only works within the 
iframe what if i want it to work outside the 
i frame?


Please help guys.

Thankss


-- 
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-scriptacul...@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.



Re: [Proto-Scripty] Getting the value of a form field

2010-04-30 Thread Shane McCarron
Clever!  I will try that.  Another approach that might work for some is to
serialize the form data into a hash.  Then you should have the values for
each form control indexed by their name.

var h = $('formId').serialize( true ) ;

Then, for a form control with a name of 'name' you can do:

if (h{'name'} == 'valueIcareAbout') ...

On Fri, Apr 30, 2010 at 1:25 PM, Jonathan Rosenberg j...@tabbysplace.orgwrote:

  I think this might work.  You could wrap it up into a function, of
 course, with name as a parameter.



 
 $$(‘input[type=”radio”][name=”whatever”]’).find(function(radio)

{ return radio.checked; }).value;



 --
 Jonathan Rosenberg
 Founder  Executive Director, Tabby's Place
 http://www.tabbysplace.org/





 *From:* prototype-scriptaculous@googlegroups.com [mailto:
 prototype-scriptacul...@googlegroups.com] *On Behalf Of *Shane McCarron
 *Sent:* Friday, April 30, 2010 1:32 PM
 *To:* prototype-scriptaculous@googlegroups.com
 *Subject:* [Proto-Scripty] Getting the value of a form field



 I am sure this is just ignorance on my part, but...

 I would really like to $F('formField') to get the value of whatever field I
 am interested in.  However, it seems formField needs to be the field's ID,
 not its Name.  That's cool, except when I have Radio Buttons or Check
 Boxes.  You aren't allowed to have multiple elements with the same ID and
 still be valid.  What's the right way to do this?

 --
 Shane McCarron
 halindr...@gmail.com

 --
 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-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.

 --
 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-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.




-- 
Shane McCarron
halindr...@gmail.com

-- 
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-scriptacul...@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: Getting the value of a form field

2010-04-30 Thread joe t.
Similar to a prior response using a CSS selector, but eliminating the
call to #find:

// Returns single value of the checked radio
var value = $F($$('input:checked[type=radio][name=groupName]')[0])

The :checked pseudo-class shortcuts to the checked element(s) in the
selector results. However, in a checkbox group, this would suit
better:

// Returns an array of values of checked boxes
var values = $$('input:checked[type=checkbox][name=groupName\
[\]]').pluck('value');

Note the escaped square brackets are how server languages like PHP
generate arrays from multiple checkboxes.

i really wish when dealing with forms, Prototype's functions dealing
with values should address the name instead of the id, since this is
also the attribute that servers deal with to identify values.
Especially when you're forced to use expensive methods like the above
to use a CSS selector, create an array of matches (pointless when you
know there's only one resulting element), and then get its value.

Hope that's useful.
-joe t.


On Apr 30, 1:32 pm, Shane McCarron halindr...@gmail.com wrote:
 I am sure this is just ignorance on my part, but...

 I would really like to $F('formField') to get the value of whatever field I
 am interested in.  However, it seems formField needs to be the field's ID,
 not its Name.  That's cool, except when I have Radio Buttons or Check
 Boxes.  You aren't allowed to have multiple elements with the same ID and
 still be valid.  What's the right way to do this?

 --
 Shane McCarron
 halindr...@gmail.com

 --
 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-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to 
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
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-scriptacul...@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.