Another day... another AJAX issue...

Jaxel

Well-known member
This is my js...
Code:
/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
	XenForo.StreamLoader = function($link)
	{
		$link.click(function(e)
		{
			e.preventDefault();

			XenForo.ajax(
				$link.attr('href'),
				{},
				function(ajaxData, textStatus)
				{
					if (ajaxData.templateHtml)
					{
						new XenForo.ExtLoader(ajaxData, function()
						{
							$(ajaxData.templateHtml).xfInsert('replaceAll', '#streamBox', 'xfShow');
						});
					}
				}
			);
		});
	}

	// *********************************************************************

	XenForo.register('.EWRcharla_Chat div.topCtrl a[href]', 'XenForo.StreamLoader');
}
(jQuery, this, document);
When I click, I get the following error...
XHR finished loading: "http://www.8wayrun.com/chat/stream".

jquery-1.4.4.min.js:147Uncaught TypeError: Cannot set property 'display' of undefined
c.fn.extend.hidejquery-1.4.4.min.js:147
jQuery.fn.extend.xfInsertxenforo.js:429
XenForo.StreamLoaderEWRcharla_ajax.js:21
XenForo.ExtLoader.callSuccessxenforo.js:1908
XenForo.ExtLoader.__constructxenforo.js:1882
XenForo.ExtLoaderxenforo.js:1846
XenForo.StreamLoaderEWRcharla_ajax.js:19
c.extend.handleSuccessjquery-1.4.4.min.js:142
Any idea why?
 
R

ragtek

Guest
What's your template looking like?
I think you had the same problem some days ago, because you had no "html tag" around your code.

bad: foobar
good: <div id="smafu">foobar</div>

hth (hope this helps)^^
 

Kier

XenForo developer
Staff member
As Ragtek says, there appears to be nothing wrong with your js, but anything loaded up for inception via .xfInsert() must be surrounded by a single tag.
 

Kier

XenForo developer
Staff member
Also, look into using .hasTemplateHtml() rather than checking ajaxData.templateHtml manually.
 

Jaxel

Well-known member
Yep, it was the single tag issue again... I keep forgetting about that...
Also, look into using .hasTemplateHtml() rather than checking ajaxData.templateHtml manually.
What do you mean? How do I use this?
 

Jaxel

Well-known member
Okay... this is my current JS. You can see how it's being used here:
http://www.8wayrun.com/chat/
http://www.8wayrun.com/chat/(click the Show Stream button in the top right control).
It looks amazing in IE9 and Chrome... looks like ass in Firefox.
Code:
/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
	slideSpeed = 1500;
	slideHeight = 0;

	XenForo.AddStream = function($link)
	{
		$link.click(function(e)
		{
			e.preventDefault();

			XenForo.ajax(
				$link.attr('href'),
				{},
				function(ajaxData, textStatus)
				{
					if (XenForo.hasTemplateHtml(ajaxData))
					{
						slideHeight = ajaxData.service_height;

						new XenForo.ExtLoader(ajaxData, function()
						{
							$(ajaxData.templateHtml).xfInsert('insertBefore', '#chatBox', 'xfSlideDown', slideSpeed);
						});

						$('#chatBox').animate({ height: $('#chatBox').height() - slideHeight }, slideSpeed);
						$('#addStream').hide();
						$('#remStream').show();
					}
				}
			);
		});
	}

	XenForo.RemStream = function($link)
	{
		$link.click(function(e)
		{
			e.preventDefault();

			$('#chatBox').animate({ height: $('#chatBox').height() + slideHeight }, slideSpeed);
			$('#addStream').show();
			$('#remStream').hide();
			$('#streamBox').xfRemove(null, null, slideSpeed);
		});
	}

	// *********************************************************************

	XenForo.register('.EWRcharla_Chat div.topCtrl #addStream', 'XenForo.AddStream');
	XenForo.register('.EWRcharla_Chat div.topCtrl #remStream', 'XenForo.RemStream');
}
(jQuery, this, document);
 

Jaxel

Well-known member
I am having a weird issue with the JS code I posted above...
You can see an example of it here: http://www.8wayrun.com/chat/

Click (Show Stream) -> stream boxes will be prependTo #chatBox in a new div called #streamBox...
Click (Hide Stream) -> stream boxes DONT get deleted, even though it should xfRemove #streamBox...
Click (Show Stream) -> a second set of stream boxes will appear below the original set...
Click (Hide Stream) -> the FIRST set of stream boxes will finally disappear...

Why are the stream boxes not getting removed when they should?
 

Kier

XenForo developer
Staff member
Yep, it was the single tag issue again... I keep forgetting about that...

What do you mean? How do I use this?
Change this:
Code:
if (ajaxData.templateHtml)
to this
Code:
if (XenForo.hasTemplateHtml(ajaxData))
This is a more robust check, and allows pre-processing to occur should we need to do any in future.
 

Jaxel

Well-known member
This is a more robust check, and allows pre-processing to occur should we need to do any in future.
Oh... okay... any advice on the post above?

Nevermind, figured it out... error on my part.
 
Top