PageSourceSearch

https://tjc.org.my/wp-content/uploads/sites/146/custom-css-js/7170.js?v=9878

js tjc.org.my collected 2026-09-24 10:18:25 UTC 8,466 bytes, 209 lines download raw bytes

1/******* Do not edit this file *******
2Simple Custom CSS and JS - by Silkypress.com
3Saved: Mar 11 2025 | 01:49:20 */
4// const testimonyAudioContainer = document.getElementById("testimony-audio-container");
5// const testimonyTitleElement = document.getElementById("current-testimony-title");
6// const readButtons = document.querySelectorAll(".read-btn");
7
8// let currentPlayingButton = null; // Track the currently playing button
9
10// readButtons.forEach(button => {
11//     button.addEventListener("click", () => {
12//         const testimonyAudioFile = button.getAttribute("data-audio");
13//         const testimonyTitle = button.getAttribute("data-title");
14// 		const icon = button.querySelector("i"); // Get the <i> icon inside the button
15
16//         // Reset previous playing button's icon
17//         if (currentPlayingButton && currentPlayingButton !== button) {
18//             currentPlayingButton.querySelector("i").className = "fas fa-play"; // Reset to Read icon
19//         }
20
21//         // Change current button icon to "Playing"
22//         icon.className = "fas fa-volume-up"; // Change to Playing icon
23//         currentPlayingButton = button;
24
25//         // Generate WordPress audio shortcode dynamically
26//         const audioShortcode = `[audio src="${testimonyAudioFile}" autoplay="true"]`;
27		
28//         // Check if WordPress provides the `wp` object (needed for processing shortcodes)
29//         if (typeof wp !== "undefined" && wp.shortcode) {
30//             // Process the shortcode and inject the player
31//             testimonyAudioContainer.innerHTML = wp.shortcode.next('audio', { src: testimonyAudioFile }).string;
32//         } else {
33//             // Fallback: Use an actual HTML5 <audio> tag with autoplay
34// 			// replace this line: 
35// 			// 
36// 			//before the "Your browser does not suppot..." evertime update button is pressed, 
37// 			//because it will auto delete afeter saved
38//             testimonyAudioContainer.innerHTML = `<audio controls autoplay style="width:100%">
39                
40//                 Your browser does not support the audio element.
41//             </audio>`;
42
43//         }
44
45//         console.log("Playing:", testimonyAudioFile);
46
47//         // Update the displayed testimony title
48//         testimonyTitleElement.textContent = testimonyTitle;
49
50//         // Ensure audio starts playing automatically after being inserted
51//         setTimeout(() => {
52//             const audioElement = testimonyAudioContainer.querySelector("audio");
53//             if (audioElement) {
54//                 audioElement.play().catch(error => console.warn("Autoplay prevented:", error));
55//             }
56//         }, 500); // Small delay to ensure audio element is available
57//     });
58// });
59
60
61
62document.addEventListener("DOMContentLoaded", function () {
63    const itemsPerPage = 5;
64    let currentPage = 1;
65    let currentPlayingButton = null; // Track the currently playing button
66
67    const listContainer = document.getElementById("audio-list");
68    const paginationContainer = document.getElementById("pagination_testimony_audio");
69    const testimonyAudioContainer = document.getElementById("testimony-audio-container");
70    const testimonyTitleElement = document.getElementById("current-testimony-title");
71
72    const readButtons = document.querySelectorAll(".read-btn");
73    const itemsArray = Array.from(readButtons);
74    const totalPages = Math.ceil(itemsArray.length / itemsPerPage);
75
76    function displayPage(page) {
77        listContainer.innerHTML = ""; // Clear list
78
79        const startIndex = (page - 1) * itemsPerPage;
80        const endIndex = startIndex + itemsPerPage;
81        const itemsToShow = itemsArray.slice(startIndex, endIndex);
82
83        itemsToShow.forEach(item => {
84            listContainer.appendChild(item.parentElement);
85        });
86
87        updatePagination();
88    }
89
90    function updatePagination() {
91        paginationContainer.innerHTML = ""; // Clear pagination
92
93        const prevButton = document.createElement("button");
94        prevButton.textContent = "上一页";
95        prevButton.disabled = currentPage === 1;
96        prevButton.classList.add("pagination-btn");
97        if (prevButton.disabled) {
98            prevButton.style.cursor = "not-allowed";
99            prevButton.style.opacity = "0.5";
100        } else {
101            prevButton.style.cursor = "pointer";
102            prevButton.style.opacity = "1";
103        }
104
105        prevButton.addEventListener("click", () => {
106            if (currentPage > 1) {
107                currentPage--;
108                displayPage(currentPage);
109            }
110        });
111		
112		const pageIndicator = document.createElement("span");
113        pageIndicator.textContent = ` 第 ${currentPage} 页,共 ${totalPages} 页 `;
114        pageIndicator.style.fontWeight = "bold";
115
116        const nextButton = document.createElement("button");
117        nextButton.textContent = "下一页";
118        nextButton.disabled = currentPage === totalPages;
119        nextButton.classList.add("pagination-btn");
120        if (nextButton.disabled) {
121            nextButton.style.cursor = "not-allowed";
122            nextButton.style.opacity = "0.5";
123        } else {
124            nextButton.style.cursor = "pointer";
125            nextButton.style.opacity = "1";
126        }
127
128        nextButton.addEventListener("click", () => {
129            if (currentPage < totalPages) {
130                currentPage++;
131                displayPage(currentPage);
132            }
133        });
134
135        paginationContainer.appendChild(prevButton);
136        paginationContainer.appendChild(pageIndicator);
137        paginationContainer.appendChild(nextButton);
138    }
139
140    function playAudio(button) {
141        const testimonyAudioFile = button.getAttribute("data-audio");
142        const testimonyTitle = button.getAttribute("data-title");
143		
144		 // Change current button icon and text to "Playing"
145		button.innerHTML = '<i class="fas fa-volume-up"></i> 正播放';
146
147		// Reset previous button's icon and text if different
148		if (currentPlayingButton && currentPlayingButton !== button) {
149			currentPlayingButton.innerHTML = '<i class="fas fa-play"></i> 聆听';
150		}
151
152		currentPlayingButton = button;
153
154//         let icon = button.querySelector("i");
155//         if (!icon) {
156//             console.error("Icon not found in button:", button);
157//             return;
158//         }
159
160//         // Reset previous button's icon
161//         if (currentPlayingButton && currentPlayingButton !== button) {
162//             let prevIcon = currentPlayingButton.querySelector("i");
163//             if (prevIcon) prevIcon.className = "fas fa-play"; // Reset to book icon
164//         }
165
166//         // Change current button icon to "Playing"
167//         icon.className = "fas fa-volume-up";
168//         currentPlayingButton = button;
169
170        // Inject WordPress audio shortcode or fallback audio tag
171        const audioShortcode = `[audio src="${testimonyAudioFile}" autoplay="true"]`;
172        if (typeof wp !== "undefined" && wp.shortcode) {
173            testimonyAudioContainer.innerHTML = wp.shortcode.next('audio', { src: testimonyAudioFile }).string;
174        } else {
175            testimonyAudioContainer.innerHTML = `<audio controls autoplay>
176                <source src="${testimonyAudioFile}" type="audio/mpeg">
177                Your browser does not support the audio element.
178            </audio>`;
179        }
180
181        console.log("Playing:", testimonyAudioFile);
182        testimonyTitleElement.textContent = `正播放: ${testimonyTitle}`;
183
184        // Ensure audio starts playing automatically
185        setTimeout(() => {
186            const audioElement = testimonyAudioContainer.querySelector("audio");
187            if (audioElement) {
188                audioElement.play().catch(error => console.warn("Autoplay prevented:", error));
189
190                 // Reset button back to "Read" with icon when audio ends
191				audioElement.onended = () => {
192					button.innerHTML = '<i class="fas fa-play"></i> 聆听';
193					currentPlayingButton = null;
194				};
195            }
196        }, 500);
197    }
198
199    // Attach event listeners to buttons
200    readButtons.forEach(button => {
201        button.addEventListener("click", function () {
202            playAudio(this);
203        });
204    });
205
206    // Initialize
207    displayPage(currentPage);
208});
209

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.