$(this).css("left",parent != window ?(parent.offsetWidth-this.offsetWidth)/2:(parent.innerWidth-this.offsetWidth)/2);
$(this).css("top",parent != window ?(parent.offsetHeight-this.offsetHeight)/2:(parent.innerHeight-this.offsetHeight)/2);
}
else
{
window.console.error("没有设置有效的position值");
}
})
return this;
}
function next(current)
{
var parent = current.parentNode,
children = parent.children,
//childNodes、nextSibling maybe contain ObjectText
length = children.length;
for(var i=0;i<length;i++)
{
if(current == children[i])
break;
}
//if not lastChild
if(i<length-1)
{
return children[i+1];
}
else
{
//recursion search until parent == document.body
if(parent != document.body)
{
return next(parent);
}
else
{
window.console.warn("Can not get next sibling");
}
}
}
function getRandomInteger(min,max)
{
return Math.floor(Math.random()*(max-min+1))+min
}
function imitateMouseEvent(element,type)
{
var event = document.createEvent("Events");
event.initEvent(type,true,true);
element.dispatchEvent(event);
}
showMessage.i = 0;
function showMessage(object)
{
var body = $("body")[0];
var $p =$("#debugp");
if($p.length==0)
{
$p = $("<p/>").attr("id","debugp");
$(body).prepend($p);
}
$p[0].innerHTML += "<br/>"+(showAttribute.i++)+" | "+object;
}
showAttribute.i=0;
function showAttribute(object,filter)
{
var body = $("body")[0];
var $p =$("#debugp");
if($p.length==0)
{
$p = $("<p/>").attr("id","debugp");
$(body).prepend($p);
}
if(getType(filter).indexOf(DataType.string)!=-1)
{
for(var a in object)
{
if(a.indexOf(filter)!=-1)
{
$p[0].innerHTML += a+" "+object[a]+"<br/>";
}
}
}
else if(getType(filter) == DataType.RegExp)
{
for(var a in object)
{
if(filter.test(a))
{
$p[0].innerHTML += a+" "+object[a]+"<br/>";
}
}
}
else if(getType(filter) == DataType.UNDEFINED)
{
for(var a in object)
{
$p[0].innerHTML += a+" "+object[a]+"<br/>";
}
}
else
{
window.console.error(arguments.callee.toString().match(/^function +(.+)\(/)[1]+"第二个参数应传递字符串或正则表达式");
}
$p[0].innerHTML +=showAttribute.i+++"--------------------------------------<br/>"
}
function showCollection(collection)
{
var body = $("body")[0];
var $p =$("#debugp");
if($p.length==0)
{
$p = $("<p/>").attr("id","debugp");
$(body).prepend($p);
}
for(var i=0;i<collection.length;i++)
$p[0].innerHTML = collection[i]+" |"+"<br/>" + $p[0].innerHTML;
}
function showLength(collection)
{
var body = $("body")[0];
var $p =$("#debugp");
if($p.length==0)
{
$p = $("<p/>").attr("id","debugp");
$(body).prepend($p);
}
$p[0].innerHTML = collection.length+" |"+"<br/>" + $p[0].innerHTML;
}
function DataType()
{
}
DataType.RegExp = "RegExp";
DataType.ObjectString = "Objectstring";
DataType.string = "string";
DataType.NULL = "null";
DataType.UNDEFINED = "undefined";
DataType.ObjectNumber = "Objectnumber";
DataType.number = "number";
DataType.ObjectBoolean = "Objectboolean";
DataType.boolean = "boolean";
DataType.function = "function";
DataType.array = "array";
function getType(type)
{
if(typeof type == DataType.UNDEFINED)
{
return DataType.UNDEFINED;
}
else if(typeof type == "object")
{
if(type == null)
{
return DataType.NULL ;
}
else
{
if(typeof type.valueOf() == DataType.string)
{
return DataType.ObjectString
}
else if(typeof type.valueOf() == DataType.number)
{
return DataType.ObjectNumber;
}
else if(typeof type.valueOf() == DataType.boolean)
{
return DataType.ObjectBoolean;
}
else if(type instanceof Array)
{
return DataType.array;
}
else if(type instanceof RegExp)
{
return DataType.RegExp;
}
else if(typeof type.constructor == DataType.function)
{
return type.constructor.toString().match(/^function +(.+)\(/)[1];
}
}
}
else if(typeof type == DataType.function)
{
return DataType.function
}
else
{
return typeof type;
}
}