• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Implemented Fire JS Action after thread prefix selection

R

ragtek

Guest
#1
I'd like to fire a js action (call my js) after the prefix was set.

I've checked title_prefix.js and i think the best way for this would be to do this inside of setPrefix after the setTextboxWidth BUT

how can i do this without overwriting the original js code?
 
R

ragtek

Guest
#4
I don't know:p :D

Can i use it for something like this pseudocode:

if (current_prefix_id == 13){
XenForo.ajax('ragtek_formtemplate',
{}, function(a) {

if (XenForo.hasTemplateHtml(a)) {

$(a.templateHtml).xfInsert("appendTo", $ragtek_editortemplates_container, "xfFadeIn");
}
else {
console.log("error");
}
});
 

Kier

XenForo Developer
Staff member
#5
You could do something like this:
Code:
var $select = $('select.TitlePrefix');

$select.bind('XFSetPrefix', function(e)
{
	var $link = e.link; // just in case you want it

	if ($select.val() == 13)
	{
		XenForo.ajax('ragtek_formtemplate', {}, function(ajaxData)
		{
			if (XenForo.hasTemplateHtml(ajaxData))
			{
				$(a.templateHtml).xfInsert('appendTo', $ragtek_editortemplates_container, 'xfFadeIn');
			}
			else
			{
				console.warn("error");
			}
		});
	}
});
 
R

ragtek

Guest
#6
You could do something like this:
Code:
var $select = $('select.TitlePrefix');

$select.bind('XFSetPrefix', function(e)
{
var $link = e.link; // just in case you want it

if ($select.val() == 13)
{
XenForo.ajax('ragtek_formtemplate', {}, function(ajaxData)
{
if (XenForo.hasTemplateHtml(ajaxData))
{
$(a.templateHtml).xfInsert('appendTo', $ragtek_editortemplates_container, 'xfFadeIn');
}
else
{
console.warn("error");
}
});
}
});
hm, it's not working:(

that's my current code:
Code:
!function($, window, document, _undefined) {
    var $select = $('select.TitlePrefix');

    $select.bind('XFSetPrefix', function(e) {
        var $link = e.link; // just in case you want it
        console.log('selected');
        if ($select.val() == 1) {
            XenForo.ajax('ragtek_formtemplate', {}, function(ajaxData) {
                        if (XenForo.hasTemplateHtml(ajaxData)) {
                            $(a.templateHtml).xfInsert('appendTo', $ragtek_editortemplates_container, 'xfFadeIn');
                        }
                        else {
                            console.warn("error");
                        }
                    });
        }
    });

}
(jQuery, this, document);
it's not sending the ajax request after i select an prefix.

I've even tried to remove the if condition so the ajax request should be send on every change, but there was none:(
 

digitalpoint

Well-known member
#9
The trigger itself seems to work for me... In it's most simplistic form, binding a simple confirm dialog works for me (dialog shows when prefix changes):

Code:
$('select.TitlePrefix').bind('XFSetPrefix', function(){confirm('hello world')});
 
R

ragtek

Guest
#13
if i run it via the fire bug console and change the prefix it's showing the popup 2 times (i think because of my own second )...

Without running
Code:
 $('select.TitlePrefix').bind('XFSetPrefix', function(){confirm('hello world')});
in the firebug console nothing happens:D

that's the content of the file
Code:
!function($, window, document, _undefined) {
    $('select.TitlePrefix').bind('XFSetPrefix', function(){confirm('hello world')});

}
(jQuery, this, document);
 

Mike

XenForo developer
Staff member
#14
It sounds to me like you're running that code before the select exists. If that code is in the head tag, then that would be the case - you should really only do your binding on document ready.

Or better yet: look at event delegation.
 
R

ragtek

Guest
#15
It sounds to me like you're running that code before the select exists. If that code is in the head tag, then that would be the case - you should really only do your binding on document ready.

Or better yet: look at event delegation.
isn't

Code:
!function($, window, document, _undefined) {
    ..
 
}
(jQuery, this, document);
this something similar to vBs

Code:
vBulletin.events.systemInit.subscribe(function()

i thought always that this code is run after everything was load:D :(


edit: OK that was my problem and this solves now several problems in my add-ons:D
 
R

ragtek

Guest
#18
or probably

XenForo.register('select.TitlePrefix', 'Ragtek.ModeratorForum');
right?


but that's something for my refactoring in some years...

thx:D