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

JS Problem

R

ragtek

Guest
#1
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:(
 

Kier

XenForo Developer
Staff member
#2
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));
 
R

ragtek

Guest
#3
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 :(
 

Kier

XenForo Developer
Staff member
#5
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
});
 
R

ragtek

Guest
#6
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
});
 
R

ragtek

Guest
#8
Is there any good page, where i can learn something about OOP in js?

Nothings working, non function/object is available :(
 
R

ragtek

Guest
#9
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