MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 208 forks source link

Why do the javascript calls only seem to work in the top of the document? #71

Open ckizer opened 11 years ago

ckizer commented 11 years ago

I need to be able to call something like doc badging when i hit a button. It works fine in the head as a script.

But as soon as I put your calls in a jquery function, my alert fires but your javascript returns exceptions. Here's an example. I can't put everything in the head. Where does your javacscript interpreter load?

works in head

macgap.dock.badge = "10";

macgap returns errors if below body tag

    $("button.feed").click(function() { 
      macgap.dock.badge = "10"; // error below
      document.title = 'Stop Clicking AND BE QUIET';  //works
    });

2013-04-19 16:08:57.406 MacGap[8057:303] JavaScript console: undefined:0: TypeError: 'undefined' is not a function

ckizer commented 11 years ago

Someone suggested setting this:

    var mgdock = macgap.dock.badge; // set a variable

macgap.dock.badge = "10"; // don't use this
mgdock = "10" // do this?

All macgap names cannot be called in jquery or any other library. Can you please show us a working example of calling these in a javascript library or any function? If we can't call them in functions then they really aren't usable.

jeff-h commented 10 years ago

I know I'm kind of late to answer this, but I'm not seeing this behaviour. I have just put a jQuery click handler very similar to your first example and it worked fine. It set the dock badge just fine.

Incidentally, my test jQuery handler was embedded inside a backbone.js view, proving the macgap api is definitely accessible inside other frameworks.

If you want to put some sample code somewhere I can see it, I'd be happy to take a look and see why it's not working.