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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post the "ZyberCoreX"

    Part of my library/framework project, and I just wanted to present my code/code style, and hopefully aquire some questions/feedback.

    Code:
    // ZyberCoreX.js
    (function( ZyberCoreX ) {
    
    	var Z = ZyberCoreX;
    	Z.window.ZyberCoreX = Z;
    	
    	//	3 methods for expansion:	
    	
    	// Z.extend;
    	// Z.include;
    	// Z.xmlhttp;
    	
    }({
    	version: "x.x.x",
    	window: window,
    	timestamp: new Date().getTime(),
    	extend: function( target , source ) {	
    	
    		if (!target) {return -1}			
    		
    		if (!source) {
    			var source = target,
    			target = this;
    		}	
    		
    		for (var x in source) 
    		{
    			if (source.hasOwnProperty(x)) {
    				target[x] = source[x];
    			}
    		}
    		
    		return target;
    	},
    	include: function( inc , fn ) {
    	
    		if (!inc) {return -1}
    		
    		var script = document.createElement("script"),
    		head = document.getElementsByTagName("head")[0];	
    		
    		script.src = inc + ".js";
    		
    		script.onload = function() {
    			head.removeChild(script);
    			if (typeof fn == 'function') {
    				fn();
    			}
    		};		
    		
    		head.appendChild(script);	
    	},
    	xmlhttp: function xmlhttp( method , url , async ) {
    	
    		if (!method || !url) {return -1}	
    		
    		var xhr; 
    		
    		if (window.XMLHttpRequest && navigator.appName != "Microsoft Internet Explorer") {
    			xhr = new XMLHttpRequest();
    		} else if (window.ActiveXObject) {
    			xhr = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		
    		xhr.onreadystatechange = function() {
    			if (xhr.readyState == 4 && xhr.status == 200) {
    				return xhr.responseText;
    			}
    		};
    		
    		xhr.open( method , url , async );
    		xhr.send();
    		
    		return xhr.responseText;
    	}
    }));

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    I am afraid this will only work for async=false, otherwise you won't be able to return the responseText ...

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by devnull69 View Post
    I am afraid this will only work for async=false, otherwise you won't be able to return the responseText ...
    why would it not work if async was true, wouldn't it just return null and let the callback do the work?

    EDIT: oh, there is not callback. that's silly.
    funny how it still checks for IE6, man i though we were long past that one...
    caching might be an issue on jsonp, since you can't set headers.
    it would be nice if i got a return from include as well, maybe the script tag in case i want to add an ie handler or remove it upon loading.
    the extend function will break if i pass it {hasOwnProperty: 0}...
    the include will break if there;s no head tag.

    in short, there are some useful ideas here, certainly these are common tasks, but i'm afraid the coding of each one is less than ideal.

    if it were more up to me, i would avoid the mentioned issues by doing it more like:

    Code:
    // ZyberCoreX.js
    var ZyberCoreX = {
    	version: 0.1,
    	window: self,
    	timestamp: +new Date(),
    	extend: function _extend(target, source) {
    
    		if (!target) {
    			target=this;
    		} /* end if */
    
    		if (!source) {
    			var source = target,
    				target = {};
    		} /* end if(!source) */
    
    		var hop = hasOwnProperty;
    
    		for (var x in source) {
    			if (hop.call(source, x)) {
    				target[x] = source[x];
    			} /* end if */
    
    		} /* next for  */
    
    		return target;
    	},/* end _extend() */
    
    	include: function _include(inc, fn, blnNocache) {
    		if (!inc) {
    			throw new Error("missing url argument");
    		} /* end if */
    
    		var d = document,
    			script = d.getElementsByTagName("script")[0].parentNode.appendChild(d.createElement("script"));
    		script.onload = fn || String;
    		script.src = String(inc).replace(/\.js$/im,"") + ".js" + (blnNocache?("?"+ +new Date() ):"");
    		return script;
    	},/* end _include() */
    
    	xmlhttp:	function xmlhttpGet( url,  data, callback) {
    		var XHRt = new XMLHttpRequest();
    		XHRt.open( data ? "POST" : "GET", url, !! callback);
    		XHRt.onreadystatechange = function() {
    			if (XHRt.readyState == 4 && XHRt.responseText) {
    				(callback||Boolean)(XHRt.responseText, url, XHRt);
    			}
    		};
    		XHRt.send(data||"");
    		return XHRt.responseText;
    	} /* end xmlhttpGet() */
    };
    Last edited by rnd me; 09-11-2013 at 05:11 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Unless the OPs 'zybercorex' and 'Bogilde' are the same person,
    there appears to be a conflict in the claimed authorship of the code contained
    at: http://www.dreamincode.net/forums/to...rex-what-next/
    and: http://www.codingforums.com/showthre...41#post1356641

    What gives?
    Last edited by jmrker; 09-11-2013 at 03:57 AM.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by jmrker View Post
    Unless the OPs 'zybercorex' and 'Bogilde' are the same person,
    there appears to be a conflict in the claimed authorship of the code contained
    at: http://www.dreamincode.net/forums/to...rex-what-next/
    and: http://www.codingforums.com/showthre...41#post1356641

    What gives?
    yikes. i edited my copy to not include any significant code from either, use in good faith.
    the change let's us handily clone an object with one arg to extend anyway...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by jmrker View Post
    Unless the OPs 'zybercorex' and 'Bogilde' are the same person,
    there appears to be a conflict in the claimed authorship of the code contained
    at: http://www.dreamincode.net/forums/to...rex-what-next/
    and: http://www.codingforums.com/showthre...41#post1356641

    What gives?
    The one on dreamincode is 0.22 this one is 0.1, your guess is as good as mine


  •  

    Tags for this Thread

    Posting Permissions

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