- /*!
- * JSFunction JavaScript Library v1.2.0
- * https://dl.dropbox.com/u/590596/index.html
- *
- * Copyright 2010, Poppy
- *
- */
- /**
- * 函数绑定this和参数
- * @param {Object} $1 新函数的this指向$1
- * $2... 加动态参数 即成为新函数的参数
- */
- Function.prototype.bind = function(){
- var a = Array.prototype.slice.call(arguments), m = this, o = a.shift();
- return function(){
- return m.apply(o || this, a.concat(Array.prototype.slice.call(arguments)));
- }
- };
- /**
- * 扩展 function 方法等
- * @param {String|Object} k
- * @param {Object} v
- */
- Function.prototype.extra = function(k, v){
- if (typeof k ==
"string"
)
- this[k] = v;
- else
- for(var n in k)
- this[n] = k[n];
- return this;
- };
- /**
- * 延时执行 闭包 函数
- */
- Function.prototype.exe = function(){
- //=====================================================================核心 绝对私有函数 开始
- var _version =
"1.2.0"
,
- /**
- * 将字符串中_以及后面的字母转换_后面字符的大写形式
- * @param {String} s
- */
- _toUpper = function(s){
- return s.replace(/\-(\w)/g, function($1){
- return $1.toUpperCase();
- }).replace(/-/g,
""
);
- },
- /**
- * 非IE下设置某些特殊属性 转义
- */
- _ExAttNams = {
- className:
"class"
- },
- /**
- * 给Dom属性赋值
- * @param {String} k 赋值的键
- * @param {Object} v 赋值的值
- */
- _ExAttr = function(k, v){
- var d = this;
- if (k ==
"style"
) {
- _.isStr(v) ? d.style.cssText = v : _.Ex.css.call(d, v);
- return;
- }
- if (_.IE == 0 && _ExAttNams[k])
- k = _ExAttNams[k];
- if (_.isFn(v) || k ==
"className"
)
- d[k] = v;
- else
- if (v === false || v === null || v === undefined)
- d.removeAttribute(k);
- else
- if (v === true)
- d.setAttribute(k, k);
- else
- d.setAttribute(k, v);
- },
- /**
- * dom的CSS属性赋值
- * @param {String} k 赋值CSS属性的键
- * @param {Object} v 赋值CSS属性的值
- */
- _ExCss = function(k, v){
- var d = this;
- if(k==
"opacity"
&& _.IE){
- if(d.filters && d.filters[
"alpha"
])
- if(v==
""
)
- d.style.filter = d.style.filter.replace(/alpha\(Opacity=[\d.]+\)/.test(d.style.filter)?/alpha\(Opacity=[\d.]+\)/g:/Opacity=[\d.]+/g,
""
);
- else
- d.filters[
"alpha"
]["Opacity"
] = (v||0)*100;
- else
- d.style.filter += (
"alpha(Opacity="
+v*100+")"
);
- return ;
- }
- d.style[_toUpper(k)] = v;
- },
- /**
- * Dom | Doms 筛选器
- * @param {String} 筛选字段
- */
- _Choice = function(s){
- var d = _(s);
- if (d)
- return d;
- //多位 ID 筛选 数组
- if (/^#(.*)\[([^\]]*)\](.*)$/.test(s)) {
- var q = RegExp[
"$1"
] ? RegExp["$1"
] + "."
: ""
,
- h = RegExp[
"$3"
] ? "."
+ RegExp["$3"
] : ""
,
- Rx = RegExp[
"$2"
].split(/[ ]/g), r = [];
- for(var i = 0; i < Rx.length; i += 1)
- r.push(_(q + Rx[i] + h));
- return r;
- }
- //多位 ID 筛选 对象
- if (/^#(.*)\{([^\]]*)\}(.*)$/.test(s)) {
- var q = RegExp[
"$1"
] ? RegExp["$1"
] + "."
: ""
,
- h = RegExp[
"$3"
] ? "."
+ RegExp["$3"
] : ""
,
- Rx = RegExp[
"$2"
].split(/[ ]/g), r = {};
- for(var i = 0; i < Rx.length; i += 1)
- r[Rx[i]] = _(q + Rx[i] + h);
- return r;
- }
- //Name 筛选 数组
- if (/^&(.*)$/.test(s))
- return _.toArr(document.getElementsByName(RegExp[
"$1"
]));
- //Tag 筛选 数组
- if (/^\*(.*)\[([^\]]*)\]$/.test(s)) {
- var fa = RegExp[
"$1"
] ? _(RegExp["$1"
]) : document,
- Rx = RegExp[
"$2"
].split(/[ ]/g),
- r = [];
- for(var i = 0; i < Rx.length; i += 1)
- r = r.concat(_.toArr(fa.getElementsByTagName(Rx[i])));
- return r;
- }
- return null;
- },
- /**
- * 动画涉及的 自动可变项目
- */
- _aOpt = [
"marginLeft"
,"marginRight"
,"paddingLeft"
,"paddingRight"
,"marginTop"
,"marginBottom"
,"paddingTop"
,"paddingBottom"
],
- /**
- * 动画涉及的 手动项目
- */
- _animes = {
- def:[
"opacity"
,"width"
,"height"
],
- opacity:[
"opacity"
],
- oWidth:[
"opacity"
,"width"
],
- oHeight:[
"opacity"
,"height"
],
- width:[
"width"
],
- height:[
"height"
]
- },
- /**
- * 动画时长 预定义
- */
- _speed = {
- slow:400,
- fast:200
- },
- /**
- * 动画统一的时钟
- */
- _clock = {
- Itvs:{},
- add:function(fn){
- var k = Date.parse(new Date()) + parseInt(Math.random()*1000);
- _clock.Itvs[k] = fn;
- if(_clock.itv==null)
- _clock.itv = setInterval(_clock.step,_.IE?13:35);
- return k;
- },
- remove:function(k){
- delete _clock.Itvs[k];
- },
- step:function(){
- var i=0;
- for(var n in _clock.Itvs){
- i+=1;
- _clock.Itvs[n]();
- }
- if(i==0){
- clearInterval(_clock.itv);
- _clock.itv = null;
- }
- }
- },
- /**
- * 获得与1970-1-1的毫秒差
- * @param {Date} d
- */
- _getMilliseconds = function(d){
- if(!d)d = new Date();
- return Date.parse(d) + d.getMilliseconds();
- },
- /**
- * 动画效果函数
- * @param {Element} dom 节点
- * @param {String} type 类型
- * @param {Number} speed 速度
- * @param {Function} jsback 回调
- * @param {Arrray} anime 动画类型
- */
- _fxc = function(dom,type,speed,jsback,anime){
- var arr = {},mx = {},unit = {},endTime = _getMilliseconds() + speed,count = 0,show = type==
"show"
;
- for(var i=0,n,o,v;i<_aOpt.length;i+=1){
- n = _aOpt[i];
- o = _.Ex.css.call(dom,n);
- v = parseFloat(o) || 0;
- if(v<=0) continue;
- arr[n] = o;
- mx[n] = v;
- unit[n] = o.replace(/\d/g,
""
);
- if(show)_.Ex.css.call(dom,0);
- }
-
- var setAnime = {
- //水平 滚动
- width:function(){
- arr.width = _.Ex.css.call(dom,
"width"
);
- unit.width = arr.width?arr.width.replace(/\d/g,
""
):"px"
;
- mx.width = parseFloat(arr.width) || _.Ex.cssWidth.call(dom);
- if(show)_.Ex.css.call(dom,
"width"
,"0px"
);
- },
- //垂直 滚动
- height:function(){
- arr.height = _.Ex.css.call(dom,
"height"
);
- unit.height = arr.height?arr.height.replace(/\d/g,
""
):"px"
;
- mx.height = parseFloat(arr.height) ||_.Ex.cssHeight.call(dom);
- if(show)_.Ex.css.call(dom,
"height"
,"0px"
);
- },
- //透明度
- opacity:function(){
- arr.opacity = _.Ex.css.call(dom,
"opacity"
) || ""
;
- unit.opacity =
""
;
- mx.opacity = arr.opacity || 1;
- if(show)_.Ex.css.call(dom,
"opacity"
,0.001);
- }
- };
- //每次滚动的 变换
- function step(fg){
- var p = (speed - endTime + _getMilliseconds())/speed, flg = fg || p>=1;
- if(flg && !show)_.Ex.css.call(dom,
"display"
,"none"
);
- for(var n in arr)
- _.Ex.css.call(dom,n,flg?arr[n]:(parseFloat(mx[n]*((-Math.cos((show?p:1-p)*Math.PI)/2) + 0.5)) + unit[n]));
- if(flg){
- _.Ex.css.call(dom,
"overflow"
,ov);
- if(!fg && jsback)jsback();
- clear();
- }
- };
- //清楚计时器
- function clear(){
- dom.$fxcKey = null;
- _clock.remove(Itv);
- Itv = null;
- };
-
- if(show)dom.style.display = dom.getAttribute(
"displayShow"
) || "block"
;
- for(i=0;ilength;i+=1)
- if(setAnime[anime[i]])setAnime[anime[i]]();
- var ov = _.Ex.css.call(dom,
"overflow"
);
- _.Ex.css.call(dom,
"overflow"
,"hidden"
);
- var Itv = _clock.add(step);
- dom.$fxcKey = Itv;
- return Itv;
- };
- //=====================================================================核心 绝对私有函数 结束 *** 隐藏方法开始========
- /**
- * 单个节点查找
- * @param {Object} v
- */
- var _ = function(v){
- return _.isStr(v) ? document.getElementById(v) : v;
- }.extra({
- /**
- * IE版本号
- */
- IE: (window.attachEvent && window.ActiveXObject && !window.opera)?
- parseInt(navigator.userAgent.toLowerCase().match(/msie ([\d.]+)/)[1]):0,
- Opera:navigator.userAgent.indexOf(
"Opera"
)>=0,
- /**
- * 验证 v的类型是否和f相同
- * @param {Object} v
- * @param {Object} f
- */
- ckType: function(v, f){
- if (v == null || v == window || v == document || v == f)
- return v == f;
-
- var r = v.nodeName ? v.nodeType == 1 ?
"Element"
: v.nodeType == 3 ? "Text"
: undefined : undefined;
- if (v.constructor && v.constructor === f){
- if(f===Object && _.Opera)return r==undefined;
- return true;
- }
-
- var r = v.nodeName ? v.nodeType == 1 ?
"Element"
: v.nodeType == 3 ? "Text"
: undefined : undefined;
- if (r)
- return r == f;
- r = _.trimStr(v.constructor.toString()).match(/^function\s*([\w$]*)/)[1];
- return r == f;
- },
- /**
- * 遍历 o
- * @param {Object|Array} o
- * @param {Function} f
- */
- each:function(o,f,self){
- if(typeof o.length ==
"number"
)
- for(var i=0;ilength;i+=1)self?f.call(self,i,o[i]):f(n,o[i]);
- else
- for(var n in o)self?f.call(self,n,o[n]):f(n,o[n]);
- return self || this;
- },
- /**
- * 去除两端空白字符
- * @param {String} v
- */
- trimStr: function(v){
- return (v ||
""
).replace(/^\s+|\s+$/g, ""
);
- },
- /**
- * 判断v是否是字符串
- * @param {Object} v
- * @param {Boolean} f 是否是严格类型的
- */
- isStr: function(v, f){
- return f ? _.ckType(v, String) : typeof v ==
"string"
;
- },
- /**
- * 判断v是否是 函数
- * @param {Object} v
- * @param {Boolean} f 是否是严格类型的
- */
- isFn: function(v, f){
- return f ? _.ckType(v, Function) : typeof v ==
"function"
;
- },
- /**
- * 判断v是否是 数组
- * @param {Object} v
- * @param {Boolean} f 是否是严格类型的
- */
- isArr: function(v, f){
- return f ? _.ckType(v, Array) : Object.prototype.toString.call(v) ==
"[object Array]"
;
- },
- /**
- * object 或者 array
- * @param {Object} v
- * @param {Object} f 是否是严格类型的
- */
- isAO: function(v, f){
- return v && (_.isArr(v, f) || _.ckType(v, Object));
- },
- /**
- * 将v强制转换成数组
- * @param {Object} v
- */
- toArr: function(v){
- if (_.isArr(v))
- return v;
- if (v == null)
- return [];
- var i = v.length;
- if (i == null || _.isStr(v) || _.isFn(v) || v === window)
- return [v];
- try {
- var r = Array.prototype.slice.call(v);
- }catch(e){
- var r = [];
- while (i)r[--i] = v[i];
- }
- return r;
- },
- /**
- * 将p格式化成url字符串
- * @param {Object} p
- * @param {Function} f 格式化函数
- * @param {Object} l1 连接字符 =
- * @param {Object} l2 连接字符 &
- */
- formatUrl: function(p, f, l1, l2){
- var s = [];
- if(p)
- for(var n in p)
- s.push(n + (l1 ||
"="
) + (f || encodeURIComponent)(p[n]));
- return s.join(l2 ||
"&"
);
- },
- /**
- * 格式化 v 代码化
- * @param {String} v
- */
- formatScript: function(v){
- try {
- window.execScript(v);
- return true;
- }catch(e){
- try {
- window.eval(v);
- return true;
- }catch(e){
- return false;
- }
- }
- },
- /**
- * 将XML格式的字符串 v 格式化为 XML
- * @param {String} v
- */
- str2xml: function(v){
- try {
- var X = new ActiveXObject(
"Microsoft.XMLDOM"
), f = X.loadXML(v);
- return f ? X : null;
- }catch (e) {
- try {
- var X = new DOMParser().parseFromString(v,
"text/xml"
);
- return X.documentElement ? X : null;
- }catch (e) {
- return null;
- }
- }
- },
- /**
- * 将json格式字符串转换成 json
- * @param {String} s
- */
- str2json: function(v){
- try {
- return eval(
"("
+ v + ")"
);
- }catch (e) {
- return null;
- }
- },
- /**
- * 单点Dom处理对象 所有的this指向Element节点
- */
- Ex: {
- /**
- * 设置Element属性
- * @param {Object|String} k
- * @param {Object} v
- */
- attr: function(k, v){
- if (v === undefined && _.isStr(k))
- return this[k] === undefined ? this.getAttribute(k) : this[k];
- if (_.isStr(k))
- _ExAttr.call(this, k, v);
- else
- _.each(k,_ExAttr,this);
- return this;
- },
- /**
- * Dom上增加一个样式
- * @param {String} v
- */
- addClass:function(v){
- v = _.trimStr(v);
- if(!v)return this;
- if(!this.className){
- this.className = v;
- return this;
- }
-
- var cn =
" "
+ _.trimStr(this.className).replace(/\s+/g," "
) + " "
;
- _.each(v.split(/\s+/),function(){
- if(cn.indexOf(
" "
+ arguments[1] + " "
)<0)cn += (arguments[1] + " "
);
- },this);
- this.className = _.trimStr(cn);
- return this;
- },
- /**
- * Dom上移除一个样式
- * @param {String} v
- */
- removeClass:function(v){
- if(!this.className)return this;
- v = _.trimStr(v);
- if(!v)return this;
-
- var cn =
" "
+ _.trimStr(this.className).replace(/\s+/g," "
) + " "
;
- _.each(v.split(/\s+/),function(){
- if(cn.indexOf(
" "
+ arguments[1] + " "
)>=0)cn = cn.replace(" "
+ arguments[1] + " "
," "
);
- },this);
- this.className = _.trimStr(cn);
- return this;
- },
- /**
- * 设置Element样式属性
- * @param {Object|String} k
- * @param {Object} v
- */
- css: function(k, v){
- if (v === undefined && _.isStr(k)){
- if(k==
"opacity"
&& _.IE){
- return this.filters[
"alpha"
]?this.filters["alpha"
]["Opacity"
]/100 || ""
:""
;
- }
- return this.style[_toUpper(k)];
- }
- if (_.isStr(k))
- _ExCss.call(this, k, v);
- else
- _.each(k,_ExCss,this);
- return this;
- },
- /**
- * 获得Dom的CSS宽度 如果是自动 更具offset自动算出
- */
- cssWidth:function(){
- var v = _.Ex.css.call(this,
"width"
);
- if(v)return v.replace(/^\d/g,
""
)*1;
- v = this.offsetWidth;
- if(v==0)return 0;
- v -= parseFloat(_.Ex.css.call( this,
"paddingLeft"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"paddingRight"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"borderLeftWidth"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"borderRightWidth"
)) || 0;
- return v;
- },
- /**
- * 获得Dom的CSS高度 如果是自动 更具offset自动算出
- */
- cssHeight:function(){
- var v = _.Ex.css.call(this,
"height"
);
- if(v)return v.replace(/^\d/g,
""
)*1;
- v = this.offsetHeight;
- if(v==0)return 0;
- v -= parseFloat(_.Ex.css.call( this,
"paddingTop"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"paddingBottom"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"borderTopHeight"
)) || 0;
- v -= parseFloat(_.Ex.css.call( this,
"borderBottomHeight"
)) || 0;
- return v;
- },
- /**
- * 增加对本节点的 显示动画 的函数
- * @param {String|Number} s 动画时长
- * @param {Function} b 动画结束回调
- * @param {Object} a 动画类型 width height def opacity
- */
- show: function(s,b,a){
- if(this.$fxcKey)$.Fn.fxcStop(this.$fxcKey);
- if(s)return _fxc(this,
"show"
,_speed[s]?_speed[s]:s,b,_animes[a]?_animes[a]:_animes.def);
- if(this.style.display ==
"none"
)this.style.display = this.getAttribute("displayShow"
) || "block"
;
- return this;
- },
- /**
- * 增加对本节点的 显示动画 的函数
- * @param {String|Number} s 动画时长
- * @param {Function} b 动画结束回调
- * @param {Object} a 动画类型 width height def opacity
- */
- hide:function(s,b,a){
- if(this.$fxcKey)$.Fn.fxcStop(this.$fxcKey);
- if(s)return _fxc(this,
"hide"
,_speed[s]?_speed[s]:s,b,_animes[a]?_animes[a]:_animes.def);
- if(this.style.display !=
"none"
)this.style.display = "none"
;
- return this;
- },
- /**
- * 设置innerHTML属性 或者获得thi的innerHTML属性
- * @param {String} v
- */
- html: function(v){
- if (v === undefined)
- return this.innerHTML;
- this.innerHTML = v;
- return this;
- },
- /**
- * 设置innerTextL属性 或者获得thi的innerText属性
- * @param {String} v
- */
- text: function(v){
- var k = _.IE ?
"innerText"
: "textContent"
;
- if (v === undefined)
- return this[k];
- this[k] = v;
- return this;
- },
- /**
- * 清除this下的所有字节点
- */
- clear: function(){
- while (this.childNodes.length)this.removeChild(this.lastChild);
- return this;
- },
- /**
- * 获得Element的 宽 高 左 顶部
- * width height left top
- */
- getCoord: function(){
- var l=0,t=0,e=this;
- while(e.parentNode){
- l += (e.offsetLeft - e.scrollLeft);
- t += (e.offsetTop - e.scrollTop);
- e = e.parentNode;
- }
- return {left:l,top:t,width:this.offsetWidth,height:this.offsetHeight};
- },
- /**
- * 添加字节点
- * @param {Element | Elements} v
- */
- append: function(v){
- d = _Choice(v);
- if (_.isAO(v))
- for(var n in v)_.Ex.append.call(this, v[n]);
- else
- this.appendChild(v);
- return this;
- },
- /**
- * 将自己加入到目标节点中去
- * @param {Object} d
- */
- appendTo: function(d){
- _.Ex.append.call(_(d),this);
- return this;
- },
- /**
- * 添加事件
- * @param {String} e
- * @param {Function} f
- */
- addEvent: function(e,f){
- if(this.attachEvent)
- this.attachEvent(
"on"
+ e,f);
- else if(this.addEventListener)
- this.addEventListener(e, f, false);
- else
- this[
"on"
+ e] = f;
- return this;
- },
- /**
- * 移除事件
- * @param {String} e
- * @param {Function} f
- */
- removeEvent: function(e,f){
- if(this.detachEvent)
- this.detachEvent(
"on"
+ e,f);
- else if(this.removeEventListener)
- this.removeEventListener(e, f, false);
- else
- delete this[
"on"
+ e];
- return this;
- },
- /**
- * 设置input为空时提示信息
- * @param {String} i
- */
- setIptCue: function(v){
- this.value = v;
- _.Ex.addEvent.call(this,
"focus"
, function(){
- if(_.trimStr(this.value)==v)this.value =
""
;
- }.bind(this));
- _.Ex.addEvent.call(this,
"blur"
, function(){
- if(_.trimStr(this.value)==
""
)this.value = v;
- }.bind(this));
- return this;
- },
- /**
- * 设置回车提交 或者Ctrl回车提交
- * @param {Function|Element} t
- * @param {boolean} f 是否需要加入ctrl
- */
- setEnterDo: function(t,f){
- _.Ex.addEvent.call(this,
"keyup"
, function(ev){
- ev = ev || window.event;
- if(ev.keyCode*1==13 && (!f || ev.ctrlKey)){
- try{t();}catch(e){_.Ex.doEvent.call(_(t),
"click"
);}
- };
- });
- return this;
- },
- /**
- * 模拟事件执行
- * @param {String} v
- */
- doEvent: function(v){
- v = v ||
"click"
;
- if(document.createEventObject)
- this.fireEvent(
'on'
+ v);
- else if(document.createEvent){
- var o = document.createEvent(
'MouseEvents'
);
- o.initEvent(v,true,false);
- this.dispatchEvent(o);
- }
- else
- this[
"on"
+ v]();
- return this;
- },
- /**
- * 设置Dom加载完毕时调用
- * @param {Function} f
- */
- ready: function(f){
- if(this.addEventListener)
- this.addEventListener(
"DOMContentLoaded"
, f, false);
- else if(this.attachEvent)
- this.attachEvent(
"onreadystatechange"
, function(){
- if (this.readyState ==
"complete"
|| this.readyState == "loaded"
)f();
- }.bind(this));
- else
- f.exe(0);
- return this;
- }
- },
- /**
- * 单个Dom操作 直接转多个Dom操作
- * @param {String} k 操作函数
- * @param {Boolean} f 是否需要分散参数
- * @param {Object} n 定义的参数个数
- * @param {Object} v 第v个参数确定 返回值
- */
- ExsBind: function(k, f, n, v){
- return function(){
- var r = _.isArr(this) ? [] : {};
- var b = v > 0 ? arguments[v - 1] ? -1 : 0 : v;
- for(var m in this)
- r[m] = _.Ex[k].apply(this[m], f ? function(){
- for(var i = 0, a = []; i < n; i += 1)
- a.push(_.isAO(this[i]) ? this[i][m] : this[i]);
- return a;
- }.call(arguments) : arguments);
- return b ? this : r;
- }
- }
- });
-
- /**
- * 单点Dom集合处理对象
- */
- _.Exs = function(ks){
- for(var i=0,v={};ilength;i+=1)v[ks[i][0]] = _.ExsBind.apply(null,ks[i]);
- return v;
- }([
- [
"attr"
,true,2,2],
- [
"css"
,true,2,2],
- [
"show"
,true,3,-1],
- [
"hide"
,true,3,-1],
- [
"html"
,true,1,1],
- [
"text"
,true,1,1],
- [
"appendTo"
,true,1,-1],
- [
"addEvent"
,true,2,-1],
- [
"removeEvent"
,true,2,-1],
- [
'setIptCue'
,false,1,-1],
- [
'setEnterDo'
,true,2,-1],
- [
'doEvent'
,true,1,-1]
- ]);
- /**
- * 某个显示
- * @param {Object} k 显示的对象
- * @param {Object} d 显示时 display赋的值
- */
- _.Exs.oneShow = function(k,d){
- d = d ||
""
;
- for(var n in this)this[n].style.display = (n==k || this[n]==k)?d:
"none"
;
- return this;
- };
- /**
- * 某个特殊显示
- * @param {Object} k
- * @param {Object} s 特殊样式
- * @param {Object} d 一般样式
- */
- _.Exs.oneSe = function(k,s,d){
- if(!s)return this;
- d = d ||
""
;
- var v;
- for(var n in this){
- v = (n == k || this[n] == k) ? s : _.isAO(d)?d[n] ||
""
:d;
- _.isStr(v)?this[n].className = v:_.Ex.css.call(this[n], v);
- }
- return this;
- };
- /**
- * 取得radio的值
- */
- _.Exs.radioValue = function(){
- for(var n in this)if(this[n].checked)return this[n].value;
- return null;
- };
- /**
- * 所有类的构建函数
- */
- var _newClass = function(){
- return function(a){
- //初始化函数
- if(a !== _C)
- this.onInit.apply(this, arguments);
- };
- },
- /**
- * 所有扩展类的基类
- */
- _C = _newClass();
- /**
- * 用户扩展基于本类的新类
- * @param {Object} e
- */
- _C.extend = function(e){
- var c = _newClass(),p = new this(this),s = this.prototype;
- for(var n in e){
- if(_.isFn(e[n]) && s[n])e[n].superset = s[n];//设置 此方法的 父方法 此方法的 superset 属性指向父方法的 执行
- p[n] = e[n];
- };
- c.prototype = p;
- //设置新的类的constructor 指向 自己
- c.prototype.constructor = c;
- //赋给这个新的子类同样的静态extend方法
- c.extend = this.extend;
- return c;
- };
- /**
- * 设置 constructor 执行自身
- */
- _C.prototype.constructor = _C;
- /**
- * 默认 初始化
- */
- _C.prototype.onInit = function(){};
- /**
- * 通用方法 扩展Object
- */
- _C.prototype.extra = function(){
- Function.prototype.extra.apply(this, arguments);
- return this;
- };
- /**
- * 通用方法 设置参数 设定所有参数的前缀为 $
- * @param {Object} k
- * @param {Object} v
- */
- _C.prototype.setAtt = function(k, v){
- this[
"$"
+ k] = v;
- return this;
- };
- //=====================================================================隐藏方法 结束 ** 全局量开始
- var $ = function(v,f){
- if(v==null)
- return null;
- if(_.isStr(v))
- v = _Choice(v);
- if(!v)
- return null;
- if(f===true)
- return new (_.isAO(v)?$.ElementCollect:$.Element)(v);
- if(_.isStr(f) || _.isFn(f))
- return (_.isFn(f)?f:(_.isAO(v)?_.Exs:_.Ex)[f]).apply(v,Array.prototype.slice.call(arguments,2));
- return v;
- }.extra({
- /**
- * Joo版本
- */
- $version:_version,
- /**
- * 所有新类的基类
- */
- Class:_C,
- /**
- * Collect 集合类 基于 _C
- */
- Collect:_C.extend({
- /**
- * 初始化 设置数据
- * @param {Object} v
- */
- onInit:function(v){
- this.$data = v;
- },
- /**
- * 获取指定路径数值
- * @param {String} k
- */
- get:function(k){
- return k===undefined?this.$data:this.$data[k];
- },
- /**
- * 设置指定路径的数值
- * @param {String} k
- * @param {Object} v
- */
- set:function(k,v){
- this.$data[k] = v;
- return this;
- },
- /**
- * 循环指定路径数值
- * @param {Function} f
- */
- each:function(f){
- _.each(this.$data,f,this);
- return this;
- },
- /**
- * 所有 $data 的键集合
- */
- keys:function(){
- var v = [];
- for(var n in this.$data)v.push(n);
- return v;
- },
- /**
- * 所有 $data 值集合
- */
- values:function(){
- var v = [];
- for(var n in this.$data)v.push(this.$data[n]);
- },
- /**
- * 合并 其他的 数组或者对象
- * @param {Array|Object} o
- */
- accept:function(o){
- Function.prototype.extra.call(this.$data,o);
- return ;
- }
- })
- });
- //=============================================================================节点对象
- /**
- * Element 或者 ElementCollect 附加原型方法是用的同意函数
- * @param {Object} v
- */
- var _newEC = function(v){
- return function(){
- var t = v.apply(this.$data,arguments);
- return t==this.$data?this:t;
- };
- },
- /**
- * 动态创建Dom时使用的缓存
- */
- _ElementCashe = {};
-
- /**
- * Element 单节点对象
- */
- $.Element = _C.extend(function(){
- //集合类
- var r = {};
- //循环 _.Ex 中的方法 作为Element的方法
- for(var n in _.Ex)
- r[n] = _newEC(_.Ex[n]);
- //增加 初始化函数
- r.onInit = function(s){
- this.$data = _(s);
- return this;
- };
- //增加 获得对象中的节点的方法
- r.get = function(){
- return this.$data;
- };
- return r;
- }());
- /**
- * 为Element 和 _.Ex类添加方法 用户开发插件
- * @param {String|Object} k
- * @param {Function} v
- */
- $.Element.add = function(k,v){
- var o = _.isStr(k)?k = Function.prototype.extra.call({},k,v):k;
- for(var n in o){
- _.Ex[n] = o[n];
- $.Element.prototype[n] = _newEC(o[n]);
- }
- return this;
- };
- /**
- * 动态创建Element
- * @param {String} t 节点类型 div span 等
- * @param {Object|text} 节点属性 text 为t创建文本节点
- * @param {Object} h innerHTML属性
- * @param {Object} y 加入某个数组或者节点
- */
- $.Element.create = function(t,b,h,y){
- if(b==
"text"
)return document.createTextNode(t);
- //制造节点
- b = b || {},t = t.toLowerCase();
- //IE中的只读属性
- if(_.IE && (b.name || b.checked || b.hidefocus)){
- t =
'<'
+ t;
- if(b.name){
- t = t +
' name="'
+ b.name + '"'
;
- delete b.name;
- }
- if(b.checked){
- t = t +
' checked="checked"'
;
- delete b.checked;
- }
- if(b.hidefocus){
- t = t +
' hidefocus="true"'
;
- delete b.hidefocus;
- }
- t = t +
" >"
;
- }
- if (!_ElementCashe[t])_ElementCashe[t] = document.createElement(t);
- var e = _ElementCashe[t].cloneNode(false);
- if(_.isStr(h) || typeof h ==
"number"
)e.innerHTML = h;
-
- //设置属性
- _.Ex.attr.call(e,b);
- //封装
- if(_.isArr(y))y.push(e);
- else if(_.ckType(y,
"Element"
) || _.isStr(y))_.Ex.appendTo.call(e,y);
- return e;
- };
-
- /**
- * ElementCollect 复节点对象
- */
- $.ElementCollect = $.Collect.extend(function(){
- var r = {};
- for(var n in _.Exs)r[n] = _newEC(_.Exs[n]);
- r.onInit = function(s){
- this.$data = _Choice(s);
- return this;
- };
- r.get = function(k,f){
- return this.$data[k]?f?new $.Element(this.$data[k]):this.$data[k]:this.$data;
- };
- return r;
- }());
- /**
- * 为ElementCollect 和 _.Exs类添加方法 用户开发插件
- * @param {String|Object} k
- * @param {Function} v
- */
- $.ElementCollect.add = function(k,v){
- var o = _.isStr(k)?k = Function.prototype.extra.call({},k,v):k;
- for(var n in o){
- _.Exs[n] = o[n];
- $.ElementCollect.prototype[n] = _newEC(o[n]);
- }
- return this;
- };
-
- /**
- * 创建有结构的节点群体
- * @param {Object} t
- * @param {Object} y
- */
- $.ElementCollect.create = function(t,y){
- if(_.isStr(t[0])){
- var rv = $.Element.create(t[0],t[1],t[2],(t[3] && _.isArr(t[3]))?t[3]:undefined);
- if(_.isArr(t[2]))_.Ex.append.call(rv,$.ElementCollect.create(t[2]));
- }
- else
- for(var i=0,rv = [];ilength;i+=1)rv.push(_.isArr(t[i])?$.ElementCollect.create(t[i]):t[i]);
- if(_.isStr(y) || _.ckType(y,
"Element"
))_.Ex.appendTo.call(rv,y);
- return rv;
- };
-
- //========================================================================Ajax对象
- /**
- * 创建Http对象
- */
- var _createHttp = function(){
- try {
- return new ActiveXObject(
"Msxml2.XMLHTTP"
);
- }catch (e) {
- try {
- return new ActiveXObject(
"Microsoft.XMLHTTP"
);
- }catch (e) {
- try {
- return new XMLHttpRequest();
- }catch (e) {
- return null;
- }
- }
- }
- },
- _getURl = function(u,p){
- return u + (p?(u.indexOf(
"?"
) > -1 ? "&"
: "?"
) + p:""
)
- },
- /**
- * Ajax Send 方式
- * @param {Boolean} async
- * @param {Object} pre
- * @param {Boolean} flag
- */
- _ajaxSend = function(async,pre,flag){
- if(this.$_opening){
- if(!flag)return;
- //强制中止现有的请求 执行新的请求
- _ajaxBlur.call(this,true);
- }
-
- this.$_opening = true;
-
- this.$HO = _createHttp();
- if(!this.$HO){
- try{this.onNoHttp();}catch(e){};
- return ;
- }
- var preStr = _.formatUrl(Function.prototype.extra.call(Function.prototype.extra.call({},this.$pre),pre));
- //Loading....
- try{this.onLoading();}catch(e){};
- _ajaxSetHead.call(this);
- if(this.$mType ==
"GET"
){
- this.$HO.open(this.$mType, _getURl(this.$url,preStr), async);
- preStr = null;
- }
- else {
- this.$HO.open(this.$mType, this.$url, async);
- this.$HO.setRequestHeader(
"Method"
, this.$mType+" "
+this.$url+" HTTP/1.1"
);
- this.$HO.setRequestHeader(
"Content-Type"
,"application/x-www-form-urlencoded"
);
- preStr = preStr.replace(/[\x00-\x08\x11-\x12\x14-\x20]/g,
"*"
);
- }
-
- //超时自动 中止
- if(this.$ovTime && this.$ovTime>0)this.$_blurer = setTimeout(_ajaxBlur.bind(this),this.$ovTime);
- if(async){
- this.$HO.onreadystatechange = _ajaxChange.bind(this);
- this.$HO.send(preStr);
- return this;
- }
- else{
- this.$HO.send(preStr);
- return _ajaxReady.call(this);
- }
- },
- /**
- * Ajax 状态改变时接收
- */
- _ajaxChange = function(){
- if(this.$HO && this.$HO.readyState==4)_ajaxReady.call(this);
- };
- /**
- * Ajax 请求结束
- */
- _ajaxReady = function(){
- //请求结束
- this.$_opening = false;
- _ajaxClearBlur.call(this);
- try{this.onComplete();}catch(e){};
- if(this.$HO.status !=200){
- if(this.$_blurFlag)return null;
- this.$data = null;
- try{this.onFail(this.$unusual);}catch(e){};
- _ajaxDestroy.call(this);
- return null;
- }
-
- //请求成功
- _ajaxBack[this.$bType].call(this);
- _ajaxDestroy.call(this);
- return this.$data;
- },
- /**
- * Ajax 中止
- * @param {Boolean} f
- */
- _ajaxBlur = function(f){
- _ajaxClearBlur.call(this);
- this.$_opening = false;
- this.$_blurFlag = f;
- try{
- this.$HO.abort();
- }catch(e){
- _scriptHODestroy.call(this,true);
- }
- //调用中止方法
- this.$data = null;
- if(f)try{this.onAbort();}catch(e){};
- this.$_blurFlag = null;
- },
- /**
- * 清楚超时 中止数据
- */
- _ajaxClearBlur = function(){
- if(!this.$_blurer)return;
- clearTimeout(this.$_blurer);
- this.$_blurer = null;
- },
- /**
- * Ajax 销毁
- */
- _ajaxDestroy = function(){
- if(!this.$HO)return ;
- setTimeout(function(){
- if(this.$_opening)return;
- try{
- _scriptHODestroy.call(this);
- }catch(e){
- this.$HO = null;
- delete this.$HO;
- }
- }.bind(this));
- },
- /**
- * 设置Ajax请求头
- */
- _ajaxSetHead = function(){
- if(!this.$HO || !this.$head)return ;
- if(this.$head)_.each(this.$head,this.$HO.setRequestHeader,this);
- },
- /**
- * jsonp Send 方好似
- * @param {Object} async
- * @param {Object} pre
- * @param {Object} flag
- */
- _scriptSend = function(async,pre,flag){
- if(this.$_opening){
- if(!flag)return;
- //强制中止现有的请求 执行新的请求
- _ajaxBlur.call(this,true);
- }
-
- this.$_opening = true;
- var o = Function.prototype.extra.call(Function.prototype.extra.call({},this.$pre),pre);
- o[this.$jsonpBackKey] = this.$jsonpBackValue =
"__jsonp_"
+ Date.parse(new Date()) + "__"
;
- window[this.$jsonpBackValue] = _scriptBack.bind(this);
- var preStr = _.formatUrl(o);
- //Loading....
- try{this.onLoading();}catch(e){};
-
- //超时自动 中止
- if(this.$ovTime && this.$ovTime>0)this.$_blurer = setTimeout(_scriptBlur.bind(this),this.$ovTime);
-
- this.$data = null;
- this.$HO = _createScript.call(this,_getURl(this.$url,preStr));
-
- return this;
- },
- /**
- * 创建动态的Stript标签
- * @param {String} url
- */
- _createScript = function(url){
- var v = $.Element.create(
"script"
,{type:"text/javascript"
});
- v.onreadystatechange = v.onload = _scriptChange.bind(this);
- v.src = url;
- document.getElementsByTagName(
"head"
)[0].appendChild(v);
- return v;
- },
- /**
- * 回调 设置Ajax对象的值
- * @param {Object} o
- */
- _scriptBack = function(o){
- this.$data = o;
- },
- /**
- * 销毁 script 标签
- */
- _scriptHODestroy = function(){
- this.$HO.onreadystatechange = this.$HO.onload = null;
- this.$HO.removeNode(true);
- this.$HO = null;
- window[this.$jsonpBackValue] = null;
- },
- /**
- * script 请求的请求状态
- */
- _scriptChange = function(){
- if(!this.$HO.readyState || this.$HO.readyState ==
'loaded'
|| this.$HO.readyState == 'complete'
){
- if(this.$data)this.$HO.status = 200;
- _ajaxReady.call(this);
- }
- },
- /**
- * Ajax 返回类型验证
- */
- _ajaxBack = {
- auto:function(){
- //xml
- var d = _.str2xml(this.$HO.responseText);
- if(d){
- _ajaxBack.xml.call(this,d);
- return ;
- };
- //json
- d = _.str2json(
"("
+ this.$HO.responseText + ")"
);
- if(d){
- _ajaxBack.json.call(this,d);
- return ;
- };
- //script
- d = _.formatScript(this.$HO.responseText);
- if(d){
- _ajaxBack.script.call(this,d);
- return ;
- };
- //text
- _ajaxBack.text.call(this);
- },
- text:function(){
- this.$data = this.$HO.responseText;
- try{this.onSucc(
"text"
);}catch(e){};
- },
- xml:function(xml){
- this.$data = xml || _.str2xml(this.$HO.responseText);
- var ret = this.chkXML();
- try{ret==true?this.onSucc(
"xml"
):this.onFail(ret)}catch(e){};
- },
- json:function(json){
- if(json || this.$HO.responseText)this.$data = json || _.str2json(
"("
+ this.$HO.responseText + ")"
);
- var ret = this.chkJson();
- try{ret==true?this.onSucc(
"json"
):this.onFail(ret)}catch(e){};
- },
- script:function(f){
- this.$data = null;
- try{f || _.formatScript(this.$HO.responseText)?this.onSucc(
"script"
):this.onFail(this.$unusual)}catch(e){};
- }
- };
-
- /**
- * Ajax对类 支持GET jsonp数据
- */
- $.Ajax = _C.extend({
- /**
- * 初始化 url type param overtime
- * @param {String} u url
- * @param {String} m type
- * @param {Object} p param
- * @param {Number} t overtime 毫秒
- */
- onInit:function(u,m,p,t){
- if(arguments.length==0)return ;
- this.$url = u; //请求URL
- this.$pre = p || {}; //默认参数
- var t = m?m.split(/:/g):[
"GET"
,"auto"
];
- this.$mType = t[0].toUpperCase(); //请求方式 POST GET PUT DELETE JSONP
- if(this.$mType==
"JSONP"
){ //跨域请求数据 请用这个
- this.$jsonpBackKey = t[1] ||
"jsback"
;
- t[1] =
"json"
;
- }
- //临时更改 把 PUT DELETE 等方式转为POST
- if(this.$mType!=
"POST"
&& this.$mType!="GET"
&& this.$mType!="JSONP"
){
- this.$pre._method = this.$mType;
- this.$mType =
"POST"
;
- }
- this.$bType = _ajaxBack[t[1]]?t[1] :
"auto"
; //服务端返回值
- this.$ovTime = t || 0; //请求超时
- this.$data = null;
- return this;
- },
- /**
- * 设置默认的参数
- */
- setPre:function(){
- Function.prototype.extra.apply(this.$pre,arguments);
- return this;
- },
- /**
- * 设置http的请求头
- */
- setHead:function(){
- if(!this.$head)this.$head = {};
- Function.prototype.extra.apply(this.$head,arguments);
- return this;
- },
- /**
- * 同步请求
- * @param {Object} pre
- * @param {Boolean} f 是否需要销毁当前正在的请求,继续新的请求
- */
- syncAsk:function(p,f){
- if(this.$mType==
"JSONP"
)return ; //jsonp 只支持异步传输
- return _ajaxSend.call(this,false,p,f);
- },
- /**
- * 异步请求
- * @param {Object} p
- * @param {Boolean} f 是否需要销毁当前正在的请求,继续新的请求
- */
- asyncAsk:function(p,f){
- if(this.$mType==
"JSONP"
)return _scriptSend.call(this,true,p,f);
- return _ajaxSend.call(this,true,p,f);
- },
- $unusual:
"返回数据有问题,请稍后再试试..."
- });
-
- /**
- * 常用方法 集合
- */
- var _F = $.Fn = {
- /**
- * 获取 下划线或者下划线中的方法
- * @param {Object} k
- */
- get:function(k){
- return k?_[k]:_;
- },
- /**
- * 动画效果停止
- * @param {Number} show或者hide时返回的句柄
- */
- fxcStop:function(n){
- if(_clock.Itvs[n])
- _clock.Itvs[n](true);
- }
- };
-
- /**
- * Joo核心方法
- * @param {Object} p
- */
- return function(p){
- if (p === undefined)
- return this.call($, _);
- if (p < 0) {
- _.Ex.ready.call(document, this);
- return p == -1 ? $ : _;
- };
- return setTimeout(this, p);
- };
- }();
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |