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

JS Problem

Discussion in 'XenForo Development Discussions' started by ragtek, Jul 21, 2011.

  1. ragtek

    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:(
     
  2. Kier

    Kier XenForo Developer Staff Member

    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));
     
  3. ragtek

    ragtek Guest

    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 :(
     
  4. ragtek

    ragtek Guest

  5. Kier

    Kier XenForo Developer Staff Member

    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
    });
     
  6. ragtek

    ragtek Guest

    thx
     
    Kier likes this.
  7. Kier

    Kier XenForo Developer Staff Member

    You're welcome :)
     
  8. ragtek

    ragtek Guest

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

    Nothings working, non function/object is available :(
     
  9. ragtek

    ragtek Guest

    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:)
     

    Attached Files:

Share This Page