JS Problem

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

ragtek

Guest
I think i'm having a scope problem and i don't know why:(

js file1:
var foo{
test:true,
};

js file2:
Code:
    XenForo.Ragtek_PostBox = function($link)
    {
        $link.click(function(e)
        {
            e.preventDefault();
            var link = this.href;
            var $box = $('<input type="textbox" value="' + this.href + '" class="textCtrl" size="80"/>');
            $box.click(function(e){
                this.select();
                XenForo.loadJs('js/ragtek/foo.js', $.context(this));
              // XenForo.loadJs('js/ragtek/foo.js');
              // XenForo.scriptLoader.loadScript('js/ragtek/foo.js', $.context(this));
//how can i access now foo???

why can't i access foo now???
I've tried loadJs and scriptLoader.LoadScript, and iwth $.content and without, ... but i had no success:(
 
What are you trying to do with $.context(this) ? I'm not sure that would actually work at all.

Surely you mean XenForo.loadjs('js/ragtek/foo.js', $.context(function() { alert('foo.js is ready...'); }, this));
 
I have no clue, what i'm doing with $.context ... :( it was just a copy & paste try.. to get foo into the scope:(

even i'm using your code, i can't access foo in my method

Code:
var $box = $('<input type="textbox" value="' + this.href + '" class="textCtrl" size="80"/>');
            $box.click(function(e){
                this.select();

                XenForo.loadJs('js/ragtek/foo.js', $.context(function() { alert('foo.js is ready...'); }, this));
                foo...

shows me the alert, and in the console i'm gettint the error, that foo is not defined :(
 
Aah okay, I think I sees what you're trying to do.

The second argument to loadJs is a callback that executes when the script is loaded - as it's not possible to do a synchronous 'require' in JS like you can in PHP, so what you need to do is this:

Code:
XenForo.loadJs('path/to/myscript.js', function()
{
// code that uses myscript.js
});
 
thx
Aah okay, I think I sees what you're trying to do.

The second argument to loadJs is a callback that executes when the script is loaded - as it's not possible to do a synchronous 'require' in JS like you can in PHP, so what you need to do is this:

Code:
XenForo.loadJs('path/to/myscript.js', function()
{
// code that uses myscript.js
});
 
Is there any good page, where i can learn something about OOP in js?

Nothings working, non function/object is available :(
 
finally i found the problem.....

the flash button isn't working with the overlay:(
it's inserted on the false high (it's put from documents top and not from overlays top:( )

edit: done:)
 

Attachments

  • button.webp
    button.webp
    13.8 KB · Views: 13
Top Bottom