12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- const {
- post,
- throttle,
- imageUrlPrefix,
- config,
- getUrlArgObject
- } = require('./promise.js');
- const $ = require("jquery");
- function getInfomation() {
- var param = {
- "type": getUrlArgObject('type'),
- "name": getUrlArgObject('name'),
- "position": getUrlArgObject('position')
- };
- const uname = getUrlArgObject('uname')
- const showName = param.name
- if (param.type == 5 || param.type == 51) {
- param.type = 12;
- param.name = uname;
- }
- post(config.information, param).then((res) => {
- const data = res.data.data
- document.title = showName
- var str = '';
- var anchors = '';
- var item = '';
- if (!data) {
- $("h1").html("暂时没有数据");
- $(".anchors").css("display", "none");
- return;
- }
- var list = data.details;
- $("h1").html(showName);
- $("h1").css({
- "color": "#267FD7",
- "borderBottom": "4px solid #E9E9E9",
- "padding": "0px 60px 50px 0px"
- });
- for (var i = 0; i < list.length; i++) {
- item = list[i];
- item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
- anchors = '<li><i></i><a href="#' + item.title +
- '">' + item.title + '</a></li><li class="anchor-line"></li>';
- str = '<div class="title"><h2 id="' + item.title +
- '">'
- if (getUrlArgObject('type') == 8) {
- str += '【' + item.title + '】'
- } else {
- str += item.title
- }
- str += '</h2></div>' +
- '<div><pre>' + item.content + '</pre><div>';
- if (i != list.length - 1 && getUrlArgObject('type') != 8) {
- str += '<div class="line"></div>'
- }
- $(".infos").append(str);
- $(".anchors ul").append(anchors);
- }
- addLinkClickEvent();
- adjustHeight();
- $('.content img').bind('contextmenu', function(){
- return false
- })
- function addScrollEvent() {
- var scrollTop = $('.infos').scrollTop()
- var divHeight = 0;
- for (var i = 0; i < list.length; i++) {
- divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 40
- if (divHeight > scrollTop) {
- var anchor = 2 * i;
- $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
- return;
- }
- }
- }
- $(".infos").scroll(throttle(addScrollEvent, 200));
- })
- }
- getInfomation();
- function addLinkClickEvent() {
- $("li:first").addClass("active");
- $("li>a").on("click", function () {
- $(".active").removeClass('active');
- $(this).parent().addClass("active");
- });
- }
- function adjustHeight() {
- var ht = window.innerHeight;
- $(".content").height(ht - 145 + "px");
- }
- $(window).on('resize', function(){
- adjustHeight()
- })
|