Slideshow Management

Google console error - Slideshow Management

Google console error

by TrekRed » Sat Jan 22, 2022 5:45 pm

Hello. Google console throws an error:
Uncaught TypeError: Cannot read properties of undefined (reading 'style')
at showSlides(site/:2508:23)
at site/:2466:1

With what it can be connected?
1.jpg
TrekRed
Registered User
Posts: 73
Joined: Fri May 17, 2019 6:31 pm

Re: Google console error

by huynhbuutam » Sat Jan 22, 2022 11:28 pm

Hi TrekRed, I guess there are some corrupted files in your package, please try downloading and reinstalling this extension, then pure the cache, force reload the page (on Windows, press Ctrl + F5)
User avatar
huynhbuutam
Registered User
Posts: 39
Joined: Wed Dec 01, 2021 4:15 pm
Location: Viet Nam
Name: Huynh Buu Tam

Re: Google console error

by TrekRed » Sun Jan 23, 2022 4:56 pm

Where will the corrupted files come from? Moreover, the extension works.

Moreover, this error occurs only on those pages where there is no slide show, and there is no such error on the page with slides.
TrekRed
Registered User
Posts: 73
Joined: Fri May 17, 2019 6:31 pm

Re: Google console error

by huynhbuutam » Mon Jan 24, 2022 7:56 am

Hi TrekRed, I checked and everything works fine. Please try the following steps:
1. Re-download the extension: https://www.phpbb.com/customise/db/download/193796
2. Disable the extension
3. Delete the extension's data
4. Delete old extension's file
5. Upload new extension's file
6. Enable the extention
7. Pure the cache
8. Force a page reload (where the error occurs. On Windows, press Ctrl + F5)
Let me know if it solves your problem
Last edited by huynhbuutam on Mon Jan 24, 2022 2:08 pm
User avatar
huynhbuutam
Registered User
Posts: 39
Joined: Wed Dec 01, 2021 4:15 pm
Location: Viet Nam
Name: Huynh Buu Tam

Re: Google console error

by TrekRed » Mon Jan 24, 2022 11:04 am

You will understand that the error occurs only when the index is enabled. Try to leave only the index, and disable everything else, and look at the settings, as in the picture. Then check for errors. The error will be on the page where there are no slides, and you need to look there.
Such settings.jpg
If you turn on all the checkboxes, then there will be no error. You apparently have all the checkboxes enabled in the settings when checking.
TrekRed
Registered User
Posts: 73
Joined: Fri May 17, 2019 6:31 pm

Re: Google console error

by huynhbuutam » Mon Jan 24, 2022 2:06 pm

I checked and found no problem, can you give me a link where the error occurs?
Furthermore, please check the following 2 files:
.\ext\tamit\slideshow\event\main_listener.php. Pay attention to lines from 87 to 90, and line 105

Code: Select all

87.		if ($this->config['tamit_slideshow_mode'] == 0)
88.		{
89.			$this->template->assign_var('SLIDESHOW_SLIDES', $this->manager->get_enabled_slides());
90.		}

Code: Select all

105.			$this->template->assign_var('SLIDESHOW_SLIDES', $this->manager->get_newest_topics($forum_id, $this->config['tamit_slideshow_topic_count']));

Code: Select all

<?php
/**
 *
 * Slideshow Management. An extension for the phpBB Forum Software package.
 *
 * @copyright (c) 2021 Huynh Buu Tam <https://www.tamit.net>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 */

namespace tamit\slideshow\event;

/**
 * @ignore
 */
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class main_listener implements EventSubscriberInterface
{
	/** @var \phpbb\template\template */
	protected $template;

	/** @var \phpbb\request\request */
	protected $request;

	/** @var \phpbb\config\config */
	protected $config;

	/** @var \tamit\slideshow\core\manager */
	protected $manager;

	/** @var string */
	protected $php_ext;

	/**
	 * {@inheritdoc}
	 */
	public static function getSubscribedEvents()
	{
		return array(
			'core.user_setup'				=> 'load_language_on_setup',
			'core.page_header_after'		=> array(array('setup_slides'), array('slideshow_target'))
		);
	}

	/**
	 * Constructor
	 *
	 * @param \phpbb\template\template				$template			Template object
	 * @param \phpbb\request\request				$request			Request object
	 * @param \phpbb\config\config					$config				Config object
	 * @param \tamit\slideshow\core\manager			$manager			Slideshow manager object
	 * @param string								$php_ext			PHP extension
	 */
	public function __construct(\phpbb\template\template $template, \phpbb\request\request $request, \phpbb\config\config $config, \tamit\slideshow\core\manager $manager, $php_ext)
	{
		$this->template = $template;
		$this->request = $request;
		$this->config = $config;
		$this->manager = $manager;
		$this->php_ext = $php_ext;
	}

	/**
	 * Load common language file during user setup
	 *
	 * @param	\phpbb\event\data	$event		The event object
	 * @return	void
	 */
	public function load_language_on_setup($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'tamit/slideshow',
			'lang_set' => 'common'
		);
		$event['lang_set_ext'] = $lang_set_ext;
	}

	/**
	 * Displays slides
	 *
	 * @return	void
	 */
	public function setup_slides()
	{
		if ($this->config['tamit_slideshow_mode'] == 0)
		{
			$this->template->assign_var('SLIDESHOW_SLIDES', $this->manager->get_enabled_slides());
		}
		else
		{
			$forum_id = $this->request->variable('f', 0);
			
			if ($forum_id == 0)
			{
				$forum_id = $this->manager->get_forum_id($this->request->variable('t', 0), false);
			}
			
			if ($forum_id == 0)
			{
				$forum_id = $this->manager->get_forum_id($this->request->variable('p', 0), true);
			}
			
			$this->template->assign_var('SLIDESHOW_SLIDES', $this->manager->get_newest_topics($forum_id, $this->config['tamit_slideshow_topic_count']));
		}
	}

	/**
	 * Assign target page
	 *
	 * @return	void
	 */
	public function slideshow_target()
	{
		$this->template->assign_var('S_SLIDESHOW_PAGE_INDEX', $this->config['tamit_slideshow_page_index']);
		$this->template->assign_var('S_SLIDESHOW_PAGE_VIEWFORUM', $this->config['tamit_slideshow_page_viewforum']);
		$this->template->assign_var('S_SLIDESHOW_PAGE_VIEWTOPIC', $this->config['tamit_slideshow_page_viewtopic']);
		$this->template->assign_var('S_SLIDESHOW_DURATION', $this->config['tamit_slideshow_duration']);
		$this->template->assign_var('S_SLIDESHOW_BOX', $this->config['tamit_slideshow_box']);
		$this->template->assign_var('S_SLIDESHOW_NAV_IMAGE', $this->config['tamit_slideshow_nav_image']);
		$this->template->assign_var('S_SLIDESHOW_NAV_DOT', $this->config['tamit_slideshow_nav_dot']);
	}
}
.\ext\tamit\slideshow\styles\all\template\event\overall_footer_after.html. Pay attention to the first line

Code: Select all

{% if SLIDESHOW_SLIDES|length > 0 %}

<script type="text/javascript">
var slides = document.getElementsByClassName("slideshow-slides");
var slideIndex = Math.floor(Math.random() * slides.length);
var showLoopTime = {{ S_SLIDESHOW_DURATION }};
showSlides(slideIndex);
var slideShowTimer = setInterval(loopSlides, showLoopTime);

function loopSlides() {
	slideIndex++;
	if (slideIndex > slides.length) {
		slideIndex = 1;
	}
	if (slideIndex < 1) {
		slideIndex = slides.length;
	}
	showSlides(slideIndex);
}

function plusSlides(n) {
	showSlides(slideIndex += n);
	resetShowTimer();
}

function currentSlide(n) {
	slideIndex = n;
	showSlides(n);
	resetShowTimer();
}

function resetShowTimer() {
	clearInterval(slideShowTimer);
	slideShowTimer = setInterval(loopSlides, showLoopTime);
}

function showSlides(n) {
	var i;
	if (n > slides.length) {
		slideIndex = 1;
	}
	if (n < 1) {
		slideIndex = slides.length;
	}
	for (i = 0; i < slides.length; i++) {
		slides[i].style.opacity = 0;
		slides[i].style.height= 0;
	}
	slides[slideIndex-1].style.opacity = 1;
	slides[slideIndex-1].style.height = "100%";
	
	{% if S_SLIDESHOW_NAV_DOT == 1 %}
	/* Dot navigator */
	var dotNav = document.getElementsByClassName("slideshow-dot-navigator");
	for (i = 0; i < dotNav.length; i++) {
		dotNav[i].className = dotNav[i].className.replace(" slideshow-active", "");
	}
	dotNav[slideIndex-1].className += " slideshow-active";
	{% endif %}
	{% if S_SLIDESHOW_NAV_IMAGE == 1 %}
	/* Image navigator */
	var imgNav = document.getElementsByClassName("slideshow-image-navigator");
	for (i = 0; i < imgNav.length; i++) {
		imgNav[i].className = imgNav[i].className.replace(" slideshow-active", "");
	}
	imgNav[slideIndex-1].className += " slideshow-active";
	imgNav[slideIndex-1].parentElement.scrollTop = imgNav[slideIndex-1].offsetTop;
	{% endif %}
}

/* Swipe event */
for (i = 0; i < slides.length; i++) {
	slides[i].addEventListener('touchstart', handleTouchStart, false);
	slides[i].addEventListener('touchmove', slideShow_handleTouchMove, false);
}

var xDown = null;
var yDown = null;

function getTouches(evt) {
	return evt.touches || evt.originalEvent.touches; // jQuery
}

function handleTouchStart(evt) {
	const firstTouch = getTouches(evt)[0];
	xDown = firstTouch.clientX;
	yDown = firstTouch.clientY;
};

function slideShow_handleTouchMove(evt) {
	if (!xDown || !yDown) {
		return;
	}

	var xUp = evt.touches[0].clientX;
	var yUp = evt.touches[0].clientY;

	var xDiff = xDown - xUp;
	var yDiff = yDown - yUp;

	/* Most significant */
	if (Math.abs(xDiff) > Math.abs(yDiff)) {
		if (xDiff > 0) {
			/* Swipe right */
			plusSlides(1);
		} else {
			/* Swipe left */
			plusSlides(-1);
		}
	} else {
		if (yDiff > 0) {
			/* Swipe down */ 
		} else { 
			/* Swipe up */
		}
	}
	/* Reset values */
	xDown = null;
	yDown = null;
};
</script>

{% endif %}
Algorithmically, if there are no slides, the <script> tag will not be included, so this error will not occur!
User avatar
huynhbuutam
Registered User
Posts: 39
Joined: Wed Dec 01, 2021 4:15 pm
Location: Viet Nam
Name: Huynh Buu Tam

Re: Google console error

by TrekRed » Mon Jan 24, 2022 5:37 pm

https://1smerch1.ru/

Errors on all pages except the forum: https://1smerch1.ru/index.php

All the above files are present and without errors.

https://1smerch1.ru/viewtopic.php?f=90&t=1789

https://1smerch1.ru/viewtopic.php?f=88&t=1781
TrekRed
Registered User
Posts: 73
Joined: Fri May 17, 2019 6:31 pm

Re: Google console error

by huynhbuutam » Wed Jan 26, 2022 9:54 am

Hi TrekRed, please check the following files:
.\ext\tamit\slideshow\styles\all\template\event\viewtopic_topic_title_before.html

Code: Select all

{% if S_SLIDESHOW_PAGE_VIEWTOPIC == 1 %}
{% INCLUDE 'tamit_slideshow_default.html' %}
{% endif %}
.\ext\tamit\slideshow\styles\all\template\event\viewforum_forum_title_before.html

Code: Select all

{% if S_SLIDESHOW_PAGE_VIEWFORUM == 1 %}
{% INCLUDE 'tamit_slideshow_default.html' %}
{% endif %}
User avatar
huynhbuutam
Registered User
Posts: 39
Joined: Wed Dec 01, 2021 4:15 pm
Location: Viet Nam
Name: Huynh Buu Tam