Showing
3 changed files
with
194 additions
and
17 deletions
@@ -301,13 +301,14 @@ define("js/header", ["jquery","handlebars","source-map","index"], function(requi | @@ -301,13 +301,14 @@ define("js/header", ["jquery","handlebars","source-map","index"], function(requi | ||
301 | * @author: wangqing<robin.wang@yoho.cn> | 301 | * @author: wangqing<robin.wang@yoho.cn> |
302 | * @date: 2015/12/01 | 302 | * @date: 2015/12/01 |
303 | */ | 303 | */ |
304 | - | ||
305 | - | ||
306 | var $ = require("jquery"); | 304 | var $ = require("jquery"); |
307 | var handlebars = require("handlebars"); | 305 | var handlebars = require("handlebars"); |
308 | var json2 = require("index"); | 306 | var json2 = require("index"); |
309 | var noticeSuccess = false; | 307 | var noticeSuccess = false; |
310 | - | 308 | +var vipInfoCombine = null; |
309 | +var loginInfoCombine = null; | ||
310 | +var apiDomain = 'http://api.open.yohobuy.com'; | ||
311 | +var cartTpl = ''; | ||
311 | /** | 312 | /** |
312 | * 判断为1的helper | 313 | * 判断为1的helper |
313 | * @param {[type]} v1 [description] | 314 | * @param {[type]} v1 [description] |
@@ -322,6 +323,37 @@ handlebars.registerHelper('equalone', function(v1, options) { | @@ -322,6 +323,37 @@ handlebars.registerHelper('equalone', function(v1, options) { | ||
322 | return options.inverse(this); | 323 | return options.inverse(this); |
323 | } | 324 | } |
324 | }); | 325 | }); |
326 | +/** | ||
327 | + * 判断等级为3的helper | ||
328 | + * @param {[type]} v1 [description] | ||
329 | + * @param {[type]} options) { if (v1 [description] | ||
330 | + * @return {[type]} [description] | ||
331 | + */ | ||
332 | + | ||
333 | +handlebars.registerHelper('equallevelthree', function(v1, options) { | ||
334 | + | ||
335 | + if (v1 === '3') { | ||
336 | + return options.fn(this); | ||
337 | + } else { | ||
338 | + return options.inverse(this); | ||
339 | + } | ||
340 | +}); | ||
341 | + | ||
342 | +/** | ||
343 | + * 判断为0的helper | ||
344 | + * @param {[type]} v1 [description] | ||
345 | + * @param {[type]} options) { if (v1 [description] | ||
346 | + * @return {[type]} [description] | ||
347 | + */ | ||
348 | + | ||
349 | +handlebars.registerHelper('equalzero', function(v1, options) { | ||
350 | + | ||
351 | + if (v1 === '0') { | ||
352 | + return options.fn(this); | ||
353 | + } else { | ||
354 | + return options.inverse(this); | ||
355 | + } | ||
356 | +}); | ||
325 | require("plugin/yohocookie"); | 357 | require("plugin/yohocookie"); |
326 | require("plugin/yohocart"); | 358 | require("plugin/yohocart"); |
327 | /** | 359 | /** |
@@ -566,13 +598,15 @@ function fadeAnimate() { | @@ -566,13 +598,15 @@ function fadeAnimate() { | ||
566 | } | 598 | } |
567 | window.$logotrans.fadeOut(window.loopdurationtime, function() { | 599 | window.$logotrans.fadeOut(window.loopdurationtime, function() { |
568 | window.isen = false; | 600 | window.isen = false; |
601 | + | ||
569 | window.$logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo.png)'); | 602 | window.$logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo.png)'); |
570 | window.$logotrans.fadeIn(window.loopdurationtime, function() { | 603 | window.$logotrans.fadeIn(window.loopdurationtime, function() { |
571 | window.onetimeoout = window.setTimeout(function() { | 604 | window.onetimeoout = window.setTimeout(function() { |
572 | window.$logotrans.fadeOut(window.loopdurationtime, function() { | 605 | window.$logotrans.fadeOut(window.loopdurationtime, function() { |
573 | window.clearTimeout(window.onetimeoout); | 606 | window.clearTimeout(window.onetimeoout); |
574 | window.isen = true; | 607 | window.isen = true; |
575 | - window.$logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo_e.png)'); | 608 | + window.$logotrans.css('background-image', |
609 | + 'url(http://static.yohobuy.com/newheader/img/logo_e.png)'); | ||
576 | window.$logotrans.fadeIn(window.loopdurationtime, function() { | 610 | window.$logotrans.fadeIn(window.loopdurationtime, function() { |
577 | window.globaltimeout = window.setTimeout(fadeAnimate, 1 * 60 * 1000); | 611 | window.globaltimeout = window.setTimeout(fadeAnimate, 1 * 60 * 1000); |
578 | }); | 612 | }); |
@@ -857,7 +891,7 @@ function loadCartData() { | @@ -857,7 +891,7 @@ function loadCartData() { | ||
857 | shoppingData, | 891 | shoppingData, |
858 | strK; | 892 | strK; |
859 | 893 | ||
860 | - $.getData(window.apiDomain, { | 894 | + $.getData(apiDomain, { |
861 | method: 'open.Shoppingcart.getCartData', | 895 | method: 'open.Shoppingcart.getCartData', |
862 | shopping_key: $.getShoppingKey() | 896 | shopping_key: $.getShoppingKey() |
863 | }, function(jsonData) { | 897 | }, function(jsonData) { |
@@ -894,7 +928,7 @@ function loadCartData() { | @@ -894,7 +928,7 @@ function loadCartData() { | ||
894 | * @return {[type]} [description] | 928 | * @return {[type]} [description] |
895 | */ | 929 | */ |
896 | function delCartGoods(id, isreduce) { | 930 | function delCartGoods(id, isreduce) { |
897 | - $.getData(window.apiDomain, { | 931 | + $.getData(apiDomain, { |
898 | method: 'open.Shoppingcart.delone', | 932 | method: 'open.Shoppingcart.delone', |
899 | shopping_key: $.getShoppingKey(), | 933 | shopping_key: $.getShoppingKey(), |
900 | id: id, | 934 | id: id, |
@@ -912,8 +946,7 @@ function delCartGoods(id, isreduce) { | @@ -912,8 +946,7 @@ function delCartGoods(id, isreduce) { | ||
912 | actionUpdateCartNum(); | 946 | actionUpdateCartNum(); |
913 | }); | 947 | }); |
914 | } | 948 | } |
915 | -window.apiDomain = 'http://api.open.yohobuy.com'; | ||
916 | -window.cartTpl = ''; | 949 | + |
917 | 950 | ||
918 | /** | 951 | /** |
919 | * 监听购物车删除 | 952 | * 监听购物车删除 |
@@ -1115,6 +1148,7 @@ function actionExeTemplate() { | @@ -1115,6 +1148,7 @@ function actionExeTemplate() { | ||
1115 | var resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, ''); | 1148 | var resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, ''); |
1116 | 1149 | ||
1117 | $('#goodcartempwarpper').html(resulthtml); | 1150 | $('#goodcartempwarpper').html(resulthtml); |
1151 | + vipInfoCombine = handlebars.compile($('#tmpl-my-login-new').html()); | ||
1118 | } | 1152 | } |
1119 | /** | 1153 | /** |
1120 | * 执行搜索 | 1154 | * 执行搜索 |
@@ -1126,6 +1160,148 @@ function actionSearch() { | @@ -1126,6 +1160,148 @@ function actionSearch() { | ||
1126 | $('#query_key').search(searchDomain); | 1160 | $('#query_key').search(searchDomain); |
1127 | } | 1161 | } |
1128 | /** | 1162 | /** |
1163 | + * 获取登录状态 | ||
1164 | + * @return {[type]} [description] | ||
1165 | + */ | ||
1166 | +function actionLoginState(_data) { | ||
1167 | + var timestamp = new Date().getTime(); | ||
1168 | + var noLoginHtml = '<span>Hi~</span>[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out ">' + | ||
1169 | + '请登录</a>] ' + | ||
1170 | + '[<a href="http://www.yohobuy.com/reg.html" class="list-a login-out" onclick="">免费注册</a>]'; | ||
1171 | + var loginHtml = '<span>Hi~<a href="http://www.yohobuy.com/home?t=' + timestamp + | ||
1172 | + '">{{user_name}}</a></span> ' + | ||
1173 | + '{{#equalone islogin}}' + | ||
1174 | + '[<a href="{{logout}}" class="list-a login-out">退出</a>]' + | ||
1175 | + '{{else}}' + | ||
1176 | + '[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out">请登录</a>] ' + | ||
1177 | + '[<a href="http://www.yohobuy.com/reg.html" onclick="" class="list-a login-out">免费注册</a>]' + | ||
1178 | + '{{/equalone}}'; | ||
1179 | + var $boxObj = $('#loginBox'); | ||
1180 | + var info = $.cookie('_UID')||''; | ||
1181 | + var name = _data.data.profile_name||''; | ||
1182 | + var _length = 0; | ||
1183 | + var t = 0; | ||
1184 | + var char = ''; | ||
1185 | + var user = info.split('::')||''; | ||
1186 | + var userName = user[0] || ' '; | ||
1187 | + var _logout = ''; | ||
1188 | + var islogin = '1'; | ||
1189 | + var _num = 0; | ||
1190 | + var data = { | ||
1191 | + user_name: name, | ||
1192 | + logout: _logout, | ||
1193 | + random: Math.random() | ||
1194 | + }; | ||
1195 | + | ||
1196 | + | ||
1197 | + loginInfoCombine = handlebars.compile(loginHtml); | ||
1198 | + if (typeof info === 'undefined' || info === null) { | ||
1199 | + $boxObj.html(noLoginHtml); | ||
1200 | + return false; | ||
1201 | + } | ||
1202 | + if (typeof user === 'undefined' || user.length < 4) { | ||
1203 | + $boxObj.html(noLoginHtml); | ||
1204 | + return false; | ||
1205 | + } | ||
1206 | + | ||
1207 | + for (t; t < userName.length; t++) { | ||
1208 | + char = userName.substr(t, 1); | ||
1209 | + if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) { | ||
1210 | + _length += 2; | ||
1211 | + } else { | ||
1212 | + _length += 1; | ||
1213 | + } | ||
1214 | + } | ||
1215 | + if (_length <= 10) { | ||
1216 | + name = userName; | ||
1217 | + } else { | ||
1218 | + _num = 0; | ||
1219 | + for (t; t < userName.length; t++) { | ||
1220 | + if (_num < 10) { | ||
1221 | + char = userName.substr(t, 1); | ||
1222 | + if (char !== '*') { | ||
1223 | + if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) { | ||
1224 | + _num += 2; | ||
1225 | + } else { | ||
1226 | + _num += 1; | ||
1227 | + } | ||
1228 | + } | ||
1229 | + name += char; | ||
1230 | + } | ||
1231 | + } | ||
1232 | + if (name.length < userName.length) { | ||
1233 | + name += '...'; | ||
1234 | + } | ||
1235 | + } | ||
1236 | + | ||
1237 | + | ||
1238 | + if (/http:\/\//.test(user[3])) { | ||
1239 | + _logout = user[3].replace('www.yohobuy.com', 'www.yohobuy.com'); | ||
1240 | + } else { | ||
1241 | + _logout = 'http://www.yohobuy.com/logout_' + user[3] + '.html'; | ||
1242 | + } | ||
1243 | + if (_data.result === -1) { | ||
1244 | + islogin = '-1'; | ||
1245 | + } | ||
1246 | + data.islogin = islogin; | ||
1247 | + $boxObj.html(loginInfoCombine(data)); | ||
1248 | +} | ||
1249 | +/** | ||
1250 | + * 获得vip用户信息 | ||
1251 | + * @return {[type]} [description] | ||
1252 | + */ | ||
1253 | +function actionVipInfo(_data) { | ||
1254 | + var vipInfo = _data.data; | ||
1255 | + var headUrl = ''; | ||
1256 | + | ||
1257 | + if (_data.result === 1) { | ||
1258 | + if (typeof vipInfo === undefined || vipInfo.length < 1) { | ||
1259 | + return false; | ||
1260 | + } | ||
1261 | + $('#myYohoBox').mouseenter(function() { | ||
1262 | + $(this).addClass('acttags'); | ||
1263 | + $('#myYohoBox .myyoho-info').show().html(vipInfoCombine(vipInfo)); | ||
1264 | + headUrl = $('.myyoho-photo img').attr('data-url'); | ||
1265 | + if ($._checkUrlState === 1) { | ||
1266 | + $('.myyoho-photo').show().find('img').attr('src', headUrl); | ||
1267 | + return; | ||
1268 | + } | ||
1269 | + if (headUrl === '' || $._checkUrl !== '') { | ||
1270 | + return; | ||
1271 | + } | ||
1272 | + $.ajax({ | ||
1273 | + url: headUrl, | ||
1274 | + type: 'GET', | ||
1275 | + complete: function(response) { | ||
1276 | + if (response.status === 200 || response.status === 0) { | ||
1277 | + $('.myyoho-photo').show().find('img').attr('src', headUrl); | ||
1278 | + $._checkUrlState = 1; | ||
1279 | + } | ||
1280 | + $._checkUrl = headUrl; | ||
1281 | + } | ||
1282 | + }); | ||
1283 | + }); | ||
1284 | + $('#myYohoBox').mouseleave(function() { | ||
1285 | + $(this).removeClass('acttags'); | ||
1286 | + $('#myYohoBox .myyoho-info').hide(); | ||
1287 | + }); | ||
1288 | + } | ||
1289 | +} | ||
1290 | +/** | ||
1291 | + * 获取登录信息 | ||
1292 | + * @return {[type]} [description] | ||
1293 | + */ | ||
1294 | +function actionLoginInfo() { | ||
1295 | + var param = { | ||
1296 | + method: 'open.passport.get' | ||
1297 | + }; | ||
1298 | + | ||
1299 | + $.getData(apiDomain, param, function(_data) { | ||
1300 | + actionLoginState(_data); // 更改登录状态 | ||
1301 | + actionVipInfo(_data); //获得vip; | ||
1302 | + }); | ||
1303 | +} | ||
1304 | +/** | ||
1129 | * 初始化函数 | 1305 | * 初始化函数 |
1130 | * @return {[type]} [description] | 1306 | * @return {[type]} [description] |
1131 | */ | 1307 | */ |
@@ -1147,6 +1323,7 @@ function init() { | @@ -1147,6 +1323,7 @@ function init() { | ||
1147 | actionClickMiniCartBox(); //点击购物车跳转 | 1323 | actionClickMiniCartBox(); //点击购物车跳转 |
1148 | actionListenDelCarGoods(); //监听购物车删除 | 1324 | actionListenDelCarGoods(); //监听购物车删除 |
1149 | actionListenCartMore(); // | 1325 | actionListenCartMore(); // |
1326 | + actionLoginInfo(); //获取登录信息 | ||
1150 | } | 1327 | } |
1151 | 1328 | ||
1152 | init(); | 1329 | init(); |
@@ -1717,6 +1894,8 @@ exports.init = function(num) { | @@ -1717,6 +1894,8 @@ exports.init = function(num) { | ||
1717 | 1894 | ||
1718 | productList = null; | 1895 | productList = null; |
1719 | 1896 | ||
1897 | + $goodItem.unbind(); | ||
1898 | + | ||
1720 | productList = productEvent($goodItem, num); | 1899 | productList = productEvent($goodItem, num); |
1721 | 1900 | ||
1722 | /** | 1901 | /** |
@@ -1834,25 +2013,25 @@ exports.init = function(num) { | @@ -1834,25 +2013,25 @@ exports.init = function(num) { | ||
1834 | display: 'none' | 2013 | display: 'none' |
1835 | }); | 2014 | }); |
1836 | }); | 2015 | }); |
2016 | +}; | ||
1837 | 2017 | ||
1838 | - //鼠标放在颜色列表上效果 | ||
1839 | - $(document).on('hover', '.good-select-color li', function() { | 2018 | +//鼠标放在颜色列表上效果 |
2019 | +$(document).on('hover', '.good-select-color li', function() { | ||
1840 | var coverImg = $(this).find('img').attr('data-cover'), | 2020 | var coverImg = $(this).find('img').attr('data-cover'), |
1841 | $coverImg = $(this).closest('.good-item-wrapper').find('.good-detail-img').find('img'); | 2021 | $coverImg = $(this).closest('.good-item-wrapper').find('.good-detail-img').find('img'); |
1842 | 2022 | ||
1843 | $coverImg.attr('src', coverImg); | 2023 | $coverImg.attr('src', coverImg); |
1844 | - }); | 2024 | +}); |
1845 | 2025 | ||
1846 | - // 左侧导航 | ||
1847 | - $productListNav.click(function() { | 2026 | +// 左侧导航 |
2027 | +$productListNav.click(function() { | ||
1848 | if ($(this).hasClass('active')) { | 2028 | if ($(this).hasClass('active')) { |
1849 | $(this).find('.sort-child-list').stop(true, true).slideUp(); | 2029 | $(this).find('.sort-child-list').stop(true, true).slideUp(); |
1850 | } else { | 2030 | } else { |
1851 | $(this).find('.sort-child-list').stop(true, true).slideDown(); | 2031 | $(this).find('.sort-child-list').stop(true, true).slideDown(); |
1852 | } | 2032 | } |
1853 | $(this).toggleClass('active'); | 2033 | $(this).toggleClass('active'); |
1854 | - }); | ||
1855 | -}; | 2034 | +}); |
1856 | }); | 2035 | }); |
1857 | define("js/common/product-event", ["jquery"], function(require, exports, module){ | 2036 | define("js/common/product-event", ["jquery"], function(require, exports, module){ |
1858 | /** | 2037 | /** |
@@ -1966,8 +2145,6 @@ module.exports = function($o, rowWidth) { | @@ -1966,8 +2145,6 @@ module.exports = function($o, rowWidth) { | ||
1966 | 2145 | ||
1967 | $o.bind('mouseenter', handleEvent); | 2146 | $o.bind('mouseenter', handleEvent); |
1968 | 2147 | ||
1969 | - //$o.bind('mouseleave', handleEvent); | ||
1970 | - | ||
1971 | return pMouseHover; | 2148 | return pMouseHover; |
1972 | }; | 2149 | }; |
1973 | }); | 2150 | }); |
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
-
Please register or login to post a comment