jBeta

a jQuery-like JS library

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 3383 Views - Last Post: 15 October 2009 - 12:25 PM

#1 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

jBeta

Posted 14 June 2009 - 12:03 AM

Okay, well I have looked into jQuery for a while, but don't like using libraries when I don't know what they are doing. So I chose to make one of my own, this may act very similar to jQuery, I don't know and I haven't used jQuery before so I can't say for certain.

NOTE - This is not by any means meant to replacee jQuery, they have had more time spend in making their library, this is meant as a training thing that some people may find useful.


One of my general philosophies is to allow the developer as much leeway as possible. I don't want to force you to rename my library to use it (if you want) along side jQuery, so I went through and added a flag for whether or not you want to allow jQuery usage with the $ variable or not.

Without further ado, here is the source (so far):
var useInConjunctionWithJQuery = false;

//Required functions to get elements from the document
document.getElementsByClassName = function(tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(tagName, Name){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(tagName, ID){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element; // can modify easily to return an array or elements with the specified ID
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

// start of library
jBeta = function(info){
  var obj;
  var parts;
  if(info.split('.').length > 1){ // class
	parts = info.split('.');
	obj = document.getElementsByClassName(parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parts[0], parts[1]);
  }
  else{
	obj = document.getElementsByTagName(info);
  }
  return (obj!=null)?(new $.Item(obj)):null;
}
  jBeta.Item = function(obj){
	this.data = obj;
	this.getStyle = function(styleLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i].style[styleLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data.style[styleLookup];
	  }
	  return returnValue;
	};
	this.getProperty = function(propertyLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i][propertyLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data[propertyLookup];
	  }
	  return returnValue;
	}
	this.show = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = '';
		}
	  }
	  else{
		this.data.style.display = '';
	  }
	};
	this.hide = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = 'none';
		}
	  }
	  else{
		this.data.style.display = 'none';
	  }
	};
	this.addEventListener = function(evt, func){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i][evt] = func;
		}
	  }
	  else{
		this.data[evt] = func;
	  }
	};
	this.clearClass = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = '';
		}
	  }
	  else{
		this.data.className = '';
	  }
	};
	this.setClass = function(className){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = className;
		}
	  }
	  else{
		this.data.className = className;
	  }
	};
  }
if(!useInConjunctionWithJQuery){
  $ = jBeta;
}




Sample application made with this (along with debug script for dev purposes):
<style>
.test{
  background: #0f0;
}
.t{
  border: 1px solid #f00;
}
</style>

<script>
onerror=handleErr;
var txt="";
function handleErr(msg,url,l){
  txt="There was an error on this page.\n\n";
  txt+="Error: " + msg + "\n";
  txt+="URL: " + url + "\n";
  txt+="Line: " + l + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  return true;
}


document.getElementsByClassName = function(tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(tagName, Name){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(tagName, ID){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element;
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

var useInConjunctionWithJQuery = false;
jBeta = function(info){
  var obj;
  var parts;
  if(info.split('.').length > 1){ // class
	parts = info.split('.');
	obj = document.getElementsByClassName(parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parts[0], parts[1]);
  }
  else{
	obj = document.getElementsByTagName(info);
  }
  return (obj!=null)?(new $.Item(obj)):null;
}
  jBeta.Item = function(obj){
	this.data = obj;
	this.getStyle = function(styleLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i].style[styleLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data.style[styleLookup];
	  }
	  return returnValue;
	};
	this.getProperty = function(propertyLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i][propertyLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data[propertyLookup];
	  }
	  return returnValue;
	}
	this.show = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = '';
		}
	  }
	  else{
		this.data.style.display = '';
	  }
	};
	this.hide = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = 'none';
		}
	  }
	  else{
		this.data.style.display = 'none';
	  }
	};
	this.addEventListener = function(evt, func){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i][evt] = func;
		}
	  }
	  else{
		this.data[evt] = func;
	  }
	};
	this.clearClass = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = '';
		}
	  }
	  else{
		this.data.className = '';
	  }
	};
	this.setClass = function(className){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = className;
		}
	  }
	  else{
		this.data.className = className;
	  }
	};
  }
if(!useInConjunctionWithJQuery){
  $ = jBeta;
}

</script>

<div id="walal" class="test">Content</div>
<div name='none' id="asd" class="test">Content</div>
<div id="asdwalal" class="test">Content</div>
<div id="awalal" class="test">Content</div>
<div id="swalal" class="test">Content</div>
<div id="dwalal" class="test">Content</div>
<span id="asd" class="test">Content</span>

<a name="test" href="http://www.google.com" onclick="alert('test'); return false">Test</a>

<script>
$('div').hide();
$('.test').clearClass();
$("#asd").setClass('t');
$("div").setClass('test t');
$('div#asd').clearClass();
$('a:test').addEventListener('onclick', function(){
  if($('div#asd').getStyle('display') == 'none'){
	$('div#asd').show();
  }
  else{
	$('div#asd').hide();
  }
  return false;
});
//$('#asd').addEventListener('onmouseover', function(){alert(this.id)});
</script>



So far I have tested this fully in IE 6, and have partially tested in Chrome; everything I have tested has worked on both.

Comments/ Suggestions welcome

Is This A Good Question/Topic? 0
  • +

Replies To: jBeta

#2 Amrykid   User is offline

  • D.I.C Lover
  • member icon

Reputation: 151
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: jBeta

Posted 14 June 2009 - 08:31 AM

View PostBetaWar, on 14 Jun, 2009 - 12:03 AM, said:

Okay, well I have looked into jQuery for a while, but don't like using libraries when I don't know what they are doing. So I chose to make one of my own, this may act very similar to jQuery, I don't know and I haven't used jQuery before so I can't say for certain.

NOTE - This is not by any means meant to replacee jQuery, they have had more time spend in making their library, this is meant as a training thing that some people may find useful.


One of my general philosophies is to allow the developer as much leeway as possible. I don't want to force you to rename my library to use it (if you want) along side jQuery, so I went through and added a flag for whether or not you want to allow jQuery usage with the $ variable or not.

Without further ado, here is the source (so far):
var useInConjunctionWithJQuery = false;

//Required functions to get elements from the document
document.getElementsByClassName = function(tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(tagName, Name){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(tagName, ID){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element; // can modify easily to return an array or elements with the specified ID
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

// start of library
jBeta = function(info){
  var obj;
  var parts;
  if(info.split('.').length > 1){ // class
	parts = info.split('.');
	obj = document.getElementsByClassName(parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parts[0], parts[1]);
  }
  else{
	obj = document.getElementsByTagName(info);
  }
  return (obj!=null)?(new $.Item(obj)):null;
}
  jBeta.Item = function(obj){
	this.data = obj;
	this.getStyle = function(styleLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i].style[styleLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data.style[styleLookup];
	  }
	  return returnValue;
	};
	this.getProperty = function(propertyLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i][propertyLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data[propertyLookup];
	  }
	  return returnValue;
	}
	this.show = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = '';
		}
	  }
	  else{
		this.data.style.display = '';
	  }
	};
	this.hide = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = 'none';
		}
	  }
	  else{
		this.data.style.display = 'none';
	  }
	};
	this.addEventListener = function(evt, func){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i][evt] = func;
		}
	  }
	  else{
		this.data[evt] = func;
	  }
	};
	this.clearClass = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = '';
		}
	  }
	  else{
		this.data.className = '';
	  }
	};
	this.setClass = function(className){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = className;
		}
	  }
	  else{
		this.data.className = className;
	  }
	};
  }
if(!useInConjunctionWithJQuery){
  $ = jBeta;
}




Sample application made with this (along with debug script for dev purposes):
<style>
.test{
  background: #0f0;
}
.t{
  border: 1px solid #f00;
}
</style>

<script>
onerror=handleErr;
var txt="";
function handleErr(msg,url,l){
  txt="There was an error on this page.\n\n";
  txt+="Error: " + msg + "\n";
  txt+="URL: " + url + "\n";
  txt+="Line: " + l + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  return true;
}


document.getElementsByClassName = function(tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(tagName, Name){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(tagName, ID){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element;
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

var useInConjunctionWithJQuery = false;
jBeta = function(info){
  var obj;
  var parts;
  if(info.split('.').length > 1){ // class
	parts = info.split('.');
	obj = document.getElementsByClassName(parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parts[0], parts[1]);
  }
  else{
	obj = document.getElementsByTagName(info);
  }
  return (obj!=null)?(new $.Item(obj)):null;
}
  jBeta.Item = function(obj){
	this.data = obj;
	this.getStyle = function(styleLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i].style[styleLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data.style[styleLookup];
	  }
	  return returnValue;
	};
	this.getProperty = function(propertyLookup){
	  returnValue = null;
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		  }
		  else if(returnValue == null){
			returnValue = this.data[i][propertyLookup];
		  }
		  else{
			return '_mixed_';
		  }
		}
	  }
	  else{
		returnValue = this.data[propertyLookup];
	  }
	  return returnValue;
	}
	this.show = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = '';
		}
	  }
	  else{
		this.data.style.display = '';
	  }
	};
	this.hide = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].style.display = 'none';
		}
	  }
	  else{
		this.data.style.display = 'none';
	  }
	};
	this.addEventListener = function(evt, func){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i][evt] = func;
		}
	  }
	  else{
		this.data[evt] = func;
	  }
	};
	this.clearClass = function(){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = '';
		}
	  }
	  else{
		this.data.className = '';
	  }
	};
	this.setClass = function(className){
	  if(this.data.length > 0){
		for(var i=0; i<this.data.length; i++){
		  this.data[i].className = className;
		}
	  }
	  else{
		this.data.className = className;
	  }
	};
  }
if(!useInConjunctionWithJQuery){
  $ = jBeta;
}

</script>

<div id="walal" class="test">Content</div>
<div name='none' id="asd" class="test">Content</div>
<div id="asdwalal" class="test">Content</div>
<div id="awalal" class="test">Content</div>
<div id="swalal" class="test">Content</div>
<div id="dwalal" class="test">Content</div>
<span id="asd" class="test">Content</span>

<a name="test" href="http://www.google.com" onclick="alert('test'); return false">Test</a>

<script>
$('div').hide();
$('.test').clearClass();
$("#asd").setClass('t');
$("div").setClass('test t');
$('div#asd').clearClass();
$('a:test').addEventListener('onclick', function(){
  if($('div#asd').getStyle('display') == 'none'){
	$('div#asd').show();
  }
  else{
	$('div#asd').hide();
  }
  return false;
});
//$('#asd').addEventListener('onmouseover', function(){alert(this.id)});
</script>



So far I have tested this fully in IE 6, and have partially tested in Chrome; everything I have tested has worked on both.

Comments/ Suggestions welcome

If you need a beta tester, i can help, i can test with IE8, Firefox 3, and Chrome 2.0
Was This Post Helpful? 0
  • +
  • -

#3 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: jBeta

Posted 14 June 2009 - 09:13 AM

No Ajax?
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 14 June 2009 - 11:04 AM

Now yet. I have a whole ajax 'class' which allows for some interesting things I will be implementing in it at some point.
Was This Post Helpful? 0
  • +
  • -

#5 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 14 June 2009 - 11:00 PM

Okay, I have a new version ready. It has my Ajax 'class' implemented, but I haven't had a chance to test it yet so the Ajax may be totally buggy.

@Amry - If you want to test any of this go ahead, it is open for anyone and everyone to use.

Well, here it is:
document.getElementsByClassName = function(tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(tagName, Name){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(tagName, ID){
  var allElements = document.getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element;
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

var useInConjunctionWithJQuery = false;
jBeta = function(info){
  var obj;
  var parts;
  if(typeof info == 'object'){
	obj = info;
  }
  else if(info.split('.').length > 1){ // class
	parts = info.split('.');
	obj = document.getElementsByClassName(parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parts[0], parts[1]);
  }
  else{
	obj = document.getElementsByTagName(info);
  }
  return (obj!=null)?(new $.Item(obj)):null;
}
jBeta.Item = function(obj){
  this.data = obj;
  this.setStyle = function(styleName, styleValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style[styleName] = styleValue;
	  }
	}
	else{
	  this.data.style[styleName] = styleValue;
	}
  };
  this.getStyle = function(styleLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i].style[styleLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data.style[styleLookup];
	}
	return returnValue;
  };
  this.setProperty = function(propertyName, propertyValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][propertyName] = propertyValue;
	  }
	}
	else{
	  this.data[propertyName] = propertyValue;
	}
  };
  this.getProperty = function(propertyLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i][propertyLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data[propertyLookup];
	}
	return returnValue;
  }
  this.show = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = '';
	  }
	}
	else{
	  this.data.style.display = '';
	}
  };
  this.hide = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = 'none';
	  }
	}
	else{
	  this.data.style.display = 'none';
	}
  };
  this.removeEventListener = function(evt){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = this.data[i].disableDefault?'return false;':'';
	  }
	}
	else{
	  this.data[evt] = this.data.disableDefault?'return false;':'';
	}
  };
  this.addEventListener = function(evt, func){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = func;
	  }
	}
	else{
	  this.data[evt] = func;
	}
  };
  this.clearClass = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = '';
	  }
	}
	else{
	  this.data.className = '';
	}
  };
  this.setClass = function(className){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = className;
	  }
	}
	else{
	  this.data.className = className;
	}
  };
//  this.getSlider = function(){
//	return new jBeta.Slider(this.data);
//  };
}
jBeta.Ajax = {
  http: '',
  maxQueries: 2,
  qIP: 0,
  queriesDone: 0,
  queryList: new Array()
}
jBeta.Ajax.init = function(func){
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
	ro = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else{
	ro = new XMLHttpRequest();
  }
  this.http = ro;
  this.respondFunc = func;
}
jBeta.Ajax.checkQueries = function(){
  if(jBeta.Ajax.qIP < jBeta.Ajax.maxQueries && jBeta.Ajax.queriesDone < jBeta.Ajax.queryList.length){
	nextQuery = jBeta.Ajax.queryList[jBeta.Ajax.queriesDone];
	ajax.query(nextQuery[0], nextQuery[1], nextQuery[2], 1);
  }
}
jBeta.Ajax.query = function(url, content, destination, a){
  if(!a){
	a = 0;
  }
  if(a == 0){
	jBeta.Ajax.queryList.push(new Array(url, content, destination));
  }
  if(jBeta.Ajax.qIP >= jBeta.Ajax.maxQueries){
  }
  else{
	jBeta.Ajax.qIP++;
	http = jBeta.Ajax.http;
	http.open('post', '#', true);
	http.onreadystatechange = jBeta.Ajax.handleResponse;
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	http.send('dest='+destination);
  }
}
jBeta.Ajax.handleResponse = function(){
  http = jBeta.Ajax.http;
  if(http.readyState == 4){
	var response = http.responseText;
	dest = response.split("||");
	jBeta.Ajax.respondFunc(response);
	jBeta.Ajax.qIP--;
	jBeta.Ajax.queriesDone++;
	jBeta.Ajax.checkQueries();
  }
  else{
	var response = "Loading -- please wait";
	document.getElementById('respond').innerHTML = response;
  }
}


if(!useInConjunctionWithJQuery){
  $ = jBeta;
}


To use the Ajax portion of it you will need to call $.Ajax.init() with a function to be called upon ajax response.
NOTE - At this point I have only implemented a single function for responses, so you have to have everything with the response done through there. (This will eventually change -- hopeully).

Here is how to make an Ajax call:

$.Ajax.query('#', '', 'respond')


With a full example (using the previous Ajax class I had, not the jBeta version):
<script>
onerror=handleErr;
var txt2="";
function handleErr(msg,url,l){
  txt2="There was an error on this page.\n\n";
  txt2+="Error: " + msg + "\n";
  txt2+="URL: " + url + "\n";
  txt2+="Line: " + l + "\n\n";
  txt2+="Click OK to continue.\n\n";
  alert(txt2);
  return true;
}

ajax = {
  http: '',
  maxQueries: 2,
  qIP: 2,
  queriesDone: 0,
  queryList: new Array()
}
ajax.init = function(){
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
	ro = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else{
	ro = new XMLHttpRequest();
  }
  this.http = ro;
}
ajax.checkQueries = function(){
  if(ajax.qIP < ajax.maxQueries && ajax.queriesDone < ajax.queryList.length){
	nextQuery = ajax.queryList[ajax.queriesDone];
	ajax.query(nextQuery[0], nextQuery[1], nextQuery[2], 1);
  }
}
ajax.query = function(url, content, destination, a){
  if(!a){
	a = 0;
  }
  if(a == 0){
	ajax.queryList.push(new Array(url, content, destination));
  }
  if(ajax.qIP >= ajax.maxQueries){
  }
  else{
	ajax.qIP++;
	http = ajax.http;
	http.open('post', '#', true);
	http.onreadystatechange = ajax.handleResponse;
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	http.send('dest='+destination);
  }
}
ajax.handleResponse = function(){
  http = ajax.http;
  alert("RESPOND");
  if(http.readyState == 4){
	var response = http.responseText;
	dest = response.split("||");
	//document.getElementById(dest[0]).innerHTML = dest[1];
  document.getElementById('respond').innerHTML = response;
	ajax.qIP--;
	ajax.queriesDone++;
//	alert("Queries comp: "+ajax.queriesDone);
//	alert("Queriees: "+ajax.queryList.length);
//	alert("Queries left: "+(ajax.queryList.length-ajax.queriesDone));
	ajax.checkQueries();
  }
  else{
	var response = "Loading -- please wait";
	document.getElementById('respond').innerHTML = response;
  }
}
window.onload = function(){
  ajax.init();
}
</script>

<div id="respond">Waiting for command</div>
<br>
<button onclick="ajax.query('#', '', 'respond')">Check it out</button>
<button onclick="ajax.qIP--;ajax.checkQueries()">-1 Query</button>


What makes this Ajax class good -
1. It uses a 'queue' to make sure there are no more than 2 queries going at once (Firefox and many other browsers only support 2 at a time). This is good because we are the ones making sure it isn't exceeding the limit, so it can store them and come back when it has an open query instead of losing the queries.
2. It is completely untested; you get to dive into open waters and tell me exactly how broken it is. NOTE - The ajax class I originally used was tested, but I haven't tested since the implementation in jBeta.

Other added jBeta functionality:
setStyle(styleName, styleValue) - set a style (using javascript's names for CSS properties).
-- Can be cone like so: $('div').setStyle('backgroundColor', '#ff0000');
setProperty(propertyName, propertyValue) - set a HTML element property, such as ID, class, name, type, etc.
-- Example: $('div').setProperty('className', 'frogger');
Was This Post Helpful? 0
  • +
  • -

#6 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: jBeta

Posted 15 June 2009 - 04:02 AM

Interesting, might play around with this a little at work.

My own JS library so far consists of an AJAX routine to request a page and then update the innerHTML of an element, some string functions, and something similar to your getElementsByClassName (mine takes a parent element as a parameter though, and only returns elements that are children of the parent which I'm finding is very useful).

Didn't even think about a limit on AJAX requests, which could explain some of the funky stuff that has been going on...
Was This Post Helpful? 0
  • +
  • -

#7 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 15 June 2009 - 11:49 AM


Was This Post Helpful? 0
  • +
  • -

#8 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 15 June 2009 - 08:08 PM

** Edit **
Hm, odd, I don't like having to do this type of thing often, but my last post seems to not want to show up and it won't let me edit it...

So, here is the updated version (with test script). It is just missing the ajax portion, which I took out to simplify some of the stuff I had to modify. I don't think any changes would need to be made from the previous ajax version.

Code:
<script>
onerror=handleErr;
var txt2="";
function handleErr(msg,url,l){
  txt2="There was an error on this page.\n\n";
  txt2+="Error: " + msg + "\n";
  txt2+="URL: " + url + "\n";
  txt2+="Line: " + l + "\n\n";
  txt2+="Click OK to continue.\n\n";
  alert(txt2);
  return true;
}


document.getElementsByClassName = function(parentTag, tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(parentTag, tagName, Name){
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(parentTag, tagName, ID){
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element;
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

var useInConjunctionWithJQuery = false;
jBeta = function(info){
  var obj = null;
  var parts;
  var returnObjects = new Array();
  if(typeof info == 'object'){
	return new jBeta.Item(info);
  }
  var levels = info.split(' ');
//  alert('Number of levels: '+levels.length+'\nLooking for '+levels[0]);
  obj = jBeta._getElementsLoop(levels.length>1?levels[0]:info, document);

  if(levels.length > 1 && obj.length >= 1){
	for(var i=1; i<levels.length; i++){
//	  alert('Looking for: '+levels[i]);
	  for(var j=0; j<obj.length; j++){
//		alert('Looking for: '+levels[i]+', with parent of: '+obj[j].tagName);
		rArray = jBeta._getElementsLoop(levels[i], obj[j]);
//		alert(rArray);
		if(rArray != null && rArray.length > 1){
		  for(var h=0; h<rArray.length; h++){
//			alert(rArray[h]);
			returnObjects.push(rArray[h]);
		  }
		}
		else if(rArray != null){
//		  alert("elif statement");
		  returnObjects.push(rArray);
		}
	  }
	  obj = (returnObjects != null && returnObjects.length>0)?returnObjects:obj;
	  returnObjects = new Array();
	}
  }
  if(obj.length > 1){
	for(i=0; i<obj.length; i++){
//	  alert(obj[i].tagName);
	}
  }
  else{
//	alert(obj.tagName);
  }
  return (obj!=null)?(new jBeta.Item(obj)):null;
}
jBeta._getElementsLoop = function(info, parentElement){
  var obj = null;
  if(info.split('.').length > 1){
	parts = info.split('.');
	obj = document.getElementsByClassName(parentElement, parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parentElement, parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parentElement, parts[0], parts[1]);
  }
  else{
	obj = ((parentElement != undefined)?parentElement:document).getElementsByTagName(info);
  }
/*  if(obj != null){
	for(i=0; i<obj.length; i++){
	  alert('Object: '+obj[i].tagName);
	}
  }*/
  return obj;
}
jBeta.Item = function(obj){
  this.data = obj;
  this.setStyle = function(styleName, styleValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style[styleName] = styleValue;
	  }
	}
	else{
	  this.data.style[styleName] = styleValue;
	}
  };
  this.getStyle = function(styleLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i].style[styleLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data.style[styleLookup];
	}
	return returnValue;
  };
  this.setProperty = function(propertyName, propertyValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][propertyName] = propertyValue;
	  }
	}
	else{
	  this.data[propertyName] = propertyValue;
	}
  };
  this.getProperty = function(propertyLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i][propertyLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data[propertyLookup];
	}
	return returnValue;
  }
  this.show = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = '';
	  }
	}
	else{
	  this.data.style.display = '';
	}
  };
  this.hide = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = 'none';
	  }
	}
	else{
	  this.data.style.display = 'none';
	}
  };
  this.removeEventListener = function(evt){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = this.data[i].disableDefault?'return false;':'';
	  }
	}
	else{
	  this.data[evt] = this.data.disableDefault?'return false;':'';
	}
  };
  this.addEventListener = function(evt, func){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = func;
	  }
	}
	else{
	  this.data[evt] = func;
	}
  };
  this.clearClass = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = '';
	  }
	}
	else{
	  this.data.className = '';
	}
  };
  this.setClass = function(className){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = className;
	  }
	}
	else{
	  this.data.className = className;
	}
  };
//  this.getSlider = function(){
//	return new jBeta.Slider(this.data);
//  };
}

if(!useInConjunctionWithJQuery){
  $ = jBeta;
}
</script>

<div>
  THis is a test
  <br/>
  <span id="test">
	This is another test :)
	<div id="t"> 
	  tesing
	</div>
	<a>
	  Tsetstset
	</a>
  </span>
</div>

<script>
$('div#t').setStyle('backgroundColor', '#f00');
$('div span#test div#t').hide();
</script>

Was This Post Helpful? 0
  • +
  • -

#9 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 16 June 2009 - 12:47 PM

Well, yet another (larger) update. Added a simple Animator class (at this point only allowing for slide height and width, with 'normal'/'strong' (both are the same) and 'ease'/'easing' (which doesn't quite work right). Also fixed the jBeta function so that it does what it is supposed to.

Here's the code:
document.getElementsByClassName = function(parentTag, tagName, className){
  var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eClass = element.className;
	if(eClass && eClass.indexOf(className) != -1 && hasClassName.test(eClass)){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByName = function(parentTag, tagName, Name){
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var results = [];
  var element;
  for(var i = 0; (element = allElements[i]) != null; i++){
	var eName = element.name;
	if(eName == Name){
	  results.push(element);
	}
  }
  return results;
}
document.getElementsByID = function(parentTag, tagName, ID){
  var allElements = ((parentTag != undefined)?parentTag:document).getElementsByTagName((tagName!='')?tagName:"*");
  var element;
  var results = [];
  for(var i = 0; i<allElements.length; i++){
	element = allElements[i];
	var eId = element.id;
	if(eId && eId == ID){
	  return element;
	  //results.push(element);
	}
  }
  return results.length<=0?null:results;
}

var useInConjunctionWithJQuery = false;
jBeta = function(info){
  var obj = null;
  var parts;
  var returnObjects = new Array();
  if(typeof info == 'object'){
	return new jBeta.Item(info);
  }
  var levels = info.split(' ');
//  alert('Number of levels: '+levels.length+'\nLooking for '+levels[0]);
  obj = jBeta._getElementsLoop(levels.length>1?levels[0]:info, document);

  if(levels.length > 1 && obj.length >= 1){
	for(var i=1; i<levels.length; i++){
//	  alert('Looking for: '+levels[i]);
	  for(var j=0; j<obj.length; j++){
//		alert('Looking for: '+levels[i]+', with parent of: '+obj[j].tagName);
		rArray = jBeta._getElementsLoop(levels[i], obj[j]);
//		alert(rArray);
		if(rArray != null && rArray.length >= 1){
		  for(var h=0; h<rArray.length; h++){
//			alert(rArray[h].tagName);
			returnObjects.push(rArray[h]);
		  }
		}
		else if(rArray != null){
//		  alert("elif statement, "+rArray.tagName);
		  returnObjects.push(rArray);
		}
	  }
	  obj = (returnObjects != null && returnObjects.length>0)?returnObjects:obj;
	  returnObjects = new Array();
	}
  }
  if(obj.length > 1){
	for(i=0; i<obj.length; i++){
//	  alert(obj[i].tagName);
	}
  }
  else{
//	alert(obj.tagName);
  }
  return (obj!=null)?(new jBeta.Item(obj)):null;
}
jBeta._getElementsLoop = function(info, parentElement){
  var obj = null;
  if(info.split('.').length > 1){
	parts = info.split('.');
	obj = document.getElementsByClassName(parentElement, parts[0], parts[1]);
  }
  else if(info.split(':').length > 1){
	parts = info.split(':');
	obj = document.getElementsByName(parentElement, parts[0], parts[1]);
  }
  else if(info.split('#').length > 1){
	parts = info.split('#');
	obj = document.getElementsByID(parentElement, parts[0], parts[1]);
  }
  else{
	obj = ((parentElement != undefined)?parentElement:document).getElementsByTagName(info);
  }
/*  if(obj != null){
	for(i=0; i<obj.length; i++){
	  alert('Object: '+obj[i].tagName);
	}
  }*/
  return obj;
}
jBeta.Item = function(obj){
  this.data = obj;
  this.setStyle = function(styleName, styleValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style[styleName] = styleValue;
	  }
	}
	else{
	  this.data.style[styleName] = styleValue;
	}
  };
  this.getStyle = function(styleLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i].style[styleLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i].style[styleLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data.style[styleLookup];
	}
	return returnValue;
  };
  this.setProperty = function(propertyName, propertyValue){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][propertyName] = propertyValue;
	  }
	}
	else{
	  this.data[propertyName] = propertyValue;
	}
  };
  this.getProperty = function(propertyLookup){
	returnValue = null;
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		if(returnValue == this.data[i][propertyLookup] && returnValue != null && i>0){
		}
		else if(returnValue == null){
		  returnValue = this.data[i][propertyLookup];
		}
		else{
		  return '_mixed_';
		}
	  }
	}
	else{
	  returnValue = this.data[propertyLookup];
	}
	return returnValue;
  }
  this.show = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = '';
	  }
	}
	else{
	  this.data.style.display = '';
	}
  };
  this.hide = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].style.display = 'none';
	  }
	}
	else{
	  this.data.style.display = 'none';
	}
  };
  this.removeEventListener = function(evt){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = this.data[i].disableDefault?'return false;':'';
	  }
	}
	else{
	  this.data[evt] = this.data.disableDefault?'return false;':'';
	}
  };
  this.addEventListener = function(evt, func){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i][evt] = func;
	  }
	}
	else{
	  this.data[evt] = func;
	}
  };
  this.clearClass = function(){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = '';
	  }
	}
	else{
	  this.data.className = '';
	}
  };
  this.setClass = function(className){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		this.data[i].className = className;
	  }
	}
	else{
	  this.data.className = className;
	}
  };
  this.slideHeight = function(toHeight, speed){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		jBeta(this.data[i]).setStyle('overflow', 'hidden');
		this.data[i].toHeight = toHeight;
		jBeta.Animator.slideHeight(this.data[i], speed);
	  }
	}
	else{
	  jBeta(this.data).setStyle('overflow', 'hidden');
	  this.data.toHeight = toHeight;
	  jBeta.Animator.slideHeight(this.data, speed);
	}
  };

  this.slideWidth = function(toWidth, speed){
	if(this.data.length > 0){
	  for(var i=0; i<this.data.length; i++){
		jBeta(this.data[i]).setStyle('overflow', 'hidden');
		this.data[i].toWidth = toWidth;
		jBeta.Animator.slideWidth(this.data[i], speed);
	  }
	}
	else{
	  jBeta(this.data).setStyle('overflow', 'hidden');
	  this.data.toWidth = toWidth;
	  jBeta.Animator.slideWidth(this.data, speed);
	}
  };
}
jBeta.Animator = {
  speeds: {
	  'slow': 100,
	  'normal': 50,
	  'fast': 10
	},
  styles: {
	  'easing': 'ease',
	  'ease': 'ease',
	  'strong': 'normal',
	  'normal': 'normal'
	},
  slideHeight: function(obj, speed, style){
	  if(jBeta.Animator.speeds[speed] == undefined){
		speed = 'normal';
	  }
	  cHeight = obj.offsetHeight;
	  exNumber = jBeta.Animator.calcDelta(cHeight, obj.toHeight, style);
	  if(cHeight == obj.toHeight){
		return;
	  }
	  if(cHeight < obj.toHeight){
		obj.style.height = (cHeight+exNumber)+'px';
	  }
	  else if(cHeight > obj.toHeight){
		obj.style.height = (cHeight-exNumber)+'px';
	  }
	  setTimeout(function(){
		jBeta.Animator.slideHeight(obj, speed, style);
	  }, jBeta.Animator.speeds[speed]);
	},
  slideWidth: function(obj, speed, style){
	  if(jBeta.Animator.speeds[speed] == undefined){
		speed = 'normal';
	  }
	  cWidth = obj.offsetWidth;
	  exNumber = jBeta.Animator.calcDelta(cWidth, obj.toWidth, style);
	  if(cWidth == obj.toWidth){
		return;
	  }
	  if(cWidth < obj.toWidth){
		obj.style.width = (cWidth+exNumber)+'px';
	  }
	  else if(cWidth > obj.toWidth){
		obj.style.width = (cWidth-exNumber)+'px';
	  }
	  setTimeout(function(){
		jBeta.Animator.slideWidth(obj, speed, style);
	  }, jBeta.Animator.speeds[speed]);
	},
  calcDelta: function(to, from, style){
	  if(to <= 0){
		to = 1;
	  }
	  if(jBeta.Animator.styles[style] == 'ease'){
		if(from > to){
		 exNumber = Math.ceil(from/(to*jBeta.Animator.speeds[speed]));
		}
		else{
		  exNumber = Math.ceil((from*jBeta.Animator.speeds[speed])/to);
		}
	  }
	  else{
		exNumber = 1;
	  }
	  return exNumber;
	}
}


if(!useInConjunctionWithJQuery){
  $ = jBeta;
}


With any luck it isn't overly long, if it is I'll upload a copy of it :)
Was This Post Helpful? 0
  • +
  • -

#10 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 17 June 2009 - 12:09 AM

Woot!!! I think I have finally got this to the point of alpha release for version 1.0!

Attached is an un-compressed, developement-ready Javascript file with everything I have done so far. It has been fully tested in IE 7, and seems to work just the same in IE 6, I haven't tested it anywhere else in recent history though, so it may not completely work cross-browser (I hope it does though).

Updates made:
Fixed (again, and hopefully for the last time) the jBeta() function. It should now actually do what it is meant to do - get elements in CSS format that you type in. Initial tests of this have proven to work great, but I haven'ttested it that thuroughly.
Fixed the Animator's easing issue. That now works nicely.

Annoying Problems:
The Animator's strong doesn't work as it should. Current code is intact for it (I hav just changed strong in the styles object to normal, so it gets mapped to something working.

Well, here is the file:
[attachment=12384:attachment]
Contents:
jBeta_v1.0a.js -- jBeta Javascript Library
jBeta_example_01a.html -- Simple example of how you could use jBeta. (Very simple)

Any comments and suggestions are still welcome.
Was This Post Helpful? 0
  • +
  • -

#11 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: jBeta

Posted 17 June 2009 - 04:06 AM

Tried the example but it doesn't appear to work in Firefox 3.0.11 on Linux unless I uncomment the jBeta.useInConjunctionWithJQuery = false; line.

I'm guessing this is the problem
if(jBeta.useInConjunctionWithJQuery != undefined && !jBeta.useInConjunctionWithJQuery){
  $ = jBeta;
}


Was This Post Helpful? 0
  • +
  • -

#12 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 17 June 2009 - 09:44 AM

Oh, hm, must have accidentally put the comment back in... I'll have to modify that. Thanks for the heads up.

<edit>
Well, I haven't fixed the bug with the jBeta() function. Instead I think it is worse. I have started up a thread, if you want to contribute to it :)
http://www.dreaminco...topic110608.htm
</edit>
Was This Post Helpful? 0
  • +
  • -

#13 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 18 June 2009 - 11:31 PM

Okay, I wound up rewriting the jBeta function and added another helper function to it, but it seems to work much better now! (Yayness)

Here is version 1.0.1a:
[attachment=12415:attachment]

Now with a lot less hassle :)
The example is tried and true exactly as it is (I tested it out right before zipping) in IE 6.

Again, comments and suggestions are welcome. (Please reply if you find anything wrong, or are even using it :))
Was This Post Helpful? 0
  • +
  • -

#14 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: jBeta

Posted 20 June 2009 - 02:36 PM

Aw, 0 downloads for the last version. Well this one should be more appealing (is is a beta!).

Changes:
Added jBeta.Animator.fadeTo(obj, speed, style)
Added jBeta.Item.fadeTo(toOpacity, speed, style)
Added jBeta.Item.fadeIn(speed, style)
Added jBeta.Item.fadeOut(speed, style)

Fixes:
Update jBeta.checkLineage() and document.getElementsByCName() to use obj.getAttribute('name') instead of obj.name(), thus making those 2 functions cross browser compatible.

Tried and True in:
IE 6
Mozilla 1.(something)
Firefox 2.(something)
Chrome 2.0.173.31
Opera 9.(something)

Should also work in IE 7.
Completely untested in IE 8 (but should work okay please let me know).

Well, here is the file:
[attachment=12442:attachment]

Contents:
jBeta_example_01a.html - Shows off some of jBeta's functionality including: slideHeight, addEventListener, fadeTo, document.getElementsByID(), document.getElementsByCName(), document.getElementsByClassName(), jBeta(Object), jBeta('div span div') (Lineage), setStyle(), getProperty(), setProperty() and more.
jBeta_v1.0b.js - jBeta developer's version
jBeta_v1.0b_compressed - jBeta compressed version. Minimal comments.

Suggestions, comments, general replies all welcome (Please reply :) if for no other reason than to let me know someone is actually looking at this...)
Was This Post Helpful? 0
  • +
  • -

#15 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: jBeta

Posted 20 June 2009 - 03:45 PM

@BetaWar: Very nice man. See what my simple question about a jQuery issue has led to lol. Keep up the good work
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2