/**
* common.js
* 2013.05.17
* kongge@office.weiphone.com
*/
//ds.base
;(function(global, document, undefined){
var
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
trim: function(str){
return String(str).replace(/^\s*/, '').replace(/\s*$/, '');
},
//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
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
isIE6: !-[1,] && !global.XMLHttpRequest
};
//CSS3 Hacker
ds.mix((function(){
var
j, name,
hack = {},
props = ['transform', 'transition'],
prefixs = ['o', 'ms', 'moz', 'webkit', ''],
docStyle = (document.documentElement || document.body).style;
for(var i=props.length-1; i>=0; i--){
for(j=prefixs.length-1; j>=0; j--){
name = prefixs[j] + (prefixs[j] ? props[i].slice(0, 1).toUpperCase()+props[i].slice(1) : props[i]);
if((name in docStyle)){
hack[props[i] + 'Support'] = {
prefix: prefixs[j],
propName: name
};
break;
}
}
}
return hack;
})());
})(this, document);
//CSS3 Support
(function(){
var
root = document.documentElement,
className = root.className,
classList = [];
if(className){
classList.push(className);
}
if(ds.transitionSupport){
classList.push('transition');
}
if(ds.transformSupport){
classList.push('transform');
}
root.className = classList.join(' ');
})();
//globar_topbar
jQuery(function($){
var
linkTimer,
linkPanel = $('#globar_topbar_links'),
linkFocusStyle = linkPanel.find('.focus').prop('style');
if(linkFocusStyle){
linkPanel.delegate('li a', 'mouseenter', function(){
var self = $(this);
clearTimeout(linkTimer);
linkFocusStyle.left = self.position().left + 'px';
linkFocusStyle.width = self.innerWidth() + 'px';
})
.bind('mouseleave', function(){
clearTimeout(linkTimer);
linkTimer = setTimeout(function(){
linkFocusStyle.left = '';
}, 240);
});
}
});
/**
* ds.buildSlider
*/
;(function(global, document, $){
var sliderList = [];
//buildSlider
ds.buildSlider = function(shell, ops, buildHandler){
if(!(shell = $(shell)).length){ return; }
ops = ops || {};
var
triggers = shell.find('.triggers a'),
_ops = {
duration: 400,
unitSize: 880,
imgLoadFlag: null,
imgLoadHandler: ds.noop,
onplay: function(inx, prevInx){
if(ops.imgLoadFlag && !ops.imgLoadFlag[inx]){
ops.imgLoadHandler.call(this, inx, prevInx);
ops.imgLoadFlag[inx] = true;
}
prevInx > -1 && triggers.eq(prevInx).removeClass('current');
triggers.eq(inx).addClass('current');
}
};
for(var k in _ops){
if(typeof ops[k] === 'undefined'){
ops[k] = _ops[k];
}
}
if(!ops.shell){
ops.shell = shell.find('ul').eq(0);
if(typeof ops.length !== 'number'){
ops.length = ops.shell.find('li').length;
}
}
var timer, slider = new (buildHandler || Slider)(ops);
shell.delegate('a.prev,a.next', 'click', function(e){
e.preventDefault();
clearTimeout(timer);
slider[this.className.indexOf('next')>-1 ? 'next' : 'prev']();
})
.hover(function(){
slider.mouseEnter = true;
slider.stopAuto();
}, function(){
slider.mouseEnter = false;
slider.autoPlay();
});
triggers.bind('click', function(e){
e.preventDefault();
})
.hover(function(){
clearTimeout(timer);
var self = this;
timer = setTimeout(function(){
Back to home |
File page
Subscribe |
Register |
Login
| N