IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Suppression de filtre - plugin Quicksand


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Mai 2013
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France, Seine et Marne (Île de France)

    Informations forums :
    Inscription : Mai 2013
    Messages : 1
    Par défaut Suppression de filtre - plugin Quicksand
    Bonjour,

    J'utilise le plugin Jquery Quicksand (voir : http://razorjack.net/quicksand/) pour trier dynamiquement des éléments, voir exemple ci-dessous :

    http://www.codesscripts.fr/demos/por...and/index.html

    Cependant je n'ai pas besoin du filtre "all" et je souhaiterais donc le supprimer mais je n'arrive pas à forcer le script sur un filtre spécifique comme "print" ou "web".

    Voici le script principal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    /*
     
    Quicksand 1.2.2
     
    Reorder and filter items with a nice shuffling animation.
     
    Copyright (c) 2010 Jacek Galanciak (razorjack.net) and agilope.com
    Big thanks for Piotr Petrus (riddle.pl) for deep code review and wonderful docs & demos.
     
    Dual licensed under the MIT and GPL version 2 licenses.
    <a href="http://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt" target="_blank">http://github.com/jquery/jquery/blob...IT-LICENSE.txt</a>
    <a href="http://github.com/jquery/jquery/blob/master/GPL-LICENSE.txt" target="_blank">http://github.com/jquery/jquery/blob...PL-LICENSE.txt</a>
     
    Project site: <a href="http://razorjack.net/quicksand" target="_blank">http://razorjack.net/quicksand</a>
    Github site: <a href="http://github.com/razorjack/quicksand" target="_blank">http://github.com/razorjack/quicksand</a>
     
    */
     
    (function ($) {
        $.fn.quicksand = function (collection, customOptions) {     
            var options = {
                duration: 750,
                easing: 'swing',
                attribute: 'data-id', // attribute to recognize same items within source and dest
                adjustHeight: 'auto', // 'dynamic' animates height during shuffling (slow), 'auto' adjusts it before or after the animation, false leaves height constant
                useScaling: true, // disable it if you're not using scaling effect or want to improve performance
                enhancement: function(c) {}, // Visual enhacement (eg. font replacement) function for cloned elements
                selector: '> *',
                dx: 0,
                dy: 0
            };
            $.extend(options, customOptions);
     
            if ($.browser.msie || (typeof($.fn.scale) == 'undefined')) {
                // Got IE and want scaling effect? Kiss my ass.
                options.useScaling = false;
            }
     
            var callbackFunction;
            if (typeof(arguments[1]) == 'function') {
                var callbackFunction = arguments[1];
            } else if (typeof(arguments[2] == 'function')) {
                var callbackFunction = arguments[2];
            }
     
     
            return this.each(function (i) {
                var val;
                var animationQueue = []; // used to store all the animation params before starting the animation; solves initial animation slowdowns
                var $collection = $(collection).clone(); // destination (target) collection
                var $sourceParent = $(this); // source, the visible container of source collection
                var sourceHeight = $(this).css('height'); // used to keep height and document flow during the animation
     
                var destHeight;
                var adjustHeightOnCallback = false;
     
                var offset = $($sourceParent).offset(); // offset of visible container, used in animation calculations
                var offsets = []; // coordinates of every source collection item            
     
                var $source = $(this).find(options.selector); // source collection items
     
                // Replace the collection and quit if IE6
                if ($.browser.msie && $.browser.version.substr(0,1)<7) {
                    $sourceParent.html('').append($collection);
                    return;
                }
     
                // Gets called when any animation is finished
                var postCallbackPerformed = 0; // prevents the function from being called more than one time
                var postCallback = function () {
     
                    if (!postCallbackPerformed) {
                        postCallbackPerformed = 1;
     
                        // hack: 
                        // used to be: $sourceParent.html($dest.html()); // put target HTML into visible source container
                        // but new webkit builds cause flickering when replacing the collections
                        $toDelete = $sourceParent.find('> *');
                        $sourceParent.prepend($dest.find('> *'));
                        $toDelete.remove();
     
                        if (adjustHeightOnCallback) {
                            $sourceParent.css('height', destHeight);
                        }
                        options.enhancement($sourceParent); // Perform custom visual enhancements on a newly replaced collection
                        if (typeof callbackFunction == 'function') {
                            callbackFunction.call(this);
                        }                    
                    }
                };
     
                // Position: relative situations
                var $correctionParent = $sourceParent.offsetParent();
                var correctionOffset = $correctionParent.offset();
                if ($correctionParent.css('position') == 'relative') {
                    if ($correctionParent.get(0).nodeName.toLowerCase() == 'body') {
     
                    } else {
                        correctionOffset.top += (parseFloat($correctionParent.css('border-top-width')) || 0);
                        correctionOffset.left +=( parseFloat($correctionParent.css('border-left-width')) || 0);
                    }
                } else {
                    correctionOffset.top -= (parseFloat($correctionParent.css('border-top-width')) || 0);
                    correctionOffset.left -= (parseFloat($correctionParent.css('border-left-width')) || 0);
                    correctionOffset.top -= (parseFloat($correctionParent.css('margin-top')) || 0);
                    correctionOffset.left -= (parseFloat($correctionParent.css('margin-left')) || 0);
                }
     
                // perform custom corrections from options (use when Quicksand fails to detect proper correction)
                if (isNaN(correctionOffset.left)) {
                    correctionOffset.left = 0;
                }
                if (isNaN(correctionOffset.top)) {
                    correctionOffset.top = 0;
                }
     
                correctionOffset.left -= options.dx;
                correctionOffset.top -= options.dy;
     
                // keeps nodes after source container, holding their position
                $sourceParent.css('height', $(this).height());
     
                // get positions of source collections
                $source.each(function (i) {
                    offsets[i] = $(this).offset();
                });
     
                // stops previous animations on source container
                $(this).stop();
                var dx = 0; var dy = 0;
                $source.each(function (i) {
                    $(this).stop(); // stop animation of collection items
                    var rawObj = $(this).get(0);
                    if (rawObj.style.position == 'absolute') {
                        dx = -options.dx;
                        dy = -options.dy;
                    } else {
                        dx = options.dx;
                        dy = options.dy;                    
                    }
     
                    rawObj.style.position = 'absolute';
                    rawObj.style.margin = '0';
     
                    rawObj.style.top = (offsets[i].top - parseFloat(rawObj.style.marginTop) - correctionOffset.top + dy) + 'px';
                    rawObj.style.left = (offsets[i].left - parseFloat(rawObj.style.marginLeft) - correctionOffset.left + dx) + 'px';
                });
     
                // create temporary container with destination collection
                var $dest = $($sourceParent).clone();
                var rawDest = $dest.get(0);
                rawDest.innerHTML = '';
                rawDest.setAttribute('id', '');
                rawDest.style.height = 'auto';
                rawDest.style.width = $sourceParent.width() + 'px';
                $dest.append($collection);      
                // insert node into HTML
                // Note that the node is under visible source container in the exactly same position
                // The browser render all the items without showing them (opacity: 0.0)
                // No offset calculations are needed, the browser just extracts position from underlayered destination items
                // and sets animation to destination positions.
                $dest.insertBefore($sourceParent);
                $dest.css('opacity', 0.0);
                rawDest.style.zIndex = -1;
     
                rawDest.style.margin = '0';
                rawDest.style.position = 'absolute';
                rawDest.style.top = offset.top - correctionOffset.top + 'px';
                rawDest.style.left = offset.left - correctionOffset.left + 'px';
     
     
     
     
     
                if (options.adjustHeight === 'dynamic') {
                    // If destination container has different height than source container
                    // the height can be animated, adjusting it to destination height
                    $sourceParent.animate({height: $dest.height()}, options.duration, options.easing);
                } else if (options.adjustHeight === 'auto') {
                    destHeight = $dest.height();
                    if (parseFloat(sourceHeight) < parseFloat(destHeight)) {
                        // Adjust the height now so that the items don't move out of the container
                        $sourceParent.css('height', destHeight);
                    } else {
                        //  Adjust later, on callback
                        adjustHeightOnCallback = true;
                    }
                }
     
                // Now it's time to do shuffling animation
                // First of all, we need to identify same elements within source and destination collections    
                $source.each(function (i) {
                    var destElement = [];
                    if (typeof(options.attribute) == 'function') {
     
                        val = options.attribute($(this));
                        $collection.each(function() {
                            if (options.attribute(this) == val) {
                                destElement = $(this);
                                return false;
                            }
                        });
                    } else {
                        destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                    }
                    if (destElement.length) {
                        // The item is both in source and destination collections
                        // It it's under different position, let's move it
                        if (!options.useScaling) {
                            animationQueue.push(
                                                {
                                                    element: $(this), 
                                                    animation: 
                                                        {top: destElement.offset().top - correctionOffset.top, 
                                                         left: destElement.offset().left - correctionOffset.left, 
                                                         opacity: 1.0
                                                        }
                                                });
     
                        } else {
                            animationQueue.push({
                                                element: $(this), 
                                                animation: {top: destElement.offset().top - correctionOffset.top, 
                                                            left: destElement.offset().left - correctionOffset.left, 
                                                            opacity: 1.0, 
                                                            scale: '1.0'
                                                           }
                                                });
     
                        }
                    } else {
                        // The item from source collection is not present in destination collections
                        // Let's remove it
                        if (!options.useScaling) {
                            animationQueue.push({element: $(this), 
                                                 animation: {opacity: '0.0'}});
                        } else {
                            animationQueue.push({element: $(this), animation: {opacity: '0.0', 
                                             scale: '0.0'}});
                        }
                    }
                });
     
                $collection.each(function (i) {
                    // Grab all items from target collection not present in visible source collection
     
                    var sourceElement = [];
                    var destElement = [];
                    if (typeof(options.attribute) == 'function') {
                        val = options.attribute($(this));
                        $source.each(function() {
                            if (options.attribute(this) == val) {
                                sourceElement = $(this);
                                return false;
                            }
                        });                 
     
                        $collection.each(function() {
                            if (options.attribute(this) == val) {
                                destElement = $(this);
                                return false;
                            }
                        });
                    } else {
                        sourceElement = $source.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                        destElement = $collection.filter('[' + options.attribute + '=' + $(this).attr(options.attribute) + ']');
                    }
     
                    var animationOptions;
                    if (sourceElement.length === 0) {
                        // No such element in source collection...
                        if (!options.useScaling) {
                            animationOptions = {
                                opacity: '1.0'
                            };
                        } else {
                            animationOptions = {
                                opacity: '1.0',
                                scale: '1.0'
                            };
                        }
                        // Let's create it
                        d = destElement.clone();
                        var rawDestElement = d.get(0);
                        rawDestElement.style.position = 'absolute';
                        rawDestElement.style.margin = '0';
                        rawDestElement.style.top = destElement.offset().top - correctionOffset.top + 'px';
                        rawDestElement.style.left = destElement.offset().left - correctionOffset.left + 'px';
                        d.css('opacity', 0.0); // IE
                        if (options.useScaling) {
                            d.css('transform', 'scale(0.0)');
                        }
                        d.appendTo($sourceParent);
     
                        animationQueue.push({element: $(d), 
                                             animation: animationOptions});
                    }
                });
     
                $dest.remove();
                options.enhancement($sourceParent); // Perform custom visual enhancements during the animation
                for (i = 0; i < animationQueue.length; i++) {
                    animationQueue[i].element.animate(animationQueue[i].animation, options.duration, options.easing, postCallback);
                }
            });
        };
    })(jQuery);
    et le script de tri :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    $(document).ready(function(){
      var pclone = $(".portfolio").clone();
     
      $("#sort a").on("click", function(e){
        e.preventDefault();
        var sorttype = $(this).attr("class");
     
        // determine if another link is selected
        if(!$(this).hasClass("selected")) {
          $("#sort a").removeClass("selected");
          $(this).addClass("selected");
        }
     
        // check filter sort type
        if(sorttype == "all") {
          var filterselect = pclone.find("li");
        } else {
          var filterselect = pclone.find("li[class="+sorttype+"]");
        }
     
        $(".portfolio").quicksand(filterselect, 
        {
          adjustHeight: 'auto',
          duration: 550
        }, function() { 
          // callback function
        });
     
      }); // end click event listener
    });
    J'ai lu que l'on pouvait simuler un clic avec la fonction suivante :

    $("#filterOptions li a.print").trigger('click');

    Mais cela ne fonctionne pas ou alors je ne sais pas exactement où l'insérer.

    Je ne suis pas spécialiste Javascript mais j'essaie d'adapter ce plugin pour mon site, si quelqu'un aurait une piste je suis preneur.

    Merci.

  2. #2
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut
    merci de poster les question JQuery dans le forum JQuery
    A+JYT

Discussions similaires

  1. [AC-2003] Filtre et suppression de filtre de sous formulaires
    Par meud007 dans le forum VBA Access
    Réponses: 2
    Dernier message: 02/04/2012, 23h36
  2. Filtre/Plugin ImageJ sous Eclipse
    Par onylink dans le forum ImageJ
    Réponses: 0
    Dernier message: 29/03/2010, 15h16
  3. Suppression des filtres
    Par zeralium dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 31/08/2007, 16h05
  4. [M2] Plugin assembly & filtres
    Par rseM2 dans le forum Maven
    Réponses: 4
    Dernier message: 27/10/2006, 18h10
  5. [Plugin] Bouton browse projet avec filtre
    Par jcarre dans le forum Eclipse Platform
    Réponses: 4
    Dernier message: 09/04/2004, 13h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo