"active" class is not applied to elements using javascript: in the href in jQTouch - html

For some background, I've built a mobile Android app using PhoneGap for native functionality and jQuery with jQTouch as the UI framework. I have an a bunch of links (categories) in a <ul> which open the camera. The app "knows" which link was tapped so it knows which category the picture belongs to.
The issue I'm seeing is the .active class isn't applied to elements in jQTouch deemed to have an external link, of which javascript: is one. Does anyone have an idea on how to give the user some sort of indication which <li> he tapped before the camera opens so that he can cancel his action if he notices the .active class gets applied to an element that is different from what he expected?

For the sake of posterity, it seemed to be that jQTouch was adding and removing the .active class so fast that the UI wasn't able to keep up. Basically, it was added/removed so fast that no changes were detectable at all. It worked on a computer but not on the phone.
In order to remedy this, I used a setTimeout() function on the class removal functionality. I set it to 500 milliseconds. The list item now becomes active, fires the camera functionality (or any function you choose), and then removes the class 500 milliseconds later. Perfect!

Related

Emulate JavaScript events with developer tools?

Chrome (and Firefox) both have really awesome tools for changing the current state of an element, e.g. setting it to a hover state so you can examine/modify css:
The problem is that this doesn't seem to set off any JavaScript events.
I'm currently trying to style a tooltip, which is shown on hover. It's difficult to hover over the element manually as the tooltip dissapears when I take the mouse off of said element, and setting the state to hover in the developer tools doesn't seem to set off the jQuery events.
I'm having to resort to adding an ID on the element in the developer tools inspector, then doing the following in the console:
$("#custom-element-hover").mouseover();
Which feels wrong (and is a little cumbersome).
Is there a better way to do this that I don't know about?
In a simple situation I think it is often easier to use the console as you are doing. But within developer tools, you can also find the event listener code and set a breakpoint on it:
You then right click on this handler and do view source, unminimize the source with the {} button and set a breakpoint in this handler function.
If this handler function triggers on unrelated events then you may need to right click on it and make the breakpoint conditional or add Watch Expressions to see when you are at the correct event.
You could also use the same method of breakpoint setting to instead skip over a particular mouseout event.
I can share with what I do in this kind of situations. I open elements tab in chrome debugger and right click on target element. Then I choose "Copy CSS path"
If you do this you will get something like this
#mdhelp-tabs > li:nth-child(1)
And this string can actually be used as legimit selector for jQuery. So this
$("#mdhelp-tabs > li:nth-child(1)")
will give jquery object with target element of dom in it.
So you would not have to assign an ID to every single element you want to deal with.
I am not sure but you can use console to handle tooltip

Catching back and home keys

After I set up my new project with libGDX v1.3.1 i am stuck with something that should be easy. In my main class which extends game I have:
Gdx.input.setCatchBackKey(true);
but I cannot get any response from this (in render method):
if(Gdx.input.isButtonPressed(Keys.BACK)){
this.dispose();
}
It like nothing was pressed, although I can see that the button was pressed in logCat console.
I need to mention that I was using the exact same code until libGDX version 1.0.0 (or the first one with gradle).
Note: i have also tried implementing InputProcessor and then setting the input processor. Result was the same.
And for the home button: using Gdx.input.setCatchMenuKey(true); is not working.
Use isKeyPressed instead of isButtonPressed. Buttons only refers to the three mouse buttons on a desktop game. Everything on Android is a Key (or Peripheral).
You mentioned "home button" but the code you posted is for the menu button. There is no way to catch the home button unless you make your manifest declare your app as a launcher replacement, in which case, the home button will always open your app, even when it's closed, and the user will have no easy way to get to the home screen. And libgdx doesn't have that functionality built in, since that would be weird. You would have to implement it yourself in your manifest and main Activity.
Also, disposing of this, whatever this is, sounds dangerous to do from the input handler. You could be about to render stuff and cause a crash. But I'm not sure where you're trying to use it from. Maybe it's OK.

Registering click handlers with browser back/forward buttons

I am building an HTML5 single-page web app that employs the concept of "views" or "screens"; essentially just different DOM elements rendered to be visible at any given time. As the user navigates between "views", I'm really just hiding/enabling DOM elements.
I'd like to be able to make use of the browser's history functionality, including the back/forward buttons, but I'm not sure how that plays into the concepts of history.pushState and window.onpopstate.
Ideally, I'd like to register "click handlers" with the browser's back/forward history buttons (obviously in a cross-browser-compatible way) so that when the user clicks either button, it engages my own custom Historian object (in JavaScript) that figures out which "view" to render for the user.
How can I do this?
Firstly, you need some sort of routing solution. You can use Crossroads to register and manage your routes. Each route should have a handler, which enables the appropriate div in your single page.
var route1 = crossroads.addRoute('/page1/', function(id){
//enable div for page1 route
});
Then, you can use Hasher to manage browser history.
Another way is to rebuild your application with Durandal, which has a router and manages browser history out of the box.

using PopUpManager in a Flex 4.5 Mobile App

This is more of a best practices question rater than something technical.
I'm working on a mobile app using the Flex 4.5 SDK and I'm trying to figure out the best way to handle notification windows. In most cases these windows will be alerting the user to when something goes wrong. Ex: bad login, no data, cannot resolve server.
I'm using a singleton design pattern, I have a Requests class that handles server calls. Most popups will be originating from this class (IOErrorEvents from my loader being used to access the API). Since this class is a singleton and is used from all Views inside the app it is not aware of applications current view. I'm also not sure having this class keep track of the current view and having it push popups on top of it would be best practice.
I'm hoping that I can use PopUpManager to keep track of where to add popups and what popups are currently on the stage. Though all examples I've seen online about this show static Components being used in a views Declarations tag.
I'm really just looking for any examples or input on how you would solve this problem. Any help would be greatly appreciated!
I had the same problem, and sorted it by making an Alert popup component that you can call from anywhere in the code base, and it will pop up in the currently active window. It also has an always visible scrollbar text area which is handy
http://bbishop.org/blog/?p=502
It works for a view navigator application, but if your using a tabbed navigator application, you can add a call for that, or simply change the code to
mainTabbedNavigator = FlexGlobals.topLevelApplication.tabbedNavigator;
currentTab = mainTabbedNavigator.selectedNavigator as ViewNavigator;

What is the best approach to building a popup inside of Flash AS3

I am trying to accomplish an "imagemap" in flash where you click on different areas in the image and when you click on it, a popup (within flash) comes up showing more information about the object that was clicked on. The popup has a close button that can will then close the popup.
My biggest trouble is the way I have my code right now is when you click on a region of the map, it creates a popup on the fly, and then I use addChild(_myPopup) to add it to the display list. The problem with this approach for me, is that the Popup is now a Child of the button I just pressed, but this object organization doesn't really make sense to me. I'd like to have the popup not be a child of the button and it be on it's own layer or a child of the stage directly.
What is a good approach and code architecture for building such an organization of objects? I'm fairly new to AS3 and I've built some small applications but my knowledge is limited.
Thanks
UPDATE
ok looks like calling stage.addChild(myPopup) from inside the button works pretty well. Is this good practice?
Assuming you have a hierarchy that looks something like this:
stage
Main class
Image class
Button
It's good practice to never call upwards in the displaylist, every object only deals with it's children. Events however, are a nice way of communicating upwards. Have the Button dispatch an event, preferrably a custom one, then handle that using a listener in the main class that then deals with creating a popup on top of everything.
An often encountered practise to organize the layers of the visible application is:
stage
main class with all children
popup container
tooltip container
mouse cursor container (apparently not longer necessary since player 10 supports custom cursors)
So you create your popups always in the popup container above the main class. If you would have tooltips, they should go into the tooltip container. This approach guarantees that popups are always visible above the main app and tooltips are always visible on top of everything.