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 :

Visionneuse ne fonctionne pas sous IE


Sujet :

JavaScript

  1. #1
    Membre confirm�
    Homme Profil pro
    Inscrit en
    F�vrier 2006
    Messages
    217
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 217
    Par d�faut Visionneuse ne fonctionne pas sous IE
    Bonjour � tous!

    Voil� mon probl�me, j'ai une vivionneuse (lightbox+carousel) qui fonctionne parfaitement sous FF, mais pas du tout sous IE
    www.sanair.fr
    Voici le code JS:

    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
     
    <script type="text/javascript">
                           // <![CDATA[
                           // Delay response
                           Ajax.Request.prototype.originalInitialize = Ajax.Request.prototype.initialize;
                           Ajax.Request.prototype.initialize = function(url, options) {
                           options.onSuccess = options.onSuccess.wrap(function(proceed, request, json) {
                           proceed.curry(request, json).delay(1);
                           });
                           this.originalInitialize(url, options);
                           }
     
          // Mock ajax response
          Ajax.Response.prototype._getHeaderJSON = function() {
            var nbElements = 12;
     
            var template = '<li></li>';
            var from = this.request.parameters.from;
            var to   = Math.min(nbElements, this.request.parameters.to);
            var html = $R(from, to).inject("", function(html, n) { return html + template.gsub("XX", n); });
      	    return {html: html, from: from, to: to, more: to != nbElements};
          }
     
          var carousel = null;
          function runTest() {
            updateCarouselSize();
            carousel = new UI.Ajax.Carousel("horizontal_carousel", {url: "carousel/test/fixtures/ajax_carousel_content.html", elementSize:250})
              .observe("request:started", function() {
    	            $('spinner').show().morph("opacity:0.8", {duration:0.5});
                })
              .observe("request:ended", function() {
    	            $('spinner').morph("opacity:0", {duration:0.5, afterFinish: function(obj) { obj.element.hide(); }});
                });
          }
     
          function resized() {
            updateCarouselSize();  
            if (carousel)
              carousel.updateSize();
          }
     
          function updateCarouselSize() {
    		    var dim = document.viewport.getDimensions(); 
    		    dim.width -= 20;                             
            $("horizontal_carousel").style.width = dim.width + "px";
            $$("#horizontal_carousel .container").first().style.width =  (dim.width - 680) + "px";
          }
     
          Event.observe(window, "load", runTest);
          Event.observe(window, "resize", resized);
        // ]]>
        </script>
    N'�tant pas assez exp�riment� en JS, voyez-vous ce qui ne passe pas sous IE?

    Merci!

  2. #2
    Expert confirm�
    Avatar de le_chomeur
    Profil pro
    D�veloppeur informatique
    Inscrit en
    F�vrier 2006
    Messages
    3 653
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activit� : D�veloppeur informatique

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 3 653
    Par d�faut
    Salut

    de mon cot� cela marche sous ie7 et FF mais sous les deux j'ai une erreur javascript li� a :

    $("spinner") has no properties
    v�rifis dans ta page que spinner existe bien ( en tant qu'id )

  3. #3
    Membre confirm�
    Homme Profil pro
    Inscrit en
    F�vrier 2006
    Messages
    217
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 217
    Par d�faut
    Ah oui? C'est bizarre, moi sous FF, j'ai pas d'erreur.

    Bon j'ai enlever le spinner, tu peux me dire si il y a toujours l'erreur sous FF et IE7?

    Et sous IE6, rien ne fonctionne lol. En fin ce sont les fl�ches qui ne fonctionne pas, il n'y pas de d�roulement.

    Merci

  4. #4
    Expert confirm�
    Avatar de le_chomeur
    Profil pro
    D�veloppeur informatique
    Inscrit en
    F�vrier 2006
    Messages
    3 653
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activit� : D�veloppeur informatique

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 3 653
    Par d�faut
    idem ... sur un rollover

  5. #5
    Membre confirm�
    Homme Profil pro
    Inscrit en
    F�vrier 2006
    Messages
    217
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 217
    Par d�faut
    Rhoooo

    Je vais regarder cela.

    Sinon, est-ce que IE6 accepte le JS?

  6. #6
    Expert confirm�
    Avatar de le_chomeur
    Profil pro
    D�veloppeur informatique
    Inscrit en
    F�vrier 2006
    Messages
    3 653
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activit� : D�veloppeur informatique

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 3 653
    Par d�faut
    lol oui

  7. #7
    Membre confirm�
    Homme Profil pro
    Inscrit en
    F�vrier 2006
    Messages
    217
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 217
    Par d�faut
    J'ai insatall� IE 7, et je n'ai aucune erreur qui s'affiche. Comment tu fais pour voir les erreurs?

    Par contre, quelques soit la version IE, le clique sur les fl�ches ne fonctionne pas...

    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
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
     
     
    if(typeof Prototype == 'undefined' || !Prototype.Version.match("1.6"))
      throw("Prototype-UI library require Prototype library >= 1.6.0");
     
    if (Prototype.Browser.WebKit) {
      Prototype.Browser.WebKitVersion = parseFloat(navigator.userAgent.match(/AppleWebKit\/([\d\.\+]*)/)[1]);
      Prototype.Browser.Safari2 = (Prototype.Browser.WebKitVersion < 420);
    }
     
    if (Prototype.Browser.IE) {
      Prototype.Browser.IEVersion = parseFloat(navigator.appVersion.split(';')[1].strip().split(' ')[1]);
      Prototype.Browser.IE6 =  Prototype.Browser.IEVersion == 6;
      Prototype.Browser.IE7 =  Prototype.Browser.IEVersion == 7;
    }
     
    Prototype.falseFunction = function() { return false };
    Prototype.trueFunction  = function() { return true  };
     
     
     
    var UI = {
      Abstract: { },
      Ajax: { }
    };
    Object.extend(Class.Methods, {
      extend: Object.extend.methodize(),
     
      addMethods: Class.Methods.addMethods.wrap(function(proceed, source) {
        // ensure we are not trying to add null or undefined
        if (!source) return this;
     
        // no callback, vanilla way
        if (!source.hasOwnProperty('methodsAdded'))
          return proceed(source);
     
        var callback = source.methodsAdded;
        delete source.methodsAdded;
        proceed(source);
        callback.call(source, this);
        source.methodsAdded = callback;
     
        return this;
      }),
     
      addMethod: function(name, lambda) {
        var methods = {};
        methods[name] = lambda;
        return this.addMethods(methods);
      },
     
      method: function(name) {
        return this.prototype[name].valueOf();
      },
     
      classMethod: function() {
        $A(arguments).flatten().each(function(method) {
          this[method] = (function() {
            return this[method].apply(this, arguments);
          }).bind(this.prototype);
        }, this);
        return this;
      },
     
      // prevent any call to this method
      undefMethod: function(name) {
        this.prototype[name] = undefined;
        return this;
      },
     
      // remove the class' own implementation of this method
      removeMethod: function(name) {
        delete this.prototype[name];
        return this;
      },
     
      aliasMethod: function(newName, name) {
        this.prototype[newName] = this.prototype[name];
        return this;
      },
     
      aliasMethodChain: function(target, feature) {
        feature = feature.camelcase();
     
        this.aliasMethod(target+"Without"+feature, target);
        this.aliasMethod(target, target+"With"+feature);
     
        return this;
      }
    });
    Object.extend(Number.prototype, {
      // Snap a number to a grid
      snap: function(round) {
        return parseInt(round == 1 ? this : (this / round).floor() * round);
      }
    });
    /*
    Interface: String
     
    */
     
    Object.extend(String.prototype, {
      camelcase: function() {
        var string = this.dasherize().camelize();
        return string.charAt(0).toUpperCase() + string.slice(1);
      },
     
     
      makeElement: function() {
        var wrapper = new Element('div'); wrapper.innerHTML = this;
        return wrapper.down();
      }
    });
    Object.extend(Array.prototype, {
      empty: function() {
        return !this.length;
      },
     
      extractOptions: function() {
        return this.last().constructor === Object ? this.pop() : { };
      },
     
      removeAt: function(index) {
        var object = this[index];
        this.splice(index, 1);
        return object;
      },
     
      remove: function(object) {
        var index;
        while ((index = this.indexOf(object)) != -1)
          this.removeAt(index);
        return object;
      },
     
      insert: function(index) {
        var args = $A(arguments);
        args.shift();
        this.splice.apply(this, [ index, 0 ].concat(args));
        return this;
      }
    });
    Element.addMethods({
      getScrollDimensions: function(element) {
        return {
          width:  element.scrollWidth,
          height: element.scrollHeight
        }
      },
     
      getScrollOffset: function(element) {
        return Element._returnOffset(element.scrollLeft, element.scrollTop);
      },
     
      setScrollOffset: function(element, offset) {
        element = $(element);
        if (arguments.length == 3)
          offset = { left: offset, top: arguments[2] };
        element.scrollLeft = offset.left;
        element.scrollTop  = offset.top;
        return element;
      },
     
      // returns "clean" numerical style (without "px") or null if style can not be resolved
      // or is not numeric
      getNumStyle: function(element, style) {
        var value = parseFloat($(element).getStyle(style));
        return isNaN(value) ? null : value;
      },
     
      // by Tobie Langel (http://tobielangel.com/2007/5/22/prototype-quick-tip)
      appendText: function(element, text) {
        element = $(element);
        text = String.interpret(text);
        element.appendChild(document.createTextNode(text));
        return element;
      }
    });
     
    document.whenReady = function(callback) {
      if (document.loaded)
        callback.call(document);
      else
        document.observe('dom:loaded', callback);
    };
     
    Object.extend(document.viewport, {
      // Alias this method for consistency
      getScrollOffset: document.viewport.getScrollOffsets,
     
      setScrollOffset: function(offset) {
        Element.setScrollOffset(Prototype.Browser.WebKit ? document.body : document.documentElement, offset);
      },
     
      getScrollDimensions: function() {
        return Element.getScrollDimensions(Prototype.Browser.WebKit ? document.body : document.documentElement);
      }
    });
     
     
    (function() {
      UI.Options = {
        methodsAdded: function(klass) {
          klass.classMethod($w(' setOptions allOptions optionsGetter optionsSetter optionsAccessor '));
        },
     
        // Group: Methods
     
        /*
          Method: setOptions
            Extends object's *options* property with the given object
        */
        setOptions: function(options) {
          if (!this.hasOwnProperty('options'))
            this.options = this.allOptions();
     
          this.options = Object.extend(this.options, options || {});
        },
     
        /*
          Method: allOptions
            Computes the complete default options hash made by reverse extending all superclasses
            default options.
     
            > Widget.prototype.allOptions();
        */
        allOptions: function() {
          var superclass = this.constructor.superclass, ancestor = superclass && superclass.prototype;
          return (ancestor && ancestor.allOptions) ?
              Object.extend(ancestor.allOptions(), this.options) :
              Object.clone(this.options);
        },
     
        /*
          Method: optionsGetter
            Creates default getters for option names given as arguments.
            With no argument, creates getters for all option names.
        */
        optionsGetter: function() {
          addOptionsAccessors(this, arguments, false);
        },
     
        /*
          Method: optionsSetter
            Creates default setters for option names given as arguments.
            With no argument, creates setters for all option names.
        */
        optionsSetter: function() {
          addOptionsAccessors(this, arguments, true);
        },
     
        /*
          Method: optionsAccessor
            Creates default getters/setters for option names given as arguments.
            With no argument, creates accessors for all option names.
        */
        optionsAccessor: function() {
          this.optionsGetter.apply(this, arguments);
          this.optionsSetter.apply(this, arguments);
        }
      };
     
      // Internal
      function addOptionsAccessors(receiver, names, areSetters) {
        names = $A(names).flatten();
     
        if (names.empty())
          names = Object.keys(receiver.allOptions());
     
        names.each(function(name) {
          var accessorName = (areSetters ? 'set' : 'get') + name.camelcase();
     
          receiver[accessorName] = receiver[accessorName] || (areSetters ?
            // Setter
            function(value) { return this.options[name] = value } :
            // Getter
            function()      { return this.options[name]         });
        });
      }
    })();
    /*
      Class: UI.Carousel
     
      Main class to handle a carousel of elements in a page. A carousel :
        * could be vertical or horizontal
        * works with liquid layout
        * is designed by CSS
     
      Assumptions:
        * Elements should be from the same size
     
      Example:
        > ...
        > <div id="horizontal_carousel">
        >   <div class="previous_button"></div>
        >   <div class="container">
        >     <ul>
        >       <li> What ever you like</li>
        >     </ul>
        >   </div>
        >   <div class="next_button"></div>
        > </div>
        > <script>
        > new UI.Carousel("horizontal_carousel");
        > </script>
        > ...
    */
    UI.Carousel = Class.create(UI.Options, {
      // Group: Options
      options: {
    	// Property: direction
    	//   Can be horizontal or vertical, horizontal by default
        direction               : "horizontal",
     
        // Property: previousButton
        //   Selector of previous button inside carousel element, ".previous_button" by default,
        //   set it to false to ignore previous button
        previousButton          : ".previous_button",
     
        // Property: nextButton
        //   Selector of next button inside carousel element, ".next_button" by default,
        //   set it to false to ignore next button
        nextButton              : ".next_button",
     
        // Property: container
        //   Selector of carousel container inside carousel element, ".container" by default,
        container               : ".container",
     
        // Property: scrollInc
        //   Define the maximum number of elements that gonna scroll each time, auto by default
        scrollInc               : "auto",
     
        // Property: disabledButtonSuffix
        //   Define the suffix classanme used when a button get disabled, to '_disabled' by default
        //   Previous button classname will be previous_button_disabled
        disabledButtonSuffix : '_disabled',
     
        // Property: overButtonSuffix
        //   Define the suffix classanme used when a button has a rollover status, '_over' by default
        //   Previous button classname will be previous_button_over
        overButtonSuffix : '_over'
      },
     
      /*
        Group: Attributes
     
          Property: element
            DOM element containing the carousel
     
          Property: id
            DOM id of the carousel's element
     
          Property: container
            DOM element containing the carousel's elements
     
          Property: elements
            Array containing the carousel's elements as DOM elements
     
          Property: previousButton
            DOM id of the previous button
     
          Property: nextButton
            DOM id of the next button
     
          Property: posAttribute
            Define if the positions are from left or top
     
          Property: dimAttribute
            Define if the dimensions are horizontal or vertical
     
          Property: elementSize
            Size of each element, it's an integer
     
          Property: nbVisible
            Number of visible elements, it's a float
     
          Property: animating
            Define whether the carousel is in animation or not
      */
     
      /*
        Group: Events
          List of events fired by a carousel
     
          Notice: Carousel custom events are automatically namespaced in "carousel:" (see Prototype custom events).
     
          Examples:
            This example will observe all carousels
            > document.observe('carousel:scroll:ended', function(event) {
            >   alert("Carousel with id " + event.memo.carousel.id + " has just been scrolled");
            > });
     
            This example will observe only this carousel
            > new UI.Carousel('horizontal_carousel').observe('scroll:ended', function(event) {
            >   alert("Carousel with id " + event.memo.carousel.id + " has just been scrolled");
            > });
     
          Property: previousButton:enabled
            Fired when the previous button has just been enabled
     
          Property: previousButton:disabled
            Fired when the previous button has just been disabled
     
          Property: nextButton:enabled
            Fired when the next button has just been enabled
     
          Property: nextButton:disabled
            Fired when the next button has just been disabled
     
          Property: scroll:started
            Fired when a scroll has just started
     
          Property: scroll:ended
            Fired when a scroll has been done,
            memo.shift = number of elements scrolled, it's a float
     
          Property: sizeUpdated
            Fired when the carousel size has just been updated.
            Tips: memo.carousel.currentSize() = the new carousel size
      */
     
      // Group: Constructor
     
      /*
        Method: initialize
          Constructor function, should not be called directly
     
        Parameters:
          element - DOM element
          options - (Hash) list of optional parameters
     
        Returns:
          this
      */
      initialize: function(element, options) {
        this.setOptions(options);
        this.element = $(element);
        this.id = this.element.id;
        this.container   = this.element.down(this.options.container).firstDescendant();
        this.elements    = this.container.childElements();
        this.previousButton = this.options.previousButton == false ? null : this.element.down(this.options.previousButton);
        this.nextButton = this.options.nextButton == false ? null : this.element.down(this.options.nextButton);
     
        this.posAttribute = (this.options.direction == "horizontal" ? "left" : "top");
        this.dimAttribute = (this.options.direction == "horizontal" ? "width" : "height");
     
        this.elementSize = this.computeElementSize();
        this.nbVisible = this.currentSize() / this.elementSize;
     
        var scrollInc = this.options.scrollInc;
        if (scrollInc == "auto")
          scrollInc = Math.floor(this.nbVisible);
        [ this.previousButton, this.nextButton ].each(function(button) {
          if (!button) return;
          var className = (button == this.nextButton ? "next_button" : "previous_button") + this.options.overButtonSuffix;
          button.clickHandler = this.scroll.bind(this, (button == this.nextButton ? -1 : 1) * scrollInc * this.elementSize);
          button.observe("click", button.clickHandler)
     
        }, this);
        this.updateButtons();
      },
     
      // Group: Destructor
     
      /*
        Method: destroy
          Cleans up DOM and memory
      */
      destroy: function($super) {
        [ this.previousButton, this.nextButton ].each(function(button) {
          if (!button) return;
            button.stopObserving("click", button.clickHandler);
        }, this);
    	  this.element.remove();
    	  this.fire('destroyed');
      },
     
      // Group: Event handling
     
      /*
        Method: fire
          Fires a carousel custom event automatically namespaced in "carousel:" (see Prototype custom events).
          The memo object contains a "carousel" property referring to the carousel.
     
        Example:
          > document.observe('carousel:scroll:ended', function(event) {
          >   alert("Carousel with id " + event.memo.carousel.id + " has just been scrolled");
          > });
     
        Parameters:
          eventName - an event name
          memo      - a memo object
     
        Returns:
          fired event
      */
      fire: function(eventName, memo) {
        memo = memo || { };
        memo.carousel = this;
        return this.element.fire('carousel:' + eventName, memo);
      },
     
      /*
        Method: observe
          Observe a carousel event with a handler function automatically bound to the carousel
     
        Parameters:
          eventName - an event name
          handler   - a handler function
     
        Returns:
          this
      */
      observe: function(eventName, handler) {
        this.element.observe('carousel:' + eventName, handler.bind(this));
        return this;
      },
     
      /*
        Method: stopObserving
          Unregisters a carousel event, it must take the same parameters as this.observe (see Prototype stopObserving).
     
        Parameters:
          eventName - an event name
          handler   - a handler function
     
        Returns:
          this
      */
      stopObserving: function(eventName, handler) {
    	  this.element.stopObserving('carousel:' + eventName, handler);
    	  return this;
      },
     
      // Group: Actions
     
      /*
        Method: checkScroll
          Check scroll position to avoid unused space at right or bottom
     
        Parameters:
          position       - position to check
          updatePosition - should the container position be updated ? true/false
     
        Returns:
          position
      */
      checkScroll: function(position, updatePosition) {
        if (position > 0)
          position = 0;
        else {
          var limit = this.elements.last().positionedOffset()[this.posAttribute] + this.elementSize;
          var carouselSize = this.currentSize();
     
          if (position + limit < carouselSize)
            position += carouselSize - (position + limit);
          position = Math.min(position, 0);
        }
        if (updatePosition)
          this.container.style[this.posAttribute] = position + "px";
     
        return position;
      },
     
      /*
        Method: scroll
          Scrolls carousel from maximum deltaPixel
     
        Parameters:
          deltaPixel - a float
     
        Returns:
          this
      */
      scroll: function(deltaPixel) {
        if (this.animating)
          return this;
     
        // Compute new position
        var position =  this.currentPosition() + deltaPixel;
     
        // Check bounds
        position = this.checkScroll(position, false);
     
        // Compute shift to apply
        deltaPixel = position - this.currentPosition();
        if (deltaPixel != 0) {
          this.animating = true;
          this.fire("scroll:started");
     
          var that = this;
          // Move effects
          this.container.morph("opacity:0.5", {duration: 0.2, afterFinish: function() {
            that.container.morph(that.posAttribute + ": " + position + "px", {
              duration: 0.4,
              delay: 0.2,
              afterFinish: function() {
                that.container.morph("opacity:1", {
                  duration: 0.2,
                  afterFinish: function() {
                    that.animating = false;
                    that.updateButtons()
                      .fire("scroll:ended", { shift: deltaPixel / that.currentSize() });
                  }
                });
              }
            });
          }});
        }
        return this;
      },
     
      /*
        Method: scrollTo
          Scrolls carousel, so that element with specified index is the left-most.
          This method is convenient when using carousel in a tabbed navigation.
          Clicking on first tab should scroll first container into view, clicking on a fifth - fifth one, etc.
          Indexing starts with 0.
     
        Parameters:
          Index of an element which will be a left-most visible in the carousel
     
        Returns:
          this
      */
      scrollTo: function(index) {
        if (this.animating || index < 0 || index > this.elements.length || index == this.currentIndex() || isNaN(parseInt(index)))
          return this;
        return this.scroll((this.currentIndex() - index) * this.elementSize);
      },
     
      /*
        Method: updateButtons
          Update buttons status to enabled or disabled
          Them status is defined by classNames and fired as carousel's custom events
     
        Returns:
          this
      */
      updateButtons: function() {
    	  this.updatePreviousButton();
        this.updateNextButton();
        return this;
      },
     
      updatePreviousButton: function() {
        var position = this.currentPosition();
        var previousClassName = "previous_button" + this.options.disabledButtonSuffix;
     
        if (this.previousButton.hasClassName(previousClassName) && position != 0) {
          this.previousButton.removeClassName(previousClassName);
          this.fire('previousButton:enabled');
        }
        if (!this.previousButton.hasClassName(previousClassName) && position == 0) {
    	    this.previousButton.addClassName(previousClassName);
          this.fire('previousButton:disabled');
        }
      },
     
      updateNextButton: function() {
        var lastPosition = this.currentLastPosition();
        var size = this.currentSize();
        var nextClassName = "next_button" + this.options.disabledButtonSuffix;
     
        if (this.nextButton.hasClassName(nextClassName) && lastPosition != size) {
          this.nextButton.removeClassName(nextClassName);
          this.fire('nextButton:enabled');
        }
        if (!this.nextButton.hasClassName(nextClassName) && lastPosition == size) {
    	    this.nextButton.addClassName(nextClassName);
          this.fire('nextButton:disabled');
        }
      },
     
      // Group: Size and Position
     
      /*
        Method: computeElementSize
          Return elements size in pixel, height or width depends on carousel orientation.
     
        Returns:
          an integer value
      */
      computeElementSize: function() {
        return this.elements.first().getDimensions()[this.dimAttribute];
      },
     
      /*
        Method: currentIndex
          Returns current visible index of a carousel.
          For example, a horizontal carousel with image #3 on left will return 3 and with half of image #3 will return 3.5
          Don't forget that the first image have an index 0
     
        Returns:
          a float value
      */
      currentIndex: function() {
        return - this.currentPosition() / this.elementSize;
      },
     
      /*
        Method: currentLastPosition
          Returns the current position from the end of the last element. This value is in pixel.
     
        Returns:
          an integer value, if no images a present it will return 0
      */
      currentLastPosition: function() {
        if (this.container.childElements().empty())
          return 0;
        return this.currentPosition() +
               this.elements.last().positionedOffset()[this.posAttribute] +
               this.elementSize;
      },
     
      /*
        Method: currentPosition
          Returns the current position in pixel.
          Tips: To get the position in elements use currentIndex()
     
        Returns:
          an integer value
      */
      currentPosition: function() {
        return this.container.getNumStyle(this.posAttribute);
      },
     
      /*
        Method: currentSize
          Returns the current size of the carousel in pixel
     
        Returns:
          Carousel's size in pixel
      */
      currentSize: function() {
        return this.container.parentNode.getDimensions()[this.dimAttribute];
      },
     
      /*
        Method: updateSize
          Should be called if carousel size has been changed (usually called with a liquid layout)
     
        Returns:
          this
      */
      updateSize: function() {
        this.nbVisible = this.currentSize() / this.elementSize;
        var scrollInc = this.options.scrollInc;
        if (scrollInc == "auto")
          scrollInc = Math.floor(this.nbVisible);
     
        [ this.previousButton, this.nextButton ].each(function(button) {
          if (!button) return;
          button.stopObserving("click", button.clickHandler);
          button.clickHandler = this.scroll.bind(this, (button == this.nextButton ? -1 : 1) * scrollInc * this.elementSize);
          button.observe("click", button.clickHandler);
        }, this);
     
        this.checkScroll(this.currentPosition(), true);
        this.updateButtons().fire('sizeUpdated');
        return this;
      }
    });
    /*
      Class: UI.Ajax.Carousel
     
      Gives the AJAX power to carousels. An AJAX carousel :
        * Use AJAX to add new elements on the fly
     
      Example:
        > new UI.Ajax.Carousel("horizontal_carousel",
        >   {url: "get-more-elements", elementSize: 250});
    */
    UI.Ajax.Carousel = Class.create(UI.Carousel, {
      // Group: Options
      //
      //   Notice:
      //     It also include of all carousel's options
      options: {
    	// Property: elementSize
    	//   Required, it define the size of all elements
        elementSize : -1,
     
    	// Property: url
    	//   Required, it define the URL used by AJAX carousel to request new elements details
        url         : null
      },
     
      /*
        Group: Attributes
     
          Notice:
            It also include of all carousel's attributes
     
          Property: elementSize
            Size of each elements, it's an integer
     
          Property: endIndex
            Index of the last loaded element
     
          Property: hasMore
            Flag to define if there's still more elements to load
     
          Property: requestRunning
            Define whether a request is processing or not
     
          Property: updateHandler
            Callback to update carousel, usually used after request success
     
          Property: url
            URL used to request additional elements
      */
     
      /*
        Group: Events
          List of events fired by an AJAX carousel, it also include of all carousel's custom events
     
          Property: request:started
            Fired when the request has just started
     
          Property: request:ended
            Fired when the request has succeed
      */
     
      // Group: Constructor
     
      /*
        Method: initialize
          Constructor function, should not be called directly
     
        Parameters:
          element - DOM element
          options - (Hash) list of optional parameters
     
        Returns:
          this
      */
      initialize: function($super, element, options) {
        if (!options.url)
          throw("url option is required for UI.Ajax.Carousel");
        if (!options.elementSize)
          throw("elementSize option is required for UI.Ajax.Carousel");
     
        $super(element, options);
     
        this.endIndex = 0;
        this.hasMore  = true;
     
        // Cache handlers
        this.updateHandler = this.update.bind(this);
        this.updateAndScrollHandler = function(nbElements, transport, json) {
    	    this.update(transport, json);
    	    this.scroll(nbElements);
    	  }.bind(this);
     
        // Run first ajax request to fill the carousel
        this.runRequest.bind(this).defer({parameters: {from: 0, to: Math.ceil(this.nbVisible) - 1}, onSuccess: this.updateHandler});
      },
     
      // Group: Actions
     
      /*
        Method: runRequest
          Request the new elements details
     
        Parameters:
          options - (Hash) list of optional parameters
     
        Returns:
          this
      */
      runRequest: function(options) {
        this.requestRunning = true;
        new Ajax.Request(this.options.url, Object.extend({method: "GET"}, options));
        this.fire("request:started");
        return this;
      },
     
      /*
        Method: scroll
          Scrolls carousel from maximum deltaPixel
     
        Parameters:
          deltaPixel - a float
     
        Returns:
          this
      */
      scroll: function($super, deltaPixel) {
        if (this.animating || this.requestRunning)
          return this;
     
        var nbElements = (-deltaPixel) / this.elementSize;
        // Check if there is not enough
        if (this.hasMore && nbElements > 0 && this.currentIndex() + this.nbVisible + nbElements - 1 > this.endIndex) {
          var from = this.endIndex + 1;
          var to   = Math.ceil(from + this.nbVisible - 1);
          this.runRequest({parameters: {from: from, to: to}, onSuccess: this.updateAndScrollHandler.curry(deltaPixel).bind(this)});
          return this;
        }
        else
          $super(deltaPixel);
      },
     
      /*
        Method: update
          Update the carousel
     
        Parameters:
          transport - XMLHttpRequest object
          json      - JSON object
     
        Returns:
          this
      */
      update: function(transport, json) {
        this.requestRunning = false;
        this.fire("request:ended");
        if (!json)
          json = transport.responseJSON;
        this.hasMore = json.more;
     
        this.endIndex = Math.max(this.endIndex, json.to);
        this.elements = this.container.insert({bottom: json.html}).childElements();
        return this.updateButtons();
      },
     
      // Group: Size and Position
     
      /*
        Method: computeElementSize
          Return elements size in pixel
     
        Returns:
          an integer value
      */
      computeElementSize: function() {
        return this.options.elementSize;
      },
     
      /*
        Method: updateSize
          Should be called if carousel size has been changed (usually called with a liquid layout)
     
        Returns:
          this
      */
      updateSize: function($super) {
        var nbVisible = this.nbVisible;
        $super();
        // If we have enough space for at least a new element
        if (Math.floor(this.nbVisible) - Math.floor(nbVisible) >= 1 && this.hasMore) {
          if (this.currentIndex() + Math.floor(this.nbVisible) >= this.endIndex) {
            var nbNew = Math.floor(this.currentIndex() + Math.floor(this.nbVisible) - this.endIndex);
            this.runRequest({parameters: {from: this.endIndex + 1, to: this.endIndex + nbNew}, onSuccess: this.updateHandler});
          }
        }
        return this;
      },
     
      updateNextButton: function($super) {
        var lastPosition = this.currentLastPosition();
        var size = this.currentSize();
        var nextClassName = "next_button" + this.options.disabledButtonSuffix;
     
        if (this.nextButton.hasClassName(nextClassName) && lastPosition != size) {
          this.nextButton.removeClassName(nextClassName);
          this.fire('nextButton:enabled');
        }
        if (!this.nextButton.hasClassName(nextClassName) && lastPosition == size && !this.hasMore) {
    	    this.nextButton.addClassName(nextClassName);
          this.fire('nextButton:disabled');
        }
      }
    });
    IL y a t-il quelques chose dans ce code que IE n'accepte pas?
    Comment savoir ce que IE et FF acceptent et n'acceptent pas?

    Merci

  8. #8
    Membre confirm�
    Homme Profil pro
    Inscrit en
    F�vrier 2006
    Messages
    217
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : F�vrier 2006
    Messages : 217
    Par d�faut
    Arf, je suis trop b�te, je chargeais 2 "prototype.js" diff�rents...

    Merci � tous!

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Script ne fonctionne pas sous IE
    Par Stessy dans le forum G�n�ral JavaScript
    R�ponses: 13
    Dernier message: 29/09/2005, 13h44
  2. [CSS] Effet de hover qui ne fonctionne pas sous IE
    Par Ricou13 dans le forum Mise en page CSS
    R�ponses: 6
    Dernier message: 14/06/2005, 09h39
  3. R�ponses: 18
    Dernier message: 19/08/2004, 15h11
  4. Java ne fonctionne pas sous Firefox
    Par Info-Rital dans le forum Applications et environnements graphiques
    R�ponses: 2
    Dernier message: 29/07/2004, 23h37
  5. R�ponses: 6
    Dernier message: 27/01/2004, 11h14

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