[Proto-Scripty] Re: event.element vs. $('element_id')
On Mar 27, 9:35 am, Hector Virgen djvir...@gmail.com wrote: [...] As for speed, I would imagine that event.element() is faster than $('object_id') because even.element() is just accessing a property, instead of searching the dom for a node. But I could be wrong on this :) Logic would say that you are. $() essentially a wrapper for getElementById, and since that function is fundamental to the DOM Core, it is likely highly optimised in browsers. Rather than having to search the DOM I expect the browser creates an indexed list of all elements with an ID and that getElementById will perform an indexed lookup. The $ function may be slower in browsers like IE where all of Prototpye.js's element methods must be added to the element. event.element is not just accessing a property. It is a function call, and as a consequence of adding a bunch of methods to the event object and also attempting to accommodate the differences in the event models of a few browsers, it does more work that the $ function. Therefore there is no reason to believe it will be faster than getElementById. In any case, it doesn't take much to test: script type=text/javascript window.onload = function() { $('button0').observe('click', function(e){ var el, i, num = 1; var msg = []; var start; start = new Date(), i = num; while (i--) {el = e.element()} msg.push('e.element: ' + (new Date() - start)); start = new Date(), i = num; while (i--) {el = $('button0');} end = new Date(); msg.push('$(id): ' + (new Date() - start)); start = new Date(), i = num; while (i--) {el = e.target || e.srcElement;} end = new Date(); msg.push('e.target or srcElement: ' + (new Date() - start)); alert(msg.join('\n')); }); } /script input type=button id=button0 value=Run test 0 The above indicates that $(id) is twice as fast as event.element() in IE, and 6 times faster in Firefox. If speed *really* matters, and you know what you are doing, access the property directly (the third test above). -- 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: event.element vs. $('element_id')
On Mar 27, 10:02 pm, Lapis petter.env...@gmail.com wrote: I do like this sometimes, when the scoping is ok: var submitter = $('submitter'); if (submitter) { submitter.observe('click', function (event) { // use submitter here }); }; It is great, time-wise. And exploits IE's memory leak due to the closure with circular reference. Don't do it. -- 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: event.element vs. $('element_id')
Well, it's not too hard to break that circular referencing by nullifying the variable when you're done with it. Of course, that should have been in the example too. /L On 27 Mar, 13:57, RobG rg...@iinet.net.au wrote: On Mar 27, 10:02 pm, Lapis petter.env...@gmail.com wrote: I do like this sometimes, when the scoping is ok: var submitter = $('submitter'); if (submitter) { submitter.observe('click', function (event) { // use submitter here }); }; It is great, time-wise. And exploits IE's memory leak due to the closure with circular reference. Don't do it. -- 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: event.element vs. $('element_id')
On Fri, Mar 27, 2009 at 8:57 AM, RobG rg...@iinet.net.au wrote: On Mar 27, 10:02 pm, Lapis petter.env...@gmail.com wrote: I do like this sometimes, when the scoping is ok: var submitter = $('submitter'); if (submitter) { submitter.observe('click', function (event) { // use submitter here }); }; It is great, time-wise. And exploits IE's memory leak due to the closure with circular reference. Don't do it. So, do I infer from this that IE (at least some version(s)) use a reference counting GC for Javascript? Yuck. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale --~--~-~--~~~---~--~~ 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] Trying to develop something new
Hi all, I started this topic in lighthouse and moved here under suggestion of Tobie. I'm pretty sure I'm overviewing something embarassingly obvious but I'm trying to modify some code and, to do it properly, I'm trying to download the entire unit test suit through git. git clone, git submodule init, git submodule update, rake dist OK. The point is I don't get any html files in test/unit! I also tried to download the tarball but I didn't have any more luck, neither I did browsing the web tree. As Tobie suggested I tried to rake test and all I got is a persistent Started tests in Chrome line with no cpu workload at all I've got a just-installed ruby 1.8.6 - 26 and a just-installed git 1.6.2 What am I missing? Thanks in advance Luca --~--~-~--~~~---~--~~ 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 dragdrop left percentage
I've just come up against the same issue, making percentage-based positioned elements draggable without flickering. The scriptaculous startDrag function doesn't notify the draggable element of the onStart method until after the left/right co-ordinates have been initialised, so there's no opportunity to convert them using the built-in notifications. It seems that any left/right values are silently assumed to be 'px' (i.e. '%' is ignored) and so the element flickers to 50px (instead of 50%) when the mousedown event is first trapped. The fix I've made listens for the mousedown event on the element, and converts the % to px (using the container ratio code you've already quoted). You also need to listen for the onEnd event of the drag action, and do another conversion back to % from the new px position using the inverse ratio. HTH, C. On Mar 23, 3:06 pm, Jay j...@demosphere.com wrote: Hi, Just noticed that if a draggable element uses a percentage in the style for 'left', a couple things don't seem to work right. !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd; html head script src=http://ussda.demosphere.com/common/js/ps1.8.2/ prototype.js language=JavaScript type=text/javascript/script script src=http://ussda.demosphere.com/common/js/ps1.8.2/ scriptaculous.js language=JavaScript type=text/javascript/ script /head body div id=d1 style=height:200px; width:300px; border:1px solid green; position:relative; div id=d2 style=position:absolute; top:20px; left:20px; height: 20px; width:80px; border:1px solid gray; ABC 123 /div /div script type=text/javascript new Draggable('d2',{revert:true}); /script /body /html Notice the 'left:20px' style - this setting works ok. But if you try it with 'left:20%' two odd things happen. The first is very quick in this example and hard to see (but shows up more in my production version) - at the start of the drag, there is a quick flash or wiggle to left=0 then back again. This does not happen with a 'px' setting only with a '%' setting. The second is the x,y location where it reverts to - it always goes back to the numeric quantity in pixel units, not the amount as a percentage. Wouldn't this be a bug? I like to use percentage because my container element changes in size if the browser window is resized or more options are chosen, etc. For now however, I'm doing something like this: var wid=$('container').getWidth(); var gleft=Math.round(wid*0.04); // left:4% gdiv.setStyle({position:'absolute', top:gtop+'px', left:gleft +'px', width:'92%'}); With that it doesn't flash, and stays lined up as the drag and drop operates, but of course it isn't reacting to dynamic changes in container size as it would with a percentage. Thanks, --Jay --~--~-~--~~~---~--~~ 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] having a default of no selection in drop down list
hi, I've seen this question asked a couple of times with no response so I thought I'd ask. When I am using the Autocompleter and I don't want the listbox to have a default selection... should I be writing my own updateElement method and overriding the existing one? or should I be doing something with the afterupdateelement method? or should I not even be attempting this type of thing? The genesis for wanting to do this is similar to the way Google behaves... I have a search text box, with an image_tag search button and am using the autocompleter. When I hit return on my keyboard I would like the text_field contents to be submitted if I have been typing but if I've used the arrows to select an item in the listbox and hit return I'd like that to be submitted (the later is always happening). Anyone have any pointers? Here is a snippet of my code: div id=search_bar % form_tag site_search_index_path(:site_id = session[:site]), :name = search_form, :method = :get do % %= text_field_tag 'search_term', @search_text, :class=search_text_input, :tabindex = 1, :title = Search Titles, Actors, Directors... % %= link_to_function image_tag(#{session[:branding_dir]} BtnSearch.gif, :width = 101px, :height = 23px, :alt = Search, :title = Click To Search, :class = search_submit), document.search_form.submit() % % end % /div script type=text/javascript document.search_form.search_term.focus() function InitSearch() { new Ajax.Autocompleter('search_term', 'autocomplete_choices', '%= search_autocomplete_path%', { method: 'get', minChars: 2, afterUpdateElement: addSearchItem }); $('search_term').focus(); } function addSearchItem(el) { el.value = '' + el.value + ''; } /script --~--~-~--~~~---~--~~ 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: event.element vs. $('element_id')
Well, it's not too hard to break that circular referencing by nullifying the variable when you're done with it. Of course, that should have been in the example too. /L On 27 Mar, 13:57, RobG rg...@iinet.net.au wrote: On Mar 27, 10:02 pm, Lapis petter.env...@gmail.com wrote: I do like this sometimes, when the scoping is ok: var submitter = $('submitter'); if (submitter) { submitter.observe('click', function (event) { // use submitter here }); }; It is great, time-wise. And exploits IE's memory leak due to the closure with circular reference. Don't do it. -- 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: Trying to develop something new
Other available rake options are: TESTS and TESTCASES. The former let's you specify a comma-separated list of pages: $ rake test TESTS=array,string (builds and runs the tests found in array.js and string.js). The latter lets you specify actual TESTCASES: $ rake test TESTCASES=test$w,testArrayInject You can of course combine those. Best, Tobie On Mar 27, 4:01 pm, T.J. Crowder t...@crowdersoftware.com wrote: Hi Luca, Curiously enough, I ran into both of those issues the other day. The point is I don't get any html files in test/unit! That's because the contribute page[1] is wrong about that. The HTML files aren't in test/unit (they're in test/unit/tmp), and they aren't *anywhere* until after you've run rake test, because they're generated at that point, not at the point they're mentioned on the contribute page (just after rake dist). There's an open ticket in Lighthouse to correct that. [1]http://prototypejs.org/contribute As Tobie suggested I tried to rake test and all I got is a persistent Started tests in Chrome line with no cpu workload at all I'm guessing you're using Windows. This happens because of a bug (or, arguably, two bugs) in the unit testing stuff; I've mentioned it to Tobie but haven't had time to find out what project it's in (I think it's unittest_js, which is one of the submodules) and raise a formal ticket or two. The problem is that it's looking in the wrong place for Chrome, not finding it, and apparently going off into never-never land. You can fix it by doing this in your command window just before rake test: set UserPath=%UserProfile% Alternately you can edit line #6 in vendor/unittest_js/lib/unittest_js/ browsers/chrome.rb ENV['UserPath'] || C:/Documents and Settings/Administrator, to read ENV['UserPath'] || ENV['UserProfile'] || C:/Documents and Settings/ Administrator, Here are some further notes from what testing I've done so far (which is quite limited): 1. You will also probably want to use the BROWSERS option of rake test, which lets you decide which browsers to run the tests in: The options I've found so far are chrome, ie, firefox, opera, and safari (which probably covers it, for now). It's a comma-delimited list. So for instance, this runs the tests in Firefox only: rake test BROWSERS=firefox or perhaps you want to test chrome and IE: rake test BROWSERS=chrome,ie 2. Always have the browser you want to test running before you run rake test. It's *supposed* to launch the browser, but I've had a lot of trouble with that under Windows. 3. When testing Opera, Rake test will display a major pain under windows message saying that you have to close the Opera window after each unit test. I find that if I have Opera running before I start the test, I don't _usually_ have to do that. I have had to sometimes, but not often. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Mar 26, 6:14 pm, Luca Diracca dirl...@gmail.com wrote: Hi all, I started this topic in lighthouse and moved here under suggestion of Tobie. I'm pretty sure I'm overviewing something embarassingly obvious but I'm trying to modify some code and, to do it properly, I'm trying to download the entire unit test suit through git. git clone, git submodule init, git submodule update, rake dist OK. The point is I don't get any html files in test/unit! I also tried to download the tarball but I didn't have any more luck, neither I did browsing the web tree. As Tobie suggested I tried to rake test and all I got is a persistent Started tests in Chrome line with no cpu workload at all I've got a just-installed ruby 1.8.6 - 26 and a just-installed git 1.6.2 What am I missing? Thanks in advance Luca --~--~-~--~~~---~--~~ 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: Trying to develop something new
2009/3/27 T.J. Crowder t...@crowdersoftware.com: Hi Luca, Curiously enough, I ran into both of those issues the other day. The point is I don't get any html files in test/unit! That's because the contribute page[1] is wrong about that. The HTML files aren't in test/unit (they're in test/unit/tmp), and they aren't *anywhere* until after you've run rake test, because they're generated at that point, not at the point they're mentioned on the contribute page (just after rake dist). There's an open ticket in Lighthouse to correct that. [1] http://prototypejs.org/contribute As Tobie suggested I tried to rake test and all I got is a persistent Started tests in Chrome line with no cpu workload at all I'm guessing you're using Windows. This happens because of a bug (or, arguably, two bugs) in the unit testing stuff; I've mentioned it to Tobie but haven't had time to find out what project it's in (I think it's unittest_js, which is one of the submodules) and raise a formal ticket or two. The problem is that it's looking in the wrong place for Chrome, not finding it, and apparently going off into never-never land. You can fix it by doing this in your command window just before rake test: set UserPath=%UserProfile% Alternately you can edit line #6 in vendor/unittest_js/lib/unittest_js/ browsers/chrome.rb ENV['UserPath'] || C:/Documents and Settings/Administrator, to read ENV['UserPath'] || ENV['UserProfile'] || C:/Documents and Settings/ Administrator, Here are some further notes from what testing I've done so far (which is quite limited): 1. You will also probably want to use the BROWSERS option of rake test, which lets you decide which browsers to run the tests in: The options I've found so far are chrome, ie, firefox, opera, and safari (which probably covers it, for now). It's a comma-delimited list. So for instance, this runs the tests in Firefox only: rake test BROWSERS=firefox or perhaps you want to test chrome and IE: rake test BROWSERS=chrome,ie 2. Always have the browser you want to test running before you run rake test. It's *supposed* to launch the browser, but I've had a lot of trouble with that under Windows. 3. When testing Opera, Rake test will display a major pain under windows message saying that you have to close the Opera window after each unit test. I find that if I have Opera running before I start the test, I don't _usually_ have to do that. I have had to sometimes, but not often. HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Mar 26, 6:14 pm, Luca Diracca dirl...@gmail.com wrote: Hi all, I started this topic in lighthouse and moved here under suggestion of Tobie. I'm pretty sure I'm overviewing something embarassingly obvious but I'm trying to modify some code and, to do it properly, I'm trying to download the entire unit test suit through git. git clone, git submodule init, git submodule update, rake dist OK. The point is I don't get any html files in test/unit! I also tried to download the tarball but I didn't have any more luck, neither I did browsing the web tree. As Tobie suggested I tried to rake test and all I got is a persistent Started tests in Chrome line with no cpu workload at all I've got a just-installed ruby 1.8.6 - 26 and a just-installed git 1.6.2 What am I missing? Thanks in advance Luca Thank you for this. Tested Chrome. Got 3 failures in Chrome (all in dom_test - 2 in testViewportDimensions and 1 in testViewportScrollOffsets) 0 assertions, 2 failures, 0 errors Failure: NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS expected: 1314, actual: 1264 Failure: NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS expected: 903, actual: 853 and 2 assertions, 1 failures, 0 errors Failure: NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS expected: 25, actual: 0 And 2 failures in IE related to (selector_test - both in testSelectorWithEmpty). 0 assertions, 2 failures, 0 errors Failure: #level1 *:empty expected: [span id=level3_1, span id=level3_2, div id=level2_3], actual: [span id=level3_1, span id=level3_2, em id=level_only_child, div id=level2_3] Failure: newlines count as content! expected: [], actual: [em id=level_only_child] Tested using 6c38d84 -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ 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
[Proto-Scripty] observe any change in the window
I have an iframe and I am using the onbeforeunload to prevent data loss. What I need to do is set a variable called save to 0 after any change is made within the frame. I tried this but it doesn't work: document.observe('change', function(){ save=0 }); How can I accomplish this task? Is it possible to observe for any change made? --~--~-~--~~~---~--~~ 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] New combination effect
Is there any documentation about creating new combination effects? How to use initialize, setup, update, etc methods? How to add an afterUpdate 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 -~--~~~~--~~--~--~---