Where to put js code for polling tile notifications for windows8 js&html app - windows-8

http://msdn.microsoft.com/en-us/library/windows/apps/hh761476.aspx
Those instructions are great, but where do I put the below code (grabbed from article above)? In my default.js file, above the app.addEventListener("activated", function (args) { line of code? Below that line? Elsewhere? Thanks Microsoft, but tell me where to put the code!
var notifications = Windows.UI.Notifications;
var recurrence = notifications.PeriodicUpdateRecurrence.hour;
var url = new Windows.Foundation.Uri("http://mytileprovider.com/tile.xml");
notifications.TileUpdateManager.createTileUpdaterForApplication().startPeriodicUpdate(url, recurrence);
Ideally this would just be a manifest setting with a dropdown of "Frequency" and an input box for the url to grab it from. That would be oh so helpful and convenient.

The answer is... it depends. :)
Where do you want to set up the tile and the polling? Is it an "always on" feature that is core to your application? If so, then put in inside the activated event for your default page (usually inside default.js). Or maybe you are adding tiles based on content that the user interacts with (i.e., selecting a stock to pin to the Start page). In that case, you would put that code inside the page that handles the user action that.
The simple answer is... inside the activated event. The real answer, as you can see, can be more involved.

Related

WKWebView - replace web action

Inside my app, I'm using the WKWebView to display a website. My goal is, when user is pressing a button on this website, I want to stop an action linked to this event and replace it with my own, natively made (custom action outside the WKWebView). I've been trying to search for any solution to fetch mentioned event but unsuccessful. What more came to my mind, if there is a way to fetch a JavaScript in WKWebView, I have a possibility to add some JS script code to this site (not to delete the action I want to block). Thank you for any help.
First, do you have a permission to mess with this web site's behaviour? I assume you do, otherwise it is likely illegal.
Second, try using Safari Web Inspector with a device/simulator, and use the DOM tree and console tools to find out what is the HTML/javascript that is involved with this action on this site.
If you can't find what happens in HTML/JS yourself, feel free to post a new separate question on SO with your target URL, some HTML/JS code, and which link/action you want to replace. Tag the question with "javascript" and ask if it is possible to write some javascript to replace that particular action to some custom JS code.
Usually there are 2 types of actions: either it is something that provokes AJAX calls to a server API triggered by an event handler, or it is a plain HTML link that results in a web navigation. For both cases it is possible to write a JS script that overrides the action.
Finally, use WKUserScript to inject javascript into the page, and override the action. Use window.webkit.messageHandlers to send an event from your custom action to the app side. Use WKScriptMessageHandler to process the event in the Objective-C or Swift code.
See an example here: http://nshipster.com/wkwebkit/

.innerHTML does not work on Windows Phone browser

I have a problem with a label field on my HTML page. I have set a label as below:
<label id="labelid" class="required control-label">Old Label Value</label>
Based on some other form input, I am trying to change the value of the label using javascript. The code for that is:
function change()
{
document.getElementById(labelid).innerHTML = "New Label Value";
}
For some reason, this works fine on a desktop browser. It also works fine on IOS and Android phones. But when i view this HTML page on a windows phone browser, the new value is not visible.
Please advise. I must be doing something silly, but i cant figure it out.
The basic objective is to update a label based on what the user has typed in a text field. Please let me know if there is another way of doing it instead of using labels.
Try this code. You didn't have quotes around labelid..
function change() {
document.getElementById("labelid").innerHTML = "New Label Value";
}
In reference to Windows phone browser, Mark Chamberlain had these comments to a similar issue:
"Standard Javascript injection is not enabled; most likely due to risk of attacks, web site spoofing etc. If you need to customize a web site that you own, you should implement your changes on the web site (server) side."
This could possibly extend to adding/deleting/modifying HTML is my interpretation.
From this link: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/94d4a806-3eca-411e-adda-9e0fa8a6f467/how-to-inject-or-insert-the-javascript-code-in-webbrowser-windows-phone-7?forum=wpdevelop

How to change dojo locale after dojo loaded?

We need set locale in data-dojo-config before dojo loaded so that dojo.i18n will work with this locale. Is there any workaround that we can change this locale in dojo/_base/config after dojo loaded so that any further dojo.i18n call will work with this new locale?
I have a single page application, by carefully design, I already be able to recreate all my UI widgets dynamically anytime. I want to add a Select somewhere so that user can change languages on the fly. Currently the only solution I have is put a queryString locale='newLocale' at Url and force browser refresh. That works but everything User have done lost and with a fresh start. That's not what I want.
Any idea? I don't afraid some changes of dojo to make this happen since my application will be built as a single layer and deploy to customers.
According to dojo's documentation, you cannot change the locale once it's loaded. See this page from their documentation, the relevant line is:
Once Dojo is loaded, it is not possible to change the locale for the
page.
Your description of adding a new parameter is what I've done in this situation, you can specify the locale property on the dojoConfig object to override the default locale.
EDIT: There is an open bug for this use case, see https://bugs.dojotoolkit.org/ticket/17196. In that ticket there also appears to be a workaround that basically involves manually loading the resource file of the language you want to use and updating any text.
So, adapting their example (http://jsbin.com/aquviq/1/edit), this would run after you initiate a change locale action:
require(['dojo/i18n!dojo/nls/' + resourceModuleWithLocale], function (resource) {
/* in here, you must set all of the text manually to the values in the resource object */
});
It still seems like a lot of work, but I suppose that's one possible way to accomplish this.

End conversation when leave page in Seam

I have a wizard in my Seam project which has four pages. When user starts the wizard by coming to the first page (wizard1.xhtml) I start a conversation. To do that in my pages.xml I have following code.
<page view-id="/pages/wizard1.xhtml">
<begin-conversation join="true"/>
</page>
At the final page of the wizard (wizard4.xhtml) I have a save button and I end the conversation by using #End annotation.
#End
public String save() {}
However while moving through the wizard, the user can redirect to a page outside the wizard by clicking a link. Note that if this happens the conversation is not yet ended.
What I want is to immediately end the conversation as soon as the user is no longer on a wizard page (wizard1.xhtml,wizard2.xhtml,wizard3.xhtml or wizard4.xhtml). I found this post but a timeout is not a good choise in my case since I want to end the conversation immediately.
I think the most straight forward and natural solution of your problem is to make your click-able link like this:
<s:link value="here is the link" view="/expectedView.xhtml"
action ="#{targetBean.endingConversation()}"/>
And your endingConversation() method can be like this:
#End
public void endingConversation(){
//do cleanup code
}
The idea is simple, you should employ a guard in every possible exiting points.
Not sure if it will work, just a thought.
Create some javascript function using a4j:jsFunction that calls a method that's annotated with #End.
You then add this jsFunction as an onClick handler to all Your links. (Not sure if onClick is the best handler though).
When the user navigates away from Your wizard the method is called and the conversation should be ended.
If you are using pages.xml (or the per-page page.xml files) to implement page navigation in your application, then you have to specify redirect behavior, for each page, based on the action string. In the navigation rule for each redirect that is not continuing your wizard conversation, you can add <end-conversation />. This is similar to other suggestions, but the result would be navigation rules files which illustrate your applications page flow including the demarcation of your long-running conversations.

Where can I read how to make web notifiers such as the StackExchange at the top left side of StackOverflow screen?

I'm not even sure what the name of that is to be able to make a search... but I would like to make those kind of things. Facebook has that too with the messages, notifications and friends requests. Thanks
I'm not sure if you expect anyone to give you a complete tutorial with source code included? :) You should probably do some digging around yourself, since a concrete answer on this could mean to write a few pages :)
How can you dig around?
Thé tool for a job like that is Firebug (IMO).
With bigger tasks like these it makes sense to try to split it up in smaller pieces.
Let's say you go for a widget like the user profile popup on SO.
you need some HTML to display in a popup: right click on any html element on the popup and click the 'inspect element' menu item. This brings you to the HTML tab in firebug. This allows you to figure out how the HTML is structured
you need some CSS to style that popup: when you're browsing the html structure, you might already have noticed that on the right side of it is the CSS that is applied to the active element
you might want to use some animation effects: for that you could use jquery. Have a look here to find out more on which effects are available and how they can be triggered. Fading is used in the profile popup on SO.
then you might ask yourself the question where SO get's that html structure from, right? To find out more about which server calls are made you can use the 'NET' tab in Firebug. (When you hover over your user name (only the first time?), then you should notice there's a call made to something like: http://stackoverflow.com/users/profile-link-stats?_=someLongNumberHere
In firebug you can then inspect the request and response. You should notice that the response is some HTML structure. This HTML structure is then inserted into the DOM.
Sooooo you can kinda glue it all together now:
the user hovers over his user name
the hovering triggers a server call (see step 4): use jquery hover to attach a handler to the user link. (subsequent hovers don't trigger that server call, so there needs to be a check to see if that profile popup was already loaded or not)
when the server call successfully returns (see jquery get), the returned html is inserted into the DOM and a fadeIn effect is triggered.
it seems a mouseout is used to fadeOut the popup
I HOPE this is the answer you were looking for. It took me a while ;)
You probably need to check out stackapps