HEX
Server: nginx/1.28.1
System: Linux VM-0-12-opencloudos 6.6.117-45.oc9.x86_64 #1 SMP Thu Dec 4 10:26:39 CST 2025 x86_64
User: www (1000)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.waciwang.com/wp-content/themes/miragev-main/assets/js/src/home.js
import { isElementVisible } from './utils.js';


function homeInit() {
  articlesGetMore();
}


/**
 * 首页文章列表获取更多文章
 */
function articlesGetMore() {
  var btn = document.querySelector('.articles-more');
  if (!btn) return;

  btn.addEventListener('click', async function(e) {
    var that = this;
    
    if (e.target.dataset.noMore == 'true') {
      return;
    }
    
    var page = Number(e.target.dataset.currentPage) + 1;
    var url = '/wp-json/vtheme/v1/home/get-more-articles?page=' + page;
    
    that.classList.add('loading');
    that.disabled = true;

    var jsonHeaders = new Headers({'Content-Type': 'application/json' });

    try {
      var response = await fetch(url, {
        method: 'GET',
        headers: jsonHeaders
      });

      var responseJson = await response.json();
      if(response.status == '404'){
        that.dataset.noMore = 'true';
        that.querySelector('span').innerText = '已经到底了';
        that.classList.remove('loading');
        return;
      }
      if (response.status == 200) {
        that.previousElementSibling.insertAdjacentHTML("beforeend", responseJson.html_str);
        e.target.dataset.currentPage++;
      } else {
        alert(responseJson.error);
      }
      that.classList.remove('loading');
      that.disabled = false;
    } catch(e) {
      console.log(e.stack);
    }
  });

  if (btn.dataset.autoLoad == '0') return;
  window.addEventListener('scroll', function(e) {
    if(btn.dataset.autoLimit != 0 && btn.dataset.currentPage > btn.dataset.autoLimit){
      return;
    }
    if (isElementVisible(btn)) {
      if (btn.disabled == true) {
        return;
      }
      if (btn.dataset.noMore == 'true') {
        return;
      }
      btn.click();
    }
  });

}


export default {
  homeInit
};