Conflit entre deux fichiers .js

Rendre son site dynamique et interactif

Modérateur : Modérateurs

Répondre
bustaflexx
Membre récent
Membre récent
Messages : 8
Enregistré le : 07 févr. 2008, 21:22:58
Localisation : Bxlles

Conflit entre deux fichiers .js

Message par bustaflexx » 28 déc. 2009, 02:46:33

Bonjour,

Le deux scripts marchent tout à fait quand ils sont séparés.
Par contre, une fois mis ensembles, l'un des deux ne fonctionne pas.
J'ai un peu cherché et il semble que c'est un problème avec les deux onload.
J'ai essayé window.onload= {Tabs.Init; LoadJS;}
Mais ça ne marche pas non plus
Any idea please

Ci-bas les deux scripts lib.js et tabs.js

Code : Tout sélectionner


// Bibliothèque Objet
function Ident(Obj){ return (document.all)?document.all[Obj]:document.getElementById(Obj); }
function posX(Obj){ return (Obj.offsetParent)?(Obj.offsetLeft + posX(Obj.offsetParent)):(Obj.offsetLeft); }
function posY(Obj){ return (Obj.offsetParent)?(Obj.offsetTop + posY(Obj.offsetParent)):(Obj.offsetTop); }
function posW(Obj){ return (Obj.offsetParent)?(Obj.offsetWidth + posX(Obj.offsetParent)):(Obj.offsetWidth); }
function posH(Obj){ return (Obj.offsetParent)?(Obj.offsetHeight + posY(Obj.offsetParent)):(Obj.offsetHeight); }

// Détection du click sur menuLeft
function menuDynam(){
	for&#40;m=1; m<5; m++&#41;&#123;
		if&#40;document.all&#41;&#123;
			Ident&#40;'menu'+m&#41;.onmousedown=thisMenu;
		&#125;else&#123;
			Ident&#40;'menu'+m&#41;.addEventListener&#40;"mousedown",thisMenu, false&#41;;
		&#125;
	&#125;
&#125;
function thisMenu&#40;e&#41;&#123; devl&#40;'s'+this.id&#41;; &#125;


// fonction pour réglementation de l'attribut 'target' du W3C
function TargetBlank&#40;&#41; &#123; 
 if &#40;!document.getElementsByTagName&#41; return; 
 var anchors = document.getElementsByTagName&#40;"a"&#41;; 
 for &#40;var i=0; i<anchors.length; i++&#41; &#123; 
	 var anchor = anchors&#91;i&#93;; 
	 if &#40;anchor.getAttribute&#40;"href"&#41; && anchor.getAttribute&#40;"rel"&#41; == "external"&#41; anchor.target = "_blank"; 
 &#125; 
&#125; 


// Fonction menu developpent
function devl&#40;id&#41; &#123;
	var d = Ident&#40;id&#41;, e=false;
	if&#40;d&#41;&#123; if&#40;d.style.display=='block'&#41; e=true; &#125;
	for &#40;var i = 1; i<=10; i++&#41; &#123;
		if &#40;Ident&#40;'smenu'+i&#41;&#41; &#123;Ident&#40;'smenu'+i&#41;.style.display='none';&#125;
	&#125;
	if&#40;d&#41;&#123;
		d.style.display=&#40;e==false&#41;?'block'&#58;'none';
	&#125;
&#125;

function LoadJS&#40;&#41;&#123;
		TargetBlank&#40;&#41;;
		devl&#40;&#41;;
		menuDynam&#40;&#41;;
&#125;

// Executer la fonction
window.onload=LoadJS;

Code : Tout sélectionner

// CSS helper functions
CSS = &#123;
    // Adds a class to an element.
    AddClass&#58; function &#40;e, c&#41; &#123;
        if &#40;!e.className.match&#40;new RegExp&#40;"\\b" + c + "\\b", "i"&#41;&#41;&#41;
            e.className += &#40;e.className ? " " &#58; ""&#41; + c;
    &#125;,

    // Removes a class from an element.
    RemoveClass&#58; function &#40;e, c&#41; &#123;
        e.className = e.className.replace&#40;new RegExp&#40;" \\b" + c + "\\b|\\b" + c + "\\b ?", "gi"&#41;, ""&#41;;
    &#125;
&#125;;

// Functions for handling tabs.
Tabs = &#123;
    // Changes to the tab with the specified ID.
    GoTo&#58; function &#40;contentId, skipReplace&#41; &#123;
        // This variable will be true if a tab for the specified
        // content ID was found.
        var foundTab = false;

        // Get the TOC element.
        var toc = document.getElementById&#40;"toc"&#41;;
        if &#40;toc&#41; &#123;
            var lis = toc.getElementsByTagName&#40;"li"&#41;;
            for &#40;var j = 0; j < lis.length; j++&#41; &#123;
                var li = lis&#91;j&#93;;

                // Give the current tab link the class "current" and
                // remove the class from any other TOC links.
                var anchors = li.getElementsByTagName&#40;"a"&#41;;
                for &#40;var k = 0; k < anchors.length; k++&#41; &#123;
                    if &#40;anchors&#91;k&#93;.hash == "#" + contentId&#41; &#123;
                        CSS.AddClass&#40;li, "current"&#41;;
                        foundTab = true;
                        break;
                    &#125; else &#123;
                        CSS.RemoveClass&#40;li, "current"&#41;;
                    &#125;
                &#125;
            &#125;
        &#125;

        // Show the content with the specified ID.
        var divsToHide = &#91;&#93;;
        var divs = document.getElementsByTagName&#40;"div"&#41;;
        for &#40;var i = 0; i < divs.length; i++&#41; &#123;
            var div = divs&#91;i&#93;;

            if &#40;div.className.match&#40;/\bcontent\b/i&#41;&#41; &#123;
                if &#40;div.id == "_" + contentId&#41;
                    div.style.display = "block";
                else
                    divsToHide.push&#40;div&#41;;
            &#125;
        &#125;

        // Hide the other content boxes.
        for &#40;var i = 0; i < divsToHide.length; i++&#41;
            divsToHide&#91;i&#93;.style.display = "none";

        // Change the address bar.
        if &#40;!skipReplace&#41; window.location.replace&#40;"#" + contentId&#41;;
    &#125;,

    OnClickHandler&#58; function &#40;e&#41; &#123;
        // Stop the event &#40;to stop it from scrolling or
        // making an entry in the history&#41;.
        if &#40;!e&#41; e = window.event;
        if &#40;e.preventDefault&#41; e.preventDefault&#40;&#41;; else e.returnValue = false;

        // Get the name of the anchor of the link that was clicked.
        Tabs.GoTo&#40;this.hash.substring&#40;1&#41;&#41;;
    &#125;,

    Init&#58; function &#40;&#41; &#123;
        if &#40;!document.getElementsByTagName&#41; return;

        // Attach an onclick event to all the anchor links on the page.
        var anchors = document.getElementsByTagName&#40;"a"&#41;;
        for &#40;var i = 0; i < anchors.length; i++&#41; &#123;
            var a = anchors&#91;i&#93;;
            if &#40;a.hash&#41; a.onclick = Tabs.OnClickHandler;
        &#125;

        var contentId;
        if &#40;window.location.hash&#41; contentId = window.location.hash.substring&#40;1&#41;;

        var divs = document.getElementsByTagName&#40;"div"&#41;;
        for &#40;var i = 0; i < divs.length; i++&#41; &#123;
            var div = divs&#91;i&#93;;

            if &#40;div.className.match&#40;/\bcontent\b/i&#41;&#41; &#123;
                if &#40;!contentId&#41; contentId = div.id;
                div.id = "_" + div.id;
            &#125;
        &#125;

        if &#40;contentId&#41; Tabs.GoTo&#40;contentId, true&#41;;
    &#125;
&#125;;

// Hook up the OnLoad event to the tab initialization function.
window.onload = Tabs.Init;

// Hide the content while waiting for the onload event to trigger.
var contentId = window.location.hash || "#Introduction";

if &#40;document.createStyleSheet&#41; &#123;
    var style = document.createStyleSheet&#40;&#41;;
    style.addRule&#40;"div.content", "display&#58; none;"&#41;;
    style.addRule&#40;"div" + contentId, "display&#58; block;"&#41;;
&#125; else &#123;
    var head = document.getElementsByTagName&#40;"head"&#41;&#91;0&#93;;
    if &#40;head&#41; &#123;
        var style = document.createElement&#40;"style"&#41;;
        style.setAttribute&#40;"type", "text/css"&#41;;
        style.appendChild&#40;document.createTextNode&#40;"div.content &#123; display&#58; none; &#125;"&#41;&#41;;
		style.appendChild&#40;document.createTextNode&#40;"div" + contentId + " &#123; display&#58; block; &#125;"&#41;&#41;;
        head.appendChild&#40;style&#41;;
    &#125;
&#125;
[/code]
Tout ce qui se conçoit bien s'énonce clairement et les mots pour le dire viennent aisément

Répondre

Retourner vers « JavaScript »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 5 invités