Skip to content

Commit

Permalink
refactor: 暴力移除 Pjax [publish dev]
Browse files Browse the repository at this point in the history
  • Loading branch information
zkz098 committed Nov 1, 2024
1 parent 6b1f994 commit 58aa58e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 102 deletions.
1 change: 0 additions & 1 deletion source/js/_app/components/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const walineRecentComments = async function () {
commentTime.className = 'breadcrumb'
commentTime.innerText = `${item.nick} @ ${item.time}`
commentLink.href = root + item.href
commentLink['data-pjax-state'] = 'data-pjax-state'
commentEl.className = 'item'

commentText.appendChild(document.createElement('br'))
Expand Down
1 change: 0 additions & 1 deletion source/js/_app/components/tcomments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const twikooRecentComments = async function () {
commentTime.className = 'breadcrumb'
commentTime.innerText = `${item.nick} @ ${item.time}`
commentLink.href = root + item.href
commentLink['data-pjax-state'] = 'data-pjax-state'
commentEl.className = 'item'

commentText.appendChild(document.createElement('br'))
Expand Down
7 changes: 0 additions & 7 deletions source/js/_app/globals/globalVars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { $dom } from '../library/dom'
import Pjax from 'theme-shokax-pjax'
import initProto from '../library/proto'

export const CONFIG = shokax_CONFIG
Expand Down Expand Up @@ -29,7 +27,6 @@ export let oWinHeight = window.innerHeight
export let oWinWidth = window.innerWidth
export let LOCAL_HASH = 0
export let LOCAL_URL = window.location.href
export let pjax:Pjax

export function setSiteNavHeight (value:number):void {
siteNavHeight = value
Expand Down Expand Up @@ -66,10 +63,6 @@ export function setLocalUrl (value:string):void {
LOCAL_URL = value
}

export function setPjax (value:Pjax):void {
pjax = value
}

export function setOriginTitle (value:string):void {
originTitle = value
}
Expand Down
5 changes: 1 addition & 4 deletions source/js/_app/library/loadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getScript } from './scriptPjax'
import { CONFIG } from '../globals/globalVars'
import { createChild } from './proto'

Expand All @@ -19,9 +18,7 @@ const assetUrl = (asset: string, type: string): string => {

export const vendorJs = (type: string, callback?: Function, condition?: string) => {
if (LOCAL[type]) {
getScript(assetUrl('js', type),CONFIG['js'][type].sri, callback || function () {
window[type] = true
}, condition || window[type])
assetUrl('js', type)
}
}

Expand Down
56 changes: 0 additions & 56 deletions source/js/_app/library/scriptPjax.ts

This file was deleted.

8 changes: 2 additions & 6 deletions source/js/_app/page/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { HitHighlightResult } from 'instantsearch.js/es/types/results'
import instantsearch from 'instantsearch.js'
import { liteClient as algoliasearch } from 'algoliasearch/lite'

export function algoliaSearch (pjax) {
export function algoliaSearch () {
const search = instantsearch({
indexName: CONFIG.search.indexName,
searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
Expand All @@ -18,10 +18,6 @@ export function algoliaSearch (pjax) {
}
})

search.on('render', () => {
pjax.refresh(document.getElementById("search-hits"))
})

// Registering Widgets
search.addWidgets([
configure({
Expand Down Expand Up @@ -105,7 +101,7 @@ export function algoliaSearch (pjax) {
}
})
document.querySelector('.close-btn').addEventListener('click', onPopupClose)
window.addEventListener('pjax:success', onPopupClose)
// window.addEventListener('pjax:success', onPopupClose)
window.addEventListener('keyup', (event) => {
if (event.key === 'Escape') {
onPopupClose()
Expand Down
5 changes: 0 additions & 5 deletions source/js/_app/pjax/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { $dom } from '../library/dom'
import { cardActive } from '../page/common'
import { pageScroll, transition } from '../library/anime'
import { vendorCss, vendorJs } from '../library/loadFile'
import { pjaxScript } from '../library/scriptPjax'
import { resizeHandle } from '../globals/handles'
import {
CONFIG,
Expand Down Expand Up @@ -61,10 +60,6 @@ export const siteRefresh = async (reload) => {
lazyBg.observe(el)
})

if (reload !== 1) {
$dom.each('script[data-pjax]', pjaxScript)
}

setOriginTitle(document.title)

resizeHandle()
Expand Down
31 changes: 9 additions & 22 deletions source/js/_app/pjax/siteInit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import domInit from './domInit'
import { pjaxReload, siteRefresh } from './refresh'
import { siteRefresh } from './refresh'
import { cloudflareInit } from '../components/cloudflare'
import { BODY, CONFIG, pjax, setPjax, setSiteSearch, siteSearch } from '../globals/globalVars'
import { BODY, CONFIG, setSiteSearch, siteSearch } from '../globals/globalVars'
import { autoDarkmode, themeColorListener } from '../globals/themeColor'
import { resizeHandle, scrollHandle, visibilityListener } from '../globals/handles'
import { pagePosition } from '../globals/tools'
import Pjax from 'theme-shokax-pjax'
import { initVue } from '../library/vue'
import { $dom } from '../library/dom'
import { createChild } from '../library/proto'
Expand All @@ -15,18 +14,6 @@ const siteInit = async () => {
initVue()
domInit()

setPjax(new Pjax({
selectors: [
'head title',
'.languages',
'.twikoo',
'.pjax',
'.leancloud-recent-comment',
'script[data-config]'
],
cacheBust: false
}))

CONFIG.quicklink.ignores = LOCAL.ignores
import('quicklink').then(({listen}) => {
listen(CONFIG.quicklink)
Expand All @@ -53,7 +40,7 @@ const siteInit = async () => {
}

import('../page/search').then(({algoliaSearch}) => {
algoliaSearch(pjax)
algoliaSearch()
})

// Handle and trigger popup window
Expand Down Expand Up @@ -83,13 +70,13 @@ const siteInit = async () => {
passive: true
})

window.addEventListener('pjax:send', pjaxReload, {
passive: true
})
// window.addEventListener('pjax:send', pjaxReload, {
// passive: true
// })

window.addEventListener('pjax:success', siteRefresh, {
passive: true
}) // 默认会传入一个event参数
// window.addEventListener('pjax:success', siteRefresh, {
// passive: true
// }) // 默认会传入一个event参数

window.addEventListener('beforeunload', () => {
pagePosition()
Expand Down

0 comments on commit 58aa58e

Please sign in to comment.