Authored by xuqi

Merge branch 'feature/plus-star' of git.dev.yoho.cn:web/yohobuy-frontend into feature/plus-star

1 -/**  
2 - * plus+star页js  
3 - * @author: xuqi(qi.xu@yoho.cn)  
4 - * @date;2015/4/16  
5 - */  
6 -  
7 -var $ = require('jquery'),  
8 - Mustache = require('mustache'),  
9 - ellipsis = require('mlellipsis');  
10 -  
11 -require('lazyload');  
12 -  
13 -/**  
14 - * 初始化页面功能  
15 - */  
16 -exports.init = function() {  
17 - $(function() {  
18 - var $intro = $('#intro'),  
19 - $infoContent = $('#info-content'),  
20 - $loadMore = $('#load-more-info'),  
21 - $loadStatus = $loadMore.children('.status'),  
22 - $loading = $loadStatus.filter('.loading'),  
23 - $noMore = $loadStatus.filter('.no-more'),  
24 - loadMoreH = $loadMore.height(),  
25 - winH = $(window).height(),  
26 - dataEnd = false,  
27 - canScroll = true,  
28 - tpl;  
29 -  
30 - //获取相关资讯模板  
31 - $.get('/ps/readTpl', function(data) {  
32 - if (data.success) {  
33 - tpl = data.data;  
34 - Mustache.parse(tpl); //pre-compile and cache template  
35 - }  
36 - });  
37 -  
38 - //文字截取  
39 - ellipsis.init();  
40 - setTimeout(function() {  
41 - $intro.mlellipsis(4); //品牌介绍  
42 - $('.info-block-content').each(function() { //相关文章  
43 - $(this).mlellipsis(2);  
44 - });  
45 - }, 0);  
46 -  
47 - //lazyload  
48 - $('img.lazy').lazyload();  
49 -  
50 - //显示品牌介绍所有文字  
51 - function showMoreIntro() {  
52 - var intro = $intro.attr('_title');  
53 -  
54 - $intro.text(intro);  
55 -  
56 - $('#more-intro .more').css('visibility', 'hidden');  
57 - }  
58 -  
59 - $('#more-intro').delegate('.more', 'touchstart', function(e) {  
60 - e.preventDefault();  
61 - showMoreIntro();  
62 - }).delegate('.more', 'click', function() {  
63 - showMoreIntro();  
64 - });  
65 -  
66 - //下拉加载更多  
67 - $(window).scroll(function() {  
68 - var count;  
69 -  
70 - if (!canScroll) {  
71 - return;  
72 - }  
73 -  
74 - if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {  
75 - //loadData  
76 - if (!dataEnd) {  
77 - count = $infoContent.children('.info-block').length;  
78 - canScroll = false;  
79 - $.ajax({  
80 - type: 'GET',  
81 - url: '/ps/loadInfo',  
82 - data: {  
83 - start: count  
84 - }  
85 - }).then(function(data) {  
86 - var html = '',  
87 - res,  
88 - i;  
89 - if (data.success) {  
90 - if (data.end) {  
91 - dataEnd = true;  
92 -  
93 - $loading.addClass('hide');  
94 - $noMore.removeClass('hide');  
95 - }  
96 - res = data.data;  
97 - for (i = 0; i < res.length; i++) {  
98 - html += Mustache.render(tpl, res[i]);  
99 - }  
100 - if (html !== '') {  
101 - $infoContent.append(html);  
102 -  
103 - //lazyload 不包含src即未加载的图片  
104 - $('img.lazy:not([src])').lazyload({  
105 - container: $infoContent  
106 - });  
107 - }  
108 - canScroll = true;  
109 - }  
110 - });  
111 - }  
112 - }  
113 - });  
114 - }); 1 +/**
  2 + * plus+star页js
  3 + * @author: xuqi(qi.xu@yoho.cn)
  4 + * @date;2015/4/16
  5 + */
  6 +
  7 +var $ = require('jquery'),
  8 + Mustache = require('mustache'),
  9 + ellipsis = require('mlellipsis');
  10 +
  11 +require('lazyload');
  12 +
  13 +/**
  14 + * 初始化页面功能
  15 + */
  16 +exports.init = function() {
  17 + $(function() {
  18 + var $intro = $('#intro'),
  19 + $infoContent = $('#info-content'),
  20 + $loadMore = $('#load-more-info'),
  21 + $loadStatus = $loadMore.children('.status'),
  22 + $loading = $loadStatus.filter('.loading'),
  23 + $noMore = $loadStatus.filter('.no-more'),
  24 + loadMoreH = $loadMore.height(),
  25 + winH = $(window).height(),
  26 + dataEnd = false,
  27 + canScroll = true,
  28 + tpl;
  29 +
  30 + //获取相关资讯模板
  31 + $.get('/ps/readTpl', function(data) {
  32 + if (data.success) {
  33 + tpl = data.data;
  34 + Mustache.parse(tpl); //pre-compile and cache template
  35 + }
  36 + });
  37 +
  38 + //文字截取
  39 + ellipsis.init();
  40 + setTimeout(function() {
  41 + $intro.mlellipsis(4); //品牌介绍
  42 + $('.info-block-content').each(function() { //相关文章
  43 + $(this).mlellipsis(2);
  44 + });
  45 + }, 0);
  46 +
  47 + //lazyload
  48 + $('img.lazy').lazyload();
  49 +
  50 + //显示品牌介绍所有文字
  51 + function showMoreIntro() {
  52 + var intro = $intro.attr('_title');
  53 +
  54 + $intro.text(intro);
  55 +
  56 + $('#more-intro .more').css('visibility', 'hidden');
  57 + }
  58 +
  59 + $('#more-intro').delegate('.more', 'touchstart', function(e) {
  60 + e.preventDefault();
  61 + showMoreIntro();
  62 + }).delegate('.more', 'click', function() {
  63 + showMoreIntro();
  64 + });
  65 +
  66 + //下拉加载更多
  67 + $(window).scroll(function() {
  68 + var count;
  69 +
  70 + if (!canScroll) {
  71 + return;
  72 + }
  73 +
  74 + if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
  75 + //loadData
  76 + if (!dataEnd) {
  77 + count = $infoContent.children('.info-block').length;
  78 + canScroll = false;
  79 + $.ajax({
  80 + type: 'GET',
  81 + url: '/ps/loadInfo',
  82 + data: {
  83 + start: count
  84 + }
  85 + }).then(function(data) {
  86 + var html = '',
  87 + res,
  88 + i;
  89 + if (data.success) {
  90 + if (data.end) {
  91 + dataEnd = true;
  92 +
  93 + $loading.addClass('hide');
  94 + $noMore.removeClass('hide');
  95 + }
  96 + res = data.data;
  97 + for (i = 0; i < res.length; i++) {
  98 + html += Mustache.render(tpl, res[i]);
  99 + }
  100 + if (html !== '') {
  101 + $infoContent.append(html);
  102 +
  103 + //lazyload 不包含src即未加载的图片
  104 + $('img.lazy').lazyload({
  105 + container: $infoContent
  106 + });
  107 + }
  108 + canScroll = true;
  109 + }
  110 + });
  111 + }
  112 + }
  113 + });
  114 + });
115 }; 115 };