[Proto-Scripty] Re: Ajax call is not working in MAC(Firefox)

2009-07-21 Thread T.J. Crowder

@Alex:

> try changing "date" to "d" or something in "var date=.." incase FF on MAC
> might reserve the word or mistake the case of it for "Date" and
> re-variablise the class

That would be a truly massive bug in FF, I doubt it would get out of
beta.

@Atanu:

Firebug[1] works on the Mac, I'd suggest walking through the code in
the debugger (the script panel).

[1] http://getfirebug.com/

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


On Jul 21, 11:14 am, "Alex McAuley" 
wrote:
> try changing "date" to "d" or something in "var date=.." incase FF on MAC
> might reserve the word or mistake the case of it for "Date" and
> re-variablise the class
>
> Alex Mcauley
> Developer
> The Vacancy Market LTDhttp://www.thevacancymarket.com
>
>
>
> - Original Message -
> From: "Atanu Dey" 
> To: "Prototype & script.aculo.us" 
> Sent: Tuesday, July 21, 2009 11:05 AM
> Subject: [Proto-Scripty] Re: Ajax call is not working in MAC(Firefox)
>
> Thanks a lot for your replies. I was not on my machine so got late to
> reply here
>
> You can see that there is a commented code:
>
> //console.log('setOnlineStatus.php?sid='+date.getTime());
>
> I cannot see that log and also there is no ajax call taking place.
> there is no javascript error found in the firebug.
>
> what I can see that it is not getting inside the function for
> periodical executer...
>
> not sure why but, this is working properly in windows with the same
> version of firefox...
>
> On Jul 21, 2:57 pm, "Alex McAuley" 
> wrote:
> > LOL @ western democracies !
>
> > Wish my scripts could do that
> > ;)
>
> > Alex Mcauley
> > Developer
> > The Vacancy Market LTDhttp://www.thevacancymarket.com
>
> > - Original Message -
> > From: "T.J. Crowder" 
> > To: "Prototype & script.aculo.us"
> > 
> > Sent: Tuesday, July 21, 2009 10:51 AM
> > Subject: [Proto-Scripty] Re: Ajax call is not working in MAC(Firefox)
>
> > Hi,
>
> > "Not working" in what way? Does it...
>
> > ...do nothing?
> > ...raise an error?
> > ...stop all scripts on the page?
> > ...turn the entire page mauve?
> > ...depress the economies of the western democracies?
>
> > You get the idea, there are dozens of things "not working" could
> > mean. ;-)
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Jul 21, 8:13 am, Atanu Dey  wrote:
> > > I have a script which executes periodically after each 10 seconds. You
> > > can see that there is an ajax call which actually updates database for
> > > me and return 1 or 0 depending of the script execution.
>
> > > The problem is, it is working cool in windows platform with firefox
> > > 3.0.11. But not working with the same version of firefox in MAC OS.
>
> > > The Script:
>
> > > new PeriodicalExecuter(function(){
> > > var date = new Date();
> > > //console.log('setOnlineStatus.php?sid='+date.getTime());
> > > new Ajax.Request('setOnlineStatus.php?sid='+date.getTime(),
> > > {method:'get', onComplete:function(transport){
> > > if(!parseInt(transport.responseText))
> > > window.location="../index.php";
> > > }});
> > > },10);
>
> > > Can anybody has any idea about this? Thanks in advance for your 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
-~--~~~~--~~--~--~---



prototype-scriptaculous@googlegroups.com

2009-07-24 Thread T.J. Crowder

Hi Mona,

> ticket#559 is very relevant indeed, and the final patch contained
> " ... id = id.replace(/[\.:]/g, "\\$1"); ... " [1]
> does solve the issue with dots and colons in IDs.
>
> However, looks like this patch didn't make it to the 'bleeding-edge
> version'. [3]

The fix is in trunk:
http://github.com/sstephenson/prototype/blob/add69978e09653808aedec43ed551df22818ee30/src/dom/selector.js

...and so will come out with the next RC.  I have no idea when that
will be, I'm not on the core team.  Until then, probably best to keep
using your manually-patched version or grab the latest source and
build it.

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


On Jul 21, 11:05 am, Mona Remlawi  wrote:
> Hi T.J.,
>
> ticket#559 is very relevant indeed, and the final patch contained
> " ... id = id.replace(/[\.:]/g, "\\$1"); ... " [1]
> does solve the issue with dots and colons in IDs.
>
> However, looks like this patch didn't make it to the 'bleeding-edge
> version'. [3]
> Instead, there is the old (still buggy) patch
> " ... id = id.replace(/[\.:]/g, "\\$0"); ... " [2]
>
> So, I don't know how to go from here, is RC4 due any time soon (i
> really dislike manual changes in prototype core :) )
>
> [1]http://github.com/sstephenson/prototype/commit/059ce21040ce1c469d13c3...
> [2]http://github.com/sstephenson/prototype/commit/97fc24a0b2f32717c40a0d...
> [3]http://prototypejs.org/assets/2009/6/16/prototype.js
>
> Thanks a lot, always helpful
>
> cheers
>
> --
> mona
>
>
>
> On Tue, Jul 21, 2009 at 11:41 AM, T.J. Crowder 
> wrote:
>
> > Hi Mona,
>
> > I agree, dots and colons are valid in HTML, and so should work with
> > the selector engine.
>
> > I took a quick look at Lighthouse[1], and it looks like there may be a
> > ticket[2] or two[3] there that is relevant, although #559 is marked as
> > fixed in 1.6.1 and you say what you're seeing is still an issue in
> > RC3.  It was a very quick search, though, so please have a good look
> > and open a ticket if you don't find one already open for this.  (I'm
> > surprised that both 1.6.0.3 and 1.6.1 should have this bug, as they
> > use completely different selector engines.)
>
> > FWIW, can I suggest a one-page test case with no dependancies other
> > than Prototype?  Just something very simple; the one you posted
> > earlier is a bit much to grok in the time most people have available.
> > (Maybe this is less true for people who have used scripty's unit test
> > suite more than I.)
>
> > [1]http://prototype.lighthouseapp.com/projects/8886-prototype
> > [2]https://prototype.lighthouseapp.com/projects/8886-prototype/tickets/559
> > [3]https://prototype.lighthouseapp.com/projects/8886-prototype/tickets/501
>
> > Cheers,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Jul 21, 10:28 am, Mona Remlawi  wrote:
> >> "
> >> 
> >> ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
> >> followed by any number of letters, digits ([0-9]), hyphens ("-"),
> >> underscores ("_"), colons (":"), and periods (".").
> >> ...
> >> " [1]
>
> >> So if HTML permits a '.' in the ID value of elements, so should prototype 
> >> core.
>
> >> Another point is that even if I rewrote my selectors, there would
> >> still be a problem in doing the following
>
> >> $('my\.long\.id').down('.myclass');
>
> >> as prototype would translate this into :
> >> element.querySelectorAll('#my.long.id .myclass')
>
> >> I still insist that escaping 'special' chars in Element#identify
> >> method is the way to go ...
>
> >> [1]http://www.w3.org/TR/html4/types.html#type-name
>
> >> cheers
>
> >> --
> >> mona
>
> >> On Tue, Jul 21, 2009 at 4:16 AM, Rick Waldron 
> >> wrote:
> >> > I feel like i should provide more insight. That was rather vague. An ID
> >> > could be labelled "a.b:c" and referenced in your style sheet as #a.b:c 
> >> > but
> >> > as well as being the id of an element, it could mean:
>
> >> > id "a", class "b", pseudo-selector "c".
>
> >> > Best to avoid the confusion and stay away from using . and : altogether.
>

[Proto-Scripty] Re: Is there a standard Ajax Event ?

2009-07-24 Thread T.J. Crowder

Hi,

For Ajax calls *via Prototype*, there's Ajax.Responders[1].  I'm
pretty sure there's no generic event for all direct XHR uses.

[1] http://prototypejs.org/api/ajax/responders

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


On Jul 24, 6:28 pm, "Joachim H. Skeie"  wrote:
> Hello,
>
> I would like to be able to execute code whenever an ajax event is
> triggered. The reason for this, is that I need to know that the DOM is
> finished loading when I first execute the code.
>
> I have my code inside the
>
> document.observe('dom:loaded'...
>
> I would also llike to be able to execute some JavaScript code on a
> ajax success, something like
>
> document.observe('ajax:success'...
>
> Does anyone know if this is available in Prototype by default ?
--~--~-~--~~~---~--~~
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: compatibility prototype_scriptaculos et mootools

2009-07-24 Thread T.J. Crowder

Hi,

IIRC, MooTools started life as a fork of Prototype. I can't imagine it
would be all that hard to port sound.js to it.  sound.js is very short
and at first glance, most of its few dependancies it has on Prototype
($, $$) are direct mappings in MooTools anyway.

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

On Jul 24, 6:34 pm, lvdesign  wrote:
> Thanks Richard for this proposition but i knew it and it's a very good
> solution.
>
> But i search a no_flash solution,  only .js and the prototype function
> sound is apparently the only one.
>
> Merci, cordialement.
>
> On Jul 24, 3:30 pm, Richard Quadling  wrote:
>
>
>
> > 2009/7/23 lvdesign :
>
> > > Thanks for the messsage and you know what?  i am very happy to know
> > > that! (sic)
>
> > > but where i can find an clever library with sound.js? i must created
> > > it?
>
> > > bye, bye and merci encore.
>
> > > On Jul 23, 8:29 pm, Tobie Langel  wrote:
> > >> Hi.
>
> > >> Mootools and Prototype are unfortunately totally incompatible.
>
> > >> You'll have to choose one or the other.
>
> > >> Best,
>
> > >> Tobie
>
> > >> On Jul 23, 6:10 pm, lvdesign  wrote:
>
> > >> > Hi, i am new french member. So i hope you could understand my
> > >> > question.
>
> > >> > I use several .js library for a site's development and i have a
> > >> > conflict between prototype and mootools.
>
> > >> > I resolve the problem with Jquery and proto like that:
>
> > >> > //--pour jQuery
> > >> > jQuery(function($) {
> > >> > //functionDoSomething
>
> > >> > });
>
> > >> > jQuery.noConflict()
> > >> > jQuery(document).ready(function ($) {
> > >> >  $('.functionDoSomething').functionDoSomething();
>
> > >> > });
>
> > >> > //
>
> > >> > I would like only use sound.js of prototype. [ Not another library
> > >> > propose this fonctionality(?)]
>
> > >> > How can i do to resolve the $ conflict ?
>
> > >> > thanks a lot for the answer
>
> > >> > Merci d'avance pour une réponse
>
> > I use the SoundManager [1]
>
> > Doesn't require prototype.
>
> > [1]http://www.schillmania.com/projects/soundmanager2/
>
> > --
> > -
> > Richard Quadling
> > Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731
> > "Standing on the shoulders of some very clever giants!"
> > ZOPA :http://uk.zopa.com/member/RQuadling
--~--~-~--~~~---~--~~
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: scriptaculous & PHP help

2009-07-24 Thread T.J. Crowder

Hi,

> echo " {duration: 2.0}); return false;\">$directory";

I'm not a PHP guy, but surely that ends up outputting HTML that has an
onclick attribute calling Effect.toggle on the literal element ID
"d2"?  And of course, IDs are unique in a page, so that's only ever
going to affect one element.

If you want to affect other elements, you'll have to give them unique
IDs and make the call use those IDs appropriately.

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


On Jul 24, 7:27 pm, dmcglone  wrote:
> Hi all,
>
>  I am trying to create a page that reads a directory of images and
> displays them with scriptaculous. So far from what I have, the code
> does work as far as displaying the directory links but it is only
> making the very 1st one active, all the rest of the directory links on
> the page work, BUT they are expanding and folding only the first
> directory (gemstone).
>
> I hope this was a good explanation. I've posted my code to help make
> it as clear as I can.
>
> Here is my code:
>
>  echo "";
> echo '';
>
> $directories = array('gemstone', 'bella', 'passage', 'sedona',
> 'deepstar', 'crystalline');
>
> foreach ($directories as $directory){
>
> $mydir2=opendir("images/laminate/Wilsonart_Laminate_Colors/
> $directory");
>
> $cats2=array();
>
> echo " {duration: 2.0}); return false;\">$directory";
>
> while(($cat2=readdir($mydir2)) !==false){
>
> if ($cat2 != "." && $cat2 != ".." && strpos(strtolower($cat2),"-
> thumb.jpg") !== false){
> array_push($cats2, $cat2);
>
> echo "";
>
> echo "";
>
> }
> }
>
> closedir($mydir2);
>
> }
>
> echo "";
> echo "";
>
> ?>
>
> Blessings
> David M.
--~--~-~--~~~---~--~~
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: A ceiling for the update interval.

2009-07-26 Thread T.J. Crowder

Hi,

FWIW, it sounds good to me -- useful and dead simple to implement.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 26, 6:39 am, Krish  wrote:
> It would be really useful to have a max value on update interval for
> the periodic updater. I didnt see anything about this in the
> documentation.
> and doesn't look like it has one.
>
> 1506:    this.timer = this.onTimerEvent.bind(this).delay(this.decay *
> this.frequency);
>
> What do you guys think about this suggestion?
>
> Regards
> Krish
--~--~-~--~~~---~--~~
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: get controls array

2009-07-26 Thread T.J. Crowder

Hi,

> obviously that I'll never have really an array of controls... but if I
> get an array when I use getElementsByName()

If you have the brackets in the names, getElementsByName isn't going
to get you the elements either:

HTML:







JavaScript:
var list = document.getElementsByName('test');
alert(list.length);

Result:
Alerts "0"

If they all had the exact same name, it would, but not if they also
have brackets with differing numbers inside.

> my question was whether to "prototype" implements a short call to do
> the same... something like $X('myarray')

Prototype provides several features that help in this situation.  The
two most useful, probably, have already been mentioned -- Douglas
pointed out that using classes and Prototype's $$ function could
easily solve the problem, and Colin pointed out that Prototype
provides nearly all of CSS Level 3 selectors, even on browsers that
don't have them natively.

Something else that might help is Prototype's extensive features for
arrays and enumerables, like Enumerable#findAll[1], which lets you
easily filter an enumerable for the items you want.  Combined with
Element#select[2] (if all of the elements you want have a common
parent) or $$[3] (if you want to look globally in the document), it's
very easy to filter:

HTML:







JavaScript:
var list = $$('input[type=text]').findAll(function(elm) {
return (elm && elm.name && elm.name.startsWith('test'));
});
alert(list.length);

Result:
Alerts "4"

In there, I also used another feature of Prototype, String#startsWith
[4].

But if you can use classes, or there's some way to identify these
things with just CSS selectors, all the better.

[1] http://prototypejs.org/api/enumerable/findall
[2] http://prototypejs.org/api/element/select
[3] http://prototypejs.org/api/utility/dollar-dollar
[4] http://prototypejs.org/api/string/startswith

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


On Jul 25, 10:36 pm, diegoturriaga  wrote:
> maybe I haven't explained well (my English is not good) or I'm reading
> or translating wrong the answers
>
> obviously that I'll never have really an array of controls... but if I
> get an array when I use getElementsByName()
>
> my question was whether to "prototype" implements a short call to do
> the same... something like $X('myarray')
>
> Well, what I was doing and I finished, so we can close this topic.
>
> On 24 jul, 07:11, ColinFine  wrote:
>
>
>
> > On Jul 24, 1:02 am, diegoturriaga  wrote:
>
> > > Well... first that all thanks for your reply!
>
> > > I'm trying to use a multidemensional javascript array... various
> > > arrays of input controls of type checkbox
>
> > > I have 10 controls with name "myarray[1][]"
> > > other 10 controls with name "myarray[2][]"
> > > other 10 controls with name "myarray[3][]"
> > > ...
> > > other 10 controls with name "myarray[n][]"
>
> > > And I need get al controls named iqual in an array var... something
> > > like:
>
> > > var aux = document.getElemntsByName('myarray[1][]`);
>
> > > but using prototype sintax... :)
>
> > I'm not sure if you are under a misapprehension.
>
> > The value of a 'NAME' property in HTML is a CDATA - a string of text.
> > It has no structure.
> > You are free to call an input "opt[0][]" but that is a text string,
> > not any kind of an array in any language.
> > (PHP kindly treats inputs with [] in their names specially, but that
> > is the server-side program, not anything to do with the page or
> > javascript: I don't know whether any other server-side languages do
> > this).
>
> > So if you want to use prototype (or any other javascript) to
> > manipulate these names, you must treat them as text: match them as
> > text, perhaps even 'eval' them. But they are not arrays in any way.
>
> > As Matt says, the nearest you can get to this in Prototype is by using
> > the =~ match in a CSS selector, but that will not necessarily do what
> > you need. Otherwise you will have to do basic Javascript text
> > matching, or use the suggestions others have made.
>
> > (It may be that you already understand the point I am making, in which
> > case, my apologies).- Ocultar texto de la cita -
>
> > - Mostrar texto de la cita -
--~--~-~--~~~---~--~~
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: Using a prototype function in dynamic content.

2009-07-26 Thread T.J. Crowder

Hi,

If you replace an element, even if the replacement has the same ID as
the original, you will have toinitialize a new InPlaceEditor.  It
grabs a reference to the element instance, which is different for the
replacement than for the original.  It would be best to *also* remove
the InPlaceEditor for the previous version of the element, so as to
free up memory.

So, say you have this div:


...
Blah blah blah
...


And you put an editor on the paragraph:

new Ajax.InPlaceEditor('editme', url);

If you replace it:

$('div').update('new content');

...then the previous paragraph element ceases to exist, and there's
nothing to indicate that the new element has an InPlaceEditor.

Instead, remember a reference to the editor when first setting it up:

var editor;
...
editor = new Ajax.InPlaceEditor('editme', url);

...and then destroy it and recreate it when updating:

if (editor) {
editor.dispose();
editor = undefined;
}
$('div').update('new content');
editor = new Ajax.InPlaceEditor('editme', url);

That's all inline code, you'll probably want to put some structure
around it, but you get the idea.

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


On Jul 26, 2:25 pm, Drum  wrote:
> I have a page which include a list of user entered keywords on which I
> want to be able to use Ajax.InPlaceEditor.
>
> It works fine when the initial page loads, The initial list is in the
> initial HTML and includes the calls to the editor.
>
> When, however, the div with the list and calls to the editor has been
> written using innerHTML = responseText, it does not work.
>
> I get no errors in Firebug, but the javascript is not running.
>
> Any 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] Re: RJS-Template and link_to_remote

2009-07-27 Thread T.J. Crowder

Hi,

This group is for discussing Prototype and script.aculo.us, most of us
have never used Ruby or Rails.  You're probably better off posting to
the Rails group[1].

[1] http://groups.google.com/group/rubyonrails-talk

Good luck with it,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 27, 6:49 pm, Drr  wrote:
> Hi, I am quite new to rails and can't use any rjs-templates.
> The problem is, that he can't use/find the methods in that template
> e.g. 'page' or 'replace_html'. I get an error message on these
> methods.
>
> Here's what I got so far in my example:
>
> Controller:
> 
> class AjaxTestController < ApplicationController
>   layout 'application', :except => :say_hello
>
>   def index
>   end
>
>   def say_hello
>     @message = "Hello World"
>     respond_to do |format|
>       format.js
>     end
>   end
>
> end
> 
>
> Layout
> 
> 
>  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
>
> http://www.w3.org/1999/xhtml"; xml:lang='en'>
> 
> Ajax
>   <%= javascript_include_tag :defaults %>
> 
> 
>   <%= yield %>
> 
> 
> 
>
> index.html.erb
> 
> Helloworld#index
>
> <%= link_to_remote "Click",
>      :url => {:action => "say_hello"} %>
>
> ...
> 
>
> say_hello.rjs
> ---
> page.replace_html 'message', @message
> page.visual_effect(:highlight, 'message', :duration => 0.5)
> ---
>
> its quite simple but does not work anyway. I don't guess why it
> behaves like this. If I use the controller for that ajax request,
> everything is ok...it's just that template thing i can't fix. Anyone
> got an idea where the problem might be?
--~--~-~--~~~---~--~~
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: how sum value from input?

2009-07-29 Thread T.J. Crowder

Hi,

That version seems okay, except it parses the number twice (first for
isNaN, then again in parseFloat).  There's also no need to check for a
blank string, '' can't be converted to a number and so parsing it will
result in NaN.  Also, parseFloat defaults to base 10, so no need for
that param (but by all means include it if you think it makes the code
clearer).

var i;
var suma = 0;
var valor;
for (i = 1; i <= 24; i++) {
valor = parseFloat($F('quincena_'+ i).strip());
if (!isNaN(valor)) {
suma += valor;
}
}

Note that parseFloat will stop at the first invalid character, so this
doesn't do much in the way of validation.  For instance, if the field
contains "15x5", parseFloat will return 15, not NaN.  If you need real
validation, you'll probably want RegExps to test for valid patterns.
A web search should do it, if you need to take it that far.

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


On Jul 29, 12:56 am, "Miguel Beltran R."  wrote:
> Hi list
>
> I have the next code, but how can be made better?
>
>          var i;
>          var suma=0;
>          var valor;
>          for(i=1; i<=24; i++){
>             valor=$F( 'quincena_'+ i).strip();
>             if(valor!='' && !(isNaN(valor))){
>                suma+=parseFloat(valor,10);
>             }
>        }
>
> --
> 
> Lo bueno de vivir un dia mas
> es saber que nos queda un dia menos de vida
--~--~-~--~~~---~--~~
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: postBody

2009-07-29 Thread T.J. Crowder

Hi,

HTML doesn't matter in POSTs, HTML is a browser concept.  POSTs are an
HTTP concept, which is a different layer and doesn't care about HTML.

POST data is URL-encoded (certain characters -- like percent signes --
turned into hex escapes, that sort of thing).

Prototype can handle it for you.  If you supply the data to post as an
object, Prototype will serialize and URL-encode it for you before
sending it, e.g.:

new Ajax.Request(url, {
parameters: {
'foo':  7,
'bar':  'This is a really cool thing.'
}
});

That anonymous object gets serialized, URL-encoded, and transmitted.
At the other end, whatever server-side software you're using will URL-
decode it and populate some sort of object with the fields
"foo" (value "7" -- everything arrives as a string) and "bar" (value
"This is a really cool thing.").  In transit, that string
will look quite different, but you don't have to worry about it
(unless you're looking at the underlying data for debugging reasons).

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


On Jul 29, 3:14 pm, jeremyrowe  wrote:
> I am trying to send postBody data through an Ajax.Request - The data
> contains html tags, and I am wondering what the best way to encode /
> decode the data so that I can make sure that the data is saved
> properly.
>
> 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-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: problems with observe mouseover and mouseout

2009-07-30 Thread T.J. Crowder

Hi,

> I have a realy similar issue as this one, but more on the mouseout
> event. Effectively, if I observe a mouseout on a ul, every time my
> mouse goes from one li to the other, a mouseout event is triggered.

That's right, that's how mouseout is supposed to work, but it's a real
pain.

What you probably really want is mouseenter and mouseleave, rather
than mouseover and mouseout.  mouseenter and mouseleave are IE-only
events (yes, IE does some things better than other browsers), but
Prototype 1.6.1 (currently on Release Candidate 3[1]) emulates them on
all supported browsers.  If you can't use 1.6.1 yet (and there are
outstanding issues), you might be able to study the code to see how
it's done.  Basically, it's a matter of checking (via
event.relatedTarget) whether the mouse is going "out" from one
descendant element to another (or from a descendant back to the main
one) and ignoring that; similarly, if you're doing mouseovers, when
handling them you need to check whether you're seeing a mouseover for
the element you're already over (since mouseover happens repeated as
the mouse moves over the element).

[1] http://prototypejs.org/download

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

On Jul 29, 11:04 pm, Christophe  wrote:
> I have a realy similar issue as this one, but more on the mouseout
> event. Effectively, if I observe a mouseout on a ul, every time my
> mouse goes from one li to the other, a mouseout event is triggered.
>
> I tried to make a check in the target function to see which element
> was doing the call, but I didn't always receive the ul...
>
> Is this how it's supposed to be done ? Has anyone an example somewhere
> of a mouseout use (on an element with children elements) ?
>
> Kind regards,
> Christophe
>
> On 17 juil, 09:37, David Behler  wrote:
>
>
>
> > Try this:http://www.prototypejs.org/api/event/findElement
>
> > $$(".superlist li").invoke("observe", "mouseover", function(event) {
> >     alert(|Event.findElement(event, 'li')|.inspect().escapeHTML()
> > |);
> > |});
>
> > That should return the li element instead of a div.
>
> > David
>
> > > Hello everyone.
>
> > > I've basically got this HTML code:
>
> > > 
> > >   
> > >     some content
> > >     some more content
> > >     some actions
> > >   
> > > 
>
> > > and this JS code:
>
> > > $$(".superlist li").invoke("observe", "mouseover", function(event) {
> > >     alert(event.element().inspect().escapeHTML());
> > > });
>
> > > So now the thing is, that the event.element() method does NOT (as I
> > > would expect) return the  element, but any of the nested elements
> > > instead. Which might be a  or a  > > class="content">.
>
> > > That results in two problems for me:
> > > 1. I want to toggle the visibility of li.actions for the li hovered.
> > > It shall become visible on mouseover and unvisible onmouseout. That
> > > doesn't work since anytime I move over one of the li's nested
> > > elements, the mouse-events get triggered. Although (from my point of
> > > view) I'm never leaving that element, since they are indeed children
> > > of the li.
>
> > > 2. (similar to the first one) I do always need to know which li
> > > element was hovered (so that I can determine which .actions div shall
> > > be toggled but don't know any good way to achieve this.
>
> > > I've run through similar problems like this several times but could
> > > never find a good solution.
> > > Hope anyone here can help me out :-)
--~--~-~--~~~---~--~~
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: IE8 invalid argument line 4501

2009-07-30 Thread T.J. Crowder

Hi,

> ...if you
> register an observer on the 'dom:load' event in a constructor
> (initialize) thats supposed to fire one of the object methods (like
> 'this.recolour()') it will end up as an infinite loop in IE6, IE7 and
> IE8...

Can you post a small, self-contained, complete example demonstrating
the problem?  (Perhaps using http://pastie.org for formatting.)
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Jul 30, 9:21 am, Eirik  wrote:
> I encountered this error in all versions of IE8 without non-alpha IDs.
> After a lot of debugging and head scratching i discovered that if you
> register an observer on the 'dom:load' event in a constructor
> (initialize) thats supposed to fire one of the object methods (like
> 'this.recolour()') it will end up as an infinite loop in IE6, IE7 and
> IE8 causing IE to report a stack overflow and invalid argument at this
> line.
>
> This is the closest i could find to a thread on this problem, so i am
> writing up my discoveries here just in case other developers encounter
> this.
>
> This behavior was present in Prototype 1.6.0 and at least 16.1rc3,
> these are the versions I've worked with.
>
> Best regards,
> Eirik
>
> On Jul 23, 1:28 pm, Jeff  wrote:
>
>
>
> > We've having this exact error with IE8 and it's always related to
> > developers using element IDs that begin with non-Alpha characters.
> > Doing something like adding and underscore to the id fixes the
> > problem.
>
> > On Jul 14, 6:37 am, adamski  wrote:
>
> > > We're now going through the enjoyable task of getting our app working
> > > in IE, 6-8 we are aiming for.
>
> > > We just downloaded the latest prototype RC3, which seems to fix a few
> > > errors, however, I am getting this error on page load, IE8 only:
>
> > > Message: Invalid argument.
> > > Line: 4501
> > > Char: 9
> > > Code: 0
> > > URI:http://bgp.brightgreen.local/javascripts/prototype.js?1247565795
>
> > > and also from scriptaculous effects.js:
>
> > > Message: Exception thrown and not caught
> > > Line: 485
> > > Char: 24
> > > Code: 0
> > > URI:http://bgp.brightgreen.local/javascripts/effects.js
>
> > > Anyone else come across these?
--~--~-~--~~~---~--~~
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: Any javascript included in document loaded in div with Updater isn't recognized

2009-07-30 Thread T.J. Crowder

Hi,

You're looking for the evalScripts option of Ajax.Updater[1], which in
turn uses Element#update[2] to update the target container, which in
turn (!) uses String#evalScripts[3] to eval the scripts.  Scripts must
be inline in script tags, they cannot have src attributes loading
external scripts.  If you want to do that, there's an article[4] on
the unofficial wiki that talks about how to do that.

[1] http://prototypejs.org/api/ajax/updater
[2] http://prototypejs.org/api/element/update
[3] http://prototypejs.org/api/string/evalScripts
[4] http://proto-scripty.wikidot.com/prototype:how-to-load-scripts-dynamically

FWIW, I suggest giving the API a good front-to-back read.  Takes about
an hour, and will save you lots of time and trouble in the long run.

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

On Jul 30, 3:31 pm, DJJQ  wrote:
> Hello.
> I use the Updater function to load a div on the page with contents
> from a php file. The load works just fine, however in the browser I
> have noticed that new javascript written in the new php isn't
> recognized.
>
> However javascript code from the original page is recognized in the
> new div.
>
> I understand that perhaps the ordinary script tagging in the head of
> the new document doesn't work. Well is there any prototype function to
> load the javascript codes?
>
> Best Regards, Joel H.
--~--~-~--~~~---~--~~
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: Using a prototype function in dynamic content.

2009-07-30 Thread T.J. Crowder

Hi,

Really close. :-)  But you're running afoul of how eval handles the
var statement.  (If you'd just left the var statement out entirely, it
probably would have worked thanks to the horror of implicit globals
[1], but you'd be cluttering up the window namespace something
fierce.)  Also,  you're repeating a lot of code.

Instead, I'd suggest declaring a hash of editors on your main page
(not the stuff loaded dynamically) and a function for adding or
replacing one; and may as well wrap those up into just the one global
symbol:

In your main script:
* * * *
var ipeManager = {
editors: {},

addOrReplaceEditor: function(id, url, size, paramstr) {
var eds;

eds = this.editors;

if (eds[id]) {
eds[id].dispose();
eds[id] = undefined; // Or: delete eds[id];
}

eds[id] = new Ajax.InPlaceEditor(
id,
url,
{
size: size,
callback: function(form, value) {
return paramstr + escape(value);
}
}
);
}
};
* * * *

Then the dynamic stuff can be much simpler:
* * * *
some keyword

ipeManager.addOrReplaceEditor(
   "kwdisp0101",
   './addkw.php',
   17,
   'oldwd=some%20keyword&idx=section-id&myparam='
);

* * * *

[1] http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html

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


On Jul 30, 5:51 pm, Drum  wrote:
> Ok, thanks. I think I understand the reasoning here, but I can't get
> my actual example to work.
>
> This is the script as it appears in the initially loaded page and also
> as it is in the html snippets bought in by ajax.
>
> some keyword
>
> 
> if(editor0101){
> editor0101.dispose();
> editor0101 = undefined;}
>
> var editor0101;
> editor0101 = new Ajax.InPlaceEditor('kwdisp0101','./addkw.php',{size:
> 17,callback: function(form, value) { return 'oldwd=some
> %20keyword&idx=section-id&myparam=' + escape(value)}});\n";
> 
>
> The 0101 is an example, I do this for each keyword in the list and
> derive the numbers from some php code, net will be 0102, 0103 0201
> 0202 &c. This goes for both the editor var name in the js, and for the
> dic id in the HTML.
>
> Have I missed or misunderstood something? (it's been a long day...)
--~--~-~--~~~---~--~~
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: ternary operators

2009-07-30 Thread T.J. Crowder

Hi Alex,

> However it cannot be achieved so it must be done usung if/else..

Well, this is JavaScript, there's almost always a way.  I can think of
four off the top of my head that keep it in a single expression -- but
all of them are much worse (most of them much, much, much worse) than
using an if/else. ;-)  The four are:

1. Massage the return value of the first thing you want to do to force
it to be the return value you want.  Actually, in your specific case,
you don't have to anything:

return $(arg) ? true : alert('Element Does not exist');

alert has no return value, hence your function returns either true or
undefined, which is good enough for anything branching on its return
value (undefined is falsey, after all).  If you really want a false,
use !! to force it.

Blech.

2. If you wanted to return something other than false, and if the
first part has an invariant result, you could manipulate that return
value to be falsey and use the OR operator, which is much more
powerful in JavaScript than in most languages (more here[1]):

return $(arg) ? "It's there" : (alert('Element Does not exist') ||
"It's not there");

or, demonstrating manipulation:

return $(arg) ? "It's there" : (!setTimeout(...) || "It's not there");

...since setTimeout returns a non-zero number; !setTimeout is false
and so the return value (for that second operand) is "It's not there".

Blech blech.

3. Wrap the two-part bit in an on-the-fly function:

return $(arg) ? true : (function(){ alert('Element Does not exist');
return false;})());

Blech blech cough.

4. Use eval (!):

return $(arg) ? true : eval("alert('Element Does not exist'); return
false;");

Blech blech cough retch.

I bet there are others.

So:  *Possible*, but if/else is just a way better way to go. ;-)

[1] http://blog.niftysnippets.org/2008/02/javascripts-curiously-powerful-or.html
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 30, 1:37 pm, "Alex McAuley" 
wrote:
> Sorry you missed the point i was trying to achieve.
>
> I wanted the operator to in essence evaluate 2 responses for example.
>
> alert('Element Does not exist'); alert('The second responsee');
>
> However it cannot be achieved so it must be done usung if/else..
>
> Regards
>
> Alex Mcauleyhttp://www.thevacancymarket.com
>
>
>
>   - Original Message -
>   From: Rick Waldron
>   To: prototype-scriptaculous@googlegroups.com
>   Sent: Thursday, July 30, 2009 1:18 PM
>   Subject: [Proto-Scripty] Re: ternary operators
>
>   Drop the parens around the first argument.
>
>   function foo(arg) {
>
>   return $(arg) ? true : alert('Element Does not exist');  // i commented 
> this out: false;
>
>   }
>   ...
>
>   On Tue, Jul 28, 2009 at 12:02 PM, Alex McAuley 
>  wrote:
>
>     In my usual "Not enough coffee" moments i just used an If/Else instead lol
>
>     Not sure why i was trying to cut code using a tenary ...
>
>     We live and learn
>
>     Sorry for useless post
>
>     Alex Mcauley
>    http://www.thevacancymarket.com
>
>     - Original Message -
>     From: "Jeztah" 
>     To: "Prototype & script.aculo.us" 
> 
>     Sent: Tuesday, July 28, 2009 4:51 PM
>     Subject: [Proto-Scripty] ternary operators
>
>     > Afternoon guys
>
>     > Is it possible in javascript to give out 2 answers to a tenary
>     > opertor (doesnt make sense i know - see below)
>
>     > function foo(arg) {
>
>     > return ($(arg)) ? true : alert('Element Does not exist');false;
>
>     > }
>     > ...
>     > (wrapped in window loaded function)
>
>     > foo('baz'); // doesnt exist so i want it to alert the
>     > alert and return false to halt the script...
>
>     > 
>
>     > Is this the right way to do it in the operator or cant it be done
>     > and no i dont want to make 2 functions i would like it in one if it
>     > can be done.
>
>     > Regards
>     > Alex Mcauley
>
>     >http://www.thevacancymarket.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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Escaping Input

2009-07-30 Thread T.J. Crowder

Hi,

You're sending an unencoded string (which happens to be in JSON
format) as part of your parameters string, which is meant to be URL-
encoded data.  A # sign is the least of your problems. ;-)  You'll
want to encode that with JavaScript's encodeURIComponent function[1].

Somewhat OT, but as of 1.6 (at least), the preferred way to provide
options to Ajax.Request is as an object.  If you give it a string,
that string will be converted to an object, and then later converted
back into a string.  Yes, really. :-)  Also, String has a toJSON
function you can use instead of JSON.stringify (not that it matters).

So:

entry = encodeURIComponent($('busCalForm').serialize(true).toJSON());
new Ajax.Request(
"modules/buscal/processes/saveBooking.php", {
parameters: {
year: year,
recnum: busmstr_id,
json: entry
},
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)
});

> How can I effectively escape an entire form, without
> having to get the value and escape them individually?  Is there a
> command I'm missing?

That's not quite what your code is doing; you're sending the form
fields as a JSON-encoded string in a parameter called "json".  If you
just want to send the form fields, and you don't need them to arrive
at the other end as a JSON string, there's a *much* shorter way:
Form#request[2].  Assuming that your form element has the
saveBooking.php as its action attribute:

$('busCalForm').request({
parameters: {
year: year,
recnum: busmstr_id
},
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)
});

The form fields will no longer be JSON-ified (but will be properly URL-
encoded), they'll arrive as individual parameters on the request.  If
the form field doesn't have saveBooking.php as its action and you
can't change that, the Ajax.Request can still be simplified:

params = $('busCalForm').serialize(true);
params.year = year;
params.recnum = busmstr_id;
new Ajax.Request(
"modules/buscal/processes/saveBooking.php", {
parameters: params,
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)
});

[1] 
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent
[2] http://prototypejs.org/api/form/request

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


On Jul 30, 8:27 pm, infringer  wrote:
> I have a form, I've been doing this in javascript:
>
> entry = $('busCalForm').serialize(true);
> entry = JSON.stringify(entry);
> new Ajax.Request("modules/buscal/processes/saveBooking.php", {
>          parameters: "year=" + year + "&recnum=" + busmstr_id + "&json=" +
> entry,
>          onSuccess: busCal.gotEntry.bind(this),
>          onFailure: busCal.gotFailure.bind(this)
>          });
>
> But i have a user that has typed a # in one of the fields, and the
> script dies.  How can I effectively escape an entire form, without
> having to get the value and escape them individually?  Is there a
> command I'm missing?
>
> -David
--~--~-~--~~~---~--~~
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: Escaping Input

2009-07-30 Thread T.J. Crowder

Sorry, I got my wires crossed half-way through the first one of
those.  You can't use String#toJSON, it's not a string!  Doh.
Correcting my first example:

entry = encodeURIComponent(Object.toJSON($('busCalForm').serialize
(true)));
new Ajax.Request(
"modules/buscal/processes/saveBooking.php", {
parameters: {
year: year,
recnum: busmstr_id,
json: entry
},
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)

});

Sorry 'bout that.

-- T.J. :-)

On Jul 30, 8:55 pm, "T.J. Crowder"  wrote:
> Hi,
>
> You're sending an unencoded string (which happens to be in JSON
> format) as part of your parameters string, which is meant to be URL-
> encoded data.  A # sign is the least of your problems. ;-)  You'll
> want to encode that with JavaScript's encodeURIComponent function[1].
>
> Somewhat OT, but as of 1.6 (at least), the preferred way to provide
> options to Ajax.Request is as an object.  If you give it a string,
> that string will be converted to an object, and then later converted
> back into a string.  Yes, really. :-)  Also, String has a toJSON
> function you can use instead of JSON.stringify (not that it matters).
>
> So:
>
> entry = encodeURIComponent($('busCalForm').serialize(true).toJSON());
> new Ajax.Request(
>     "modules/buscal/processes/saveBooking.php", {
>     parameters: {
>         year: year,
>         recnum: busmstr_id,
>         json: entry
>     },
>     onSuccess: busCal.gotEntry.bind(this),
>     onFailure: busCal.gotFailure.bind(this)
>
> });
> > How can I effectively escape an entire form, without
> > having to get the value and escape them individually?  Is there a
> > command I'm missing?
>
> That's not quite what your code is doing; you're sending the form
> fields as a JSON-encoded string in a parameter called "json".  If you
> just want to send the form fields, and you don't need them to arrive
> at the other end as a JSON string, there's a *much* shorter way:
> Form#request[2].  Assuming that your form element has the
> saveBooking.php as its action attribute:
>
> $('busCalForm').request({
>     parameters: {
>         year: year,
>         recnum: busmstr_id
>     },
>     onSuccess: busCal.gotEntry.bind(this),
>     onFailure: busCal.gotFailure.bind(this)
>
> });
>
> The form fields will no longer be JSON-ified (but will be properly URL-
> encoded), they'll arrive as individual parameters on the request.  If
> the form field doesn't have saveBooking.php as its action and you
> can't change that, the Ajax.Request can still be simplified:
>
> params = $('busCalForm').serialize(true);
> params.year = year;
> params.recnum = busmstr_id;
> new Ajax.Request(
>     "modules/buscal/processes/saveBooking.php", {
>     parameters: params,
>     onSuccess: busCal.gotEntry.bind(this),
>     onFailure: busCal.gotFailure.bind(this)
>
> });
>
> [1]https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global...
> [2]http://prototypejs.org/api/form/request
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Jul 30, 8:27 pm, infringer  wrote:
>
>
>
> > I have a form, I've been doing this in javascript:
>
> > entry = $('busCalForm').serialize(true);
> > entry = JSON.stringify(entry);
> > new Ajax.Request("modules/buscal/processes/saveBooking.php", {
> >          parameters: "year=" + year + "&recnum=" + busmstr_id + "&json=" +
> > entry,
> >          onSuccess: busCal.gotEntry.bind(this),
> >          onFailure: busCal.gotFailure.bind(this)
> >          });
>
> > But i have a user that has typed a # in one of the fields, and the
> > script dies.  How can I effectively escape an entire form, without
> > having to get the value and escape them individually?  Is there a
> > command I'm missing?
>
> > -David
--~--~-~--~~~---~--~~
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: What object is it exactly that's passed to the Ajax.Request onSuccess callback?

2009-07-30 Thread T.J. Crowder

Hi,

Yes, those docs are messed up (out of date, I think, and will be fixed
by the new documentation stuff in 1.6.1).  It's an Ajax.Response[1].

[1] http://prototypejs.org/api/ajax/response

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

On Jul 31, 3:57 am, David Karr  wrote:
> I've briefly surveyed the documentation, and I really can't figure out
> exactly what object is passed to the "onSuccess" callback of the
> Ajax.Request() method.  I've read one statement that says it's the
> XMLHttpRequest object, so they called the parameter "request", which
> seems very odd for an Ajax callback.
--~--~-~--~~~---~--~~
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: ternary operators

2009-07-30 Thread T.J. Crowder

Hi,

I thought that too, but tried it and it didn't work, so I figured I
had to be misremembering.  Turns out I just messed up my test. :-)

-- T.J.

On Jul 31, 5:49 am, kangax  wrote:
> On Jul 30, 3:26 pm, "T.J. Crowder"  wrote:
>
>
>
>
>
> > Hi Alex,
>
> > > However it cannot be achieved so it must be done usung if/else..
>
> > Well, this is JavaScript, there's almost always a way.  I can think of
> > four off the top of my head that keep it in a single expression -- but
> > all of them are much worse (most of them much, much, much worse) than
> > using an if/else. ;-)  The four are:
>
> > 1. Massage the return value of the first thing you want to do to force
> > it to be the return value you want.  Actually, in your specific case,
> > you don't have to anything:
>
> > return $(arg) ? true : alert('Element Does not exist');
>
> > alert has no return value, hence your function returns either true or
> > undefined, which is good enough for anything branching on its return
> > value (undefined is falsey, after all).  If you really want a false,
> > use !! to force it.
>
> > Blech.
>
> > 2. If you wanted to return something other than false, and if the
> > first part has an invariant result, you could manipulate that return
> > value to be falsey and use the OR operator, which is much more
> > powerful in JavaScript than in most languages (more here[1]):
>
> > return $(arg) ? "It's there" : (alert('Element Does not exist') ||
> > "It's not there");
>
> > or, demonstrating manipulation:
>
> > return $(arg) ? "It's there" : (!setTimeout(...) || "It's not there");
>
> > ...since setTimeout returns a non-zero number; !setTimeout is false
> > and so the return value (for that second operand) is "It's not there".
>
> > Blech blech.
>
> > 3. Wrap the two-part bit in an on-the-fly function:
>
> > return $(arg) ? true : (function(){ alert('Element Does not exist');
> > return false;})());
>
> > Blech blech cough.
>
> > 4. Use eval (!):
>
> > return $(arg) ? true : eval("alert('Element Does not exist'); return
> > false;");
>
> > Blech blech cough retch.
>
> > I bet there are others.
>
> You can use comma operator (which evaluates all of its expressions
> left to right and evaluates itself to the last expression):
>
> return $(arg) ? true : alert('...'), false;
>
> [...]
>
> --
> 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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Using a prototype function in dynamic content.

2009-07-31 Thread T.J. Crowder

Hi,

You're using the evalScripts option in your ajax call?  Can you
produce a small, self-contained example[1]?

[1] http://proto-scripty.wikidot.com/self-contained-test-page

-- T.J. :-)

On Jul 31, 1:22 am, Drum  wrote:
> P.S. I tried with both delete eds[id];  and eds[id] = undefined.
--~--~-~--~~~---~--~~
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: Newbee question : Compatibility with javascript 1.5

2009-07-31 Thread T.J. Crowder

Hi,

There are the documented supported browsers:
http://prototypejs.org/download

Using Prototype & script.aculo.us in earlier browsers will not be
_supported_, but whether it'll "work" is more a fuzzy gray than black
or white -- e.g., it will vary dramatically by feature.  I expect that
the $() function will work on quite a few older browsers, whereas I'd
be surprised if Element#getDimensions and some of the niftier things
script.aculo.us does with computed styles were reliable.

In terms of *language* features, I think you're pretty safe.
Prototype uses Function#apply, Function#call, the arguments array, and
the special behavior of the || (OR) operator, all of which were added
after the first couple of releases of the language, but it was a
looong time ago.  In fact, just looked it up[1], and if Wikipedia is
correct we're talking 1998 or earlier for all of those.

Prototype may (or may not) use some of the new array features from
JavaScript 1.6 (~2005), but I suspect not (at least not 1.6.0.3) or
that it has emulations of them it'll use if they're not there.  If
there are any missing, though, it's easy enough to add emulations to
the array prototype, and in any case a quick scan through the source
for the new methods will tell you.

In terms of Ajax features, if you're talking Mozilla 1.7, that would
be well after Gecko had XmlHttpRequest.  Can't guarantee there won't
be niggles, but...

Bottom line is that it's unlikely to "just work," but I suspect most
of what you'll hit will be manageable.  The joy is you have the
source, and the license is not forbidding.

[1] http://en.wikipedia.org/wiki/JavaScript#Versions

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


On Jul 31, 9:09 am, Christophe Decaux 
wrote:
> That's right, it's device app dev.
> The device is a Cisco DMP 4300 series
> Does anyone knows what are the minimum browser requirements to run  
> Prototype and Scriptaculous
> Christophe
>
> Le 30 juil. 09 à 22:40, Rick Waldron a écrit :
>
>
>
> > That sounds like fun... i like device app development. Can you tell  
> > us what device you're working with? That will be helpful
>
> > Rick
>
> > On Thu, Jul 30, 2009 at 3:55 PM, Christophe  > > wrote:
>
> > Hi there,
>
> > Apologies to everybody if my question is offending in any way, but
> > this is my first post to such a group.
>
> > I'm a occasional user of Prototype and Scriptaculous and pretty happy
> > with these tools.
>
> > However, I'm facing an issue for which I can find any answer around:
>
> > I created some pages that work pretty well on modern browsers such as
> > FF 3 or 3.5 and Safari 3 or 4, but I'm asked to make them run on some
> > special Internet devices that run only Mozilla Firefox 1.7 with
> > Javascript 1.5
>
> > So my question is : what are the requirements of Prototype 1.6 and
> > Scriptaculous 1.8, will my pages run well on such an old browser.
> > If not, is there an older version of Prototype and/or Scriptaculous
> > that will answer my problem.
>
> > Thanks in advance
>
> > Christophe
--~--~-~--~~~---~--~~
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, attachEvent to div

2009-08-01 Thread T.J. Crowder

Hi Jake,

I know you said to cancel your post (it had already been posted), so
you're not expecting an answer, but:

>  element = Element('div')  // Doesn't work when created this way.

It's "new Element(...)", not "Element(...)".  (See [1], scroll down to
"Element as a constructor").

>  element.attachEvent('onclick', function(evt) {alert('hello')} ); //

If you're using Prototype, why not use Prototype?[2]

[1] http://prototypejs.org/api/element
[2] http://prototypejs.org/api/element/observe

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


On Jul 31, 7:56 pm, Jake  wrote:
> I am using prototype 1.6.0.3 and IE8.  Although I think the same
> problem occurred in IE7. Why do the following lines of code give
> errors?
>
> 
>  element = Element('div')  // Doesn't work when created this way.
>  element.attachEvent('onclick', function(evt) {alert('hello')} ); //
> can't attach event.
> 
>
> This doesn't work either:
>
> 
>   element = Element('div')
>   Event.observe(element, 'click', function(evt) {alert('hello')});
> 
>
> However, when I do not use prototype to create the div element, both
> of these do not generate errors:
>
> 
>  element = document.createElement('div');
>  element.attachEvent('onclick', function(evt) {alert('hello')} );
> 
>
> 
>  element = document.createElement('div');
>  Event.observe(element, 'click', function(evt) {alert('hello')});
> 
>
> I was thinking that a div created with
>   element = Element('div')
> can do everything that a div created with
>  element = document.createElement('div');
> can do, but it will not allow me to attach an event for some reason.
>
> Any ideas as far as why the first two don't work?
>
> 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-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: Escaping Input

2009-08-01 Thread T.J. Crowder

Hi,

I'm surprised by the POST data you quoted, but it doesn't matter, I'm
pretty sure I know what's wrong.

I was hurrying too much when posting my reply.  You don't have to URL-
encode the JSON string if you're going to give Ajax.Request a
parameters *object* rather than parameters *string*, because Prototype
will do it for you -- which is half the point of using an object.  So
drop the encodeURIComponent bit:

// Using an object:
entry = Object.toJSON($('busCalForm').serialize(true));
new Ajax.Request(
"modules/buscal/processes/saveBooking.php", {
parameters: {
year: year,
recnum: busmstr_id,
json: entry
},
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)
});

// Using a string (not recommended, data gets transformed to an object
// and then back again -- but it demonstrates using the
// encodeURIComponent function
entry = Object.toJSON($('busCalForm').serialize(true));
new Ajax.Request(
"modules/buscal/processes/saveBooking.php", {
parameters:
"year=" + encodeURIComponent(year) +
"&recnum=" + encodeURIComponent(busmstr_id) +
"&json=" + encodeURIComponent(entry),
onSuccess: busCal.gotEntry.bind(this),
onFailure: busCal.gotFailure.bind(this)
});

Note that I'm escaping all of the components, although if you *know*
year and busmstr_id won't include any characters that are special in
URLs, you can skip it.  Again, though, best to use the object feature
of Ajax.Request and let it handle URL-encoding.

Sorry for the bum steer earlier, rushing too much.  "Do less, better"
should be my motto. ;-)
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 31, 5:49 pm, infringer  wrote:
> This method works well in FF 3.5, but FF 3.0.12 doesn't like it...  I
> really would like to keep the from coming in a separate variable, but
> realize I may have to change that.
>
> 3.0.12's POST (truncated) just for info:
> %7Bstartdate%3A%202009-04-23%2C%20
>
> 3.5's POST (truncated):
> %7B%22startdate%22%3A%20%222009-04-23%22%2C%
>
> As you can see 3.5 has extra characters...
>
> I'm sending this to PHP, and my processing script receives the JSON
> variable as such
>
> $json_string = (isset($_POST['json']) ? rawurldecode($_POST['json']) :
> "");
> $json = json_decode($json_string, true);
> if (($json == '') || empty($json) || ($json == null)) {
>         $result['valid_result'] = 2;
>         $result['reason'] = rawurlencode("Unknown error, Administrator has
> been notified.  Please try again later");
>         $result = json_encode($result);
>         header("Content-Type: application/json");
>         print $result;
>         exit(0);
>
> }
>
> so when users are using 3.0.xx they always receive this error message,
> because the PHP script doesn't see it as valid JSON.
>
> but 3.5 users (myself only) can perform the saves/deletes, etc
>
> This is for an internal application, we only allow FF to be used.
>
> Thanks for the help!
> -David
>
> On Jul 30, 4:00 pm, "T.J. Crowder"  wrote:
>
>
>
> > Sorry, I got my wires crossed half-way through the first one of
> > those.  You can't use String#toJSON, it's not a string!  Doh.
> > Correcting my first example:
>
> > entry = encodeURIComponent(Object.toJSON($('busCalForm').serialize
> > (true)));
> > new Ajax.Request(
> >     "modules/buscal/processes/saveBooking.php", {
> >     parameters: {
> >         year: year,
> >         recnum: busmstr_id,
> >         json: entry
> >     },
> >     onSuccess: busCal.gotEntry.bind(this),
> >     onFailure: busCal.gotFailure.bind(this)
>
> > });
>
> > Sorry 'bout that.
>
> > -- T.J. :-)
>
> > On Jul 30, 8:55 pm, "T.J. Crowder"  wrote:
>
> > > Hi,
>
> > > You're sending an unencoded string (which happens to be in JSON
> > > format) as part of your parameters string, which is meant to be URL-
> > > encoded data.  A # sign is the least of your problems. ;-)  You'll
> > > want to encode that with JavaScript's encodeURIComponent function[1].
>
> > > Somewhat OT, but as of 1.6 (at least), the preferred way to provide
> > > options to Ajax.Request is as an object.  If you give it a string,
> > > that string will be converted to an object, and then later converted
> > > back into a string.  Yes, really. :-)  Also, String has a toJSON
> > >

[Proto-Scripty] Re: Beginners question, trouble with Event.stop in AJAX

2009-08-02 Thread T.J. Crowder

Hi Ashley,

In the one that's not working, you're using what's called a "DOM0-
style" handler -- that's where you're attaching the handler the old-
fashioned way, by using an attribute on the form element:

> action="procBasketPasswordNoJS.php" method="post">

Event.stop works only for handlers registered with more modern methods
like the Event.observe you used with your first form.

To correct the problem, I'd recommend using Event.observe to set up
the handler for the second form as you did with the first.  If there's
a reason you can't do that, though, the "DOM0" equivalent of
Event.stop is to return false from callProcBasketPassword.

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


On Aug 1, 4:35 pm, Ash  wrote:
> Hi, I just started my first experiment with AJAX today. Got the basics
> working, but when I add a tiny bit more complexity I have a problem,
> Event.stop doesn't work properly for me.
>
> I've followed a couple of basic tutorials to submit an e-mail address
> to a PHP script, the PHP looks up the e-mail address and if it finds
> it, it shows an input to enter a password. This all works fine except
> the function with the ajax call to the password PHP script does not
> stop the form submitting.
>
> There is probably something very obvious I am doing wrong so hopefully
> someone will be able to spot this a mile away! :)
>
> The HTML looks like this, once the second form has been displayed
>
> 
> 
> 
> 
>
> 
>    we have saved details on file for you, please enter your password
> below to retrieve them
>    
>     action="procBasketPasswordNoJS.php" method="post">
>          name="password"/>
>          value="Submit"/>
>    
> 
>
> 
> 
>
> Here is the ajax.js
>
> // Attach handler to window load event
> Event.observe(window, 'load', init, false);
>
> function init(){
>  Event.observe('email-form', 'submit', callProcBasketEmail);
>
> }
>
> function callProcBasketEmail(e) {
>  var pars = Form.serialize('email-form');
>  var myAjax = new Ajax.Updater('email-response',
> 'procBasketEmail.php', {method: 'post', parameters: pars});
>  Event.stop(e);
>
> }
>
> function callProcBasketPassword(e) {
>  var pars = Form.serialize('password-form');
> var myAjax = new Ajax.Updater('password-response',
> 'procBasketPassword.php', {method: 'post', parameters: pars});
>  Event.stop(e);
>
> }
>
> When I step through in Firebug I can see that the password-response
> div gets filled with the results of the procBasketPassword.php script,
> but then the page tries to reload where the form is pointing to -
> action="procBasketPasswordNoJS.php".
>
> Event.stop(e); works fine in the first function, but not in the second
> one. Please can you help?
>
> Thanks in advance.
> Ashley
--~--~-~--~~~---~--~~
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: Using a prototype function in dynamic content.

2009-08-02 Thread T.J. Crowder

Hi,

I wasn't talking about String#evalScripts function, I was talking
about the evalScripts *option* on Ajax.Updater:
http://prototypejs.org/api/ajax/updater

If you're not using Ajax.Updater, if you're doing the update yourself,
Element#update[1] will eval the scripts for you as part of its
processing.  But if you need to do it yourself, you'd use
String#evalScripts on the responseText member of the Ajax.Response
passed into your onSuccess handler.

[1] http://prototypejs.org/api/element/update

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


On Aug 1, 7:26 pm, Drum  wrote:
> Ah, now, that's interesting. I did try to use evalScripts, but I
> couldn't find any clear examples of how or where to apply it. I tried
> putting it in the places it seemed logical, but without effect.
>
> So, ok, I have an HTML page includes an onclick to fetch some content
> which will include scripts. The JS functions to handle this are in an
> external file. Do I put the evalScripts() in
>
> onclick="getStuff(param, param).evalScipts();
>
> or do I apply it to the returned text before putting it in innerHTML
> like
>
> var thereturn = http_request.responseText.evalScripts();
> document.getElementById(div).innerHTML = thereturn;
>
> I tried both, but couldn't get either to work.
>
> C
>
> On 31 July, 11:13, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > You're using the evalScripts option in your ajax call?  Can you
> > produce a small, self-contained example[1]?
>
> > [1]http://proto-scripty.wikidot.com/self-contained-test-page
>
> > -- T.J. :-)
>
> > On Jul 31, 1:22 am, Drum  wrote:
>
> > > P.S. I tried with both delete eds[id];  and eds[id] = undefined.
--~--~-~--~~~---~--~~
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: Will remove() method on top DIV element automatically remove children of that element?

2009-08-02 Thread T.J. Crowder

Hi,

Yes, it will, removing an element (via Prototype or directly with
Node.removeChild) removes that element and its children.  Which is
just as well, as the children would have no where to be otherwise.

Note that neither Prototype nor the underlying DOM methods will
automatically remove event handlers from the removed elements, which
can mean that memory remains in use even though the element isn't on
the page anymore.  You want to track what children you have event
handlers on and remove the handlers as well.  This is much easier if
you're using event delegation to keep the number of handlers to a
minimum.

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


On Aug 2, 11:25 pm, Kostil  wrote:
> Hi All,
>
> I am wondering if remove() method executed on top DIV (parent DIV
> element) will automatically remove the children of this element (as in
> remove them from the page and memory if appropriate)? Currently, I am
> doing the following to remove the children:
>
> $('topdiv').childElements().each(function(e) {
>         RemoveChildren(e);
>     });
>
> Where RemoveChildren(e) defined as:
>
> function RemoveChildren(e)
> {
>     if (e.childElements().length > 0)
>     {
>         e.childElements().each(function(ee) {
>             RemoveChildren(ee);
>         });
>     }
>     e.remove();
>
> }
>
> The method above seems to work slow especially on IE where very
> visible lag is apparent when executing this type of cleanup.
>
> Thank you in advance,
--~--~-~--~~~---~--~~
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: Beginners question, trouble with Event.stop in AJAX

2009-08-03 Thread T.J. Crowder

Hi,

> But this stops the whole function from working - where should the
> observe line be placed to ensure it will work properly?

Right, because this new line:

> Event.observe('password-form', 'submit', callProcBasketPassword);

...will cause an error, because there is no element with the ID
'password-form' yet.  Remember that Ajax calls are *asynchronous*
(that's what the "A" in Ajax stands for).  You start the call at the
point in your code where you create the Ajax.Updater object, but then
your code continues immediately without waiting for the Ajax call to
finish.  As DJ pointed out, that's what the onSuccess callback is for
-- so you can execute code once the Ajx call has successfully
completed.  So it would look something like this:

http://pastie.org/569908

In terms of getting you past these initial hurtles, some recommended
reading:
http://prototypejs.org/learn/introduction-to-ajax
http://proto-scripty.wikidot.com/prototype:how-to-bulletproof-ajax-requests
http://prototypejs.org/api/ajax/request
http://prototypejs.org/api/ajax/updater

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


On Aug 3, 2:23 pm, Ash  wrote:
> Thanks for the help, I just tried replacing Event.stop(e); with return
> false; in the function but it still submits the form.
>
> I would prefer to do it the new way anyway, if you would be able to
> help me...
>
> The first function is called from Event.observe('email-form',
> 'submit', callProcBasketEmail); which is within a function that is
> called when the document loads.
>
> The question is, where to put the event observe to watch the second
> form.
>
> My first instinct would be to put it in the function which outputs the
> form EG
>
> function callProcBasketEmail(e) {
>  var pars = Form.serialize('email-form');
>  var myAjax = new Ajax.Updater('email-response',
> 'procBasketEmail.php', {method: 'post', parameters: pars});
>  Event.observe('password-form', 'submit', callProcBasketPassword);
>  Event.stop(e);
>
> }
>
> (line added just after the ajax function has drawn 'password-form' to
> the screen)
>
> But this stops the whole function from working - where should the
> observe line be placed to ensure it will work properly?
>
> Thanks in advance, I think once I get over these initial few hurdles
> of getting to grips with good practices, I will be fine!
>
> Ashley
>
> Here is the javascript in full:
>
> // Attach handler to window load event
> Event.observe(window, 'load', init, false);
>
> function init(){
>     Event.observe('email-form', 'submit', callProcBasketEmail);
>
> }
>
> function callProcBasketEmail(e) {
>  var pars = Form.serialize('email-form');
>  var myAjax = new Ajax.Updater('email-response',
> 'procBasketEmail.php', {method: 'post', parameters: pars});
>  Event.observe('password-form', 'submit', callProcBasketPassword);
>  Event.stop(e);
>
> }
>
> function callProcBasketPassword(e) {
>  var pars = Form.serialize('password-form');
>  alert(pars);
>  var myAjax = new Ajax.Updater('password-response',
> 'procBasketPassword.php', {method: 'post', parameters: pars});
>  Event.stop(e);
>
> }
>
> On Aug 2, 11:19 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi Ashley,
>
> > In the one that's not working, you're using what's called a "DOM0-
> > style" handler -- that's where you're attaching the handler the old-
> > fashioned way, by using an attribute on the form element:
>
> > >     > > action="procBasketPasswordNoJS.php" method="post">
>
> > Event.stop works only for handlers registered with more modern methods
> > like the Event.observe you used with your first form.
>
> > To correct the problem, I'd recommend using Event.observe to set up
> > the handler for the second form as you did with the first.  If there's
> > a reason you can't do that, though, the "DOM0" equivalent of
> > Event.stop is to return false from callProcBasketPassword.
>
> > HTH,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Aug 1, 4:35 pm, Ash  wrote:
>
> > > Hi, I just started my first experiment with AJAX today. Got the basics
> > > working, but when I add a tiny bit more complexity I have a problem,
> > > Event.stop doesn't

[Proto-Scripty] Re: Class.create and this keyword

2009-08-03 Thread T.J. Crowder

Hi,

> But it's really inelegant. How am I supposed to handle this?

Pretty much like that, except I haven't reassigned the property like
that.  It *should* be fine, you'll create an own property 'f' on the
instance (rather than an inherited one from the prototype) that's
bound.  But it bothers me and I can't give you a good reason for
it. :-)  I've done that sort of thing before (keep a bound copy around
on the instance, if I'm going to reuse it), I've just for some reason
always used a different prop name, I guess so I'm not in doubt whether
I've bound it.  But doing it in the initializer like you have, there
wouldn't be any confusion...

Also, the odds are pretty high you just want #bind, not
#bindAsEventListener.[1]

[1] 
http://proto-scripty.wikidot.com/prototype:tip-you-probably-don-t-need-bindaseventlistener

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


On Aug 3, 2:39 pm, Cédric  wrote:
> Hello,
>
> I'm trying to use the Class methods to manage my object hierarchy on
> my current project, but I have some trouble with the "this" keyword in
> conjonction with Class.create.
>
> Here is a piece of plain-js code using prototypes to get inheritance:
>
> var Super1 = function () {
>         this.fu = "bar";
>
> }
>
> var Sub1 = function () {
>         this.baz = "bat";
>         this.f = function () {
>                 alert("classic:"+this.fu+this.baz);
>         }.bind(this);
>         document.observe("click", this.f);};
>
> Sub1.prototype = new Super1();
> new Sub1();
>
> Here is my attempt at mimic this with Class.create:
>
> var Super2 = Class.create({
>         fu: "bar"
>
> });
>
> var Sub2 = Class.create(Super2, {
>         baz: "bat",
>         f: function () {
>                 alert("Class:"+this.fu+this.baz);
>         }.bindAsEventListener(this),
>         initialize: function () {
>                 document.observe("click", this.f);
>         }});
>
> new Sub2();
>
> But of course it doesn't work, f in bound to window, not the object
> create by new. The only way I found is:
>
> var Super2 = Class.create({
>         fu: "bar"
>
> });
>
> var Sub2 = Class.create(Super2, {
>         baz: "bat",
>         f: function () {
>                 alert("Class:"+this.fu+this.baz);
>         },
>         initialize: function () {
>                 this.f = this.f.bindAsEventListener(this);
>                 document.observe("click", this.f);
>         }});
>
> new Sub2();
>
> But it's really inelegant. How am I supposed to handle 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: Using a prototype function in dynamic content.

2009-08-04 Thread T.J. Crowder

Hi,

>   if (http_request.readyState == 4) {
> if (http_request.status == 200) {
>  document.getElementById('load').innerHTML = 
> "";

You're not using Ajax.Request[1] or Ajax.Updater[2]?

> This is my onSuccess handler, how do
> I apply evalScripts?

DJ and I are talking about a Prototye onSuccess handler for one of the
two features above.

> document.getElementById(div).innerHTML = thereturn;

Your code is setting the innerHTML property directly.  If you just
change that line to use Element#update instead, #update will handle
eval'ing the scripts for you:

$(div).update(thereturn);

Altenately, keep setting innerHTML directly (although #update does
some very handy things for you) and then after doing that, call
String#evalScripts() directly:

document.getElementById(div).innerHTML = thereturn;
thereturn.evalScripts();

String#evalScripts is a method Prototype adds to the String prototype
and so it's available on all strings.  Details here.[4]

Looking at your quoted code, you're not making much use of Prototype
at all -- not even the $() function!  (So much more compact than
document.getElementById.)  I suggest taking an hour to read through
the API docs[5] front-to-back to get an idea of what's on offer.  It
literally takes an hour and saves you no end of time in the long run.
May also be worth reading through some stuff on the unofficial wiki
[6].

[1] http://prototypejs.org/api/ajax/request
[2] http://prototypejs.org/api/ajax/updater
[3] http://prototypejs.org/api/element/update
[4] http://prototypejs.org/api/string/evalScripts
[5] http://prototypejs.org/api
[6] http://proto-scripty.wikidot.com/

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

On Aug 4, 1:22 am, Drum  wrote:
> > if you need to do it yourself, you'd use
> > String#evalScripts on the responseText member of the Ajax.Response
> > passed into your onSuccess handler.
>
> Sorry, I still don't understand. This is my onSuccess handler, how do
> I apply evalScripts?
>
>           if (http_request.readyState == 4) {
>             if (http_request.status == 200) {
>                                  document.getElementById('load').innerHTML = 
> "";
>                                  var thereturn = http_request.responseText;
>                                  document.getElementById(div).innerHTML = 
> thereturn;
>  } else {
>                                  alert(error);
>             }
>     }
--~--~-~--~~~---~--~~
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: Firefox v3.5

2009-08-04 Thread T.J. Crowder

Hi,

> I had similar problems - and found out that .down() or .select() fails
> when the element's id that it's fetching is starting with a number.

IDs can't start with nubmbrs.[1]  But Mona's bug report is for a valid
ID (containing a dot and/or colon, both of which are valid).  It's
been accepted on the bug list and probably fixed by now in trunk.

[1] http://www.w3.org/TR/html401/types.html#type-name
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 4, 2:46 pm, mindVex  wrote:
> I had similar problems - and found out that .down() or .select() fails
> when the element's id that it's fetching is starting with a number.
>
> So, $('test').down('ul, 1) failed for me, because the ul-element's id
> was something like "1_23402922". I changed it to begin with a letter
> ("s_1_23402922") and it worked then.
>
> On Jul 29, 2:59 pm, evrim  wrote:
>
>
>
> > No there is not a space in ID e is expression like "div."
> > and the code adds in front of it "# " after that the expression
> > is
> > "# div." and the expression does not work in this form
> > on "$A(root.querySelectorAll(e)).map(Element.extend);" .
> > but after commented this line code work well.
>
> > On Jul 29, 3:45 pm, "Alex McAuley" 
> > wrote:
>
> > > that has a space in it no ?
>
> > > ID's are not allowed spaces
>
> > > Alex Mcauleyhttp://www.thevacancymarket.com
>
> > > - Original Message -
> > > From: "evrim" 
> > > To: "Prototype & script.aculo.us" 
> > > 
> > > Sent: Wednesday, July 29, 2009 12:29 PM
> > > Subject: [Proto-Scripty] Re: Firefox v3.5
>
> > > this change fixed only elements whose id = 0 so the new change fixed
> > > it well
> > >   //e = "#" + id + " " + e;
> > > I closed this row
>
> > > On Jul 29, 1:19 pm, evrim  wrote:
> > > > I have done that change but still there is an error then,
> > > > I changed line 3339 (e = "#" + id + " " + e;) to
> > > > if (id != 0)
> > > > e = "#" + id + " " + e;
>
> > > > Now it seems working
>
> > > > On Jul 29, 12:00 pm, Mona Remlawi  wrote:
>
> > > > > Must be that you're using (dot) or (colon) in your ids.
> > > > > This has been fixed, but not yet released. You can manually change in
> > > > > prototype.js line:3338 to match
> > > > > id = id.replace(/([\.:])/g, "\\$1"); // NOTE the $1 instead of $0
>
> > > > > This fix will be a part of next release as it is in the trunk [1]
>
> > > > > [1]http://github.com/sstephenson/prototype/blob/add69978e09653808aedec43...
>
> > > > > cheers
>
> > > > > --
> > > > > mona
>
> > > > > On Wed, Jul 29, 2009 at 10:54 AM, webbear1000
> > > > > wrote:
>
> > > > > > Does it work with the latest stable release?
>
> > > > > > On Jul 29, 8:49 am, evrim  wrote:
> > > > > >> Nobody has problem like that?
> > > > > >> Select method in your codes can run well in Firefox 3.5
--~--~-~--~~~---~--~~
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: How to catch/prevent onclick event?

2009-08-05 Thread T.J. Crowder

Hi,

One of the few good things about those old-style handlers is that
they're attributes, so finding the links is easy:

var hookedlinks = $$('a[onclick]');

Then if your goal is to remove the handler:

var n;
for (n = hookedlinks.length - 1; n >= 0; --n) {
hookedlinks[n].onclick = null;
}

Or you can have more fun, I wrote this up a while back to convert DOM0
handlers into modern ones and optionally put some pre-condition logic
in place prior to firing the DOM0 handler:

* * * * (also at http://pastie.org/573599)
function wrapDom0Handler(elm, evtname) {
var propname, dom0handler;

// Grab the current DOM0 handler for the event
propname = "on" + evtname;
dom0handler = elm[propname];

// Clear it
elm[propname] = null;

// Hook up your handler
elm.observe(evtname, function(event) {
var rv;

alert("TODO: Your optional precondition logic goes here");

// Chain to the DOM0 handler, if any
if (Object.isString(dom0handler)) {
rv = eval(dom0handler);
}
else if (Object.isFunction(dom0handler)) {
rv = dom0handler.call(elm, event);
}
if (!Object.isUndefined(rv) && !rv) {
// Handler returned something falsey, cancel
event.stop();
    }
});
}
* * * *

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

On Aug 4, 11:21 pm, Hipnotik  wrote:
> Hi
> I have observer set for the whole document to catch click events on
> links (a href) and prevent default action (open page from href,
> event.stop). It works correct, but ... now I have onclick event
> defined inside of each a-herf element and I need to catch/prevent this
> event too. How to do that? I'm hope it's quite clear ;)
--~--~-~--~~~---~--~~
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: PeriodicalExecuter Error: this.callback is not a function (prototype.js Line 308)

2009-08-07 Thread T.J. Crowder

Hi,

> When I change the line into "new PeriodicalExecuter
> (myobject.unknownMethod(), 3);", firebug at once states correctly that
> this function doesn't exist, which is right.

And if it did exist, it would execute once, immediately, and the
PeriodicalExecuter would fail three seconds later.  This line of code:

new PeriodicalExecuter(obj.method(), 3);

...like any other function call runs obj.method _immediately_ and
passes the return value of the method into the PeriodicalExecuter
constructor.  Unless the method returns a function reference, that's
not going to work.

You probably want to do this:

new PeriodicalExecuter(obj.method.bind(obj), 3);

Note that we are *not* calling method here; we're calling bind and
telling it to return a function that, when called, will call
obj.method.

If you're not using an object method, just a function, you don't need
bind:

new PeriodicalExecuter(someFunction, 3);

Note, again, that we are not *calling* someFunction there (there are
no parens after it), we're just passing a reference to it into the
constructor.

[1] http://prototypejs.org/api/periodicalExecuter
[2] http://prototypejs.org/api/function/bind

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

On Aug 7, 1:30 am, Schweitzer  wrote:
> Hi there!
>
> Got an error with Prototypes PeriodicalExecuter() (Version 1.6.0.3):
> When I use the "verified" (http://www.prototypejs.org/api/
> periodicalExecuter) "new PeriodicalExecuter(myobject.testMethod(),
> 3);", everything seems fine (no error in Firebug etc) but after 3
> Seconds an error "this.callback is not a function [...]/prototype.js
> Line 308" appears. testMethod was not started.
>
> The line "new PeriodicalExecuter(function() { alert("test"); }, 3);"
> works when written instead.
>
> When I change the line into "new PeriodicalExecuter
> (myobject.unknownMethod(), 3);", firebug at once states correctly that
> this function doesn't exist, which is right.
>
> Now I wonder about why this error appears. As you may imagine,
> testMethod() is part of an Object, but the error appears outside as
> inside the initialize()-function of the "Class" created by Class.create
> (). Even outside the "class". The used testMethod() seems to exist
> nonetheless.
>
> I would like to read any hint or maybe solution to this problem,
> please feel free to ask for more information, too.
>
> Schweitzer
--~--~-~--~~~---~--~~
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: How to loop through array? New to Proto

2009-08-08 Thread T.J. Crowder

Hi,

Expanding on DJ's answer (which has a couple of errors, but he was on
his phone!), more generally, if you can get the elements into an
array, you can use Enumerable#invoke[1] to call the same method on
each of the elements.  So for instance, if you used DJ's suggestion
and gave them all the same class, it becomes:

$$('.theclass').invoke('hide');

Tidy, eh?  Now, if you need to do it with a disparate set of elements,
you can always use an array literal:

[ 'ErrorConsumerEmail0address',
  'ErrorConsumerfirstname',
  'ErrorConsumerlastname',
  'ErrorConsumerPhone0Number'
].invoke('hide');

If you *really* want to squeeze down the character count, you can use
$w[2] to create the array:

$w('ErrorConsumerEmail0address ErrorConsumerfirstname
ErrorConsumerlastname ErrorConsumerPhone0Number').invoke('hide');

$w (note that it's lower case; it's the only lower case one of the $
functions) splits a string into an array on whitespace.  Adds a tiny
bit of overhead and saves a few keystrokes.

There's more about looping arrays in the unofficial wiki[3].  It is
also well worth your time to take an hour and read through the
Prototype API[4] front to back.  It literally takes an hour or so, and
it pays you back very very quickly.

[1] http://prototypejs.org/api/enumerable/invoke
[2] http://prototypejs.org/api/utility/dollar-w
[3] http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays
[4] http://prototypejs.org/api

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

On Aug 7, 6:59 pm, trope  wrote:
> I have some code that appears to be a prime candidate for a loop.
>
> How could I wrap this up in one neat little function???
>
> /* Hide previous errors */
>         $('ErrorConsumerEmail0address').hide();
>         $('ErrorConsumerfirstname').hide();
>         $('ErrorConsumerlastname').hide();
>         $('ErrorConsumerPhone0Number').hide();
>
> Thank you.
>
> Trope!
--~--~-~--~~~---~--~~
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: help with select on element not working

2009-08-08 Thread T.J. Crowder

Hi,

> I am able to get the element lotTotalTr = $(accountTotal) to work

IDs cannot contain spaces[1].  Apparently you're getting away with it
on the $() call (the underlying getElementById must be allowing it),
spaces have meaning in selectors.  Invalid IDs will not work reliably.

[1] http://www.w3.org/TR/html401/types.html#type-name

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


On Aug 7, 8:18 pm, molo  wrote:
> I have the following httml and javascript code (see snippets below).
> I am running this using firebug
>
> I am able to get the element lotTotalTr = $(accountTotal) to work
> However the select on the element does not work. I have tried many
> variations of the select
>  totalLotSharesTd =  lotTotalTr.select('td.totalLotShares')
>
> I was able to use lotTotalTr.childElements() and then
> totalLotSharesTd3 = totalLotSharesTd2[3] to position myself where I
> want to be but not select. This is not a good way to do this
>
> Can anyone explain this to me?
>
> --
> 
> Total 87002B
> 
> 
> 18031 td>
> 316186.29
> 316186.29
> 
> 
> 
>
> -
>
>  function lotShareChange(obj){
>        var e = $(obj).up('tr');
>        var account = e.select('td input.account');
>        var accountVal = account[0].value;
>        var accountTotal = "Total " + accountVal;
>        var lotTotalTr = $(accountTotal);
>
>        var totalLotSharesTd;
>        var totalLotSharesTd2, totalLotSharesTd3,  totalLotSharesTd4;
>
>        totalLotSharesTd =  lotTotalTr.select('td.totalLotShares'); //
> selects do not work
>        totalLotSharesTd2 = lotTotalTr.childElements();  //worked
>        totalLotSharesTd3 = totalLotSharesTd2[3]; //worked
>        totalLotSharesTd4 = lotTotalTr.select('td'); //does not work
>        //totalLotSharesTd = lotTotalTr.select('td');
>
>        totalLotSharesTd3.update(totalShares);
>
>    }
--~--~-~--~~~---~--~~
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: help with select on element not working

2009-08-08 Thread T.J. Crowder

The word "but" is missing from the above "...allowing it), _but_
spaces have..."

On Aug 8, 9:12 am, "T.J. Crowder"  wrote:
> Hi,
>
> > I am able to get the element lotTotalTr = $(accountTotal) to work
>
> IDs cannot contain spaces[1].  Apparently you're getting away with it
> on the $() call (the underlying getElementById must be allowing it),
> spaces have meaning in selectors.  Invalid IDs will not work reliably.
>
> [1]http://www.w3.org/TR/html401/types.html#type-name
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Aug 7, 8:18 pm, molo  wrote:
>
>
>
> > I have the following httml and javascript code (see snippets below).
> > I am running this using firebug
>
> > I am able to get the element lotTotalTr = $(accountTotal) to work
> > However the select on the element does not work. I have tried many
> > variations of the select
> >  totalLotSharesTd =  lotTotalTr.select('td.totalLotShares')
>
> > I was able to use lotTotalTr.childElements() and then
> > totalLotSharesTd3 = totalLotSharesTd2[3] to position myself where I
> > want to be but not select. This is not a good way to do this
>
> > Can anyone explain this to me?
>
> > --
> > 
> > Total 87002B
> > 
> > 
> > 18031 > td>
> > 316186.29
> > 316186.29
> > 
> > 
> > 
>
> > -
>
> >  function lotShareChange(obj){
> >        var e = $(obj).up('tr');
> >        var account = e.select('td input.account');
> >        var accountVal = account[0].value;
> >        var accountTotal = "Total " + accountVal;
> >        var lotTotalTr = $(accountTotal);
>
> >        var totalLotSharesTd;
> >        var totalLotSharesTd2, totalLotSharesTd3,  totalLotSharesTd4;
>
> >        totalLotSharesTd =  lotTotalTr.select('td.totalLotShares'); //
> > selects do not work
> >        totalLotSharesTd2 = lotTotalTr.childElements();  //worked
> >        totalLotSharesTd3 = totalLotSharesTd2[3]; //worked
> >        totalLotSharesTd4 = lotTotalTr.select('td'); //does not work
> >        //totalLotSharesTd = lotTotalTr.select('td');
>
> >        totalLotSharesTd3.update(totalShares);
>
> >    }
--~--~-~--~~~---~--~~
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: spam click = buggy???

2009-08-08 Thread T.J. Crowder

Hi,

There are ways to know whether the effect is in progress and not
trigger it again; apparently the functional test just doesn't use
those, being a unit test rather than an application. :-)

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


On Aug 9, 4:55 am, HOLYCOWBATMAN  wrote:
> Hi , im looking into script.aculo.us Functional Tests effects3_test
> and if i spam 'Start slide down' 4-5 times( or any other effect on any
> other page) it starts to bug... the animation is only partial then
> complete instantly and it wont get back to normal until i reload the
> page. I would like to know if this is normal... and if its the example
> that are faulty .. or scriptaculous itself ( i tested it in ie8 and
> ff3 and the same bug happens ) or if its something on my side
>
> Im just starting to look into some javascript / ajax framework and
> found scriptaculous / prototype to be really simple and powerfull but
> seeing that kind of bug would make me stay away from the
> 'effects'...everything else seems great though!
--~--~-~--~~~---~--~~
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: Getting keys from a JSON object returned from transport.responseText.evalJSON(); or for that matter any JSON object

2009-08-10 Thread T.J. Crowder

Hi,

Regardless of where the object came from (having evaluated it from a
JSON string or something else), that's what "for..in" is for:

var name, obj = "{'a': 1, 'b': 2}".evalJSON();
for (name in obj) {
alert(name + "=" + obj[name]);
}

...alerts "a=1" then "b=2".  The order is not guaranteed.  Cool, eh?

Speaking generally, "for..in" iterates through the names of the
properties in the object.  Note that depending on the object in
question, some of those properties may refer to functions:

var obj = {
foo: function() {
alert("Foo!");
},
bar: 42
};
var name;
for (name in obj) {
alert("typeof obj[" + name + "] = " + typeof obj[name]);
}

...alerts "obj[foo] = function" and "obj[bar] = number".

"for..in" includes properties an object has inherited from its
prototype:

var a = ['one', 'two'];
var name;
for (name in a) {
alert("typeof a[" + name + "] = " + typeof a[name]);
}

...will not only alert "a[0] =one" and "a[1] = 2" but also any other
enumerable properties on arrays.  In most implementations, there
aren't any other *enumerable* properties (some properties can be
marked "dontEnum", but only by the implementation, not our code), but
when you're using Prototype, there are lots -- because Prototype adds
lots of properties to the Array prototype referencing additional nifty
Array functions.  Which is why you don't use "for..in" to loop through
array elements, there could be more than just the array elements.[1]

You can filter out the properties that are inherited from the
prototype by using hasOwnProperty:

var a = ['one', 'two'];
var name;
for (name in a) {
if (a.hasOwnProperty(name)) {
alert("typeof a[" + name + "] = " + typeof a[name]);
}
}

...will only alert the two you expect.

All of the above is JavaScript, not Prototype; details in the spec[2].

[1] http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays
[2] http://www.ecma-international.org/publications/standards/Ecma-262.htm

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


On Aug 10, 2:54 pm, krishna81m  wrote:
> I tried to google and search prototype API for a method that will give
> me just the keys in a JSON object.
>
> Is there none in Prototype and no way to know the keys?
>
> Regards
> Krishna
--~--~-~--~~~---~--~~
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: Many warnings

2009-08-10 Thread T.J. Crowder

Hi,

Sounds like you have some kind of "JavaScript lint" plug-in installed
(or I think there's also a mode of Firefox that will do that).  It's
not out-of-the-box behavior.  These tools aim to help you find
*possible* errors in your code, but can also flag up things which are
perfectly valid though they may look like coding errors.

I'd suggest finding the plug-in (add-on) or setting that's doing this
and turning it off if you don't care for it.

Specifically, what the lint tool is complaining about is something
like this:

For instance:

function foo(bar) {
if (bar) {
return bar * 2;
}
}

Although I would strongly recommend you didn't code things this way,
it's perfectly legal JavaScript whereas in many languages that
wouldn't be valid syntax because "...not all code paths return a
value."  In that example, foo only returns a value if 'bar' is
truthy.  In JavaScript, if a function doesn't return a value, the
expression calling it takes the value undefined as though the function
had returned undefined.  So here:

var x = foo(false);

...x is undefined, whereas here:

var x = foo(1);

x is 2.

For all practical intents and purposes, you can read a function that
doesn't explicitly return anything as having an implicit "return
undefined". (Although technically the spec draws a distinction between
the two situations, in practical terms, it's a distinction without a
difference.)

Prototype has several functions that these lint tools would look at a
bit askance; this is a fairly common Prototype pattern:

function someNiftyElementFunction(element) {
element = $(element);
if (!element) return;
// ...nifty stuff here...
return element;
}

Again, technically only one of those code paths has a return value,
although in practice it's as though the "return;" were "return
undefined;", and in any case it's valid syntax, just the kind of thing
that *looks* like it might be a programmer error.

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


On Aug 10, 12:19 pm, panoramix  wrote:
> Hi,
>
> I try prototype.js tout retrieve the browser type with if
> (Prototype.Browser.IE) and so on and when i load this page with
> Firefox, i recieve many warnings ex:
>
> Warning: anonymous function does not always return a value
> Line: 130, Column: 45
> Source Code:
>       case 'boolean': return object.toString();
>
> Warning: anonymous function does not always return a value
> Line: 133, Column: 32
> Source Code:
>     if (object === null) return 'null';
>
> Warning: test for equality (==) mistyped as assignment (=)?
> Line: 348, Column: 39
> Source Code:
>       if (match = source.match(pattern)) {
>
> I don't know if is very important but for your information
>
> thank's
> panoramix
--~--~-~--~~~---~--~~
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: Encounter a bug in endsWith ?

2009-08-10 Thread T.J. Crowder

Hi,

If I assume 'input' is defined in the second example (you show it
defined in the first example but not the second), I'm not seeing an
error.

Can you produce a small, self-contained example[1] of the problem?

[1] http://proto-scripty.wikidot.com/self-contained-test-page

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

On Aug 10, 11:08 am, "Arnaud F."  wrote:
> Hello,
>
> I don't know why but :
>
> 
> input = 'prototypes'
> bool = input.endsWith('n');
> bool = bool || input.endsWith('s');
> alert(bool);
> 
>
> works fine but :
>
> 
> alert(input.endsWith('n') || input.endsWith('s'));
> 
>
> return me an error (IE6)
>
> What I've do wrong?
>
> 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-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: Casting a json object into an instance of a class

2009-08-12 Thread T.J. Crowder

Hi,

That should work.  I notice that you have "class.Create" rather than
"Class.create"; I assume that's just an error in the note and that the
actual code uses Class.create?  Because if not, that's your problem.

> if(myInstance.isB())...
>
> => isB is undefined

That indicates there's a different problem.  isB should be defined
regardless, you defined it in your class definition.  If the
Object.extend thing weren't working, it should *return* undefined, but
not *be* undefined.

FWIW, this works:
* * * * (also at http://pastie.org/581050)
// Defining
var Thing = Class.create({
initialize: function(src)
{
if (src) {
Object.extend(this, src);
}
},

isB: function()
{
return this.b;
}
});

// Using:
var t;
t = new Thing({"b": true});
alert("t.isB() ? " + t.isB());
* * * *

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

On Aug 11, 6:07 pm, Eric  wrote:
> Hi,
>
> I make some Ajax calls to fetch objects from my server, and I would
> like those object to be instance of some class.
> I just cannot find a way to achieve this...
>
> Here is what I've tried so far :
>
> var MyClass = class.Create({
>   initialize: function(src) {
>     if(src) Object.extend(this,src);
>   },
>   isB: function() { return this.b;}
>
> });
>
> var myJsonObject = {"a":0, "b":true}; // xrh.responseJSON
>
> myInstance = new MyClass(myJsonObject);
>
> if(myInstance.isB())...
>
> => isB is undefined
>
> I also tried the opposite approach with:
> myInstance = Object.extend(myJsonObject,MyClass.prototype)
>
> if(myInstance.isB())...
> => isB is undefined
>
> What is the correct way of achieving this ?
>
> Eric
--~--~-~--~~~---~--~~
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: Responders

2009-08-12 Thread T.J. Crowder

Hi Alex,

I don't think there's any official way.  A quick look at the 1.6.0.3
release (line #1439) suggests that your responder can access the
target container via the request parameter passed to your responder,
specifically request.container.success (the container that will be
updated on success) and request.container.failure (the one that will
be updated on failure).  As this is undocumented (AFAIK), it may
change from release to release...

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


On Aug 12, 9:37 am, Jeztah  wrote:
> Morning Guys / Gals...
>
> I am sure this has been covered before but i'll post it anyway as i
> cant find it in a search!...
>
> I am speeding up a website at the moment by using Ajax to do some
> dirty work in heavy loading pages (pagination and so on)...
>
> I need to put a "loading" spinner or text in place of an element while
> the ajax is doing its thing
>
> I could code each function to do this but i am sure there is an easier
> way.
>
> My first thought is to use "Ajax.Responders" to do something,
> but..
>
> Is there a way i can get the Element that is going to be updated by
> the Ajax.Updater via Ajax.Responders - then i can just code something
> Generic into the JS and dont have to worry about updating stuff all
> the time...
>
> Thanks in advance
>
> Alex
--~--~-~--~~~---~--~~
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: Prototype: getStyle of document element throws exception

2009-08-12 Thread T.J. Crowder

Hi,

Can you post a minimalist, complete failing test case?  I'm not
immediately seeing how it would ascend all the way to document unless
the element you're using isn't in the body, which would be curious.
getOffsetParent stops as of document.body and doesn't try to go
further up than that.

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

On Aug 11, 4:29 pm, fda  wrote:
> Hi, we are using Prototype 1.6.0.3 in combination with Gabriel Lanzani
> select.js. When loading the page in (any) IE browser, the first time
> the select box is clicked it will not open and a js error will
> occure.
>
> As fare as i understand at some point after the click the Prototype
> getOffsteParent is called with the actual Document element as
> argument. Wich later then will create an exception in element.getStyle
> because the document node dose not have a style property. Im not sure
> if it is Prototype's job to check whether the argument will create an
> exception. I patched the getOffsetParent checking whether the argument
> is not document (element !== document).
>
> I know that altering the library files is not Best Practice, maybe the
> problem could be fixed in future within Prototype, that if it is his
> responsibility.
>
> greetings
> FDA
--~--~-~--~~~---~--~~
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: Casting a json object into an instance of a class

2009-08-12 Thread T.J. Crowder

> At least, I now know what is the "state of the art" way of getting a
> class instance through Ajax ;o)

Well, I don't know if it's state of the art, but provided you're in
control of both ends (so, for instance, the raw data object doesn't
get fields that end up overwriting your methods), it seems fine.

> Thanks again!

Happy to help,

-- T.J.

On Aug 12, 12:06 pm, Eric  wrote:
> Thanks for your reply T.J.!
>
> I did used Class instead of class. This was a typo when I posted :o)
>
> You're right, it should have work the way I did it... and it actually
> did work this way...
> ...except that due to a mistake in my events handling, my new thing
> value was overridden by some obsolete part of code just after being
> converted into a class instance :o(
> And since it was overridden by the raw JSON object value, I stupidly
> assumed that the casting didn't work.
>
> At least, I now know what is the "state of the art" way of getting a
> class instance through Ajax ;o)
>
> Thanks again!
> Eric
>
> On Aug 12, 10:49 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > That should work.  I notice that you have "class.Create" rather than
> > "Class.create"; I assume that's just an error in the note and that the
> > actual code uses Class.create?  Because if not, that's your problem.
>
> > > if(myInstance.isB())...
>
> > > => isB is undefined
>
> > That indicates there's a different problem.  isB should be defined
> > regardless, you defined it in your class definition.  If the
> > Object.extend thing weren't working, it should *return* undefined, but
> > not *be* undefined.
>
> > FWIW, this works:
> > * * * * (also athttp://pastie.org/581050)
> > // Defining
> > var Thing = Class.create({
> >     initialize: function(src)
> >     {
> >         if (src) {
> >             Object.extend(this, src);
> >         }
> >     },
>
> >     isB: function()
> >     {
> >         return this.b;
> >     }
>
> > });
>
> > // Using:
> > var t;
> > t = new Thing({"b": true});
> > alert("t.isB() ? " + t.isB());
> > * * * *
>
> > HTH,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
--~--~-~--~~~---~--~~
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: Using Ajax.Updater posts the contain form

2009-08-13 Thread T.J. Crowder

Hi,

The code you included in your message isn't posting any forms; it must
be something else on the page.

Can you produce a minimalist, complete, stand-alone example of the
behavior?  (There's a template here[1] if you like.)  See Step 3 in
this troubleshooting tip[2] on the FAQ for details and rationale.

[1] http://proto-scripty.wikidot.com/self-contained-test-page
[2] http://proto-scripty.wikidot.com/faq#xyzprob

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


On Aug 13, 9:18 am, dpGoose  wrote:
> Hi,
>
> I am using Axaj.Updater to retrieve a message from the server and it
> does do this but it also posts the form the Updater script and
> associated controls are contained in. I have followed the examples on
> the prototype site with modifications for my web server. Why is this
> happening? Here is the relevant code. This response is just a text
> message.
>
> 
>         function loadit()
>         {
>                 new Ajax.Updater( 'structureTree', 'Render?s=OrgConfigAjax',
>                 {
>                         method: 'get',
>                         parameters:
>                         {
>                                 cmd: 'test'
>                         }
>                  });
>         }
> 
> Click me
> Loading...
> 
--~--~-~--~~~---~--~~
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: Using Ajax.Updater posts the contain form

2009-08-13 Thread T.J. Crowder

> I assume the snippet you posted is contained in a form, right?
> Button-tags are type="submit" by default...

Gah!  I read right past that.  Nice catch.

-- T.J.

On Aug 13, 1:21 pm, Daniel Rubin  wrote:
> dpGoose wrote:
> > Hi,
>
> > I am using Axaj.Updater to retrieve a message from the server and it
> > does do this but it also posts the form the Updater script and
> > associated controls are contained in. I have followed the examples on
> > the prototype site with modifications for my web server. Why is this
> > happening? Here is the relevant code. This response is just a text
> > message.
>
> > 
> >    function loadit()
> >    {
> >            new Ajax.Updater( 'structureTree', 'Render?s=OrgConfigAjax',
> >            {
> >                    method: 'get',
> >                    parameters:
> >                    {
> >                            cmd: 'test'
> >                    }
> >             });
> >    }
> > 
> > Click me
> > Loading...
> > 
>
> Hi,
> you might want to try putting the attribute setting
>     type="button"
> in your button-tag.
>
> I assume the snippet you posted is contained in a form, right?
> Button-tags are type="submit" by default, so clicking the button will
> trigger both 'click' and 'submit' events.
>
> Does this help?
>
> Daniel
--~--~-~--~~~---~--~~
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: How to disable draggables in script.aculo.us

2009-08-14 Thread T.J. Crowder

Hi,

A brief glance at the documentation[1] suggests that you should keep a
reference to the Draggables you create and when you don't want
something to be draggable anymore, call the #destroy method on them.

[1] http://wiki.github.com/madrobby/scriptaculous/draggable

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


On Aug 13, 9:36 pm, nimzo  wrote:
> Hi-
>
> I'm trying to make a group of objects draggable as you can see below -
> easy enough. But I'd like to configure things so that at the very
> moment any one of these items is dragged, the others automatically
> cease to be draggable. Does anyone know how to do this?
>
>     var products = document.getElementsByClassName('box');
>     for (var i = 0; i < products.length; i++) {
>         new Draggable(products[i].id, {ghosting:true})
>     }
>
> Thanks very much.
--~--~-~--~~~---~--~~
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: Observing a checkbox

2009-08-14 Thread T.J. Crowder

Hi,

FWIW, the Abstract.EventObserver class in Prototype uses click, see
lines 3,762-3,764 of 1.6.0.3.  I've typically used click and haven't
run into issues.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 13, 4:03 pm, "Alex McAuley" 
wrote:
> Thanks Douglas
>
> My way works fine...
>
> That is not the issue... the issue is with change or click
>
> Thanks
>
> Alex Mcauleyhttp://www.thevacancymarket.com
>
>
>
> - Original Message -
> From: "Douglas" 
> To: 
> Sent: Thursday, August 13, 2009 3:35 PM
> Subject: [Proto-Scripty] Re: Observing a checkbox
>
> checked === true is wrong you should check for ('checked' ==
> $(input).checked || true == $(input).checked)
>
> ps: untested
>
> On Thu, Aug 13, 2009 at 10:53 AM, Jeztah
> wrote:
>
> > What is the correct Cross browser way to observe a checkbox being
> > checked or not
>
> > I am using
>
> > $('hidenonlive').observe('change',function() {
>
> > if($('hidenonlive').checked!==true) {
> > alert('Showing');
>
> > } else {
> > $$('.dead-vacancy').invoke('hide');
>
> > }
>
> > });
>
> > But it doesnt seem to want to work in IE8 and it doesnt throw an
> > error SHoudl i just use "click" instead?
>
> > Thanks in advance
>
> > ALex
>
> --
> Believe nothing, no matter where you read it, or who said it, no
> matter if I have said it, unless it agrees with your own reason and
> your own common sense.
--~--~-~--~~~---~--~~
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: How to disable draggables in script.aculo.us

2009-08-14 Thread T.J. Crowder

Alex,

> It seems bizzare to me that...you are still using vanilla JS methods to 
> select dom
> nodes/elements.
>
> speed your code up with.

It may be more expressive, shorter, more elegant, more maintainable,
etc., but _speedier_ it ain't. ;-)  You're suggesting two things:

A) That he bypass what is in most cases a built-in compiled
optimisation of a common selector use case (find by class name) in
favor of using something interpreted and via the notoriously slow DOM
API.

and

B) That he introduce several completely unnecessary function calls
(#each and its callbacks).

That will not speed up his code.

For instance, on Firefox 3 for Windows, $$ is more than an order of
magnitude (!) slower than getElementsByClassName (both 1.6.0.3 and
1.6.1; the latter surprised me) for the one use case where
getElementsByClassName is useful; in my ad hoc tests between 12x and
25x slower.  Even on IE7 (where getElementsByClassName is not native,
it's supplied by Prototype), $$ is somewhere between slightly slower
and twice as slow because it has to deal with a lot more complexity.

Separately, #each is appropriate only for looping small enumerations
(which, granted, this one probably is), or where time isn't critical
(and given that JavaScript has only one thread, time is pretty much
always critical).  They may not be l33t, but the fastest way *by far*
to loop through an array is a boring old-fashioned for loop.  I mean,
again, we're into orders of magnitude here, 20-25x slower.  This will
continue to be the case at least until #each is directly supported by
the JavaScript interpreter (which is coming!), and even then only if
its JIT compiling can factor out the function call on each iteration
(which in many cases we can expect it will).

Now, if browsers were way fast, it wouldn't matter much.  But the fact
is, right now, we're dealing with a slow environment, hugely slow in
the case of the majority browser, IE.  The freakishly fast Chrome is
helping set the stage for that to change, but as we know, these things
change slowly.

So...let's not tell him to "speed up" his code in ways that will
demonstrably slow it down, eh? ;-)  There are lots of reasons to use $
$ (not least almost complete support for CSS3!), and separately for
using #each (more expressive IMV, less error-prone), but speed isn't
on either list.

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


On Aug 14, 11:03 am, "Alex McAuley" 
wrote:
> Nizmo...
>
> It seems bizzare to me that you are using Draggables (which relies on
> prototypejs) yet you are still using vanilla JS methods to select dom
> nodes/elements.
>
> speed your code up with.
>
> $$('.box').each(function(element) {
>
> new Draggable(element, {ghosting:true})
>
> });
>
> //
>
> HTH
>
> Alex Mcauleyhttp://www.thevacancymarket.com
>
>
>
> - Original Message -
> From: "nimzo" 
> To: "Prototype & script.aculo.us" 
> Sent: Thursday, August 13, 2009 9:36 PM
> Subject: [Proto-Scripty] How to disable draggables in script.aculo.us
>
> > Hi-
>
> > I'm trying to make a group of objects draggable as you can see below -
> > easy enough. But I'd like to configure things so that at the very
> > moment any one of these items is dragged, the others automatically
> > cease to be draggable. Does anyone know how to do this?
>
> >    var products = document.getElementsByClassName('box');
> >    for (var i = 0; i < products.length; i++) {
> >        new Draggable(products[i].id, {ghosting:true})
> >    }
>
> > Thanks very much.
--~--~-~--~~~---~--~~
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: Calling method from another method

2009-08-16 Thread T.J. Crowder

Hi,

Your syntax is fine.  If you're callilng explainYourself like this:

this.explainYourself();

...it should work.  How are you calling it?  Because context (the
meaning of the "this" keyword) is slightly different in JavaScript
than in other languages using that keyword, and it's easily lost.  For
instance:

var f;
f = this.explainYourself; // Getting a reference to the function, not
calling it
f();  // Now I'm calling it

That would fail because "this" would not be a reference to an instance
of myClass when the function was called.

Here are some resources for reading up on context:

[1] http://blog.niftysnippets.org/2008/03/mythical-methods.html
[2] http://blog.niftysnippets.org/2008/04/you-must-remember-this.html
[3] http://www.alistapart.com/articles/getoutbindingsituations
[4] 
http://proto-scripty.wikidot.com/prototype:tip-using-an-instance-method-as-a-callback-or-event-handler

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

On Aug 15, 10:27 pm, Mojito  wrote:
> I'm a complete noob to Prototype and don't know how to call a method
> from another method.
>
> I'm using the [URL="http://www.prototypejs.org/learn/class-
> inheritance"]Prototype JS library[/URL] to make classes.
>
> 
> var myClass = Class.create({
>    initialize: function() {
>       this.myValue = 5;
>    },
>    returnHello: function() {
>       return 'hello';
>    },
>    explainYourself: function() {
>       return this.returnHello() + ", my value is: " + this.myValue;
>    }});
>
> ++
>
> In explainYourself(), I tried to call returnHello() and I got an error
> saying this.returnHello() is not a function. What is the correct
> syntax?
--~--~-~--~~~---~--~~
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: Element.select fails in IE

2009-08-17 Thread T.J. Crowder

Hi,

You need to run your form reference through $(), e.g.:

frm = $(frm);

...in order to get access to the extended methods provided by
Prototype.  See this article[1] on the Prototype site for details.

[1] http://prototypejs.org/learn/extensions

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


On Aug 17, 4:34 pm, "speedpac...@gmail.com" 
wrote:
> Hi,
>
> I'm working on our new website, and I love prototypejs for it.
> Unfortunately, I seem to be having an issue with Element.select when I
> initialise my forms when the page is being opened in IE.
>
> You can check the error 
> onhttp://flexin.be/site/nl/Product/details/100011.html&_s=0
>
> Unfortunately, I seem to be unable to fix the issue.  Does anyone have
> any idea as to what might be causing this?
>
> FF, as usual just loves the code and renders the page error-free.
>
> Thanks a lot for your assistance!
> David.
--~--~-~--~~~---~--~~
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: Element.select fails in IE

2009-08-17 Thread T.J. Crowder

Hi,

> That last line gives the error - should I do $(el).getAttribute
> ('validation')?
> I believe that I already extended it setting var el to $(elements[i]),
> or am I mistaking?

No, you're right, having done the extension once, you're all set.

> Is there a nicer way to create
> an array from this in stead of doing what I do with the eval function?

If I'm reading you right, you're going to end up eval'ing this string:

new Array({type:'required',
errorMessage:'Vereist Veld'} , {type:'minchars',
errorMessage:'Minimaal 2 karakters vereist', chars: '2'} ,
{type:'maxchars', errorMessage:'Maximaal 63 toegelaten', chars:
'63'} )

That's probably not going to have the intended effect.  I would
probably suggest:

validations = ('[' + el.getAttribute('validations') + ']').evalJSON();

...or better yet, have your server side output the brackets.  But is
that really the best way to pass the validations from server to
client?

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


On Aug 17, 5:58 pm, "speedpac...@gmail.com" 
wrote:
> Hi again,
>
> I tried modifying the code, but I'm still running into an error saying
> that "the property or method is not supported on this object".
>
> Code snippet as follows:
> ---
>     var elements = $(frm).select('[validation]');
>     alert(elements.length);
>     for(var i=0; i < elements.length; i++) {
>         var el = $(elements[i]);
>
>         // first add validations to the form...
>         validations = eval('new Array' + el.getAttribute
> ('validation'));
> ---
> That last line gives the error - should I do $(el).getAttribute
> ('validation')?
> I believe that I already extended it setting var el to $(elements[i]),
> or am I mistaking?
>
> Also - the attribute 'validation' is set to ({type:'required',
> errorMessage:'Vereist Veld'} , {type:'minchars',
> errorMessage:'Minimaal 2 karakters vereist', chars: '2'} ,
> {type:'maxchars', errorMessage:'Maximaal 63 toegelaten', chars:
> '63'} ), which is rendered serverside.  Is there a nicer way to create
> an array from this in stead of doing what I do with the eval function?
>
> Again - prototype rules, even for me not being a javascript guru :)
>
> David.
>
> On 17 aug, 18:04, "speedpac...@gmail.com" 
> wrote:
>
>
>
> > Wow!
> > thanks so much for the response.  I was under the impression that as
> > it was already passed to the function as an element and not the id
> > reference, it was already extended, but I just learned something new
> > then, so thanks for the incredibly fast response.
>
> > I have some other errors on IE, but I'll try to figure them out myself
> > as well.
>
> > Again - thanks for the great script and support through these groups!
>
> > David.
>
> > On 17 aug, 17:57, "T.J. Crowder"  wrote:
>
> > > Hi,
>
> > > You need to run your form reference through $(), e.g.:
>
> > > frm = $(frm);
>
> > > ...in order to get access to the extended methods provided by
> > > Prototype.  See this article[1] on the Prototype site for details.
>
> > > [1]http://prototypejs.org/learn/extensions
>
> > > HTH,
> > > --
> > > T.J. Crowder
> > > tj / crowder software / com
> > > Independent Software Engineer, consulting services available
>
> > > On Aug 17, 4:34 pm, "speedpac...@gmail.com" 
> > > wrote:
>
> > > > Hi,
>
> > > > I'm working on our new website, and I love prototypejs for it.
> > > > Unfortunately, I seem to be having an issue with Element.select when I
> > > > initialise my forms when the page is being opened in IE.
>
> > > > You can check the error 
> > > > onhttp://flexin.be/site/nl/Product/details/100011.html&_s=0
>
> > > > Unfortunately, I seem to be unable to fix the issue.  Does anyone have
> > > > any idea as to what might be causing this?
>
> > > > FF, as usual just loves the code and renders the page error-free.
>
> > > > Thanks a lot for your assistance!
> > > > David.
--~--~-~--~~~---~--~~
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: POSTing a form via AJAX

2009-08-18 Thread T.J. Crowder

Hi,

'Tis indeed very easy.  Say you have a form wrapped in a div:





You can post it like so and take the result (which is presumed to be
an HTML snippet in this case) and use that to update the container:

new Ajax.Updater('formwrapper', someurl, {
parameters:  $('formwrapper').down('form').serialize(true),
onFailure: function(response) {
// ...show a failure message...
}
});

That uses:

$[1] to find the formwrapper div.
Element#down[2] to find the form within the wrapper.
Form#serialize[3] to grab the form fields and make an object out of
them.
Ajax.Updater[4] to make the request (by default it uses POST) and
update the wrapper on success.

[1] http://prototypejs.org/api/utility/dollar
[2] http://prototypejs.org/api/element/down
[3] http://prototypejs.org/api/form/serialize
[4] http://prototypejs.org/api/ajax/updater

You can also do it without wrapping the form in a div, but it's a
*tiny* bit more work; assuming the form has the ID 'myform' (creative,
aren't I?):

var form = $('myform');
new Ajax.Request(someurl, {
parameters:  form.serialize(true),
onSuccess: function(response) {
form.insert({below: response.responseText});
form.remove();
},
onFailure: function(response) {
// ...show a failure message...
}
});

Citations for Ajax.Request, Element#insert, and Element#remove are
left as an exercise for the reader... ;-)

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


On Aug 18, 3:09 pm, bill  wrote:
> I've read the docs, but can't seem to figure out how to POST a form
> via AJAX.
> I'm sure it is easy (as most prototype.js function calls are) but
> how ?
>
> I want the reply to update the div that holds the form (which itself
> was downloaded via AJAX).
> bill
--~--~-~--~~~---~--~~
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: help with select on element not working

2009-08-18 Thread T.J. Crowder

Colin,

> Incidentally (and not on topic for your question)
> 
> is not valid in either HTML or XHTML.

It's valid XHTML for an empty table cell.

> Also,  does not have a 'type' attribute. I believe browsers
> generally do let you set an arbitrary attribute (though I haven't
> found anything in the HTML spec that explicitly permits it)...

It is in fact verboten.  In HTML5, though, we're allowed to use our
own attributes as long as their names start with "data-", e.g.:

    

...is valid but



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

On Aug 18, 4:03 pm, ColinFine  wrote:
> On Aug 10, 3:53 pm, molo  wrote:
>
> > Thanks so much T.J., that was the problem. I never would have gotten
> > that
>
> Incidentally (and not on topic for your question)
> 
> is not valid in either HTML or XHTML.
>
> Also,  does not have a 'type' attribute. I believe browsers
> generally do let you set an arbitrary attribute (though I haven't
> found anything in the HTML spec that explicitly permits it), but it
> seems an odd thing to do: did you mean to say 'class="text"'?
--~--~-~--~~~---~--~~
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: Nested updater calls , weird result

2009-08-18 Thread T.J. Crowder

Hi,

How 'bout a NON-pseudo, standalone example?  Because there are a
number of things in that pseudo that could be tripping you up, but I
figure most of them are because it's pseudo...
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 18, 4:49 pm, dweeves  wrote:
> Hi , i'm using Ajax.Updater in a "nested" way.
>
> here is a pseudo-code of my use case
>
> First pass
>
> 
>   load subdiv
>   
>   
> 
>
> Second pass, sub_div is filled with something like that
> load subdiv
>   
>     
>         new Ajax.Updater(targetDiv,url,
>                           {
>                                 asynchronous:(async!=null),
>                                 onComplete:completecb,
>                               evalScripts:true,
>                                 postBody:params
>                           }
>         );
>
>
>
> };
--~--~-~--~~~---~--~~
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: Which parameters to stopObserving are optional?

2009-08-18 Thread T.J. Crowder

Hi,

It's documented here[1], which is where you get with the links in the
API TOC.  It also appears there's an outdated page here[2] (note the
capitalisation) that does not mention this.  Scary.  Can't wait until
we ditch this Mephisto stuff for the 1.6.1 generated docs.

[1] http://prototypejs.org/api/event/stopObserving
[2] http://prototypejs.org/api/event/stopobserving

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


On Aug 18, 6:27 pm, Paul Lynch  wrote:
> I noticed in the code for stopObserving that it appears you can get
> away with just specifying the element, and then (perhaps) it cancels
> all observers for all events for that element.  However, the
> documentation surprisingly does not mention this ability, but lists
> the element, event name, and event handler function as though they
> were required elements.
>
> It would be very convenient to be able to say Event.stopObserving
> (someElement), and so I'm wondering whether the documentation is
> simply incomplete, or whether it was intentionally trying to
> discourage people from using the method that way.
>
> Thanks,
>      --Paul
--~--~-~--~~~---~--~~
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: Using Ajax.Request and evalJS to load functions on the fly

2009-08-18 Thread T.J. Crowder

Hi,

They're accessible from anywhere after they're evaluated, but mind how
you declare them, because of a bit of a quirk about how they're
evaluated.  There's a badly misplaced note about this in the
documentation, at the bottom of the discussion of Ajax.Updater[1].  It
really should be in the String#evalScripts documentation, and it's on
my list, but I haven't had a chance to move it.

[1] http://prototypejs.org/api/ajax/updater

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


On Aug 18, 8:00 pm, Remah  wrote:
> I am trying to call a JS file using Ajax.Request that will return a
> javascript function.  This function will be used by code taht will be
> injected into a div.  Is this possible?  It seems like the function is
> accessible within the CallBacks of Ajax.Request, but they are not
> accessible outside.
>
> Thanks for your help,
>
> Remah
--~--~-~--~~~---~--~~
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: onclick functionality in ajax

2009-08-20 Thread T.J. Crowder

Hi,

When you replace an element, the old element is no longer displayed
(ideally it no longer exists) and a new element is put in its place.
Any event handlers associated with the old element are not
automatically transferred to the new one.

There are a couple of ways to handle this:

1. Event Delegation:  If you can handle events on the container
containing B, rather than on B itself, then you'll be fine since
you're not replacing the container.  Clicks and most other events
"bubble up" from the child elements to their ancestors, so this can be
a powerful approach.  For instance, I have an app with a bunch of
links that trigger client-side actions (rather than actually going
somewhere).  I don't look the "click" event on each link, that would
be horribly inefficient.  Instead, I hook the "click" event on the
container all of these links are in, and then when I get the event I
ask what link triggered it via Event#findElement[1].

2. If event delegation won't work for you, you'll need to unhook all
of your handlers on B before replacing it, then hook them up to the
new B after replacing it.  If you don't unhook your handlers before
you replace B, you'll probably leak some memory on every update; and
of course if you don't hook up the new handlers you won't see the
clicks.

[1] http://prototypejs.org/api/event/findElement

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

On Aug 20, 12:19 am, hass  wrote:
> I have set up a relatively straight forward scenario where i have a
> listener for event A.  On click of A (a button), I run an ajax request
> to update a div B.  B was a large div, representing one of 3 panels on
> a page.  B had some javascript functionality (lets call this event C)
> inside of it which worked prior to clicking A, but after clicking A,
> it no longer works.  I know this is a DOM issue, but I've got to think
> there is a good way around this.  Any ideas?
--~--~-~--~~~---~--~~
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: help with select on element not working

2009-08-20 Thread T.J. Crowder

Hi Colin,

> > > Incidentally (and not on topic for your question)
> > > 
> > > is not valid in either HTML or XHTML.
>
> > It's valid XHTML for an empty table cell.
>
> Wrong. It's a common misconception (which I had myself until
> recently).

If so, it's a misconception the W3C's own validator shares.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 19, 10:24 am, ColinFine  wrote:
> On Aug 18, 4:47 pm, "T.J. Crowder"  wrote:
>
> > Colin,
>
> > > Incidentally (and not on topic for your question)
> > > 
> > > is not valid in either HTML or XHTML.
>
> > It's valid XHTML for an empty table cell.
>
> Wrong. It's a common misconception (which I had myself until
> recently).
>
> "All elements other than those declared in the DTD as EMPTY must have
> an end tag. Elements that are declared in the DTD as EMPTY can have an
> end tag or can use empty element shorthand (see Empty
> Elements)." (http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.3)
>
> That is, elements DECLARED TO BE EMPTY may use the shorthand. Elements
> which happen to have no content may not.
>
> I discovered this when Firefox correctly objected to  or
> something when I had given it an XTHML-Strict DOCTYPE.
>
> > > Also,  does not have a 'type' attribute. I believe browsers
> > > generally do let you set an arbitrary attribute (though I haven't
> > > found anything in the HTML spec that explicitly permits it)...
>
> > It is in fact verboten.  
>
> Is it? I couldn't find an explicit statement that only the defined
> attributes were permitted, though it is implied (and I thought I had
> found somewhere in the HTML spec where it referred to 'attributes
> defined in this specification', which might be taken to imply that
> other attributes were permitted; but I can't find that now).
>
> In HTML5, though, we're allowed to use our
>
>
>
> > own attributes as long as their names start with "data-", e.g.:
>
> >     
>
> > ...is valid but
>
> >     
>
> > ...is not.
--~--~-~--~~~---~--~~
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: Using Ajax.Request and evalJS to load functions on the fly

2009-08-20 Thread T.J. Crowder

Hi,

Can you post a minimal, self-contained example[1] of the problem?

[1] http://proto-scripty.wikidot.com/self-contained-test-page
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 19, 2:39 pm, "Donnie Carvajal" 
wrote:
> HI T.J.,
>
> Will this work with Ajax.Request?  I changed my script so that it is created 
> instead of defined and I still can't access it using evalJS.
>
> Donnie
>
>
>
> -Original Message-
> From: prototype-scriptaculous@googlegroups.com 
> [mailto:prototype-scriptacul...@googlegroups.com] On Behalf Of T.J. Crowder
> Sent: Tuesday, August 18, 2009 4:24 PM
> To: Prototype & script.aculo.us
> Subject: [Proto-Scripty] Re: Using Ajax.Request and evalJS to load functions 
> on the fly
>
> Hi,
>
> They're accessible from anywhere after they're evaluated, but mind how
> you declare them, because of a bit of a quirk about how they're
> evaluated.  There's a badly misplaced note about this in the
> documentation, at the bottom of the discussion of Ajax.Updater[1].  It
> really should be in the String#evalScripts documentation, and it's on
> my list, but I haven't had a chance to move it.
>
> [1]http://prototypejs.org/api/ajax/updater
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Aug 18, 8:00 pm, Remah  wrote:
> > I am trying to call a JS file using Ajax.Request that will return a
> > javascript function.  This function will be used by code taht will be
> > injected into a div.  Is this possible?  It seems like the function is
> > accessible within the CallBacks of Ajax.Request, but they are not
> > accessible outside.
>
> > Thanks for your help,
>
> > Remah
--~--~-~--~~~---~--~~
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: Prototype breaks the IE8 native JSON parser.

2009-08-20 Thread T.J. Crowder

Hi,

Wait! Stop the presses, are you saying IE8 has...a bug in it? ;-)
(Oh, I shouldn't be mean to Microsoft, all browsers have bugs in them,
and they seem to have made quite an effort in IE8.)

Have you reported the bug to Microsoft?

Seriously, though, thank you for doing the research to why it breaks
and posting the info here, very very useful -- I'm sure you just saved
the core team a fair bit of time hunting this down.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 19, 9:58 pm, Joel  wrote:
> See the following URL for all the gory details:
>
> http://stackoverflow.com/questions/1288962/ie8-native-json-parse-prot...
>
> But to sum up, the following test case will get an "out of stack
> space" error in IE8 when it is running in IE8 Standards mode (you can
> check the mode by hitting F12 for the Developer Tools). If you comment
> out either the Function.prototype line or the Array.prototype line,
> you won't get the error.
>
> Because Prototype adds functions to both Array.prototype and
> Function.prototype, pages that use Prototype will get the "out of
> stack space" error whenever they try to use the native JSON parser to
> parse some JSON that contains an array. But only if they pass a
> "reviver" function to the JSON.parse() method. Which, unfortunately,
> is pretty common in order to handle dates.
>
>              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>
>     http://www.w3.org/1999/xhtml";>
>     
>         
>     
>
>     Function.prototype.test1 = function() { };
>     Array.prototype.test2 = function() { };
>
>     window.onload = function()
>     {
>         alert(JSON.parse('{ "foo": [1,2,3] }', function(k,v) { return
> v; }));
>     }
>
>     
>     
>     
>
>     
>     
--~--~-~--~~~---~--~~
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: to NEW or not to NEW, that is the question

2009-08-20 Thread T.J. Crowder

Hi,

In general, the correct thing is what the docs[1] say it is.  Fade,
Appear, and most others are just functions, not constructor functions,
and so "new" is not correct.  Some other things, like Effect.Opacity
[2] (which confusingly use *exactly* the same capitalization -- don't
shoot the messenger), are constructor functions, and so you need to
use "new" with them.  When in doubt, check the docs.  I don't know
scripty well enough to know why some of them are constructors and some
aren't; perhaps there's a good reason...

If you use the methodized form instead:

$('myNiftyFadingElement').fade();

...you don't have to worry about it.

[1] http://wiki.github.com/madrobby/scriptaculous/effect-fade
[1] http://wiki.github.com/madrobby/scriptaculous/effect-opacity

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

On Aug 20, 7:29 am, Mojito  wrote:
> Which is more proper?
>
> new Effect.Fade(..)
>
> or
>
> Effect.Fade(..)
>
> Both work for me. I'm just wondering which one is more cross browser
> compatible or runs faster.
--~--~-~--~~~---~--~~
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: this keyword inside of the map function

2009-08-20 Thread T.J. Crowder

Hi,

Rather than binding it, use the second parameter to map (aka collect
[1]), that's what the second param ("context") is for.  You'll find
that most of the Enumerable methods that take callbacks also take a
context parameter so the callback can be a method.

[1] http://prototypejs.org/api/enumerable/collect

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


On Aug 20, 8:34 am, Daniel Rubin  wrote:
> Andy Daykin wrote:
> > Hello, I am having some difficulties writing a class, in my code I have a 
> > class where I need to be able to bind event listeners to values. In my code 
> > I want the variable pointerIndex to be accessible outside of the initialize 
> > function, but right now it is not. If I make a global variable for 
> > pointerIndex I can solve the problem, but I would rather have a class 
> > variable using the this keyword.
>
> > I am not positive, but I believe the problem is from my event listeners on 
> > the line:
>
> > Now: $(e).observe('click', this.doSlide.bind(featuresWrapper[i].id));
>
> > Before: (working) $(e).observe('click', 
> > mySlide.doSlide.curry(featuresWrapper[i].id));
>
> > With the new way of calling the doSlide function I can't even seem to be 
> > able to call the function, nothing happens when the function should get 
> > called. Before I was using the curry function to try and pass the values of 
> > the featuresWrapper array to the doSlide function. I was able to get that 
> > to work, but I would rather just use bind and this to make the code more 
> > object oriented. Based on my alert statements I can tell that the this 
> > keyword is different inside and outside of the map function.
>
> Hi Andy,
>
> the last observation is crucial.  Because this is not your expected
> SlideShow instance when you do this.doSlide.bind (...), this.doSlide is
> undefined and thus the call to this.doSlide.bind fails (there should be
> an exception in the error console somewhere).
>
> You can solve it by bind()-ing the map function, too:
>   $(parentDiv).childElements().map( (function(e) {
>     $(e).observe('click',
>                  this.doSlide.bind(this, featuresWrapper[i].id));
>   }).bind (this) );
>
> (Note: Passing this as first arg to the inner bind call, as Kevin
> suggested, is needed, too.)
>
> Have fun
> Daniel
>
>
>
> > var SlideShow = Class.create({
>
> > initialize: function(parentDiv) {
>
> > this.pointerIndex = 0;
>
> > //pointerIndex = 0;
>
> > // Load the event listener for each section
>
> > document.observe("dom:loaded", function() {
>
> > var featuresWrapper = $('featuresWrapper').childElements();
>
> > var i = 0;
>
> > alert(this);
>
> > $(parentDiv).childElements().map(function(e) {
>
> > alert(this);
>
> > $(e).observe('click', this.doSlide.bind(featuresWrapper[i].id));
>
> > //$(e).observe('click', mySlide.doSlide.curry(featuresWrapper[i].id));
>
> > i++;
>
> > });
>
> > slides = $$('.featureImage').map(function(e) {
>
> > return e.id;
>
> > });
>
> > });
>
> > },
>
> > doSlide: function(slideClicked) {
>
> > alert('here');
>
> > if(active == 0) {
>
> > active = 1;
>
> > var yValCurrent = $(slides[this.pointerIndex]).viewportOffset().top;
>
> > //var yValCurrent = $(slides[pointerIndex]).viewportOffset().top;
>
> > var yValClick = $(slideClicked).viewportOffset().top;
>
> > var yValDiff = yValClick - yValCurrent;
>
> > var pointerShift = 0;
>
> > if (Math.abs(yValDiff) == Math.abs(210)) {
>
> > pointerShift = 70; // Change this to get the height as well as a few more
>
> > }
>
> > else {
>
> > pointerShift = 140;
>
> > }
>
> > if (yValDiff > 0) {
>
> > $$('.featureImage').map(function(e) {
>
> > new Effect.Move(e, { y: -yValDiff, duration: .8, afterFinish: function(e) { 
> > active = 0; } });
>
> > });
>
> > new Effect.Move('featurePointer', { y: pointerShift });
>
> > }
>
> > else if (yValDiff < 0) {
>
> > $$('.featureImage').map(function(e) {
>
> > new Effect.Move(e, { y: -yValDiff, duration: .8, afterFinish: function(e) { 
> > active = 0; } });
>
> > });
>
> > new Effect.Move('featurePointer', { y: -pointerShift });
>
> > }
>
> > this.pointerIndex = slides.indexOf(slideClicked);
>
> > }
>
> > }
>
> > });
>
> > var slides;
>
> > var active = 0;
>
> > //var pointerIndex = 0;
>
> > var mySlide = new SlideShow('featureList');
--~--~-~--~~~---~--~~
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: Prototype breaks the IE8 native JSON parser.

2009-08-20 Thread T.J. Crowder

Tobie,

What's the issue #?  I'm curious how Prototype can work around this
IE8 behavior...

Cheers,

-- T.J.

On Aug 20, 1:04 pm, Tobie Langel  wrote:
> This is a Prototype bug and will be fixed in  version 1.7.
>
> In the meantime, please use Object.toJSON(...) instead.
>
> Best,
>
> Tobie
>
> On Aug 20, 10:53 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > Wait! Stop the presses, are you saying IE8 has...a bug in it? ;-)
> > (Oh, I shouldn't be mean to Microsoft, all browsers have bugs in them,
> > and they seem to have made quite an effort in IE8.)
>
> > Have you reported the bug to Microsoft?
>
> > Seriously, though, thank you for doing the research to why it breaks
> > and posting the info here, very very useful -- I'm sure you just saved
> > the core team a fair bit of time hunting this down.
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Aug 19, 9:58 pm, Joel  wrote:
>
> > > See the following URL for all the gory details:
>
> > >http://stackoverflow.com/questions/1288962/ie8-native-json-parse-prot...
>
> > > But to sum up, the following test case will get an "out of stack
> > > space" error in IE8 when it is running in IE8 Standards mode (you can
> > > check the mode by hitting F12 for the Developer Tools). If you comment
> > > out either the Function.prototype line or the Array.prototype line,
> > > you won't get the error.
>
> > > Because Prototype adds functions to both Array.prototype and
> > > Function.prototype, pages that use Prototype will get the "out of
> > > stack space" error whenever they try to use the native JSON parser to
> > > parse some JSON that contains an array. But only if they pass a
> > > "reviver" function to the JSON.parse() method. Which, unfortunately,
> > > is pretty common in order to handle dates.
>
> > >      > >         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>
> > >     http://www.w3.org/1999/xhtml";>
> > >     
> > >         
> > >     
>
> > >     Function.prototype.test1 = function() { };
> > >     Array.prototype.test2 = function() { };
>
> > >     window.onload = function()
> > >     {
> > >         alert(JSON.parse('{ "foo": [1,2,3] }', function(k,v) { return
> > > v; }));
> > >     }
>
> > >     
> > >     
> > >     
>
> > >     
> > >     
--~--~-~--~~~---~--~~
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: help with select on element not working

2009-08-20 Thread T.J. Crowder

Thanks, Colin, glad it was something like that.

-- T.J. :-)

On Aug 20, 5:43 pm, ColinFine  wrote:
> On Aug 20, 9:39 am, "T.J. Crowder"  wrote:
>
> > Hi Colin,
>
> > > > > Incidentally (and not on topic for your question)
> > > > > 
> > > > > is not valid in either HTML or XHTML.
>
> > > > It's valid XHTML for an empty table cell.
>
> > > Wrong. It's a common misconception (which I had myself until
> > > recently).
>
> > If so, it's a misconception the W3C's own validator shares.
>
> Apologies - I was wrong. After discussion with somebody from W3C I now
> understand that the section I was quoting is informative not
> normative. I do think that it is misleading however (and I'm sure I
> discovered this apparent limitation when something - I thought it was
> firefox - threw out a construct like ).
>
> Both the XML and XHTML specs recommend not using the short form for
> elements which are not defined as EMPTY, but they do not forbid it.
--~--~-~--~~~---~--~~
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: this keyword inside of the map function

2009-08-20 Thread T.J. Crowder

Hi,

I haven't been into the details of your specific situation, I just
happened to notice the suggestion to bind when using map and it jumped
out at me.  But generally:

Say `this` points to an instance that has a flurgle property with the
value "bar".  And so:

alert(this.flurgle);

...alerts "bar".

Within the map function, unless you specify context, `this` won't
refer to the instance anymore:

[1, 2].map(function(item) {
alert(this.flurgle + ": " + item);
});

...alerts "undefined: 1" and "undefined: 2" because `this` inside the
map function doesn't have the same value as `this` outside of it.  But
map allows you to pass a second parameter specifying what `this`
should be inside the function:

[1, 2].map(function(item) {
alert(this.flurgle + ": " + item);
}, this);

...and so that alerts "bar: 1" and "bar: 2" as expected.  Many of the
Enumerable methods have this optional second context parameter.

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


On Aug 21, 12:45 am, "Andy Daykin"  wrote:
> I tried the first suggestion, but the function still isn't getting called.
>
> TJ, can you explain more, or show an example of what the context param would
> look like? Should I just put the doSlide function as the 2nd parameter?
>
> -Andy
>
> --
> From: "T.J. Crowder" 
> Sent: Thursday, August 20, 2009 3:56 AM
> To: "Prototype & script.aculo.us" 
> Subject: [Proto-Scripty] Re: this keyword inside of the map function
>
>
>
>
>
> > Hi,
>
> > Rather than binding it, use the second parameter to map (aka collect
> > [1]), that's what the second param ("context") is for.  You'll find
> > that most of the Enumerable methods that take callbacks also take a
> > context parameter so the callback can be a method.
>
> > [1]http://prototypejs.org/api/enumerable/collect
>
> > HTH,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Aug 20, 8:34 am, Daniel Rubin  wrote:
> >> Andy Daykin wrote:
> >> > Hello, I am having some difficulties writing a class, in my code I have
> >> > a class where I need to be able to bind event listeners to values. In
> >> > my code I want the variable pointerIndex to be accessible outside of
> >> > the initialize function, but right now it is not. If I make a global
> >> > variable for pointerIndex I can solve the problem, but I would rather
> >> > have a class variable using the this keyword.
>
> >> > I am not positive, but I believe the problem is from my event listeners
> >> > on the line:
>
> >> > Now: $(e).observe('click', this.doSlide.bind(featuresWrapper[i].id));
>
> >> > Before: (working) $(e).observe('click',
> >> > mySlide.doSlide.curry(featuresWrapper[i].id));
>
> >> > With the new way of calling the doSlide function I can't even seem to
> >> > be able to call the function, nothing happens when the function should
> >> > get called. Before I was using the curry function to try and pass the
> >> > values of the featuresWrapper array to the doSlide function. I was able
> >> > to get that to work, but I would rather just use bind and this to make
> >> > the code more object oriented. Based on my alert statements I can tell
> >> > that the this keyword is different inside and outside of the map
> >> > function.
>
> >> Hi Andy,
>
> >> the last observation is crucial.  Because this is not your expected
> >> SlideShow instance when you do this.doSlide.bind (...), this.doSlide is
> >> undefined and thus the call to this.doSlide.bind fails (there should be
> >> an exception in the error console somewhere).
>
> >> You can solve it by bind()-ing the map function, too:
> >>   $(parentDiv).childElements().map( (function(e) {
> >>     $(e).observe('click',
> >>                  this.doSlide.bind(this, featuresWrapper[i].id));
> >>   }).bind (this) );
>
> >> (Note: Passing this as first arg to the inner bind call, as Kevin
> >> suggested, is needed, too.)
>
> >> Have fun
> >> Daniel
>
> >> > var SlideShow = Class.create({
>
> >> > initialize: function(parentDiv) {
>
> >> > this.pointerIndex = 0;
>
> >> > //pointerIndex = 0;
>
>

[Proto-Scripty] Re: Effect.Event d

2009-08-21 Thread T.J. Crowder

Hi,

Why not just use the afterFinish on the effect itself?  I don't see
the need for queuing here.

To fade and remove, I think this should do it (note I'm using fade,
not toggle):

$('invitation_row_1').fade({
duration: 0.5,
afterFinish: function(effect) {
effect.element.remove();
    }
    });

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

On Aug 21, 11:40 am, tomkiller44  wrote:
> Hi,
>
> I am using Scriptaculous through RoR and still be confused with the
> queue and Effect.Event.
> I want to fade out a row in a table before removing it from the DOM.
>
> I do this:
>
> Effect.toggle("invitation_row_1",'appear',{duration:0.5,
> queue:'remove'});
> new Effect.Event({queue: 'remove', afterFinish:function(){
>          Element.remove("invitation_row_1");
>
> }}
>
> The row is deleted without (or before) any fading effect.
>
> Has someone any idea why removal does not wait until effect
> completion?
>
> Cheers,
>
> Thomas
--~--~-~--~~~---~--~~
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: to NEW or not to NEW, that is the question

2009-08-23 Thread T.J. Crowder

Hi,

> If I want to quickly develop without looking up whether I need NEW or
> don't need NEW, can I just put NEW in front of everything?

Surely it's better to have an idea what you're actually using, a
function or a constructor?  There aren't that many effects.  If you
use `new` inappropriately, you will at least cause unnecessary
temporary memory allocations, and at worst introduce avoidable bugs in
your code.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 22, 10:09 pm, JoJo  wrote:
> If I want to quickly develop without looking up whether I need NEW or
> don't need NEW, can I just put NEW in front of everything?  Would this
> lead to a memory leak or does Prototype have some sort of garbage
> collection?
>
> On Aug 20, 2:04 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > In general, the correct thing is what the docs[1] say it is.  Fade,
> > Appear, and most others are just functions, not constructor functions,
> > and so "new" is not correct.  Some other things, like Effect.Opacity
> > [2] (which confusingly use *exactly* the same capitalization -- don't
> > shoot the messenger), are constructor functions, and so you need to
> > use "new" with them.  When in doubt, check the docs.  I don't know
> > scripty well enough to know why some of them are constructors and some
> > aren't; perhaps there's a good reason...
>
> > If you use the methodized form instead:
>
> >     $('myNiftyFadingElement').fade();
>
> > ...you don't have to worry about it.
>
> > [1]http://wiki.github.com/madrobby/scriptaculous/effect-fade
> > [1]http://wiki.github.com/madrobby/scriptaculous/effect-opacity
>
> > HTH
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Aug 20, 7:29 am, Mojito  wrote:
>
> > > Which is more proper?
>
> > > new Effect.Fade(..)
>
> > > or
>
> > > Effect.Fade(..)
>
> > > Both work for me. I'm just wondering which one is more cross browser
> > > compatible or runs faster.
--~--~-~--~~~---~--~~
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: scope of "this" in anonymous functions

2009-08-23 Thread T.J. Crowder

Hi,

> myMethod().  I suspect this has something to do with the "this" scope
> in my anonymous function.

It's true that `this` within the function will not be what it was
outside the function unless you do something to make it so, and
certainly that would need to be fixed if you were going to do this
this way.

But you seem to be assuming that the window load event has not already
happened when your `initialize` function is called.  When are you
calling it?  I'd suggest it would be better to call your `initialize`
function (by creating an instance via `new`) *after* the load has
occurred (from some kind of load event handler [window.load or
dom:loaded]), rather than writing the class code such that it assumes
it will be called before the load is complete.  The latter is
delicate; the class won't work correctly if the page has already been
loaded.

* * * *
// Where you're defining your class
var MyClass = Class.create({
   initialize: function() {
  this.myField = new Field();
   },
   myMethod: function() {
  alert(this.myField);
   }
});

// You probably have some main "load" function somewhere
document.observe('dom:loaded', function() {
someAppropriateVarHere = new MyClass();
});
* * * *

Re your request for bind coding help in your follow-up, there are lots
of examples out there if you look.  Some places to look:

http://prototypejs.org/api/function/bind
http://proto-scripty.wikidot.com/prototype:tip-using-an-instance-method-as-a-callback-or-event-handler

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


On Aug 22, 10:06 pm, Mojito  wrote:
> MyClass = Class.create({
>    initialize: function() {
>       this.myField = null;
>       Event.observe(window, 'load', function() {
>          this.myField = new Field();
>       });
>    },
>    myMethod: function() {
>       alert(this.myField);
>    }
>
> });
>
> +++
>
> Field's constructor uses Scriptaculous's sliders, which require an
> element to be already loaded.  That's why I'm only setting
> this.myField when the window has loaded.  I see that my sliders get
> initialized properly, but this.myField is still null when I call
> myMethod().  I suspect this has something to do with the "this" scope
> in my anonymous function.  How do I fix this to do what I intended?
--~--~-~--~~~---~--~~
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: KEY_DOWN event

2009-08-25 Thread T.J. Crowder

Hi,

If you want to know whether the control key was down when the mouse
was clicked, then yes, the ctrlKey property of the mouse click event
object is what you want.

element.observe('click', function(event) {
if (event.ctrlKey) {
// Something cool here
}
}

https://developer.mozilla.org/en/DOM/event.ctrlKey

If you're looking to receive an event (separate from the click) when
the control key is pressed, that varies quite a bit by browser:
http://unixpapa.com/js/key.html

But my impression is that you're just looking for it when the mouse is
clicked, which is much more reliable.

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

On Aug 25, 12:09 am, Ooypunk  wrote:
> Hi,
>
> I was looking for a way to capture a mouse-click plus ctrl-button. As
> I am using Prototype now for some time (it's great!), I thought
> Prototype could help me with this too.
> Sure, the manual is clear enough of how to capture a mouse-click event
> (that works fine here), but how about the ctrl-button? According to
> the manual, there's a list of key codes to be used (KEY_DOWN, for
> example), but there is no KEY_CTRL and there is nowhere to be found
> how they should be used.
> It says it's self explanatory, but for me it isn't. :(
>
> I think I can get it to work with event.ctrlKey, but I have a feeling,
> this is not the way.
>
> Thanks in advance.
>
> Ooypunk
>
> PS. I hope I made my problem clear enough, I know I'm not very good at
> explaining, especially because english is not my mother tongue.
--~--~-~--~~~---~--~~
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: too much recursion when try to use Ajax.Request repeatly

2009-08-25 Thread T.J. Crowder

Hi,

You're rescheduling the function right away without waiting for the
Ajax call to complete.  I can't say I've seen that specific error, but
if the call takes more than a second (which is perfectly likely),
you'll start getting things stacking up quite quickly.  If you move
your rescheduling `setTimeout` call into the onComplete callback,
it'll get scheduled for a second after the last call completed, which
is probably more appropriate.

There are some other things you might consider:

1. Using the onSuccess callback rather than onComplete. onComplete is
appropriate for your rescheduling call, but onSuccess is where you
should be updating the div.

2. Using `String#startsWith`[1] rather than a regex to match "Error"
at the beginning of the response text, since the matching isn't
complicated.

[1] http://prototypejs.org/api/string/startsWith

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


On Aug 25, 7:52 pm, sddeals  wrote:
> What I'm trying to do is let the page make ajax request every second
> to get the latest status from ajax.php however I got a "too much
> recursion" error in the javascript. Any ideas? Thanks a lot!
>
> 
> function displayMSAStatus()
> {
>
>         var url="Ajax.ashx";
>         var params="do=MSAStatus";
>         var myAjax = new Ajax.Request
>         ( url,
>
>             {
>                 method: 'get',  parameters: params ,
>                         onComplete: function(response)
>                         {
>                             var el = document.getElementById('MSAStatusDiv');
>
>                             var re = /^Error/;
>
>                             if (!response.responseText.match(re))
>                             {
>                                         el.innerHTML = response.responseText;
>
>                                 }
>
>                 }
>         }
>         );
>
>         setTimeout(displayMSAStatus, 1000);
>
> }
>
> setTimeout(displayMSAStatus, 1000);
>
> 
> 
> 
>         setTimeout(displayStatus(vthis), 1000);
>
> }
>
> displayStatus(document.getElementById('statusDiv'));
>
> 
> 
> 
--~--~-~--~~~---~--~~
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: KEY_DOWN event

2009-08-25 Thread T.J. Crowder

Hi,

> Only thing left for me to complain is that I still don't know what
> names like KEY_DOWN are for...

They're for the keyboard events; see the link in my previous post.

> ...and that
> there's nothing in the manual (hint).

Isn't there?[1, fourth paragraph]  But by all means, feel free to post
a documentation ticket to Lighthouse with a patch in markdown format,
contributions are welcome. :-) Details.[2]

[1] http://prototypejs.org/api/event
[2] http://prototypejs.org/contribute
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 25, 1:07 pm, Ooypunk  wrote:
> OK, then I'll go with that. Thanks!
>
> Only thing left for me to complain is that I still don't know what
> names like KEY_DOWN are for, or how they should be used, and that
> there's nothing in the manual (hint).
>
> On Aug 25, 11:37 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > If you want to know whether the control key was down when the mouse
> > was clicked, then yes, the ctrlKey property of the mouse click event
> > object is what you want.
>
> >     element.observe('click', function(event) {
> >         if (event.ctrlKey) {
> >             // Something cool here
> >         }
> >     }
>
> >https://developer.mozilla.org/en/DOM/event.ctrlKey
>
> > If you're looking to receive an event (separate from the click) when
> > the control key is pressed, that varies quite a bit by 
> > browser:http://unixpapa.com/js/key.html
>
> > But my impression is that you're just looking for it when the mouse is
> > clicked, which is much more reliable.
>
> > HTH,
> > --
> > T.J. Crowder
> > tj / crowder software / com
> > Independent Software Engineer, consulting services available
>
> > On Aug 25, 12:09 am, Ooypunk  wrote:
>
> > > Hi,
>
> > > I was looking for a way to capture a mouse-click plus ctrl-button. As
> > > I am using Prototype now for some time (it's great!), I thought
> > > Prototype could help me with this too.
> > > Sure, the manual is clear enough of how to capture a mouse-click event
> > > (that works fine here), but how about the ctrl-button? According to
> > > the manual, there's a list of key codes to be used (KEY_DOWN, for
> > > example), but there is no KEY_CTRL and there is nowhere to be found
> > > how they should be used.
> > > It says it's self explanatory, but for me it isn't. :(
>
> > > I think I can get it to work with event.ctrlKey, but I have a feeling,
> > > this is not the way.
>
> > > Thanks in advance.
>
> > > Ooypunk
>
> > > PS. I hope I made my problem clear enough, I know I'm not very good at
> > > explaining, especially because english is not my mother tongue.
--~--~-~--~~~---~--~~
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: can I get a list of event listeners on an element?

2009-08-26 Thread T.J. Crowder

Hi,

Prototype doesn't have an official API call that gives you the event
handlers for an element. If you look at the source, it's fairly easy
to get them (in particular the stopObserving source is helpful), but
in a way that's undocumented and subject to change. (It changed quite
a bit between 1.6.0 and 1.6.1, for instance.)

It may well not be appropriate to move an event handler from one
element to another.  Consider this:

function foo(container) {
container.down('.flargle').observe('change', function(event) {
if (this.value.length == 0) {
container.addClassName('error');
} else {
container.removeClassName('error');
}
});
}

If you clone the container, including its flargle element, the handler
will not function as expected -- it'll update the original container,
not the new one.  Now, I'm not saying that's a smart way to implement
that function, but I suspect there's a more realistic version of this
scenario (a corrolation between the observed element and some data
bound to the handler function in some way, in this case via a closure)
that I just didn't come up with on first thought.

Now, if you're in control of the code and know things like that aren't
being done, you could safely transfer the event handlers to cloned
elements.  But I wonder if refactoring (perhaps refactoring involving
event delegation) could obviate the need for doing this...

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


On Aug 25, 10:45 pm, Kevin Porter  wrote:
> Hi,
>
> Can I get a list of registered listeners/observers on an element?
>
> What I'm trying to do is dynamically replace an element with another
> element, but want to preserve the events.
>
> I don't want to resort to something like:
>
> new_element.onclick = old_element.onclick;
>
> as the prototype docs advise against using .onclick, .onmouseover etc.
>
> If prototype doesn't provide a way to do this, is there a bare JS way to
> do it (ie to get a list of events that were registered with
> addEventListener)? I googled but couldn't find this.
>
> regards,
>
> - Kev
>
> --
> Kevin Porter
> Advanced Web Construction 
> Ltdhttp://webutils.co.ukhttp://billiardsearch.nethttp://9ballpool.co.uk
>
> AJAX Blackjack - real-time multi-player blackjack game with no flash, java or 
> software downloads required -http://blackjack.webutils.co.uk
--~--~-~--~~~---~--~~
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 requests again

2009-08-26 Thread T.J. Crowder

Alex,

> 1. The element that triggered the call

What element?  Ajax calls can be initiated by any code, anywhere, and
don't necessarily have anything to do with any element "triggering"
them.  For example:

function pollForData() {
new Ajax.Request(pollurl, {
onSuccess: function(resp) {
doSomethingWithTheData(resp);
},
onComplete: function() {
window.setTimeout(pollForData, pollForDataInterval);
}
});
}
document.observe("dom:loaded", function() {
window.setTimeout(pollForData, pollForDataInterval);
});

There's no element associated with the call. Even in cases where there
is (a request triggered by a button click, for instance), we don't
pass that element into Ajax.Request in any defined way, so there's no
defined way for you to get it.

I think your requirement is at a level above Ajax.Request and
Ajax.Updater, and that you should put your own infrastructure in place
for it. For example:

var MoreAjax = {
react: function(element, url, options) {
var completeCallback;

element = $(element);
element.disable();
if (!options) options = {};
completeCallback = options.onComplete;
options.onComplete = function() {
element.enable();
if (completeCallback) {
completeCallback.apply(undefined, arguments);
}
};
}
};

That defines an explicit way for you to say "this call was triggered
by this element" and it provides automatic element disabling/
enabling.  So in a click handler:

$('mybutton').observe('click', function(event) {
event.stop();
MoreAjax.react(this, 'myurl', {
parameters: this.up('form').serialize({hash: true}),
onSuccess: function(resp) {
// Some nifty thing
}
});
});

Voila, the button is disabled during the request and enabled when it's
done.

I'm sure that function as written (er, dashed off) is completely wrong
for what you're trying to do, it just illustrates the idea.

In my apps, I never use Ajax.Request or Ajax.Updater directly.  I
always have wrappers that factor out the complexity in ways
appropriate to the application.

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


On Aug 26, 9:25 am, "Alex McAuley" 
wrote:
> Really?
>
> I thought the explination was a simple one.
>
> To recap
>
> A global way of knowing what is going on inside Ajax requests including.
>
> 1. The element that triggered the call
> 2. The container (if Ajax.Updater) the response is going to.
>
> Yes i have looked at Responders and i am using them now to lock (disable)
> input elements but as i cannot get the element that triggered the call i
> have to lock the whole document which is not neccesary and slow - it would
> be better to find the parent or inputs above the callee and lock them while
> the request is going on (to stop people pushing the button twice etc etc)
> then unlock on onComplete.
>
> My way is working fine at the moment ... but ... it would be quicker and
> more efficient if i could in some way get the nodes/elements i desire on a
> global basis as part fo the framework and not hacked ontop of it.
>
> Hope this clears things up a bit
>
> Alex Mcauleyhttp://www.thevacancymarket.com
>
>
>
> - Original Message -
> From: "Timo" 
> To: "Prototype & script.aculo.us" 
> Sent: Tuesday, August 25, 2009 4:11 PM
> Subject: [Proto-Scripty] Re: Ajax requests again
>
> > On 20 Aug., 17:15, Alex Mcauley 
> > wrote:
> >> earlier on in the month i posted on how to do some things with Ajax
> >> requests genericaly like adding a loading message to all requests and
> >> i got a couple of responses but not many.
>
> >> I've been giving it alot of thought and i cam up with addMethods as a
> >> way to add some things to the Ajax Class...
>
> >> Could anyone give me an example of how to do this with addMethods -
> >> just a hello world will do then i can take it from there
>
> > I am not sure I understand what you are trying to achieve (and I
> > couldn't find the older topic you mention),
> > but did you look at Ajax.Responders? [http://www.prototypejs.org/api/
> > ajax/responders]
>
> > Timo
--~--~-~--~~~---~--~~
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 requests again

2009-08-26 Thread T.J. Crowder

Alex,

> 1. Element that triggered the call (if any)

"if any" doesn't make any difference to the question -- again, you
can't get that information from Ajax.Request or Ajax.Updater, because
it's not passed into them (whether it exists or not). You can only get
that information if you pass it into something of your own.

Sorry if I'm completely missing what you're talking about, but I think
a wrapper solution is your best bet.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 26, 9:53 am, "Alex McAuley" 
wrote:
> My mistake...
>
> i meant.
>
> 1. Element that triggered the call (if any)
> 2. Element receiving the response (if any)
>
> Alex Mcauleyhttp://www.thevacancymarket.com
>
>
>
> - Original Message -
> From: "T.J. Crowder" 
> To: "Prototype & script.aculo.us" 
> Sent: Wednesday, August 26, 2009 9:47 AM
> Subject: [Proto-Scripty] Re: Ajax requests again
>
> Alex,
>
> > 1. The element that triggered the call
>
> What element?  Ajax calls can be initiated by any code, anywhere, and
> don't necessarily have anything to do with any element "triggering"
> them.  For example:
>
>     function pollForData() {
>         new Ajax.Request(pollurl, {
>             onSuccess: function(resp) {
>                 doSomethingWithTheData(resp);
>             },
>             onComplete: function() {
>                 window.setTimeout(pollForData, pollForDataInterval);
>             }
>         });
>     }
>     document.observe("dom:loaded", function() {
>         window.setTimeout(pollForData, pollForDataInterval);
>     });
>
> There's no element associated with the call. Even in cases where there
> is (a request triggered by a button click, for instance), we don't
> pass that element into Ajax.Request in any defined way, so there's no
> defined way for you to get it.
>
> I think your requirement is at a level above Ajax.Request and
> Ajax.Updater, and that you should put your own infrastructure in place
> for it. For example:
>
>     var MoreAjax = {
>         react: function(element, url, options) {
>             var completeCallback;
>
>             element = $(element);
>             element.disable();
>             if (!options) options = {};
>             completeCallback = options.onComplete;
>             options.onComplete = function() {
>                 element.enable();
>                 if (completeCallback) {
>                     completeCallback.apply(undefined, arguments);
>                 }
>             };
>         }
>     };
>
> That defines an explicit way for you to say "this call was triggered
> by this element" and it provides automatic element disabling/
> enabling.  So in a click handler:
>
>     $('mybutton').observe('click', function(event) {
>         event.stop();
>         MoreAjax.react(this, 'myurl', {
>             parameters: this.up('form').serialize({hash: true}),
>             onSuccess: function(resp) {
>                 // Some nifty thing
>             }
>         });
>     });
>
> Voila, the button is disabled during the request and enabled when it's
> done.
>
> I'm sure that function as written (er, dashed off) is completely wrong
> for what you're trying to do, it just illustrates the idea.
>
> In my apps, I never use Ajax.Request or Ajax.Updater directly.  I
> always have wrappers that factor out the complexity in ways
> appropriate to the application.
>
> FWIW!
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Aug 26, 9:25 am, "Alex McAuley" 
> wrote:
> > Really?
>
> > I thought the explination was a simple one.
>
> > To recap
>
> > A global way of knowing what is going on inside Ajax requests including.
>
> > 1. The element that triggered the call
> > 2. The container (if Ajax.Updater) the response is going to.
>
> > Yes i have looked at Responders and i am using them now to lock (disable)
> > input elements but as i cannot get the element that triggered the call i
> > have to lock the whole document which is not neccesary and slow - it would
> > be better to find the parent or inputs above the callee and lock them
> > while
> > the request is going on (to stop people pushing the button twice etc etc)
> > then unlock on onComplete.
>
> > My way is working fine at the moment ... but ... it would be quicker and
> > more efficient if i could in 

[Proto-Scripty] Re: stopping the PeriodicalExecuter

2009-08-27 Thread T.J. Crowder

Hi,

> I've searched high & low for this but I haven't been able to dig
> anything specific up about stopping the PeriodicalExecuter.

Really?[1]

[1] http://prototypejs.org/api/periodicalExecuter
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 26, 10:02 pm, plo  wrote:
> Hey Everybody,
>
> I've searched high & low for this but I haven't been able to dig
> anything specific up about stopping the PeriodicalExecuter.  I've seen
> many examples that stop the PeriodicalExecuter within the same line
> that it's called, but what about from another function?  For example,
> I have the PeriodicalExecuter calling another function:
>
> new PeriodicalExecuter(function(pe) {outsideFunction();}, 3);
>
> Is it possible to call pe.stop(); from another function?
>
> Any help would be greatly appreciated.
>
> Cheers.
--~--~-~--~~~---~--~~
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: How can I replace a fx with a method call on an obj instead of passing the obj to the fx

2009-08-27 Thread T.J. Crowder

Hi,

Yes, JavaScript objects can have method-like things. This statement:

obj.doSomething();

...does two things:

1. It looks up the property 'doSomething' on the object 'obj'.

2. If the value is a function, it calls the function and sets its
context (the `this` value inside the function) to 'obj'. (If the value
isn't a function, it throws an error.)

Taken together, these two things make it seem like JavaScript has
methods.  (It doesn't, but its functions are so powerful that they can
do what methods do -- and plenty more besides.)

So that means that to do what you're talking about, you must do two
things:

1. Make doSomething a property of obj.
2. Have doSomething work with `this` rather than with an argument
passed in.

More about JavaScript's mythical methods in my incredibly anemic
programming blog:
http://blog.niftysnippets.org/2008/03/mythical-methods.html

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


On Aug 26, 8:31 pm, Nik  wrote:
> Hello, say I have this function doSomething();
> I have always been passing it an obj (prototype object) to return
> something I want from the obj.
> so it goes like this: doSomething(obj);
>
> can I do it more like Rails, that is to say, like:
> obj.doSomething()?
>
> For instance,
> function pulse(obj){
>   Effect.pulsate(obj, {pulses:4, duration:0.5});
>
> }
>
> I normall do :
> obj = $('some_div');
> pulse(obj);
>
> How can I do it like:
> obj.pulse()?
>
> 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-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: Detecting failure

2009-08-27 Thread T.J. Crowder

Hi,

I'm surprised it works in IE7, on the face of it it should run into
the Same Origin Policy[1] (unless, of course, your page is loaded from
http://search.yahooapis.com).  On the off-chance that Yahoo was
implementing the new CORS[2] stuff, I tried it, but with IE7 I got an
Access Denied exception (which is as expected).  With FF3.5 and
Chrome2 I got blank responses.  (And if Yahoo were implementing CORS,
FF3.5 should work, as it supports that -- I don't think IE7 does.)

[1] http://en.wikipedia.org/wiki/Same_origin_policy
[2] http://www.w3.org/TR/access-control/
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Aug 27, 3:49 am, emooney  wrote:
> Alex,
> When I try this code, the only line I replace is:
>
> var request=new Ajax.Request('./load_test.html?x=2345',{
>
> for this
>
> var request=new Ajax.Request('http://search.yahooapis.com/
> ImageSearchService/V1/imageSearch?
> appid=YahooDemo&query=Madonna&output=json',{
>
> I get "no response text" in FF 3.5.2 and in Chrome 3.0.195.6, but it
> works in IE 7.
> I've been trying to get this to work for a couple of days now and
> don't know what else to try.
>
> Thanks,
> Eric
>
> On Aug 7, 4:14 am, "Alex McAuley" 
> wrote:
>
>
>
> > Just change the script to adjust a little
>
> >http://pastie.org/575168
>
> > HTH
>
> > Alex Mcauleyhttp://www.thevacancymarket.com
>
> > - Original Message -
> > From: "Krish" 
> > To: "Prototype & script.aculo.us" 
> > Sent: Friday, August 07, 2009 5:18 AM
> > Subject: [Proto-Scripty] Detecting failure
>
> > > This maybe anewbiequestions but I am having some trouble with this.
>
> > > 1. I would like use prototype to make an ajax call to load a page ..
> > > grab a particular div target_div
> > > from that page and stick it into a destination div dest_div on this
> > > page.
>
> > >   $("#dest_div").load("load_test.html #target_div img");
>
> > > Is there something similar for prototype?
>
> > > 2. If load fails, I want to put some default content that can be on
> > > this page.
> > > I am having detecting load failure. The exception handlers in
> > > makeAjaxCall don't work properly.
> > > Whats the best way to detect failure in a cross browser way?
>
> > > Thanks in advance,
> > > Kris
>
> > > --- my test page
> > > 
> > > 
>
> > > 
> > > 
>
> > > function makeAjaxCall()
> > > {
> > > alert();
> > > new Ajax.Request('./load_test.html?x=2345',
> > >   {
> > > method:'get',
> > > onSuccess: function(transport){
> > >   var response = transport.responseText || "no response text";
> > >   alert("Success! \n\n" + response);
> > > },
> > > //onFailure: function(){ alert('Failure: Something went wrong...') }
> > > onException: function(){ alert('Exception: Something went
> > > wrong...') }
> > >   });
> > > }
> > > 
> > > 
>
> > > 
> > > 
> > >  original page.
> > > 
> > > 
--~--~-~--~~~---~--~~
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: Strict mode?

2009-08-27 Thread T.J. Crowder

Hi Richard,

Strict in what sense?
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 27, 12:04 pm, Richard Heyes  wrote:
> Hi,
>
> I'm trying to get my graphing library (RGraph) working in conjunction
> with Prototype and to start I'm wondering if Prototype uses a
> "strict"mode?
>
> 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-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: change DOM on select option

2009-08-28 Thread T.J. Crowder

Hi,

>$('#englisch').onfocus = function() {

$() accepts IDs, not selectors -- I'm guessing you're coming from
jQuery, which is different.

Also, to hook an event, you're better off using Element#observe[1]
rather than assigning to an attribute.

It's well worth taking an hour or two and reading the Prototype API[2]
from beginning to end. It really only takes an hour or two, and it
will save you a lot more time than that in the long run.

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

On Aug 27, 1:47 pm, "clicforw...@googlemail.com"
 wrote:
> Hello,
>
> I need to change content of a dom element on select a option.
> I tried to handel it like this:
>
> 
>
>  document.observe("dom:loaded", function() {
>    $('#englisch').onfocus = function() {
>      $('div').replace('<p>This is English</p>');}
> });
>
> 
>
> 
> 
> Select Language
> Englisch
> German
> 
>
> But nothing happens.
> Can anyone help me out?
>
> 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-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: change DOM on select option

2009-08-28 Thread T.J. Crowder

Erm, I kind of forgot the links:

[1] http://prototypejs.org/api/element/observe
[2] http://prototypejs.org/api

-- T.J.

On Aug 28, 9:56 am, "T.J. Crowder"  wrote:
> Hi,
>
> >    $('#englisch').onfocus = function() {
>
> $() accepts IDs, not selectors -- I'm guessing you're coming from
> jQuery, which is different.
>
> Also, to hook an event, you're better off using Element#observe[1]
> rather than assigning to an attribute.
>
> It's well worth taking an hour or two and reading the Prototype API[2]
> from beginning to end. It really only takes an hour or two, and it
> will save you a lot more time than that in the long run.
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / comwww.crowdersoftware.com
>
> On Aug 27, 1:47 pm, "clicforw...@googlemail.com"
>
>
>
>  wrote:
> > Hello,
>
> > I need to change content of a dom element on select a option.
> > I tried to handel it like this:
>
> > 
>
> >  document.observe("dom:loaded", function() {
> >    $('#englisch').onfocus = function() {
> >      $('div').replace('<p>This is English</p>');}
> > });
>
> > 
>
> > 
> > 
> > Select Language
> > Englisch
> > German
> > 
>
> > But nothing happens.
> > Can anyone help me out?
>
> > 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-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: Copy event observer

2009-08-28 Thread T.J. Crowder

Hi,

Check out this recent thread on this topic:
http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/e5286fee9ac18a40

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

On Aug 27, 7:26 pm, louis w  wrote:
> I have a bit of javascript that replaces a text field with a bunch of
> html and another text field. problem is, if the original input has an
> event observer on it it gets thrown away,
>
> Is it possible  to see if an element has an event observer and copy it
> to another element?
>
> 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-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: Prototype and Cross Domain Access

2009-08-28 Thread T.J. Crowder

The work you're talking about is CORS[1], from the W3C.  It's
implemented in Firefox 3.5[2] and Safari 4[3].

[1] http://www.w3.org/TR/access-control/
[2] https://developer.mozilla.org/En/HTTP_access_control
[3] 
http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/XHR.html

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

On Aug 28, 1:03 pm, david  wrote:
> Hi emooney,
>
> You're exemple were launch from your computer locally, not from an
> external website.
> I try your exemple and it works in IE6 & FF3.5
>
> But in real website, that shouldn't work for both and all other
> browser, because AJAX should be submitted to the same domain/subdomain
> as the document domain/subdomain. There is some work to specify this
> need, but I don't know if browser implement it at all.
> I remember that I saw a prototype extension (think it was for 1.5)
> that implement cross domain request, but I did not know if it is
> ported to prototype 1.6.
>
> Go and have a look athttp://scipteka.comto see if any exist, or try
> googling.
>
> --
> david
>
> On 27 août, 20:20, emooney  wrote:
>
>
>
> > I'm working on a RSS News Feed app and I want to be able to update my
> > news feeds through the Prototype.Request object. Bringing them in
> > using JSON seems like a perfect solution because I can access the data
> > as a javascript object. But I'm having trouble just bringing the data
> > in.
>
> > I'm reading that this isn't a limitation with Prototype, but a
> > security 'feature' at the browser level. The strange this though is I
> > can get it to work in IE6 and IE7, but not FF 3.5.2 and Chrome xxx.
>
> > Here is a link to my findings. Includes an image of what I'm bringing
> > back in IE as well as the code that created 
> > this.https://sites.google.com/site/ericstestsite1/
>
> > If someone could help me understand what's happening that would be
> > great.
>
> > Thanks,
> > Eric
--~--~-~--~~~---~--~~
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: More useful clone method

2009-08-28 Thread T.J. Crowder

Interesting you should ask that question:
http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/e5286fee9ac18a40/53ff3b0aec0b293d#53ff3b0aec0b293d

-- T.J. :-)

On Aug 28, 8:24 pm, Matt Foster  wrote:
> Scenario for you...
>
> What if I have a parent object that I use deepClone on and it has
> child elements that have event handlers, is this functionality
> preserved with the method?
>
> On Aug 26, 1:18 pm, watermark86  wrote:
>
>
>
> > Well, I have x-mas presents.  I give it "it works for me" status.
> > I've tested this bit of code with firefox and it seems to work with
> > every scenario I can throw at it.  I'm sure there is room for speed
> > improvements and I know it doesn't conform to coding style, but it
> > works.  It would be great if prototype officially extended
> > Element.clone with this functionality.
>
> > deepClone: function(element) {
> >         var newElement = element.clone(true); //clone the node
>
> >         //stop observing all events on the newElement (IE (and some
> > others?) copies them)
> >         newElement.stopObserving();
>
> >         //copy storage
> >         Element.getStorage(newElement);
> >         (Element.Storage[newElement._prototypeUID[0]]=new Hash
> > (Element.getStorage(element))).unset('prototype_event_registry');
>
> >         //copy the events on the parent
> >         if (!Object.isUndefined(registry = Element.retrieve(element,
> > 'prototype_event_registry'))) {
> >                 registry.each( function(pair) {
> >                         var eventName = pair.key, responders = pair.value;
> >                         responders.each( function(r) {
> >                                 Element.observe(newElement, eventName, 
> > r.handler);
> >                 });
> >                 });
> >         }
>
> >         //get all of the descendants
> >     var srcdecend = element.descendants();
> >     var dstdecend = newElement.descendants();
> >     var numdecend = srcdecend.length;
>
> >     //foreach of the descendants
> >     for(var i = 0; i < numdecend; ++i) {
> >         //stop observing all events on the newElement (IE (and some
> > others?) copies them)
> >                 dstdecend[i].stopObserving();
> >                 //copy storage
> >                 Element.getStorage(dstdecend[i]);
> >                 
> > (Element.Storage[dstdecend[i]._prototypeUID[0]]=Element.getStorage
> > (srcdecend[i]).clone()).unset('prototype_event_registry');
> >         //copy the events on each child to it's new corrisponding child
> >         var registry = Element.retrieve(srcdecend[i],
> > 'prototype_event_registry');
> >                 if (!Object.isUndefined(registry)) {
> >                         registry.each( function(pair) {
> >                                 var eventName = pair.key, responders = 
> > pair.value;
> >                                 responders.each( function(r) {
> >                                         Element.observe(dstdecend[i], 
> > eventName, r.handler);
> >                         });
> >                         });
> >                 }
> >     }
>
> >     return newElement;
> >   }
>
> > On Aug 26, 9:43 am, watermark86  wrote:
>
> > > 1.6.1rc3 added Element.clone (which calls cloneNode).
>
> > > On Aug 25, 5:46 pm, Matt Foster  wrote:
>
> > > > Good luck with this,  let us know if it works out.
>
> > > > Quick glance at your code I can see an obvious error...
>
> > > > >         var newElement = element.clone(true); //clone the node
>
> > > > Element doesn't have a clone method.  The native DOM element does have
> > > > a cloneNode method though.
>
> > > > --
>
> > > >http://positionabsolute.net
>
> > > > On Aug 25, 2:15 pm, watermark86  wrote:
>
> > > > > I'm using 1.6.1rc3 to have access to Element.storage.  I need to write
> > > > > a function that deep clones an element and copies the Element.observe
> > > > > events as well as the Element.Storage items with it.  I've managed to
> > > > > write the code that can copy one or the other.
>
> > > > > The problem comes in when I try to do both (copy the storage items and
> > > > > the events.)  I suppose due to Event.observe using the Element.storage
> > > > > item, I can't seem to have the items that I've stored with
> > > > > Element.store to copy while maintaining the Event.observe events that
> > > > > I've copied.
>
> > > > > I can copy the observe events or the element.store events, but not
> > > > > both.  Below is some terrible code for review.  Thanks for any help or
> > > > > insults.
>
> > > > > deepClone: function(element) {
> > > > >         //deep clone node
> > > > >         var newElement = element.clone(true); //clone the node
>
> > > > >         //stop observing because of IE BS
> > > > >         newElement.stopObserving();
>
> > > > >         //copy the item
> > > > >         var registry = Element.retrieve(element,
> > > > > 'prototype_event_registry');
> > > > >         if (!Object.isUndefined(registry)) {
> > > > >                 reg

[Proto-Scripty] Re: hide/show div id not working - HELP!

2009-08-31 Thread T.J. Crowder

Hi,

> $(document).ready(function(){
>
>  $(".bio_button").click(function(event) {   //when a user clicks on

Both of those look like jQuery, not Prototype.  Prototype's equivalent
of the jQuery ready function is the dom:loaded event[1]:

document.observe('dom:loaded', yourCallbackGoesHere);

Similarly, $()[2] looks up elements by ID, it does not search for them
by selector.  $$()[3] does that.

It may be worth your taking a step back and reading the Prototype API
[4] through from beginning to end.  It takes about an hour, and will
save you at least that much time across the life of your project
(heck, probably even in the coming week).

[1] http://prototypejs.org/api/document/observe
[2] http://prototypejs.org/api/utility/dollar
[3] http://prototypejs.org/api/utility/dollar-dollar
[4] http://prototypejs.org/api

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

On Aug 31, 1:48 am, Nelson Hernandez  wrote:
> I have a very simple script that is intended to show an employees
> biography on click, and hide all other biography's (since they occupy
> the same space).  I have two issues I can't resolve, and for the life
> of me can't figure out why.  I'm using Ruby on Rails and I have
> included the default javascrip which includes Prototype.  I'm testing
> in FireFox.
>
> Here's the code with comments for reference, exact problems detailed
> below:
>
> 
> $(document).ready(function(){
>
>  $(".bio_button").click(function(event) {   //when a user clicks on
> div with class bio_button, do:
>                 $(".bio").hide();                    //hide all divs that 
> have a
> class of "bio"
>                 var element = Event.element(event);    //get the div id for 
> the
> element clicked
>                 var id = element.id.substring(0,element.id.length-1);   
> //remove the
> last letter of that div id, which
>                                                                               
>                //
> corresponds to the div which contains the
>                                                                               
>                //
> biography text
>
>                 //alert(id);                  //used to make sure the 
> substring was
> working, it is.
>                 $(id).show();         //this doesn't work for some reason 
> HELP,
> please :(
>  });});
>
> 
> ...
> click to show Tims bio
> click to show Beths bio
> ...
> tim's awesome
> biography
> beth's awesome
> biography
>
> PROBLEM(s) (using a click on tim as example):
> 1) The above does indeed hide all bio's, and will output an alert of
> "tim" if I click on tim.  However, it won't change the display style
> to show.
>
> 2) In the javascript, if I replace $(id).show(); with $("tim").show();
> it still doesn't workunless I use tim as one of the class
> definitions in the html instead of a div id.  If I specify tim as a
> class, and use "tim" explicitly in the javascript, it works perfectly.
>
> Sorry if this is the wrong forum, i'm losing my mind over what seems
> should be very simple.  Thanks to anyone that can help.
>
> -Nelson
--~--~-~--~~~---~--~~
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: onchange event delegation on IE

2009-08-31 Thread T.J. Crowder

Hi Mona,

Have you considered using Form.Observer[1] instead of events?

[1] http://prototypejs.org/api/timedObserver/form-observer
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Aug 31, 10:07 am, Mona Remlawi  wrote:
> Hello Prototypers,
>
> I am currently in the process of implementing events delegation on HTML forms.
> As you might know, IE does not bubble the onchange event :( and i find
> that the onblur is a poor and a high maintenance alternative.
> Can anyone propose a neater solution?
> The forms i'm delegating events on have repeatable sections, so that's
> why i would insist on delegation.
>
> Thanks in advance
>
> cheers
>
> --
> mona
--~--~-~--~~~---~--~~
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: prototype dom:loaded in IE 6 and 7 shows race conditions on certain environments?

2009-09-01 Thread T.J. Crowder

Hi,

Can you pick up with #3 on this list:

http://proto-scripty.wikidot.com/faq#xyzprob

...and post the result (unless you figure it out in the meantime)?
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Aug 31, 2:35 pm, Alexander Knöller 
wrote:
> Hi there.
>
> We register some calls for the dom:loaded-event in the HTML-BODY.
> Depending on the runtime environment (hardware/Windows version)
> sometimes the page produces in both IE-Versions JS-errors, because
> some or all registered functions were never called and so some
> references are missing for later actions.
> The more the JS-Script-node for the event registration  is pushed
> upward in the html-source, the less probable this error occurs until
> it disappears completely for our test environment.
> Our guess is, the dom:loaded event is fired before the event
> registration-JS-code has finished.
>
> Of course a workaround is to put this kind of event registration in
> the HEAD-section, but I did not find a direct statement in the
> documentation mentioning this as a requirement.
>
> Does anybody know about this effect/problem?
>
> Thanx
--~--~-~--~~~---~--~~
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: Safari 4 public beta issue

2009-09-01 Thread T.J. Crowder

Hi,

Can you pick up with Step #3 from here[1] and post the result?  If
it's really a bug, that's the first step to reporting it[2].

[1] proto-scripty.wikidot.com/faq#xyzprob
[2] http://prototypejs.org/contribute

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

On Aug 31, 8:46 pm, az  wrote:
> I'm using AjaxUpload script from here:http://valums.com/ajax-upload
>
> when i try to use it i get this error:
> prototype.js (line 1611)Error: NO_MODIFICATION_ALLOWED_ERR: DOM
> Exception 7
>
> also tried using the new version of prototype - no difference.
--~--~-~--~~~---~--~~
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] Prototype 1.6.1 Released!

2009-09-01 Thread T.J. Crowder

In case anyone missed it:

http://prototypejs.org/2009/9/1/prototype-1-6-1-released

Kudos to the team!

And separate kudos to Tobie & Andrew, who now officially take up the
reins:
http://prototypejs.org/2009/9/1/core-team-update-andrew-and-tobie-take-the-reins

Congrats!
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.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 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: array.indexOf fails sometimes in IE8

2009-09-02 Thread T.J. Crowder

Hi,

You're probably running into equality vs. identity (loose equality vs.
strict equality).  The emerging standard for what Array#indexOf is
supposed to do uses strict equality (===), not ==, whereas previously
Prototype used loose equality.  This is an issue with strings because

"mpg" !== new String("mpg")

even though

"mpg" == new String("mpg")

Oddly, I can't replicate the behavior you're seeing on IE8 if I have
Prototype loaded, but I can easily do so without it by calling
isVideoFile(new String("mpg")).

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

On Sep 1, 11:14 pm, Mojito  wrote:
> My function works as expected in all non-IE browsers.  But when I try
> it in IE8, it doesn't scan the array correctly.  Any easy workaround
> rather than implementing my own indexOf()?
>
> +
>
> function isVideoFile(extension)
> {
>     extension = extension.strip();
>     alert(typeof extension);
>     alert(extension);
>     alert(['3g2', '3gp', 'asf', 'asx', 'avi', 'flv', 'mkv', 'mov',
>             'mp4', 'mpg', 'mpeg', 'qt', 'rm', 'vob', 'wmv'].indexOf
> (extension));
>
> }
>
> +
>
> The output when I pass in 'mpg':
>
> 1) string
> 2) mpg
> 3) -1
--~--~-~--~~~---~--~~
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: prototype dom:loaded in IE 6 and 7 shows race conditions on certain environments?

2009-09-02 Thread T.J. Crowder

Hi,

That's not a "...pared-down, self-contained example..."  Please have a
look at Step 3 at the link[1] again, there's a _reason_ for going
through the process of creating the pared-down example.

[1] http://proto-scripty.wikidot.com/faq#xyzprob
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 2, 11:21 am, Alexander Knöller 
wrote:
> Hi.
>
> Until tomorrow you can reproduce it with IEs and fitting hardware/
> software-environments. (On a virtualBox-installation on a macosX I
> could not reproduce it, on an Ubuntu with VMWare a colleage could,
> another could with a native Installation):
> Tryhttp://www.jungstil.de/akn/bundle.htm?bu=2023439
> several times.
> Each time try to click "Artikel auf den Wunschzettel".
> Often it works. Sometimes you get an JS-Error because of missing
> references.
>
> From tomorrow morning on there will be a fix, which executes the JS-
> Code directly instead of registering it as a function for
> "dom:loaded".
>
> On Sep 1, 9:37 am, "T.J. Crowder"  wrote:
>
>
>
> > Hi,
>
> > Can you pick up with #3 on this list:
>
> >http://proto-scripty.wikidot.com/faq#xyzprob
>
> > ...and post the result (unless you figure it out in the meantime)?
> > --
> > T.J. Crowder
> > tj / crowder software / comwww.crowdersoftware.com
>
> > On Aug 31, 2:35 pm, Alexander Knöller 
> > wrote:
>
> > > Hi there.
>
> > > We register some calls for the dom:loaded-event in the HTML-BODY.
> > > Depending on the runtime environment (hardware/Windows version)
> > > sometimes the page produces in both IE-Versions JS-errors, because
> > > some or all registered functions were never called and so some
> > > references are missing for later actions.
> > > The more the JS-Script-node for the event registration  is pushed
> > > upward in the html-source, the less probable this error occurs until
> > > it disappears completely for our test environment.
> > > Our guess is, the dom:loaded event is fired before the event
> > > registration-JS-code has finished.
>
> > > Of course a workaround is to put this kind of event registration in
> > > the HEAD-section, but I did not find a direct statement in the
> > > documentation mentioning this as a requirement.
>
> > > Does anybody know about this effect/problem?
>
> > > Thanx
--~--~-~--~~~---~--~~
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: Element#Storage

2009-09-02 Thread T.J. Crowder

Is that a question? An observation? A bug report? What?
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 2, 11:10 am, Yaffle  wrote:
> after Element removed from dom Element.Storage[uid] still exist?
--~--~-~--~~~---~--~~
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: array.indexOf fails sometimes in IE8

2009-09-02 Thread T.J. Crowder

Hi,

There's a difference between primitives ("mpg") and objects (new String
("mpg")). The == operator allows for a *lot* of type coercion; the ===
operator is _supposed_ to be a strict equality operator including type
and so "mpg" !== new String("mpg") because they're different types.
See section 11.9.6 of the spec[1] for details.

[1] http://www.ecma-international.org/publications/standards/Ecma-262.htm
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 2, 4:56 pm, enigment  wrote:
> Hmmm, even outside the indexOf() question, this is a bit creepy to me.
> I hadn't previously tested, but these are all true, at least in
> Firefox 3.5 and IE8:
>         "mpg" === "mpg"
>         "mpg" !== new String("mpg")
>         new String("mpg") !== new String("mpg")
>         new String("mpg") != new String("mpg")
>
>         new Number(1) == 1
>         new Number(1) !== 1
>         new Number(1) != new Number(1)
>
>         [] != []
>         new Array() != new Array()
>         new Array() != []
>
>         new Object() != {}
>
> Is it an identity test -- is it the same actual object? -- maybe
> coupled with the way various types of data are stored internally? It
> looks like once the string "mpg" has been created, another literal
> "msg" is the same, but a new String object containing the same literal
> is not. The analogous tests with Number, Array, and Object values
> indicate somewhat different behavior, but since it's consistent across
> IE and Firefox, it seems inherent in the language.
>
> Can anyone explain, not *how* this actually works, but the logic
> behind it?
>
> Thanks,
> e
>
> On Sep 2, 4:28 am, "T.J. Crowder"  wrote:
>
>
>
> > You're probably running into equality vs. identity (loose equality vs.
> > strict equality).
--~--~-~--~~~---~--~~
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: clonePosition not behaving accurately on spans

2009-09-03 Thread T.J. Crowder

Hi,

This probably isn't the answer, but FWIW, those IDs are invalid. IDs
cannot start with a digit.[1]

It'd be nice if correcting them happened to fix it, but I tend to
doubt it. :-)

[1] http://www.w3.org/TR/html401/types.html#type-name
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 3, 3:24 am, Tiago  wrote:
> Hello,
>
> I wrote the following HTML code:
>
> 
> 
> 
>
> 
> 
> 
>
> And I would like to place span #2 on the same position as span #1. I
> tried to run the following command:
>
> $('2').clonePosition($('1'));
>
> However, span #2 is placed a little below span #1 (2 pixels or so).
> Does anyone know why this happens? Is there anyway to correct this?
>
> It's worth noticing that the method clonePosition works accurately if
> I replace the spans by divs (or any other block element).
>
> Thanks a lot,
> Tiago
--~--~-~--~~~---~--~~
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: Element.setParent? Is there a core method instead I can use?

2009-09-04 Thread T.J. Crowder

Hi,

Leaving aside the question of whether conflating statements on one
line is a good idea, you can do all of it at once like so:

parent.appendChild(new Element('div', {'class': 'container'}));

you can even put text in the element:

parent.appendChild(new Element('div', {'class': 'container'}).update
('Text in element');

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

On Sep 3, 10:07 pm, dwp  wrote:
> Quite often I create large chunks of HTML in javascript and use the
> prototype new Element method. I like this method because you can chain
> it with other methods, and create clean readable code. However, after
> I create an element I usually want to append it to a parent element
> first thing. I can do this in two lines of code with appendChild, but
> that doesn't seem very "prototypish". My solution was to add a
> Element.setParent function. Is there a core method I can use that does
> this better, or is setParent the away to go? I looked at insert, but
> its the other way around parent to child.
>
> Example:
> var divPane          = new Element('div', {'class':'sv_panel' +
> this._className });
> var divContainer    = new Element('div',
> {'class':'container'}).setParent(divPanel);
> var divTitleBar       = new Element('div',
> {'class':'titlebar'}).setParent(divContainer).update("My Titlebar');
> 
>
> 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-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: Element.setParent? Is there a core method instead I can use?

2009-09-04 Thread T.J. Crowder

Sorry, there should be one more closing paren on the second example.

-- T.J.

On Sep 4, 8:37 am, "T.J. Crowder"  wrote:
> Hi,
>
> Leaving aside the question of whether conflating statements on one
> line is a good idea, you can do all of it at once like so:
>
> parent.appendChild(new Element('div', {'class': 'container'}));
>
> you can even put text in the element:
>
> parent.appendChild(new Element('div', {'class': 'container'}).update
> ('Text in element');
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / comwww.crowdersoftware.com
>
> On Sep 3, 10:07 pm, dwp  wrote:
>
>
>
> > Quite often I create large chunks of HTML in javascript and use the
> > prototype new Element method. I like this method because you can chain
> > it with other methods, and create clean readable code. However, after
> > I create an element I usually want to append it to a parent element
> > first thing. I can do this in two lines of code with appendChild, but
> > that doesn't seem very "prototypish". My solution was to add a
> > Element.setParent function. Is there a core method I can use that does
> > this better, or is setParent the away to go? I looked at insert, but
> > its the other way around parent to child.
>
> > Example:
> > var divPane          = new Element('div', {'class':'sv_panel' +
> > this._className });
> > var divContainer    = new Element('div',
> > {'class':'container'}).setParent(divPanel);
> > var divTitleBar       = new Element('div',
> > {'class':'titlebar'}).setParent(divContainer).update("My Titlebar');
> > 
>
> > 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-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: Favicon disappearing in Firefox?

2009-09-04 Thread T.J. Crowder

Firefox has *long* had favicon bugs. The symptom (and possibly the
underlying cause) seems to change with every release, but there's
usually a problem with them somewhere.

-- T.J.

On Sep 3, 4:46 pm, Walter Lee Davis  wrote:
> That's the odd thing. It was working, and now it's kinda working --  
> you see the favicon for a fraction of a second, then it disappears and  
> is replaced with the generic globe.
>
> Walter
>
> On Sep 3, 2009, at 11:34 AM, Alex McAuley wrote:
>
>
>
>
>
> > I had a similar issue with caching once with firefox.. i had to  
> > delete the
> > whole cache and it reverted the favicon back to the one i chose.
> > Alex Mcauley
> >http://www.thevacancymarket.com
> > - Original Message -
> > From: "Walter Lee Davis" 
> > To: 
> > Sent: Thursday, September 03, 2009 3:36 PM
> > Subject: [Proto-Scripty] Favicon disappearing in Firefox?
>
> >> I am seeing something on a site I'm developing that I've never seen
> >> before. The favicon appears briefly, then (watching in Firebug) the
> >> various Ajax requests run, and as soon as they do, the favicon
> >> disappears. Nothing in my Ajax callbacks is set to modify the head of
> >> the main page, they merely replace the content of certain DIVs on the
> >> page. I am using Firefox 2, my client is using Firefox 3.5 and sees
> >> the same thing.
>
> >> Safari shows the favicon just fine.
>
> >> I have the following line in the HEAD of the page:
>
> >> 
>
> >> and the file is at the specified location.
>
> >> Does this ring any bells for anyone?
>
> >> Thanks in advance,
>
> >> Walter
--~--~-~--~~~---~--~~
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: execution order in IE

2009-09-04 Thread T.J. Crowder

Hi JoJo,

I suspect there's some small (but important) piece of information or
understanding that you don't have, being a beginner, but we're
shooting a bit in the dark trying to identify it.

Can you create an example of the problem using one very simple HTML
file and (say) two script files?  (Three if you need it to make the
problem occur.)  Paste them in Pastie[1] and drop us a link here, and
we'll try to figure it out.

FWIW, I've never had a problem with files getting loaded and executed
out of order.  I find it very, very hard to believe that that's
actually happening (Alex, if you have a reference for your earlier
comment, please do share it), the number of sites that would break is
legion.

If that really _is_ happening, another way to solve it is to combine
all of your JavaScript files into one file as part of a build
process.  There are good reasons for doing that anyway; more here.[2]

[1] http://pastie.org
[2] http://proto-scripty.wikidot.com/prototype:tip-minimizing-download-times

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

On Sep 4, 7:17 am, JoJo  wrote:
> My classes are just class definitions.
>
> MYAPP.Class1= Class.create({...});
> MYAPP.Class2= Class.create({...});
>
> I don't create the objects until I get to main.js, which creates them
> after the window has loaded.  Why is IE7 not giving an error when I
> access MYAPP in Class1.js and Class2.js, but is giving an error when I
> access it in main.js? This native and function object talk just went
> straight over my head.  I am only a beginner to JS.
>
> On Sep 3, 10:51 pm, RobG  wrote:
>
>
>
> > On Sep 4, 3:43 pm, RobG  wrote:
>
> > > On Sep 4, 4:40 am, JoJo  wrote:
>
> > > > ^ great article!
>
> > > > Now I have another question.  Here is my new workflow in an attempt to
> > > > execute files in the correct order across all browsers.  It works in
> > > > IE8, but not in IE7.  In IE7 I get an error saying "object expected"
> > > > on line 2 of main.js.  This is not very descriptive; what does it
> > > > mean?
>
> > > > (1) include my global wrapper MYAPP.js:
>
> > > >     MYAPP = {class1: null, class2: null}
>
> > > MYAPP is an instance of the built-in Object object (i.e. a native
> > > object). Because it has not been declared, it doesn't exist until the
> > > code is executed.
>
> > That is, until that line of code is executed.
>
> > > > (2) include Class1.js (no instantiation)
> > > > (3) include Class2.js (no instantiation)
> > > > (4) include main.js:
>
> > > >     Event.observe(window, 'load', function() {
> > > >         MYAPP.class1  = new MYAPP.Class1();
>
> > > Even if MYAPP exists at this point, the above won't work: the only
> > > native objects that can be used as constructors are function objects.
> > > MYAPP is and native object, it can't be used as a constructor as it
> > > doesn't have an internal [[consruct]] method (functions do).
>
> > Ooops, you're actually calling MYAPP.Class1 as a constructor, hey
> > nasty. You say the other script files don't to any instantiation, so
> > how do the MYAPP.Class1 and 2 properties get set?
>
> > --
> > Rob
--~--~-~--~~~---~--~~
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: When to expect code changes to be added to Prototype.

2009-09-04 Thread T.J. Crowder

Hi,

The Lighthouse ticket should still be there.  If you filed the ticket,
you should be able to see it by searching for all tickets created by
you.  Hopefully that would shed light on the issue.

You've said there's a "fix" to Prototype...but what you describe is an
enhancement, isn't it?  Very big difference between enhancements and
fixes.  It may well be that the Core team didn't think that supporting
multiple expressions in that way was appropriate for the project.
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com


On Sep 4, 3:10 pm, FigglesKoy  wrote:
> There's a fix to Prototype that I've been waiting for a while to see.
> Specifically, that the Element.match method would support commas to
> support checking for multiple rules in a single call i.e. match
> ('DIV.aClass, DIV.bClass').  Thing is, this has been fixed online for
> a while, but it has never made it to a Prototype release and I'm not
> sure why.  The github commit is here (http://github.com/sstephenson/
> prototype/commit/afd74ce1c72a17666d8c9d86131463ad73cafe9e) and if I'm
> reading it correctly, its been there since November of last year.
> However, even in the latest 1.6.1 release, it is not present.  I can
> no longer find it on the lighthouse page though I did at one time.  I
> believe it was attached to milestone 1.6.0.4, which seems to not exist
> any more.  I can manually add the code in for now but if this won't be
> in subsequent releases, then I will have to remember to add it back in
> each time I upgrade.  So I guess I'm just looking for some explanation
> on how to know when/if some code commit will be added to a future
> release.  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-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.Updater - Sending form.serialize + other variables

2009-09-04 Thread T.J. Crowder

E.g.:

var data = $('myform').serialize(true);
data.more = "stuff";
new Ajax.Updater(id, url, {
parameters: data
    });
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 4, 4:56 pm, Daniel Rubin  wrote:
> Senthil Krishnamoorthy wrote:
> > Actually I want to pass form parameter as well as other my defined
> > parameters to the Ajax.Updater.  How do i do that.  Basically
> > Ajax.Updater is recognizing the either form.serialize or {} hash
> > parameters.
>
> > Anybody help me out how to pass the both in parameters option.
>
> Hi Senthil,
>
> there's an option "hash" [1] to Form.serialize () which -- when set to
> true -- returns a {}-Object that can be passed as params to
> Ajax.Updater.  Get that and alter it to suit your needs.
>
> [1]http://api.prototypejs.org/dom/form.html#serialize-class_method
>
> Have fun
> Daniel
>
>
>
> > regards,
> > Senthil Krishnamoorthy
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



  1   2   3   4   5   6   7   8   9   10   >