[Proto-Scripty] Re: How to disable draggables in script.aculo.us
Hello- I was wondering if you could please tell me where in the documentation you found this. There is very little about destroy() that I can find. In fact, I only found a single mention of it on the "draggable" page. Also, I tried the bit of code you posted and it does not seem to be working for me. I can repeatedly drag the same object around. Thank-you for any additional insight. On Aug 14, 1:48 pm, nimzo wrote: > More glances at the documentation led me to this: > > onEnd: function(d) { > Draggables.drags.each(function(draggable) { > draggable.destroy(); > }) > > }, > > ... and it worked. Apparently, there is already a reference > to all the draggables on the page. Thanks for your help. > > On Aug 14, 4:36 am, "Alex McAuley" > wrote: > > > > > Speed up was the wrong term - which i realised when i pressed "Send" > > > Alex Mcauleyhttp://www.thevacancymarket.com > > > - Original Message - > > From: "T.J. Crowder" > > To: "Prototype & script.aculo.us" > > Sent: Friday, August 14, 2009 12:17 PM > > Subject: [Proto-Scripty] Re: How to disable draggables in script.aculo.us > > > 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
[Proto-Scripty] Re: How to disable draggables in script.aculo.us
More glances at the documentation led me to this: onEnd: function(d) { Draggables.drags.each(function(draggable) { draggable.destroy(); }) }, ... and it worked. Apparently, there is already a reference to all the draggables on the page. Thanks for your help. On Aug 14, 4:36 am, "Alex McAuley" wrote: > Speed up was the wrong term - which i realised when i pressed "Send" > > Alex Mcauleyhttp://www.thevacancymarket.com > > - Original Message - > From: "T.J. Crowder" > To: "Prototype & script.aculo.us" > Sent: Friday, August 14, 2009 12:17 PM > Subject: [Proto-Scripty] Re: How to disable draggables in script.aculo.us > > 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: How to disable draggables in script.aculo.us
Speed up was the wrong term - which i realised when i pressed "Send" Alex Mcauley http://www.thevacancymarket.com - Original Message - From: "T.J. Crowder" To: "Prototype & script.aculo.us" Sent: Friday, August 14, 2009 12:17 PM Subject: [Proto-Scripty] Re: How to disable draggables in script.aculo.us 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: How to disable draggables in script.aculo.us
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: How to disable draggables in script.aculo.us
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 Mcauley http://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: How to disable draggables in script.aculo.us
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 -~--~~~~--~~--~--~---