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 :

Ecriture de script dans un fichier


Sujet :

JavaScript

  1. #1
    Membre actif Avatar de katoyi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    101
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 101
    Par défaut Ecriture de script dans un fichier
    Bonsoir à tous,
    J'ai un soucis dans l'écriture d'un code javascript.
    Voilà, lorsque j'écris le script dans le même fichier que ma page HTML, ca marche, mais dès que je sort le script dans un fichier JS que j'intègre dans ma page, ca ne marche plus. Auriez vous une solution ou une explication?
    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
     
    //FSMenu est une classe que j'ai télécharger pour la gestion des menus déroulant.
    listMenu = new FSMenu(listMenu, true, 'display', 'block', 'none');
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animFade;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animSwipeDown;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animClipDown;
        var arrow = null;
        if (document.createElement && document.documentElement)
        {
            arrow = document.createElement('span');
            arrow.appendChild(document.createTextNode(''));
            arrow.className = 'subind';
        }
        addReadyEvent(new Function('listMenu.activateMenu("listMenuRoot", arrow)'));
    Merci à vous.

  2. #2
    Membre éclairé Avatar de SPACHFR
    Profil pro
    Paaaaaa
    Inscrit en
    Février 2004
    Messages
    557
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Paaaaaa

    Informations forums :
    Inscription : Février 2004
    Messages : 557
    Par défaut
    Salut,

    Es tu sur du path de ton fichier js ?

  3. #3
    Membre actif Avatar de katoyi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    101
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 101
    Par défaut
    Citation Envoyé par SPACHFR Voir le message
    Salut,

    Es tu sur du path de ton fichier js ?
    Absolument sûr.

  4. #4
    Expert confirmé

    Homme Profil pro
    Développeur Web
    Inscrit en
    Septembre 2010
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 5 418
    Par défaut
    Et la classe FSMenu est bien dans ce même fichier ?

  5. #5
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonsoir,

    Peut-être que ton script est mis en brut après les éléments HTML nécessaire et que quand tu le mets dans un autre fichier, tu l'appelles dans le head alors que les éléments ne sont pas encore chargé sur le DOM.

    A+.

  6. #6
    Membre actif Avatar de katoyi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    101
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 101
    Par défaut
    Citation Envoyé par andry.aime Voir le message
    Bonsoir,

    Peut-être que ton script est mis en brut après les éléments HTML nécessaire et que quand tu le mets dans un autre fichier, tu l'appelles dans le head alors que les éléments ne sont pas encore chargé sur le DOM.

    A+.
    J'ai pas très bien compris ce que tu veux dire par là.
    Néanmoins, j'ai déplacé l'appel de la fonction qui à la fin de mon fichier html mais rien ne s'est passé.

  7. #7
    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
    si tu montrait comment tu l'inclus ça aiderait

    en aparté valable pour tout le monde
    Lors que vous avez un pb que ça marche dans un cas et pas dans l'autre le contenu du code est rarement la cause c'est la façon de l'utiliser qui l'est donc sans connaîtrais ses façons pas de solution.

    A+JYT

  8. #8
    Membre actif Avatar de katoyi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    101
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 101
    Par défaut
    Citation Envoyé par sekaijin Voir le message
    si tu montrait comment tu l'inclus ça aiderait

    en aparté valable pour tout le monde
    Lors que vous avez un pb que ça marche dans un cas et pas dans l'autre le contenu du code est rarement la cause c'est la façon de l'utiliser qui l'est donc sans connaîtrais ses façons pas de solution.

    A+JYT
    Désolé, le week end a fait que j'ai pas pu continuer le fil de la discussion
    Bon voila, je mets le code
    Code JS que j'ai ecrit dans un fichier js.js et qui ne marche 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
     
    /* 
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    function pushMenu(){
        var listMenu = new FSMenu(listMenu, true, 'display', 'block', 'none');
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animFade;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animSwipeDown;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animClipDown;
        var arrow = null;
        if (document.createElement && document.documentElement)
        {
            arrow = document.createElement('span');
            arrow.appendChild(document.createTextNode(''));
            arrow.className = 'subind';
        }
        addReadyEvent(new Function(listMenu.activateMenu("listMenuRoot", arrow)));
    }
    Code HTLM
    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
    <html><html xmlns="http://www.w3.org/1999/xhtml" ><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Bienvenue .....</title>
     
    <link  href="listmenu_o.css" rel="stylesheet" type="text/css" media="all" />
    <meta name="robots" content="no-cache" />
    <meta name="robots" content="no-cache" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
    <script  type="text/javascript" src="fsmenu.js"></script>
    <script  type="text/javascript" src="js.js"></script>
    </script>
    </head>
    <body>
    <table class="" width="100%" cellpadding="0"  cellspacing="0"  border="0"  >
              <tr><td colspan="2" height=""></td></tr>     <tr>
                      <td width="10px" height="" class=""></td>
                      <td class="mm_millieu1">
                        <ul class="menulist" id="listMenuRoot">
                            <li><a href="revisions">R&eacute;visions</a>
     
                                <ul>
                                    <li><a href="revisions/planifier">Planifier</a></li>
                                    <li><a href="revisions/rechercher">Rechercher</a></li>
                                </ul>
                            </li>
                        </ul>
                      </td>
                  </tr>        
    </table>
    <script type="text/javascript">
         var listMenu = "listMenu";
         var listMenuRoot = "listMenuRoot";
         pushMenu();
     
        /*var listMenu = new FSMenu(listMenu, true, 'display', 'block', 'none');
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animFade;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animSwipeDown;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animClipDown;
        var arrow = null;
        if (document.createElement && document.documentElement)
        {
            arrow = document.createElement('span');
            arrow.appendChild(document.createTextNode(''));
            arrow.className = 'subind';
        }
        addReadyEvent(new Function(listMenu.activateMenu("listMenuRoot", arrow)));*/
        </script>
     
     
    </body>
    </html>
    Le code commenté marche mais le pushMenu ne marche pas
    Le code CSS
    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
    .inputForm {
        background-image:url(form_bg.jpg);
        background-repeat:repeat-x;
        border:1px solid #d1c7ac;
        width: 230px;
        color:#333333;
        padding:3px;
        margin-right:4px;
        margin-bottom:8px;
        font-family:tahoma, arial, sans-serif;
    }
     
     
     
    .menulist, .menulist ul {
     margin: 0;
     padding: 1px;
     width: 170px;
     list-style: none;
     border: none;
     background-image: url("mm_millieu1.png");
    }
     
    /* Submenus (<ul> tags) are hidden and absolutely positioned across from their parent */
    .menulist ul {
     display: none;
     position: absolute;
     top: 0;
     left: 180px;
    }
     
    /* All menu items (<li> tags) are relatively positioned (to correctly offset submenus). */
    .menulist li {
     position: relative;
    }
     
    /* Links inside the menu */
    .menulist li a {
     display: block;
     padding: 3px 4px 3px 30px;
     color: #000;
     text-decoration: none;
     border: 1px solid transparent;
     margin: 0;
     
    }
    /* HACKS: MSIE6 doesn't support transparent borders, mimic with margins */
    * html .menulist li a {
     border-width: 0;
     margin: 1px;
    }
     
    /*
     Lit items: hover/focus = the current item. 'highlighted' = parent items to visible menus.
     Here, active items are given a border, and a padding tweak to 'elevate' the text within.
     Feel free to use background-image:url(file.gif) instead of background-color:#nnn here...
    */
    .menulist a:hover, .menulist a.highlighted:hover, .menulist a:focus {
     color: #FFF;
     background-image: url("mm_millieu1.png");
     padding: 2px 5px 4px 29px;
     border: 1px solid #ADF;
     margin: 0;
    }
    .menulist a.highlighted {
     color: #FFF;
     background-image: url("mm_millieu1.png");
     border: 0px solid #CDE;
     margin: 0;
    }
     
    /*
     If you want per-item background images in your menu items, here's how to do it.
     1) Assign a unique ID tag to each link in your menu, like so: <a id="xyz" href="#">
     2) Copy and paste these next lines for each link you want to have an image:
        .menulist a#xyz {
          background-image: url(out.gif);
        }
        .menulist a#xyz:hover, .menulist a.highlighted#xyz, .menulist a:focus {
         background-image: url(over.gif);
        }
    */
     
     
    /* 'subind' submenu indicators, which are automatically prepended to 'A' tag contents. */
    .menulist a .subind {
     float: right;
    }
     
    /*
     HACKS: IE/Win:
     A small height on <li> and <a> tags and floating prevents gaps in menu.
     * html affects <=IE6 and *:first-child+html affects IE7.
     You may want to move these to browser-specific style sheets.
    \*/
    *:first-child+html .menulist li {
     float: left;
     width: 100%;
    }
     
    * html .menulist li {
     float: left;
     height: 1%;
    }
    * html .menulist a {
     height: 1%;
    }
    /* End Hacks */
    Code FSMenu qui gère le menu
    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
     
    /*
     
    FREESTYLE MENUS v1.0 RC (c) 2001-2009 Angus Turnbull, http://www.twinhelix.com
    Altering this notice or redistributing this file is prohibited.
     
    */
     
     
     
    // This is the full, commented script file, to use for reference purposes or if you feel
    // like tweaking anything. I used the "CodeTrimmer" utility availble from my site
    // (under 'Miscellaneous' scripts) to trim the comments out of this JS file.
     
     
     
    // *** COMMON CROSS-BROWSER COMPATIBILITY CODE ***
     
     
    // This is taken from the "Modular Layer API" available on my site.
    // See that for the readme if you are extending this part of the script.
     
    var isDOM=document.getElementById?1:0,
     isIE=document.all?1:0,
     isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,
     isOp=self.opera?1:0,
     isDyn=isDOM||isIE||isNS4;
     
    function getRef(i, p)
    {
     p=!p?document:p.navigator?p.document:p;
     return isIE ? p.all[i] :
      isDOM ? (p.getElementById?p:p.ownerDocument).getElementById(i) :
      isNS4 ? p.layers[i] : null;
    };
     
    function getSty(i, p)
    {
     var r=getRef(i, p);
     return r?isNS4?r:r.style:null;
    };
     
    if (!self.LayerObj) var LayerObj = new Function('i', 'p',
     'this.ref=getRef(i, p); this.sty=getSty(i, p); return this');
    function getLyr(i, p) { return new LayerObj(i, p) };
     
    function LyrFn(n, f)
    {
     LayerObj.prototype[n] = new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px"; ' +
      'with (this) { '+f+' }');
    };
    LyrFn('x','if (!isNaN(p)) sty.left=p+px; else return parseInt(sty.left)');
    LyrFn('y','if (!isNaN(p)) sty.top=p+px; else return parseInt(sty.top)');
     
     
    if (typeof addEvent != 'function')
    {
     var addEvent = function(o, t, f, l)
     {
      var d = 'addEventListener', n = 'on' + t;
      if (o[d] && !l) return o[d](t, f, false);
      if (!o._evts) o._evts = {};
      if (!o._evts[t])
      {
       o._evts[t] = {};
       if (o[n]) addEvent(o, t, o[n], l);
       o[n] = new Function('e',
        'var r = true, o = this, a = o._evts["' + t + '"], i; for (i in a) {' +
        'o._f = a[i]; if (o._f._i) r = o._f(e||window.event) != false && r;' +
        '} o._f = null; return r');
      }
      if (!f._i) f._i = addEvent._i++;
      o._evts[t][f._i] = f;
      if (t != 'unload') addEvent(window, 'unload', function() {
       removeEvent(o, t, f, l);
      });
     };
     addEvent._i = 1;
     var removeEvent = function(o, t, f, l)
     {
      var d = 'removeEventListener';
      if (o[d] && !l) return o[d](t, f, false);
      if (o._evts && o._evts[t] && f._i) delete o._evts[t][f._i];
     };
    }
     
     
    var addReadyEvent = function(f)
    {
     // Calls a function 'f' when the document DOM has loaded.
     var a = addReadyEvent, n = null;
     addEvent(a, 'ready', f);
     if (!a.r)
     {
      a.r = function()
      {
       clearInterval(t);
       if (a.r) a.onready();
       a.r = null;
      };
      addEvent(document, 'DOMContentLoaded', a.r);
      addEvent(window, 'load', a.r);
      /*@if (@_win32)
      n = document.createElement('document:ready');
      /*@end @*/
     
      var t = setInterval(function()
      {
       if (/complete|loaded/.test(document.readyState))
       {
        if (!n) a.r();
        else try
        {
         n.doScroll('left');
         n = null;
         a.r();
        } catch (e) {}
       }
      }, 50);
     }
    };
     
     
    // *** CORE MENU OBJECT AND FUNCTIONS ***
     
     
    function FSMenu(myName, nested, cssProp, cssVis, cssHid)
    {
     // This is the base object that users create.
     // It stores menu properties, and has a 'menus' associative array to store a list of menu nodes,
     // and allow timeouts to refer to nodes by name (e.g. menuObject.menus.nodeName).
     
     this.myName = myName;
     this.nested = nested;
     // Some CSS settings users can specify.
     this.cssProp = cssProp;
     this.cssVis = cssVis;
     this.cssHid = cssHid;
     this.cssLitClass = 'highlighted';
     // The 'root' menu only exists for list menus, and is created in the activation function.
     // For non-nested menus, here's an imaginary node that acts as a parent to other nodes.
     this.menus = nested ? {} : { root: new FSMenuNode('root', true, this) };
     this.menuToShow = [];
     this.mtsTimer = null;
     // Other configurable defaults.
     this.showDelay = 0;
     this.switchDelay = 125;
     this.hideDelay = 500;
     this.showOnClick = 0;
     this.hideOnClick = true;
     // Animation speeds: set to a number between 0 and 1. Larger = faster. 1 = disabled.
     this.animInSpeed = 0.2;
     this.animOutSpeed = 0.2;
     this.animations = [];
     
     // Free memory onunload in IE.
     //if (isIE && !isOp) addEvent(window, 'unload', new Function(myName + ' = null'));
    };
     
     
     
     
    FSMenu.prototype.show = function(mN) { with (this)
    {
     // Set menuToShow to the function parameters. Use a loop to copy values so we don't leak memory.
     menuToShow.length = arguments.length;
     for (var i = 0; i < arguments.length; i++) menuToShow[i] = arguments[i];
     // Use a timer to call a virtual 'root' menu over() function for non-nested menus.
     // For nested/list menus event bubbling will call the real root menu node over() function.
     clearTimeout(mtsTimer);
     if (!nested) mtsTimer = setTimeout(myName + '.menus.root.over()', 10);
    }};
     
     
    FSMenu.prototype.hide = function(mN) { with (this)
    {
     // Clear the above timer and route the hide event to the appropriate menu node.
     clearTimeout(mtsTimer);
     if (menus[mN]) menus[mN].out();
    }};
     
     
    FSMenu.prototype.hideAll = function() { with (this)
    {
     // Hides all non-root menus, mercilessly!
     for (var m in menus)
      if (menus[m].visible && !menus[m].isRoot) menus[m].hide(true);
    }};
     
     
     
     
    function FSMenuNode(id, isRoot, obj)
    {
     // Each menu is represented by a FSMenuNode object.
     // This is the node constructor function, with the properties and functions needed by that node.
     // It's passed its own name in the menus[] array, whether this is a root level menu (boolean),
     // and a reference to the parent FSMenu object.
     
     this.id = id;
     this.isRoot = isRoot;
     this.obj = obj;
     this.lyr = this.child = this.par = this.timer = this.visible = null;
     this.args = [];
     var node = this;
     
     
     // These next per-node over/out functions are an example of closures in JavaScript.
     // Since they're instantiated here, they can use the node's variables as if they were their own.
     
     this.over = function(evt) { with (node) with (obj)
     {
      // Basically, over() gets called when the onmouseover event reaches the menu container,
      // which might be a DIV or UL tag in the document. The event source is a tag inside
      // that container that calls FSMenu.show() and sets the menuToShow array (see above).
      // Browsers will then 'bubble' the event upwards, reaching this function which is set
      // as the onmouseoover/focus/click handler on a menu container. This picks up the
      // properties in menuToShow and shows the given menu as a child of this one.
      // Note that for non-nested menus there is a default timer (mtsTimer) that will mimic
      // an outermost 'root' menu that picks up the event if no other menus intercept it first.
     
      // Ensure NS4 calls the show/hide function within this layer first.
      if (isNS4 && evt && lyr.ref) lyr.ref.routeEvent(evt);
      // Stop this menu hiding itself and intercept the default root show handler (if any).
      clearTimeout(timer);
      clearTimeout(mtsTimer);
     
      // A quick check; if this menu isn't visible, show it (i.e. cancel any animation).
      if (!isRoot && !visible) node.show();
     
      if (menuToShow.length)
      {
       // Pull information out of menuToShow[].
       var a = menuToShow, m = a[0];
       if (!menus[m] || !menus[m].lyr.ref) menus[m] = new FSMenuNode(m, false, obj);
       // c = reference to new child menu that will be shown.
       var c = menus[m];
       // Just clear the menuToShow array and return if we're "showing" the current menu...!
       if (c == node)
       {
        menuToShow.length = 0;
        return;
       }
       // Otherwise, stop any impending show/hide of the child menu, and check if it's a new child.
       clearTimeout(c.timer);
       if (c != child && c.lyr.ref)
       {
        // We have a genuinely new child menu to show. Give it some properties, set a timer to show it.
        // Again, try and avoid memory leaks, but copy over the a/menuToShow arguments.
        c.args.length = a.length;
        for (var i = 0; i < a.length; i++) c.args[i] = a[i];
        // Decide which delay to use: switchDelay if we already have a child menu, showDelay otherwise.
        var delay = child ? switchDelay : showDelay;
        c.timer = setTimeout('with(' + myName + ') { menus["' + c.id + '"].par = menus["' +
         node.id + '"]; menus["' + c.id + '"].show() }', delay ? delay : 1);
       }
       // Try, try, try to avoid leaking memory... :).
       menuToShow.length = 0;
      }
     
      // For non-nested menus, mimic event bubbling.
      if (!nested && par) par.over();
     }};
     
     
     this.out = function(evt) { with (node) with (obj)
     {
      // Basically the same as over(), this cancels impending events and sets a hide timer.
      if (isNS4 && evt && lyr && lyr.ref) lyr.ref.routeEvent(evt);
      clearTimeout(timer);
      // We never hide the root menu. Otherwise, mimic event-bubbling for non-nested menus.
      if (!isRoot && hideDelay >= 0)
      {
       timer = setTimeout(myName + '.menus["' + id + '"].hide()', hideDelay);
       if (!nested && par) par.out();
      }
     }};
     
     
     // Finally, now we have created our menu node, get a layer object for the right ID'd element
     // in the page, and assign it onmouseout/onmouseover events.
     // Don't do for virtual root node (in the case of non-nested menus).
     if (id != 'root') with (this) with (lyr = getLyr(id)) if (ref)
     {
      if (isNS4) ref.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
      addEvent(ref, 'mouseover', this.over);
      addEvent(ref, 'mouseout', this.out);
      // For nested UL/LI menus, assign focus/blur events for accessibility.
      if (obj.nested)
      {
       addEvent(ref, 'focus', this.over, 1);
       addEvent(ref, 'click', this.over);
       addEvent(ref, 'blur', this.out, 1);
      }
     }
    };
     
     
     
     
    FSMenuNode.prototype.show = function(forced) { with (this) with (obj)
    {
     // This is called to show the menu node of which it's a method.
     // It sets the parent's child to this, and hides any existing children of the parent node.
     if (!lyr || !lyr.ref) return;
     
     if (par)
     {
      if (par.child && par.child != this) par.child.hide();
      par.child = this;
     }
     
     // This is the positioning routine, it can be deleted if you're not using it.
     // It pulls values out of the stored args[] array, and uses the page.elmPos function in the
     // cross-browser code to find the pixel position of the parent item + menu.
     var offR = args[1], offX = args[2], offY = args[3], lX = 0, lY = 0,
      doX = ''+offX!='undefined', doY = ''+offY!='undefined';
     if (self.page && offR && (doX||doY))
     {
      with (page.elmPos(offR, par.lyr ? par.lyr.ref : 0)) lX = x, lY = y;
      if (doX) lyr.x(lX + eval(offX));
      if (doY) lyr.y(lY + eval(offY));
     }
     
     // Highlight the triggering element, if any.
     if (offR) lightParent(offR, 1);
     
     // Show the menu and trigger any 'onshow' events.
     // Also raise the parent <li> to avoid z-index issues in MSIE.
     visible = 1;
     if (obj.onshow) obj.onshow(id);
     lyr.ref.parentNode.style.zIndex = '2';
     setVis(1, forced);
    }};
     
     
    FSMenuNode.prototype.hide = function(forced) { with (this) with (obj)
    {
     // Same as show() above, but this clears the child/parent settings and hides the menu.
     if (!lyr || !lyr.ref || !visible) return;
     
     // This is an NS4 hack as its mouse events are notoriously unreliable. Remove as needed.
     if (isNS4 && self.isMouseIn && isMouseIn(lyr.ref)) return show();
     // Dim the triggering element.
     if (args[1]) lightParent(args[1], 0);
     
     // Route the hide call through any child nodes, and clear the par/child references.
     if (child) child.hide();
     if (par && par.child == this) par.child = null;
     
     // Hide the menu node element, trigger an 'onhide' event if set, lower the
     // parent <li> and finally show the menu.
     if (lyr)
     {
      visible = 0;
      if (obj.onhide) obj.onhide(id);
      lyr.ref.parentNode.style.zIndex = '1';
      setVis(0, forced);
     }
    }};
     
     
    FSMenuNode.prototype.lightParent = function(elm, lit) { with (this) with (obj)
    {
     // This is passed a reference to the parent triggering element, and whether it is lit or not.
     
     if (!cssLitClass || isNS4) return;
     // By default the cssLitClass value is appended/removed to any existing class.
     // Otherwise, if hiding, remove all trailing instances of it (in case of script errors).
     if (lit) elm.className += (elm.className?' ':'') + cssLitClass;
     else elm.className = elm.className.replace(new RegExp('(\\s*' + cssLitClass + ')+$'), '');
    }};
     
     
    FSMenuNode.prototype.setVis = function(sh, forced) { with (this) with (obj)
    {
     // This is passed two parameteres: whether its menu is shown (boolean), and
     // whether it's a "forced" animation (can't be interrupted by an unforced one).
     // It sets the chosen CSS property of the menu element, and repeatedly calls itself if
     // one or more animations have been specified in the animations property.
     
     if (lyr.forced && !forced) return;
     lyr.forced = forced;
     lyr.timer = lyr.timer || 0;
     lyr.counter = lyr.counter || 0;
     with (lyr)
     {
      clearTimeout(timer);
      var speed = sh ? animInSpeed : animOutSpeed;
     
      if (!counter) sty[cssProp] = sh ? cssVis : cssHid;
     
      if (isDOM && (speed < 1))
       for (var a = 0; a < animations.length; a++) animations[a](ref, counter, sh);
     
      if (isDOM && (sh ? counter < 1 : counter > 0))
       timer = setTimeout(myName + '.menus["' + id + '"].setVis(' + sh + ',' + (forced||0) + ')', 50);
      else lyr.forced = false;
     
      counter = counter + speed*(sh?1:-1);
      if (counter < 0.001) counter = 0;
      if (counter > 0.999) counter = 1;
     }
    }};
     
     
     
     
    // *** ANIMATION FUNCTIONS ***
     
    // Here are some sample animation functions you can customise.
    // These functions are called with a reference to the menu element being
    // animated, an animation counter variable that changes from 0 to 1 and back,
    // and whether or not the element is currently being shown.
    // They must set properties of 'ref' each frame of the animation.
     
    /*
    // Broken in IE8b2: clipping+alpha bug.
    FSMenu.animSwipeDown = function(ref, counter, show)
    {
     // Backup original top/margin-top, then 'swipe' movement + clipping.
     if (show && (counter == 0))
     {
      ref._fsm_styT = ref.style.top;
      ref._fsm_styMT = ref.style.marginTop;
      ref._fsm_offT = ref.offsetTop || 0;
     }
     var cP = Math.pow(Math.sin(Math.PI * counter / 2), 0.75);
     var clipY = parseInt(ref.offsetHeight * (1 - cP));
     ref.style.clip = (counter == 1 ?
      ((window.opera || navigator.userAgent.indexOf('KHTML') > -1) ? '' :
       'rect(auto, auto, auto, auto)') :
       'rect(' + clipY + 'px, ' + ref.offsetWidth + 'px, ' + ref.offsetHeight + 'px, 0px)');
     if (counter == 1 || (counter < 0.01 && !show))
     {
      ref.style.top = ref._fsm_styT;
      ref.style.marginTop = ref._fsm_styMT;
     }
     else
     {
      ref.style.top = ((0 - clipY) + (ref._fsm_offT)) + 'px';
      ref.style.marginTop = '0';
     }
    };
    */
     
    FSMenu.animSwipeDown = function(ref, counter, show)
    {
     var elm = ref.firstChild.style ? ref.firstChild : ref.firstChild.nextSibling,
      isOldIE = /MSIE\s(5|6|7)\./.test(navigator.userAgent);
     if (!elm) return;
     if (show && (counter == 0))
     {
      if (!elm._fsm_marg) elm._fsm_marg = { 'top': elm.style.marginTop };
      ref._fsm_height = ref.offsetHeight;
     }
     
     if (counter == 1 || (counter < 0.01 && !show))
     {
      ref.style.overflow = 'visible';
      elm.style.marginTop = elm._fsm_marg.top;
      if (isOldIE) ref.style.height = '';
     }
     else
     {
      var cP = Math.pow(Math.sin(Math.PI * counter / 2), 0.75);
      ref.style.overflow = 'hidden';
      if (isOldIE) ref.style.height = (ref._fsm_height * cP) + 'px';
      else elm.style.marginTop = (0 - ref._fsm_height * (1 - cP)) + 'px';
     }
    };
     
    FSMenu.animFade = function(ref, counter, show)
    {
     // Use IE's ActiveX alpha filter or the W3C/Mozilla 'opacity' to fade.
     if (typeof ref.filters == 'unknown') return;
     var f = ref.filters, done = (show ? counter == 1 : counter < 0.01),
      a = /MSIE\s(4|5)/.test(navigator.userAgent) ? 'alpha' :
       'DXImageTransform.Microsoft.Alpha';
     if (f)
     {
      if (!done && ref.style.filter.indexOf(a) == -1)
       ref.style.filter += ' ' + (a == 'alpha' ? a : 'progid:' + a) +
        '(opacity=' + (counter * 100) + ')';
      else if (f.length && f[a])
      {
       if (done) f[a].enabled = false;
       else { f[a].opacity = (counter * 100); f[a].enabled = true }
      }
     }
     else ref.style.opacity = ref.style.MozOpacity = counter * 0.999;
    };
     
    FSMenu.animClipDown = function(ref, counter, show)
    {
     // Clip the menu down like a 'blind'.
     var cP = Math.pow(Math.sin(Math.PI * counter / 2), 0.75);
     ref.style.clip = (counter == 1 ?
      ((window.opera || navigator.userAgent.indexOf('KHTML') > -1) ? '' :
       'rect(auto, auto, auto, auto)') :
       'rect(0, ' + ref.offsetWidth + 'px, '+ (ref.offsetHeight * cP) + 'px, 0px)');
    };
     
     
     
     
     
    // *** LIST MENU ACTIVATION ***
     
     
    // This is only required for activating list-type menus.
    // You can delete it if you're using div-menus only.
     
    FSMenu.prototype.activateMenu = function(id, subInd) { with (this)
    {
     if (!isDOM || !document.documentElement) return;
     
     // First of all, disable the CSS menu behaviour.
     var fsmFB = getRef('fsmenu-fallback');
     if (fsmFB)
     {
      fsmFB.rel = 'alternate stylesheet';
      fsmFB.disabled = true;
     }
     
     // References to menu elements for a given level.
     var a, ul, li, parUL, mRoot = getRef(id), nodes;
     if (!FSMenu._count) FSMenu._count = 1;
     
     // The property of the event object to pass click information up the tree.
     // Safari 1.x is buggy and crashes when you access "returnValue".
     // Also Opera defaults to "false" so use something different there.
     var evtProp = navigator.userAgent.indexOf('Safari') > -1 || isOp ?
      'safRtnVal' : 'returnValue';
     
     // Loop through all sub-lists under the given menu.
     var lists = mRoot.getElementsByTagName('ul');
     for (var i = 0; i < lists.length; i++)
     {
      // Find a parent LI node, if any, by recursing upwards from the UL. Quit if not found.
      li = ul = lists[i];
      while (li)
      {
       if (li.nodeName.toLowerCase() == 'li') break;
       li = li.parentNode;
      }
      if (!li) continue;
      // Next, find the parent UL to that LI node.
      parUL = li;
      while (parUL)
      {
       if (parUL.nodeName.toLowerCase() == 'ul') break;
       parUL = parUL.parentNode;
      }
     
      // Now, find the anchor tag that triggers this menu; it should be a child of the LI.
      a = li.getElementsByTagName('a');
      if (!a) continue;
      a = a.item(0);
     
      // We've found a menu node by now, so give it an ID and event handlers.
      // Only assign a new ID if it doesn't have one already.
      var menuID;
      if (ul.id) menuID = ul.id;
      else
      {
       menuID = myName + '-id-' + FSMenu._count++;
       ul.setAttribute('id', menuID);
      }
      // If already activated, no need to proceed.
      if (menus[menuID] && menus[menuID].lyr.ref == ul) continue;
     
      // New menu node for the <ul>.
      menus[menuID] = new FSMenuNode(menuID, false, this);
     
      // Attach focus/mouse events to the triggering anchor tag.
      // Check if this link will be triggered onclick instead of onmouseover.
      // If so, we only respect mouseovers/focuses when the menu is visible from a click.
      var rootItem = (li.parentNode == mRoot) ? 1 : 0;
      // Create the functions that handle show & hide events.
      var eShow = new Function('with (' + myName + ') { ' +
       'var m = menus["' + menuID + '"], pM = menus["' + parUL.id + '"];' +
       'if (!showOnClick || (showOnClick == 1 && !' + rootItem + ') || ' +
           '((showOnClick <= 2) && ((pM && pM.child) || (m && m.visible))))' +
       'show("' + menuID + '", this) }');
      var eHide = new Function('e', 'if (e.' + evtProp + ' != false) ' +
       myName + '.hide("' + menuID + '")');
      // Assign them to the <a> element.
      addEvent(a, 'mouseover', eShow);
      addEvent(a, 'mouseout', eHide);
      addEvent(a, 'focus', eShow);
      addEvent(a, 'blur', eHide);
      addEvent(a, 'click', new Function('e', 'var s = ' + myName + '.showOnClick, ' +
       'm = ' + myName + '.menus["' + menuID + '"]; ' +
       'if (!((s == 1 && ' + rootItem + ') || s >= 2)) return; ' +
       myName + '[m && m.visible ? "hide" : "show"]("' + menuID + '", this); ' +
       'if (e.cancelable && e.preventDefault) e.preventDefault(); ' +
       'e.' + evtProp + ' = false; return false'));
     
      // Prepend an arrow indicator to the anchor tag content if given.
      if (subInd) a.insertBefore(subInd.cloneNode(true), a.firstChild);
     }
     
     
     // Emulate onfocus/blur event bubbling for accessibility,
     // which allows users to tab/shift+tab through the menus.
     var aNodes = mRoot.getElementsByTagName('a');
     for (var i = 0; i < aNodes.length; i++)
     {
      // A setTimeout helps ensure the focus is always after any blur.
      addEvent(aNodes[i], 'focus', new Function('e', 'var node = this.parentNode; while(node) { ' +
       'if (node.onfocus) node.onfocus(e); node = node.parentNode }'));
      addEvent(aNodes[i], 'blur', new Function('e', 'var node = this.parentNode; while(node) { ' +
       'if (node.onblur) node.onblur(e); node = node.parentNode }'));
     }
     
     // If this menu hides its children onclick, setup that now.
     if (hideOnClick) addEvent(mRoot, 'click', new Function('e', 'if (e.' + evtProp +
      ' != false) ' + myName + '.hideAll()'));
     
     // Create an instance for the root menu data node.
     menus[id] = new FSMenuNode(id, true, this);
    }};
     
     
     
     
    // *** DIV MENU & v4 BROWSER COMPATIBILITY ***
     
     
    // You may freely delete this section if you're only using "list" type menus.
    // This script will "run" in NS4, but I recommend you use my "Cascading Popup Menus" script if you
    // want NS4 users to have an experience comparable to users of modern browsers.
    // You can download it from my site, http://www.twinhelix.com if you're interested.
     
    // 'page' object from layer API code, detects positions of page elements.
    var page = { win: self, minW: 0, minH: 0, MS: isIE&&!isOp,
     db: document.compatMode&&document.compatMode.indexOf('CSS')>-1?'documentElement':'body' };
    page.elmPos=function(e,p)
    {
     var x=0,y=0,w=p?p:this.win;
     e=e?(e.substr?(isNS4?w.document.anchors[e]:getRef(e,w)):e):p;
     if(isNS4){if(e&&(e!=p)){x=e.x;y=e.y};if(p){x+=p.pageX;y+=p.pageY}}
     if (e && this.MS && navigator.platform.indexOf('Mac')>-1 && e.tagName=='A')
     {
      e.onfocus = new Function('with(event){self.tmpX=clientX-offsetX;' +
       'self.tmpY=clientY-offsetY}');
      e.focus();x=tmpX;y=tmpY;e.blur()
     }
     else while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent}
     return{x:x,y:y};
    };
     
     
    if (isNS4)
    {
     // Various NS4 hacks and tweaks. You can delete this if you don't care about NS4 support.
     
     var fsmMouseX, fsmMouseY, fsmOR=self.onresize, nsWinW=innerWidth, nsWinH=innerHeight;
     document.fsmMM=document.onmousemove;
     
     self.onresize = function()
     {
      if (fsmOR) fsmOR();
      if (nsWinW!=innerWidth || nsWinH!=innerHeight) location.reload();
     };
     
     document.captureEvents(Event.MOUSEMOVE);
     document.onmousemove = function(e)
     {
      fsmMouseX = e.pageX;
      fsmMouseY = e.pageY;
      return document.fsmMM?document.fsmMM(e):document.routeEvent(e);
     };
     
     function isMouseIn(sty)
     {
      with (sty) return ((fsmMouseX>left) && (fsmMouseX<left+clip.width) &&
       (fsmMouseY>top) && (fsmMouseY<top+clip.height));
     };
    }
     
     
    function pushMenu(){
        var listMenu = new FSMenu(listMenu, true, 'display', 'block', 'none');
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animFade;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animSwipeDown;
        listMenu.animations
    [listMenu.animations.length] = FSMenu.animClipDown;
        var arrow = null;
        if (document.createElement && document.documentElement)
        {
            arrow = document.createElement('span');
            arrow.appendChild(document.createTextNode(''));
            arrow.className = 'subind';
        }
        addReadyEvent(new Function(listMenu.activateMenu("listMenuRoot", arrow)));
    }

  9. #9
    Membre actif Avatar de katoyi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    101
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 101
    Par défaut
    Alors, ce que j'ai fait c'est normal? Si oui pourquoi ca ne marche pas???

Discussions similaires

  1. [VBA-E]Ecriture de données dans un fichier texte
    Par osito57 dans le forum Macros et VBA Excel
    Réponses: 15
    Dernier message: 18/08/2017, 19h42
  2. Ecriture d'accents dans un fichier
    Par tenshu dans le forum C
    Réponses: 5
    Dernier message: 07/10/2006, 09h26
  3. Enregistrer un script dans un fichier externe
    Par Furius dans le forum Général JavaScript
    Réponses: 12
    Dernier message: 30/11/2005, 12h57
  4. Ecriture par caractere dans un fichier.
    Par SaianSupa dans le forum C
    Réponses: 5
    Dernier message: 29/11/2005, 15h31
  5. ecriture caractere null dans un fichier
    Par Mitox dans le forum C
    Réponses: 5
    Dernier message: 08/11/2005, 15h52

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