$(function(){
//瀑布流
var masonry_layou = $('#masonry').isotope({
itemSelector: '.item',
layoutMode: 'masonry',
masonry:{
fitWidth :true
}
});
//懒加载
$("img.lazy").lazyload({
effect: "fadeIn",
load:function(){
masonry_layou.isotope('layout');
}
});
//大图番号列表页瀑布流
var fh_layou= $('.fh-list').isotope({
itemSelector: '.fh-list-item',
layoutMode: 'masonry'
});
//大图番号列表页懒加载
$("img.fh-lazy").lazyload({
effect: "fadeIn",
load:function(){
fh_layou.isotope('layout');
}
});
//重置遮罩层
$(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+'
';
}
}
//弹出内容完成
$('
').appendTo('body').on('touchmove', function (e) { e.preventDefault(); }, false);//取消手机端滑动
//如果是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{
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 tips
$(".form-input").each(function(){
var ThisInput=$(this).find('.form-input-input');
var inputVal=ThisInput.val();
var inputTips=ThisInput.attr('input-tips');
//记录input类型
var inputType=ThisInput.attr('type');
ThisInput.attr('input-type',inputType);
if(inputVal==inputTips || inputVal==''){
//对密码类型特殊处理
if(inputType=='password'){
var inputHtml=ThisInput.prop("outerHTML");
var inputHtmlReplace=inputHtml.replace(/password/, "text")
ThisInput.replaceWith(inputHtmlReplace);
var ThisInput=$(this).find('.form-input-input');
}
ThisInput.val(inputTips);
ThisInput.removeClass('input');
ThisInput.addClass('placeholder');
}else{
ThisInput.removeClass('placeholder');
ThisInput.addClass('input');
}
});
$(document).on("focus",".form-input-input",function(){
var ThisInput=$(this);
var inputVal=ThisInput.val();
var inputTips=ThisInput.attr('input-tips');
var inputType=ThisInput.attr('input-type');
if(inputVal==inputTips){
//对密码类型特殊处理
if(inputType=='password'){
var inputHtml=ThisInput.prop("outerHTML");
var inputHtmlReplace=inputHtml.replace(/text/, "password");
var ParentThis=ThisInput.parents('.form-input');//找到父节点
ThisInput.replaceWith(inputHtmlReplace);//替换
var ThisInput=ParentThis.find('.form-input-input');//父找到新子节点
}
ThisInput.val('');
ThisInput.removeClass('placeholder');
ThisInput.addClass('input');
ThisInput.focus();
}
ThisInput.blur(function(){
var ThisInput=$(this);
var inputVal=ThisInput.val();
var inputTips=ThisInput.attr('input-tips');
var inputType=ThisInput.attr('input-type');
if(inputVal==inputTips || inputVal==''){
//对密码类型特殊处理
if(inputType=='password'){
var inputHtml=ThisInput.prop("outerHTML");
var inputHtmlReplace=inputHtml.replace(/password/, "text");
var ParentThis=ThisInput.parents('.form-input');//找到父节点
ThisInput.replaceWith(inputHtmlReplace);//替换
var ThisInput=ParentThis.find('.form-input-input');//父找到新子节点
}
ThisInput.val(inputTips);
ThisInput.removeClass('input');
ThisInput.addClass('placeholder');
}
});
});
//导航栏
$(document).on("click",".top-nav-btn",function(){
$(".top-nav-link").toggleClass('block');
});
//登录提交
$(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-pass').val();
var newpassword=$('.new-pass').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'
});
});
//关注事件-----------------------------------------
//关注用户
$(document).on('click','.user-follow-btn.btn-default',function(){
//登录检测
if(IsLogin==0){
PopLayer({
type:'alert',
content:'亲!登陆后能关注!',
autoclose:3000
});
}else{
var user_id=$(this).attr('user-id');
var thisItem=$(this);
$.ajax({
type: 'post',
url: '/ajax/follow_add.html?r='+Math.random(),
data: {uid:user_id},
success: function(data){
if(data.code==1){
PopLayer({
type:'alert',
icon:0,
content:data.msg,
autoclose:1000,
callback:function(){
thisItem.find('i').text("已关注");
thisItem.find('em').removeClass('cm-follow').addClass('cm-follow-o');
thisItem.removeClass('btn-default').addClass('btn-primary');
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:1000
});
}
},dataType: 'json'
});
}
});
//取消关注
$(document).on('click','.user-follow-btn.btn-primary',function(){
var user_id=$(this).attr('user-id');
var thisItem=$(this);
$.ajax({
type: 'post',
url: '/ajax/follow_delete.html?r='+Math.random(),
data: {uid:user_id},
success: function(data){
if(data.code==1){
PopLayer({
type:'alert',
icon:0,
content:data.msg,
autoclose:1000,
callback:function(){
thisItem.find('i').text("关注");
thisItem.find('em').removeClass('cm-follow-o').addClass('cm-follow');
thisItem.removeClass('btn-primary').addClass('btn-default');
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:1000
});
}
},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-ad.btn-default',function(){
//登录检测
if(IsLogin==0){
PopLayer({
type:'alert',
content:'亲!登陆后能收藏!',
autoclose:3000
});
}else{
var movie_k=$(this).attr('movie-k');
$.ajax({
type: 'post',
url: '/ajax/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:1000,
callback:function(){
$('.collect-ad').find('i').text('已加入收藏');
$('.collect-ad').find('em').removeClass('cm-collection').addClass('cm-collection-o');
$('.collect-ad').removeClass('btn-default').addClass('btn-primary');
}
});
}else{
PopLayer({
type:'alert',
icon:1,
content:data.msg,
autoclose:1000
});
}
},dataType: 'json'
});
}
});
//数据页-取消收藏
$(document).on('click','.collect-ad.btn-primary',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: '/ajax/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(){
$('.collect-ad').find('i').text('加入收藏夹');
$('.collect-ad').find('em').removeClass('cm-collection-o').addClass('cm-collection');
$('.collect-ad').removeClass('btn-primary').addClass('btn-default');
$('.layer').remove();
}
});
}else{
PopLayer({
type:'alert',
content:data.msg,
autoclose:1000,
callback:function(){
$('.layer').remove();
}
});
}
},dataType: 'json'
});
}}
]
});
});
//收藏页-取消收藏
$(document).on('click','.member-fh-item-delete',function(){
var movie_k=$(this).attr('movie-k');
var thisItem=$(this).parents('.fh-list-item');
PopLayer({
type:'button',
title:'取消收藏',
content:'您确定取消此收藏吗?',
buttons:[
{name:"取消",class:"btn-default"},
{name:"确认",class:"btn-primary",click:function(){
$.ajax({
type: 'post',
url: '/ajax/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(){
thisItem.remove();
$('.layer').remove();
fh_layou.isotope('layout');
}
});
}else{
PopLayer({
type:'alert',
content:data.msg,
autoclose:1000,
callback:function(){
$('.layer').remove();
}
});
}
},dataType: 'json'
});
}}
]
});
});
});