Well, I''ve been burning the midnight oil trying to figure out how to issue the stop() command to a PeriodicUpdater. I''ve come up with a solution that uses setTimeouts to call the stop function. I think my solution is very kludgey... especially since I''m new to Javascript + Prototype. Can anyone let me know if the below code is at all proper? :) --------- Summary: A PeriodicUpdater calls a server script which returns the percent finished of a process as a JSON encoded string in a x-json header. When the percent is > 10, I''d like to STOP the periodicupdater from making any further AJAX calls. The problem: If I issue pb.stop() in the onSuccess function [pbCheck()], nothing happens. The script continues! The workaround: Set percent value using pbCheck, Use setTimeout to continually poll pbKill() which checks the percent value & if it''s greater than 10, issues STOP to updater before destroying it (when a STOP is recieved, the onComplete function is called[pbClean()]). <script type="text/javascript"> // <![CDATA[ if (!pb) { var pb new Ajax.PeriodicalUpdater("ajaxUpdate", "ajax_mailingStatus.php", { asynchronous:true, frequency : 2, onSuccess: pbCheck, onComplete: pbClean }); } var percent = 0; function pbCheck(request,json) { percent = json.percent; } setTimeout(pbKill,5000); function pbKill() { if (percent > 10) { pb.stop(); } else { setTimeout(pbKill,5000); } } function pbClean() { pb = null; } } // ]]> </script> ------ Thanks, ~ Brice Burgess
Maninder, Singh
2006-May-02 09:29 UTC
RE: Stopping the Ajax.PeriodicalUpdater -- My Kludge?
Prototype PeriodicalExecuter.stop() http://blog.jagregory.com/Blog/archive/2006/01/09/801.aspx Thanks, Mandy.
I think correct URL is: http://blog.jagregory.com/articles/2006/01/09/801.aspx On 5/2/06, Maninder, Singh <mandiv@corp.untd.com> wrote:> > Prototype PeriodicalExecuter.stop() > http://blog.jagregory.com/Blog/archive/2006/01/09/801.aspx > > Thanks, > Mandy. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
The page you linked to doesn''t work... I''m still having issues with this -- and having to rely on setTimeout -- even though it''s bound. Here''s the updated code: -- notice setTimeout(pb.stopper,300); -- [BEGIN] var pb = { init: function() { this.percent = 0; this.updater = new Ajax.PeriodicalUpdater( ''ajaxUpdate'', ''ajax_status.php'', { frequency: 5, onSuccess: this.update.bind(this) } ); pb.nextUpdate = 5; pb.updateTimer(); }, update: function(resp, json) { $(''pbBarTextPercent'').innerHTML = json.sent; $(''pbText'').innerHTML = json.percent + "%"; $(''pbBar'').setStyle({width: json.percent + ''%'' }); if (json.status == ''finished'') { this.updater.stop(); setTimeout(pb.stopper,300); } ............. }, stopper: function() { pb.updater.stop(); }, updateTimer: function() { if (pb.nextUpdate > 0) { pb.nextUpdate = pb.nextUpdate - 1; $(''updateTime'').innerHTML = pb.nextUpdate; } setTimeout(pb.updateTimer,1000); } } /* INIT FUNCTIONS */ pb.init(); [END] Ed C. wrote:> I think correct URL is: > > http://blog.jagregory.com/articles/2006/01/09/801.aspx > > > On 5/2/06, *Maninder, Singh* <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org > <mailto:mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org>> wrote: > > Prototype PeriodicalExecuter.stop() > http://blog.jagregory.com/Blog/archive/2006/01/09/801.aspx > > Thanks, > Mandy. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > <mailto:Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
This is my fault, the page they were referring to is actually at the following address: http://blog.jagregory.com/articles/2006/01/09/prototype-periodicalexecuter- stop-javascript-function (watch for the word-wrap in the url) I apologise for the inconvenience, but my blogging software recently had an upgrade and in the process I lost some of the legacy url support.
Hi all, I''ve been writing a little add-on to allow for dragging multiple elements in Sortables. See it in action here: http://www.abomb.co.uk/multidrag/scriptaculous-js-1.5_rc5/test/functional/so rtable_multi_test.html This "works" in both IE 6 and Firefox 1.5.0.3 which are the only browsers I''ve tested it in. Hopefully the source should be fairly easy to understand: * Clicking an element adds it to the "selectedElementIDs" array * If more than one element is selected (using CTRL or SHIFT) and dragged then the selected elements are cloned and appended to the element being dragged. This "draggee" is then ridded of its innerHTML and any duplicates are removed. This gives the impression that you are dragging the selected elements. * On drag end the reverse is performed Now for the problem. * Start IE. Select a couple of items. Drag them and drop them. Now drag them and drop them again. Look in the debugging area at the bottom. Nooo! IE clones too much. (In Firefox it''s fine). It doesn''t actually notice, but what''s going on there? * In scriptaculous-js-1.5.0, scriptaculous-js-1.5.1, scriptaculous-js-1.6.1 in IE the second time you drag it doesn''t show the drag. http://www.abomb.co.uk/multidrag/scriptaculous-js-1.5.1/test/functional/sort able_multi_test.html So it works in 1.5_rc5 but nothing else I''ve tested it in. You can drop the files sortable_multi_test.html and class.mulitDragPatch.js into your \test\functional directory to test for yourselves. If anyone has any experience with problems cloning in IE or can shed any light on this, I''d be very grateful to hear from you. I''ve spent many hours fiddling about with this! Many thanks, Leon _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Brice Burgess
2006-May-07 19:31 UTC
Re: Re: Stopping the Ajax.PeriodicalUpdater -- My Kludge?
James Gregory wrote:> This is my fault, the page they were referring to is actually at the following > address: > > http://blog.jagregory.com/articles/2006/01/09/prototype-periodicalexecuter- > stop-javascript-function > > (watch for the word-wrap in the url) > > I apologise for the inconvenience, but my blogging software recently had an > upgrade and in the process I lost some of the legacy url support. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >James, Thanks for the link. It looks like you''re using a similar method to mine? ~ Brice