// 棣栭〉銆佸垪琛ㄩ〉绛夊姞鍏ヨ喘鐗╄溅 function ShopAddCart1625194556(aid, spec_value_id, num, rootDir) { rootDir = rootDir ? rootDir : ''; $.ajax({ url : rootDir + '/index.php?m=user&c=Shop&a=shop_add_cart&_ajax=1', data: {aid: aid, num: num, spec_value_id: spec_value_id}, type:'post', dataType:'json', success:function(res){ if (1 == res.code) { window.location.href = res.url; } else { if (-1 == res.data.code) { layer.msg(res.msg, {time: time}); } else { // 鍘荤櫥闄 window.location.href = res.url; } } } }); } /** * 閿氱偣 - 鍐呭椤垫樉绀虹洰褰曞ぇ绾 * @param {[type]} toc_id [鐩綍澶х翰鐨勬渶澶栧眰鍏冪礌id] * @param {[type]} content_id [鍐呭鐨勫厓绱爄d] * @return {[type]} [description] */ function ey_outline_toc(content_id, toc_id, scrollTop) { setTimeout(function(){ // 鏄惁瑕佹樉绀虹洰褰曞ぇ绾 var is_show_toc = false; // 鑾峰彇瑕佹樉绀虹洰褰曠殑鍏冪礌 const tocContainer = document.getElementById(toc_id); if (tocContainer) { // 鑾峰彇瑕佹彁鍙杊2\h3\h4\h5\h6鐨勫唴瀹瑰厓绱 const articleObj = document.getElementById(content_id); // 鑾峰彇鎵€鏈夋爣棰樺厓绱 if (articleObj) { const headers = articleObj.querySelectorAll('h2, h3'); // 鍐呭閲屾槸鍚﹀瓨鍦╤2\h3\h4\h5\h6鏍囩 if (headers.length > 0) { // 鑾峰彇閿氱偣 var anchor = window.location.hash; // 鍒涘缓鐩綍鍒楄〃 const tocList = document.createElement('ul'); // 閬嶅巻鏍囬鍏冪礌锛屽垱寤虹洰褰曢」 headers.forEach((header) => { const level = header.tagName.substr(1); const tocItem = document.createElement('li'); const link = document.createElement('a'); var name = ''; if (header.id) { name = header.id; } else if (header.querySelector('a') && header.querySelector('a').name) { name = header.querySelector('a').name; } if (name) { var data_top = -1; try { data_top = $("#"+content_id+" a[name='" + name + "']").offset().top; }catch(err){} link.setAttribute('data-top', data_top); if (anchor.length > 0 && anchor == `#${name}`) { link.setAttribute('class', 'ey_toc_selected'); } link.href = `#${name}`; link.textContent = name; tocItem.appendChild(link); tocItem.setAttribute('class', `ey_toc_h${level}`); tocItem.style.paddingLeft = ((level - 2) * 1) + 'em'; tocList.appendChild(tocItem); // 鏄剧ず鐩綍澶х翰 is_show_toc = true; } }); if (is_show_toc) { // 灏嗙洰褰曞垪琛ㄦ坊鍔犲埌瀹瑰櫒涓 tocContainer.appendChild(tocList); } } } if (is_show_toc) { tocContainer.style.display = "block"; // 鑷姩缁戝畾鐐瑰嚮婊戝姩浜嬩欢 if (window.jQuery) { if (!scrollTop) scrollTop = 'unbind'; if ('unbind' != scrollTop) { $('#'+toc_id+' ul li').on('click', function(){ var aObj = $(this).find('a'); var name = aObj.attr('data-name'); if (!name) { name = aObj.attr('href'); name = name.replace('#', ''); aObj.attr('data-name', name); } // aObj.attr('href', 'javascript:void(0);'); aObj.attr('data-name', name); $('#'+toc_id+' ul li').find('a').removeClass('ey_toc_selected'); aObj.addClass('ey_toc_selected'); var contentObj = $("#"+content_id+" a[name='" + name + "']"); if (0 < contentObj.length) { var data_top = aObj.attr('data-top'); if (data_top <= -1) { data_top = contentObj.offset().top; } $("html,body").animate({ scrollTop: data_top - scrollTop }) } }); // 鍒锋柊椤甸潰鑷姩瀹氫綅鍒伴敋鐐逛綅缃 setTimeout(function(){ $('#'+toc_id+' ul li').find('a.ey_toc_selected').click(); }, 300); } } } } }, 10); } /** * 璁剧疆cookie * @param {[type]} name [description] * @param {[type]} value [description] * @param {[type]} time [description] */ function ey_setCookies(name, value, time) { var cookieString = name + "=" + escape(value) + ";"; if (time != 0) { var Times = new Date(); Times.setTime(Times.getTime() + time); cookieString += "expires="+Times.toGMTString()+";" } document.cookie = cookieString+"path=/"; } // 璇诲彇 cookie function getCookie(c_name) { if (document.cookie.length>0) { c_start = document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return ""; } function ey_getCookie(c_name) { return getCookie(c_name); } function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }