Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help me to understand these codes!?

    I'm totally new when it comes to JavaScript and I'm trying to learn new things. Here I found the codes I tried it and it works but I would like to have comments for the code to understand how they have proceeded.
    can someone help me and explain these codes with comments?
    I really appreciate it.

    Code:
    var config = {
        "tags": "vfx+compositing",
        "user": "andreasl",
        "scriptTagTarget": "scriptTagDiv",
        "deliciousTarget": "deliciousLinks",
        "callbackFunction": "fetchDelicious"
    };
    
    window.onload = function() {
        var url = 'http://feeds.delicious.com/v2/json/' + config.user + '/' + config.tags + '?callback=' + config.callbackFunction;
        var scriptDiv = document.getElementById(config.scriptTagTarget);
        addScriptTag(url, scriptDiv);
    };
    
    
    
    function addScriptTag(url, scriptDiv) {
    
        if (scriptDiv.hasChildNodes())
        {
            scriptDiv.removeChild(scriptDiv.firstChild)
        };
    
        var scriptElement = document.createElement('script');
        scriptElement.setAttribute('src', url);
        scriptDiv.appendChild(scriptElement);
    }
    
    
    function fetchDelicious(json) {
    	var html = "";
    	for (var i = 0; i < json.length; i++) {
    		var uri = json[i].u;
    		var description = json[i].d;
    		var tags = json[i].t; //array
    		var time = json[i].dt; 
    		//var n = json[i].n; //new?
    		var author = json[i].a;
    		var bHtml = "<li><a href=\":u\">:d</a>:t</li>".replace(":u", uri).replace(":d", description); 
    		var tagHtml = ""; 
    		for(var n = 0; n < tags.length; n++)  { 
    		tagHtml += "<li><a href=\"http://delicious.com/:u\">:d</a></li>".replace(":u", [author,tags[n]].join("/")).replace(":d", tags[n]); 
    		}
    		tagHtml = "<ul>" + tagHtml + "</ul>";
    		html += bHtml.replace(":t", tagHtml); 
    	}
    	html = "<ul>" + html + "</ul>"; 
    	document.getElementById(config.deliciousTarget).innerHTML = html;
       
    
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote Originally Posted by newbe View Post
    I'm totally new when it comes to JavaScript and I'm trying to learn new things.
    That is admirable, but you are trying to run (or fly!!) before you can walk. It would take a very long time to explain in full this advanced code to someone who is "totally new" to the subject. Suggest you master more basic things first.

    There were lots of examples of poor defending, both prior to and preceding the goal. - Football Commentator

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I understand what you mean and I have done some but in this code I would like to have comments for the last bit. I have some problems and understand how it has been done and have some explanations and comments.
    I really appreciate the help

    Code:
    function fetchDelicious(json) {
    	var html = "";
    	for (var i = 0; i < json.length; i++) {
    		var uri = json[i].u;
    		var description = json[i].d;
    		var tags = json[i].t; //array
    		var time = json[i].dt; 
    		//var n = json[i].n; //new?
    		var author = json[i].a;
    		var bHtml = "<li><a href=\":u\">:d</a>:t</li>".replace(":u", uri).replace(":d", description); 
    		var tagHtml = ""; 
    		for(var n = 0; n < tags.length; n++)  { 
    		tagHtml += "<li><a href=\"http://delicious.com/:u\">:d</a></li>".replace(":u", [author,tags[n]].join("/")).replace(":d", tags[n]); 
    		}
    		tagHtml = "<ul>" + tagHtml + "</ul>";
    		html += bHtml.replace(":t", tagHtml); 
    	}
    	html = "<ul>" + html + "</ul>"; 
    	document.getElementById(config.deliciousTarget).innerHTML = html;
       
    
    }

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    problem solved


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •