Authored by lore-w

Merge branch 'develop' of git.dev.yoho.cn:ued/yohogirls-frontend into develop

Showing 44 changed files with 2208 additions and 1888 deletions

Too many changes to show.

To preserve performance only 44 of 44+ files are displayed.

2.43 KB | W: | H:

1.43 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

2.91 KB | W: | H:

1.53 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

2.49 KB | W: | H:

1.46 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

3.27 KB | W: | H:

1.59 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

2.11 KB | W: | H:

1.34 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

2.65 KB | W: | H:

1.46 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

1.87 KB | W: | H:

2.62 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

2.74 KB | W: | H:

2.62 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

981 Bytes | W: | H:

981 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -3,7 +3,7 @@ var gutil = require('gulp-util');
var ftp = require('gulp-ftp');
var fs = require('fs');
var uglify = require('gulp-uglify'),
rename = require('gulp-rename');
rename = require('gulp-rename');
var concat = require('gulp-concat');
var exec = require('child_process').exec;
var compass = require('gulp-compass');
... ... @@ -13,63 +13,56 @@ var stylish = require('jshint-stylish');
//获取package.json的配置参数
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var dist_assets_dir = 'dist/'+config.name+'/assets';
var dist_seajs_dir='dist/'+config.name+'/'+config.version+"/min";
var dist_js_dir='dist/'+config.name+'/'+config.version;
var source_js_dir='js/';
var dist_assets_dir = 'dist/' + config.name + '/assets';
var dist_seajs_dir = 'dist/' + config.name + '/' + config.version + "/min";
var dist_js_dir = 'dist/' + config.name + '/' + config.version;
var source_js_dir = 'js/';
var dist_dir =
{
css: 'dist/'+config.name+'/'+config.version,
image: dist_assets_dir+'/images',
font: dist_assets_dir+'/fonts'
var dist_dir = {
css: 'dist/' + config.name + '/' + config.version,
image: dist_assets_dir + '/images',
font: dist_assets_dir + '/fonts'
};
var ftpConfig =
{
host: '218.94.77.166',
user: 'php',
pass: 'yoho9646'
var ftpConfig = {
host: '218.94.77.166',
user: 'php',
pass: 'yoho9646'
};
gulp.task('default',function(){
gulp.watch(['sass/scss/**','js/**'],['compass-dist','build']);
gulp.task('default', function() {
gulp.watch(['sass/scss/**', 'js/**'], ['compass-dist', 'build']);
});
//compass的watch
gulp.task('cw',function(cb)
{
/*exec('compass watch', function(err)
{
if (err) return cb(err);
cb();
});*/
gulp.watch(['sass/scss/**','js/**'],['compass-dist','build']);
gulp.task('cw', function(cb) {
/*exec('compass watch', function(err)
{
if (err) return cb(err);
cb();
});*/
gulp.watch(['sass/scss/**'], ['compass-dist']);
});
//js代码验证
gulp.task('lint',function()
{
return gulp.src(['js/*.js','js/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
gulp.task('lint', function() {
return gulp.src(['js/*.js', 'js/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
//编译部署compass
gulp.task('compass-dist',['assets'],function()
{
gulp.src('sass/scss/**')
.pipe(compass(
{
gulp.task('compass-dist', ['assets'], function() {
gulp.src('sass/scss/**')
.pipe(compass({
css: dist_dir.css,
sass: 'sass/scss',
image: dist_dir.image,
font: dist_dir.font,
style:'compressed'
style: 'compressed'
}))
.on('error', function(error)
{
.on('error', function(error) {
console.log(error);
this.emit('end');
});
... ... @@ -77,85 +70,79 @@ gulp.task('compass-dist',['assets'],function()
//执行spm的build
gulp.task('spm',function(cb)
{
exec('spm build --include all', function(err)
{
if (err) return cb(err);
cb();
});
gulp.task('spm', function(cb) {
exec('spm build --include all', function(err) {
if (err) return cb(err);
cb();
});
});
gulp.task('js',['seajs','copy','concat'],function(){
console.log("压缩合并完成");
gulp.task('js', ['seajs', 'copy', 'concat'], function() {
console.log("压缩合并完成");
});
gulp.task('seajs',function(){
gulp.src('js/util/seajs_dev.js')
.pipe(uglify())
.pipe(rename('seajs.min.js'))
.pipe(gulp.dest(dist_seajs_dir));
gulp.task('seajs', function() {
gulp.src('js/util/seajs_dev.js')
.pipe(uglify())
.pipe(rename('seajs.min.js'))
.pipe(gulp.dest(dist_seajs_dir));
});
gulp.task('copy',function(){
gulp.src(dist_js_dir+'/index.js')
.pipe(rename('z_index.js'))
.pipe(gulp.dest(dist_seajs_dir));
gulp.src(source_js_dir+'/yas.js')
.pipe(gulp.dest(dist_js_dir));
gulp.task('copy', function() {
gulp.src(dist_js_dir + '/index.js')
.pipe(rename('z_index.js'))
.pipe(gulp.dest(dist_seajs_dir));
gulp.src(source_js_dir + '/yas.js')
.pipe(gulp.dest(dist_js_dir));
});
gulp.task('concat',function(){
gulp.src(dist_seajs_dir+'/*.js')
.pipe(concat('index.min.js'))
.pipe(gulp.dest(dist_js_dir));
gulp.task('concat', function() {
gulp.src(dist_seajs_dir + '/*.js')
.pipe(concat('index.min.js'))
.pipe(gulp.dest(dist_js_dir));
});
//拷贝assets到发布目录
gulp.task('assets',function()
{
gulp.src('assets/**')
gulp.task('assets', function() {
gulp.src('assets/**')
.pipe(gulp.dest(dist_assets_dir));
});
gulp.task('yangshi',['assets','compass-dist'],function(){
gulp.task('yangshi', ['assets', 'compass-dist'], function() {
});
//spm build
gulp.task('build', function() {
exec('spm build --include all', function() {
exec('gulp build-debug');
exec('gulp build-production');
});
exec('spm build --include all', function() {
exec('gulp build-debug');
exec('gulp build-production');
});
});
//generate all-debug.js for development ENV
gulp.task('build-debug', function() {
gulp.src(['js/util/seajs.js', 'dist/yohogirls-frontend-web/0.0.1/index-debug.js'])
.pipe(concat('all-debug.js'))
.pipe(gulp.dest('dist/yohogirls-frontend-web/0.0.1'))
gulp.src(['js/util/seajs.js', 'dist/yohogirls-frontend-web/0.0.1/index-debug.js'])
.pipe(concat('all-debug.js'))
.pipe(gulp.dest('dist/yohogirls-frontend-web/0.0.1'))
});
//generate all.js for production ENV
gulp.task('build-production', function() {
gulp.src(['js/util/seajs.js', 'dist/dist/yohogirls-frontend-web/0.0.1/index.js'])
.pipe(concat('all.js'))
.pipe(gulp.dest('dist/yohogirls-frontend-web/0.0.1'))
gulp.src(['js/util/seajs.js', 'dist/dist/yohogirls-frontend-web/0.0.1/index.js'])
.pipe(concat('all.js'))
.pipe(gulp.dest('dist/yohogirls-frontend-web/0.0.1'))
});
//发布到CDN
gulp.task('dist',['compass-dist'], function ()
{
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**')
gulp.task('dist', ['compass-dist'], function() {
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**')
.pipe(ftpstream)
.pipe(gutil.noop());
});
//发布到CDN
gulp.task('comp',['compass-dist','js'], function ()
{
//编译到本地
console.log("将文件编译到本地!!!!");
});
gulp.task('comp', ['compass-dist', 'js'], function() {
//编译到本地
console.log("将文件编译到本地!!!!");
});
\ No newline at end of file
... ...
require('./channel/detail');
require('./channel/magazine')
\ No newline at end of file
require('./channel/magazine')
var $=require("jquery");
var tips=require("yoho-tips");
var box=require("yoho-box");
//首页碎片交互=================================================================================================
function dealItems() {
var citems = $(".content-item,.content-item-without-border");
if (!citems.length) {
return;
}
var totalLineNum = 7;
// 7 行
var maxTitleStrNum = 45;
// 15个字
var maxDetailStrNum = 24;
// 22个字
if (document.body.clientWidth < 1190) {
totalLineNum = 6;
// 6 行
maxTitleStrNum = 39;
// 13个字
maxDetailStrNum = 54;
// 18个字
}
var titleLineNum = 0;
var subTitleLineNum = 0;
var detailLineNum = 0;
var detailStr = "";
var self = null;
citems.each(function() {
self = $(this);
var itemTitleObj= self.find(".content-item-detail-title");
// 主标题行数
if(typeof(itemTitleObj.attr("_title"))==="undefined"||itemTitleObj.attr("_title")===null)
return;
titleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
titleLineNum = 2;
}
// 副标题行数
subTitleLineNum = 1;
if (maxTitleStrNum < $(".content-item-detail-subtitle").attr("_title").length) {
subTitleLineNum = 2;
}
// 摘要内容行数
detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
if ((maxDetailStrNum * detailLineNum) < self.find(".content-item-detail-detail").attr("_title").length) {
detailStr = self.find(".content-item-detail-detail").attr("_title").substring(0, maxDetailStrNum * detailLineNum ) + " ...";
self.find(".content-item-detail-detail").text(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
}
else
{
self.find(".content-item-detail-detail").text(self.find(".content-item-detail-detail").attr("_title"));
}
});
citems = null;
}
dealItems();
//=============================================================
//邮件订阅=============================================================================================================
$(".followus-button").click(function(){
if($(".follow-us-input-content input").val()=='')
{
box.alert(tips.getTips("emailEmpty"));
return;
}
if(!tools.IYOHO_isEmail($(".follow-us-input-content input").val()))
{
box.alert(tips.getTips("emailError"));
return;
}
$(".search-suggest").hide();
window.open( '/passport/subscribe/index?email='+$(".follow-us-input-content input").val());
});
$(".followus-input").keydown(function(event){
if(event.keyCode==13)
{
$(".followus-button").trigger("click");
}
});
... ...
... ... @@ -7,25 +7,89 @@
var $ = require('jquery'),
share = require('../plugin/share'),
box = require('../plugin/box'),
imgZoom = require('../plugin/imgzoom'),
tools = require('yoho-tools');
imgZoom = require('../plugin/imgZoom'),
tools = require('yoho-tools'),
mustache = require('mustache'),
mulLine = require('mlellipsis'),
flip = require("../plugin/flip"),
slide = require("../plugin/photoslide");
require('lazyload');
require('../plugin/slider');
require('../plugin/comment');
require('../plugin/content-paging');
exports.init = function() {
var shareUrl = $(".share").attr("data-link"),
shareCover = $(".share").attr("cover-url"),
detailTitle = $(".detail-title").find("h1"),
detailSubtitle = $(".detail-title").find("h2");
detailSubtitle = $(".detail-title").find("h2"),
ajaxParam,
i,
data,
cidNum;
//边栏数据相关变量
var adItem, //边栏广告
sideVideoTpl, //边栏视频模板
sideVideoData, //边栏视频数据
sideVideoHtml, //边栏视频渲染的html
sidePostTpl, //边栏relatedpost模板
sidePostData, //边栏relatedpost数据
sidePostHtml; //边栏relatedpost渲染的html
//related-post截行相关变量
var relatedPost,
postList, //post列表
totalLineNum, //总行数
titleLineNum, //title行数
subTitleLineNum; //subtitle行数
//滑出边栏小视频side-video播放区域暂停相关变量
var relatedPostsOffsetTop,
relatedPostsTop,
relatedPostsMarginLeft;
//页面滑动热播位置变化相关变量
var detailBodyOffsetTop,
relatedPostsOffsetHeightTop,
distance,
eleTop,
detailBodyHeight;
//底部数据相关变量
var bottomPostTpl, //底部relatedpost模板
bottomPostData, //底部relatedpost数据
bottomPostHtml; //底部relatedpost渲染的html
//态度设置相关变量
var exType = 0,
isCancel = 0,
attitudeData,
attitudeDataWowIcon,
attitudeWowNum,
attitudeDataWtfIcon,
attitudeWtfNum,
attitudeDataZzzIcon,
attitudeZzzNum;
//兼容视频,IE等相关变量
var video,
ieVideo,
ipadVideo,
browser,
b_version,
version,
trim_Version;
//初始化截行插件
mulLine.init();
//分享
share.init({
shareUrl: shareUrl,
img: shareCover,
sinaText:'【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
fbTextFunction: function(){
sinaText: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
fbTextFunction: function() {
return {
des: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YohoGirl',
name: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YohoGirl',
... ... @@ -67,7 +131,9 @@ exports.init = function() {
//图片轮播
if ($(".detail-slide-body").size() > 0) {
$(".detail-slide-ctrl-tabs").find("img.lazy").lazyload();
$(".detail-slide-body").ImgZoom();
$(".detail-slide-body").imgZoom({
styleClass: 'detail-zoom'
});
$(".detail-slide-piclist").slider({
pageCtrl: $(".detail-slide-ctrl-tabs"),
... ... @@ -76,15 +142,15 @@ exports.init = function() {
};
//调用评论插件
$(".stats-btn").on("click",".comments",function() {
var cidNum = $(".comments-box").attr("cid");
if($(".comments-box").find(".comment-textarea").size() > 0) {
if($(".comments-box").css("display") === "none") {
$(".stats-btn").on("click", ".comments", function() {
cidNum = $(".comments-box").attr("cid");
if ($(".comments-box").find(".comment-textarea").size() > 0) {
if ($(".comments-box").css("display") === "none") {
$(".comments-box").show();
}else{
} else {
$(".comments-box").hide();
}
}else{
} else {
$(".comments-box").comment({
cid: cidNum,
thirdLogin: true,
... ... @@ -94,4 +160,485 @@ exports.init = function() {
});
}
});
}
\ No newline at end of file
//ajax参数
ajaxParam = {
id: $(".comments-box").attr("cid"),
type: $(".comments-box").attr("ctype"),
c: $(".comments-box").attr("cc"),
twoc: $(".comments-box").attr("ctwoc")
};
//右侧side的数据获取
$.ajax({
type: 'GET',
url: YohoConfig.mainUrl + '/channel/detail/getright', //?id=' + ajaxParam.id + '&type=' + ajaxParam.type + '&c=' + ajaxParam.c + '&twoc=' + ajaxParam.twoc,
success: function(response) {
data = response.data;
//广告
for (i = 0; i < data.banners.length; i++) {
adItem += '<a href="' + data.banners[i].link + '" target="_blank"><img src="' + data.banners[i].img + '" alt="" /></a>'
}
$(".detail-ad").html(adItem);
//没有广告去掉margin
if (data.banners.length == 0) {
$(".detail-side .app-download").css("margin", 0);
}
//视频
sideVideoTpl = $('#side-video-tpl').html();
sideVideoData = {
video: data.video
}
sideVideoHtml = mustache.render(sideVideoTpl, sideVideoData);
$('.detail-side').append($(sideVideoHtml));
if (navigator.userAgent.indexOf('iPad') !== -1) {
// 封面视频播放器替换为H5的VIDEO标签
if (!!$('.video-area').find('object').size()) {
$('.video-area').find('object').hide();
$('.side-video').find('video').show();
}
}
//边栏related-post
sidePostTpl = $('#side-related-posts').html();
sidePostData = {
relatedPost: {
postList: data.mosts
}
}
sidePostHtml = mustache.render(sidePostTpl, sidePostData);
$('.detail-side').append($(sidePostHtml));
//边栏related-post根据行数截取字符
relatedPost = $('.side-related-posts');
postList = relatedPost.find("li");
if (postList.length > 0) {
totalLineNum = 3;
postList.each(function(index, obj) {
titleLineNum = $(obj).find('h3').getTextLineNumber('title');
subTitleLineNum = $(obj).find('p').getTextLineNumber('subtitle');
if (titleLineNum > 2) {
$(obj).find('h3').mlellipsis(2);
titleLineNum = 2;
}
if (subTitleLineNum > totalLineNum - titleLineNum) {
$(obj).find('p').mlellipsis(totalLineNum - titleLineNum, 'detail');
}
});
}
//滑出小视频播放区域暂停小视频
$(window).resize(function() {
relatedPostsOffsetTop = relatedPost.offset().top - $('#minEnterprise').outerHeight();
relatedPostsTop = $('#minEnterprise').outerHeight();
relatedPostsMarginLeft = $('.detail-container').width() / 2 - relatedPost.outerWidth();
}).resize();
$(window).bind('scroll', function() {
function thisMovie(movieName) {
if (navigator.appName.indexOf('Microsoft') != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
if ($('.side-video').size() > 0) {
if ($(window).scrollTop() >= $('.side-video').offset().top || $(window).scrollTop() < $('.side-video').offset().top - $(window).height()) {
try {
if (navigator.appName.indexOf('Microsoft') != -1) {
thisMovie('newestvideo').StopMovie();
} else if (navigator.userAgent.indexOf('iPad') !== -1) {
var videoId = document.getElementById('side-video-ipad');
videoId.pause();
} else {
$('.side-video').find('embed').get(0).StopMovie();
}
} catch (e) {}
}
}
if ($(window).scrollTop() >= relatedPostsOffsetTop && relatedPost.css('display') !== 'none') {
if (navigator.userAgent.indexOf('iPad') !== -1) return;
//right_tab_toped=true;
relatedPost.css({
'position': 'fixed',
'left': '50%',
'margin-left': relatedPostsMarginLeft,
'top': relatedPostsTop
});
//热播位置
detailBodyOffsetTop = $('.detail-body').offset().top;
detailBodyHeight = $('.detail-body').outerHeight();
relatedPostsOffsetHeightTop = relatedPost.offset().top + relatedPost.outerHeight();
distance = detailBodyHeight + detailBodyOffsetTop;
eleTop = distance - relatedPost.outerHeight();
if (relatedPostsOffsetHeightTop >= distance) {
relatedPost.css({
'position': 'absolute',
'top': eleTop - relatedPostsTop
});
}
if (relatedPost.offset().top - $(window).scrollTop() > relatedPostsTop) {
relatedPost.css({
'position': 'fixed',
'top': relatedPostsTop
});
}
} else if ($(window).scrollTop() < relatedPostsOffsetTop && relatedPost.css('display') !== 'none') {
//right_tab_toped=false;
relatedPost.removeAttr('style').show();
}
});
}
});
//底部数据的获取
$.ajax({
type: 'GET',
url: YohoConfig.mainUrl + '/channel/detail/getbottom', //?id=' + ajaxParam.id + '&type=' + ajaxParam.type + '&c=' + ajaxParam.c + '&twoc=' + ajaxParam.twoc,
success: function(response) {
data = response.data;
var relatedPost = data.related,
prevnext = data.prevnext,
attitude = data.attitude,
commentnum = data.commentnum;
//底部related-post
bottomPostTpl = $('#bottom-related-posts').html();
bottomPostData = {
relatedPost: {
postList: data.related
}
}
bottomPostHtml = mustache.render(bottomPostTpl, bottomPostData);
$('.detail-body').append($(bottomPostHtml));
postList = $('.related-posts').find("li");
postList.eq(5).nextAll().hide();
//底部related-post根据行数截取字符
if (postList.length > 0) {
postList.each(function(index, obj) {
totalLineNum = 3;
titleLineNum = $(obj).find('h3').getTextLineNumber('title');
subTitleLineNum = $(obj).find('p').getTextLineNumber('subtitle');
if (titleLineNum > 2) {
$(obj).find('h3').mlellipsis(2);
titleLineNum = 2;
}
if (subTitleLineNum > totalLineNum - titleLineNum) {
$(obj).find('p').mlellipsis(totalLineNum - titleLineNum, 'detail');
}
});
}
//上一篇下一篇
if (data.prevnext.prev.title) {
$(".news-next-prev .prev").show();
$(".news-next-prev .prev").find("a").attr("href", prevnext.prev.link).attr("title", prevnext.prev.title).attr("onclick", "prevOrNextClickEvent();");
}
if (data.prevnext.next.title) {
$(".news-next-prev .next").show();
$(".news-next-prev .next").find("a").attr("href", prevnext.next.link).attr("title", prevnext.next.title).attr("onclick", "prevOrNextClickEvent();");
}
//态度
if (data.attitude.userWow > 0) {
$(".stats-btn .wow").addClass("current");
};
if (data.attitude.userWtf > 0) {
$(".stats-btn .wtf").addClass("current");
};
if (data.attitude.userZzz > 0) {
$(".stats-btn .zzz").addClass("current");
};
setattitude(data.attitude.wowCount, data.attitude.zzzCount, data.attitude.wtfCount);
if (data.commentnum > 0) {
$(".comment-num").text(data.commentnum);
} else {
$(".comment-num").html('<img src="' + YohoConfig.resUrl + '/assets/images/mobile/comment-mobile.png">');
}
}
});
//态度设置
$(".stats-btn").on("click", "li", function() {
if ($(this).index() == 3) return;
exType = $(this).index() + 1;
isCancel = 0;
if ($(this).hasClass("current")) {
isCancel = 1;
}
attitudeData = {
id: ajaxParam.id,
exType: exType,
isCancel: isCancel
};
$.ajax({
type: 'POST',
url: YohoConfig.mainUrl + '/channel/detail/setattitude',
data: attitudeData,
dataType: 'json',
success: function(response) {
$(".stats-btn").find("li").removeClass("current");
if (response.data.userWow > 0) {
$(".stats-btn .wow").addClass("current");
};
if (response.data.userWtf > 0) {
$(".stats-btn .wtf").addClass("current");
};
if (response.data.userZzz > 0) {
$(".stats-btn .zzz").addClass("current");
};
setattitude(response.data.wowCount, response.data.zzzCount, response.data.wtfCount);
}
});
});
/*
* 态度设置函数
* @param:三种态度的数值
*/
function setattitude(wow, zzz, wtf) {
attitudeDataWowIcon = $(".stats-btn .wow").find("img");
attitudeWowNum = $(".stats-btn .wow").find("i");
attitudeDataZzzIcon = $(".stats-btn .zzz").find("img");
attitudeZzzNum = $(".stats-btn .zzz").find("i");
attitudeDataWtfIcon = $(".stats-btn .wtf").find("img");
attitudeWtfNum = $(".stats-btn .wtf").find("i");
if (wow == 0) {
attitudeDataWowIcon.show();
attitudeWowNum.hide();
} else {
attitudeWowNum.text(wow).show();
attitudeDataWowIcon.hide();
};
if (zzz == 0) {
attitudeDataZzzIcon.show();
attitudeZzzNum.hide();
} else {
attitudeZzzNum.text(zzz).show();
attitudeDataZzzIcon.hide();
};
if (wtf == 0) {
attitudeDataWtfIcon.show();
attitudeWtfNum.hide();
} else {
attitudeWtfNum.text(wtf).show();
attitudeDataWtfIcon.hide();
};
}
//relatedpost的loadmore事件
$('.detail-body').on('click.loadMore', '.load-more', function() {
$(this).fadeOut(500, function() {
$('.related-posts').find('li').show();
});
})
//翻转
flip.init({
wrapClass: ".yohoboy-flip",
operate: "mouse"
});
//hr分页
$(".detail-body").contentPaging();
//兼容以前视频视频的大小
video = $(".text-body").find("embed");
ieVideo = $(".text-body").find("object");
ipadVideo = $(".text-body").find("video");
if ($(window).width() >= 1200) {
video.css({
"width": "738px",
"height": "415px"
});
ieVideo.css({
"width": "738px",
"height": "415px"
})
} else if ($(window).width() <= 768) {
ipadVideo.css({
"width": "460px",
"height": "259px"
});
video.css({
"width": "460px",
"height": "259px"
});
ieVideo.css({
"width": "460px",
"height": "259px"
});
} else {
video.css({
"width": "630px",
"height": "354px"
});
ieVideo.css({
"width": "630px",
"height": "354px"
});
};
//检测ie版本,ie7/8采用1024分辨率
browser = navigator.appName;
b_version = navigator.appVersion;
version = b_version.split(";");
if (version.length > 1) {
var trim_Version = version[1].replace(/[ ]/g, "");
if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE8.0" || browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
ieVideo.css({
"width": "630px",
"height": "354px"
})
}
}
//ipad横竖屏切换
$(window).resize(function() {
clearTimeout(timer);
var timer = setTimeout(function() {
$(".detail-slide-piclist").slider('resize');
}, 0)
});
slide.initSlide();
//视频内容右下角浮层小视频同步播放
exports.videoMiniPlayer = function() {
var videoPlace = $(".detail-video"),
videoWrap = $('.video-wrap'),
video = videoWrap.find("object"),
videoIpad = videoWrap.find("video"),
videoHeight,
videoOffsetHeight,
headerNavHeight,
scrollTop,
smallVideoMarginLeft;
if (video.size() > 0) {
$(window).on("resize", function() {
$(".detail-video").css({
"width": videoIpad.outerWidth(),
"height": videoIpad.outerHeight()
})
}).resize();
videoWrap.addClass("suspend");
videoHeight = videoWrap.outerHeight();
videoOffsetHeight = videoWrap.offset().top;
headerNavHeight = $("#minEnterprise").height();
scrollTop = videoHeight + videoOffsetHeight - headerNavHeight;
$(window).on("scroll", function() {
if ($(window).scrollTop() > scrollTop && !videoWrap.hasClass("current") && !videoWrap.hasClass("close") && !videoWrap.hasClass("suspend") && !videoWrap.hasClass("stop")) {
videoWrap.css("opacity", 0);
videoWrap.addClass("current");
smallVideoMarginLeft = $(".detail-container").width() / 2 - videoWrap.outerWidth();
videoWrap.css("margin-left", smallVideoMarginLeft);
videoWrap.animate({
"opacity": 1
}, 1000);
} else if ($(window).scrollTop() < scrollTop) {
videoWrap.css("opacity", 1);
videoWrap.removeClass("close").removeClass("current").removeAttr("style");
}
});
//小视频关闭按钮
$(".video-close-btn").on("click", function() {
videoWrap.animate({
"opacity": 0
}, 500, function() {
videoWrap.addClass("close").removeClass("current");
});
})
}
};
}
window.updateState = function() {
seajs.use("channel/detail", function(detail) {
detail.updateLogin();
});
};
window.picLimited = function() {
seajs.use("jquery/1.8.3/jquery.js", function($) {
if ($(".text-body") <= 0) return;
$(".text-body").find("img").css("max-width", "700px");
});
};
window.normarlPlayer = function() {
seajs.use("jquery/1.8.3/jquery.js", function($) {
$(".video-wrap").removeClass("current");
});
};
window.stopPlayer = function() {
seajs.use('jquery/1.8.3/jquery.js', function($) {
if ($(".video-wrap").hasClass("current")) {
$(".video-wrap").animate({
"opacity": 0
}, 500, function() {
$(".video-wrap").addClass("stop").removeClass("current");
});
} else {
$(".video-wrap").addClass("stop").removeClass("current");
}
});
};
window.suspendPlayer = function() {
seajs.use("jquery/1.8.3/jquery.js", function($) {
$(".video-wrap").addClass("suspend");
});
};
window.startPlayer = function() {
seajs.use("jquery/1.8.3/jquery.js", function($) {
$(".video-wrap").removeClass("stop").removeClass("suspend");
});
};
//视频不能同时播放
window.thisMovie = function(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
};
window.StopAnotherMovie = function(id) {
seajs.use("jquery/1.8.3/jquery.js", function($) {
var allVideo = $("body").find("embed");
allVideo.each(function() {
window.StopMovie();
});
});
};
\ No newline at end of file
... ...
/**
* @author DELL
*/
... ...
... ... @@ -9,7 +9,10 @@ var $ = require('jquery'),
swiper = require('yoho-idangerous.swiper');
require('lazyload');
require('../plugin/imgslider');
require('../plugin/imgSlider');
require('../plugin/imgZoom');
exports.init = function() {
var shareUrl = $('.share').attr('data-link'),
... ... @@ -24,8 +27,8 @@ exports.init = function() {
share.init({
shareUrl: shareUrl,
img: shareCover,
sinaText:'【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
fbTextFunction: function(){
sinaText: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
fbTextFunction: function() {
return {
des: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YohoGirl',
name: '【Yoho!Girls】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YohoGirl',
... ... @@ -38,34 +41,34 @@ exports.init = function() {
});
//图片懒加载
$('img.lazy').lazyload({
$('img.lazy').lazyload({
placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
});
//显示控制箭头
(function() {
$('.column-slide').on('mouseenter',function() {
$('.column-slide').on('mouseenter', function() {
$('.column-slide').find('.slide-ctrl').hide();
if ($(this).find('li').size() <= 4) return;
clearTimeout(timer);
$(this).find('.slide-ctrl').show();
}).on('mouseleave',function(event) {
}).on('mouseleave', function(event) {
var $that = $(this);
timer = setTimeout(function() {
$that.find('.slide-ctrl').hide();
$that.find('.slide-ctrl').hide();
}, 1000)
});
$('.column-slide .slide-ctrl').on('mouseenter',function() {
$('.column-slide .slide-ctrl').on('mouseenter', function() {
clearTimeout(timer);
$(this).show();
}).on('mouseleave',function() {
timer=setTimeout(function() {
$(this).hide();
}).on('mouseleave', function() {
timer = setTimeout(function() {
$(this).hide();
}, 100)
});
})();
})();
//封面杂志图滚动
magazineSlide = new swiper('.mags-slide .swiper-container', {
... ... @@ -80,7 +83,7 @@ exports.init = function() {
});
$('.column-slide.magazine-list').imgSlider({
itemClass:'magazine'
itemClass: 'magazine'
});
//当页面改变大小,ipad横竖屏切换重新加载插件
... ... @@ -88,18 +91,18 @@ exports.init = function() {
clearTimeout(magazineTimer);
magazineTimer = setTimeout(function() {
$('.column-slide.magazine-list').imgSlider('resize');
}, 0)
}, 0);
});
$.ajax({
type:'GET',
url:'/channel/magazine/ezine',
success:function(response) {
type: 'GET',
url: '/channel/magazine/ezine',
success: function(response) {
var data = response.data,
len = data.length;
item ='',
ulNum = Math.ceil(len/16),
ulItem ='',
len = data.length,
item = '',
ulNum = Math.ceil(len / 16),
ulItem = '',
ulAnimateIndex = 0;
var animateWidth,
... ... @@ -107,32 +110,34 @@ exports.init = function() {
itemIndexStart,
itemIndexEnd,
i;
$('.e-zine .slide-box').html('<div class="slide-piclist-wrap clearfix" style="position:relative;top:0;left:0;"></div>');
//添加4个ul
for (var i=0; i<ulNum; i++) {
for (var i = 0; i < ulNum; i++) {
ulItem += '<ul class="slide-piclist clearfix"></ul>';
}
$('.slide-piclist-wrap').html(ulItem);
animateWidth = $('.mags-column').find('.slide-piclist').outerWidth();
slideWrapWidth = animateWidth * ulNum;
$('.slide-piclist-wrap').css({'width': slideWrapWidth});
slideWrapWidth = animateWidth * ulNum;
$('.slide-piclist-wrap').css({
'width': slideWrapWidth
});
//分别插入数据到4个ul
for (i=0; i<ulNum; i++) {
for (i = 0; i < ulNum; i++) {
itemIndexStart = i * 16,
itemIndexEnd = i * 16 + 16;
itemIndexEnd = i * 16 + 16;
item = '';
if (itemIndexEnd > len) {
itemIndexEnd = len;
}
for(var j = itemIndexStart;j<itemIndexEnd;j++){
item += '<li data-type='+data[j].magazineType+'><a href="javascript:;" title="'+data[j].releaseDate+'"><div class="img-wrap"><img src="'+data[j].cover+'" alt="" /></div><span>'+data[j].releaseDate+'</span></a></li>';
for (var j = itemIndexStart; j < itemIndexEnd; j++) {
item += '<li data-type=' + data[j].magazineType + '><a href="javascript:;" title="' + data[j].releaseDate + '"><div class="img-wrap"><img src="' + data[j].cover + '" alt="" /></div><span>' + data[j].releaseDate + '</span></a></li>';
}
$('.slide-piclist-wrap').find('.slide-piclist').eq(i).html(item);
}
... ... @@ -142,20 +147,22 @@ exports.init = function() {
$(window).resize(function() {
animateWidth = $('.mags-column').find('.slide-piclist').outerWidth();
slideWrapWidth = animateWidth * ulNum;
$('.mags-column').on('click.next','.slide-ctrl-next',function() {
if (ulAnimateIndex >= ulNum-1) return;
slideWrapWidth = animateWidth * ulNum;
$('.mags-column').on('click.next', '.slide-ctrl-next', function() {
if (ulAnimateIndex >= ulNum - 1) return;
if ($('.slide-piclist-wrap').is(':animated')) return;
if (ulAnimateIndex==ulNum-2) {
if (ulAnimateIndex == ulNum - 2) {
$(this).hide();
}
$(this).siblings('.slide-ctrl-prev').show();
ulAnimateIndex++;
$('.slide-piclist-wrap').stop().animate({'left':-animateWidth * ulAnimateIndex}, 500);
$('.slide-piclist-wrap').stop().animate({
'left': -animateWidth * ulAnimateIndex
}, 500);
});
$('.mags-column').on('click.prev','.slide-ctrl-prev',function() {
$('.mags-column').on('click.prev', '.slide-ctrl-prev', function() {
if (ulAnimateIndex <= 0) return;
if ($('.slide-piclist-wrap').is(':animated')) return;
if (ulAnimateIndex === 1) {
... ... @@ -163,15 +170,21 @@ exports.init = function() {
}
$(this).siblings('.slide-ctrl-next').show();
ulAnimateIndex--;
$('.slide-piclist-wrap').stop().animate({'left':-animateWidth * ulAnimateIndex}, 500);
$('.slide-piclist-wrap').stop().animate({
'left': -animateWidth * ulAnimateIndex
}, 500);
});
clearTimeout(timer);
timer = setTimeout(function() {
$('.slide-piclist-wrap').css({'width': slideWrapWidth});
$('.slide-piclist-wrap').css({'left':-animateWidth * ulAnimateIndex}, 500);
}, 0)
$('.slide-piclist-wrap').css({
'width': slideWrapWidth
});
$('.slide-piclist-wrap').css({
'left': -animateWidth * ulAnimateIndex
}, 500);
}, 0)
}).resize();
/*for(var i=0;i<len;i++){
item += '<li data-type='+data[i].magazineType+'><a href='javascript:;' title=''+data[i].releaseDate+''><div class='img-wrap'><img src=''+data[i].cover+'' alt='' /></div><span>'+data[i].releaseDate+'</span></a></li>';
... ... @@ -181,10 +194,31 @@ exports.init = function() {
*/
$('.mags-column .slide-piclist').find('li').each(function() {
if($(this).data('type') ==2) {
if ($(this).data('type') == 2) {
$('<em class="border"></em><i class="special-icon"></i>').appendTo($(this).find('.img-wrap'));
};
});
});
}
});
$('.magazine-list').on('click', '.magazine', function() {
if (!$(this).find('img').attr('data-slide')) return;
if ($(this).find('ul').size() >= 1) return;
var data = decodeURIComponent($(this).find('img').attr('data-slide')),
arr = eval('(' + data + ')'),
len = arr.length,
$picList = $('<ul style="display:none;" class="magazine-content"></ul').appendTo($(this)),
item = '';
for (i = 0; i < len; i++) {
item += '<li><img src="" data-imgzoom="' + arr[i] + '" alt="" /></li>';
}
})
}
\ No newline at end of file
$(item).appendTo($picList);
$(this).imgZoom({
originalAttr: 'data-imgzoom',
styleClass: 'magazine-zoom',
isContainer: true
});
});
};
\ No newline at end of file
... ...
/**
* @fileOverview map页面JS
* @author wei.wang@yoho.cn
* @date 2014-05-21
*/
var $ = jQuery = require("jquery");
require("../public");
require("../plugin/nicescroll");
var _ui=require("jquery-ui");
_ui($);
require("jquery.imagesloaded");
initShopListHeight();
$(".city-list").niceScroll();
var currentZoom=0.85;
var OriginalWidth=0,OriginalHeight=0,OriginalMarks={};
exports.init=function(){
$(".map-zoom").show();
OriginalWidth=$("#citymap-img").width();
OriginalHeight=$("#citymap-img").height();
$("#map-zoom-max").click(function(){zoomMax();});
$("#map-zoom-min").click(function(){zoomMin();});
$(".big-mark").each(function(index,obj){
var top=$(this).top();
var left=$(this).left();
OriginalMarks[$(this).attr("id")]={left:left,top:top};
});
$(window).bind("resize",function(){
initShopListHeight();
});
$(".shop").unbind("hover").hover(
function(){
$("#citymap").stop();
$(".mark-tips").hide();//隐藏现有的气泡
moveShopToView(this);
},
function(){
var shopId=$(this).id().replace("shoplist-","mark");
$("#"+shopId).find(".mark-tips").hide();
}
);
$(".big-mark").hover(
function(){$(this).find(".mark-tips").css("display","table");},
function(){$(this).find(".mark-tips").css("display","none");}
);
$(".shop-name").click(function(){
var url=$(this).attr("src");
window.open(url);
});
$(".big-mark").click(function(){
var href=$("a[val='"+$(this).attr("val")+"']").attr("src");
window.open(href);
});
var bodyHeight = document.body.clientHeight - 177;
$(".map-city-content").height(bodyHeight);
$(window).bind("resize", function()
{
var bodyHeight = document.body.clientHeight - 177;
$(".map-city-content").height(bodyHeight);
$("#citymap-img").width($("#citymap").width());
$("#citymap-img").height($("#citymap").height());
});
$("#citymap-img").imagesLoaded(function()
{
$(this).width("100%").height("100%");
$("#citymap").css({width: $(this).width(), height: $(this).height(), position: "relative"}).draggable({
drag: function() {},
stop: function() {
mapRevert(this);
}
});
});
var isMouseDown = false;
};
function initShopListHeight(){
var currentWidth=document.body.clientWidth;
if(currentWidth>=1190)
{
$(".city-list").height(document.body.clientHeight-310);
}
else if(currentWidth<1190&&currentWidth>769)
{
$(".city-list").height(document.body.clientHeight-260);
}
else if(currentWidth<=768)
{
$(".city-list").height(document.body.clientHeight-178);
}
}
/*在商店上显示tips*/
function shopShowTips(obj){
var shopId=$(obj).id().replace("shoplist-","mark");
$("#"+shopId).find(".mark-tips").show();
}
/*如果店铺不在当前视野范围内,则移动到当前范围*/
function moveShopToView(obj){
var contentHeight=$(".map-city-content").height();
var contentWidth=document.body.clientWidth;
var shopId=$(obj).id().replace("shoplist-","mark");
var top=$("#"+shopId).offset().top;
var left=$("#"+shopId).offset().left;
var absoluteTop=0;
var absoluteLeft=0;//$("#"+shopId).offset().left+$("#citymap").left();
if ($("#"+shopId).css("top").indexOf("%")>0) {
absoluteTop=parseFloat($("#"+shopId).css("top").replace("%",""))/100*$("#citymap").height();
absoluteLeft=parseFloat($("#"+shopId).css("left").replace("%",""))/100*$("#citymap").width();
}
else
{
absoluteTop=$("#"+shopId).top();
absoluteLeft=$("#"+shopId).left();
}
var location=getScreenCenter();
if(top<304&&top>0||top<0||
top+177>document.body.clientHeight
||left<$(".city-list").width()
||left>document.body.clientWidth
)
{
var toTop=location.y-absoluteTop;
var toLeft=location.x-absoluteLeft;
if (toLeft>$(".city-list").width()) {
toLeft=$(".city-list").width();
}
if (toTop>190) {
toTop=190;
}
$("#citymap").animate({top:toTop,left:toLeft},500,function(){
$("#"+shopId).find(".mark-tips").show();
});
}
else
{
$("#"+shopId).find(".mark-tips").show();
}
}
function zoom(){
var width=OriginalWidth*currentZoom;
var height=OriginalHeight*currentZoom;
$("#citymap").width(width);
$("#citymap").height(height);
}
function zoomMax(){
if(currentZoom>=1)
{
return;
}
currentZoom=currentZoom+0.05;
zoom();
}
function zoomMin(){
if(currentZoom<=0.7)
{
return;
}
currentZoom=currentZoom-0.05;
zoom();
}
function mapRevert(obj)
{
var top = parseFloat($(obj).css("top").replace("px", ""));
var left = parseFloat($(obj).css("left").replace("px", ""));
var contentHeight = $(".map-city-content").height();
var contentWidth = document.body.clientWidth;
var bottom = contentHeight - top - $(obj).height();
// var right = contentWidth - left - parseFloat($(obj).width());
// var rightForbid = contentWidth - $(".city-shop-list").width();
if (top > 120 && bottom < 0)
{
$(obj).animate({top: 120}, 500);
}
if (bottom > 0 && top < 120)
{
$(obj).animate({top: contentHeight - $(obj).height()}, 500);
}
if (left + $(obj).width() <= $(".city-shop-list").width())
{
$(obj).animate({left: contentWidth - $(obj).width()}, 500);
}
if (left > contentWidth)
{
$(obj).animate({left: contentWidth - $(obj).width()}, 500);
}
}
function getScreenCenter(){
var width=document.body.clientWidth;
var height=document.body.clientHeight;
var _left=(width-$(".city-shop-list").width())/2+$(".city-shop-list").width();
var _headerHeight=$("#maxEnterprise").height()-$(".enterprise-header").height()-12;
var _top=$(".map-city-content").height()/2;
//$("<span/>").css({position:"absolute",display:"block",width:20,height:20,"z-index":20,background:"#f00",left:_left,top:_top}).appendTo(document.body);
return {x:_left,y:_top};
}
/**
* @fileOverview 首页JS
* @author wei.wang@yoho.cn
* @date 2014-05-21
*/
var $=require("jquery");
//require("lib/ui/touch");
//require("lib/util/jquery.hammer");
require("../public");
require("jquery.imagesloaded");
var currentZoom=0.85;
var OriginalWidth=0,OriginalHeight=0,OriginalMarks={};
window.onresize=function(){
initShopListHeight();
var bodyWidth=document.body.clientWidth;
$("#citymap").width(bodyWidth-$(".city-shop-list").width());
var contentWidth = $(".map-city-content").width();
var currentLeft=parseFloat(contentWidth-$("#citymap").width());
$("#citymap").css({"left":currentLeft,top:0});
}
exports.init=function(){
initShopListHeight();
$(".city-list").find("div").niceScroll();
$(document.body).css({overflow:"hidden"});
var bodyWidth=document.body.clientWidth;
$("#citymap-img").imagesLoaded(function()
{
$(this).width("100%").height("100%");
});
$(".shop").hover(
function(){
$(".mark-tips").hide();
var shopId=$(this).id().replace("shoplist-","mark");
var shopObj=$("#"+shopId);
var top=0;
var left=0;
var _top=parseFloat($("#"+shopId)[0].style.top.replace("%",""));
var _left=parseFloat($("#"+shopId)[0].style.left.replace("%",""));
top=_top/100*$("#citymap").height();
left=_left/100*$("#citymap").width();
console.log(top,left);
console.log(bodyWidth-shopObj.offset().left);
if(top<120&&left<250){
//显示在右下角
$("#"+shopId).find(".mark-tips").attr("class","mark-tips left-bottom");
}
else if(top>120&&left<250)
{
//显示在右上角
$("#"+shopId).find(".mark-tips").attr("class","mark-tips left");
}
else if(top<120&&left>250&&bodyWidth-shopObj.offset().left>250)
{
//显示在左下角
$("#"+shopId).find(".mark-tips").attr("class","mark-tips left-bottom");
}
else if (top<120&&left>250&&bodyWidth-shopObj.offset().left<250) {
$("#"+shopId).find(".mark-tips").attr("class","mark-tips right-bottom");
}
else if(top>120&&left>250&&bodyWidth-shopObj.offset().left>250)
{
//显示在左角
$("#"+shopId).find(".mark-tips").attr("class","mark-tips left");
}
else if(top>120&&left>250&&bodyWidth-shopObj.offset().left<250)
{
//显示在左角
$("#"+shopId).find(".mark-tips").attr("class","mark-tips right");
}
$("#"+shopId).find(".mark-tips").show().unbind().click(function(){
var href=$("a[val='"+$(this).parent().attr("val")+"']").attr("src");
window.open(href);
});
},
function(){
var shopId=$(this).id().replace("shoplist-","mark");
}
);
$("#citymap-img").width("100%").height("100%");
var bodyHeight = document.body.clientHeight - 177;
$(".map-city-content").height(bodyHeight);
$("#citymap").width(bodyWidth-$(".city-shop-list").width());
var contentWidth = $(".map-city-content").width();
var currentLeft=parseFloat(contentWidth-$("#citymap").width());
$("#citymap").css({"left":currentLeft,top:0});
var currentTop=parseFloat($("#citymap").css("top").replace("px",""));
};
function initShopListHeight(){
var currentWidth=document.body.clientWidth;
if(currentWidth>=1190)
{
$(".city-list").height(document.body.clientHeight-310);
}
else if(currentWidth<1190&&currentWidth>=769)
{
$(".city-list").height(document.body.clientHeight-260);
}
else if(currentWidth<=768)
{
$(".city-list").height(document.body.clientHeight-268);
}
}
var $=require("jquery");
require("jquery.autocomplete");
var box=require('../plugin/box');
var box=require('yoho-box');
if ($("#search-content").find(".content-item").length==0) {
var clientHeight=document.body.clientHeight;
$("#search-content").height(clientHeight-436);
$("#search-content").height(clientHeight-704);
}
$("#search-button-search").click(function(){
... ... @@ -22,11 +22,14 @@
window.location.href=YohoConfig.mainUrl+"/search?q="+input.val();
}
});
$("#input-search-search")
.autocomplete('/search/default/words', {
resultsClass: "search-suggest helveticaneue", loadingClass:"loading",
width:249, scrollHeight:360,
max:10, selectFirst:false, autoFill:false,
$("#input-search-search").autocomplete('/search/default/words', {
resultsClass: "search-suggest helveticaneue",
loadingClass:"loading",
width:249,
scrollHeight:360,
max:10,
selectFirst:false,
autoFill:false,
formatResult: function(row, data)
{
return data.replace(/<\/?[^>]*>/g,'');
... ... @@ -49,3 +52,72 @@
$("#search-button-search").trigger("click");
}
});
//首页碎片交互=================================================================================================
function dealItems() {
var citems = $(".content-item,.content-item-without-border");
if (!citems.length) {
return;
}
var totalLineNum = 7;
// 7 行
var maxTitleStrNum = 45;
// 15个字
var maxDetailStrNum = 24;
// 22个字
if (document.body.clientWidth < 1190) {
totalLineNum = 6;
// 6 行
maxTitleStrNum = 39;
// 13个字
maxDetailStrNum = 54;
// 18个字
}
var titleLineNum = 0;
var subTitleLineNum = 0;
var detailLineNum = 0;
var detailStr = "";
var self = null;
citems.each(function() {
self = $(this);
var itemTitleObj= self.find(".content-item-title");
// 主标题行数
if(typeof(itemTitleObj.attr("_title"))==="undefined"||itemTitleObj.attr("_title")===null)
return;
titleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
titleLineNum = 2;
}
// 副标题行数
subTitleLineNum = 1;
if (maxTitleStrNum < $(".content-item-subtitle").attr("_title").length) {
subTitleLineNum = 2;
}
// 摘要内容行数
detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
if(itemTitleObj.text()=="sports"){
console.log((maxDetailStrNum * detailLineNum) );
}
if ((maxDetailStrNum * detailLineNum) < self.find(".content-item-detail").attr("_title").length) {
detailStr = self.find(".content-item-detail").attr("_title").substring(0, maxDetailStrNum * detailLineNum ) + " ...";
self.find(".content-item-detail").text(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
}
else
{
self.find(".content-item-detail").text(self.find(".content-item-detail").attr("_title"));
}
});
citems = null;
}
dealItems();
//=============================================================
\ No newline at end of file
... ...
/**
* 文件功能描述 :首页JS
* 使用方法 :直接use
* author :wei.wang@yoho.cn
* date :2015-4-23
*/
var $ = require("jquery");
require("lazyload");
var Swiper = require("yoho-idangerous.swiper");
var tips=require("yoho-tips");
var box=require("yoho-box");
//pop=============================================================================================
var pop = new Swiper('.swiper-container3', {
loop : true,
autoplay : 5000,
autoStopPlay : false,
paginationClickable : true,
onSlideChangeEnd : function() {
pop.startAutoplay();
$(".swiper-container3 .lazy").lazyload();
}
});
$('.prev-button').bind('click', function(e) {
e.preventDefault();
pop.swipePrev();
});
$('.next-button').bind('click', function(e) {
e.preventDefault();
pop.swipeNext();
});
var popTop = $(".pop-container").offset().top;
var popLeft=$(".pop-container").offset().left;
var limitTop=$(".pager-content-default").offset().top+$(".pager-content-default").height()+2-$(".pop-container").height();
var stopTop=$(".pager-content-default").offset().top-$(".pop-container").height();
var stopLeft=$(".bottom-item-container").offset().left+$(".bottom-item-container").width()-$(".pop-container").width();
console.log(stopLeft);
var isFixed=false;
if(limitTop-popTop>$(".pop-container").height())
{
$(window).scroll(function() {
if ($(document).scrollTop() >= popTop&&isFixed===false&&$(document).scrollTop() < limitTop) {
isFixed=true;
$(".pop-container-bottom").attr("class","pop-container");
$(".pop-container").css({position:"fixed",top:0,left:popLeft});
}
else if($(document).scrollTop() > limitTop){
$(".pop-container").removeAttr("style");
if($(".swiper-container2")[0]!=null){
$(".pop-container").css({"border-top":0});
}
$(".pop-container").attr("class","pop-container-bottom");
isFixed=false;
}
else if(isFixed===true&&$(document).scrollTop() < popTop)
{
isFixed=false;
$(".pop-container").removeAttr("style");
if($(".swiper-container2")[0]!=null){
$(".pop-container").css({"border-top":0});
}
}
});
}
//================================================================================================
//首页碎片交互=================================================================================================
//mulLine.init();
function dealItems() {
var citems = $(".item-text-area");
if (!citems.length) {
alert("返回");
return;
}
var totalLineNum = 7;
// 7 行
var maxTitleStrNum = 45;
// 15个字
var maxDetailStrNum = 22;
// 22个字
if (document.body.clientWidth < 1190) {
totalLineNum = 6;
// 6 行
maxTitleStrNum = 39;
// 13个字
maxDetailStrNum = 54;
// 18个字
}
var titleLineNum = 0;
var subTitleLineNum = 0;
var detailLineNum = 0;
var detailStr = "";
var self = null;
citems.each(function() {
self = $(this);
var itemTitleObj= self.find(".item-title:first");
// 主标题行数
titleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
titleLineNum = 2;
}
// 副标题行数
subTitleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.next().attr("_title").length) {
subTitleLineNum = 2;
}
// 摘要内容行数
detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
if ((maxDetailStrNum * detailLineNum) < self.find(".item-detail").attr("_title").length) {
detailStr = self.find(".item-detail").attr("_title").substring(0, maxDetailStrNum * detailLineNum ) + " ...";
self.find(".item-detail").text(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
}
});
citems = null;
}
dealItems();
//=============================================================
//邮件订阅=============================================================================================================
$(".followus-button").click(function(){
if($(".follow-us-input-content input").val()=='')
{
box.alert(tips.getTips("emailEmpty"));
return;
}
if(!tools.IYOHO_isEmail($(".follow-us-input-content input").val()))
{
box.alert(tips.getTips("emailError"));
return;
}
$(".search-suggest").hide();
window.open( '/passport/subscribe/index?email='+$(".follow-us-input-content input").val());
});
$(".followus-input").keydown(function(event){
if(event.keyCode==13)
{
$(".followus-button").trigger("click");
}
});
//===================================================================================================================
\ No newline at end of file
... ...
/**
* @fileOverview 地图列表
* @author feiker <fei.hong@yoho.cn>
* @date 2013-06-04
*/
var $ = require('jquery');
require('yoho.easing');
require('jquery.imagesloaded');
require('jquery.pin');
require('jquery-ui');
require('jquery.ui.touch-punch');
require('jquery.wresize');
$("#map-pannel").css({"background":"#fff",height:"300px"}).pin({containerSelector: ".wrapper"});
$(".hot-area").mouseover(function(){
$(this).find(".background").show();
$(this).find(".china-area").show();
});
$(window).scroll(function()
{
var height = $(".page-head").height();
$("#map-pannel").css({"top":height+"px"});
});
var mapW = $(".grid-city-map").width();
$(".background").on("click",function(){
$(this).hide();
$(".china-area").hide();
});
if($(".grid-city-map #map").length)
{
//页面图加载完成
$(".grid-city-map #map").imagesLoaded(function()
{
$(".handle").show().mousedown(function()
{
$(this).addClass('grabbing');
}).mouseup(function()
{
$(this).removeClass('grabbing');;
});
//hover到店铺列表后的地图移动和tip展示
var timeoutHandle= null;
$(".map-shop-list .shop-name").hover(function()
{
var self = $(this);
window.clearTimeout(timeoutHandle);
timeoutHandle = window.setTimeout(function()
{
showTip(self.attr("val"),this);
$("#"+self.attr("val")).css({"z-index":1000});
},650);
},function()
{
$(".mark-tip").fadeOut('fast');
$("#"+$(this).attr("val")).css({"z-index":3});
});
//鼠标移到建筑物展示tip
var setime = null;
var tip_clone = null;
$(".grid-city-map .mark").hover(function()
{
// window.clearTimeout(setime);
var id = $(this).attr("val");
$(this).find(".mark-tip").show();
var pos = $("#"+id).position();
var tipPos = pos.left>$(".grid-city-map").width()/2?"left":"right";
$("#"+id).find(".mark-tip").attr("class","mark-tip "+tipPos);
$("#"+id).css({"z-index":1000});
var distance = $("#"+id).find(".mark-tip").offset();
tip_clone = $("#"+id).find(".mark-tip").hide().clone();
//$(this).parent().append(tip_clone);
$("body").append(tip_clone);
var top=parseInt($("#"+id).css("top").replace("px",""))-parseInt(tip_clone.css("height").replace("px",""));
var left=parseInt($("#"+id).css("left").replace("px",""))-parseInt(tip_clone.css("width").replace("px",""));
tip_clone.attr("id", id+"_clone").css({"position": "fixed",
"top": distance.top+"px",
"left": distance.left+"px",
"z-index": 1000000}).show();
// 鼠标移动到克隆的mark-tip触发的事件
$("#"+id+"_clone").hover(function(){
window.clearTimeout(setime); //鼠标划过的时候清除延迟(即清除setime这个函数);
}, function(){
$(this).fadeOut("fast");
$(this).remove();
});
},function()
{
var self = $(this);
setime = setTimeout(function(){
var clone = $("#"+self.attr("val")+"_clone");
clone.fadeOut("fast");
clone.remove();
}, 50);
$("#"+$(this).attr("val")).css({"z-index":3});
});
//打开该店铺
$(".grid-city-map .mark img").click(function()
{
var id = $(this).parent('.mark').attr("id");
var href = $(".map-shop-list a[val='"+id+"']").attr("href");
//window.location.href = href;
window.open(href);
});
initMap();
$(".handle").draggable({ axis: "y",containment:"parent"});
});
function initMap()
{
//设置地图面板的高宽
var mapH = $("#map")[0].clientHeight;
var mapW = $("#map")[0].clientWidth;
$(".grid-city-map").height(mapH);
$("#map-pannel").width(mapW);
//初始化坐标位置
$(".grid-city-map .mark").each(function()
{
var w = $(this).attr('left')/10000;
var h = $(this).attr('top')/10000;
$(this).css({left:(mapW*w)+"px",top:(mapH*h)+"px"});
});
//设置拖拽
var ch = $(".map-hide").height();
$("#drag-pannel").width(mapW).height(mapH*2-ch+161).css({"position":"absolute","top":(ch-mapH)+"px"});
$(".handle").css({"top":(mapH-ch)+"px"});
}
$(window).resize(initMap);
//展示tip和移动
function showTip(id,obj)
{
$(".mark-tip").hide();
var pos = $("#"+id).position();
var height = $("#"+id).height();
var tipHeight = 161;
var cur = (420-(height+161))/2+tipHeight;
var num = cur-pos.top;
var tipPos = pos.left>$(".grid-city-map").width()/2?"left":"right";
$("#"+id).find(".mark-tip").attr("class","mark-tip "+tipPos);
var ch = $(".map-hide").height();
var mapH = $("#map").height();
num=num+(mapH-ch);
if(num==0)
{
return;
}
//设置移动和动画
$(".grid-city-map").stop( true, true ).animate({"top":num+"px"},200,"easeOutExpo",function()
{
$("#"+id).stop( true, true ).animate({"top":"-=40px"},100,"easeOutQuart")
.animate({"top":"+=40px"},300,"easeOutBounce",function()
{
$(".mark-tip").hide();
$(this).find(".mark-tip").show();
});
});
}
$(".parent-nav li").css({"cursor":"pointer"});
$(".parent-nav li").click(function()
{
window.location.href = $(this).find("a").attr("href");
});
}
//导航切换分页
var offset = 0;
var limit = 9;
function navMove(num)
{
if((offset==0&&num<0)||(num>0&&offset+limit>=$(".sub-nav:eq(1) li").length))
{
return;
}
offset+=num;
$(".sub-nav:eq(1) li").hide();
$(".sub-nav:eq(1) li").each(function()
{
var index = $(".sub-nav:eq(1) li").index(this);
if(index>=offset&&index<(offset+limit))
{
$(this).show();
}
});
if((num>0&&offset+limit>=$(".sub-nav:eq(1) li").length))
{
$(".sub-nav:eq(2) span").removeClass("click");
}
else
{
$(".sub-nav:eq(2) span").addClass("click");
}
if((offset==0&&num<0))
{
$(".sub-nav:eq(0) span").removeClass("click");
}
else
{
$(".sub-nav:eq(0) span").addClass("click");
}
}
$(".sub-nav:eq(0) span").click(function()
{
navMove(-limit);
});
$(".sub-nav:eq(2) span").click(function()
{
navMove(limit);
});
//首页的行为
$(".big-mark").hover(function()
{
$(this).css({'z-index':1000});
if(Number(this.style.left.replace("%",""))<50)
{
$(this).find(".mark-tip").attr("class","mark-tip rights");
}
$(this).find(".mark-tip").fadeIn('fast');
},function()
{
$(this).find(".mark-tip").fadeOut('fast');
$(this).css({'z-index':2});
});
$(".big-mark").click(function()
{
window.location.href = $(this).attr("url");
});
function setDrag()
{
//$(".wrapper").css({"width":"100%"});
var w = $(".gird-map-pan").width();
var maxW = $("#drag_handle").width();
var left = $(".gird-map-pan").offset().left;
//$("#drag_handle").draggable({ axis: "x",containment:[(w-maxW+left),0,left,0]});
//$("#drag_handle").css({"left":((w-maxW)/2)+"px"});
if(w<1320)
{
$("#drag_handle").width(980).height(486);
$("#Map-area area").attr("coords","684,203,640,236,669,264,711,285,730,296,755,286,767,289,769,277,773,237,782,234,792,226,799,216,801,203,797,191,767,191,755,210,747,218,717,226");
}
else
{
$("#drag_handle").width(1320).height(654);
$("#Map-area area").attr("coords","900,271,863,313,886,345,927,359,946,379,971,370,986,385,1024,362,1033,339,1027,321,1039,305,1056,292,1045,264,1025,258,1005,278,983,294,968,299,934,295");
}
$(".footer").css({"margin-top":"20px"});
}
if($("#drag_handle").length>0)
{
$(window).resize(setDrag);
setDrag();
}
var flag = null;
$("#Map-area area").hover(function()
{
$("#china-map").show();
$("#drag_handle").css({'opacity':'0.4'});
},function()
{
flag = window.setTimeout(function()
{
$("#china-map").hide();
$("#drag_handle").css({'opacity':'1'});
},0);
});
$("#china-map").hover(function()
{
window.clearTimeout(flag);
$("#china-map").show();
$("#drag_handle").css({'opacity':'0.4'});
},function()
{
$("#china-map").hide();
$("#drag_handle").css({'opacity':'1'});
});
... ... @@ -2,209 +2,209 @@
* 评论及登录插件
* author:liuyue
* date:2015-01-07
*/
*/
var $ = require("jquery"),
validate = require("./validate"),
box = require("./box"),
tools = require("yoho-tools"),
tips = require("./tips");
mustache = require("mustache");
validate = require("./validate"),
box = require("./box"),
tools = require("yoho-tools"),
tips = require("./tips"),
mustache = require('mustache');
require("./login");
(function(global, undefined) {
var Comment = function(element, options) {
this.options = options;
this.$element = $(element);
//this.$loginBox = $(this.options.loginbox).appendTo("body");
this.init();
};
Comment.DEFAULTS = {
cid: '',
commentPageUrl: '/writer/default/comment',
publishUrl: '/writer/default/publish',
deleteUrl: '/writer/default/delete',
commentNum: $(".comment-num"),
commentItemTpl: '<li class="clearfix">'+
'<div class="userimg">'+
'<img src="\{{userimg}}" alt="">'+
'<i class="\{{partnerType}}"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>\{{username}}</h6> '+
'<p class="comment-text">\{{content}}</p>'+
'\{{# isSelf}}'+
'<a class="delete-comment" href="javascript:;" pid="{{id}}"></a>'+
'\{{/ isSelf}} '+
'</div>'+
'</li>',
thirdLogin: false,
isEdit: false,
isMobile: false,
login: ''
};
Comment.prototype = {
constructor: Comment,
init:function() {
// 组件的创建主函数。
this._creat();
},
// 主函数,主要是创建节点,绑定事件。
_creat: function() {
if ($(".comments-list").size() > 0 || $(".comment-textarea").size() > 0) return;
// 创建节点
this._creatCommentDom();
this._creatThirdLogin();
// 绑定事件
this._bindEvent();
},
_creatCommentDom:function() {
var that = this;
//var id = {id:this.options.cid};
$.ajax({
type:'GET',
url:YohoConfig.mainUrl + this.options.commentPageUrl,
var Comment = function(element, options) {
this.options = options;
this.$element = $(element);
//this.$loginBox = $(this.options.loginbox).appendTo("body");
this.init();
};
Comment.DEFAULTS = {
cid: '',
commentPageUrl: '/writer/default/comment',
publishUrl: '/writer/default/publish',
deleteUrl: '/writer/default/delete',
commentNum: $(".comment-num"),
commentItemTpl: '<li class="clearfix">' +
'<div class="userimg">' +
'<img src="\{{userimg}}" alt="">' +
'<i class="\{{partnerType}}"></i>' +
'</div>' +
'<div class="userinfo">' +
'<h6>\{{username}}</h6> ' +
'<p class="comment-text">\{{content}}</p>' +
'\{{# isSelf}}' +
'<a class="delete-comment" href="javascript:;" pid="{{id}}"></a>' +
'\{{/ isSelf}} ' +
'</div>' +
'</li>',
thirdLogin: false,
isEdit: false,
isMobile: false,
login: ''
};
Comment.prototype = {
constructor: Comment,
init: function() {
// 组件的创建主函数。
this._creat();
},
// 主函数,主要是创建节点,绑定事件。
_creat: function() {
if ($(".comments-list").size() > 0 || $(".comment-textarea").size() > 0) return;
// 创建节点
this._creatCommentDom();
this._creatThirdLogin();
// 绑定事件
this._bindEvent();
},
_creatCommentDom: function() {
var that = this;
//var id = {id:this.options.cid};
$.ajax({
type: 'GET',
url: YohoConfig.mainUrl + this.options.commentPageUrl,
/*data: id,
dataType:'json',*/
success:function(response) {
var data = response.data, //返回数据的data
viewMoreNum = data.total - 5, //评论总数-5,除显示评论剩下的评论数量
moreString = viewMoreNum + '', //剩余评论数量转为字符串
moreFirstnum = moreString.slice(0,1), //评论数量的首数字
commentTpl = $('#comment-tpl').html(), //引入评论html模板
commentPage, //分页数据
commentHtml, //用数据渲染后的html
commentData; //评论数据
if(data.length === 0) return;
commentData = {
comment: data.comment
};
//评论多于五条,渲染more节点
if (viewMoreNum > 0) {
commentData = {
comment: data.comment,
more: {
moreNum : viewMoreNum
}
}
}
//如果分页数据不为空和undefined,渲染分页
if ($.trim(data.page) !== '' || typeof(data.page) === 'undefined' || !!data.page) {
success: function(response) {
var data = response.data, //返回数据的data
viewMoreNum = data.total - 5, //评论总数-5,除显示评论剩下的评论数量
moreString = viewMoreNum + '', //剩余评论数量转为字符串
moreFirstnum = moreString.slice(0, 1), //评论数量的首数字
commentTpl = $('#comment-tpl').html(), //引入评论html模板
commentPage, //分页数据
commentHtml, //用数据渲染后的html
commentData; //评论数据
if (data.length === 0) return;
commentData = {
comment: data.comment
};
//评论多于五条,渲染more节点
if (viewMoreNum > 0) {
commentData = {
comment: data.comment,
more: {
moreNum: viewMoreNum
}
}
}
//如果分页数据不为空和undefined,渲染分页
if ($.trim(data.page) !== '' || typeof(data.page) === 'undefined' || !!data.page) {
commentPage = data.page;
commentData = {
comment: data.comment,
more: {
moreNum : viewMoreNum
},
page: commentPage
}
}
commentData = {
comment: data.comment,
more: {
moreNum: viewMoreNum
},
page: commentPage
}
}
commentHtml = mustache.render(commentTpl, commentData, {
html: commentPage
});
that.$element.prepend($(commentHtml));
//5条后的评论隐藏
that.$element.find("li").eq(4).nextAll().hide(); //5条后的评论隐藏
//评论总数上千显示k+,上万显示w+
if (moreString.length === 4) {
$(".view-more").find("span").text(moreFirstnum + 'k+');
} else if (moreString.length === 5) {
$(".view-more").find("span").text(moreFirstnum + 'w+');
}
that.$element.prepend($(commentHtml));
//5条后的评论隐藏
that.$element.find("li").eq(4).nextAll().hide(); //5条后的评论隐藏
//评论总数上千显示k+,上万显示w+
if (moreString.length === 4) {
$(".view-more").find("span").text(moreFirstnum + 'k+');
} else if (moreString.length === 5) {
$(".view-more").find("span").text(moreFirstnum + 'w+');
}
}
});
},
//创建评论文本域
/*_creatTextareaDom:function(){
data = this.options.login;
var textarea = $('<div class="comment-textarea"><textarea placeholder="'+tips.getTips("textareaPlaceholder")+'" cid='+this.options.cid+'></textarea></div>'),
loginarea = $('<div class="login-status clearfix">\n\
<div class="userimg">\n\
<img src="'+YohoConfig.resUrl+'boysweb/assets/images/detail/user-img.png" alt="">\n\
<i></i>\n\
</div>\n\
<div class="userinfo">\n\
<span></span>\n\
<a class="exit-btn" href="javascript:;">退出</a>\n\
</div>\n\
<div class="publish">\n\
<a class="publish-btn" href="javascript:;">Publish</a>\n\
</div>\n\
</div>');
textarea.appendTo(this.$element);
loginarea.appendTo(textarea);
if(this.options.isFeedback){
var anonymous = $('<div class="anonymous">YohoBoy</div>');
$(".login-status .userimg").after(anonymous);
}
if(!data){
$(".login-status .userinfo").hide();
}
},*/
//创建第三方登录
_creatThirdLogin:function(){
var thirdLoginTpl = $("#third-login-tpl").html();
if (this.options.thirdLogin === true) {
$(thirdLoginTpl).appendTo(this.$element);
//this.$element.html(thirdLoginTpl);
}
},
//事件绑定
_bindEvent: function(){
var that = this;
//查看更多评论
this.$element.on("click.comment",".view-more",function() {
that.$element.find("li").show(); //显示第一页后五条
that.$element.find(".comment-pager-content").show(); //显示分页按钮
that.$element.find(".view-more").remove(); //移除view more
});
//弹出登录框
/*$(this).login();
this.$element.on("click.login",".publish-btn",function() {
if(that.options.isFeedback) return;
$(this).login("loginBoxAnimate");
});*/
//显示删除按钮
if (this.options.isMobile) {
this.$element.find(".delete-comment").show();
} else {
this.$element.on("mouseenter","li",function() {
$(this).find(".delete-comment").show();
}).on("mouseleave","li",function(){
$(this).find(".delete-comment").hide();
});
}
//发表评论
this.$element.on("click.publish",".publish-btn",function() {
var $textarea = that.$element.find("textarea"),
nameInput = that.$element.find(".name-input"),
});
},
//创建评论文本域
/*_creatTextareaDom:function(){
data = this.options.login;
var textarea = $('<div class="comment-textarea"><textarea placeholder="'+tips.getTips("textareaPlaceholder")+'" cid='+this.options.cid+'></textarea></div>'),
loginarea = $('<div class="login-status clearfix">\n\
<div class="userimg">\n\
<img src="'+YohoConfig.resUrl+'boysweb/assets/images/detail/user-img.png" alt="">\n\
<i></i>\n\
</div>\n\
<div class="userinfo">\n\
<span></span>\n\
<a class="exit-btn" href="javascript:;">退出</a>\n\
</div>\n\
<div class="publish">\n\
<a class="publish-btn" href="javascript:;">Publish</a>\n\
</div>\n\
</div>');
textarea.appendTo(this.$element);
loginarea.appendTo(textarea);
if(this.options.isFeedback){
var anonymous = $('<div class="anonymous">YohoBoy</div>');
$(".login-status .userimg").after(anonymous);
}
if(!data){
$(".login-status .userinfo").hide();
}
},*/
//创建第三方登录
_creatThirdLogin: function() {
var thirdLoginTpl = $("#third-login-tpl").html();
if (this.options.thirdLogin === true) {
$(thirdLoginTpl).appendTo(this.$element);
//this.$element.html(thirdLoginTpl);
}
},
//事件绑定
_bindEvent: function() {
var that = this;
//查看更多评论
this.$element.on("click.comment", ".view-more", function() {
that.$element.find("li").show(); //显示第一页后五条
that.$element.find(".comment-pager-content").show(); //显示分页按钮
that.$element.find(".view-more").remove(); //移除view more
});
//弹出登录框
/*$(this).login();
this.$element.on("click.login",".publish-btn",function() {
if(that.options.isFeedback) return;
$(this).login("loginBoxAnimate");
});*/
//显示删除按钮
if (this.options.isMobile) {
this.$element.find(".delete-comment").show();
} else {
this.$element.on("mouseenter", "li", function() {
$(this).find(".delete-comment").show();
}).on("mouseleave", "li", function() {
$(this).find(".delete-comment").hide();
});
}
//发表评论
this.$element.on("click.publish", ".publish-btn", function() {
var $textarea = that.$element.find("textarea"),
nameInput = that.$element.find(".name-input"),
emailInput = that.$element.find(".email-input"),
comment = $textarea.val(),
comment = $textarea.val(),
cid,
data,
commentsNum,
... ... @@ -216,7 +216,7 @@ require("./login");
if (!tools.IYOHO_isUserName(nameInput.val())) {
box.alert(tips.getTips("commentUncompleted"), 5, function() {
nameInput.focus();
});
});
return false;
};
... ... @@ -224,7 +224,7 @@ require("./login");
if (emailInput.val() !== '' && !tools.IYOHO_isEmail(emailInput.val())) {
box.alert(tips.getTips("commentUncompleted"), 5, function() {
emailInput.focus();
});
});
return false;
};
... ... @@ -232,228 +232,229 @@ require("./login");
if (typeof(comment) === 'undefined' || $.trim(comment) === '') {
box.alert(tips.getTips("commentUncompleted"), 5, function() {
$textarea.focus();
});
});
return false;
};
if (comment.length > 100) {
box.alert(tips.getTips("commentToMuch"), 5);
return false;
};
cid = that.$element.attr('cid');
if (!cid) {
return false;
};
if (comment.length > 100) {
box.alert(tips.getTips("commentToMuch"), 5);
return false;
};
data = {id:cid,comment:comment,sync:'222',title:'111'};
cid = that.$element.attr('cid');
if (!cid) {
return false;
};
data = {
id: cid,
comment: comment,
sync: '222',
title: '111'
};
$.ajax({
type: 'GET',
url: YohoConfig.mainUrl + that.options.publishUrl,
success: function(response) {
if (response.code === '800000') {
type: 'GET',
url: YohoConfig.mainUrl + that.options.publishUrl,
success: function(response) {
if (response.code === '800000') {
box.alert(tips.getTips("relogin"), 5);
that.$element.login("setLogout");
return false;
};
if (response.status && response.data) {
var $commentsList = $(".comments-list");
publishHtml = mustache.render(that.options.commentItemTpl, response.data);
if ($commentsList.find("li").size() === 0) {
$commentsList.html(publishHtml);
} else {
$commentsList.find("li").eq(0).before(publishHtml);
}
box.alert(tips.getTips("publishSuccess"), 5);
$(".comment-textarea textarea").val('');
commentsNum = 1;
if (!!parseInt(that.options.commentNum.eq(0).text())) {
commentsNum = parseInt(that.options.commentNum.eq(0).text()) + 1;
};
that.options.commentNum.text(commentsNum);
} else if (900000 === response.code) {
box.alert(tips.getTips("notSameContent"), 5);
} else {
box.alert(tips.getTips("systemBus"), 5);
}
publishHtml = mustache.render(that.options.commentItemTpl, response.data);
that.$element.find(".comments-list").prepend(publishHtml);
}
})
/*$.ajax({
type:'POST',
url:YohoConfig.mainUrl + that.options.publishUrl,
data: data,
dataType:'json',
success:function(response) {
if (response.code === '800000')
{
box.alert(tips.getTips("relogin"), 5);
that.$element.login("setLogout");
return false;
};
}
if (response.status && response.data) {
var $commentsList = $(".comments-list");
publishHtml = mustache.render(that.options.commentItemTpl, response.data);
if ($commentsList .find("li").size() === 0){
$commentsList.html(publishHtml);
} else {
$commentsList.find("li").eq(0).before(publishHtml);
var $commentsList = $(".comments-list");
var commentItem = '<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+response.data.headpic+'" alt="">'+
'<i class="'+response.data.partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+response.data.nick+'</h6>'+
'<p class="comment-text">'+response.data.content+'</p>'+
'<a class="delete-comment" href="javascript:;" pid="'+response.data.id+'"></a>'+
'</div>'+
'</li>';
if(that.options.isFeedback && $(".login-status .anonymous").css("display") != "none"){
commentItem = '<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+response.data.headpic+'" alt="">'+
'<i class="'+response.data.partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+response.data.nick+'</h6>'+
'<p class="comment-text">'+response.data.content+'</p>'+
'</div>'+
'</li>';
}
if($commentsList .find("li").size()==0){
$commentsList .html(commentItem);
}else{
$commentsList .find("li").eq(0).before(commentItem);
}
if(that.options.isFeedback){
box.alert(tips.getTips("publishFeedback"), 5);
}else if(that.options.isEdit){
box.alert(tips.getTips("editPublishSuccess"), 5);
}else{
box.alert(tips.getTips("publishSuccess"), 5);
}
box.alert(tips.getTips("publishSuccess"), 5);
$(".comment-textarea textarea").val('');
commentsNum = 1;
var comments = 1;
if(!!parseInt(that.options.commentNum.eq(0).text())){
commentsNum = parseInt(that.options.commentNum.eq(0).text())+1;
comments = parseInt(that.options.commentNum.eq(0).text())+1;
};
that.options.commentNum.text(commentsNum);
} else if (900000 === response.code) {
that.options.commentNum.text(comments);
}
else if(900000 == response.code){
box.alert(tips.getTips("notSameContent"), 5);
} else {
box.alert(tips.getTips("systemBus"), 5);
}
publishHtml = mustache.render(that.options.commentItemTpl, response.data);
that.$element.find(".comments-list").prepend(publishHtml);
}
})
/*$.ajax({
type:'POST',
url:YohoConfig.mainUrl + that.options.publishUrl,
data: data,
dataType:'json',
success:function(response) {
if (response.code === '800000')
else
{
box.alert(tips.getTips("relogin"), 5);
that.$element.login("setLogout");
return false;
box.alert(tips.getTips("systemBus"), 5);
}
if (response.status && response.data) {
var $commentsList = $(".comments-list");
var commentItem = '<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+response.data.headpic+'" alt="">'+
'<i class="'+response.data.partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+response.data.nick+'</h6>'+
'<p class="comment-text">'+response.data.content+'</p>'+
'<a class="delete-comment" href="javascript:;" pid="'+response.data.id+'"></a>'+
'</div>'+
'</li>';
if(that.options.isFeedback && $(".login-status .anonymous").css("display") != "none"){
commentItem = '<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+response.data.headpic+'" alt="">'+
'<i class="'+response.data.partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+response.data.nick+'</h6>'+
'<p class="comment-text">'+response.data.content+'</p>'+
'</div>'+
'</li>';
}
if($commentsList .find("li").size()==0){
$commentsList .html(commentItem);
}else{
$commentsList .find("li").eq(0).before(commentItem);
}
if(that.options.isFeedback){
box.alert(tips.getTips("publishFeedback"), 5);
}else if(that.options.isEdit){
box.alert(tips.getTips("editPublishSuccess"), 5);
}else{
box.alert(tips.getTips("publishSuccess"), 5);
}
$(".comment-textarea textarea").val('');
var comments = 1;
if(!!parseInt(that.options.commentNum.eq(0).text())){
comments = parseInt(that.options.commentNum.eq(0).text())+1;
};
that.options.commentNum.text(comments);
}
else if(900000 == response.code){
box.alert(tips.getTips("notSameContent"), 5);
}
else
{
box.alert(tips.getTips("systemBus"), 5);
}
}
}); */
});
}
}); */
});
//评论翻页
this.$element.on("click.commentPage",".pager-item",function(){
var url = $(this).attr("href"),
this.$element.on("click.commentPage", ".pager-item", function() {
var url = $(this).attr("href"),
pageHtml,
pageIcon,
commentListTop;
$.ajax({
type: 'GET',
$.ajax({
type: 'GET',
url: url,
success: function(response) {
$(".comments-list").empty();
pageHtml = mustache.render(that.options.commentItemTpl, response.data.comment);
$(".comments-list").empty();
pageHtml = mustache.render(that.options.commentItemTpl, response.data.comment);
$(".comments-list").html(pageHtml);
pageIcon = $('<div class="channel-index-pager">'+response.data.page+'</div>');
$(".comment-pager-content").html(pageIcon);
pageIcon = $('<div class="channel-index-pager">' + response.data.page + '</div>');
$(".comment-pager-content").html(pageIcon);
commentListTop = $(".comments-list").offset().top - $("#minEnterprise").outerHeight();
$(window).scrollTop(commentListTop);
commentListTop = $(".comments-list").offset().top - $("#minEnterprise").outerHeight();
$(window).scrollTop(commentListTop);
}
});
});
return false;
return false;
});
//删除评论
this.$element.on("click.deleteComment", ".delete-comment", function() {
var _this = $(this);
var id = _this.attr('pid');
var deleteTip = tips.getTips("deleteComment");
if (that.options.isFeedback) {
deleteTip = tips.getTips("deleteFeedback");
} else if (that.options.isEdit) {
deleteTip = tips.getTips("deleteEdit");
}
box.confirm(deleteTip, function() {
$.ajax({
type: 'POST',
url: YohoConfig.mainUrl + that.options.deleteUrl,
data: 'id=' + id,
dataType: 'json',
success: function(response) {
if (response.status) {
_this.parents("li").remove();
var comments = parseInt($(".comment-num").eq(0).text()) - 1;
if (comments > 0) {
that.options.commentNum.text(comments);
} else {
that.options.commentNum.html('<img src="' + YohoConfig.resUrl + 'boysweb/assets/images/mobile/comment-mobile.png">');
$(".comment-num.zero").text(0);
$(".comment-num.edit-comment").text('留言');
}
}
}
});
});
});
//删除评论
this.$element.on("click.deleteComment",".delete-comment",function(){
var _this = $(this);
var id = _this.attr('pid');
var deleteTip = tips.getTips("deleteComment");
if(that.options.isFeedback){
deleteTip = tips.getTips("deleteFeedback");
}else if(that.options.isEdit){
deleteTip = tips.getTips("deleteEdit");
}
box.confirm(deleteTip, function()
{
$.ajax
({
type:'POST',
url:YohoConfig.mainUrl+that.options.deleteUrl,
data:'id='+id,
dataType:'json',
success:function(response)
{
if (response.status)
{
_this.parents("li").remove();
var comments = parseInt($(".comment-num").eq(0).text())-1;
if(comments > 0){
that.options.commentNum.text(comments);
}else{
that.options.commentNum.html('<img src="'+YohoConfig.resUrl+'boysweb/assets/images/mobile/comment-mobile.png">');
$(".comment-num.zero").text(0);
$(".comment-num.edit-comment").text('留言');
}
}
}
});
});
});
$(".third-login-box").on("click","a",function(){
var _this = $(this);
$(".third-login-box").on("click", "a", function() {
var _this = $(this);
if (!_this.attr('ref')) return;
window.open(_this.attr('ref'), "","width=760,height=650,top=300,left=300");
window.open(_this.attr('ref'), "", "width=760,height=650,top=300,left=300");
return false;
})
$(".third-login-box").on("click","a.yoho",function(){
$(this).login("loginBoxAnimate");
})
},
publishComment:function(){
var textareaVal = $(".comment-textarea").find("textarea").val();
if (!!!textareaVal || $.trim(textareaVal) === '') return;
if(this.options.isFeedback) return;
$(".publish-btn").trigger("click.publish");
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.Comment');
var options = $.extend({}, Comment.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.Comment', (data = new Comment(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.comment = Plugin;
$.fn.comment.Constructor = Comment;
})
$(".third-login-box").on("click", "a.yoho", function() {
$(this).login("loginBoxAnimate");
})
},
publishComment: function() {
var textareaVal = $(".comment-textarea").find("textarea").val();
if (!!!textareaVal || $.trim(textareaVal) === '') return;
if (this.options.isFeedback) return;
$(".publish-btn").trigger("click.publish");
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.Comment');
var options = $.extend({}, Comment.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.Comment', (data = new Comment(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.comment = Plugin;
$.fn.comment.Constructor = Comment;
})(this);
\ No newline at end of file
... ...
... ... @@ -4,37 +4,38 @@
* @date 2014-07-22
*/
var $ = require("jquery");
require("yoho-rotate2d");
require("jquery.rotate2d");
var height;
var scrollTop;
var windowHeight=$(window).height();
var delay,returnDelay,isPlaying=false;
var windowHeight = $(window).height();
var delay, returnDelay, isPlaying = false;
//翻转当前对象动画
function RevolvePic(target){
function RevolvePic(target) {
//延时对象
var timeHandler1,timeHandler2,timeHandler3,timeHandler4;
var Y = target.offset().top;
height=target.height();
var timeHandler1, timeHandler2, timeHandler3, timeHandler4;
var Y = target.offset().top;
height = target.height();
//分别判断图片小于屏幕和大于屏幕的情况
var last=target.find("a[pic='last']");//第二章图片对象
last.bind("webkitAnimationEnd",function(){
isPlaying=false;
var last = target.find("a[pic='last']"); //第二章图片对象
last.bind("webkitAnimationEnd", function() {
isPlaying = false;
});
//当图片高度小于屏幕高度:滚动高度+屏幕高度>=图片顶端位置+图片高度的三分之二(当三分之二的图片进入屏幕范围即可开始旋转),滚动高度<空间顶端位置+控件高度的三分之二(说明向上滚动)
if ((scrollTop+windowHeight>=Y+height/3*2&&scrollTop<Y+height/3*2)//图片小于屏幕
if ((scrollTop + windowHeight >= Y + height / 3 * 2 && scrollTop < Y + height / 3 * 2) //图片小于屏幕
||
//当图片高度大于屏幕时分别判断:图片顶端位置+图片高度<=滚动高度+屏幕高度(说明图片已经滚动到底)以及 图片顶端位置-50<=滚动高度(说明图片顶端接近屏幕顶端)
//以上两种判断分别对应:向上滚动、向下滚动
(height>=windowHeight&&Y-50<=scrollTop)||(height>=windowHeight&&Y+height<=scrollTop+windowHeight)) {//当图片大于屏幕时执行
//当图片高度大于屏幕时分别判断:图片顶端位置+图片高度<=滚动高度+屏幕高度(说明图片已经滚动到底)以及 图片顶端位置-50<=滚动高度(说明图片顶端接近屏幕顶端)
//以上两种判断分别对应:向上滚动、向下滚动
(height >= windowHeight && Y - 50 <= scrollTop) || (height >= windowHeight && Y + height <= scrollTop + windowHeight)) { //当图片大于屏幕时执行
isStayLong = true; //用户在该显示区域已经停留了足够长的时间,1S
isStayLong=true;//用户在该显示区域已经停留了足够长的时间,1S
//判断是否已经增加过了旋转样式,如果没有增加就追加
if (target.attr("RevolvePic")==undefined) {
var eleBack = null, eleFront = null,
// 两张被翻转的图片元素
eleList = target.find(".img");
if (target.attr("RevolvePic") == undefined) {
var eleBack = null,
eleFront = null,
// 两张被翻转的图片元素
eleList = target.find(".img");
// 确定前面与后面元素
var funBackOrFront = function() {
eleList.each(function() {
... ... @@ -46,108 +47,104 @@ function RevolvePic(target){
});
};
window.setTimeout(function(){
//根据动画播放完毕的回调事件判断动画播放不会重叠
window.setTimeout(function() {
//根据动画播放完毕的回调事件判断动画播放不会重叠
if (!isPlaying) {
isPlaying=true;
isPlaying = true;
funBackOrFront();
timeHandler1=window.setTimeout(function(){
timeHandler1 = window.setTimeout(function() {
eleFront.addClass("out").removeClass("in");
timeHandler2=setTimeout(function() {
timeHandler2 = setTimeout(function() {
eleBack.addClass("in").removeClass("out");
// 重新确定正反元素
funBackOrFront();
},155);
},delay-1000);
timeHandler3=window.setTimeout(function(){
}, 155);
}, delay - 1000);
timeHandler3 = window.setTimeout(function() {
eleFront.addClass("out").removeClass("in");
timeHandler4=setTimeout(function() {
timeHandler4 = setTimeout(function() {
eleBack.addClass("in").removeClass("out");
// 重新确定正反元素
funBackOrFront();
target.find(".imga:first").removeClass("out").removeClass("in");
target.find(".imga:last").addClass("out");
},155);
},delay+returnDelay-1000);
target.attr("RevolvePic","RevolvePic");
}, 155);
}, delay + returnDelay - 1000);
target.attr("RevolvePic", "RevolvePic");
}
},1000);
}, 1000);
}
}
else
{
//页面被拉动到其他区域后
isStayLong=false;
//移出当前区域后解除对target对象的标记
if (target.attr("RevolvePic")!=undefined) {
target.removeAttr("RevolvePic");
}
//清除四个定时器
window.clearTimeout(timeHandler1);
window.clearTimeout(timeHandler2);
window.clearTimeout(timeHandler3);
window.clearTimeout(timeHandler4);
} else {
//页面被拉动到其他区域后
isStayLong = false;
//移出当前区域后解除对target对象的标记
if (target.attr("RevolvePic") != undefined) {
target.removeAttr("RevolvePic");
}
//清除四个定时器
window.clearTimeout(timeHandler1);
window.clearTimeout(timeHandler2);
window.clearTimeout(timeHandler3);
window.clearTimeout(timeHandler4);
}
}
exports.init=function(info){
exports.init = function(info) {
/**
* target:被翻转图片的父级DIV元素
* height:图片高度
* delay:从静止到开始动画的等待时间
* returnDelay:从第二幅图片翻转至第一幅图片的等待时间
*/
var defaults={
operate:"auto",//auto:进入显示区域自动翻转;mouse:鼠标hover翻转一次,鼠标离开再次翻转
delay:2000,
returnDelay:2000,
* target:被翻转图片的父级DIV元素
* height:图片高度
* delay:从静止到开始动画的等待时间
* returnDelay:从第二幅图片翻转至第一幅图片的等待时间
*/
var defaults = {
operate: "auto", //auto:进入显示区域自动翻转;mouse:鼠标hover翻转一次,鼠标离开再次翻转
delay: 2000,
returnDelay: 2000,
wrapClass: '.lifestyle-flip'
}
var opts = $.extend(defaults, info);
var targets=null;
targets=$(opts.wrapClass);
height=opts.height ;
delay=opts.delay;
returnDelay=opts.returnDelay;
//当前滚动条的位置
scrollTop=$(document).scrollTop();
//是否单次播放完毕
var isPlaying=false;
var isStayLong=false;
if(opts.operate=="auto")
{
//获取到前后面的图片
targets.each(function(index,obj){
RevolvePic($(obj));
});
$(window).scroll(function(){
scrollTop=$(document).scrollTop();
targets.each(function(index,obj){
RevolvePic($(obj));
});
});
}
else if(opts.operate=="mouse")
{
var eleBack = null, eleFront = null;
// 确定前面与后面元素
var funBackOrFront = function(tmpobj) {
eleList = tmpobj.find(".img");
eleList.each(function() {
if ($(this).hasClass("out")) {
eleBack = $(this);
} else {
eleFront = $(this);
}
var targets = null;
targets = $(opts.wrapClass);
height = opts.height;
delay = opts.delay;
returnDelay = opts.returnDelay;
//当前滚动条的位置
scrollTop = $(document).scrollTop();
//是否单次播放完毕
var isPlaying = false;
var isStayLong = false;
if (opts.operate == "auto") {
//获取到前后面的图片
targets.each(function(index, obj) {
RevolvePic($(obj));
});
};
targets.each(function(index,obj){
$(obj).dbRotate2D();
});
}
$(window).scroll(function() {
scrollTop = $(document).scrollTop();
targets.each(function(index, obj) {
RevolvePic($(obj));
});
});
} else if (opts.operate == "mouse") {
var eleBack = null,
eleFront = null;
// 确定前面与后面元素
var funBackOrFront = function(tmpobj) {
eleList = tmpobj.find(".img");
eleList.each(function() {
if ($(this).hasClass("out")) {
eleBack = $(this);
} else {
eleFront = $(this);
}
});
};
targets.each(function(index, obj) {
$(obj).dbRotate2D();
});
}
};
\ No newline at end of file
... ...
var $=require("jquery");
var $ = require("jquery");
require('./lazyloadImage');
;
(function(global, undefined) {
var ImgSlider = function(element, options) {
this.options = options;
this.$wrap = $(element);
this.$element = $(element).find("ul");
this.$lis = this.$element.find("li");
this.$ctrl = $(this.options.slideCtrl).appendTo(this.$wrap);
this.$btnPrev = this.$ctrl.find('.slide-ctrl-prev');//上一张按钮
this.$btnNext = this.$ctrl.find('.slide-ctrl-next');//下一张按钮
this.len = this.$lis.length;
this.width = this.$lis.width() + parseInt(this.$lis.css("margin-right"));
this.index = 1;
this.page = 1;
this.init();
};
ImgSlider.DEFAULTS = {
slideCtrl:'<div class="slide-ctrl"><a class="slide-ctrl-prev" href="javascript:;"></a><a class="slide-ctrl-next" href="javascript:;"></a></div>',
pageNum :4,
itemClass:''
};
ImgSlider.prototype = {
constructor: ImgSlider,
init:function(){
var _this = this;
if(this.len<=4) return;
this._calculationWidth(this.len,this.width);
this.$btnPrev.hide();
// 绑定事件
this._bindEvent();
},
/*
* next
*/
next:function(){
this.$btnPrev.show();
this.index ++;
var ImgSlider = function(element, options) {
this.options = options;
this.$wrap = $(element);
this.$element = $(element).find("ul");
this.$lis = this.$element.find("li");
this.$ctrl = $(this.options.slideCtrl).appendTo(this.$wrap);
this.$btnPrev = this.$ctrl.find('.slide-ctrl-prev'); //上一张按钮
this.$btnNext = this.$ctrl.find('.slide-ctrl-next'); //下一张按钮
this.len = this.$lis.length;
this.width = this.$lis.width() + parseInt(this.$lis.css("margin-right"));
this.index = 1;
this.page = 1;
this.init();
};
ImgSlider.DEFAULTS = {
slideCtrl: '<div class="slide-ctrl"><a class="slide-ctrl-prev" href="javascript:;"></a><a class="slide-ctrl-next" href="javascript:;"></a></div>',
pageNum: 4,
itemClass: ''
};
ImgSlider.prototype = {
constructor: ImgSlider,
init: function() {
var _this = this;
if (this.len <= 4) return;
this._calculationWidth(this.len, this.width);
this.$btnPrev.hide();
// 绑定事件
this._bindEvent();
},
/*
* next
*/
next: function() {
this.$btnPrev.show();
this.index++;
this._animate(-this.width);
},
/*
* prev
*/
prev:function(){
this.$btnNext.show();
this.index --;
},
/*
* prev
*/
prev: function() {
this.$btnNext.show();
this.index--;
this._animate(this.width);
},
/*
* 添加节点
*/
_addDom:function(){
var _this = this;
if(!this.$element.data("url")) return;
$.ajax({
type:'GET',
url:YohoConfig.mainUrl+_this.$element.data("url")+_this.page,
dataType:'json',
success:function(data){
var item = '',
msg = data.data,
len = msg.length;
for(var i=0;i<len;i++){
item += '<li class="'+_this.options.itemClass+'"><a href="javascript:;"><img src="" data-slide="'+msg[i].pics+'" data-original="'+msg[i].cover+'" data-imgzoom="'+msg[i].dynamic+'"/><span>'+msg[i].title+'</span></a></li>'
}
$(item).appendTo(_this.$element);
//添加节点后重新计算宽度
if(_this.options.itemClass != ''){
_this.len = _this.$element.find("li."+_this.options.itemClass).length;
}else{
_this.len = _this.$element.find("li").length;
}
_this._calculationWidth(_this.len,_this.width);
_this.page++;
},
/*
* 添加节点
*/
_addDom: function() {
var _this = this;
if (!this.$element.data("url")) return;
$.ajax({
type: 'GET',
url: YohoConfig.mainUrl + _this.$element.data("url") + _this.page,
dataType: 'json',
success: function(data) {
var item = '',
msg = data.data,
len = msg.length;
for (var i = 0; i < len; i++) {
item += '<li class="' + _this.options.itemClass + '"><a href="javascript:;"><img src="" data-slide="' + msg[i].pics + '" data-original="' + msg[i].cover + '" data-imgzoom="' + msg[i].dynamic + '"/><span>' + msg[i].title + '</span></a></li>'
}
$(item).appendTo(_this.$element);
//添加节点后重新计算宽度
if (_this.options.itemClass != '') {
_this.len = _this.$element.find("li." + _this.options.itemClass).length;
} else {
_this.len = _this.$element.find("li").length;
}
_this._calculationWidth(_this.len, _this.width);
_this.page++;
}
});
},
/*
});
},
/*
* 插件事件绑定
*/
_bindEvent: function(){
var _this = this;
this.$btnNext.on("click",function(){
if (_this.$element.is(':animated')) return;
_this.next();
_this.$element.find("img").lazyload();
if (_this.index == _this.len-_this.options.pageNum+1) {
$(this).hide();
};
if((Math.ceil(_this.index/_this.options.pageNum))%3 == 0 && (Math.ceil((_this.index-1)/_this.options.pageNum))%3 != 0){
_this._addDom();
}
});
this.$btnPrev.on("click",function(){
if (_this.$element.is(':animated')) return;
_this.prev();
if (_this.index == 1) {
$(this).hide();
};
});
},
/*
* 动画
*/
_animate: function(offset) {
var left = parseInt(this.$element.css('left')) + offset;
var _this = this;
if (offset>0) {
*/
_bindEvent: function() {
var _this = this;
this.$btnNext.on("click", function() {
if (_this.$element.is(':animated')) return;
_this.next();
_this.$element.find("img").lazyload();
if (_this.index == _this.len - _this.options.pageNum + 1) {
$(this).hide();
};
if ((Math.ceil(_this.index / _this.options.pageNum)) % 3 == 0 && (Math.ceil((_this.index - 1) / _this.options.pageNum)) % 3 != 0) {
_this._addDom();
}
});
this.$btnPrev.on("click", function() {
if (_this.$element.is(':animated')) return;
_this.prev();
if (_this.index == 1) {
$(this).hide();
};
});
},
/*
* 动画
*/
_animate: function(offset) {
var left = parseInt(this.$element.css('left')) + offset;
var _this = this;
if (offset > 0) {
offset = '+=' + offset;
}
else {
} else {
offset = '-=' + Math.abs(offset);
}
this.$element.stop().animate({'left': offset}, 300);
},
//计算宽度
_calculationWidth: function(len,width){
this.$element.width(len*width);
},
//resize
resize:function(){
this.width = this.$lis.width() + parseInt(this.$lis.css("margin-right"));
if(this.options.itemClass != ''){
this.len = this.$element.find("li."+this.options.itemClass).length;
}else{
this.len = this.$element.find("li").length;
}
this._calculationWidth(this.len,this.width);
this.$element.css({'left': -(this.index-1)*this.width});
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.ImgSlider');
var options = $.extend({}, ImgSlider.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.ImgSlider', (data = new ImgSlider(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.imgSlider = Plugin;
$.fn.imgSlider.Constructor = ImgSlider;
})($);
this.$element.stop().animate({
'left': offset
}, 300);
},
//计算宽度
_calculationWidth: function(len, width) {
this.$element.width(len * width);
},
//resize
resize: function() {
this.width = this.$lis.width() + parseInt(this.$lis.css("margin-right"));
if (this.options.itemClass != '') {
this.len = this.$element.find("li." + this.options.itemClass).length;
} else {
this.len = this.$element.find("li").length;
}
this._calculationWidth(this.len, this.width);
this.$element.css({
'left': -(this.index - 1) * this.width
});
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.ImgSlider');
var options = $.extend({}, ImgSlider.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.ImgSlider', (data = new ImgSlider(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.imgSlider = Plugin;
$.fn.imgSlider.Constructor = ImgSlider;
})($);
\ No newline at end of file
... ...
var $=require("jquery");
/*
* 图片放大轮播插件
* author:liuyue
* date:2015-04-23
*/
var $ = require("jquery");
+function($){
'use strict';
function ImgZoom(element,options){
;
(function(global, undefined) {
var ImgZoom = function(element, options) {
this.$element = $(element);
if(!options){
this.options = this.getDefaults();
}else{
this.options = $.extend(true,this.getDefaults(),options);
}
this.options = options;
this.$tpl = ''; //大图存放模板
this.$overlay = ''; //黑色透明背景
this.$zoomBox = ''; //大图最外层包裹
this.imgHeight = 0; //大图高度
this.imgWidth = 0; //大图宽度
this.$btnPrev = ''; //前一张按钮
this.$btnNext = ''; //后一张按钮
this.currentClass = 'currentPhoto'; //当前图片的标识类
this.init();
};
ImgZoom.DEFAULTS = {
isContainFather: false,
overlay: true,
template:'<div class="imgZoom" onselectstart="return false" unselecttable="on">'+
'<img src="" />'+
'<a href="javascript:;" class="close"></a>'+
'<a href="javascript:;" class="guideBtn prev"></a>'+
'<a href="javascript:;" class="guideBtn next"></a>'+
'</div>'+
'<div class="overlay"></div>',
imgSrcAttr:'data-original'
};
ImgZoom.prototype.getDefaults = function () {
return ImgZoom.DEFAULTS
};
//初始化
ImgZoom.prototype.init = function(){
this.overlay = this.options.overlay;
var $template = $('.imgZoom,.overlay');
this.$template = !!$template.size() ? $template : ($(this.options.template).appendTo("body"));//Dom对象
this.$box = this.$template.filter('.imgZoom');//相册对象
this.$overlayObj = this.$template.filter('.overlay');//遮罩对象
this.$btnPrev = this.$template.find('.guideBtn.prev');//上一张按钮
this.$btnNext = this.$template.find('.guideBtn.next');//下一张按钮
this.$btnClose = this.$template.find('.close');//关闭按钮
this.currentObj = 'currentPhoto';//当前图片的标识类
this.event();
if(this.options.isContainFather){
this.$element.find('['+this.options.imgSrcAttr+']').eq(0).trigger('click.imgzoom');
}
originalAttr: 'data-original', //图片原图存放属性
styleClass: '',
isContainer: false //杂志页需求
};
//事件绑定集合
ImgZoom.prototype.event = function(){
var _this = this;
this.btnClick();
this.photoClick();
this.$overlayObj.on('click',function(){
_this.close();
});
};
//左右按钮点击事件
ImgZoom.prototype.btnClick = function(){
var _this = this;
this.$btnPrev.off('click');
this.$btnNext.off('click');
this.$btnPrev.on("click",function(){
var that = _this.$template.data('target');
that.photoSwitch(that.$element.find('['+_this.options.imgSrcAttr+']').index(that.$element.find("."+that.currentObj)),"left");
});
this.$btnNext.on("click",function(){
var that = _this.$template.data('target');
that.photoSwitch(that.$element.find('['+_this.options.imgSrcAttr+']').index(that.$element.find("."+that.currentObj)),"right");
//console.log(_this.$element);
});
};
//图片点击事件
ImgZoom.prototype.photoClick = function(){
var _this = this;
this.$element.on("click.imgzoom",'['+_this.options.imgSrcAttr+']',function(){
_this.$element.find("."+_this.currentObj).removeClass(_this.currentObj);
$(this).addClass(_this.currentObj);
_this.$template.data('target', _this);
_this.photoEfficiency();
});
};
//图片左右切换事件
ImgZoom.prototype.photoSwitch = function(index,direction){
this.$element.find("."+this.currentObj).removeClass(this.currentObj);
if(direction=="left"){
var _index = index - 1;
}else{
var _index = index + 1;
}
this.$element.find("["+this.options.imgSrcAttr+"]:eq("+_index+")").addClass(this.currentObj);
this.photoEfficiency();
};
//检测首尾状态
ImgZoom.prototype.getArrowState = function(){
if(this.$element.find('['+this.options.imgSrcAttr+']').index(this.$element.find("."+this.currentObj))==0){
this.$btnPrev.hide();
}else{
this.$btnPrev.show();
}
if(this.$element.find('['+this.options.imgSrcAttr+']').index(this.$element.find("."+this.currentObj))==this.$element.find('['+this.options.imgSrcAttr+']').size()-1){
this.$btnNext.hide();
}else{
this.$btnNext.show();
}
};
//图片显示效果
ImgZoom.prototype.photoEfficiency = function(){
var _this = this;
var hiddenImg = $('<img src="'+_this.$element.find("."+this.currentObj).attr(this.options.imgSrcAttr)+'">').appendTo("body").css({"position":"fixed",'left':'-9999px','top':'-9999px'});
this.loadImg(hiddenImg.attr("src"), function(){
_this.$box.find("img").remove().end().prepend(hiddenImg.removeAttr("style"));
ImgZoom.prototype = {
init: function() {
this._create();
if(!_this.$box.hasClass("show")){
_this.open();
this._bindEvent();
if (this.options.isContainer) {
this.$element.find('[' + this.options.originalAttr + ']').eq(0).trigger('click.imgzoom');
}
if(!_this.$box.hasClass("complete")){
_this.$box.addClass("complete")
}
_this.$box.css("margin-top",-_this.$box.outerHeight()/2);
_this.$box.css("margin-left",-_this.$box.outerWidth()/2);
})
_this.getArrowState();
};
ImgZoom.prototype.loadImg = function(src, callback){
var img = new Image();
if($.browser.msie){
obj.onreadystatechange=function(){
if(this.readyState=="complete"){
callback.call(img);//将回调函数的this替换为Image对象
img = null;
}
},
/*
* 创建大图模板
*/
_create: function() {
if ($('.img-zoom').size() <= 0) {
this.$tpl = $('<div class="img-zoom ' + this.options.styleClass + '" onselectstart="return false" unselecttable="on">' +
'<img src="" />' +
'<a href="javascript:;" class="close"></a>' +
'<a href="javascript:;" class="guide-btn prev"></a>' +
'<a href="javascript:;" class="guide-btn next"></a>' +
'</div>' +
'<div class="overlay"></div>');
$('body').append(this.$tpl);
}
}else{
img.onload = function () { //图片下载完毕时异步调用callback函数。
callback.call(img);//将回调函数的this替换为Image对象
img = null;
};
}
img.src = src;
};
this.$overlay = $('.overlay');
this.$zoomBox = $('.img-zoom');
this.$btnPrev = $('.guide-btn.prev');
this.$btnNext = $('.guide-btn.next');
},
//打开事件
ImgZoom.prototype.open = function(){
this.$box.addClass("show");
if(this.options.overlay){
this.$overlayObj.fadeIn(100);
}
};
//关闭事件
ImgZoom.prototype.close = function(){
this.$box.removeClass("show complete");
if(this.options.overlay){
this.$overlayObj.fadeOut(100);
}
};
//组件封装处理
function Plugin(option,object){
this.each(function(){
var $this = $(this),
data = $this.data('hc.ImgZoom'),
options = typeof option == 'object' && option;
if(!data){
$this.data('hc.ImgZoom',(data = new ImgZoom($this,options)));
/*
* 事件绑定
*/
_bindEvent: function() {
var that = this;
//图片点击事件
this.$element.on('click.imgzoom', '[' + this.options.originalAttr + ']', function() {
that.$element.find("." + that.currentClass).removeClass(that.currentClass);
$(this).addClass(that.currentClass);
that._photoEfficiency($(this));
});
//点击zoom外部隐藏zoom及overlay
this.$overlay.on('click', function() {
that._zoomHide();
});
this.$btnPrev.off('click');
this.$btnNext.off('click');
this.$btnPrev.on('click', function() {
that._photoSwitch(that.$element.find('[' + that.options.originalAttr + ']').index(that.$element.find("." + that.currentClass)), "left");
});
this.$btnNext.on("click", function() {
that._photoSwitch(that.$element.find('[' + that.options.originalAttr + ']').index(that.$element.find("." + that.currentClass)), "right");
});
},
/*
* 图片显示效果
*/
_photoEfficiency: function(data) {
var that = this,
hiddenImg = $('<img src="' + this.$element.find("." + this.currentClass).attr(this.options.originalAttr) + '">');
this._loadImg(hiddenImg.attr('src'), function() {
that.$zoomBox.find('img').attr('src', hiddenImg.attr('src'));
that.imgHeight = that.$zoomBox.find('img').outerHeight();
that.imgWidth = that.$zoomBox.find('img').outerWidth();
that.$zoomBox.css({
"marginTop": -that.imgHeight / 2
})
});
//图片显示
this._zoomShow();
//检测首尾状态
this._getArrowState();
},
/*
* zoom及overlay显示
*/
_zoomShow: function() {
this.$overlay.addClass("show");
this.$zoomBox.addClass("show");
},
/*
* zoom及overlay隐藏
*/
_zoomHide: function() {
this.$overlay.removeClass("show");
this.$zoomBox.removeClass("show");
},
/*
* 检测首尾状态
*/
_getArrowState: function() {
if (this.$element.find('[' + this.options.originalAttr + ']').index(this.$element.find("." + this.currentClass)) == 0) {
this.$btnPrev.hide();
} else {
this.$btnPrev.show();
}
if(typeof option =='string'){
data[option](object);
if (this.$element.find('[' + this.options.originalAttr + ']').index(this.$element.find("." + this.currentClass)) == this.$element.find('[' + this.options.originalAttr + ']').size() - 1) {
this.$btnNext.hide();
} else {
this.$btnNext.show();
}
return $this;
},
/*
* 图片左右切换
* @param: index为当前图片索引,direction为切换方向
*/
_photoSwitch: function(index, direction) {
var _index;
this.$element.find('.' + this.currentClass).removeClass(this.currentClass);
if (direction === 'left') {
_index = index - 1;
} else {
_index = index + 1;
}
console.log(_index);
this.$element.find('[' + this.options.originalAttr + ']:eq(' + _index + ')').addClass(this.currentClass);
this._photoEfficiency();
},
/*
* 图片load
* @param: src为要load的图片src
*/
_loadImg: function(src, callback) {
var img = new Image();
if ($.browser.msie) {
obj.onreadystatechange = function() {
if (this.readyState == "complete") {
callback.call(img); //将回调函数的this替换为Image对象
img = null;
}
}
} else {
img.onload = function() { //图片下载完毕时异步调用callback函数。
callback.call(img); //将回调函数的this替换为Image对象
img = null;
};
}
img.src = src;
}
}
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.imgZoom');
var options = $.extend({}, ImgZoom.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.imgZoom', (data = new ImgZoom(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
var old = $.fn.ImgZoom;
$.fn.ImgZoom = Plugin;
$.fn.ImgZoom.Constructor = ImgZoom;
$.fn.ImgZoom.noConflict = function () {
$.fn.ImgZoom = old;
return this;
};
}($);
$.fn.imgZoom = Plugin;
$.fn.imgZoom.Constructor = ImgZoom;
})(this);
\ No newline at end of file
... ...
/**
* @package plugin/photoslide.js
* @author:ww(wei.wang@yoho.cn)
* @date:2014-08-19
*/
var $=require("jquery");
var $ = require("jquery");
require("lazyload");
var tmpInfo=null;
window.onresize=function(){
if (tmpInfo!=null) {
var tmpInfo = null;
window.onresize = function() {
if (tmpInfo != null) {
exports.initSlide(tmpInfo);
}
}
exports.initSlide=function(info){
tmpInfo=info;
var defaults={
isMobile:false,
mobileStartDrage:window.photoSlide_StartDrage||function(){},
mobileEndDrage:function(){},
isAndroid:false //是否为安卓客户端程序
exports.initSlide = function(info) {
tmpInfo = info;
var defaults = {
isMobile: false,
mobileStartDrage: window.photoSlide_StartDrage || function() {},
mobileEndDrage: function() {},
isAndroid: false //是否为安卓客户端程序
}
var opts=$.extend(defaults,info);
var isMobile=opts.isMobile;
var photos=$(".photoslider_moused_over");
if(photos.length>0)
{
var maxWidth={},maxHeight={};
var brow=getBrowType();
photos.each(function(index,obj){
var opts = $.extend(defaults, info);
var isMobile = opts.isMobile;
var photos = $(".photoslider_moused_over");
if (photos.length > 0) {
var maxWidth = {},
maxHeight = {};
var brow = getBrowType();
photos.each(function(index, obj) {
//alert(index);
var tmpId="photoslider_moused_over_"+index;
$(obj).attr("id",tmpId);
var imgs={};
$(obj).find(".photoslider_right_image").find("img:first").css({"max-width":"100%"}).imagesLoaded(function(){
imgs[tmpId]=$(this).attr("src");
maxWidth[tmpId]=$(this).width();
maxHeight[tmpId]=$(this).height();
var tmpId = "photoslider_moused_over_" + index;
$(obj).attr("id", tmpId);
var imgs = {};
$(obj).find(".photoslider_right_image").find("img:first").css({
"max-width": "100%"
}).imagesLoaded(function() {
imgs[tmpId] = $(this).attr("src");
maxWidth[tmpId] = $(this).width();
maxHeight[tmpId] = $(this).height();
$(obj).find(".photoslider_left_image img").css({
"max-width":maxWidth[tmpId],
"max-height":maxHeight[tmpId],
"min-width":maxWidth[tmpId],
"min-height":maxHeight[tmpId],
"width":maxWidth[tmpId],
"height":maxHeight[tmpId]
"max-width": maxWidth[tmpId],
"max-height": maxHeight[tmpId],
"min-width": maxWidth[tmpId],
"min-height": maxHeight[tmpId],
"width": maxWidth[tmpId],
"height": maxHeight[tmpId]
}).show();
$(".photoslider_drag_message")
.html("← SLIDE →")
.show();
.html("← SLIDE →")
.show();
var u = navigator.userAgent;
if(isMobile&&$(obj).find(".drageObject")[0]==null||brow.bIsIpad||brow.bIsAndroid)
{
$("<div/>").css({
position:"absolute",
height:maxHeight[tmpId]*0.2,
width:maxWidth[tmpId],
top:0,
left:0,
"z-index":100
}).attr("noslider","yes").appendTo(obj);
$("<div/>").css({
position:"absolute",
height:maxHeight[tmpId]*0.3,
width:maxWidth[tmpId],
bottom:0,
left:0,
"z-index":100
if (isMobile && $(obj).find(".drageObject")[0] == null || brow.bIsIpad || brow.bIsAndroid) {
$("<div/>").css({
position: "absolute",
height: maxHeight[tmpId] * 0.2,
width: maxWidth[tmpId],
top: 0,
left: 0,
"z-index": 100
}).attr("noslider", "yes").appendTo(obj);
$("<div/>").css({
position: "absolute",
height: maxHeight[tmpId] * 0.3,
width: maxWidth[tmpId],
bottom: 0,
left: 0,
"z-index": 100
//background:"#f00"
}).attr("noslider","yes").appendTo(obj);
var drageObject=$("<div/>").attr("class","drageObject").css({
width:20,
height:"100%",
margin:"0 0 0 -10px",
top:0,
left:"50%",
//background:"#f00",
position:"absolute",
"z-index":9999
}).appendTo(obj);
drageObject.bind({
"touchstart":function(){
$(this).parent().find(".photoslider_drag_message").fadeOut();
//opts.mobileStartDrage();
if(opts.isAndroid===true)
{
try{
window.yohoboy.clickOnAndroid(true);
}catch(e){}
}
},
"touchmove":function(event){
var pointX = event.originalEvent.changedTouches[0].pageX;
var left=$(this).parent().offset().left;
var mouseX=pointX-left;
if(mouseX<$(this).parent().parent().width()&&mouseX>0)
{
$(this).parent().find(".photoslider_left_image").width(mouseX);
$(this).css({left:mouseX});
//return false;
}
return false;
},
"touchend":function(){
if(opts.isAndroid===true)
{
try{
window.yohoboy.clickOnAndroid(false);
}catch(e){}
}
}).attr("noslider", "yes").appendTo(obj);
var drageObject = $("<div/>").attr("class", "drageObject").css({
width: 20,
height: "100%",
margin: "0 0 0 -10px",
top: 0,
left: "50%",
//background:"#f00",
position: "absolute",
"z-index": 9999
}).appendTo(obj);
drageObject.bind({
"touchstart": function() {
$(this).parent().find(".photoslider_drag_message").fadeOut();
//opts.mobileStartDrage();
if (opts.isAndroid === true) {
try {
window.yohoboy.clickOnAndroid(true);
} catch (e) {}
}
},
"touchmove": function(event) {
var pointX = event.originalEvent.changedTouches[0].pageX;
var left = $(this).parent().offset().left;
var mouseX = pointX - left;
if (mouseX < $(this).parent().parent().width() && mouseX > 0) {
$(this).parent().find(".photoslider_left_image").width(mouseX);
$(this).css({
left: mouseX
});
//return false;
}
return false;
},
"touchend": function() {
if (opts.isAndroid === true) {
try {
window.yohoboy.clickOnAndroid(false);
} catch (e) {}
}
});
var self=this;
}
});
var self = this;
}
});
});
if(isMobile||brow.bIsIpad||brow.bIsAndroid)
{
window.onresize=function(){
if (isMobile || brow.bIsIpad || brow.bIsAndroid) {
window.onresize = function() {
exports.initSlide(info);
//var tmpHtml=$(this).parent().parent().parent().html();
//var tmpHtml=$(this).parent().parent().parent().html();
}
}
}
if(isMobile===false)
if (isMobile === false)
photos.bind({
"mousemove":function(event){
"mousemove": function(event) {
var pointX = event.pageX;
var left=$(this).offset().left;
var mouseX=pointX-left;
if(mouseX<maxWidth[this.id]&&(!isMobile))
{
var left = $(this).offset().left;
var mouseX = pointX - left;
if (mouseX < maxWidth[this.id] && (!isMobile)) {
$(this).find(".photoslider_left_image").width(mouseX);
//$(this).find(".photoslider_drag_message").css({left:mouseX});
}
}
},
"mouseover":function(){
var drag_handler=$(this).find(".photoslider_drag_message");
"mouseover": function() {
var drag_handler = $(this).find(".photoslider_drag_message");
drag_handler.fadeOut();
},
mouseout:function(event){
var x=event.pageX;
if(x-$(this).offset().left>maxWidth[this.id])
{
mouseout: function(event) {
var x = event.pageX;
if (x - $(this).offset().left > maxWidth[this.id]) {
$(this).find(".photoslider_left_image").width(maxWidth[this.id]);
}
else if(x-$(this).offset().left<0){
} else if (x - $(this).offset().left < 0) {
$(this).find(".photoslider_left_image").width(0);
}
}
});
}
}
function getBrowType(){
var info={};
var sUserAgent = navigator.userAgent.toLowerCase();
info.bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
info.bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
info.bIsMidp = sUserAgent.match(/midp/i) == "midp";
info.bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
info.bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
info.bIsAndroid = sUserAgent.match(/android/i) == "android";
info.bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
info.bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
return info;
}
function getBrowType() {
var info = {};
var sUserAgent = navigator.userAgent.toLowerCase();
info.bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
info.bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
info.bIsMidp = sUserAgent.match(/midp/i) == "midp";
info.bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
info.bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
info.bIsAndroid = sUserAgent.match(/android/i) == "android";
info.bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
info.bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
return info;
}
\ No newline at end of file
... ...
... ... @@ -2,187 +2,200 @@
* detail页图片移动插件
* author:liuyue
* date:2015-01-07
*/
var $=require("jquery");
*/
var $ = require("jquery");
require('./lazyloadImage');
;
(function(global, undefined) {
var Slider = function(element, options) {
this.options = options;
this.$element = $(element);
this.$lis = this.$element.children();
this.len = this.$lis.length;
this.timer = null;
this.width = this.$lis.width();
this.index = 0;
this.ctrlIndex = 0;
this.ctrl = this.options.pageCtrl;
this.ctrlEle = this.options.pageCtrl.children();
this.ctrlLen = this.ctrlEle.length;
this.ctrlWidth = this.ctrlEle.width() + parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.ctrlMaxLeft = this.ctrl.width()-this.ctrl.parent().width()-parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.excessWidth = this.ctrlMaxLeft - this.ctrlWidth*(this.ctrlLen -this.options.ctrlShowNum);
var Slider = function(element, options) {
this.options = options;
this.$element = $(element);
this.$lis = this.$element.children();
this.len = this.$lis.length;
this.timer = null;
this.width = this.$lis.width();
this.index = 0;
this.ctrlIndex = 0;
this.ctrl = this.options.pageCtrl;
this.ctrlEle = this.options.pageCtrl.children();
this.ctrlLen = this.ctrlEle.length;
this.ctrlWidth = this.ctrlEle.width() + parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.ctrlMaxLeft = this.ctrl.width() - this.ctrl.parent().width() - parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.excessWidth = this.ctrlMaxLeft - this.ctrlWidth * (this.ctrlLen - this.options.ctrlShowNum);
this.init();
};
};
Slider.DEFAULTS = {
pageCtrl: '',
ctrlShowNum: 6,
prevBtn: $(".detail-slide-ctrl-prev"),
nextBtn: $(".detail-slide-ctrl-next")
};
Slider.DEFAULTS = {
pageCtrl: '',
ctrlShowNum: 6,
prevBtn: $(".detail-slide-ctrl-prev"),
nextBtn: $(".detail-slide-ctrl-next")
};
Slider.prototype = {
init:function(){
Slider.prototype = {
init: function() {
this.ctrlEle.eq(0).addClass("current");
this.setWidth();
if(this.options.autoPlay){
this.play();
}
this.cloneDom();
this.bindEvent();
this.addIndex();
if(this.ctrlLen<=this.options.ctrlShowNum){
this.options.prevBtn.hide();
this.options.nextBtn.hide();
}
},
setWidth:function(){
this.$element.width(this.len*this.width);
this.options.pageCtrl.width(this.ctrlWidth*this.ctrlLen);
this.ctrlMaxLeft = this.ctrl.width()-this.ctrl.parent().width()-parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.excessWidth = this.ctrlMaxLeft - this.ctrlWidth*(this.ctrlLen -this.options.ctrlShowNum);
},
cloneDom:function(){
if(this.$element.children().length > this.len) return;
},
addIndex:function(){
this.options.pageCtrl.children().each(function(i,value){
$(this).attr("index",i);
})
},
bindEvent:function(){
var _this =this;
this.options.pageCtrl.children().on("click",function(){
if (_this.$element.is(':animated') || $(this).attr('class')=='current') {
return;
}
var myIndex = parseInt($(this).attr("index"));
var offset = -_this.width * (myIndex - _this.index);
_this.animate(offset);
clearTimeout(_this.timer);
_this.index = myIndex;
if(_this.options.autoPlay){
_this.play();
}
_this.showButton();
var left = Math.abs(parseInt($(".detail-slide-ctrl-tabs").css("left")));
if($(this).index() == _this.options.ctrlShowNum-1+parseInt(left/_this.ctrlWidth) && left< _this.ctrlMaxLeft){
_this.options.nextBtn.trigger("click.next");
}else if($(this).index() == parseInt(left/_this.ctrlWidth) && left>0){
_this.options.prevBtn.trigger("click.prev");
}
});
this.options.prevBtn.on("click.prev",function(){
if (_this.options.pageCtrl.is(':animated')) {
return;
}
_this.prev();
});
this.options.nextBtn.on("click.next",function(){
if (_this.options.pageCtrl.is(':animated')) {
return;
}
_this.next();
});
},
prev:function(){
var excessWidth = this.excessWidth;
var maxCtrlIndex = this.ctrlLen -this.options.ctrlShowNum;
this.ctrlIndex--;
if(this.ctrlIndex < 0){
this.ctrlIndex = maxCtrlIndex;
this.setWidth();
if (this.options.autoPlay) {
this.play();
}
if(this.ctrlIndex == 0){
this.options.pageCtrl.stop().animate({"left":0});
}else{
this.options.pageCtrl.stop().animate({"left":-this.ctrlWidth*this.ctrlIndex-excessWidth});
}
},
next:function(){
var maxCtrlIndex = this.ctrlLen -this.options.ctrlShowNum;
if(this.ctrlIndex < maxCtrlIndex){
this.ctrlIndex++;
}else{
this.ctrlIndex=0;
this.cloneDom();
this.bindEvent();
this.addIndex();
if (this.ctrlLen <= this.options.ctrlShowNum) {
this.options.prevBtn.hide();
this.options.nextBtn.hide();
}
if(this.ctrlIndex == maxCtrlIndex && this.ctrlMaxLeft>0){
this.options.pageCtrl.stop().animate({"left":-this.ctrlMaxLeft});
}else{
this.options.pageCtrl.stop().animate({"left":-this.ctrlWidth*this.ctrlIndex});
},
setWidth: function() {
this.$element.width(this.len * this.width);
this.options.pageCtrl.width(this.ctrlWidth * this.ctrlLen);
this.ctrlMaxLeft = this.ctrl.width() - this.ctrl.parent().width() - parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.excessWidth = this.ctrlMaxLeft - this.ctrlWidth * (this.ctrlLen - this.options.ctrlShowNum);
},
cloneDom: function() {
if (this.$element.children().length > this.len) return;
},
addIndex: function() {
this.options.pageCtrl.children().each(function(i, value) {
$(this).attr("index", i);
})
},
bindEvent: function() {
var _this = this;
this.options.pageCtrl.children().on("click", function() {
if (_this.$element.is(':animated') || $(this).attr('class') == 'current') {
return;
}
var myIndex = parseInt($(this).attr("index"));
var offset = -_this.width * (myIndex - _this.index);
_this.animate(offset);
clearTimeout(_this.timer);
_this.index = myIndex;
if (_this.options.autoPlay) {
_this.play();
}
_this.showButton();
var left = Math.abs(parseInt($(".detail-slide-ctrl-tabs").css("left")));
if ($(this).index() == _this.options.ctrlShowNum - 1 + parseInt(left / _this.ctrlWidth) && left < _this.ctrlMaxLeft) {
_this.options.nextBtn.trigger("click.next");
} else if ($(this).index() == parseInt(left / _this.ctrlWidth) && left > 0) {
_this.options.prevBtn.trigger("click.prev");
}
});
this.options.prevBtn.on("click.prev", function() {
if (_this.options.pageCtrl.is(':animated')) {
return;
}
_this.prev();
});
this.options.nextBtn.on("click.next", function() {
if (_this.options.pageCtrl.is(':animated')) {
return;
}
_this.next();
});
},
prev: function() {
var excessWidth = this.excessWidth;
var maxCtrlIndex = this.ctrlLen - this.options.ctrlShowNum;
this.ctrlIndex--;
if (this.ctrlIndex < 0) {
this.ctrlIndex = maxCtrlIndex;
}
},
if (this.ctrlIndex == 0) {
this.options.pageCtrl.stop().animate({
"left": 0
});
} else {
this.options.pageCtrl.stop().animate({
"left": -this.ctrlWidth * this.ctrlIndex - excessWidth
});
}
},
next: function() {
var maxCtrlIndex = this.ctrlLen - this.options.ctrlShowNum;
if (this.ctrlIndex < maxCtrlIndex) {
this.ctrlIndex++;
} else {
this.ctrlIndex = 0;
}
if (this.ctrlIndex == maxCtrlIndex && this.ctrlMaxLeft > 0) {
this.options.pageCtrl.stop().animate({
"left": -this.ctrlMaxLeft
});
} else {
this.options.pageCtrl.stop().animate({
"left": -this.ctrlWidth * this.ctrlIndex
});
}
},
showButton: function() {
showButton: function() {
this.options.pageCtrl.children().eq(this.index).addClass('current').siblings().removeClass('current');
},
animate:function(offset){
var left = parseInt(this.$element.css('left')) + offset;
var _this = this;
if (offset>0) {
animate: function(offset) {
var left = parseInt(this.$element.css('left')) + offset;
var _this = this;
if (offset > 0) {
offset = '+=' + offset;
}
else {
} else {
offset = '-=' + Math.abs(offset);
}
this.$element.stop().animate({'left': offset}, 300);
_this.$element.find(".lazy").lazyload();
},
//屏幕改变大小时重新计算
resize:function(){
this.width = this.$lis.width();
this.ctrlWidth = this.ctrlEle.width() + parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.setWidth();
this.$element.css({'left': -this.index*this.width});
if(this.ctrlIndex == 0) return;
this.options.pageCtrl.css({"left":-this.ctrlWidth*this.ctrlIndex-this.excessWidth});
}
}
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.Slider');
var options = $.extend({}, Slider.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.Slider', (data = new Slider(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.slider = Plugin;
$.fn.slider.Constructor = Slider;
this.$element.stop().animate({
'left': offset
}, 300);
_this.$element.find(".lazy").lazyload();
},
//屏幕改变大小时重新计算
resize: function() {
this.width = this.$lis.width();
this.ctrlWidth = this.ctrlEle.width() + parseInt(this.ctrlEle.eq(1).css("marginLeft"));
this.setWidth();
this.$element.css({
'left': -this.index * this.width
});
if (this.ctrlIndex == 0) return;
this.options.pageCtrl.css({
"left": -this.ctrlWidth * this.ctrlIndex - this.excessWidth
});
}
}
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.slider');
var options = $.extend({}, Slider.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.slider', (data = new Slider(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
};
$.fn.slider = Plugin;
$.fn.slider.Constructor = Slider;
})(this);
\ No newline at end of file
... ...