Implemented Fire JS Action after thread prefix selection

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
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?
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
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");
}
});
 
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");
			}
		});
	}
});
 
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:(
 
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')});
 
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);
 
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.
 
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
 
or probably

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


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

thx:D
 
Top Bottom