Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • Andy P 2:03 pm on January 18, 2006 Permalink | Reply  

    Getting a single AJAX loading progress indicator into your web application can be a relatively straightforward task thanks to a simple piece of Javascript from Thomas Fuchs:

    // lang javascript
    Ajax.Responders.register({
    onCreate: function() {
     if($('busy') && Ajax.activeRequestCount>0)
     Effect.Appear('busy',{duration:0.5,queue:'end'});
    },
    
    onComplete: function() {
     if($('busy') && Ajax.activeRequestCount==0)
     Effect.Fade('busy',{duration:0.5,queue:'end'});
    }
    });

    However, from what I could tell (and subsequently experienced) is that by using this code, you are limited to only one progress indicator per page. This caused me problems, as on my Archives page I have a progress indicator for when the application is fetching monthly archives, but also for the live search function that appears on every page. Whenever I activated an AJAX request by using either function, both the loading indicators would be displayed, thus confusing the user.

    So, how is it possible to get around this? Well, from what I can see it’s impossible to pass the ID of a loading indicator into Thomas’ script. The trick is to move the hiding and displaying of the indicators into function calls for the “onComplete” and “onCreate” events within your specific AJAX request:

    // lang javascript
    function getMonthResults(vars)
    {
      var url = 'archives_month.php';
      var pars = 'm=' + vars;
      var target = 'monthResults';
      var myAjax = new Ajax.Updater(target, url, {
    asynchronous:true,
    onCreate: function() { showLoader('mArchive_loader'); },
    onComplete: function() { hideLoader('mArchive_loader'); },
    parameters: pars,
    method: 'get'
      });
      var element = document.getElementById(target);
    }

    The two events now call separate functions that pass the ID of the loading indicator, allowing you to define which indicator to hide or display:

    // lang javascript
    function showLoader(loader)
    {
       new Effect.Appear($(loader), {duration: 0.5});
    }
    
    function hideLoader(loader)
    {
       new Effect.Fade($(loader), {duration: 0.5});
    }
    

    Simple as that. Now, I’m not saying that this is the “offical” or “ideal” way of going about this task, but it’s the one that worked for me. You can also extend the show and hide functions, to add an effect to your target container by passing the target as well as the loader to the function. For example, I have used the following as my show and hide functions:

    // lang javascript
    function loadingRequest(loader, target)
    {
       new Effect.Appear($(loader), {duration: 0.5});
       $(target).style.display = "none";
    }
    
    function completedRequest(loader, target)
    {
       new Effect.Fade($(loader), {duration: 0.5});
       new Effect.BlindDown($(target));
    }
    

    This means that when the AJAX request has completed, the results will slide into view using the “BlindDown” effect from the Scriptaculous library. A nice added extra.

    Technorati Tags: ,

     
    • Cheyne 8:38 pm on February 3, 2006 Permalink | Reply

      Great article. I have blogged about it on http://www.thewebdesignblog.com

    • Tru 3:58 am on March 16, 2006 Permalink | Reply

      Test

    • T 10:52 am on April 23, 2006 Permalink | Reply

      d

    • htrshtrh 1:58 pm on June 13, 2006 Permalink | Reply

      t(“‘gt(szhy§’(h§’h§hj§e

    • Porter 4:12 pm on November 19, 2006 Permalink | Reply

      Thanks! I’m building my first app using CakePHP and Prototype/Scriptaculous – this saved me some valuable figuring-out time while I’m on a tight deadline.

    • trtr 12:09 pm on November 25, 2006 Permalink | Reply

      trtrtr

    • Ryan McCue 9:09 pm on December 11, 2006 Permalink | Reply

      Great, thanks. Just what I was looking for.

    • test 12:23 pm on April 3, 2007 Permalink | Reply

      test

    • Kristoffer Eriksson 2:51 pm on May 1, 2007 Permalink | Reply

      Thanks!

    • nicolas 7:41 am on May 31, 2007 Permalink | Reply

      Make your own Ajax loading indicators with http://www.webscriptlab.com

    • nicolas 11:33 am on June 2, 2007 Permalink | Reply

      Great, thanks.
      I just found an Ajax loading generator on http://www.webscriptlab.com, lets you generate loading icons on demand for your applications. Pretty cool stuff!

    • Sheri 10:49 am on June 10, 2007 Permalink | Reply

      I got this to work with ‘onLoading’ rather than ‘onCreate’.

      onCreate would just not work for me!

      Best,
      Sheri

    • Mukesh Variya 12:40 am on June 26, 2007 Permalink | Reply

      Hi,

      this is very simple and important information for AJAX Users.

      good one.

      http://mukeshvariya.blogspot.com

    • Jason 5:01 pm on July 11, 2007 Permalink | Reply

      Using onLoading causes a problem in IE 6. Sometimes onLoading gets called after onComplete. It is suggested by the Prototype documentation that you avoid using onLoading because it’s not deterministic oon each browser.

      does onCreate have these problems?

    • sergio 5:39 pm on October 27, 2007 Permalink | Reply

      Hello! You have a Very good site! I like it! I just wanted to pass on a note to let you know

    • Rupert 5:59 am on November 26, 2007 Permalink | Reply

      I only wish i came across this article sooner! Great read!

    • Mircea 6:15 am on March 18, 2008 Permalink | Reply

      I am using this for showing the loading indicator everytime an Ajax call is made on different places from a page (see the … {Element.show(’show_tags_loading’);} and {Element.hide(’show_tags_loading’);}…):
      ———————-
      Click here  
      ———————–

    • Mircea 6:18 am on March 18, 2008 Permalink | Reply

      Ops, it seems WordPress eats the code (put for a href and other HTML tags):
      ———
      a href=”javascript:void(0)” onClick=”new Ajax.Updater(‘form_add_new’,'display/show.cfm?page=1′, {onCreate: function(){Element.show(’show_tags_loading’);},onComplete:function(){Element.hide(’show_tags_loading’)},asynchronous:true});return false;” …Click here…. /a span id=”show_tags_loading” class=”normal” style=”display: none;” img src=”loading.gif” /span
      ————–

    • nbgfng 9:56 am on July 24, 2008 Permalink | Reply

      nfg nfg df

    • cross 4:42 am on August 26, 2008 Permalink | Reply

      Will try to use this code

  • Andy P 11:19 pm on January 9, 2006 Permalink | Reply  

    Textmate IconBefore using TextMate I’d switched and swapped which editor I used regularly. Sometimes I’d settle for the bloated features of an IDE like Zend Studio, and other times just shoot for something simple and fast like Mac OS X’s TextEdit. I never really found the balance, and like most people I have spoken to, they and I found BBEdit to be too old (and too ugly) for any real productive use.

    So why does TextMate appeal so much? I guess it’s attention to detail, and the developers ability to prioritize what features the user really wants. It includes all the basics you would expect of your average editor, code highlighting, auto indentation, some level of auto completion etc etc. However, it also adds to these, by including features like snippets, code block collapsing and a project file browser. These are features that won’t make the software bloated, but go a long way for increasing your productivity and appreciation of the simple added extras.

    Snippets

    Snippets in TextmateMy favorite of the three features I mentioned above is snippets. This is one of TextMate’s features that I took some time to really get used to. I’m one of those people who tends to retype code over and over again, just because I don’t want remove my fingers from the keyboard to select and copy a block of code. Snippets allows me to assign a keyword to code that I regularly have to retype, then all I need to do is type this keyword and hit tab. The code magically appears and even lets you tab between input locations within it. This has been an amazing time saver, TextMate already has hundreds of snippets pre-bundled.

    I’m also amazed by the rate and amount of updates that come out for the software. I subscribe to the bleeding edge releases, so I receive all the unofficial builds. Even so, I’ve found all the releases so far to be perfectly stable, and allow me to take advantage of features before their official release. TextMate includes it’s own auto-update feature, which is easily the best that I’ve seen. I hate auto updates, they’re annoying and always get in the way. TextMate’s is quite the opposite however, updates download quickly and unobtrusively, and everything is automated. It even removes your old copy, copies itself over to you applications directory and then restarts. This all happens in less that 15 seconds for me. Perfect.

    What’s Missing?

    TextMate does have a couple of features missing that I would really like to see included. CVS or Subversion support would be a great bonus, that would cut my checking in time down dramatically. Also, auto completion of code would be great for all the PHP work I do. This is lesser of a wish however, as I’m finding that I memorize far more functions by having to remember them and not rely on the prompt window to back me up! I’m sure that these features will come, but again they are lower down on the priority list as they are not so important for the masses.

    If you are a Mac user and find BBEdit ugly and slow, give TextMate a shot. It has a free trial and is cheap (around €39). I paid for a license within the first week of using it, it’s that good. They also just redesigned their website which now looks very polished compared with the old one. I’m looking forward to continued updates, and with version 1.5 just released, I’ve got a whole bunch of new features to test out!

    Technorati Tags: ,

     
    • Jon Fried 11:58 pm on January 16, 2006 Permalink | Reply

      I moved to a Mac last year and spent quite a while looking for a decent editor for work. Textmate was great as you say, and I agree that snippets can be a real time saver.

    • Drew 6:07 pm on March 13, 2006 Permalink | Reply

      TextMate does have SVN integration. It may have been added since you wrote this, but I’m pretty sure it’s been in for some time. Selecting the files you want to operate on in the drawer, ctrl-shift-a will pull up the svn operations menu. It’s not as nice as, say, Eclipse’s SVN integration, but it gets the job done for basic checking in, diffing, and reverting.

      If it’s not in your version, check around the TextMate wiki. It’s definitely available as a downloadable bundle.

  • Andy P 6:41 pm on January 2, 2006 Permalink | Reply  

    It turns out however, that trying to run WordPress 1.5 and 2.0 on the same server was not a good idea.

    I wanted to put the new site up into a sub folder, and import all of my WP 1.5 content. Long story, but it ended up mixing up my databases, WP 1.5 went down, and here we are with 2.0.

    I’ll be tweaking lot’s of different areas over the next few days, most notably Internet Explorer 6 support, which being on a Mac over the xmas period has proved difficult to test so far. Adding a comment right now may prove to be difficult/impossible as I’m using position:fixed…

    I’m also finishing up the contact form, comment previewing and tag archives, all which need a little AJAX love.

    So, in true 37 Signals style, here it is, the rest will come later. ;)

     
    • Dave S 10:06 pm on January 2, 2006 Permalink | Reply

      New design is fresh, I like that style.

      Be glad to see it when you’ve made the final updates, you’ve got a few html issues to clear up I noticed too.

    • Andy P 10:09 pm on January 2, 2006 Permalink | Reply

      Ah yes, I’m sure there are a few validation errors to clean up.

      That’s generally the last thing I get to when creating the site, I’ll give it a once over and make sure it’s all in place.

      I’ll clean those up once I’ve finished the above features. Thanks for kind comments and checking those out.

    • Orion 10:58 am on January 7, 2006 Permalink | Reply

      am i the only one who sees the text a little bit mashed up ?

    • Andy P 9:53 pm on January 8, 2006 Permalink | Reply

      Hey Orion, can you expand at all please, what you do mean that the text is “mashed up” and what browser/operating system are you using?

      I’m still in the process of testing things out, however, the text has generally looked okay on most platforms so far.

      Thanks for the input.

    • Polybuzz 2:14 pm on February 18, 2006 Permalink | Reply

      nice. :) i dig this very much. is this the one you’re planning to submit to the WordPress 2.0 Theme Competition? got through your website via the participants list at http://kcyap.com/competition/?page_id=8. :D

      looking forward to see this design win, if ever! send me an email (as unusual as it may seem, that really is my email. :P ) when voting starts there so i can pitch in some votes from myself and my mates. :D

      regards!

    • Timmargh 12:36 pm on April 13, 2006 Permalink | Reply

      I know I’m a bit late to the party, but this design is superb – good looking and devoid of most design clichés.

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel