You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
24 KiB

3 years ago
//ds.base
;(function(global, document, undefined){
var
rblock = /\{([^\}]*)\}/g,
ds = global.ds = {
noop: function(){},
//Object
mix: function(target, source, cover){
if(typeof source !== 'object'){
cover = source;
source = target;
target = this;
}
for(var k in source){
if(cover || target[k] === undefined){
target[k] = source[k];
}
}
return target;
},
//String
mixStr: function(sStr){
var args = Array.prototype.slice.call(arguments, 1);
return String(sStr).replace(rblock, function(a, i){
return args[i] != null ? args[i] : a;
});
},
trim: function(str){
return String(str).replace(/^\s*/, '').replace(/\s*$/, '');
},
//Number
getRndNum: function(max, min){
min = isFinite(min) ? min : 0;
return Math.random() * ((isFinite(max) ? max : 1000) - min) + min;
},
//BOM
scrollTo: (function(){
var
duration = 480,
view = $(global),
setTop = function(top){ global.scrollTo(0, top);},
fxEase = function(t){return (t*=2)<1?.5*t*t:.5*(1-(--t)*(t-2));};
return function(top, callback){
top = Math.max(0, ~~top);
var
tMark = new Date(),
currTop = view.scrollTop(),
height = top - currTop,
fx = function(){
var tMap = new Date() - tMark;
if(tMap >= duration){
setTop(top);
return (callback || ds.noop).call(ds, top);
}
setTop(currTop + height * fxEase(tMap/duration));
setTimeout(fx, 16);
};
fx();
};
})(),
//DOM
loadScriptCache: {},
loadScript: function(url, callback, args){
var cache = this.loadScriptCache[url];
if(!cache){
cache = this.loadScriptCache[url] = {
callbacks: [],
url: url
};
var
firstScript = document.getElementsByTagName('script')[0],
script = document.createElement('script');
if(typeof args === 'object'){
for(var k in args){
script[k] = args[k];
}
}
script.src = url;
script.onload = script.onreadystatechange =
script.onerror = function(){
if(/undefined|loaded|complete/.test(this.readyState)){
script = script.onreadystatechange =
script.onload = script.onerror = null;
cache.loaded = true;
for(var i=0,len=cache.callbacks.length; i<len; i++){
cache.callbacks[i].call(null, url);
}
cache.callbacks = [];
}
};
firstScript.parentNode.insertBefore(script, firstScript);
}
if(!cache.loaded){
if(typeof callback === 'function'){
cache.callbacks.push(callback);
}
}
else{
(callback || ds.noop).call(null, url);
}
return this;
},
requestAnimationFrame: (function(){
var handler = global.requestAnimationFrame || global.webkitRequestAnimationFrame ||
global.mozRequestAnimationFrame || global.msRequestAnimationFrame ||
global.oRequestAnimationFrame || function(callback){
return global.setTimeout(callback, 1000 / 60);
};
return function(callback){
return handler(callback);
};
})(),
animate: (function(){
var
easeOut = function(pos){ return (Math.pow((pos - 1), 3) + 1);};
getCurrCSS = global.getComputedStyle ? function(elem, name){
return global.getComputedStyle(elem, null)[name];
} : function(elem, name){
return elem.currentStyle[name];
};
return function(elem, name, to, duration, callback, easing){
var
from = parseFloat(getCurrCSS(elem, name)) || 0,
style = elem.style,
tMark = new Date(),
size = 0;
function fx(){
var elapsed = +new Date() - tMark;
if(elapsed >= duration){
style[name] = to + 'px';
return (callback || ds.noop).call(elem);
}
style[name] = (from + size * easing(elapsed/duration)) + 'px';
ds.requestAnimationFrame(fx);
};
to = parseFloat(to) || 0;
duration = ~~duration || 200;
easing = easing || easeOut;
size = to - from;
fx();
return this;
};
})(),
//Cookies
getCookie: function(name){
var ret = new RegExp('(?:^|[^;])' + name + '=([^;]+)').exec(document.cookie);
return ret ? decodeURIComponent(ret[1]) : '';
},
setCookie: function(name, value, expir){
var cookie = name + '=' + encodeURIComponent(value);
if(expir !== void 0){
var now = new Date();
now.setDate(now.getDate() + ~~expir);
cookie += '; expires=' + now.toGMTString();
}
document.cookie = cookie;
},
//Hacker
transitionSupport: (function(){
var
name = '',
prefixs = ['', 'webkit', 'moz', 'ms', 'o'],
docStyle = (document.documentElement || document.body).style;
for(var i=0,len=prefixs.length; i<len; i++){
name = prefixs[i] + (prefixs[i]!=='' ? 'Transition' : 'transition');
if(name in docStyle){
return {
propName: name,
prefix: prefixs[i]
};
}
}
return null;
})(),
isIE6: !-[1,] && !global.XMLHttpRequest
};
})(this, document);
/**
* ds.tmpl.js
* create: 2013.01.10
* update: 2013.09.26
* admin@laoshu133.com
**/
;(function(global){var ds=global.ds||(global.ds={});var rarg1=/\$1/g,rgquote=/\\"/g,rbr=/([\r\n])/g,rchars=/(["\\])/g,rdbgstrich=/\\\\/g,rfuns=/<%\s*(\w+|.)([\s\S]*?)\s*%>/g,rbrhash={'10':'n','13':'r'},helpers={'=':{render:'__.push($1);'}};ds.tmpl=function(tmpl,data){var render=new Function('_data','var __=[];__.data=_data;'+'with(_data){__.push("'+tmpl.replace(rchars,'\\$1').replace(rfuns,function(a,key,body){body=body.replace(rbr,';').replace(rgquote,'"').replace(rdbgstrich,'\\');var helper=helpers[key],tmp=!helper?key+body:typeof helper.render==='function'?helper.render.call(ds,body,data):helper.render.replace(rarg1,body);return'");'+tmp+'__.push("';}).replace(rbr,function(a,b){return'\\'+(rbrhash[b.charCodeAt(0)]||b);})+'");}return __.join("");');return data?render.call(data,data):render;};ds.tmpl.helper=helpers;})(this);
/**
* jquery.mask.js
* create: 2012.12.04
* update: 2012.12.13
* admin@laoshu133.com
*/
;(function(global,document,$,undefined){var DOC=$(document),_noop=function(){},ds=global.ds||(global.ds={});var _uuid=0,_ops={id:null,anim:true,animDuration:320,zIndex:999,opacity:0.8,background:'#000',onshow:_noop,onhide:_noop,onclick:_noop},Mask=ds.Mask=function(ops){return this.init(ops);};Mask._cache={};Mask.prototype={constructor:Mask,init:function(ops){this.ops=ops=ops||{};$.each(_ops,function(k,val){typeof ops[k]==='undefined'&&(ops[k]=val);});var id=ops.id;if(typeof id!=='string'){id='ds_mask_'+(++_uuid);}this.id=id;if(Mask._cache[id]){var _mask=Mask._cache[id];_mask.ops=ops;return _mask;}Mask._cache[id]=this;return this;},_getElem:function(){var elem=this.elem,self=this;if(!elem){var ops=this.ops,css='border:0;margin:0;padding:0;height:100%;width:100%;left:0;top:0;opacity:0;';elem=this.elem=$(document.createElement('div'));elem.bind('click.jquery_mask',function(){self.ops.onclick.call(self);});elem[0].style.cssText=css+'display:none;position:fixed;background:'+ops.background+';z-index:'+ops.zIndex;if(!Mask.fixedPositionSupport()){elem[0].style.position='absolute';css+='position:absolute;filter:Alpha(opacity=0);';elem[0].innerHTML='<iframe src="javascript:false" frameborder="0" height="100%" width="100%" style="'+css+'z-index:1;"></iframe><div style="'+css+'background:#fff;z-index:9;"></div>';}elem[0].id=this.id;elem.appendTo('body');}return elem;},show:function(opacity){var self=this,ops=this.ops,elem=this._getElem();opacity=typeof opacity==='number'?opacity:ops.opacity;if(!Mask.fixedPositionSupport()){elem.css('height',DOC.height());}this.elem.css('background',ops.background).show();if(ops.anim){elem.stop().animate({opacity:opacity},ops.animDuration,function(){ops.onshow.call(self,opacity);});}else{elem.stop().css('opacity',opacity);ops.onshow.call(this,opacity);}return this;},hide:function(){var self=this,ops=this.ops,elem=this._getElem();if(ops.onhide.call(this)!==false){if(ops.anim){elem.stop().animate({opacity:0},ops.animDuration,function(){this.style.display='none';});}else{elem[0].style.display='none';}}return this;},destory:function(){if(this.elem){this.elem.remove();this.elem=null;}delete Mask._cache[this.id];}};Mask.fixedPositionSupport=function(){if(typeof $.support.fixedPosition==='boolean'){return $.support.fixedPosition;}var div,ret=false,body=document.body,css='border:0;margin:0;padding:0;position:fixed;left:0;top:20px;';if(body){div=document.createElement('div');div.style.cssText=css+'position:absolute;top:0;';div.innerHTML='<div style="'+css+'"></div>';body.insertBefore(div,body.firstChild);ret=$.support.fixedPosition=div.firstChild.offsetTop===20;body.removeChild(div);}return ret;};ds.mask=$.mask=function(opacity,background){var ops=typeof opacity==='object'?opacity:{opacity:opacity,background:background};ops.id='ds_global_mask';return new Mask(ops).show();};})(this,this.document,jQuery);
/**
* ds.dialog.js
* create: 2012.12.05
* update: 2012.12.14
* admin@laoshu133.com
*/
;(function(global,document,$,undefined){var view=$(global),DOC=$(document),ds=global.ds||(global.ds={});var _guid=0,_noop=function(){},_tmpl='<div class="ds_dialog_outer"><table class="ds_dialog_border"><tr><td class="ds_dialog_tl"></td><td class="ds_dialog_tc"></td><td class="ds_dialog_tr"></td></tr><tr><td class="ds_dialog_ml"></td><td class="ds_dialog_mc"><div class="ds_dialog_inner"><table class="ds_dialog_panel"><tr><td colspan="2" class="ds_dialog_header"><div class="ds_dialog_title"><h3></h3></div><div class="ds_dialog_close"><a href="javascript:;">\u00d7</a></div></td></tr><tr><td class="ds_dialog_icon" style="display:none"><div class="ds_dialog_icon_bg"></div></td><td class="ds_dialog_main"><div id="{id}_content" class="ds_dialog_content"></div></td></tr><tr><td colspan="2" class="ds_dialog_footer"><div class="ds_dialog_buttons"></div></td></tr></table></div></td><td class="ds_dialog_mr"></td></tr><tr><td class="ds_dialog_bl"></td><td class="ds_dialog_bc"></td><td class="ds_dialog_br"></td></tr></table></div>',_ops={id:null,title:null,content:'',className:null,padding:'20px 25px',height:'auto',width:'auto',left:'50%',top:'40%',zIndex:1990,icon:null,iconBasePath:global.iconBasePath||'images/',buttons:null,follow:null,followOffset:null,autoOpen:true,esc:true,lock:true,lockOpacity:0.6,lockColor:'#000',showCloseButton:true,drag:true,fixed:true,anim:true,animDuration:320,timeout:0,oninit:_noop,onopen:_noop,onfocus:_noop,onmaskclick:_noop,onhide:_noop,onclose:_noop,yesText:'\u786e\u5b9a',noText:'\u53d6\u6d88',onyes:null,onno:null},Dialog=ds.Dialog=function(ops){return this.init(ops||{});};$.extend(Dialog,{items:{},defaults:_ops,currIndex:1990,defaultTmpl:_tmpl,activeDialog:null,dialogQueue:[],addDialog:function(dialog){var queue=this.dialogQueue;this.removeDialog(dialog);queue.push(dialog);dialog.inQueue=true;dialog.queueIndex=queue.length-1;},removeDialog:function(dialog){var i=dialog.queueIndex,queue=this.dialogQueue;if(dialog.inQueue){queue.splice(i,1);for(var len=queue.length;i<len;i++){queue[i].queueIndex--;}}dialog.inQueue=false;dialog.queueIndex=-1;},maskQueue:[],addMask:function(dialog){this.removeMask(dialog);this.maskQueue.push(dialog);dialog.maskIndex=this.maskQueue.length-1;},removeMask:function(dialog){var i=dialog.maskIndex,maskQueue=this.maskQueue;if(dialog.locked){maskQueue.splice(i,1);for(var len=maskQueue.length;i<len;i++){maskQueue[i].maskIndex--;}}dialog.maskIndex=-1;}});Dialog.items={};Dialog.defaults=_ops;Dialog.currZIndex=1990;Dialog.defaultTmpl=_tmpl;Dialog.prototype={version:'2.0',constructor:Dialog,init:function(ops){var id=typeof ops.id==='string'?ops.id:('ds_dialog_'+(++_guid));if(Dialog.items[id]){var dialog=Dialog.items[id],rOps=dialog.ops;var opsChangeMaps={left:1,top:1,follow:1,onopen:1,onfocus:1,onhide:1,onclose:1,onyes:1,onno:1,esc:2,lock:2,anim:2,drag:2,fixed:2,autoOpen:2,icon:3,content:3};$.each(ops,function(k,val){if(k in opsChangeMaps&&val!==void 0){var type=opsChangeMaps[k];if(type===2){val=!!val;}if(val!==rOps[k]){rOps[k]=val;type===3&&dialog[k](val);}}});dialog[rOps.drag?'initDrag':'releaseDrag']();dialog[rOps.fixed?'initFixed':'releaseFixed']();rOps.autoOpen&&dialog.show();return dialog;}$.each(_ops,function(k,val){typeof ops[k]==='undefined'&&(ops[k]=val);});if(!$.isArray(ops.followOffset)){ops.followOffset=[0,0];}this.id=id;this.ops=ops;this._getElem(ops);Dialog.items[id]=this;this._initEvent();this.padding(ops.padding).size(ops.width,ops.height).title(ops.title).button(ops.buttons).icon(ops.icon).content(ops.content).timeout(ops.timeout);typeof ops.oninit==='function'&&ops.oninit.call(this);ops.fixed&&this.initFixed&&this.initFixed();ops.drag&&this.initDrag&&this.initDrag();ops.autoOpen&&this.show();},_getElem:function(ops){var shell=document.createElement('div');shell.id=this.id;shell.tabIndex=-1;shell.style.position='absolute';shell.className='ds_dialog'+(ops.className?' '+ops.className:'');shell.innerHTML=Dialog.defaultTmpl.replace(/\{id\}/g,this.id);shell=this.shell=$(shell);this.contentShell=shell.find('.ds_dialog_content').eq(0);this.buttonShell=shell.find('.ds_dialo