富贵资源网 Design By www.hznty.com
主要是集成了常用的扩展,包括Dom与String、Array、StringBuffer、NameSpace等,当然还少不了Ajax。体积约8k。因为严格控制体积,所以功能有限。如果只要Ajax部分,就1k而已。
这个小框架已经应用到公司的项目,并开始逐步在前端展示页面上接替prototype.js。以后将围绕这个框架做一些应用。
复制代码 代码如下:
/*
* My JavaScript Framework
* Version : 1.0 beta
* Author : misshjn
* Email : misshjn@163.com
*/
function NameSpace(){};
function StringBuffer(){this.data = []};
var Method = {
Version : "1.0 beta",
Element : function(){
this.version = Method.Version;
this.hide = function(){this.style.display="none"; return this};
this.show = function(){this.style.display=""; return this};
this.getStyle = function(s){
var value = this.style[s.camelize()];
if (!value){
if (this.currentStyle) {
value = this.currentStyle[s.camelize()];
}else if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(this, null);
value = css ? css.getPropertyValue(s) : null;
}
}
return value;
};
this.setStyle = function(s){
var sList = s.split(";");
for (var i=0,j; j=sList[i]; i++){
var k = j.split(":");
this.style[k[0].trim().camelize()] = k[1].trim();
}
return this;
};
this.toggle = function(){this.getStyle("display")=="none"?this.setStyle("display:"):this.setStyle("display:none"); return this};
this.hasClassName = function(c){return this.className.hasSubString(c," ")?true:false;};
this.addClassName = function(c){if(!this.hasClassName(c)){this.className+=" "+c};return this};
this.removeClassName = function(c){if(this.hasClassName(c)){this.className = (" "+this.className+" ").replace(" "+c+" "," ").trim(); return this}};
this.getElementsByClassName = function(c){return this.getElementsByAttribute("className",c)};
this.getElementsByAttribute = function(n,v){ //name,value;
var elems = this.getElementsByTagName("*");
var elemList = [];
for (var i=0,j; j=elems[i]; i++){
var att = j[n] || j.getAttribute(n);
if (att==v){
elemList.push(j);
}
}
return elemList;
};
this.parentIndex = function(p){
if (this==p){return 0}
for (var i=0,n=this; n=n.parentNode; i++){
if(n==p){return i;}
if(n==document.documentElement) return -1;
}
}
this.nextElement = function(){
var n = this;
for (var i=0,n; n = n.nextSibling; i++){
if(n.nodeType==1) return $(n);
}
return null;
};
this.previousElement = function(){
var n = this;
for (var i=0,n; n = n.previousSibling; i++){
if(n.nodeType==1) return $(n);
}
return null;
};
this.moveAhead = function(){
if (this.previousElement()){
this.parentNode.insertBefore(this,this.previousElement());
}
return this;
};
this.moveBack = function(){
var n = this.nextElement();
if (n){
this.parentNode.removeChild(n);
this.parentNode.insertBefore(n,this);
}
return this;
};
},
Array : function(){
this.indexOf = function(){
for (i=0; i<this.length; i++){
if (this[i]==arguments[0])
return i;
}
return -1;
};
this.lastIndexOf = function(){
for (i=this.length-1; i>=0; i--){
if (this[i]==arguments[0])
return i;
}
return -1;
};
this.each = function(fn){
for (var i=0,len=this.length; i<len; i++){
fn(this[i]);
}
return this;
};
},
String : function(){
this.trim = function(){
var _re,_argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(^\s*)|(\s*$)/g : _re = new RegExp("(^"+_argument+"*)|("+_argument+"*$)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.ltrim = function(){
var _re, _argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(^\s*)/g : _re = new RegExp("(^"+_argument+"*)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.rtrim = function(){
var _re, _argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(\s*$)/g : _re = new RegExp("("+_argument+"*$)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.concat = function(){
var s = new StringBuffer();
s.append(this);
for (var i=0,j; j=arguments[i]; i++){
s.append(typeof j=="object" ? j.join("") : j);
}
return s.toString();
};
this.stripTags = function(){
return this.replace(/<\/?[^>]+>/gi, '');
};
this.cint = function(){
return this.replace(/\D/g,"")-0;
};
this.camelize = function(){
return this.replace(/(-\S)/g,function($1){return $1.toUpperCase().substring(1,2)})
};
this.hasSubString = function(s,f){
if(!f) f="";
var v = (f+this+f).indexOf(f+s+f);
return v==-1?false:v;
};
this.toXMLString = function(){
var arr = arguments[0].split("&");
var str = new StringBuffer();
for (var i=0,len=arr.length; i<len; i++){
var item = arr[i].split("=");
str.append("<"+item[0]+"><![CDATA["+item[1]+"]]></"+item[0]+">");
}
return str.toString();
};
this.URLEncode = function(){ return encodeURIComponent(this)};
this.URLDecode = function(){ return decodeURIComponent(this)};
},
StringBuffer : function(){
this.append = function(){this.data.push(arguments[0]);return this};
this.toString = function(){return this.data.join(arguments[0]||"")};
this.length = function(){return this.data.length};
},
NameSpace : function(){
this.copyChild = this.appendChild = function(ns){
for (var key in ns){
this[key] = ns[key];
}
return this;
};
}
};
Method.Array.apply(Array.prototype);
Method.String.apply(String.prototype);
Method.StringBuffer.apply(StringBuffer.prototype);
Method.NameSpace.apply(NameSpace.prototype);
function $(){
var elem = typeof(arguments[0])=="string"?document.getElementById(arguments[0]):arguments[0];
if (!elem){return null}
if (elem["version"]){return elem}
if ( arguments[1] == undefined || arguments[1]==true ){Method.Element.apply(elem);}
return elem;
};
$(document);
var Ajax={
xmlhttp:function (){
try{
return new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
return new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
return new XMLHttpRequest();
}
}
}
};
Ajax.Request=function (){
if(arguments.length<2)return ;
var para = {asynchronous:true,method:"GET",parameters:""};
for (var key in arguments[1]){
para[key] = arguments[1][key];
}
var _x=Ajax.xmlhttp();
var _url=arguments[0];
if(para["parameters"].length>0) para["parameters"]+='&_=';
if(para["method"].toUpperCase()=="GET") _url+=(_url.match(/\?/)?'&':'?')+para["parameters"];
_x.open(para["method"].toUpperCase(),_url,para["asynchronous"]);
_x.onreadystatechange=function (){
if(_x.readyState==4){
if(_x.status==200)
para["onComplete"]?para["onComplete"](_x):"";
else{
para["onError"]?para["onError"](_x):"";
}
}
};
if(para["method"].toUpperCase()=="POST")_x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
for (var ReqHeader in para["setRequestHeader"]){
_x.setRequestHeader(ReqHeader,para["setRequestHeader"][ReqHeader]);
}
_x.send(para["method"].toUpperCase()=="POST"?(para["postBody"]?para["postBody"]:para["parameters"]):null);
};
var Cookies = {
get : function(n){
var dc = "; "+document.cookie+"; ";
var coo = dc.indexOf("; "+n+"=");
if (coo!=-1){
var s = dc.substring(coo+n.length+3,dc.length);
return unescape(s.substring(0, s.indexOf("; ")));
}else{
return null;
}
},
set : function(name,value,expires){
var expDays = expires*24*60*60*1000;
var expDate = new Date();
expDate.setTime(expDate.getTime()+expDays);
var expString = expires ? "; expires="+expDate.toGMTString() : "";
var pathString = ";path=/";
document.cookie = name + "=" + escape(value) + expString + pathString;
},
del : function(n){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=this.get(n);
if(cval!=null) document.cookie= n + "="+cval+";expires="+exp.toGMTString();
}
}
function $A(list){
var arr = [];
for (var i=0,len=list.length; i<len; i++){
arr[i] = list[i];
}
return arr;
}
function $D(str){return str.URLDecode();}
function $E(str){return str.URLEncode();}
function $V(id){return $(id).value}
function request(paras){
var url = location.href;
var paraString = "&"+url.substring(url.indexOf("?")+1,url.length)+"&";
if (paraString.indexOf("&"+paras+"=")==-1){return ""};
paraString = paraString.substring(paraString.indexOf("&"+paras+"=")+paras.length+2,paraString.length);
return paraString.substring(0,paraString.indexOf("&"));
}
这个小框架已经应用到公司的项目,并开始逐步在前端展示页面上接替prototype.js。以后将围绕这个框架做一些应用。
复制代码 代码如下:
/*
* My JavaScript Framework
* Version : 1.0 beta
* Author : misshjn
* Email : misshjn@163.com
*/
function NameSpace(){};
function StringBuffer(){this.data = []};
var Method = {
Version : "1.0 beta",
Element : function(){
this.version = Method.Version;
this.hide = function(){this.style.display="none"; return this};
this.show = function(){this.style.display=""; return this};
this.getStyle = function(s){
var value = this.style[s.camelize()];
if (!value){
if (this.currentStyle) {
value = this.currentStyle[s.camelize()];
}else if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(this, null);
value = css ? css.getPropertyValue(s) : null;
}
}
return value;
};
this.setStyle = function(s){
var sList = s.split(";");
for (var i=0,j; j=sList[i]; i++){
var k = j.split(":");
this.style[k[0].trim().camelize()] = k[1].trim();
}
return this;
};
this.toggle = function(){this.getStyle("display")=="none"?this.setStyle("display:"):this.setStyle("display:none"); return this};
this.hasClassName = function(c){return this.className.hasSubString(c," ")?true:false;};
this.addClassName = function(c){if(!this.hasClassName(c)){this.className+=" "+c};return this};
this.removeClassName = function(c){if(this.hasClassName(c)){this.className = (" "+this.className+" ").replace(" "+c+" "," ").trim(); return this}};
this.getElementsByClassName = function(c){return this.getElementsByAttribute("className",c)};
this.getElementsByAttribute = function(n,v){ //name,value;
var elems = this.getElementsByTagName("*");
var elemList = [];
for (var i=0,j; j=elems[i]; i++){
var att = j[n] || j.getAttribute(n);
if (att==v){
elemList.push(j);
}
}
return elemList;
};
this.parentIndex = function(p){
if (this==p){return 0}
for (var i=0,n=this; n=n.parentNode; i++){
if(n==p){return i;}
if(n==document.documentElement) return -1;
}
}
this.nextElement = function(){
var n = this;
for (var i=0,n; n = n.nextSibling; i++){
if(n.nodeType==1) return $(n);
}
return null;
};
this.previousElement = function(){
var n = this;
for (var i=0,n; n = n.previousSibling; i++){
if(n.nodeType==1) return $(n);
}
return null;
};
this.moveAhead = function(){
if (this.previousElement()){
this.parentNode.insertBefore(this,this.previousElement());
}
return this;
};
this.moveBack = function(){
var n = this.nextElement();
if (n){
this.parentNode.removeChild(n);
this.parentNode.insertBefore(n,this);
}
return this;
};
},
Array : function(){
this.indexOf = function(){
for (i=0; i<this.length; i++){
if (this[i]==arguments[0])
return i;
}
return -1;
};
this.lastIndexOf = function(){
for (i=this.length-1; i>=0; i--){
if (this[i]==arguments[0])
return i;
}
return -1;
};
this.each = function(fn){
for (var i=0,len=this.length; i<len; i++){
fn(this[i]);
}
return this;
};
},
String : function(){
this.trim = function(){
var _re,_argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(^\s*)|(\s*$)/g : _re = new RegExp("(^"+_argument+"*)|("+_argument+"*$)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.ltrim = function(){
var _re, _argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(^\s*)/g : _re = new RegExp("(^"+_argument+"*)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.rtrim = function(){
var _re, _argument = arguments[0] || " ";
typeof(_argument)=="string"?(_argument == " "?_re = /(\s*$)/g : _re = new RegExp("("+_argument+"*$)","g")) : _re = _argument;
return this.replace(_re,"");
};
this.concat = function(){
var s = new StringBuffer();
s.append(this);
for (var i=0,j; j=arguments[i]; i++){
s.append(typeof j=="object" ? j.join("") : j);
}
return s.toString();
};
this.stripTags = function(){
return this.replace(/<\/?[^>]+>/gi, '');
};
this.cint = function(){
return this.replace(/\D/g,"")-0;
};
this.camelize = function(){
return this.replace(/(-\S)/g,function($1){return $1.toUpperCase().substring(1,2)})
};
this.hasSubString = function(s,f){
if(!f) f="";
var v = (f+this+f).indexOf(f+s+f);
return v==-1?false:v;
};
this.toXMLString = function(){
var arr = arguments[0].split("&");
var str = new StringBuffer();
for (var i=0,len=arr.length; i<len; i++){
var item = arr[i].split("=");
str.append("<"+item[0]+"><![CDATA["+item[1]+"]]></"+item[0]+">");
}
return str.toString();
};
this.URLEncode = function(){ return encodeURIComponent(this)};
this.URLDecode = function(){ return decodeURIComponent(this)};
},
StringBuffer : function(){
this.append = function(){this.data.push(arguments[0]);return this};
this.toString = function(){return this.data.join(arguments[0]||"")};
this.length = function(){return this.data.length};
},
NameSpace : function(){
this.copyChild = this.appendChild = function(ns){
for (var key in ns){
this[key] = ns[key];
}
return this;
};
}
};
Method.Array.apply(Array.prototype);
Method.String.apply(String.prototype);
Method.StringBuffer.apply(StringBuffer.prototype);
Method.NameSpace.apply(NameSpace.prototype);
function $(){
var elem = typeof(arguments[0])=="string"?document.getElementById(arguments[0]):arguments[0];
if (!elem){return null}
if (elem["version"]){return elem}
if ( arguments[1] == undefined || arguments[1]==true ){Method.Element.apply(elem);}
return elem;
};
$(document);
var Ajax={
xmlhttp:function (){
try{
return new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
return new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
return new XMLHttpRequest();
}
}
}
};
Ajax.Request=function (){
if(arguments.length<2)return ;
var para = {asynchronous:true,method:"GET",parameters:""};
for (var key in arguments[1]){
para[key] = arguments[1][key];
}
var _x=Ajax.xmlhttp();
var _url=arguments[0];
if(para["parameters"].length>0) para["parameters"]+='&_=';
if(para["method"].toUpperCase()=="GET") _url+=(_url.match(/\?/)?'&':'?')+para["parameters"];
_x.open(para["method"].toUpperCase(),_url,para["asynchronous"]);
_x.onreadystatechange=function (){
if(_x.readyState==4){
if(_x.status==200)
para["onComplete"]?para["onComplete"](_x):"";
else{
para["onError"]?para["onError"](_x):"";
}
}
};
if(para["method"].toUpperCase()=="POST")_x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
for (var ReqHeader in para["setRequestHeader"]){
_x.setRequestHeader(ReqHeader,para["setRequestHeader"][ReqHeader]);
}
_x.send(para["method"].toUpperCase()=="POST"?(para["postBody"]?para["postBody"]:para["parameters"]):null);
};
var Cookies = {
get : function(n){
var dc = "; "+document.cookie+"; ";
var coo = dc.indexOf("; "+n+"=");
if (coo!=-1){
var s = dc.substring(coo+n.length+3,dc.length);
return unescape(s.substring(0, s.indexOf("; ")));
}else{
return null;
}
},
set : function(name,value,expires){
var expDays = expires*24*60*60*1000;
var expDate = new Date();
expDate.setTime(expDate.getTime()+expDays);
var expString = expires ? "; expires="+expDate.toGMTString() : "";
var pathString = ";path=/";
document.cookie = name + "=" + escape(value) + expString + pathString;
},
del : function(n){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=this.get(n);
if(cval!=null) document.cookie= n + "="+cval+";expires="+exp.toGMTString();
}
}
function $A(list){
var arr = [];
for (var i=0,len=list.length; i<len; i++){
arr[i] = list[i];
}
return arr;
}
function $D(str){return str.URLDecode();}
function $E(str){return str.URLEncode();}
function $V(id){return $(id).value}
function request(paras){
var url = location.href;
var paraString = "&"+url.substring(url.indexOf("?")+1,url.length)+"&";
if (paraString.indexOf("&"+paras+"=")==-1){return ""};
paraString = paraString.substring(paraString.indexOf("&"+paras+"=")+paras.length+2,paraString.length);
return paraString.substring(0,paraString.indexOf("&"));
}
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。