Giter Site home page Giter Site logo

Comments (17)

rawcreative avatar rawcreative commented on September 13, 2024

Are you wanting it to emit a js event or are you wanting it to actually do something (like interact with the MG Api)? Yes in both cases but the approach would be different depending on what you wanted the button to actually do.

On Jun 9, 2014, at 3:53 PM, Bijan [email protected] wrote:

Hey is it possible to make a Button that was added via IB to emit a javascript signal?
Can this be done and if so how?

Cheers Bijan

PS: MacGap2 is great!


Reply to this email directly or view it on GitHub.

from macgap2.

gobijan avatar gobijan commented on September 13, 2024

I thought about emitting an event that an app could listen for.
This way the logic what should be done could be coded in javascript. What do you think? Which approach is easier for non obj-c people?

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

Kinda depends on the task really.. the downside to using a button in IB (or any native control really), is that you can't add/configure them on the fly. So it's not something we could make an API for or anything like that because it requires using IB and linking in the code via IBActions. It's not hard to do, it just has to be done before the app is built/compiled.

from macgap2.

gobijan avatar gobijan commented on September 13, 2024

How would this be done?
Let's say one simply adds a button on the top in the MainWindow.xib like so:
bildschirmfoto 2014-06-09 um 22 19 01

How would I emit a "buttonHasBeenClicked" event to the javascript scope of my app? Is that possible?

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

If you just want to emit an event when the button is clicked, here's the steps:

  1. Open MainWindow.xib in IB and add your button
  2. Click the Assistant editor button in the top right of the Xcode toolbar ( second one from the left). You should now have a split view, IB on the left, code for WindowController.m on the right.
  3. Click on/Select the button you added to interface builder, hold the control key and drag to an empty spot in WindowController.m. A popover will show asking for a name for your action, put whatever you want in there and click 'Connect'.
  4. In the method that was added to the WindowController.m file, add the following line, and replace the myEvent with whatever you want your event name to be.
  5. That's it.

You need to make sure that any buttons you're adding don't overlay the actual webview, otherwise you will run into issues, so you'll need to adjust the webview's size in IB. The gif below is just for illustrative purposes.

buttonaction

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

Sorry never added gave ya the actual event code, it's

[Event triggerEvent:@"myEvent" forWebView:webView];

There's other variations of the event code if you need to pass data or specify an element that the event will be triggered on, default is: document.

from macgap2.

gobijan avatar gobijan commented on September 13, 2024

Whoa! That's a lot easier than I expected! Thanks for detailed explanation! :) 👍

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

No problem..

Another solution might be to use a toolbar, that way you don't have to worry about the webview getting in the way or having to move anything around. It's also something that an API could be made for. It works almost the exact same way the Status Bar api works. That way you could make your own buttons and do whatever you'd like to do with it.

from macgap2.

gobijan avatar gobijan commented on September 13, 2024

Yeah that was my original intention.
A button might be trivial but for example in my kanban app I have a dropdown that is populated by angularjs and also a search box that is bound via angularjs, too.

So a two way communication would be needed and parameters needed to be passed from app javascript realm to xcode obj-c interface realm.

This might be a little too painful to implement via api, right?

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

The buttons and drop downs aren’t hard, but for the search field to work you’d have to have an obj-c object representation of whatever you’re searching, in other words, the search would have to be handled via obj-c code.

On Jun 9, 2014, at 4:51 PM, Bijan [email protected] wrote:

Yeah that was my original intention.
A button might be trivial but for example in my kanban app I have a dropdown that is populated by angularjs and also a search box that is bound via angularjs, too.

So a two way communication would be needed and parameters needed to be passed from app javascript realm to xcode obj-c interface realm.

This might be a little too painful to implement via api, right?


Reply to this email directly or view it on GitHub.

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

Off-topic, but how’d you get a file size of 29MB using node-webkit?

On Jun 9, 2014, at 4:51 PM, Bijan [email protected] wrote:

Yeah that was my original intention.
A button might be trivial but for example in my kanban app I have a dropdown that is populated by angularjs and also a search box that is bound via angularjs, too.

So a two way communication would be needed and parameters needed to be passed from app javascript realm to xcode obj-c interface realm.

This might be a little too painful to implement via api, right?


Reply to this email directly or view it on GitHub.

from macgap2.

gobijan avatar gobijan commented on September 13, 2024

Hmm maybe for the search it would be enough to be able to get and set the text in the box via JS...

I ripped off everything I didn't need form node-webkit :D Just kidding: The App Store lists the file size that has to be downloaded and they pack their apps into compressed pkg files. So it's just the compression.

from macgap2.

jeff-h avatar jeff-h commented on September 13, 2024

+1 for a toolbar API :) I currently hand-coded mine in ObjC and it was partially why I added NSUserDefaults — but a better communication method for JS-to-toolbar-items would be great.

from macgap2.

jeff-h avatar jeff-h commented on September 13, 2024

@tschundeee Any chance you could turn the best parts of this issue into a doc page?

from macgap2.

perfaram avatar perfaram commented on September 13, 2024

As this issue isn't closed, I allow myself to ask help for my problem :
Is it possible - and if so, how - to access the webView object from the App delegate ?

from macgap2.

rawcreative avatar rawcreative commented on September 13, 2024

@perfaram self.windowController.webView

from macgap2.

perfaram avatar perfaram commented on September 13, 2024

Thanks ! In the meantime, I had to use a little workaround (I created another IBOutlet in the AppDelegate, referencing the WebView)

from macgap2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.