$(function(){
//演员、内容瀑布流
$('#masonry').isotope({
itemSelector: '.item',
layoutMode: 'masonry',
masonry:{
fitWidth :true
}
});
//收藏列表瀑布流
var $collect_isotope=$('.collect-page-list').isotope({
itemSelector: '.collect-page-list-item',
layoutMode: 'masonry'
});
//收藏页懒加载
$(".collect-page img.lazy").lazyload({
placeholder : "http://ww1.sinaimg.cn/large/87c01ec7ly1frb5k7ofu7j20m80dwt8u.jpg",
effect: "fadeIn",
container: $(".wrap"),
load:function(){
$collect_isotope.isotope('layout');
}
});
//演员页懒加载
$(".actress img.lazy").lazyload({
placeholder : "http://ww1.sinaimg.cn/large/87c01ec7ly1frb5k8cur5j203h03hjr6.jpg",
effect: "fadeIn",
container: $(".wrap")
});
//数据页懒加载
$(".movie img.lazy").lazyload({
placeholder : "http://ww1.sinaimg.cn/large/87c01ec7ly1frb5k7ofu7j20m80dwt8u.jpg",
effect: "fadeIn",
container: $(".wrap")
});
//列表页懒加载
$(".content img.lazy").lazyload({
placeholder : "http://ww1.sinaimg.cn/large/87c01ec7ly1frb5k7hxhuj204305k743.jpg",
effect: "fadeIn",
container: $(".wrap")
});
if(localStorage.warp_scrollTop){
if( localStorage.current_url && (localStorage.current_url == document.location) ){
$(".wrap").scrollTop(localStorage.warp_scrollTop);
}else{
localStorage.current_url = document.location;
}
}else{
localStorage.warp_scrollTop=0;
}
$(".wrap").scroll(function() {
localStorage.warp_scrollTop=$(".wrap").scrollTop();
});
//重置遮罩层
$(window).resize(function() {
var wrapHeight=$('.wrap').height();
$('.layer .layer-shade').css({height:wrapHeight});
});
// //弹出测试
// PopLayer({
// type:'button',
// content:'成功啦1111!',
// });
//弹出层
function PopLayer(params){
//默认参数
var PopDEFAULTPARAMS = {
type:'alert',//类型alert msg html button
icon:0,//0为成功,1为错误,3为警告
content: "",//内容信息
autoclose:3000,//0为不自动关闭,其他参数需为1000倍的整数
callback:new Object,//前置操作函数
buttons:[{name:"确定",class:"btn-default"}],//默认按钮
title:'标题',//标题
};
//合并参数
var PopPARAMS;
if (params != undefined && params != null) {
PopPARAMS = $.extend({},PopDEFAULTPARAMS, params);
}
//layerId生成
PopPARAMS.LayerId = Math.random().toFixed(2)*4000;
//选择是否需要遮罩
if(PopPARAMS.type=='msg'){
maskDiv='';
}else{
var wrapHeight=$('.wrap').height();
maskDiv='
'+PopPARAMS.content+''+OutTimeMsg+'
';
}else{
var LayerContainer='
'+PopPARAMS.content+''+OutTimeMsg+'
';
}
}
//弹出内容完成
$("body").append('
');
//如果是alert或msg 则开始自动计时关闭函数
if( (PopPARAMS.type == 'alert') || (PopPARAMS.type == 'msg') ){//alert msg
//自动关闭函数
function PopAutoCloseFun(){
if(PopPARAMS.PopAutoCloseTime>=1){
$("#layer-"+PopPARAMS.LayerId+' .poplayer-content strong i').text(PopPARAMS.PopAutoCloseTime);
PopPARAMS.PopAutoCloseTime=PopPARAMS.PopAutoCloseTime-1;
PopPARAMS.PopAutoClose=setTimeout(function(){PopAutoCloseFun();},1000);
}else{
$("#layer-"+PopPARAMS.LayerId).remove();
if($.isFunction(PopPARAMS.callback)){
PopPARAMS.callback();
}
}
}
PopPARAMS.PopAutoCloseTime=autocloseTime;//自动关闭事件
PopPARAMS.PopAutoClose=new Object;//自动关闭函数
PopAutoCloseFun();
}
}
//图片查看函数
function OpenImgView(type,ImgViewHtml,ImgViewIndex){
var PlusImgViewIndex=ImgViewIndex+1;
if(type==2){
PopLayer({type:'html',content:'
'});
imgviewSwiper = new Swiper('.swiper-container', {
initialSlide :ImgViewIndex,
mousewheelControl : true,
loop : true,
onSwiperCreated: function(swiper){
ImgLazyLoad(swiper);
},
onSlideChangeStart: function(swiper){
var Index=imgviewSwiper.activeLoopIndex+1;
$('.swiper-custom').text(Index+' / '+ImgViewLength);
ImgLazyLoad(swiper);
}
});
}else{
PopLayer({type:'html',content:'
'});
new Swiper('.swiper-container',{
onSwiperCreated: function(swiper){
ImgLazyLoad(swiper);
}
});
}
}
function ImgLazyLoad(swiper){
imgviewSwiper =swiper;
var Index=imgviewSwiper.activeIndex;
var spv = 1;
var maxIndex = Math.min(Index + spv + Math.max(2, spv), imgviewSwiper.slides.length);
var minIndex = Math.max(Index - Math.max(spv, 2), 0);
// Next Slides
for (i = Index; i < maxIndex; i++) {
if (imgviewSwiper.slides[i]) ImageInSlide(i);
}
// Prev Slides
for (i = minIndex; i < Index ; i++) {
if (imgviewSwiper.slides[i]) ImageInSlide(i);
}
}
function ImageInSlide(Index){
if (imgviewSwiper.slides.length === 0) return;
var slide = $('.swiper-slide').eq(Index);
var img = slide.find('.swiper-lazy:not(.swiper-lazy-loaded)');
img.each(function () {
var _img = $(this);
var src = _img.attr('data-src');
image = new window.Image();
image.onload = function(){
_img.attr('src', src);
_img.addClass('swiper-lazy-loaded');
};
image.src = src;
});
}
//loading
// http://wx1.sinaimg.cn/mw690/0060lm7Tly1fsf8vie0b8g300v00va9u.gif
// http://wx1.sinaimg.cn/mw690/0060lm7Tly1fsf8vimiqag301o01ojra.gif
var ImgViewArray=new Array();
var ImgViewLength=0;
var ImgViewHtml='';
var imgviewSwiper;
var imgviewLodingGif="http://ww1.sinaimg.cn/mw690/0060lm7Tly1fsf8vimiqag301o01ojra.gif";
//封面大图
$(document).on('click','.move .pic a',function(){
var imgsrc=$(this).attr("href");
var ViewHtml='
';
OpenImgView(1,ViewHtml);
return false;
});
//预览图片大图
$(document).on('click','.sample-box',function(){
if(ImgViewArray.length==0){
//遍历出src
$(".sample-box").each(function(){
var imgsrc=$(this).attr("href");
ImgViewArray.push({"src":imgsrc});
});
//图片总数
ImgViewLength=ImgViewArray.length;
//生成HTML
var x;
for (x in ImgViewArray){
ImgViewHtml+='
';
}
}
ImgViewIndex=$(this).index();
OpenImgView(2,ImgViewHtml,ImgViewIndex);
return false;
});
//左翻页
$(document).on('click','.imgview .cm-icon.cm-left',function(){
imgviewSwiper.swipePrev();
});
//右翻页
$(document).on('click','.imgview .cm-icon.cm-right',function(){
imgviewSwiper.swipeNext();
});
//hover事件
$(document).on('touchstart mousedown','.imgview .cm-icon',function(){
$(this).addClass('hover');
});
$(document).on('touchend mouseup','.imgview .cm-icon',function(){
$(this).removeClass('hover');
});
//关闭图片预览图层
$(document).on('click','.imgview .cm-close',function(){
$(".layer").remove();
});
//授权提交
var wordlength=0;
$(document).on('click','.wisdom-key div[class!="cur"] b',function(){
if(wordlength<3){
var word=$(this).parent("div").addClass('cur').children("b").text();
$(".wisdom-value div:eq('"+wordlength+"')").addClass('word').children("b").text(word);
if(wordlength==2){
var allword="";
$(".wisdom-value div").each(function(){
var thisword=$(this).children("b").text();
allword+=thisword;
});
$.post("/Index/authWord.html?r="+Math.random(),{keyword:allword},function(data){
if(data.code==1){
PopLayer({
type:'alert',
icon:0,
content:data.msg,
autoclose:2000,
callback:function(){
if(typeof data.url){
window.location.href=data.url;
}else{
if(refreshUrl==""){
window.location.href="/content/all";
}else{
window.location.href=window.location.href;
}
}
ClearWisdom();
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:2000,
callback:function(){
ClearWisdom();
}
});
}
}, "json");
wordlength=3;
}else{
wordlength=wordlength+1;
}
}
});
function ClearWisdom() {
$(".wisdom-key div").removeClass("cur");
$(".wisdom-value div").removeClass("word");
wordlength=0;
}
//input 提示
$(document).on("click",".form-input-tips",function(){
$(this).parent('.form-input').find('.form-input-input').focus();
});
$(document).on("keyup keydown",".form-input-input",function(){
var inputStrlen=$(this).val().length;
if(inputStrlen>=1){
$(this).parent('.form-input').find('.form-input-tips').hide();
}else{
$(this).parent('.form-input').find('.form-input-tips').show();
}
});
$(".form-group .form-input-input").each(function(){
var formgroup=$(this).val().length;
if(formgroup>=1){
$(this).parent('.form-input').find('.form-input-tips').hide();
}
});
//导航栏
$(document).on("click",".top-nav-btn",function(){
var isblock=$(".top-nav-link").hasClass('block');
if(isblock){
$(".top-nav-link").slideUp('fast',function(){
$(this).removeClass("block").css({display:"",overflow:""});
});
}else{
$(".top-nav-link").addClass("block").slideDown('fast');
}
});
//登录提交
$(document).on("click",".login-form .submit",function(){
var formaction= $(this).parents('form').attr("action");
var formmethod= $(this).parents('form').attr("method");
var formvalue= $(this).parents('form').serialize();
$.ajax({
type: formmethod,url: formaction,data: formvalue,
success: function(data){
if(data.code==1){
PopLayer({
type:'alert',
icon:0,
content:data.msg,
autoclose:2000,
callback:function(){
window.location.href=data.url;
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:2000
});
}
},dataType: 'json'
});
return false;
});
//头像上传
$(document).on("change",".face-upload-input",function() {
var formData=new FormData();
var file=this.files[0];
formData.append('file',file);
//上传图库后回调
$.ajax({
type: 'post',
url: '/upload/image.html?r='+Math.random(),
contentType:false,
processData : false,
data: formData,
success: function(data){
if(data.code==1){
//获取数据后再提交
$.ajax({
type: 'post',
url: '/member/changeface.html?r='+Math.random(),
data: {src:data.url},
success: function(resdata){
if(resdata.code==1){
$('.member-face').attr('src',data.url);
PopLayer({
type:'alert',
icon:0,
content:resdata.msg,
autoclose:2000
});
}else{
PopLayer({
type:'alert',
icon:1,
content:resdata.msg,
autoclose:2000
});
}
},dataType: 'json'
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:2000
});
}
},dataType: 'json'
});
});
//密码更改
$(document).on("click",".password-change-btn",function() {
var oldpassword=$('.old-password').val();
var newpassword=$('.new-password').val();
$.ajax({
type: 'post',
url: '/member/changepassword.html?r='+Math.random(),
data: {oldpassword:oldpassword,newpassword:newpassword},
success: function(res){
if(res.code==1){
PopLayer({
type:'alert',
icon:0,
content:res.msg,
autoclose:2000
});
}else{
PopLayer({
type:'alert',
icon:1,
content:res.msg,
autoclose:2000
});
}
},dataType: 'json'
});
});
//收藏夹事件-----------------------------------------
// function ButtonFormSerialize(input){
// var formvalue=new Object;
// $.each(input,function(i,inputname){
// var inputval=$('.layer-button-form [name="'+inputname+'"]').val();
// formvalue[inputname]=inputval;
// });
// return formvalue;
// }
//加入收藏夹
$(document).on('click','.collect-add',function(){
//登录检测
if(IsLogin==0){
PopLayer({
type:'alert',
content:'亲!登陆后能收藏!',
autoclose:3000
});
}else{
var movie_k=$(this).attr('movie-k');
$.ajax({
type: 'post',
url: '/collect/collect_add.html?r='+Math.random(),
data: {k:movie_k},
success: function(data){
if(data.code==1){
PopLayer({
type:'alert',
icon:0,
content:data.msg,
autoclose:2000,
callback:function(){
window.location.href=data.url;
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:2000
});
}
},dataType: 'json'
});
}
});
//取消收藏
$(document).on('click','.collect-delete,.collect-item-delete',function(){
var movie_k=$(this).attr('movie-k');
PopLayer({
type:'button',
title:'取消收藏',
content:'取消后无法找回收藏!
您确定取消此收藏吗?',
buttons:[
{name:"取消",class:"btn-default"},
{name:"确认",class:"btn-primary",click:function(){
$.ajax({
type: 'post',
url: '/collect/collect_delete.html?r='+Math.random(),
data: {k:movie_k},
success: function(data){
if(data.code==1){
PopLayer({
type:'msg',
content:data.msg,
autoclose:1000,
callback:function(){
window.location.href=data.url;
}
});
}else{
PopLayer({
type:'alert',
content:data.msg,
autoclose:1000
});
}
},dataType: 'json'
});
}}
]
});
});
});