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 :

Appel d'un script à partir d'un module de forum


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 8
    Par défaut Appel d'un script à partir d'un module de forum
    Bonjour,

    J'ai quelque petits problèmes pour faire appel à un code javascript depuis un "module" dans un forum ForumActif.

    Je ne comprend pas d'ou vient le problème... Est ce l'appel qui ne fonctionne pas? Ou est-ce le javascript? Ou bien le code fonctionne mais rien ne s'affiche?
    Le problème ne doit pas venir du script en lui même, il y a quelque chose que je rate ailleurs...
    J'ai un doute sur les "document.getElementById" étant donné que mon code se trouve dans un module et non sur une page HTML.


    Voici le code à l'intérieure de mon module :

    Code html : 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
    <head>
    <script type="text/javascript" src="http://originslinkshell.forumgratuit.fr/12078.js">
     
    </script>
     
    </head>
    <body onload="RunEorzeaClock(1325692136);">
     
    	<style type="text/css">
            .MoonTime {
                    color: #BABEBE;
                    text-align: center;
            }
            .Moon {
                    color: #BABEBE;
                    text-align: center;
                    vertical-align: bottom;
                    padding: 0 3px;
            }
            .current_moon {
                    font-weight: bold;
            }
            .moon_width {
                    width: 69px;
            }
            #EorzeaTime {
                    color: #BABEBE;
                    text-align: center;
            }
            #leverefreshdiv {
                    color: #BABEBE;
                    text-align: center;
            }
            </style>
     
    	<table style="width: 987px;margin: 0 auto;">
     
    		<tr>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/newm10.png" width="32px" /><div id="lunar_m1" class="MoonTime"></div></div>
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/waxc10.png" width="32px" /><div id="lunar_m2" class="MoonTime"></div></div>
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/firstq10.png" width="32px" /><div id="lunar_m3" class="MoonTime"></div></div>
     
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/waxg10.png" width="32px" /><div id="lunar_m4" class="MoonTime"></div></div>
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/fullm10.png" width="32px" /><div id="lunar_m5" class="MoonTime"></div></div>
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/wang10.png" width="32px" /><div id="lunar_m6" class="MoonTime"></div></div>
     
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/lastq10.png" width="32px" /><div id="lunar_m7" class="MoonTime"></div></div>
    			</td>
    			<td class="moon_width">
    				<div class="Moon"><img src="http://i45.servimg.com/u/f45/16/35/50/30/wanc10.png" width="32px" /><div id="lunar_m8" class="MoonTime"></div></div>
    			</td>
    			<td class="Moon">
    				<div class="Moon"><span class="current_moon">Eorzea Time:</span><div id="EorzeaTime"></div></div>
     
    			</td>
    			<td class="Moon">
    				<div class="Moon"><span class="current_moon">Reset mandats:</span><div id="leverefreshdiv"></div></div>
    			</td>
    		</tr>
    </table>
    </body>

    Et voici le script Javascript appelé :

    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
    var timestamp;
    var localTimestamp;
    var ratio;
    var formula;
    var mooncount;
    var offset2;
    var moonstart;
    var newmoon;
    var waxcrescent;
    var firstquarter;
    var waxgibbous;
    var fullmoon;
    var wangibbous;
    var lastquarter;
    var wancrescent;
     
    function RunEorzeaClock(serverTimestamp) {
     
        //Adjusting the time
        serverTimestamp = (serverTimestamp + 5) * 1000;
        //Setting timestamp to that of the server
        timestamp = serverTimestamp;
        //Settting local time stamp to current dates time
        localTimestamp = new Date().getTime();
        updateEorzeaTime();
     
        //Information for moonphases
        ratio = 1440 / 70;
        formula = 1000 * 60 * 60 * 24 * 4 / ratio;
        mooncount = new Date();
        offset2 = 21 - mooncount.getTimezoneOffset() / 60;
        moonstart = new Date(2010, 7, 15, offset2, 20, 0);
     
        newmoon = new Date(moonstart.getTime());
        waxcrescent = new Date(moonstart.getTime() + formula);
        firstquarter = new Date(moonstart.getTime() + formula * 2);
        waxgibbous = new Date(moonstart.getTime() + formula * 3);
        fullmoon = new Date(moonstart.getTime() + formula * 4);
        wangibbous = new Date(moonstart.getTime() + formula * 5);
        lastquarter = new Date(moonstart.getTime() + formula * 6);
        wancrescent = new Date(moonstart.getTime() + formula * 7);
     
        UpdateMoons();
     
        LeveRefresh();
     
    }
     
    function updateEorzeaTime() {
     
        var now = new Date();
     
        //Converting current time to Eorzean
        //getTime function returns UNIX UTC timestamp
        var tmpTime = ((timestamp + now.getTime() - localTimestamp) / 1000) * 4188615725;
     
        var EorzeanYear = parseInt(tmpTime / 562949953421312);
        EorzeanYear -= 9519;
        EorzeanYear /= 12;
        EorzeanYear = parseInt(EorzeanYear);
     
        var EorzeanMonth = parseInt(tmpTime / 562949953421312);
        EorzeanMonth = EorzeanMonth % 12;
        EorzeanMonth++;
        EorzeanMonth = parseInt(EorzeanMonth);
     
        var EorzeanDay = parseInt(tmpTime / 17592186044416);
        EorzeanDay &= 31;
        EorzeanDay++;
        EorzeanDay = parseInt(EorzeanDay);
     
        var tmpTime = ((timestamp + now.getTime() - localTimestamp) / 1000) * 24
        var EorzeanHour = parseInt(tmpTime / 4200);
        EorzeanHour %= 24;
     
        tmpTime = ((timestamp + now.getTime() - localTimestamp) / 1000) * 1440;
        var EorzeanMinute = parseInt(tmpTime / 4200);
        EorzeanMinute -= 10;
        EorzeanMinute %= 60;
     
        //adding '0' before hours and minutes if less than 10
        if (EorzeanHour < 10) EorzeanHour = "0" + EorzeanHour;
        if (EorzeanMinute < 10) EorzeanMinute = "0" + EorzeanMinute;
     
        document.getElementById("EorzeaTime").innerHTML = EorzeanHour + ':' + EorzeanMinute + ', ' + EorzeanMonth + '/' + EorzeanDay + '/' + EorzeanYear;
     
        t = setTimeout('updateEorzeaTime()', 1000);
    }
     
    function UpdateMoons() {
     
        //gets the value per moon
        var moon1 = LunarCalendarRefresh(newmoon, 'moon1');
        var moon2 = LunarCalendarRefresh(waxcrescent, 'moon2');
        var moon3 = LunarCalendarRefresh(firstquarter, 'moon3');
        var moon4 = LunarCalendarRefresh(waxgibbous, 'moon4');
        var moon5 = LunarCalendarRefresh(fullmoon, 'moon5');
        var moon6 = LunarCalendarRefresh(wangibbous, 'moon6');
        var moon7 = LunarCalendarRefresh(lastquarter, 'moon7');
        var moon8 = LunarCalendarRefresh(wancrescent, 'moon8');
     
        //transfer the content to the dom respectively
        if (document.getElementById("lunar_m1"))
            document.getElementById("lunar_m1").innerHTML = moon1;
        if (document.getElementById("lunar_m2"))
            document.getElementById("lunar_m2").innerHTML = moon2;
        if (document.getElementById("lunar_m3"))
            document.getElementById("lunar_m3").innerHTML = moon3;
        if (document.getElementById("lunar_m4"))
            document.getElementById("lunar_m4").innerHTML = moon4;
        if (document.getElementById("lunar_m5"))
            document.getElementById("lunar_m5").innerHTML = moon5;
        if (document.getElementById("lunar_m6"))
            document.getElementById("lunar_m6").innerHTML = moon6;
        if (document.getElementById("lunar_m7"))
            document.getElementById("lunar_m7").innerHTML = moon7;
        if (document.getElementById("lunar_m8"))
            document.getElementById("lunar_m8").innerHTML = moon8;
     
        //if moons' value is default then we need much faster refresh to get the proper time the soonest
        if (moon1 == '00 : 00 : 00' && moon2 == '00 : 00 : 00' && moon3 == '00 : 00 : 00' && moon4 == '00 : 00 : 00' && moon5 == '00 : 00 : 00' && moon6 == '00 : 00 : 00' && moon7 == '00 : 00 : 00' && moon8 == '00 : 00 : 00')
            m = setTimeout('UpdateMoons()', 1);
        else
            m = setTimeout('UpdateMoons()', 500);
    }
     
    function LunarCalendarRefresh(adjust, moon) {
        //00 : 00 : 00 set as the default value
        var value = '00 : 00 : 00';
        var now = new Date();
        // difference will be the countdown time for each moon
        difference = adjust.getTime() - (timestamp + now.getTime() - localTimestamp);
        if (difference > 0) {
            //translate to hours
            hours = Math.floor(difference / (60 * 60 * 1000));
            difference -= hours * 60 * 60 * 1000;
            //translate to min
            minutes = Math.floor(difference / (60 * 1000));
            difference -= minutes * 60 * 1000;
            //translate to sec
            seconds = Math.floor(difference / 1000);
     
            //if single digit then add padding-left '0'
            if (hours < 10) hours = "0" + hours;
            if (minutes < 10) minutes = "0" + minutes;
            if (seconds < 10) seconds = "0" + seconds;
     
            value = hours + " : " + minutes + " : " + seconds;
        }
        else {
            if ((adjust.getTime() + formula) < (timestamp + now.getTime() - localTimestamp)) {
                temp = adjust.getTime();
                adjust.setTime(temp + formula * 8);
            }
            else {
                //if difference <= 0 then the moon will be the current moon
                value = '<span class="current_moon">&nbsp&nbsp;&nbsp;&nbsp;Current&nbsp;&nbsp;&nbsp;</span>';
                //change the big moon current
                if (document.getElementById("lb_lunar_calendar_icon"))
                    document.getElementById("lb_lunar_calendar_icon").className = 'icon ' + moon;
                //change the langbar moon current
                if (document.getElementById("moon_image"))
                    document.getElementById("moon_image").className = 'moon ' + moon;
            }
        }
        return value;
    }
     
    function LeveRefresh() {
        var now = new Date();
        //compute time passed between a UNIX timestamp when we had a guild refresh and the current UNIX timestamp
        var difference = (timestamp + now.getTime() - localTimestamp) - Date.UTC(2010, 11, 10, 12);
        if (isNaN(difference))
            return;
     
        //resets happens every 36 hrs, so find out how many resets we had in the passed time
        var resetsSoFar = Math.floor(difference / (12 * 60 * 60 * 1000));
        //compute the next reset
        var nextReset = (resetsSoFar + 1) * 12 * 60 * 60 * 1000;
        //next reset will occur in
        difference = nextReset - difference;
     
        //translate to hours
        var hours = Math.floor(difference / (60 * 60 * 1000));
        difference -= hours * 60 * 60 * 1000;
        //translate to min
        var minutes = Math.floor(difference / (60 * 1000));
        difference -= minutes * 60 * 1000;
        //translate to sec
        var seconds = Math.floor(difference / 1000);
     
        //if single digit then add padding-left '0'
        if (hours < 10) hours = "0" + hours;
        if (minutes < 10) minutes = "0" + minutes;
        if (seconds < 10) seconds = "0" + seconds;
     
        //refresh the lunar clock with current value
        if (document.getElementById("leverefreshdiv"))
            document.getElementById("leverefreshdiv").innerHTML = hours + "h " + minutes + "m " + seconds + "s";
     
        setTimeout('LeveRefresh()', 200);
    }

  2. #2
    Membre Expert
    Avatar de RomainVALERI
    Homme Profil pro
    POOête
    Inscrit en
    Avril 2008
    Messages
    2 652
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : POOête

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 652
    Par défaut hors-sujet : refactorisation
    Loin de moi l'idée d'entreprendre avec toi une refactorisation complète ^^

    Mais ce genre de structures...
    Code javascript : 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
    var moonTypes = [];
    newmoon = new Date(moonstart.getTime());
    waxcrescent = new Date(moonstart.getTime() + formula);
    firstquarter = new Date(moonstart.getTime() + formula * 2);
    waxgibbous = new Date(moonstart.getTime() + formula * 3);
    fullmoon = new Date(moonstart.getTime() + formula * 4);
    wangibbous = new Date(moonstart.getTime() + formula * 5);
    lastquarter = new Date(moonstart.getTime() + formula * 6);
    wancrescent = new Date(moonstart.getTime() + formula * 7);
     
    //gets the value per moon
    var moon1 = LunarCalendarRefresh(newmoon, 'moon1');
    var moon2 = LunarCalendarRefresh(waxcrescent, 'moon2');
    var moon3 = LunarCalendarRefresh(firstquarter, 'moon3');
    var moon4 = LunarCalendarRefresh(waxgibbous, 'moon4');
    var moon5 = LunarCalendarRefresh(fullmoon, 'moon5');
    var moon6 = LunarCalendarRefresh(wangibbous, 'moon6');
    var moon7 = LunarCalendarRefresh(lastquarter, 'moon7');
    var moon8 = LunarCalendarRefresh(wancrescent, 'moon8');
     
    //transfer the content to the dom respectively
    if (document.getElementById("lunar_m1"))
    document.getElementById("lunar_m1").innerHTML = moon1;
    if (document.getElementById("lunar_m2"))
    document.getElementById("lunar_m2").innerHTML = moon2;
    if (document.getElementById("lunar_m3"))
    document.getElementById("lunar_m3").innerHTML = moon3;
    if (document.getElementById("lunar_m4"))
    document.getElementById("lunar_m4").innerHTML = moon4;
    if (document.getElementById("lunar_m5"))
    document.getElementById("lunar_m5").innerHTML = moon5;
    if (document.getElementById("lunar_m6"))
    document.getElementById("lunar_m6").innerHTML = moon6;
    if (document.getElementById("lunar_m7"))
    document.getElementById("lunar_m7").innerHTML = moon7;
    if (document.getElementById("lunar_m8"))
    document.getElementById("lunar_m8").innerHTML = moon8;
    ...peut, après examen des parties communes et quelques refactorisations, ressembler grosso modo à...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    var MOON_TYPE_NAMES = ["newmoon", "waxcrescent", "firstquarter", "waxgibbous", "fullmoon", "wangibbous", "lastquarter", "wancrescent"];
    for (var m, i = 1; i <= MOON_TYPE_NAMES.length; ++i) {
       m = new Date(moonstart.getTime()) + formula * (i - 1);
       document.getElementById("lunar_m" + i).innerHTML = LunarCalendarRefresh(m, 'moon' + i);
    }
    ^^

    (et à la place d'accéder aux variables moon1, moon2, etc., tu crées un tableau moons, alimenté en ajoutant une ligne dans la boucle que je te propose, et tu pourras accéder au contenu par indice.)

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 8
    Par défaut
    Ah oui c'est vrai merci du conseil, vu que c'est pas moi l'auteur de ce code et que j'ai juste essayé de me l'approprier j'avais pas vraiment fait gaffe à ça.

    Cela dit je ne pense pas que le problème vienne de la...

  4. #4
    Membre Expert
    Avatar de RomainVALERI
    Homme Profil pro
    POOête
    Inscrit en
    Avril 2008
    Messages
    2 652
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : POOête

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 652
    Par défaut
    Citation Envoyé par Jeremy Lepretre Voir le message
    Cela dit je ne pense pas que le problème vienne de la...
    Non, carrément pas. (comme le suggérait le titre de mon post : "hors-sujet..." )

    En passant : balises CODE autour des extraits s'il te plait épargne nos pauvres yeux

  5. #5
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Si je comprends bien, le code de ton module est inséré dans ta page.
    Ceci dit, ton module contient des balises <head> et <body> qui n'ont rien à y faire et qui sont probablement sources de dysfonctionnements...
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  6. #6
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2011
    Messages : 8
    Par défaut
    Oui c'est exactement ca Bovino, j'ai retiré les balises head et body, merci.
    Du coup je ne comprend pas comment faire appel à ma fonction depuis mon module.

    Donc comment déclencher la fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <body onload="RunEorzeaClock(1325692136);">
    sans le body onload?

    j'ai mis
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <a href="javascript:RunEorzeaClock(1325692136);"></a>
    Mais cela ne fonctionne toujours pas

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Appeler un code java à partir d'un script shell
    Par supcomingenieur dans le forum Shell et commandes GNU
    Réponses: 3
    Dernier message: 06/06/2013, 16h01
  2. Appel d'un script js à partir d'une page html
    Par developppez dans le forum Général JavaScript
    Réponses: 14
    Dernier message: 04/06/2008, 20h59
  3. Appel des fonctions à partir d'un module
    Par walf80 dans le forum VB 6 et antérieur
    Réponses: 42
    Dernier message: 21/03/2007, 12h56
  4. Réponses: 7
    Dernier message: 30/09/2004, 12h19
  5. [Kylix] Appel d'un script depuis un Kylix...
    Par paty.olivier dans le forum EDI
    Réponses: 9
    Dernier message: 13/05/2004, 16h04

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