/*
 * Etalage -- Open Data POIs portal
 * By: Emmanuel Raviart <eraviart@easter-eggs.com>
 *
 * Copyright (C) 2011, 2012 Easter-eggs
 * http://gitorious.org/infos-pratiques/etalage
 *
 * This file is part of Etalage.
 *
 * Etalage is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Etalage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


var etalage = etalage || {};


etalage.bind = (function ($) {
    var $loadingGif;
    var isLoaded = false;

    function preloadLoadingGif() {
        image = new Image();
        image.src = etalage.miscUrl + 'please-wait.gif';
        image.alt = 'Chargement...';

        $loadingGif = $(image);
        $loadingGif.addClass('loading');

        isLoaded = true;
    }

    function loadingGif() {
        if (!isLoaded) {
            preloadLoadingGif();
        }

        $('a.internal').bind('click', function(event) {
            $('#search-form .form-actions').last().append($loadingGif);
        });

        $('#search-form').bind('submit', function(event) {
            $('#search-form .form-actions').last().append($loadingGif);
        });
    }

    function toggleCategories() {
        if (!isLoaded) {
            preloadLoadingGif();
        }

        $("#search-form input[name='category'][type='checkbox']").bind('change', function(event) {
            var action = $("#search-form").attr('action');
            var queryString = $("#search-form").serializeArray().concat({
                name: 'submit',
                value: 'Submit'
            });

            $('#search-form .form-actions').last().append($loadingGif);

            if (typeof rpc !== "undefined" && rpc !== null) {
                rpc.requestNavigateTo(action, queryString);
                return false;
            } else {
                document.location = action + "?" + queryString;
            }
        });
    }

    return {
        loadingGif: loadingGif,
        toggleCategories: toggleCategories
    };
})(jQuery);


@@ -1371,20 +1371,18 @@
 ernal').
-bind
+on
 ('click'
@@ -1383,24 +1383,129 @@
 click', 
-function
+appendLoadingGif);%0A        $('#search-form').on('submit', appendLoadingGif);%0A    %7D%0A%0A    function appendLoadingGif
 (event) 
@@ -1506,36 +1506,32 @@
 vent) %7B%0A        
-   
- 
 $('#search-form 
@@ -1586,130 +1586,281 @@
     
-%7D);%0A%0A        $('#search-form').bind('submit', function(event) %7B%0A            $('#search-form .form-actions').last().append(
+$loadingGif.data('activeUrl', document.location);%0A%0A        setTimeout(function () %7B%0A            if (typeof($loadingGif) !== %22undefined%22 &&%0A                    $loadingGif !== null &&%0A                    document.location == $loadingGif.data('activeUrl')) %7B%0A                
 $loa
@@ -1858,32 +1858,40 @@
      $loadingGif
+.detach(
 );%0A        %7D);%0A 
@@ -1877,33 +1877,84 @@
 tach();%0A        
-%7D
+        clearTimeout();%0A            %7D%0A        %7D, 300
 );%0A    %7D%0A%0A    fu

Fix loading GIF (remove it when using navigator's back button)