[Proto-Scripty] Re: Dynamic script file loading

2008-10-17 Thread T.J. Crowder

For anyone coming to this thread later, there's now a (rough) how-to
on the unofficial wiki:
http://proto-scripty.wikidot.com/prototype:how-to-load-scripts-dynamically

-- T.J. :-)

On Oct 16, 11:11 am, T.J. Crowder [EMAIL PROTECTED] wrote:
 Hey Jason,

 [Call me T.J. :-)]

 Caveat:  I have not had to do this in the wild, so there are sure to
 be better answers from others.  I'll throw out an example that works
 in my limited testing (FF3, IE6, Safari 3, Opera 9):

 Loading the script dynamically from the statically-loaded script
 already on the page (in my example file I triggered this vi a button):
 * * *
 function go()
 {
     var head;
     var script;

     head = $$('head')[0];
     if (head)
     {
         script = new Element('script', { type: 'text/javascript', src:
 'dynamic.js' });
         head.appendChild(script);
     }}

 * * *

 A function in the statically-loaded script that other scripts can use
 to announce themselves:
 * * *
 function hello(name)
 {
     alert('Script ' + name + ' loaded');}

 * * *

 My dynamic.js file:
 * * *
 hello('dynamic');
 function coolness()
 {
     alert('Coolness!');}

 * * * *

 A modified version of hello() demonstrating that the dynamically-
 loaded script is accessible from the statically-loaded one:
 * * * *
 function hello(name)
 {
     alert('Script ' + name + ' loaded');
     if (name == 'dynamic')
     {
         coolness();
     }}

 * * * *

 Complete code on Pastie:
 HTML+static script:http://pastie.org/293753
 dynamic.js:http://pastie.org/293754

 Again, though, I wouldn't be at all surprised if there are subtlties
 and wrinkles that aren't dreamt of in my philosophy -- or at least not
 handled in this code. :-)
 --
 T.J. Crowder
 tj / crowder software / com

 On Oct 16, 10:54 am, jason maina [EMAIL PROTECTED] wrote:

  @Crowder:
  This kind of amateurish, how will the script announce itself?
  Kind of don't understand the concept

  2008/10/16 T.J. Crowder [EMAIL PROTECTED]

When the script element is inserted into the document body, does the
currently-running script wait for the js file to be downloaded and
   executed?

   You'll want to try it out on the browsers you're targeting, but I tend
   to doubt it:  All the code inserting the tag is doing is inserting the
   script element in the DOM, the browser does the rest and I'm guessing
   does it on its own thread(s).  Probably best to have the script you're
   loading announce itself to the script loading it when it loads.  Then
   you know it's there.
   --
   T.J. Crowder
   tj / crowder software / com

   On Oct 15, 8:08 pm, Hector Virgen [EMAIL PROTECTED] wrote:
When the script element is inserted into the document body, does the
currently-running script wait for the js file to be downloaded and
   executed?
Or does the js file download in the background while the current script
finishes?
-Hector

2008/10/15 buda [EMAIL PROTECTED]

 tere is a beautifull script ENSURE - try it

 On 15 окт, 14:16, jason maina [EMAIL PROTECTED] wrote:
  Hi,

  Is it possible to load script files only when they are needed.
  In the application im currently making there are too many script(js)
 files
  loaded on the parent page yet in the entire life-cycle of the
   application
  usage some tabs will not even be clicked hence the idea to only load
 script
  files when needed.

  Thank you in advance.

  - Jason

--
-Hector


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Why doesn't this work in Internet Explorer?

2008-10-17 Thread moijk

http://mpdemo.no/mpi/Doc/Moduler/MediaManager/

When I close the node down. that works perfectly.

But when I try to open it - using blindUp - That doesn't work. nothing
happend in internet explorer.

(test it in any browser, then in ie)

or it is my ie 8 beta that isn't working perfectly?

Well. I asked some at work to look at it, and it worked in ie6 and ie7
for one guy, but it flickered and was slow? and he about as hardcore
machine as you can get today.

any way to make this work 100% in any browser?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Enumerable context - bug?

2008-10-17 Thread Tomasz Kalkosiński

Hey guys.

For Enumerable, according to API Docs I've found: If there is no
context argument, the iterator function will preserve the scope it
would have anyway.

I've came to that:

function Person(name)
{
this.name=name;
this.Check=Check;
}

function Check()
{
alert(Context is  + this); //Object - ok

$w(John Mike Mary Jane).each ( function (n) {
alert(each context is  + this); //Window - why?

if (n == this.name)
alert(We have same names!);
} /*, this*/ );
}

var mike = new Person(Mike);
mike.Check ();

I assumed that while I'm in Check function my context is mike
instance. But each() is invoked in Window context instead. I had to
manually add context (like you see commented /*, this*/). Is it a bug
according to API Docs : If there is no context argument, the iterator
function will preserve the scope it would have anyway?

Greetings,
Tomasz Kalkosiński
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Unofficial wiki - layout question

2008-10-17 Thread T.J. Crowder

Hi folks,

The initial let's get something out there layout I did for the
unofficial wiki[1] has a clear distinction between Prototype and
script.aculo.us.  There are separate sections for them, and each
section has its own list of Tips, How Tos, etc.  In fact, I even had
us putting pages about Prototype in a prototype category and pages
about script.aculo.us in a scripty category.
[1] http://proto-scripty.wikidot.com

Is there any point to that?  I mean, is the tip about minimizing
download times (or about unobtrusive JavaScript, or about instance
methods as callbacks/event handlers) related to Prototype or
script.aculo.us?  My answer to that second question is Yes, both,
which suggests that the answer to the first question is No, not
really and we should get rid of it before things go on much further.
(The site already has a bunch of stuff broken into these categories,
so before things grow too much further...)

Like many wikis, we can use tags on pages, and we've been careful to
tag Prototype pages with a prototype tag, script.aculo.us pages with
a script.aculo.us tag, and pages about both with both.  I tend to
think that's enough.

So that would leave the menu on the left looking a bit like this:

Home
Tips
How Tos
Troubleshooting
API Notes
Extras / Add-ons
Resources
Pitch In!
Editing this wiki

...followed by the mini-tag cloud.

It's a biggish reorganization, getting rid of the categories and such,
so I thought it best to throw the idea out and see if it makes sense.

BTW:  If you feel like pitching in, there's a list of things needed/
wanted here:
http://proto-scripty.wikidot.com/pitch-in

Thanks in advance,
--
T.J. Crowder
tj / crowder software / 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-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Why doesn't this work in Internet Explorer?

2008-10-17 Thread grunk

It's work for me on IE 7.0.5730.13, The blindDown  effect is not as
fluent as with firefox but it's working

On 17 oct, 13:25, moijk [EMAIL PROTECTED] wrote:
 http://mpdemo.no/mpi/Doc/Moduler/MediaManager/

 When I close the node down. that works perfectly.

 But when I try to open it - using blindUp - That doesn't work. nothing
 happend in internet explorer.

 (test it in any browser, then in ie)

 or it is my ie 8 beta that isn't working perfectly?

 Well. I asked some at work to look at it, and it worked in ie6 and ie7
 for one guy, but it flickered and was slow? and he about as hardcore
 machine as you can get today.

 any way to make this work 100% in any browser?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Dynamic script file loading

2008-10-17 Thread jason maina
@T.J:
This was a time saver on the scripts I have to load on my application
as well as have learnt something new
Many thanks ;-)

Regards
Jason

On 10/17/08, T.J. Crowder [EMAIL PROTECTED] wrote:

 For anyone coming to this thread later, there's now a (rough) how-to
 on the unofficial wiki:
 http://proto-scripty.wikidot.com/prototype:how-to-load-scripts-dynamically

 -- T.J. :-)

 On Oct 16, 11:11 am, T.J. Crowder [EMAIL PROTECTED] wrote:
 Hey Jason,

 [Call me T.J. :-)]

 Caveat:  I have not had to do this in the wild, so there are sure to
 be better answers from others.  I'll throw out an example that works
 in my limited testing (FF3, IE6, Safari 3, Opera 9):

 Loading the script dynamically from the statically-loaded script
 already on the page (in my example file I triggered this vi a button):
 * * *
 function go()
 {
 var head;
 var script;

 head = $$('head')[0];
 if (head)
 {
 script = new Element('script', { type: 'text/javascript', src:
 'dynamic.js' });
 head.appendChild(script);
 }}

 * * *

 A function in the statically-loaded script that other scripts can use
 to announce themselves:
 * * *
 function hello(name)
 {
 alert('Script ' + name + ' loaded');}

 * * *

 My dynamic.js file:
 * * *
 hello('dynamic');
 function coolness()
 {
 alert('Coolness!');}

 * * * *

 A modified version of hello() demonstrating that the dynamically-
 loaded script is accessible from the statically-loaded one:
 * * * *
 function hello(name)
 {
 alert('Script ' + name + ' loaded');
 if (name == 'dynamic')
 {
 coolness();
 }}

 * * * *

 Complete code on Pastie:
 HTML+static script:http://pastie.org/293753
 dynamic.js:http://pastie.org/293754

 Again, though, I wouldn't be at all surprised if there are subtlties
 and wrinkles that aren't dreamt of in my philosophy -- or at least not
 handled in this code. :-)
 --
 T.J. Crowder
 tj / crowder software / com

 On Oct 16, 10:54 am, jason maina [EMAIL PROTECTED] wrote:

  @Crowder:
  This kind of amateurish, how will the script announce itself?
  Kind of don't understand the concept

  2008/10/16 T.J. Crowder [EMAIL PROTECTED]

When the script element is inserted into the document body, does
the
currently-running script wait for the js file to be downloaded and
   executed?

   You'll want to try it out on the browsers you're targeting, but I tend
   to doubt it:  All the code inserting the tag is doing is inserting the
   script element in the DOM, the browser does the rest and I'm guessing
   does it on its own thread(s).  Probably best to have the script you're
   loading announce itself to the script loading it when it loads.  Then
   you know it's there.
   --
   T.J. Crowder
   tj / crowder software / com

   On Oct 15, 8:08 pm, Hector Virgen [EMAIL PROTECTED] wrote:
When the script element is inserted into the document body, does
the
currently-running script wait for the js file to be downloaded and
   executed?
Or does the js file download in the background while the current
script
finishes?
-Hector

2008/10/15 buda [EMAIL PROTECTED]

 tere is a beautifull script ENSURE - try it

 On 15 окт, 14:16, jason maina [EMAIL PROTECTED] wrote:
  Hi,

  Is it possible to load script files only when they are needed.
  In the application im currently making there are too many
  script(js)
 files
  loaded on the parent page yet in the entire life-cycle of the
   application
  usage some tabs will not even be clicked hence the idea to only
  load
 script
  files when needed.

  Thank you in advance.

  - Jason

--
-Hector


 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable context - bug?

2008-10-17 Thread kangax

On Oct 17, 7:35 am, Tomasz Kalkosiński [EMAIL PROTECTED]
wrote:
 Hey guys.

 For Enumerable, according to API Docs I've found: If there is no
 context argument, the iterator function will preserve the scope it
 would have anyway.

Sorry, that's just a poor wording on our side : /
By preserve scope it would have anyway it was probably meant that a
function is not explicitly bound to any object.
What actually happens is simple. The function (e.g. `Enumerable.each`)
always invokes its iterator via `apply` (passing it an explicit
`context` argument). When that `context` argument is `undefined`,
function is called within a global context (see 15.3.4.3 in ecma-262
specs).

The way you understood binding in this case is actually pretty
intuitive to many people. The problem is that callee has nothing to do
with caller's context (at the moment when it's being called). Caller's
context is never preserved when callee enters its own execution
context. There's not much we can do to make it work the way you
describe : )

[snip]


 Greetings,
 Tomasz Kalkosiński

--
kangax
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable context - bug?

2008-10-17 Thread Tomasz Kalkosiński

On Oct 17, 3:44 pm, kangax [EMAIL PROTECTED] wrote:
 Sorry, that's just a poor wording on our side : /
 By preserve scope it would have anyway it was probably meant that a
 function is not explicitly bound to any object.

 The way you understood binding in this case is actually pretty
 intuitive to many people.

It's intuitive because it's like closures work. Now I have doubts if
my other Enumerable methods behave as I intended them to. What do
others think?

I think you should use simple example in like mine in API Docs to
illustrate it's not intuitive.

I'm sad :(
Tomasz Kalkosiński


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Unofficial wiki - layout question

2008-10-17 Thread Jerod Venema
Hey TJ,

My vote is lump it all together. Especially since scripty has its own wiki
anyways, there are going to be sections that are really not relevant for
scripty.

Anyway, I think it makes sense to keep it primarily a prototype wiki, with
general tips for other stuff and links out to the scriptaculous wiki where
appropriate, which means your re-org pattern looks good :)

-Jerod

On Fri, Oct 17, 2008 at 7:25 AM, T.J. Crowder [EMAIL PROTECTED]wrote:


 Hi folks,

 The initial let's get something out there layout I did for the
 unofficial wiki[1] has a clear distinction between Prototype and
 script.aculo.us.  There are separate sections for them, and each
 section has its own list of Tips, How Tos, etc.  In fact, I even had
 us putting pages about Prototype in a prototype category and pages
 about script.aculo.us in a scripty category.
 [1] http://proto-scripty.wikidot.com

 Is there any point to that?  I mean, is the tip about minimizing
 download times (or about unobtrusive JavaScript, or about instance
 methods as callbacks/event handlers) related to Prototype or
 script.aculo.us?  My answer to that second question is Yes, both,
 which suggests that the answer to the first question is No, not
 really and we should get rid of it before things go on much further.
 (The site already has a bunch of stuff broken into these categories,
 so before things grow too much further...)

 Like many wikis, we can use tags on pages, and we've been careful to
 tag Prototype pages with a prototype tag, script.aculo.us pages with
 a script.aculo.us tag, and pages about both with both.  I tend to
 think that's enough.

 So that would leave the menu on the left looking a bit like this:

 Home
 Tips
 How Tos
 Troubleshooting
 API Notes
 Extras / Add-ons
 Resources
 Pitch In!
 Editing this wiki

 ...followed by the mini-tag cloud.

 It's a biggish reorganization, getting rid of the categories and such,
 so I thought it best to throw the idea out and see if it makes sense.

 BTW:  If you feel like pitching in, there's a list of things needed/
 wanted here:
 http://proto-scripty.wikidot.com/pitch-in

 Thanks in advance,
 --
 T.J. Crowder
 tj / crowder software / com
 



-- 
Jerod Venema

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] pass object as function argument - bind?

2008-10-17 Thread pancakes

I have searched around for some answer to this and I have a feeling I
could make it work using bind(), but I'm not sure - I'm not exactly
understanding the examples and explanations in regard to my example.

I am returning a json object from the server/ajax.  I am building some
page elements using the json object.  I'd like to allow the user to
click on the newly updated content and have that click update a
different part of the page.  But I'd like to reference the original
json object, rather than pass all of the relevant information in the
onclick.

Is this what bind() is for?  Can I *bind* my json object to a function
that refers back to the original object?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: pass object as function argument - bind?

2008-10-17 Thread T.J. Crowder

Hi,

 Is this what bind() is for?  Can I *bind* my json object to a function
 that refers back to the original object?

FWIW, I'd say it's a clever use of bind().  The question of whether
it's what bind() is *for* is kind of moot.  (I'd say, on balance, yes
it is -- bind() is for binding functions to objects [or maybe vice-
versa].  This isn't the way you normally see it used, but that's a
different matter...)  So yeah, if you don't need the context (this)
for some other purpose, no reason you can't do it like that.

Once you're at the point where you have your JSON data turned back
into an object (I'll call it 'json'), hooking up an event handler
would look like this:

$('someElement').observe('click', clickHandler.bind(json));

Then when someone clicks that element and your clickHandler() function
is called, you have access to 'json' within your function as this:

function clickHandler(evt)
{
// Get the blarg from json:
var blarg = this.blarg;
}

I don't think I've seen anyone do quite that thing before, but it
seems like a perfectly valid use of bind().

HTH,
--
T.J. Crowder
tj / crowder software / com

On Oct 17, 7:49 pm, pancakes [EMAIL PROTECTED] wrote:
 I have searched around for some answer to this and I have a feeling I
 could make it work using bind(), but I'm not sure - I'm not exactly
 understanding the examples and explanations in regard to my example.

 I am returning a json object from the server/ajax.  I am building some
 page elements using the json object.  I'd like to allow the user to
 click on the newly updated content and have that click update a
 different part of the page.  But I'd like to reference the original
 json object, rather than pass all of the relevant information in the
 onclick.

 Is this what bind() is for?  Can I *bind* my json object to a function
 that refers back to the original object?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Enumerable context - bug?

2008-10-17 Thread T.J. Crowder

 It's kind of understandable why context would
 behave the way scoping (or rather identifier resolution) works.

Oh, completely.  It's one of the big, big adjustments people like me
have to make coming to JavaScript from C++, Java, C#, etc.  All I
meant was, having made that adjustment (er, mostly) and with my
JavaScript hat on, I wasn't surprised to have the context of each()'s
iterators default to the global object, because that's what I'm used
to *in JavaScript*.  If I were coding in Java, it would be very
surprising indeed.

No, the whole question of whether the behavior of JavaScript's 'this'
pseudo-parameter (as Crockford calls it) is surprising is a
different thing entirely.  *I* was certainly surprised by it at first,
I don't mind saying. ;-)

-- T.J. :-)

On Oct 17, 8:33 pm, kangax [EMAIL PROTECTED] wrote:
 On Oct 17, 12:08 pm, T.J. Crowder [EMAIL PROTECTED] wrote:



   It's intuitive because it's like closures work.

  Not really, or at least, not if I understand what you mean.  This
  code, for instance:

  var Thingy = Class.create({

      initialize: function(name)
      {
          this.name = name;
      },

      showName: function()
      {
          alert(this.name =  + this.name);
      },

      doSomething: function()
      {
          (function(){
              alert(this.name =  + this.name);
          })();
      }

  });

  If I call it like this:

      var t;
      t = new Thingy('Fred');
      t.showName();
      t.doSomething();

  ...first alerts this.name = Fred (from showName) and then this.name
  =  (from doSomething).  The closure inside doSomething() does not
  inherit this from the scope in which it's called, so this is
  window within it.  Like all other functions, this is determined by
  *how* it's called, not where.

  Granted closures do inherit other aspects of context (in-scope vars
  and such), so if that's what you mean, I take your point.  But I think
  that's a bit apples and oranges.

 Well, some people do indeed expect *context* to behave as *scope*.
 Some people also confuse these two or believe that one depends on
 another in some way : / It's kind of understandable why context would
 behave the way scoping (or rather identifier resolution) works. Maybe,
 if context was set to the caller's one, we wouldn't have all this
 binding mess we have now.

 IIRC, Crockford was one of the first people to complain about
 context semantics (proposing something along the lines of what Tomasz
 expected)



   I think you should use simple example in like mine in API Docs to
   illustrate it's not intuitive.

  Just my two pennies worth, but it worked the way *I* expected it to.
  I haven't been using Prototype that long and I remember not being
  surprised by this, because it worked the way functions in general
  work:  I didn't explicitly supply a context, and it got the global
  object.  So I found it intuitive and would be surprised if it were
  something else without me telling it to be.  Just FWIW.
  --
  T.J. Crowder
  tj / crowder software / com

 [snip]

 --
 kangax
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: pass object as function argument - bind?

2008-10-17 Thread suki rosen
that's great.  thanks - I'm glad I was on the right track there.  This seems
very useful for dealing with ajax data.

On Fri, Oct 17, 2008 at 3:33 PM, T.J. Crowder [EMAIL PROTECTED]wrote:


 Hi,

  Is this what bind() is for?  Can I *bind* my json object to a function
  that refers back to the original object?

 FWIW, I'd say it's a clever use of bind().  The question of whether
 it's what bind() is *for* is kind of moot.  (I'd say, on balance, yes
 it is -- bind() is for binding functions to objects [or maybe vice-
 versa].  This isn't the way you normally see it used, but that's a
 different matter...)  So yeah, if you don't need the context (this)
 for some other purpose, no reason you can't do it like that.

 Once you're at the point where you have your JSON data turned back
 into an object (I'll call it 'json'), hooking up an event handler
 would look like this:

 $('someElement').observe('click', clickHandler.bind(json));

 Then when someone clicks that element and your clickHandler() function
 is called, you have access to 'json' within your function as this:

 function clickHandler(evt)
 {
// Get the blarg from json:
var blarg = this.blarg;
 }

 I don't think I've seen anyone do quite that thing before, but it
 seems like a perfectly valid use of bind().

 HTH,
 --
 T.J. Crowder
 tj / crowder software / com

 On Oct 17, 7:49 pm, pancakes [EMAIL PROTECTED] wrote:
  I have searched around for some answer to this and I have a feeling I
  could make it work using bind(), but I'm not sure - I'm not exactly
  understanding the examples and explanations in regard to my example.
 
  I am returning a json object from the server/ajax.  I am building some
  page elements using the json object.  I'd like to allow the user to
  click on the newly updated content and have that click update a
  different part of the page.  But I'd like to reference the original
  json object, rather than pass all of the relevant information in the
  onclick.
 
  Is this what bind() is for?  Can I *bind* my json object to a function
  that refers back to the original object?
 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: pass object as function argument - bind?

2008-10-17 Thread T.J. Crowder

Hi again,

I will just mention that if you start using logic objects and such on
the client side where the handler is a method of the logic object,
then this becomes more problematic, since you have two different
things you want to do with this:  Refer to the logic instance, and
refer to the 'json' object.  Not a problem if you don't intend to do
that, but if you do, Prototype makes it easy to both preserve this
AND pass an extra parameter to your event handler after the event
object:  Function.bindAsEventListener[1].  It's pretty specialized,
you don't find you need it much, but if you want to set up an event
handler and pass it extra parameters, this is what you need.
[1] http://www.prototypejs.org/api/function/bindaseventlistener

Assuming we're operating in the context where you have 'json' and
where this currently refers to your logic instance, here's how you
hook it up:

$('myelement').observe('click',
this.clickHandler.bindAsEventListener(this, json));

When clickHandler() gets triggered, this will be the logic instance,
the first parameter will be the event object, and the second parameter
will be 'json':

function clickHandler(evt, json)
{
// Get the glarb from json
var glarb = json.glarb;

// Do something with it using another method of this instance
this.doSomething(glarb);
}

FWIW,
--
T.J. Crowder
tj / crowder software / com


On Oct 17, 8:51 pm, suki rosen [EMAIL PROTECTED] wrote:
 that's great.  thanks - I'm glad I was on the right track there.  This seems
 very useful for dealing with ajax data.

 On Fri, Oct 17, 2008 at 3:33 PM, T.J. Crowder [EMAIL PROTECTED]wrote:



  Hi,

   Is this what bind() is for?  Can I *bind* my json object to a function
   that refers back to the original object?

  FWIW, I'd say it's a clever use of bind().  The question of whether
  it's what bind() is *for* is kind of moot.  (I'd say, on balance, yes
  it is -- bind() is for binding functions to objects [or maybe vice-
  versa].  This isn't the way you normally see it used, but that's a
  different matter...)  So yeah, if you don't need the context (this)
  for some other purpose, no reason you can't do it like that.

  Once you're at the point where you have your JSON data turned back
  into an object (I'll call it 'json'), hooking up an event handler
  would look like this:

  $('someElement').observe('click', clickHandler.bind(json));

  Then when someone clicks that element and your clickHandler() function
  is called, you have access to 'json' within your function as this:

  function clickHandler(evt)
  {
     // Get the blarg from json:
     var blarg = this.blarg;
  }

  I don't think I've seen anyone do quite that thing before, but it
  seems like a perfectly valid use of bind().

  HTH,
  --
  T.J. Crowder
  tj / crowder software / com

  On Oct 17, 7:49 pm, pancakes [EMAIL PROTECTED] wrote:
   I have searched around for some answer to this and I have a feeling I
   could make it work using bind(), but I'm not sure - I'm not exactly
   understanding the examples and explanations in regard to my example.

   I am returning a json object from the server/ajax.  I am building some
   page elements using the json object.  I'd like to allow the user to
   click on the newly updated content and have that click update a
   different part of the page.  But I'd like to reference the original
   json object, rather than pass all of the relevant information in the
   onclick.

   Is this what bind() is for?  Can I *bind* my json object to a function
   that refers back to the original object?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Autocomplete not working with ColdFusion

2008-10-17 Thread behaviour

The tutorial that I'm referencing is located here:  
http://tutorial473.easycfm.com
There are many posts of this all over the internet it seems, with
slight variations, but this one makes most sense to me.

Where it's not working is where it's checking to see if the variable
has been passed to the cfm page.  The variable never exists no matter
what I try.  CFIF IsDefined(FORM.SearchCriteria)  It's supposed to
simply pass what you type in the textbox with the name of the variable
being the name attribute of the textbox.  Does not work.

Here is the exact code that I'm using, pasted below.  First is the
search code (I won't include the entire page as we don't need it),
second is the CF page that basically only displays ALL results because
the SearchCriteria variable doesn't get passed for some reason.

Thanks so much in advance for all your help!

Jeff W!


SEARCH PAGE CODE

FORM NAME=SearchForm ACTION=Contacts.cfm METHOD=Post
TARGET=DataFrame
TABLE CELLSPACING=0 CELLPADDING=0
CFOUTPUT
TR
TDnbsp;nbsp;INPUT CLASS=textbox TYPE=Text 
ID=SearchData
NAME=SearchCriteria SIZE=32 VALUE=CFIF Session.SearchCriteria IS
Contact SearchCFELSE#Session.SearchCriteria#/CFIF onBlur=if
(this.value == '') this.value='Contact Search' onFocus=if
(this.value ==
'Contact Search') this.value='' AUTOCOMPLETE=Off
DIV ID=Search_Choices CLASS=autocomplete/DIV
SCRIPT TYPE=text/javascript LANGUAGE=JavaScript
var myAutoCompleter = new 
Ajax.Autocompleter('SearchData',
'Search_Choices', 'Suggest.cfm', {});
/SCRIPT/TD
/TR
/CFOUTPUT
/TABLE
/FORM


CODE FOR THE CF PAGE

CFIF IsDefined(FORM.SearchCriteria)
CFSET name_parameter=#FORM.SearchCriteria#
CFELSE
CFSET name_parameter=
/CFIF

!--- Get Contacts search suggestion ---
CFQUERY NAME=GetContactSuggestions DATASOURCE=#Application.DSN#
MAXROWS=4
SELECT ContactID, ContactName, FirstName
FROM Contacts
WHERE MasterClientID = #Session.MasterClientID# AND BookID =
#Session.AddressBook# AND Hidden = '#Session.ABViewHidden#' AND
ContactName
Like '#name_parameter#%'
ORDER BY ContactName, FirstName
/CFQUERY

ul
  cfoutput query=GetContactSuggestions
  li#ContactName#, #FirstName#/li
  /cfoutput
  cfif GetContactSuggestions.RECORDCOUNT EQ 4
  li...more (refine search)/li
  /cfif
/ul

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: pass object as function argument - bind?

2008-10-17 Thread Trevan Richins

pancakes wrote:
 I have searched around for some answer to this and I have a feeling I
 could make it work using bind(), but I'm not sure - I'm not exactly
 understanding the examples and explanations in regard to my example.
 
 I am returning a json object from the server/ajax.  I am building some
 page elements using the json object.  I'd like to allow the user to
 click on the newly updated content and have that click update a
 different part of the page.  But I'd like to reference the original
 json object, rather than pass all of the relevant information in the
 onclick.
 
 Is this what bind() is for?  Can I *bind* my json object to a function
 that refers back to the original object?

You could also use curry() or the builtin curry functionality of bind().
 If you do someFunction.bind(this, jsonObject) then when someFunction is
called, the 'this' will point to the first parameter in the bind call,
the first argument to someFunction will be jsonObject and the other
arguments will be the arguments that are passed in through other means.
 So if someFunction was an event listener, the second parameter would be
the event.

An example code would be:

var test = Class.create({

initialize: function() {
   this.func1 = someFunction.bind(this, {dummy: 1});
   this.func2 = someFunction.bind(this, {dummy: 2});

   $('nodeId1').observe('click', this.func1);
   $('nodeId2').observe('click', this.func2);
},

someFunction: function(data, event) {
},

});

So when you click on nodeId1, the data will be {dummy: 1}.  If you click
on nodeId2, the data will be {dummy: 2}.

Trevan

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---