Authored by lore-w

css\js基础交互

Showing 57 changed files with 1283 additions and 3493 deletions

Too many changes to show.

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://localhost:8000/index.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*
var mobile;
require("./js/index");
module.exports = mobile;
*/
... ...
/*
* @description: 详情页
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require("jquery");
var tools = require('yoho-tools');
var swiper = require('yoho.swiper');
var oShare = require("../plugin/share");
var flip = require("../plugin/flip");
var slide = require("../plugin/photoslide");
require("../plugin/login");
require("../plugin/comment");
require("../plugin/contentPaging");
exports.init = function() {
//轮播图
var fashionSwiper = new swiper('.fashion-banner',{
mode:'horizontal',
loop: true,
grabCursor: true,
paginationClickable: true,
slideElement: 'li',
onSlideChangeEnd: fashionSwiperIndex
});
var fashionSwitch = $(".fashion-switch");
var page;
if (!!fashionSwiper.slides) {
page = fashionSwiper.slides.length-2;
}
fashionSwitch.text(1+'/'+page);
function fashionSwiperIndex () {
var index = fashionSwiper.activeIndex;
//index = index > page ? 1 : index;
if (index > page) {
index = 1;
}else if (index <= 0) {
index = page;
}
fashionSwitch.text(index+'/'+page);
$(".relazy").lazyload({threshold: 100});
}
//变脸效果
slide.initSlide({
isMobile: true
});
var commentBox =$(".comments-box");
$(".comments").on("click",function(){
var cidNum = commentBox.attr("cid");
if($(".comment-textarea").size()>0){
if(commentBox.css("display") == "none"){
commentBox.show();
}else{
commentBox.hide();
}
}else{
commentBox.comment({
cid:cidNum,
commentPageUrl:'/comment/default/list',
publishUrl:'/comment/default/publish',
deleteUrl:'/comment/default/delete',
isMobile:true
});
}
});
//ajax参数
var param = {
id:commentBox.attr("cid"),
type:commentBox.attr("ctype"),
c:commentBox.attr("cc"),
twoc:commentBox.attr("ctwoc")
};
//底部数据的获取
$.ajax({
type:'GET',
url:YohoConfig.mainUrl+'/channel/detail/getbottom?id='+param.id+'&type='+param.type+'&c='+param.c+'&twoc='+param.twoc,
success:function(response){
var data = response.data;
var relatedPost = data.related,
prevnext = data.prevnext,
attitude = data.attitude,
commentnum = data.commentnum;
//新品播报
var relatedPostItem = '';
for(var i=0;i<3;i++){
if(relatedPost[i].isVideo === true){
var video = '<li>'+
'<a href="'+relatedPost[i].link+'" target="_blank" onclick="relatedClickEvent();">'+
'<div class="content-pic">'+
'<img src="'+relatedPost[i].cover+'" alt="" />'+
'<span class="play-icon"></span>'+
'</div>'+
'<div class="content-text">'+
'<h2>'+relatedPost[i].title+'</h2>'+
'<h3>'+relatedPost[i].subtitle+'</h3>'+
'</div>'+
'</a>'+
'</li>';
relatedPostItem += video;
}else{
var img = '<li>'+
'<a href="'+relatedPost[i].link+'" target="_blank" onclick="relatedClickEvent();">'+
'<div class="content-pic">'+
'<img src="'+relatedPost[i].cover+'" alt="" />'+
'</div>'+
'<div class="content-text">'+
'<h2>'+relatedPost[i].title+'</h2>'+
'<h3>'+relatedPost[i].subtitle+'</h3>'+
'</div>'+
'</a>'+
'</li>';
relatedPostItem += img;
}
}
$(".recomment ul").append($(relatedPostItem));
//上一篇下一篇
var pagePrev = $('.detail-prev');
var pageNext = $('.detail-next');
if(prevnext.prev.title){
pagePrev.show();
pagePrev.find("a").attr("href",prevnext.prev.link)
.attr("title",prevnext.prev.title).attr("onclick","prevOrNextClickEvent();");
}
if(prevnext.next.title){
pageNext.show();
pageNext.find("a").attr("href",prevnext.next.link)
.attr("title",prevnext.next.title).attr("onclick","prevOrNextClickEvent();");
}
//态度
$(".stats-btn").find("li").removeClass("current");
setattitude(attitude.wowCount,attitude.zzzCount,attitude.wtfCount);
if(commentnum>0){
$(".comment-num").text(commentnum);
}else{
$(".comment-num").html('<img src="'+YohoConfig.resUrl+'/assets/images/comment-mobile.png">');
}
}
});
//态度设置
$(".stats-btn").on("click","li",function(){
if($(this).index() == 3) return;
var exType = $(this).index()+1;
var isCancel = 0;
if($(this).hasClass("current")){
isCancel = 1;
}
//在请求开始之前先变色
if($(this).hasClass("current")){
$(this).removeClass('current');
}else{
$(".stats-btn").find("li").removeClass("current");
$(this).addClass('current');
}
var attitudeData = {id:param.id,exType:exType,isCancel:isCancel};
$.ajax({
type:'POST',
url:YohoConfig.mainUrl+'/channel/detail/setattitude',
data:attitudeData,
dataType:'json',
success:function(response){
var attitude = response.data;
/*if(attitude.userWow>0){
$(".stats-btn .wow").addClass("current");
};
if(attitude.userWtf>0){
$(".stats-btn .wtf").addClass("current");
};
if(attitude.userZzz>0){
$(".stats-btn .zzz").addClass("current");
};*/
setattitude(attitude.wowCount,attitude.zzzCount,attitude.wtfCount);
}
});
});
function setattitude(wow,zzz,wtf){
if(wow ===0){
$(".stats-btn .wow").find("span").find("img").show();
$(".stats-btn .wow").find("span").find("i").hide();
}else{
$(".stats-btn .wow").find("span").find("i").text(wow).show();
$(".stats-btn .wow").find("span").find("img").hide();
}
if(zzz ===0){
$(".stats-btn .zzz").find("span").find("img").show();
$(".stats-btn .zzz").find("span").find("i").hide();
}else{
$(".stats-btn .zzz").find("span").find("i").text(zzz).show();
$(".stats-btn .zzz").find("span").find("img").hide();
}
if(wtf ===0){
$(".stats-btn .wtf").find("span").find("img").show();
$(".stats-btn .wtf").find("span").find("i").hide();
}else{
$(".stats-btn .wtf").find("span").find("i").text(wtf).show();
$(".stats-btn .wtf").find("span").find("img").hide();
}
}
exports.updateLogin = function(){
$(".comments-box").login("updateLoginState");
$(".comments-box").comment("publishComment");
};
$(".side-bar-header").login();
$(".side-bar-header").on("click",function(){
$(this).login("loginBoxAnimate");
});
//手机版弹出登录框
/*$(".side-bar-header").on("click",function(){
if($(this).hasClass("login-success")) return;
$(".comments-box").comment("loginBoxAnimate");
})*/
//$(".comments-box").comment("initLoginState");
//share
var shareUrl = $("#share").attr("data-link");
oShare.init({
shareUrl:shareUrl,
img:$("#share").attr("cover"),
sinaText:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text(),
fbTextFunction:function(){
return {
des:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text()+'#YohoBoy',
name:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text()+'#YohoBoy',
caption:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text()+'#YohoBoy',
url:location.href
}
},
tweetText:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text()+'@YOHO潮流志',
qqText:'【Yoho!Boys】'+$(".share-h2").text()+'\r\n'+$(".share-h3").text()+'(来自Yoho!Boys)'
});
//hr分页
(function () {
// iphone上面的视频处理
var UserAgent = navigator.userAgent.toLowerCase();
var IsIphoneOs = UserAgent.match(/iphone os/i) == "iphone os";
var videoWrap = $('.fashion-text');
if (IsIphoneOs) {
// 内容中视频播放器替换为H5的VIDEO标签
if (videoWrap.find("object").length > 0) {
var defaultCover = videoWrap.attr("cover-url");
var playHref = "", videoUrl = "", videoCover = "", videoHtml = "";
videoWrap.find("object").each(function() {
playHref = $(this).find('embed').attr('src');
videoUrl = tools.request('url', playHref);
videoCover = tools.request('coverpic', playHref);
if (videoCover === "") {
videoCover = defaultCover;
}
videoCover = videoCover.replace(/%3A/g, ':').replace(/%2F/g, '/');
videoHtml = '<video controls="controls" preload="auto" width="290px" height="163px" poster="'+videoCover+'">'+
'<source src="' + videoUrl + '" type="video/mp4">'+
'</video>';
$(this).replaceWith(videoHtml);
});
}
}
})();
$(".fashion").contentPaging({
pageContentWrap:".fashion-text",
callback:function () {
lifeFlip();
}
});
//翻转
function lifeFlip () {
var lifestyleFlip = $('.lifestyle-flip').size();
if (!!lifestyleFlip) {
flip.init();
}
}
lifeFlip();
};
/**
* 点击关联关系区的事件
*/
function relatedClickEvent()
{
_hmt.push(['_trackEvent', '2.0 related', '2.0 post mobile', '2.0 related mobile']);
}
/**
* 点击上一页/下一页的事件
*/
function prevOrNextClickEvent()
{
_hmt.push(['_trackEvent', '2.0 prev or next', '2.0 prev or next mobile', '2.0 prev or next mobile']);
}
var $ = require("jquery");
require("../plugin/comment");
require("../plugin/login");
var commentBox = $('.comment-area');
exports.init = function() {
var cidNum = $(".has-comment").attr("cid");
$(".comment_button").on("click",function(){
if(commentBox.attr('isshow') === 'true'){
commentBox.attr('isshow','false').css('display','none');
}else{
commentBox.comment({cid:cidNum,isEdit:true,isMobile:true}).css('display','block');
commentBox.attr('isshow','true');
}
});
var id = {id:cidNum};
$.ajax({
type:'GET',
url:YohoConfig.mainUrl+'/writer/default/comment',
data: id,
dataType:'json',
success:function(response) {
var data = response.data.total;
if (data) {
$('.comment_button b').text(data);
}else{
$('.comment_button b').text('留言');
}
}
});
};
//第三方登陆
exports.updateLogin = function(){
commentBox.login("updateLoginState");
commentBox.comment("publishComment");
};
\ No newline at end of file
/*
* @description: 意见反馈
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require("jquery");
require("../plugin/login");
require("../plugin/comment");
exports.init = function() {
$('.about-nav .feedback').addClass('current');
$(".comments-box").comment({
cid:'0',
commentPageUrl:'/feedback/default/list',
publishUrl:'/feedback/default/publish',
deleteUrl:'/feedback/default/delete',
isFeedback:true,
isMobile:true
});
exports.updateLogin = function(){
$(".comments-box").login("updateLoginState");
$(".comments-box").comment("publishComment");
};
};
\ No newline at end of file
/*
* @description: home js
* @author: lore-w
* @date: 2015-4-23
*/
var $ = require('jquery'),
swiper = require('swiper-mobile');
exports.init = function () {
};
\ No newline at end of file
... ...
/*
* @description: magazine js
* @author: lore-w
* @date: 2015-4-23
*/
var $ = require('jquery'),
swiper = require('swiper-mobile');
exports.init = function () {
// magazine banner
var magazineSwiper = new swiper('.magazine-banner .swiper-container',{
loop: true,
pagination: '.pagination',
grabCursor: true,
paginationClickable: true,
autoplay: 5000,
slideElement: 'li'
});
// 立即购买下方的slide
var buySwiper = new swiper('#buy-slide',{
slidesPerView: 'auto',
grabCursor: true,
slideElement: 'li',
wrapperClass:"buy-wrapper"
});
// zine slide
var zineSwiper = new swiper('#zine-slide',{
slidesPerView: 'auto',
grabCursor: true,
slideElement: 'li',
wrapperClass:"zine-wrapper"
});
};
\ No newline at end of file
... ...
/*
* @description: 杂志页
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require('jquery');
var swiper = require('yoho.swiper');
var Hammer = require('hammerjs');
var oShare = require("../plugin/share");
exports.init = function () {
var buySlide=new swiper('#buy-slide',{
paginationClickable: true,
slidesPerView: 'auto',
slideElement: 'li',
onSlideChangeEnd: fallSwiperItems_buy
});
var ruleSlide=new swiper('.rules-slide',{
wrapperClass:"rules-wrapper",
paginationClickable: true,
slidesPerView: 'auto',
slideElement: 'li',
onSlideChangeEnd: fallSwiperItems_rule
});
function fallSwiperItems_buy(){
var currentSlide=arguments[0];
_fallSwiperItems(currentSlide,"buy");
}
function fallSwiperItems_rule(){
var currentSlide=arguments[0];
_fallSwiperItems(currentSlide,"rule");
}
var currentPageNumber=1;
function _fallSwiperItems(currentSlide,type){
var url="";
if(type=="buy") {
url="/channel/magazine/page?type=1&p=";
} else if( type=="zine") {
url="/channel/magazine/page?type=2&p=";
} else {
url="/channel/magazine/rules?p=";
}
var totalLength=$(currentSlide.container).find(".swiper-slide").length;
var currentIndex=currentSlide.activeIndex;
if(totalLength-currentIndex<=6) {
$.ajax({
url:YohoConfig.mainUrl+url+(currentPageNumber++),
cache:false,
success:function(data){
for(var i=0;i<data.data.length;i++) {
var cItem=data.data[i];
var newAppend=currentSlide.createSlide("<a><img src='"+cItem.cover+"' dynamic='"+cItem.dynamic+"'/></a><time>"+cItem.title+"</time>");
newAppend.append();
}
var oLi=$(currentSlide.container).find(".swiper-slide");
var LastSlide = currentSlide.getLastSlide();
oLi.css({'width':'131px'});
$(LastSlide).css({'width':'121px'});
currentSlide.reInit();
}
});
}
}
//e-zine
$.ajax({
type:'GET',
url:YohoConfig.mainUrl+'/channel/magazine/ezine',
success:function(response){
var data = response.data;
var len = data.length;
var item ='';
for(var i=0;i<len;i++){
if (data[i].magazineType == 2) {
item += '<li class="swiper-slide"><a class="magazine-special" href="javascript:;" title="'+data[i].releaseDate+'"><img src="'+data[i].cover+'" alt="" /></a><time>'+data[i].releaseDate+'</time></li>';
}else{
item += '<li class="swiper-slide"><a href="javascript:;" title="'+data[i].releaseDate+'"><img src="'+data[i].cover+'" alt="" /></a><time>'+data[i].releaseDate+'</time></li>';
}
}
$(".zine-wrapper").html(item);
var zineSlide=new swiper('.zine-slide',{
wrapperClass:"zine-wrapper",
paginationClickable: true,
slidesPerView: 'auto',
slideElement: 'li'
});
}
});
//rules动图弹层
var mobile = $("#mobile");
var rules = new Hammer(document.getElementById('rules'));
rules.on('tap',function (event) {
if ($(event.target).is($('img'))) {
var rulesMark = $('<div id="rulesMark"><img src="" class="popImg" /></div>').appendTo(mobile);
var url = $(event.target).attr('dynamic');
var popImg = $('.popImg');
popImg.attr('src',url);
rulesMark.fadeIn();
}
});
//关闭弹层
var close = new Hammer(document.getElementById('mobile'));
close.on('tap',function (event) {
var $temp = $('#rulesMark');
if ($(event.target).is($temp)) {
$temp.fadeOut().remove();
}
});
//分享
var shareUrl = $("#share").attr("data-link");
oShare.init({
shareUrl:shareUrl,
img:$("#share").attr("cover"),
sinaText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~',
fbTextFunction:function(){
return {
des:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~',
name:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~',
caption:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~',
url:location.href
}
},
tweetText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~',
qqText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".magazine-more").find("time").text()+'期点杂志,每月7日,17日,27日出刊哦~'
});
};
/*
* @description: 搜索
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require("jquery");
require("jquery.autocomplete");
exports.init = function () {
var search = $('.search_input input');
var searchBtn = $('.search_btn');
search.keydown(function (event) {
if (event.keyCode == 13) {
searchBtn.trigger("click");
}
}).autocomplete('/search/default/words', {
width: 290,
scrollHeight: 100,
max: 10,
selectFirst: false,
autoFill: false,
formatResult: function (row, data) {
return data.replace(/<\/?[^>]*>/g, '');
}
}).result(function (event, data, formatted) {
window.location.href = './search?q=' + encodeURIComponent(formatted.replace(/<\/?[^>]*>/g, ''));
});
searchBtn.click(function () {
if (search.val() !== "") {
window.location = YohoConfig.mainUrl + "/search?q=" + search.val();
return false;
} else {
$(document).trigger("click");
}
});
};
/*
* @description: common js
* @author: lore-w
* @date: 2015-4-23
*/
var $ = require('jquery'),
swiper = require('swiper-mobile');
require('jgestures');
// 初始化页面
exports.init = function () {
// nav
var navSwiper = new swiper('.girl-nav',{
grabCursor: true,
slidesPerView: 'auto',
slideElement: 'li',
hashnav: true
});
// channel page banner
var channelSwiper = new swiper('.banner .swiper-container',{
loop: true,
pagination: '.pagination',
grabCursor: true,
paginationClickable: true,
autoplay: 5000,
slideElement: 'li'
});
// download app
var downBtn = $('.home-download').find('.down-btn');
if (downBtn.length > 0) {
if (getDeviceType().isIphone) {
downBtn.each(function (index) {
$(this).attr('href', $(this).attr('data-ios'));
});
}
if (getDeviceType().isAndroid) {
downBtn.each(function (index) {
$(this).attr('href', $(this).attr('data-android'));
});
}
}
// back to top
$('.come-back').bind('tapone',function () {
$('body').animate({scrollTop: 0});
});
};
/*
* @description: 获取设备类型
* @param: none
* @return: JSON
*/
function getDeviceType () {
var sUserAgent = navigator.userAgent.toLowerCase(),
bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os",
bIsAndroid = sUserAgent.match(/android/i) == "android",
bIsWeixin = sUserAgent.match(/MicroMessenger/i) == 'micromessenger';
return {
isIphone: bIsIphoneOs,
isAndroid: bIsAndroid,
isWeixin: bIsWeixin
}
}
exports.getDeviceType = getDeviceType;
\ No newline at end of file
... ...
var $ = require("jquery");
console.log($);
/**
* Sea.js 3.0.0 | seajs.org/LICENSE.md
*/
(function(global, undefined) {
// Avoid conflicting when `sea.js` is loaded multiple times
if (global.seajs) {
return
}
var seajs = global.seajs = {
// The current version of Sea.js being used
version: "3.0.0"
}
var data = seajs.data = {}
/**
* util-lang.js - The minimal language enhancement
*/
function isType(type) {
return function(obj) {
return {}.toString.call(obj) == "[object " + type + "]"
}
}
var isObject = isType("Object")
var isString = isType("String")
var isArray = Array.isArray || isType("Array")
var isFunction = isType("Function")
var _cid = 0
function cid() {
return _cid++
}
/**
* util-events.js - The minimal events support
*/
var events = data.events = {}
// Bind event
seajs.on = function(name, callback) {
var list = events[name] || (events[name] = [])
list.push(callback)
return seajs
}
// Remove event. If `callback` is undefined, remove all callbacks for the
// event. If `event` and `callback` are both undefined, remove all callbacks
// for all events
seajs.off = function(name, callback) {
// Remove *all* events
if (!(name || callback)) {
events = data.events = {}
return seajs
}
var list = events[name]
if (list) {
if (callback) {
for (var i = list.length - 1; i >= 0; i--) {
if (list[i] === callback) {
list.splice(i, 1)
}
}
}
else {
delete events[name]
}
}
return seajs
}
// Emit event, firing all bound callbacks. Callbacks receive the same
// arguments as `emit` does, apart from the event name
var emit = seajs.emit = function(name, data) {
var list = events[name]
if (list) {
// Copy callback lists to prevent modification
list = list.slice()
// Execute event callbacks, use index because it's the faster.
for(var i = 0, len = list.length; i < len; i++) {
list[i](data)
}
}
return seajs
}
/**
* util-path.js - The utilities for operating path such as id, uri
*/
var DIRNAME_RE = /[^?#]*\//
var DOT_RE = /\/\.\//g
var DOUBLE_DOT_RE = /\/[^/]+\/\.\.\//
var MULTI_SLASH_RE = /([^:/])\/+\//g
// Extract the directory portion of a path
// dirname("a/b/c.js?t=123#xx/zz") ==> "a/b/"
// ref: http://jsperf.com/regex-vs-split/2
function dirname(path) {
return path.match(DIRNAME_RE)[0]
}
// Canonicalize a path
// realpath("http://test.com/a//./b/../c") ==> "http://test.com/a/c"
function realpath(path) {
// /a/b/./c/./d ==> /a/b/c/d
path = path.replace(DOT_RE, "/")
/*
@author wh1100717
a//b/c ==> a/b/c
a///b/////c ==> a/b/c
DOUBLE_DOT_RE matches a/b/c//../d path correctly only if replace // with / first
*/
path = path.replace(MULTI_SLASH_RE, "$1/")
// a/b/c/../../d ==> a/b/../d ==> a/d
while (path.match(DOUBLE_DOT_RE)) {
path = path.replace(DOUBLE_DOT_RE, "/")
}
return path
}
// Normalize an id
// normalize("path/to/a") ==> "path/to/a.js"
// NOTICE: substring is faster than negative slice and RegExp
function normalize(path) {
var last = path.length - 1
var lastC = path.charCodeAt(last)
// If the uri ends with `#`, just return it without '#'
if (lastC === 35 /* "#" */) {
return path.substring(0, last)
}
return (path.substring(last - 2) === ".js" ||
path.indexOf("?") > 0 ||
lastC === 47 /* "/" */) ? path : path + ".js"
}
var PATHS_RE = /^([^/:]+)(\/.+)$/
var VARS_RE = /{([^{]+)}/g
function parseAlias(id) {
var alias = data.alias
return alias && isString(alias[id]) ? alias[id] : id
}
function parsePaths(id) {
var paths = data.paths
var m
if (paths && (m = id.match(PATHS_RE)) && isString(paths[m[1]])) {
id = paths[m[1]] + m[2]
}
return id
}
function parseVars(id) {
var vars = data.vars
if (vars && id.indexOf("{") > -1) {
id = id.replace(VARS_RE, function(m, key) {
return isString(vars[key]) ? vars[key] : m
})
}
return id
}
function parseMap(uri) {
var map = data.map
var ret = uri
if (map) {
for (var i = 0, len = map.length; i < len; i++) {
var rule = map[i]
ret = isFunction(rule) ?
(rule(uri) || uri) :
uri.replace(rule[0], rule[1])
// Only apply the first matched rule
if (ret !== uri) break
}
}
return ret
}
var ABSOLUTE_RE = /^\/\/.|:\//
var ROOT_DIR_RE = /^.*?\/\/.*?\//
function addBase(id, refUri) {
var ret
var first = id.charCodeAt(0)
// Absolute
if (ABSOLUTE_RE.test(id)) {
ret = id
}
// Relative
else if (first === 46 /* "." */) {
ret = (refUri ? dirname(refUri) : data.cwd) + id
}
// Root
else if (first === 47 /* "/" */) {
var m = data.cwd.match(ROOT_DIR_RE)
ret = m ? m[0] + id.substring(1) : id
}
// Top-level
else {
ret = data.base + id
}
// Add default protocol when uri begins with "//"
if (ret.indexOf("//") === 0) {
ret = location.protocol + ret
}
return realpath(ret)
}
function id2Uri(id, refUri) {
if (!id) return ""
id = parseAlias(id)
id = parsePaths(id)
id = parseAlias(id)
id = parseVars(id)
id = parseAlias(id)
id = normalize(id)
id = parseAlias(id)
var uri = addBase(id, refUri)
uri = parseAlias(uri)
uri = parseMap(uri)
return uri
}
// For Developers
seajs.resolve = id2Uri;
// Check environment
var isWebWorker = typeof window === 'undefined' && typeof importScripts !== 'undefined' && isFunction(importScripts);
// Ignore about:xxx and blob:xxx
var IGNORE_LOCATION_RE = /^(about|blob):/;
var loaderDir;
// Sea.js's full path
var loaderPath;
// Location is read-only from web worker, should be ok though
var cwd = (!location.href || IGNORE_LOCATION_RE.test(location.href)) ? '' : dirname(location.href);
if (isWebWorker) {
// Web worker doesn't create DOM object when loading scripts
// Get sea.js's path by stack trace.
var stack;
try {
var up = new Error();
throw up;
} catch (e) {
// IE won't set Error.stack until thrown
stack = e.stack.split('\n');
}
// First line is 'Error'
stack.shift();
var m;
// Try match `url:row:col` from stack trace line. Known formats:
// Chrome: ' at http://localhost:8000/script/sea-worker-debug.js:294:25'
// FireFox: '@http://localhost:8000/script/sea-worker-debug.js:1082:1'
// IE11: ' at Anonymous function (http://localhost:8000/script/sea-worker-debug.js:295:5)'
// Don't care about older browsers since web worker is an HTML5 feature
var TRACE_RE = /.*?((?:http|https|file)(?::\/{2}[\w]+)(?:[\/|\.]?)(?:[^\s"]*)).*?/i
// Try match `url` (Note: in IE there will be a tailing ')')
var URL_RE = /(.*?):\d+:\d+\)?$/;
// Find url of from stack trace.
// Cannot simply read the first one because sometimes we will get:
// Error
// at Error (native) <- Here's your problem
// at http://localhost:8000/_site/dist/sea.js:2:4334 <- What we want
// at http://localhost:8000/_site/dist/sea.js:2:8386
// at http://localhost:8000/_site/tests/specs/web-worker/worker.js:3:1
while (stack.length > 0) {
var top = stack.shift();
m = TRACE_RE.exec(top);
if (m != null) {
break;
}
}
var url;
if (m != null) {
// Remove line number and column number
// No need to check, can't be wrong at this point
var url = URL_RE.exec(m[1])[1];
}
// Set
loaderPath = url
// Set loaderDir
loaderDir = dirname(url || cwd);
// This happens with inline worker.
// When entrance script's location.href is a blob url,
// cwd will not be available.
// Fall back to loaderDir.
if (cwd === '') {
cwd = loaderDir;
}
}
else {
var doc = document
var scripts = doc.scripts
// Recommend to add `seajsnode` id for the `sea.js` script element
var loaderScript = doc.getElementById("seajsnode") ||
scripts[scripts.length - 1]
function getScriptAbsoluteSrc(node) {
return node.hasAttribute ? // non-IE6/7
node.src :
// see http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx
node.getAttribute("src", 4)
}
loaderPath = getScriptAbsoluteSrc(loaderScript)
// When `sea.js` is inline, set loaderDir to current working directory
loaderDir = dirname(loaderPath || cwd)
}
/**
* util-request.js - The utilities for requesting script and style files
* ref: tests/research/load-js-css/test.html
*/
if (isWebWorker) {
function requestFromWebWorker(url, callback, charset) {
// Load with importScripts
var error;
try {
importScripts(url);
} catch (e) {
error = e;
}
callback(error);
}
// For Developers
seajs.request = requestFromWebWorker;
}
else {
var doc = document
var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement
var baseElement = head.getElementsByTagName("base")[0]
var currentlyAddingScript
function request(url, callback, charset) {
var node = doc.createElement("script")
if (charset) {
var cs = isFunction(charset) ? charset(url) : charset
if (cs) {
node.charset = cs
}
}
addOnload(node, callback, url)
node.async = true
node.src = url
// For some cache cases in IE 6-8, the script executes IMMEDIATELY after
// the end of the insert execution, so use `currentlyAddingScript` to
// hold current node, for deriving url in `define` call
currentlyAddingScript = node
// ref: #185 & http://dev.jquery.com/ticket/2709
baseElement ?
head.insertBefore(node, baseElement) :
head.appendChild(node)
currentlyAddingScript = null
}
function addOnload(node, callback, url) {
var supportOnload = "onload" in node
if (supportOnload) {
node.onload = onload
node.onerror = function() {
emit("error", { uri: url, node: node })
onload(true)
}
}
else {
node.onreadystatechange = function() {
if (/loaded|complete/.test(node.readyState)) {
onload()
}
}
}
function onload(error) {
// Ensure only run once and handle memory leak in IE
node.onload = node.onerror = node.onreadystatechange = null
// Remove the script to reduce memory leak
if (!data.debug) {
head.removeChild(node)
}
// Dereference the node
node = null
callback(error)
}
}
// For Developers
seajs.request = request
}
var interactiveScript
function getCurrentScript() {
if (currentlyAddingScript) {
return currentlyAddingScript
}
// For IE6-9 browsers, the script onload event may not fire right
// after the script is evaluated. Kris Zyp found that it
// could query the script nodes and the one that is in "interactive"
// mode indicates the current script
// ref: http://goo.gl/JHfFW
if (interactiveScript && interactiveScript.readyState === "interactive") {
return interactiveScript
}
var scripts = head.getElementsByTagName("script")
for (var i = scripts.length - 1; i >= 0; i--) {
var script = scripts[i]
if (script.readyState === "interactive") {
interactiveScript = script
return interactiveScript
}
}
}
/**
* util-deps.js - The parser for dependencies
* ref: tests/research/parse-dependencies/test.html
* ref: https://github.com/seajs/searequire
*/
function parseDependencies(s) {
if(s.indexOf('require') == -1) {
return []
}
var index = 0, peek, length = s.length, isReg = 1, modName = 0, parentheseState = 0, parentheseStack = [], res = []
while(index < length) {
readch()
if(isBlank()) {
}
else if(isQuote()) {
dealQuote()
isReg = 1
}
else if(peek == '/') {
readch()
if(peek == '/') {
index = s.indexOf('\n', index)
if(index == -1) {
index = s.length
}
}
else if(peek == '*') {
index = s.indexOf('*/', index)
if(index == -1) {
index = length
}
else {
index += 2
}
}
else if(isReg) {
dealReg()
isReg = 0
}
else {
index--
isReg = 1
}
}
else if(isWord()) {
dealWord()
}
else if(isNumber()) {
dealNumber()
}
else if(peek == '(') {
parentheseStack.push(parentheseState)
isReg = 1
}
else if(peek == ')') {
isReg = parentheseStack.pop()
}
else {
isReg = peek != ']'
modName = 0
}
}
return res
function readch() {
peek = s.charAt(index++)
}
function isBlank() {
return /\s/.test(peek)
}
function isQuote() {
return peek == '"' || peek == "'"
}
function dealQuote() {
var start = index
var c = peek
var end = s.indexOf(c, start)
if(end == -1) {
index = length
}
else if(s.charAt(end - 1) != '\\') {
index = end + 1
}
else {
while(index < length) {
readch()
if(peek == '\\') {
index++
}
else if(peek == c) {
break
}
}
}
if(modName) {
res.push(s.slice(start, index - 1))
modName = 0
}
}
function dealReg() {
index--
while(index < length) {
readch()
if(peek == '\\') {
index++
}
else if(peek == '/') {
break
}
else if(peek == '[') {
while(index < length) {
readch()
if(peek == '\\') {
index++
}
else if(peek == ']') {
break
}
}
}
}
}
function isWord() {
return /[a-z_$]/i.test(peek)
}
function dealWord() {
var s2 = s.slice(index - 1)
var r = /^[\w$]+/.exec(s2)[0]
parentheseState = {
'if': 1,
'for': 1,
'while': 1,
'with': 1
}[r]
isReg = {
'break': 1,
'case': 1,
'continue': 1,
'debugger': 1,
'delete': 1,
'do': 1,
'else': 1,
'false': 1,
'if': 1,
'in': 1,
'instanceof': 1,
'return': 1,
'typeof': 1,
'void': 1
}[r]
modName = /^require\s*\(\s*(['"]).+?\1\s*\)/.test(s2)
if(modName) {
r = /^require\s*\(\s*['"]/.exec(s2)[0]
index += r.length - 2
}
else {
index += /^[\w$]+(?:\s*\.\s*[\w$]+)*/.exec(s2)[0].length - 1
}
}
function isNumber() {
return /\d/.test(peek)
|| peek == '.' && /\d/.test(s.charAt(index))
}
function dealNumber() {
var s2 = s.slice(index - 1)
var r
if(peek == '.') {
r = /^\.\d+(?:E[+-]?\d*)?\s*/i.exec(s2)[0]
}
else if(/^0x[\da-f]*/i.test(s2)) {
r = /^0x[\da-f]*\s*/i.exec(s2)[0]
}
else {
r = /^\d+\.?\d*(?:E[+-]?\d*)?\s*/i.exec(s2)[0]
}
index += r.length - 1
isReg = 0
}
}
/**
* module.js - The core of module loader
*/
var cachedMods = seajs.cache = {}
var anonymousMeta
var fetchingList = {}
var fetchedList = {}
var callbackList = {}
var STATUS = Module.STATUS = {
// 1 - The `module.uri` is being fetched
FETCHING: 1,
// 2 - The meta data has been saved to cachedMods
SAVED: 2,
// 3 - The `module.dependencies` are being loaded
LOADING: 3,
// 4 - The module are ready to execute
LOADED: 4,
// 5 - The module is being executed
EXECUTING: 5,
// 6 - The `module.exports` is available
EXECUTED: 6,
// 7 - 404
ERROR: 7
}
function Module(uri, deps) {
this.uri = uri
this.dependencies = deps || []
this.deps = {} // Ref the dependence modules
this.status = 0
this._entry = []
}
// Resolve module.dependencies
Module.prototype.resolve = function() {
var mod = this
var ids = mod.dependencies
var uris = []
for (var i = 0, len = ids.length; i < len; i++) {
uris[i] = Module.resolve(ids[i], mod.uri)
}
return uris
}
Module.prototype.pass = function() {
var mod = this
var len = mod.dependencies.length
for (var i = 0; i < mod._entry.length; i++) {
var entry = mod._entry[i]
var count = 0
for (var j = 0; j < len; j++) {
var m = mod.deps[mod.dependencies[j]]
// If the module is unload and unused in the entry, pass entry to it
if (m.status < STATUS.LOADED && !entry.history.hasOwnProperty(m.uri)) {
entry.history[m.uri] = true
count++
m._entry.push(entry)
if(m.status === STATUS.LOADING) {
m.pass()
}
}
}
// If has passed the entry to it's dependencies, modify the entry's count and del it in the module
if (count > 0) {
entry.remain += count - 1
mod._entry.shift()
i--
}
}
}
// Load module.dependencies and fire onload when all done
Module.prototype.load = function() {
var mod = this
// If the module is being loaded, just wait it onload call
if (mod.status >= STATUS.LOADING) {
return
}
mod.status = STATUS.LOADING
// Emit `load` event for plugins such as combo plugin
var uris = mod.resolve()
emit("load", uris)
for (var i = 0, len = uris.length; i < len; i++) {
mod.deps[mod.dependencies[i]] = Module.get(uris[i])
}
// Pass entry to it's dependencies
mod.pass()
// If module has entries not be passed, call onload
if (mod._entry.length) {
mod.onload()
return
}
// Begin parallel loading
var requestCache = {}
var m
for (i = 0; i < len; i++) {
m = cachedMods[uris[i]]
if (m.status < STATUS.FETCHING) {
m.fetch(requestCache)
}
else if (m.status === STATUS.SAVED) {
m.load()
}
}
// Send all requests at last to avoid cache bug in IE6-9. Issues#808
for (var requestUri in requestCache) {
if (requestCache.hasOwnProperty(requestUri)) {
requestCache[requestUri]()
}
}
}
// Call this method when module is loaded
Module.prototype.onload = function() {
var mod = this
mod.status = STATUS.LOADED
// When sometimes cached in IE, exec will occur before onload, make sure len is an number
for (var i = 0, len = (mod._entry || []).length; i < len; i++) {
var entry = mod._entry[i]
if (--entry.remain === 0) {
entry.callback()
}
}
delete mod._entry
}
// Call this method when module is 404
Module.prototype.error = function() {
var mod = this
mod.onload()
mod.status = STATUS.ERROR
}
// Execute a module
Module.prototype.exec = function () {
var mod = this
// When module is executed, DO NOT execute it again. When module
// is being executed, just return `module.exports` too, for avoiding
// circularly calling
if (mod.status >= STATUS.EXECUTING) {
return mod.exports
}
mod.status = STATUS.EXECUTING
if (mod._entry && !mod._entry.length) {
delete mod._entry
}
//non-cmd module has no property factory and exports
if (!mod.hasOwnProperty('factory')) {
mod.non = true
return
}
// Create require
var uri = mod.uri
function require(id) {
var m = mod.deps[id] || Module.get(require.resolve(id))
if (m.status == STATUS.ERROR) {
throw new Error('module was broken: ' + m.uri);
}
return m.exec()
}
require.resolve = function(id) {
return Module.resolve(id, uri)
}
require.async = function(ids, callback) {
Module.use(ids, callback, uri + "_async_" + cid())
return require
}
// Exec factory
var factory = mod.factory
var exports = isFunction(factory) ?
factory(require, mod.exports = {}, mod) :
factory
if (exports === undefined) {
exports = mod.exports
}
// Reduce memory leak
delete mod.factory
mod.exports = exports
mod.status = STATUS.EXECUTED
// Emit `exec` event
emit("exec", mod)
return mod.exports
}
// Fetch a module
Module.prototype.fetch = function(requestCache) {
var mod = this
var uri = mod.uri
mod.status = STATUS.FETCHING
// Emit `fetch` event for plugins such as combo plugin
var emitData = { uri: uri }
emit("fetch", emitData)
var requestUri = emitData.requestUri || uri
// Empty uri or a non-CMD module
if (!requestUri || fetchedList.hasOwnProperty(requestUri)) {
mod.load()
return
}
if (fetchingList.hasOwnProperty(requestUri)) {
callbackList[requestUri].push(mod)
return
}
fetchingList[requestUri] = true
callbackList[requestUri] = [mod]
// Emit `request` event for plugins such as text plugin
emit("request", emitData = {
uri: uri,
requestUri: requestUri,
onRequest: onRequest,
charset: isFunction(data.charset) ? data.charset(requestUri) || 'utf-8' : data.charset
})
if (!emitData.requested) {
requestCache ?
requestCache[emitData.requestUri] = sendRequest :
sendRequest()
}
function sendRequest() {
seajs.request(emitData.requestUri, emitData.onRequest, emitData.charset)
}
function onRequest(error) {
delete fetchingList[requestUri]
fetchedList[requestUri] = true
// Save meta data of anonymous module
if (anonymousMeta) {
Module.save(uri, anonymousMeta)
anonymousMeta = null
}
// Call callbacks
var m, mods = callbackList[requestUri]
delete callbackList[requestUri]
while ((m = mods.shift())) {
// When 404 occurs, the params error will be true
if(error === true) {
m.error()
}
else {
m.load()
}
}
}
}
// Resolve id to uri
Module.resolve = function(id, refUri) {
// Emit `resolve` event for plugins such as text plugin
var emitData = { id: id, refUri: refUri }
emit("resolve", emitData)
return emitData.uri || seajs.resolve(emitData.id, refUri)
}
// Define a module
Module.define = function (id, deps, factory) {
var argsLen = arguments.length
// define(factory)
if (argsLen === 1) {
factory = id
id = undefined
}
else if (argsLen === 2) {
factory = deps
// define(deps, factory)
if (isArray(id)) {
deps = id
id = undefined
}
// define(id, factory)
else {
deps = undefined
}
}
// Parse dependencies according to the module factory code
if (!isArray(deps) && isFunction(factory)) {
deps = typeof parseDependencies === "undefined" ? [] : parseDependencies(factory.toString())
}
var meta = {
id: id,
uri: Module.resolve(id),
deps: deps,
factory: factory
}
// Try to derive uri in IE6-9 for anonymous modules
if (!isWebWorker && !meta.uri && doc.attachEvent && typeof getCurrentScript !== "undefined") {
var script = getCurrentScript()
if (script) {
meta.uri = script.src
}
// NOTE: If the id-deriving methods above is failed, then falls back
// to use onload event to get the uri
}
// Emit `define` event, used in nocache plugin, seajs node version etc
emit("define", meta)
meta.uri ? Module.save(meta.uri, meta) :
// Save information for "saving" work in the script onload event
anonymousMeta = meta
}
// Save meta data to cachedMods
Module.save = function(uri, meta) {
var mod = Module.get(uri)
// Do NOT override already saved modules
if (mod.status < STATUS.SAVED) {
mod.id = meta.id || uri
mod.dependencies = meta.deps || []
mod.factory = meta.factory
mod.status = STATUS.SAVED
emit("save", mod)
}
}
// Get an existed module or create a new one
Module.get = function(uri, deps) {
return cachedMods[uri] || (cachedMods[uri] = new Module(uri, deps))
}
// Use function is equal to load a anonymous module
Module.use = function (ids, callback, uri) {
var mod = Module.get(uri, isArray(ids) ? ids : [ids])
mod._entry.push(mod)
mod.history = {}
mod.remain = 1
mod.callback = function() {
var exports = []
var uris = mod.resolve()
for (var i = 0, len = uris.length; i < len; i++) {
exports[i] = cachedMods[uris[i]].exec()
}
if (callback) {
callback.apply(global, exports)
}
delete mod.callback
delete mod.history
delete mod.remain
delete mod._entry
}
mod.load()
}
// Public API
seajs.use = function(ids, callback) {
Module.use(ids, callback, data.cwd + "_use_" + cid())
return seajs
}
Module.define.cmd = {}
global.define = Module.define
// For Developers
seajs.Module = Module
data.fetchedList = fetchedList
data.cid = cid
seajs.require = function(id) {
var mod = Module.get(Module.resolve(id))
if (mod.status < STATUS.EXECUTING) {
mod.onload()
mod.exec()
}
return mod.exports
}
/**
* config.js - The configuration for the loader
*/
// The root path to use for id2uri parsing
data.base = loaderDir
// The loader directory
data.dir = loaderDir
// The loader's full path
data.loader = loaderPath
// The current working directory
data.cwd = cwd
// The charset for requesting files
data.charset = "utf-8"
// data.alias - An object containing shorthands of module id
// data.paths - An object containing path shorthands in module id
// data.vars - The {xxx} variables in module id
// data.map - An array containing rules to map module uri
// data.debug - Debug mode. The default value is false
seajs.config = function(configData) {
for (var key in configData) {
var curr = configData[key]
var prev = data[key]
// Merge object config such as alias, vars
if (prev && isObject(prev)) {
for (var k in curr) {
prev[k] = curr[k]
}
}
else {
// Concat array config such as map
if (isArray(prev)) {
curr = prev.concat(curr)
}
// Make sure that `data.base` is an absolute path
else if (key === "base") {
// Make sure end with "/"
if (curr.slice(-1) !== "/") {
curr += "/"
}
curr = addBase(curr)
}
// Set config
data[key] = curr
}
}
emit("config", configData)
return seajs
}
})(this);
seajs.config({
base: 'http://localhost:8000',
charset: 'utf-8'
});
\ No newline at end of file
... ...
/*
SeaJS - A Module Loader for the Web
v2.3.0 | seajs.org | MIT Licensed
*/
!function(a,b){function c(a){return function(b){return{}.toString.call(b)=="[object "+a+"]"}}function d(){return z++}function e(a){return a.match(C)[0]}function f(a){for(a=a.replace(D,"/"),a=a.replace(F,"$1/");a.match(E);)a=a.replace(E,"/");return a}function g(a){var b=a.length-1,c=a.charAt(b);return"#"===c?a.substring(0,b):".js"===a.substring(b-2)||a.indexOf("?")>0||"/"===c?a:a+".js"}function h(a){var b=u.alias;return b&&w(b[a])?b[a]:a}function i(a){var b=u.paths,c;return b&&(c=a.match(G))&&w(b[c[1]])&&(a=b[c[1]]+c[2]),a}function j(a){var b=u.vars;return b&&a.indexOf("{")>-1&&(a=a.replace(H,function(a,c){return w(b[c])?b[c]:a})),a}function k(a){var b=u.map,c=a;if(b)for(var d=0,e=b.length;e>d;d++){var f=b[d];if(c=y(f)?f(a)||a:a.replace(f[0],f[1]),c!==a)break}return c}function l(a,b){var c,d=a.charAt(0);if(I.test(a))c=a;else if("."===d)c=f((b?e(b):u.cwd)+a);else if("/"===d){var g=u.cwd.match(J);c=g?g[0]+a.substring(1):a}else c=u.base+a;return 0===c.indexOf("//")&&(c=location.protocol+c),c}function m(a,b){if(!a)return"";a=h(a),a=i(a),a=j(a),a=g(a);var c=l(a,b);return c=k(c)}function n(a){return a.hasAttribute?a.src:a.getAttribute("src",4)}function o(a,b,c){var d=K.createElement("script");if(c){var e=y(c)?c(a):c;e&&(d.charset=e)}p(d,b,a),d.async=!0,d.src=a,R=d,Q?P.insertBefore(d,Q):P.appendChild(d),R=null}function p(a,b,c){function d(){a.onload=a.onerror=a.onreadystatechange=null,u.debug||P.removeChild(a),a=null,b()}var e="onload"in a;e?(a.onload=d,a.onerror=function(){B("error",{uri:c,node:a}),d()}):a.onreadystatechange=function(){/loaded|complete/.test(a.readyState)&&d()}}function q(){if(R)return R;if(S&&"interactive"===S.readyState)return S;for(var a=P.getElementsByTagName("script"),b=a.length-1;b>=0;b--){var c=a[b];if("interactive"===c.readyState)return S=c}}function r(a){var b=[];return a.replace(U,"").replace(T,function(a,c,d){d&&b.push(d)}),b}function s(a,b){this.uri=a,this.dependencies=b||[],this.exports=null,this.status=0,this._waitings={},this._remain=0}if(!a.seajs){var t=a.seajs={version:"2.3.0"},u=t.data={},v=c("Object"),w=c("String"),x=Array.isArray||c("Array"),y=c("Function"),z=0,A=u.events={};t.on=function(a,b){var c=A[a]||(A[a]=[]);return c.push(b),t},t.off=function(a,b){if(!a&&!b)return A=u.events={},t;var c=A[a];if(c)if(b)for(var d=c.length-1;d>=0;d--)c[d]===b&&c.splice(d,1);else delete A[a];return t};var B=t.emit=function(a,b){var c=A[a],d;if(c){c=c.slice();for(var e=0,f=c.length;f>e;e++)c[e](b)}return t},C=/[^?#]*\//,D=/\/\.\//g,E=/\/[^/]+\/\.\.\//,F=/([^:/])\/+\//g,G=/^([^/:]+)(\/.+)$/,H=/{([^{]+)}/g,I=/^\/\/.|:\//,J=/^.*?\/\/.*?\//,K=document,L=location.href&&0!==location.href.indexOf("about:")?e(location.href):"",M=K.scripts,N=K.getElementById("seajsnode")||M[M.length-1],O=e(n(N)||L);t.resolve=m;var P=K.head||K.getElementsByTagName("head")[0]||K.documentElement,Q=P.getElementsByTagName("base")[0],R,S;t.request=o;var T=/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\/\*[\S\s]*?\*\/|\/(?:\\\/|[^\/\r\n])+\/(?=[^\/])|\/\/.*|\.\s*require|(?:^|[^$])\brequire\s*\(\s*(["'])(.+?)\1\s*\)/g,U=/\\\\/g,V=t.cache={},W,X={},Y={},Z={},$=s.STATUS={FETCHING:1,SAVED:2,LOADING:3,LOADED:4,EXECUTING:5,EXECUTED:6};s.prototype.resolve=function(){for(var a=this,b=a.dependencies,c=[],d=0,e=b.length;e>d;d++)c[d]=s.resolve(b[d],a.uri);return c},s.prototype.load=function(){var a=this;if(!(a.status>=$.LOADING)){a.status=$.LOADING;var c=a.resolve();B("load",c);for(var d=a._remain=c.length,e,f=0;d>f;f++)e=s.get(c[f]),e.status<$.LOADED?e._waitings[a.uri]=(e._waitings[a.uri]||0)+1:a._remain--;if(0===a._remain)return a.onload(),b;var g={};for(f=0;d>f;f++)e=V[c[f]],e.status<$.FETCHING?e.fetch(g):e.status===$.SAVED&&e.load();for(var h in g)g.hasOwnProperty(h)&&g[h]()}},s.prototype.onload=function(){var a=this;a.status=$.LOADED,a.callback&&a.callback();var b=a._waitings,c,d;for(c in b)b.hasOwnProperty(c)&&(d=V[c],d._remain-=b[c],0===d._remain&&d.onload());delete a._waitings,delete a._remain},s.prototype.fetch=function(a){function c(){t.request(g.requestUri,g.onRequest,g.charset)}function d(){delete X[h],Y[h]=!0,W&&(s.save(f,W),W=null);var a,b=Z[h];for(delete Z[h];a=b.shift();)a.load()}var e=this,f=e.uri;e.status=$.FETCHING;var g={uri:f};B("fetch",g);var h=g.requestUri||f;return!h||Y[h]?(e.load(),b):X[h]?(Z[h].push(e),b):(X[h]=!0,Z[h]=[e],B("request",g={uri:f,requestUri:h,onRequest:d,charset:u.charset}),g.requested||(a?a[g.requestUri]=c:c()),b)},s.prototype.exec=function(){function a(b){return s.get(a.resolve(b)).exec()}var c=this;if(c.status>=$.EXECUTING)return c.exports;c.status=$.EXECUTING;var e=c.uri;a.resolve=function(a){return s.resolve(a,e)},a.async=function(b,c){return s.use(b,c,e+"_async_"+d()),a};var f=c.factory,g=y(f)?f(a,c.exports={},c):f;return g===b&&(g=c.exports),delete c.factory,c.exports=g,c.status=$.EXECUTED,B("exec",c),g},s.resolve=function(a,b){var c={id:a,refUri:b};return B("resolve",c),c.uri||t.resolve(c.id,b)},s.define=function(a,c,d){var e=arguments.length;1===e?(d=a,a=b):2===e&&(d=c,x(a)?(c=a,a=b):c=b),!x(c)&&y(d)&&(c=r(""+d));var f={id:a,uri:s.resolve(a),deps:c,factory:d};if(!f.uri&&K.attachEvent){var g=q();g&&(f.uri=g.src)}B("define",f),f.uri?s.save(f.uri,f):W=f},s.save=function(a,b){var c=s.get(a);c.status<$.SAVED&&(c.id=b.id||a,c.dependencies=b.deps||[],c.factory=b.factory,c.status=$.SAVED,B("save",c))},s.get=function(a,b){return V[a]||(V[a]=new s(a,b))},s.use=function(b,c,d){var e=s.get(d,x(b)?b:[b]);e.callback=function(){for(var b=[],d=e.resolve(),f=0,g=d.length;g>f;f++)b[f]=V[d[f]].exec();c&&c.apply(a,b),delete e.callback},e.load()},t.use=function(a,b){return s.use(a,b,u.cwd+"_use_"+d()),t},s.define.cmd={},a.define=s.define,t.Module=s,u.fetchedList=Y,u.cid=d,t.require=function(a){var b=s.get(s.resolve(a));return b.status<$.EXECUTING&&(b.onload(),b.exec()),b.exports},u.base=O,u.dir=O,u.cwd=L,u.charset="utf-8",t.config=function(a){for(var b in a){var c=a[b],d=u[b];if(d&&v(d))for(var e in c)d[e]=c[e];else x(d)?c=d.concat(c):"base"===b&&("/"!==c.slice(-1)&&(c+="/"),c=l(c)),u[b]=c}return B("config",a),t}}}(this);
/**
* @fileOverview SeaJS 配置
*/
seajs.config({
alias: {
'jquery': 'lib/jquery'
},
base: 'http://cdn.yoho.cn',
charset: 'utf-8'
});
\ No newline at end of file
/*
SeaJS - A Module Loader for the Web
v2.3.0 | seajs.org | MIT Licensed
*/
!function(a,b){function c(a){return function(b){return{}.toString.call(b)=="[object "+a+"]"}}function d(){return z++}function e(a){return a.match(C)[0]}function f(a){for(a=a.replace(D,"/"),a=a.replace(F,"$1/");a.match(E);)a=a.replace(E,"/");return a}function g(a){var b=a.length-1,c=a.charAt(b);return"#"===c?a.substring(0,b):".js"===a.substring(b-2)||a.indexOf("?")>0||"/"===c?a:a+".js"}function h(a){var b=u.alias;return b&&w(b[a])?b[a]:a}function i(a){var b=u.paths,c;return b&&(c=a.match(G))&&w(b[c[1]])&&(a=b[c[1]]+c[2]),a}function j(a){var b=u.vars;return b&&a.indexOf("{")>-1&&(a=a.replace(H,function(a,c){return w(b[c])?b[c]:a})),a}function k(a){var b=u.map,c=a;if(b)for(var d=0,e=b.length;e>d;d++){var f=b[d];if(c=y(f)?f(a)||a:a.replace(f[0],f[1]),c!==a)break}return c}function l(a,b){var c,d=a.charAt(0);if(I.test(a))c=a;else if("."===d)c=f((b?e(b):u.cwd)+a);else if("/"===d){var g=u.cwd.match(J);c=g?g[0]+a.substring(1):a}else c=u.base+a;return 0===c.indexOf("//")&&(c=location.protocol+c),c}function m(a,b){if(!a)return"";a=h(a),a=i(a),a=j(a),a=g(a);var c=l(a,b);return c=k(c)}function n(a){return a.hasAttribute?a.src:a.getAttribute("src",4)}function o(a,b,c){var d=K.createElement("script");if(c){var e=y(c)?c(a):c;e&&(d.charset=e)}p(d,b,a),d.async=!0,d.src=a,R=d,Q?P.insertBefore(d,Q):P.appendChild(d),R=null}function p(a,b,c){function d(){a.onload=a.onerror=a.onreadystatechange=null,u.debug||P.removeChild(a),a=null,b()}var e="onload"in a;e?(a.onload=d,a.onerror=function(){B("error",{uri:c,node:a}),d()}):a.onreadystatechange=function(){/loaded|complete/.test(a.readyState)&&d()}}function q(){if(R)return R;if(S&&"interactive"===S.readyState)return S;for(var a=P.getElementsByTagName("script"),b=a.length-1;b>=0;b--){var c=a[b];if("interactive"===c.readyState)return S=c}}function r(a){var b=[];return a.replace(U,"").replace(T,function(a,c,d){d&&b.push(d)}),b}function s(a,b){this.uri=a,this.dependencies=b||[],this.exports=null,this.status=0,this._waitings={},this._remain=0}if(!a.seajs){var t=a.seajs={version:"2.3.0"},u=t.data={},v=c("Object"),w=c("String"),x=Array.isArray||c("Array"),y=c("Function"),z=0,A=u.events={};t.on=function(a,b){var c=A[a]||(A[a]=[]);return c.push(b),t},t.off=function(a,b){if(!a&&!b)return A=u.events={},t;var c=A[a];if(c)if(b)for(var d=c.length-1;d>=0;d--)c[d]===b&&c.splice(d,1);else delete A[a];return t};var B=t.emit=function(a,b){var c=A[a],d;if(c){c=c.slice();for(var e=0,f=c.length;f>e;e++)c[e](b)}return t},C=/[^?#]*\//,D=/\/\.\//g,E=/\/[^/]+\/\.\.\//,F=/([^:/])\/+\//g,G=/^([^/:]+)(\/.+)$/,H=/{([^{]+)}/g,I=/^\/\/.|:\//,J=/^.*?\/\/.*?\//,K=document,L=location.href&&0!==location.href.indexOf("about:")?e(location.href):"",M=K.scripts,N=K.getElementById("seajsnode")||M[M.length-1],O=e(n(N)||L);t.resolve=m;var P=K.head||K.getElementsByTagName("head")[0]||K.documentElement,Q=P.getElementsByTagName("base")[0],R,S;t.request=o;var T=/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\/\*[\S\s]*?\*\/|\/(?:\\\/|[^\/\r\n])+\/(?=[^\/])|\/\/.*|\.\s*require|(?:^|[^$])\brequire\s*\(\s*(["'])(.+?)\1\s*\)/g,U=/\\\\/g,V=t.cache={},W,X={},Y={},Z={},$=s.STATUS={FETCHING:1,SAVED:2,LOADING:3,LOADED:4,EXECUTING:5,EXECUTED:6};s.prototype.resolve=function(){for(var a=this,b=a.dependencies,c=[],d=0,e=b.length;e>d;d++)c[d]=s.resolve(b[d],a.uri);return c},s.prototype.load=function(){var a=this;if(!(a.status>=$.LOADING)){a.status=$.LOADING;var c=a.resolve();B("load",c);for(var d=a._remain=c.length,e,f=0;d>f;f++)e=s.get(c[f]),e.status<$.LOADED?e._waitings[a.uri]=(e._waitings[a.uri]||0)+1:a._remain--;if(0===a._remain)return a.onload(),b;var g={};for(f=0;d>f;f++)e=V[c[f]],e.status<$.FETCHING?e.fetch(g):e.status===$.SAVED&&e.load();for(var h in g)g.hasOwnProperty(h)&&g[h]()}},s.prototype.onload=function(){var a=this;a.status=$.LOADED,a.callback&&a.callback();var b=a._waitings,c,d;for(c in b)b.hasOwnProperty(c)&&(d=V[c],d._remain-=b[c],0===d._remain&&d.onload());delete a._waitings,delete a._remain},s.prototype.fetch=function(a){function c(){t.request(g.requestUri,g.onRequest,g.charset)}function d(){delete X[h],Y[h]=!0,W&&(s.save(f,W),W=null);var a,b=Z[h];for(delete Z[h];a=b.shift();)a.load()}var e=this,f=e.uri;e.status=$.FETCHING;var g={uri:f};B("fetch",g);var h=g.requestUri||f;return!h||Y[h]?(e.load(),b):X[h]?(Z[h].push(e),b):(X[h]=!0,Z[h]=[e],B("request",g={uri:f,requestUri:h,onRequest:d,charset:u.charset}),g.requested||(a?a[g.requestUri]=c:c()),b)},s.prototype.exec=function(){function a(b){return s.get(a.resolve(b)).exec()}var c=this;if(c.status>=$.EXECUTING)return c.exports;c.status=$.EXECUTING;var e=c.uri;a.resolve=function(a){return s.resolve(a,e)},a.async=function(b,c){return s.use(b,c,e+"_async_"+d()),a};var f=c.factory,g=y(f)?f(a,c.exports={},c):f;return g===b&&(g=c.exports),delete c.factory,c.exports=g,c.status=$.EXECUTED,B("exec",c),g},s.resolve=function(a,b){var c={id:a,refUri:b};return B("resolve",c),c.uri||t.resolve(c.id,b)},s.define=function(a,c,d){var e=arguments.length;1===e?(d=a,a=b):2===e&&(d=c,x(a)?(c=a,a=b):c=b),!x(c)&&y(d)&&(c=r(""+d));var f={id:a,uri:s.resolve(a),deps:c,factory:d};if(!f.uri&&K.attachEvent){var g=q();g&&(f.uri=g.src)}B("define",f),f.uri?s.save(f.uri,f):W=f},s.save=function(a,b){var c=s.get(a);c.status<$.SAVED&&(c.id=b.id||a,c.dependencies=b.deps||[],c.factory=b.factory,c.status=$.SAVED,B("save",c))},s.get=function(a,b){return V[a]||(V[a]=new s(a,b))},s.use=function(b,c,d){var e=s.get(d,x(b)?b:[b]);e.callback=function(){for(var b=[],d=e.resolve(),f=0,g=d.length;g>f;f++)b[f]=V[d[f]].exec();c&&c.apply(a,b),delete e.callback},e.load()},t.use=function(a,b){return s.use(a,b,u.cwd+"_use_"+d()),t},s.define.cmd={},a.define=s.define,t.Module=s,u.fetchedList=Y,u.cid=d,t.require=function(a){var b=s.get(s.resolve(a));return b.status<$.EXECUTING&&(b.onload(),b.exec()),b.exports},u.base=O,u.dir=O,u.cwd=L,u.charset="utf-8",t.config=function(a){for(var b in a){var c=a[b],d=u[b];if(d&&v(d))for(var e in c)d[e]=c[e];else x(d)?c=d.concat(c):"base"===b&&("/"!==c.slice(-1)&&(c+="/"),c=l(c)),u[b]=c}return B("config",a),t}}}(this);
/**
* @fileOverview SeaJS 配置
*/
seajs.config({
alias: {
'jquery': 'lib/jquery'
},
base: 'http://res.yohoboys.com/res/new/boys/js/',
charset: 'utf-8'
});
\ No newline at end of file
exports.Dic={
//email为空
emailEmpty_jian:"请输入Email!",
emailEmpty_fan:"請輸入Email!",
//email格式错误
emailError_jian:"输入的Email格式不对!",
emailError_fan:"輸入的Email格式不對!",
//评论内容不能为空
commentEmpty_jian:"评论内容不能为空!",
commentEmpty_fan:"評論內容不能為空!",
//评论内容太多
commentToMuch_jian:"文字超过限制,请删改至100个字以内!",
commentToMuch_fan:"文字超過限制,請刪改至100個字以內!",
//系统繁忙请稍后再试
systemBus_jian:"系统繁忙,请稍候再试!",
systemBus_fan:"系統繁忙,請稍候再試!",
//意见反馈为空
feedbackEmpty_jian:"请输入内容后再发送!",
feedbackEmpty_fan:"請輸入內容后再發送!",
//意见反馈发布成功
publishFeedback_jian:"意见反馈发送成功!",
publishFeedback_fan:"意見反饋發送成功!",
//刪除意见反馈
deleteFeedback_jian:"是否删除此条反馈意见?",
deleteFeedback_fan:"是否刪除此條反饋意見?",
//留言内容不能为空
editEmpty_jian:"留言内容不能为空!",
editEmpty_fan:"留言內容不能為空!",
//留言发布成功
editPublishSuccess_jian:"留言发送成功!",
editPublishSuccess_fan:"留言發送成功!",
//刪除留言
deleteEdit_jian:"你确定要删除该留言吗?",
deleteEdit_fan:"你確定要刪除該留言嗎",
//账号密码错误
loginError_jian:"您输入的账号或密码不正确",
loginError_fan:"您輸入的賬號或密碼不正確",
//评论发布成功
publishSuccess_jian:"评论发送成功!",
publishSuccess_fan:"評論發送成功!",
//登录接口
thirdLoginFeedback_jian:"第三方评论",
thirdLoginFeedback_fan:"第三方評論",
//第三方登录提示
thirdLogin_jian:"已注册过有货、SHOW、友和市集,可直接登录",
thirdLogin_fan:"已註冊過有貨、SHOW、友和市集,可直接登錄",
//登录
login_jian:"登录",
login_fan:"登錄",
//退出登录
logout_jian:"是否退出登录?",
logout_fan:"是否退出登錄",
//密码
yohoPwd_jian:"密码",
yohoPwd_fan:"密碼",
//yoho账号
yohoAccount_jian:"YOHO账号",
yohoAccount_fan:"YOHO賬號",
//说点什么
textareaPlaceholder_jian:"说点什么...",
textareaPlaceholder_fan:"說點什麼...",
//刪除评论
deleteComment_jian:"你确定要删除该评论吗?",
deleteComment_fan:"你確定要刪除該評論嗎",
//重新登录
relogin_jian:"请重新登录!",
relogin_fan:"請重新登錄!",
//5分钟内不能评论相同内容
notSameContent_jian:'5分钟内不能评论相同内容!',
notSameContent_fan:'5分鐘內不能評論相同內容!'
};
\ No newline at end of file
# YOHO!插件库
## 概念
插件简言之就是在一个应用中通用的组件,但是其抽象程度,没有到通用组件的高度,只适用于当前的项目
/**
* @fileOverview 弹出层组件
* @author:Hbomb(zhouqq@yoho.cn)
* @date:2012-08-07
*/
var $ = require("jquery");
var tools = require("yoho-tools");
var html_front =
'<div class="comfirm">'+
'<div class="comfirm-head">'+
'<a href="javascript:void(0);" class="iconfont close" title="close">&#xe64d;</a>'+
'</div>'+
'<div class="comfirm-content">'+
'<p class="comfirm-text">';
var html_end =
'</p>'+
'</div>'+
'<div class="comfirm-foot">'+
'<div class="comfirm-line"></div>'+
'<div class="comfirm-ctrl clearfix">'+
'<a href="javascript:void(0);" class="cancel">取消</a>'+
'<a href="javascript:void(0);" class="ok">确定</a>'+
'</div>'+
'</div>'+
'</div>';
var zhHK = {
'晕了晕了...明明是空的!':'暈了暈了...明明是空的!',
'请输入有效的邮箱或手机号!':'請輸入有效的郵箱或手機號!',
'密码不得小于6位字符':'密碼不得小於6位字符',
'账号或密码不正确!':'賬號或密碼不正確!',
'你确定要删除该评论吗?':'妳確定要刪除該評論嗎?',
'评论内容不能为空!':'評論內容不能為空!',
'评论内容超过上限60个字!':'評論內容超過上限60個字!',
'系统繁忙,请稍候再试!':'系統繁忙,請稍候再試!',
'请输入Email!':'請輸入Email!',
'输入的Email格式不对!':'輸入的Email格式不對!',
'密码不正确,请重新输入':'密碼不正確,請重新輸入',
'5分钟内不能评论重复内容':'5分鐘內不能評論重復內容'
};
var setPos = function()
{
var _dialog = $(".comfirm");
var wH = $(window).height();
var dialogH = _dialog.height();
var w = $(window).width();
var t = $(window).scrollTop();
var ww = _dialog.outerWidth();
_dialog.css({"top":(wH-dialogH)/2,"left":(w/2-ww/2)+"px",'z-index':10000000000,'position': 'absolute'});
if (!($.browser.msie&&$.browser.version=='6.0'))
{
_dialog.css({"position":"fixed"});
}
else
{
_dialog.css({"top":t+"px"});
}
};
$(window).resize(function () {
setTimeout(function () {
setPos();
},500);
});
/**
* 弹出提示框
*
* @param string message 弹出的提示消息内容
* @param int delay 当需要几秒后自动关闭时,设置该值
*/
exports.alert = function(message, delay,callback)
{
message = translate(message);
if ($(".comfirm").length > 0)
{
$(".confirm").remove();
}
$("body").append(html_front + message + html_end);
$('.comfirm .cancel').hide();
setPos();
$(".close,.ok").click(function()
{
$(".comfirm").remove();
if (callback) {
callback();
}
return false;
});
if (delay && !isNaN(delay))
{
window.setTimeout(function()
{
$(".comfirm").remove();
}, delay * 1000);
}
};
/**
* 弹出确认对话框
*
* @param string message 弹出的提示消息内容
* @param int delay 当需要几秒后自动关闭时,设置该值
*/
exports.confirm = function(message, callback, delay)
{
message = translate(message);
if ($(".comfirm").length > 0)
{
$(".confirm").remove();
}
$("body").append(html_front + message + html_end);
setPos();
$(".cancel,.close").click(function()
{
$('.comfirm .ok').unbind('click');
$(".comfirm").remove();
});
if (callback)
{
$('.comfirm .ok').click(function()
{
$(".comfirm").remove();
callback();
});
}
if (delay && !isNaN(delay))
{
window.setTimeout(function()
{
$(".comfirm").remove();
}, delay * 1000);
}
};
/**
* 转换消息简繁体
*
* @param string message
* @returns string
*/
function translate(message)
{
var lang = tools.cookie('yh_language');
if (!lang)
{
return message;
}
if (lang == 'zh-hk' && zhHK[message])
{
message = zhHK[message];
}
return message;
}
\ No newline at end of file
/*
评论及登录插件
author:liuyue
date:2015-01-07
*/
var $=require("jquery");
var validate = require("./validate");
var box = require("./box");
var tools = require("yoho-tools");
var tips=require("./tips");
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"),
isFeedback:false,
isEdit:false,
isMobile:false,
login:''
};
Comment.prototype = {
constructor: Comment,
init:function(){
if($(".comments-list").size()>0 || $(".comment-textarea").size()>0) return;
// 组件的创建主函数。
this._creat();
},
// 主函数,主要是创建节点,绑定事件。
_creat: function(){
// 创建节点
this._creatCommentDom();
this._creatTextareaDom();
if(this.options.isFeedback){
this._creatFeedbackLogin();
}
// 绑定事件
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;
var commentsList = $('<ul class="comments-list"></ul>'),
commentsItem = '';
commentsList.prependTo(that.$element);
if(data.length === 0) return;
var total = data.total,
viewMoreNum = total-5;
viewMore = $('<div class="view-more"><a href="javascript:;">View&nbsp;<span>'+viewMoreNum+'</span>&nbsp;more</a></div>'),
commentArr = data.comment,
commentLen = commentArr.length;
for (var i = 0; i < commentLen; i++){
if(commentArr[i].isSelf === true){
commentsItem = $('<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+commentArr[i].userimg+'" alt="">'+
'<i class="'+commentArr[i].partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+commentArr[i].username+'</h6>'+
'<p class="comment-text">'+commentArr[i].content+'</p>'+
'<a class="delete-comment" href="javascript:;" pid="'+commentArr[i].id+'"></a>'+
'</div>'+
'</li>');
}else{
commentsItem = $('<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+commentArr[i].userimg+'" alt="">'+
'<i class="'+commentArr[i].partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+commentArr[i].username+'</h6>'+
'<p class="comment-text">'+commentArr[i].content+'</p>'+
'</div>'+
'</li>');
}
commentsList.append(commentsItem);
}
if(commentLen>5){
var string = viewMoreNum+'';
var num =string.slice(0,1);
commentsList.find("li").eq(4).nextAll().hide();
commentsList.after(viewMore);
if(string.length == 4){
$(".view-more").find("span").text(num+'k+');
}else if(string.length == 5){
$(".view-more").find("span").text(num+'w+');
}
}
if(data.page){
var commentPage = data.page;
var pageWrap = $('<div style="display:none" class="pager-content comment-pager-content"></div>');
var pageIcon = $('<div class="channel-index-pager">'+commentPage+'</div>');
commentsList.after(pageWrap);
pageIcon.appendTo(pageWrap);
}
}
});
},
//创建评论文本域
_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">'+
'<div class="userimg">'+
'<img src="'+YohoConfig.resUrl+'/assets/images/detail/user-img.png" alt="">'+
'<i></i>'+
'</div>'+
'<div class="userinfo">'+
'<span></span>'+
'<a class="exit-btn" href="javascript:;">退出</a>'+
'</div>'+
'<div class="publish">'+
'<a class="publish-btn" href="javascript:;">Publish</a>'+
'</div>'+
'</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();
}
},
_creatFeedbackLogin:function(){
var $feedbackLogin = '';
if(tips.isJian){
$feedbackLogin = $('<div class="feedback-login clearfix">'+
'<span>'+tips.getTips("thirdLoginFeedback")+'</span>'+
'<a class="qq" ref="/passport/partner/index/oauth/qq" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-qq.png" alt="" /></a>'+
'<a class="yoho" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-yoho.png" alt="" /></a>'+
'<a class="sina" ref="/passport/partner/index/oauth/sina" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-sina.png" alt="" /></a>'+
'</div>');
}else{
$feedbackLogin = $('<div class="feedback-login clearfix">'+
'<span>'+tips.getTips("thirdLoginFeedback")+'</span>'+
'<a class="fb" ref="/passport/partner/index/oauth/facebook" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-facebook.png" alt="" /></a>'+
'<a class="yoho" href="javascript:;"><img src="'+YohoConfig.resUrl+'assets/images/about/thirdbtn-yoho.png" alt="" /></a>'+
'<a class="sina" ref="/passport/partner/index/oauth/sina" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-sina.png" alt="" /></a>'+
'<a class="qq" ref="/passport/partner/index/oauth/qq" href="javascript:;"><img src="'+YohoConfig.resUrl+'/assets/images/about/thirdbtn-qq.png" alt="" /></a>'+
'</div>');
}
$feedbackLogin.appendTo(this.$element);
},
//事件绑定
_bindEvent: function(){
var that = this;
//查看更多评论
this.$element.on("click.comment",".view-more",function(){
that.$element.find("li").show(); //显示第一页后五条
that.$element.find(".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");
});
//发表评论
this.$element.on("click.publish",".publish-btn",function(){
if($(".login-status").hasClass("login-success") || that.options.isFeedback){
//if($(".comment-textarea textarea").val() == '') return;
var $textarea = that.$element.find("textarea");
var comment = $textarea.val();
if (!!!comment || $.trim(comment) === '')
{
var valEmpty = tips.getTips("commentEmpty");
if(that.options.isFeedback){
valEmpty = tips.getTips("feedbackEmpty");
}else if(that.options.isEdit){
valEmpty = tips.getTips("editEmpty");
}
box.alert(valEmpty, 5,function(){
$textarea.focus();
});
return false;
}
if (comment.length > 100)
{
box.alert(tips.getTips("commentToMuch"), 5);
return false;
}
var cid = $textarea.attr('cid');
if (!cid)
{
return false;
}
/*
var sync = [];
if ($('.sync').length > 0)
{
$('.sync:checked').each(function()
{
sync.push($(this).val());
});
}*/
//var title = $(".detail-title h1").text()+" "+$(".detail-title h2").text();
var data = {id:cid,comment:comment,sync:'222',title:'111'};
$.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 $target = $(".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($target.find("li").size()===0){
$target.html(commentItem);
}else{
$target.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");
var $_this = $(this);
$.ajax({
type:'GET',
url:url,
success:function(response)
{
var data = response.data;
var commentArr = data.comment,
commentLen = commentArr.length,
commentsItem = '',
commentPage = data.page;
var pageIcon = $('<div class="channel-index-pager">'+commentPage+'</div>');
$(".comments-list").empty();
for (var i = 0; i < commentLen; i++){
if(commentArr[i].isSelf === true){
commentsItem = $('<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+commentArr[i].userimg+'" alt="">'+
'<i class="'+commentArr[i].partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+commentArr[i].username+'</h6>'+
'<p class="comment-text">'+commentArr[i].content+'</p>'+
'<a class="delete-comment" href="javascript:;" pid="'+commentArr[i].id+'"></a>'+
'</div>'+
'</li>');
}else{
commentsItem = $('<li class="clearfix">'+
'<div class="userimg">'+
'<img src="'+commentArr[i].userimg+'" alt="">'+
'<i class="'+commentArr[i].partnerType+'"></i>'+
'</div>'+
'<div class="userinfo">'+
'<h6>'+commentArr[i].username+'</h6>'+
'<p class="comment-text">'+commentArr[i].content+'</p>'+
'</div>'+
'</li>');
}
$(".comments-list").append(commentsItem);
}
$(".comment-pager-content").html(pageIcon);
var commentListTop = $(".comments-list").offset().top - $("#minEnterprise").outerHeight();
$(window).scrollTop(commentListTop);
}
});
return false;
});
//显示删除按钮
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.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+'/assets/images/comment-mobile.png">');
$(".comment-num.zero").text(0);
$(".comment-num.edit-comment").text('留言');
}
}
}
});
});
});
$(".feedback-login").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");
return false;
});
$(".feedback-login").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
/**
* @description 根据水平线分页
* @author ly yue.liu@yoho.cn
* @since 2014-12-17
*/
var $=require("jquery");
var slide = require("./photoslide");
var flip = require("./flip");
(function(global, undefined) {
var ContentPaging = function(element, options) {
this.options = options;
this.$element = $(element);
this.$contentWrap = this.$element.find(this.options.pageContentWrap);
this.$coverPic = this.$element.find(this.options.coverPic);
this.dataArr = this.$contentWrap.html().split("<hr>");
this.len = this.dataArr.length;
this.init();
};
ContentPaging.DEFAULTS = {
coverPic:".pic-body",
pageContentWrap:".text-body",
callback:null
};
ContentPaging.prototype = {
constructor: ContentPaging,
init:function(){
//this.$contentWrap.text(this.$contentWrap.html());
if(this.len ===0) return;
this._browserjuge();
this._creat();
this._bindEvent();
this.pagination(0);
},
//兼容ie8
_browserjuge:function(){
//检测ie版本,ie8采用1024分辨率
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=b_version.split(";");
var trim_Version=version[1].replace(/[ ]/g,"");
if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE8.0" || browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){
this.dataArr = this.$contentWrap.html().split("<HR>");
this.len = this.dataArr.length;
}
},
// 主函数,主要是创建节点,绑定事件。
_creat: function(){
// 创建分页按钮
this._creatPagination();
},
_creatPagination: function(){
if(this.len<=1) return;
var $paginationWrap = $('<div class="pager-content detail-pagination"><div class="channel-index-pager"></div></div>');
var $paginationItem;
this.$contentWrap.after($paginationWrap);
for(var i=0;i<this.len;i++){
$paginationItem = $('<a class="pager-item" href="javascript:;">'+(i+1)+'</a>');
$(".detail-pagination .channel-index-pager").append($paginationItem);
}
},
/*
* 分页函数
*/
pagination: function(index) {
var _this = this;
if(this.len<=1) return;
//除了第一页,均不显示封面图
if(index === 0){
this.$coverPic.show();
}else{
this.$coverPic.hide();
}
this.$contentWrap.html(this.dataArr[index]);
$(".detail-pagination .channel-index-pager").find("a").removeClass("pager-item-choosen").eq(index).addClass("pager-item-choosen");
$("body").animate({scrollTop:0},10);
$(document.documentElement).animate({scrollTop:0},10);
slide.initSlide({isMobile:false});
flip.init({
operate:"mouse",
wrapClass:".yohoboy-flip"
});
if(this.options.callback){
clearTimeout(timer);
var timer = null;
timer = setTimeout(function(){
_this.options.callback();
},500);
}
},
/*
* 插件事件绑定
*/
_bindEvent: function(){
var that = this;
$(".detail-pagination .channel-index-pager").on("click","a",function(){
var index = $(this).index();
that.pagination(index);
});
},
/**跳转到某一个分页**/
jumpTo: function(index){
pagination(index);
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.ContentPaging');
var options = $.extend({}, ContentPaging.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.ContentPaging', (data = new ContentPaging(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
}
$.fn.contentPaging = Plugin;
$.fn.contentPaging.Constructor = ContentPaging;
})(this);
\ No newline at end of file
/**
* @fileOverview 实现图片翻转控件
* @author ww
* @date 2014-07-22
*/
var $ = require("jquery");
require("yoho-rotate2d");
require('jquery.imagesloaded'); //懒加载
var height;
var scrollTop;
var windowHeight=$(window).height();
var delay,returnDelay,isPlaying=false;
//翻转当前对象动画
function revolvePic(target){
//延时对象
var timeHandler1,timeHandler2,timeHandler3,timeHandler4;
var Y = target.offset().top;
target.height(target.find("img:first").height());
height=target.height();
//分别判断图片小于屏幕和大于屏幕的情况
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) || //图片小于屏幕
//当图片高度大于屏幕时分别判断:图片顶端位置+图片高度<=滚动高度+屏幕高度(说明图片已经滚动到底)以及 图片顶端位置-50<=滚动高度(说明图片顶端接近屏幕顶端)
//以上两种判断分别对应:向上滚动、向下滚动
(height>=windowHeight&&Y-50<=scrollTop)||(height>=windowHeight&&Y+height<=scrollTop+windowHeight)) {//当图片大于屏幕时执行
isStayLong=true;//用户在该显示区域已经停留了足够长的时间,1S
//判断是否已经增加过了旋转样式,如果没有增加就追加
if (target.attr("RevolvePic")===undefined) {
var eleBack = null, eleFront = null,
// 两张被翻转的图片元素
eleList = target.find(".img");
// 确定前面与后面元素
var funBackOrFront = function() {
eleList.each(function() {
if ($(this).hasClass("out")) {
eleBack = $(this);
} else {
eleFront = $(this);
}
});
};
window.setTimeout(function(){
//根据动画播放完毕的回调事件判断动画播放不会重叠
if (!isPlaying) {
isPlaying=true;
funBackOrFront();
timeHandler1=window.setTimeout(function(){
eleFront.addClass("out").removeClass("in");
timeHandler2=setTimeout(function() {
eleBack.addClass("in").removeClass("out");
// 重新确定正反元素
funBackOrFront();
},155);
},delay-1000);
timeHandler3=window.setTimeout(function(){
eleFront.addClass("out").removeClass("in");
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");
}
},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);
}
}
exports.init=function(info){
/**
* 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")
{
//获取到前后面的图片
var isImagesLoaded=false;
targets.find("img:first").imagesLoaded(function(){
isImagesLoaded=true;
revolvePic($(this).parent().parent());
});
$(window).scroll(function(){
if(isImagesLoaded===true){
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");
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 ++;
this._animate(-this.width);
},
/*
* 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++;
}
});
},
/*
* 插件事件绑定
*/
_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 {
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;
})($);
var $=require("jquery");
+function($){
'use strict';
function ImgZoom(element,options){
this.$element = $(element);
if(!options){
this.options = this.getDefaults();
}else{
this.options = $.extend(true,this.getDefaults(),options);
}
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');
}
};
//事件绑定集合
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);
var _index;
if(direction=="left"){
_index = index - 1;
}else{
_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"));
if(!_this.$box.hasClass("show")){
_this.open();
}
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;
}
};
}else{
img.onload = function () { //图片下载完毕时异步调用callback函数。
callback.call(img);//将回调函数的this替换为Image对象
img = null;
};
}
img.src = src;
};
//打开事件
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)));
}
if(typeof option =='string'){
data[option](object);
}
return $this;
});
}
var old = $.fn.ImgZoom;
$.fn.ImgZoom = Plugin;
$.fn.ImgZoom.Constructor = ImgZoom;
$.fn.ImgZoom.noConflict = function () {
$.fn.ImgZoom = old;
return this;
};
}($);
/**
* @fileOverview 图片懒加载的组件
* @author fei.hong@yoho.cn
* @date 2014-05-14
*/
//require("lib/util/jquery.scrollev");
require("lazyload");
var $ = require("jquery");
var settings =
{
threshold : 0, // 灵敏度. 提前加载, 值为像素值
failure_limit : 0, // 容差范围. 检查是否在显示区域内,默认找到第 1 张不可见的图片时,就终止遍历
event : "scroll", // 自定义触发事件 默认为 scroll. 如scrollstop
effect : "fadeIn", // 自定义显示效果, 默认为show. 如show, fadeIn, slideDown
container : window, // 图片插入到的容器,默认为window
data_attribute : "original", // 真实图片地址的 data 属性后缀
skip_invisible : true, // 加载不可见图像, 默认true是不会加载隐藏的不可见图像
appear : null, // 图片加载时的事件 (Function)
load : null, // 图片加载后的事件 (Function)
placeholder : "data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=="
};
/**
* 初始化页面的图片
*
* 实现懒加载需要修改的HTML代码:
* 需要在页面的img图片标签加上"data-original"属性, 值为需要懒加载的图片地址
*
* @param string className class样式名称
* @param object options 配置项
* @return void
*/
exports.init = function(className, options)
{
$.extend(settings, options || {});
$('img.'+className).lazyload(options);
};
/*
登录插件
author:liuyue
date:2015-01-07
*/
var $=require("jquery");
//var validate = require("./validate");
var box = require("./box");
var tools = require("yoho-tools");
var tips=require("./tips");
(function(global, undefined) {
var Login = function(element, options) {
this.options = options;
this.$element = $(element);
this.init();
};
Login.DEFAULTS = {
};
Login.prototype = {
constructor: Login,
init:function(){
if($(".login-box").size()<=0){
this.creatLoginBox();
this._bindEvent();
}
this.initLoginState();
if($(".cookieList").size()<=0){
var cookieList = $('<ul class="cookieList"></ul>').appendTo($(".accountwrap"));
}
this.cookieAccount();
},
creatLoginBox:function(){
var $loginBox = $('<div class="login-box">'+
'<h2>登录</h2>'+
'<div class="input-box">'+
'<p class="accountwrap"><input class="yoho-account" type="text" placeholder="'+tips.getTips("yohoAccount")+'"></p>'+
'<p><input class="yoho-pwd" type="password" placeholder="'+tips.getTips("yohoPwd")+'" style="display:none;" /><input class="yoho-pwd-text" type="text" placeholder="'+tips.getTips("yohoPwd")+'" /></p>'+
'</div>'+
'<div class="warn">'+tips.getTips("loginError")+'</div>'+
'<div class="login-btn">'+
'<a id="login" href="javascript:;">'+tips.getTips("login")+'</a>'+
'</div>'+
'<div class="third-login">'+
'<p>'+tips.getTips("thirdLogin")+'</p>'+
'<div class="third-btn clearfix">'+
'<a class="sina" ref="/passport/partner/index/oauth/sina" href="javascript:;"></a>'+
'<a class="qq" ref="/passport/partner/index/oauth/qq" href="javascript:;"></a>'+
'<a class="fb" ref="/passport/partner/index/oauth/facebook" href="javascript:;"></a>'+
'</div>'+
'</div>'+
'<div class="close-btn"></div>'+
'</div>'+
'<div class="login-shadow"></div>').appendTo("body");
},
_bindEvent:function(){
var that = this;
//关闭登录框
$(document).on("click.closeLogin",function(event){
if($(event.target).is(".publish-btn") || $(event.target).is(".login-box") || $(event.target).parents(".login-box").length>=1 ||$(event.target).is(".yoho")||$(event.target).parents(".yoho").length>=1||$(event.target).is(".side-bar-header")) return;
that.closeLoginBox();
event.stopPropagation();
});
$(".login-box").on("click.closeLoginBox",".close-btn",function(){
that.closeLoginBox();
});
//输入账号时登录按钮样式变化
$(".login-box").on("focus",".yoho-account",function(){
$(".login-box").find("#login").addClass("login");
});
//账号密码输入框默认提示
$('.yoho-account').val(tips.getTips("yohoAccount")).addClass("default-tip");
$('.yoho-pwd-text').val(tips.getTips("yohoPwd")).addClass("default-tip");
$('.yoho-account').on("focus",function()
{
if ($(this).val() == tips.getTips("yohoAccount"))
{
$(this).removeClass("default-tip");
$(this).val('');
}
}).on("blur",function()
{
if ($(this).val() === '')
{
$(this).addClass("default-tip");
$(this).val(tips.getTips("yohoAccount"));
}
});
$('.yoho-pwd-text').on("focus",function()
{
if ($(this).val() === '' || $(this).val() == tips.getTips("yohoPwd"))
{
$('.yoho-pwd').val('').show().focus();
$(this).hide();
$(this).removeClass("default-tip");
}
});
$('.yoho-pwd').on("blur",function()
{
if ($(this).val() === '')
{
$(this).hide();
$('.yoho-pwd-text').addClass("default-tip");
$('.yoho-pwd-text').val(tips.getTips("yohoPwd")).show();
}
});
//登录按钮点击事件
$(".login-box").on("click.login","#login",function()
{
var $this = $(this);
var account = $('.yoho-account').val();
var password = $('.yoho-pwd').val();
$.ajax
({
type:'POST',
url:YohoConfig.mainUrl+'/passport/partner/yoho',
data:{'account':account,'password':password},
dataType:'json',
success:function(response)
{
if (response&&response.status && response.data)
{
var userName;
var currentUserName=tools.cookie('userName');
var account = $(".yoho-account").val();
if(currentUserName===null||currentUserName===undefined){
tools.cookie('userName',account,{expires:5,path: '/'});
}else{
tools.cookie('userName',currentUserName+","+account,{expires:5,path: '/'});
}
that.cookieAccount();
that.setLogin(response.data);
$(".login-box").find(".warn").css({"visibility":"hidden"});
that.closeLoginBox();
$this.comment("publishComment");
}
else if (response&&response.message !== '')
{
$(".login-box").find(".warn").css({"visibility":"visible"});
}
else
{
$(".login-box").find(".warn").css({"visibility":"visible"});
}
}
});
});
//回车执行登录
$(".login-box").find(".yoho-pwd").keyup(function(e)
{
var event = e || window.event;
var k = event.keyCode || event.which;
if (k == 13)
{
$('#login').trigger("click.login");
}
});
$(".third-btn").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");
that.closeLoginBox();
return false;
});
},
//滑出登录框
loginBoxAnimate:function(){
if($(".login-status").hasClass("login-success")) return;
if($(".side-bar-header").hasClass("login-success")) return;
var height = $(".login-box").outerHeight();
$(".login-shadow").show();
$("body").find(".login-box").animate({"top":"50%","margin-top":-height/2},200);
},
//隐藏登录框
closeLoginBox:function(){
var height = $(".login-box").outerHeight();
$(".login-box").css({"top":-height,"margin-top":0});
$(".login-shadow").hide();
},
//初始化登录状态
initLoginState:function()
{
var state = tools.cookie('yh_state');
var syncs = tools.cookie('yh_syncs');
if (state && syncs)
{
var data = $.parseJSON(syncs);
if (data && data.nick)
{
this.setLogin(data);
}
}
},
//更新登录信息
updateLoginState:function()
{
this.initLoginState();
},
//登录
setLogin:function(data){
var that = this;
$(".login-status .userimg").find("i").attr("class",data.type);
$(".login-status .userinfo").find("span").text(data.nick);
//用户头像
if (data.headpic)
{
$(".login-status .userimg").find("img").attr("src",data.headpic);
}
//手机版
if (data.headpic)
{
$(".user-avatar").find("img").attr("src",data.headpic);
}
$(".login-username").text(data.nick);
$(".side-bar-header").addClass("login-success");
$(".login-status .userinfo").show();
$(".login-status").addClass("login-success");
//隐藏匿名
if($(".login-status .anonymous").size()>0){
$(".login-status .anonymous").hide();
}
//隐藏意见反馈页登录按钮
if($(".feedback-login").size()>0){
$(".feedback-login").hide();
}
$(".exit-btn").on("click",function(){
box.confirm(tips.getTips("logout"), function(){
that.setLogout();
});
});
},
//登出
setLogout:function(){
$(".login-status").removeClass("login-success");
$(".login-status .userimg").find("img").attr("src",YohoConfig.resUrl+"/assets/images/detail/user-img.png");
$(".login-status .userinfo").hide();
$(".login-status .userimg").find("i").attr("class",'');
$(".comments-list").find(".delete-comment").remove();
//手机版
$(".side-bar-header").removeClass("login-success");
$(".user-avatar").find("img").attr("src",YohoConfig.resUrl+"/assets/images/detail/user-img.png");
$(".login-username").text("登录");
//显示匿名
if($(".login-status .anonymous").size()>0){
$(".login-status .anonymous").show();
}
//显示意见反馈页登录按钮
if($(".feedback-login").size()>0){
$(".feedback-login").show();
}
$.ajax
({
type:'GET',
url:YohoConfig.mainUrl+'/passport/partner/logout',
dataType:'json'
});
},
//cookie记入账号
cookieAccount:function(){
//cookie
var getCookie,
arrCookie;
getCookie = decodeURIComponent(tools.cookie('userName'));
if(!!tools.cookie('userName'))
{
arrCookie = tools.unique(getCookie.split(','));
$(".cookieList").empty();
for (var i=0;i<arrCookie.length;i++) {
$(".cookieList").append($('<li><a href="javascript:;">'+arrCookie[i]+'</a></li>'));
}
$(".login-box").click(function(e){
if($(e.target).is(".yoho-account")||$(e.target).is(".cookieList")|| $(e.target).closest(".cookieList").size()>0){
$(".cookieList").show();
}else{
$(".cookieList").hide();
}
})
$(".cookieList").on("click","li",function(){
$(".yoho-account").val($(this).find("a").text()).removeClass("default-tip");
$(".cookieList").hide();
return false;
});
}
}
};
function Plugin(option, _relatedTarget) {
return this.each(function() {
var $this = $(this);
var data = $this.data('yoho.Login');
var options = $.extend({}, Login.DEFAULTS, $this.data(), typeof option == 'object' && option);
// 如果没有初始化,则初始化该对象,并且把该对象绑定到此元素的yoho.PicSilder属性下。
if (!data) $this.data('yoho.Login', (data = new Login(this, options)));
// 如果传递的options是一个字符串,则表示调用改对象的原型方法。
if (typeof option == 'string') data[option](_relatedTarget);
});
}
$.fn.login = Plugin;
$.fn.login.Constructor = Login;
})(this);
\ No newline at end of file
window.lineHeightDatabase = {};
var $ = require("jquery");
exports.init = function() {
/*获取一段文本共计多少行*/
$.fn.getTextLineNumber = function(keyword) {
//省略后加上title
var $this = $(this);
var fontSize,lineHeight;
if (!window.lineHeightDatabase[keyword]) {
window.lineHeightDatabase[keyword] = {fontSize: 0, lineHeight: 0};
}
if (window.lineHeightDatabase[keyword].fontSize !== 0)
{
fontSize = window.lineHeightDatabase[keyword].fontSize;
}
else
{
fontSize = getFinalStyle(this[0], "fontSize");
window.lineHeightDatabase[keyword].fontSize = fontSize;
}
//获取计算后的样式
if (window.lineHeightDatabase[keyword].lineHeight !== 0)
{
lineHeight = window.lineHeightDatabase[keyword].lineHeight;
window.lineHeightDatabase[keyword].lineHeight = lineHeight;
}
else
{
if (/msie/i.test(navigator.userAgent)) {
lineHeight = getFinalStyle(this[0], "lineHeight", fontSize);
}
else {
lineHeight = getFinalStyle(this[0], "lineHeight");
}
}
if (this[0] === null)
return;
var height = this[0].clientHeight;
if (lineHeight === "norm") {
lineHeight = Number(fontSize * 1.5);
var nowStyle = $this.attr("style") || "";
this[0].setAttribute("style", nowStyle + ";line-height:" + lineHeight + "px");
}
else {
lineHeight = Number(lineHeight);
}
return parseInt(height / lineHeight);
};
$.fn.mlellipsis = function(row, keyword) {
//省略后加上title
var $this = $(this);
var title = $this.attr("_title");
if (!title) {
$this.attr("_title", $this.text());
}
else {
$this.text(title);
}
//获取计算后的样式
var fontSize,lineHeight;
if (!window.lineHeightDatabase[keyword]) {
window.lineHeightDatabase[keyword] = {fontSize: 0, lineHeight: 0};
}
if (window.lineHeightDatabase[keyword].fontSize !== 0)
{
fontSize = window.lineHeightDatabase[keyword].fontSize;
}
else
{
fontSize = getFinalStyle(this[0], "fontSize");
window.lineHeightDatabase[keyword].fontSize = fontSize;
}
//获取计算后的样式
if (window.lineHeightDatabase[keyword].lineHeight !== 0)
{
lineHeight = window.lineHeightDatabase[keyword].lineHeight;
}
else
{
if (/msie/i.test(navigator.userAgent)) {
lineHeight = getFinalStyle(this[0], "lineHeight", fontSize);
}
else {
lineHeight = getFinalStyle(this[0], "lineHeight");
//window.lineHeightDatabase[keyword].lineHeight=lineHeight;
}
}
if (!this[0])
return;
var height = this[0].clientHeight;
var width=this[0].clientWidth;
if (lineHeight === "norm") {
lineHeight = Number(fontSize * 1.5);
var nowStyle = $this.attr("style") || "";
this[0].setAttribute("style", nowStyle + ";line-height:" + lineHeight + "px");
}
else {
lineHeight = Number(lineHeight);
}
//若高度足够,则不用省略
var dheight = Math.floor(row * lineHeight);
str = $this.text();
if (height >= dheight)
{
var str = this.text();
var fillText="";
var currentIndex=0;
//减去末尾文字
var count=getRowNumber(width,fontSize)*row;
$this.text("");
while (dheight >this[0].clientHeight) {
if(str.length>count+currentIndex)
{
fillText+=str.substring(currentIndex,currentIndex+count);
currentIndex+=count+1;
count=10;
$this.text(fillText+"...");
}
else if(fillText==="")
{
$this.text(str);
}
else{
$this.text(fill);
}
}
return row;
}
else
{
return parseInt(height / lineHeight);
}
};
$.fn.fillText = function(keyword) {
//省略后加上title
var $this = $(this);
var title = $this.attr("_title");
if (!title) {
$this.attr("_title", $this.text());
}
else {
$this.text(title);
}
//获取计算后的样式
var fontSize,lineHeight;
if (!window.lineHeightDatabase[keyword]) {
window.lineHeightDatabase[keyword] = {fontSize: 0, lineHeight: 0};
}
if (window.lineHeightDatabase[keyword].fontSize !== 0)
{
fontSize = window.lineHeightDatabase[keyword].fontSize;
}
else
{
fontSize = getFinalStyle(this[0], "fontSize");
window.lineHeightDatabase[keyword].fontSize = fontSize;
}
//获取计算后的样式
if (window.lineHeightDatabase[keyword].lineHeight !== 0)
{
lineHeight = window.lineHeightDatabase[keyword].lineHeight;
}
else
{
if (/msie/i.test(navigator.userAgent)) {
lineHeight = getFinalStyle(this[0], "lineHeight", fontSize);
}
else {
lineHeight = getFinalStyle(this[0], "lineHeight");
//window.lineHeightDatabase[keyword].lineHeight=lineHeight;
}
}
if (!this[0])
return;
var height = this[0].clientHeight;
if (lineHeight === "norm") {
lineHeight = Number(fontSize * 1.5);
var nowStyle = $this.attr("style") || "";
this[0].setAttribute("style", nowStyle + ";line-height:" + lineHeight + "px");
}
else {
lineHeight = Number(lineHeight);
}
//若高度足够,则不用省略
if (height > 5 * lineHeight)
{
row = 5;
}
else
{
row = (Math.floor(height / lineHeight) - 1);
}
/*var titleHeight = $this.parent().find(".a-title").height() / 30;
var subTitleHeight = $this.parent().find(".a-subtitle").height() / 30;
if (titleHeight + subTitleHeight >= 4)
{
row = 4;
}*/
var dheight = Math.floor(row * lineHeight);
if (height >= dheight)
{
var str = this.text();
while (dheight * 3 < this[0].clientHeight) {
$this.text(str.substring(0, str.length / 2));
str = $this.text();
}
//减去末尾文字
while (dheight < this[0].clientHeight) {
str = $this.text();
var strLen = str.length;
$this.text(str.substring(0,strLen-8)+' ...');
//$this.text(str.replace(/(\s)*([a-zA-Z0-9]?|\W)(\.\.\.)?$/, "..."));
}
$this.text($this.text().replace(/[a-zA-Z]+?\s{1}\.\.\.\B/, " ..."));
return row;
}
};
};
function getRowNumber(width,fontsize){
return Math.floor(width/fontsize);
}
function getCountNumber(row,rowNum){
return row*rowNum;
}
function getFinalStyle(obj, property, fontSize)
{
var s;
if (undefined !== obj && obj !== null && !!obj.currentStyle) {
s = parseInt(obj.currentStyle[property].replace("px", ""));
}
else if (window.getComputedStyle && obj !== null &&undefined !== obj) {
s = window.getComputedStyle(obj, null)[property].replace("px", "");
}
//兼容IEbug:IE解析getComputedStyle或currentStyle,然而若line-height=1.5,它会获取计算后是1.5,而其他浏览器获得1.5*line-height
/*if(fontSize!=undefined){
s = s*fontSize ;
}*/
return s;
}
This diff could not be displayed because it is too large.
/**
* @package plugin/photoslide.js
* @author:ww(wei.wang@yoho.cn)
* @date:2014-08-19
*/
var $=require("jquery");
require("jquery.imagesloaded");
var tmpInfo=null;
window.onresize=function(){
exports.initSlide(tmpInfo);
};
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){
//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();
$(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]
}).show();
$(".photoslider_drag_message")
.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
//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){}
}
}
});
//var self=this;
}
});
});
if(isMobile||brow.bIsIpad||brow.bIsAndroid)
{
window.onresize=function(){
exports.initSlide(info);
//var tmpHtml=$(this).parent().parent().parent().html();
};
}
if(isMobile===false)
photos.bind({
"mousemove":function(event){
var pointX = event.pageX;
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");
drag_handler.fadeOut();
},
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){
$(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;
}
/**
* @author DELL
*/
/*
* @fileOverview 弹出层组件
* @author:王威
* @date:2014-09-19
* yohoo-share-button-sina
* yohoo-share-button-facebook
* yohoo-share-button-tweet
* fbAppId:YohoConfig.girl.fbAppId,'657464311006064',
fbUrl:YohoConfig.girl.mainUrl+'/channel/yohood/closedialog',
*/
var $=require("jquery");
exports.init=function(info){
var defaults={
width:800,
height:500,
img:"",
imgFunction:null,
sinaText:"",
sinaTextFunction:null,
tweetText:"",
tweetTextFunction:null,
fbCaption:"",
fbDescription:"",
fbName:"",
fbTextFunction:null,
shareUrl:"",
shareUrlFunction:null,
fbAppId:"",
fbUrl:"",
qqText:""
};
var options=$.extend(defaults,info);
$(".yohoo-share-button-sina").unbind().on("click", function()
{
if(options.sinaTextFunction!==null)
{
options.sinaText=(function(){
return options.sinaTextFunction.apply($(".yohoo-share-button-sina"));
})();
}
options.sinaText=options.sinaText.replace(/[ ]/g, "%20")
.replace(/[&]/g,"%26")
.replace(/[#]/g,"%23")
.replace(/[+]/g,"%2B");
window.sharetitle = options.sinaText;
if(options.imgFunction!==null)
{
options.img=(function(){
return options.imgFunction.apply($(".yohoo-share-button-sina"));
})();
}
window.shareUrl = options.img;
share();
});
if(options.shareUrlFunction!==null)
{
options.shareUrl=(function(){
return options.shareUrlFunction.apply({sina:$(".yohoo-share-button-sina"),
facebook:$(".yohoo-share-button-facebook"),
tweet:$(".yohoo-share-button-tweet")});
})();
}
else
{
options.shareUrl=options.shareUrl===""?document.location.href:options.shareUrl;
}
function share() {
(function(s, d, e) {
/*try {
} catch (err) {
}*/
var f = 'http://v.t.sina.com.cn/share/share.php?', u = options.shareUrl, p = ['url=', e(u), '&title=', e(window.sharetitle+' @YOHO潮流志'), '&appkey=3910025296', '&pic=', e(window.shareUrl)].join('');
function a() {
if (!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=620,height=450,left=', (s.width - 620) / 2, ',top=', (s.height - 450) / 2].join('')))
u.href = [f, p].join('');
}
if (/Firefox/.test(navigator.userAgent)) {
setTimeout(a, 0);
} else {
a();
}
})(screen, document, encodeURIComponent);
}
var iTop = (window.screen.availHeight - 30 - options.height) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - options.width) / 2; //获得窗口的水平位置;
$(".yohoo-share-button-facebook").unbind().on("click",function() {
if(options.imgFunction!==null)
{
options.img=(function(){
return options.imgFunction.apply($(".yohoo-share-button-facebook"));
})();
}
var tmpResult={des:"",name:"",caption:""};
if(options.fbTextFunction!==null)
{
tmpResult=(function(){
return options.fbTextFunction.apply($(".yohoo-share-button-facebook"));
})();
if (!tmpResult.url)
{
options.fbCaption=tmpResult.caption;
options.fbDescription=tmpResult.des;
options.fbName=tmpResult.name;
}
else
{
options.fbUrl = tmpResult.url;
}
}
if (options.fbUrl)
{
window.open("https://www.facebook.com/sharer/sharer.php?u=" + options.fbUrl, "",
"height="+options.height+",width="+options.width+",left=" + iLeft + ",top=" + iTop);
}
else
{
options.fbCaption=options.fbCaption.replace(/[ ]/g, "%20")
.replace(/[&]/g,"%26")
.replace(/[#]/g,"%23")
.replace(/[+]/g,"%2B");
options.fbDescription=tmpResult.des.replace(/[ ]/g, "%20")
.replace(/[&]/g,"%26")
.replace(/[#]/g,"%23")
.replace(/[+]/g,"%2B");
options.fbName=tmpResult.name.replace(/[ ]/g, "%20")
.replace(/[&]/g,"%26")
.replace(/[#]/g,"%23")
.replace(/[+]/g,"%2B");
window.open("http://www.facebook.com/dialog/feed?app_id=1431491300468916&redirect_uri=http://www.yohoboys.com/channel/yohood/closedialog&" +
"link=" + options.shareUrl +
"&picture=" + options.img+
"&caption=" +options.fbName+
"&description="+options.fbDescription+(options.fbDescription===""?"":"(分享自 @yohoboy)")+
"&name="+options.fbCaption,
"",
"height="+options.height+",width="+options.width+",left=" + iLeft + ",top=" + iTop);
}
});
$(".yohoo-share-button-tweet").unbind().on("click",function() {
if(options.tweetTextFunction!==null)
{
options.tweetText=(function(){
return options.tweetTextFunction.apply($(".yohoo-share-button-tweet"));
})();
}
options.tweetText=options.tweetText.replace(/[ ]/g, "%20")
.replace(/[&]/g,"%26")
.replace(/[#]/g,"%23")
.replace(/[+]/g,"%2B");
window.open("http://twitter.com/intent/tweet?url=" + options.shareUrl +
"&text="+options.tweetText,
"",
"height="+options.height+",width="+options.width+",left=" + iLeft + ",top=" + iTop);
});
$(".yohoo-share-button-qq").unbind().on("click",function(){
window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+ options.shareUrl+
'&title='+options.qqText+'&summary= '+
'&pics='+options.img,'_blank','height='+options.height+',width='+options.width+',left='+iLeft+',top='+iTop);
});
};
$(".yohoo-share-button-wx").on("mouseover",function(){
$(".wx-qrcode-dialog").show();
}).on("mouseout",function(){
$(".wx-qrcode-dialog").hide();
});
//ipad微信
$(".detail-container").on("click.closeWxDialog",function(event){
if($(event.target).is(".yohoo-share-button-wx") || $(event.target).parents(".yohoo-share-button-wx").size()>0){
$(".wx-qrcode-dialog").show();
}else{
$(".wx-qrcode-dialog").hide();
}
});
$(".bottom-content").on("click.closeWxDialog",function(){
$(".detail-container").trigger("click.closeWxDialog");
});
$(".enterprise").on("click.closeWxDialog",function(){
$(".detail-container").trigger("click.closeWxDialog");
});
/*
评论及登录插件
author:liuyue
date:2015-01-07
*/
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.init();
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);
};
Slider.DEFAULTS = {
pageCtrl:'',
ctrlShowNum:6,
prevBtn:$(".detail-slide-ctrl-prev"),
nextBtn:$(".detail-slide-ctrl-next")
};
Slider.prototype = {
init:function(){
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){
$(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() {
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) {
offset = '+=' + offset;
}
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);
\ No newline at end of file
var dic=require("./DicTips");
exports.getTips=function(key){
if(isJian())
{
return dic.Dic[key+"_jian"];
}
else
{
return dic.Dic[key+"_fan"];
}
};
exports.isJian=isJian;
function isJian(){
var currentDomain=YohoConfig.mainUrl;
if(currentDomain.indexOf("hk")>=0)
{
return false;//false,繁体
}
return true;//简体,
}
window.DicTips={
};
/**
* @fileOverview 发布组件
* @author:xmg
* @date:2013-01-14
*/
//邮箱检测
exports.isEmail = function (val)
{
var mailValid = /^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
return mailValid.test(val);
};
//手机检测
exports.isMobile = function (val)
{
//var mobileValid = /^(1)([0-9]{10})$/;
var mobileValid = /^1[3|4|5|8][0-9]\d{8}$/ ;
return mobileValid.test(val);
};
//昵称检测
exports.isNickname = function (val)
{
var valid = /^[\u4E00-\u9FA5A-Za-z0-9_-]{2,32}$/;
return valid.test(val);
};
//是否整数
exports.isInt = function (val)
{
var mobileValid = /^\d$/ ;
return mobileValid.test(val);
};
//是否浮点数
exports.isFloat = function (val)
{
var mobileValid = /^\d+(\.\d+)?$/ ;
return mobileValid.test(val);
};
/*
* @description: h5 js
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require('jquery');
var swiper = require('yoho.swiper');
var Hammer = require('hammerjs');
var tools = require('yoho-tools');
var mulLine = require('./plugin/mlellipsis');
var box = require('./plugin/box');
var tips = require("./plugin/tips");
require('lazyload');
require("./plugin/login");
//public banner
var publicSwiper = new swiper('.public-banner',{
mode:'horizontal',
loop: true,
pagination: '.pagination',
grabCursor: true,
paginationClickable: true,
autoplay: 5000,
slideElement: 'li',
onSlideChangeEnd: function () {
publicSwiper.startAutoplay();
$(".relazy").lazyload({threshold: 100});
}
});
//侧边栏展开、折叠
var isExpand = true;
var oNav = $('.nav-bar');
var wrap = $('#mobile');
var side = $('#side-bar');
var wW = $(window).width();
var nav = new Hammer(document.getElementById('mobile-wrap'),{time:50});
nav.on('tap',function (event) {
if ($(event.target).is(oNav)) {
side.css('visibility','visible');
wrap.addClass('menuOpen').css({
'height':'100%',
'min-height':'580px',
'overflow-y':'hidden',
'overflow-x':'hidden'
});
$('.header-download').css('left',0);
isExpand = false;
event.preventDefault();
}else {
if (!isExpand) {
wrap.removeClass('menuOpen').css({
'height':'auto',
'overflow-y':'auto',
'overflow-x':'hidden'
});
setTimeout(function () {
side.css('visibility','hidden');
$('.header-download').css({
'left':(wW-320)/2
});
},500);
}
}
});
var oLogin = $(".side-bar-header");
oLogin.login();
oLogin.click(function () {
$(this).login("loginBoxAnimate");
});
//关闭顶部浮层
$('.tip-c').click(function () {
$('.header-download-wrap').remove();
});
//滚动到顶部
var top = new Hammer(document.getElementById('back-top'));
top.on('tap',function () {
$('#mobile').animate({scrollTop: 0});
});
//懒加载
$(".lazy").lazyload({threshold: 100});
//rss
var oRss = $(".rss input");
if (oRss.length>0) {
$(".rss-btn").click(function(){
if(oRss.val()==='') {
box.alert(tips.getTips("emailEmpty"));
return;
}
if(!tools.IYOHO_isEmail(oRss.val())) {
box.alert(tips.getTips("emailError"));
return;
}
window.open( '/passport/subscribe/index?email='+oRss.val());
});
oRss.keydown(function(event){
if(event.keyCode===13) {
$(".rss-btn").trigger("click");
}
});
}
//截字
(function () {
var items=$(".home-content li");
if(items.length > 0) {
var detailStr = "";
items.each(function(index,obj){
detailStr = $(obj).find(".a-detail").text().substring(0, 58) + " ...";
$(obj).find(".a-detail").text( detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\B/, " ...") );
});
items = null;
}
})();
//获取设备类型
(function (){
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsweixin = sUserAgent.match(/MicroMessenger/i) == 'micromessenger';
var app = $('.yohoboy-download-app');
var downBtn = $('.home-download').find('.down-btn');
if(bIsIphoneOs){
app.attr('href',app.attr('ios-href'));
app.attr('onclick','openApp("'+app.attr('data-ios')+'")');
downBtn.each(function (index) {
$(this).attr('href',$(this).attr('data-ios'));
});
}
if (bIsAndroid) {
downBtn.each(function (index) {
$(this).attr('href',$(this).attr('data-android'));
});
}
if (bIsweixin) {
$('.header-download-wrap').remove();
}
})();
function openApp(link) {
var clickedAt = +new Date();
setTimeout(function(){
if (+new Date() - clickedAt < 2000) {
window.location.href = link;
}
}, 500);
}
\ No newline at end of file
... ... @@ -4,28 +4,31 @@
"description": "girlsmobile",
"keywords": [],
"homepage": "",
"author": "hbomb",
"author": "lore-w",
"repository": {
"type": "git",
"url": ""
},
"bugs": {
"url": ""
},
"licenses": "MIT",
"spm": {
"main": "index.js",
"dependencies": {
"jquery": "1.7.2",
"yoho-tools": "0.0.1",
"yoho.swiper": "2.7.0",
"hammerjs": "2.0.4",
"jquery.autocomplete": "0.0.1",
"yoho-rotate2d": "0.0.1",
"lazyload": "1.9.4",
"jquery.imagesloaded": "0.0.2",
"import-style": "1.0.0"
"jquery": "1.8.3",
"swiper-mobile": "3.0.6",
"hammer": "2.0.4",
"jgestures": "0.9.1"
},
"buildArgs": "--include standalone",
"devDependencies": {
"expect.js": "0.3.1"
}
},
"output": [
"js/**/*.js",
"!js/lib/*.js"
],
"buildArgs": "--include all"
},
"devDependencies": {
"gulp": "^3.8.11",
... ... @@ -42,4 +45,4 @@
"test": "spm test",
"build": "spm build"
}
}
}
\ No newline at end of file
... ...
... ... @@ -20,6 +20,7 @@
@import "partial/components/tag";
@import "partial/components/search";
@import "partial/components/follow-us";
@import "partial/components/banner";
//页面
... ...
... ... @@ -2,33 +2,4 @@
* @description: video css
* @author: chenglong.wang@yoho.cn
* @date: 2015/4/16
*/
#fashion {
.banner {
.swiper-pagination-switch {
@include retina-sprite($icons, normal-fashion);
margin-right: 5px;
float: left;
&:nth-last-of-type(1) {
margin-right: 0;
}
&.swiper-active-switch {
@include retina-sprite($icons, active-fashion);
}
}
}
/*.img-link {
&:after {
@include retina-sprite($icons, channel-fashion);
}
}*/
/*.content-item {
> h2, h3 {
color: #9999ff;
}
}*/
}
\ No newline at end of file
*/
\ No newline at end of file
... ...