I wanna add an overlay (already built the HTML 'n jQuery) to a custom iframe tab, that only shows if people haven't liked my client's page yet. Is this possible with the JS SDK? How would I go about this?
While this is better done server-side, you code use something like:
FB.api('/me/likes/PAGE_ID',function(response) {
if( response.data ) {
if( !isEmpty(response.data) )
alert('You are a fan!');
else
alert('Not a fan!');
} else {
alert('ERROR!');
}
});
// function to check for an empty object
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
The code is taken from my tutorial.
Related
i have this code in Xamarin for translate to flutter.
whith the class WKNavigationAction i can know if the url to navigate comes from a user click or javascript
My interest is traslate this statement to flutter
navigationAction.NavigationType == WebKit.WKNavigationType.LinkActivated)
public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
string url = navigationAction.Request.ToString();
// send external links out of the web domain if the user clicked in link
if (!StartsWihtBaseUrl(url) && navigationAction.NavigationType == WebKit.WKNavigationType.LinkActivated)
{
decisionHandler(WKNavigationActionPolicy.Cancel);
ExternalUrlManager.Instance.ManageExternalUrl(url);
}
else
{
decisionHandler(WKNavigationActionPolicy.Allow);
}
}
}
...
I have run into an issue when I deselect "show page in site map" it takes off the parent page but still renders its children.
Now I am assuming it is a simple boolean check to see if "site map" is selected in the Page properties. However I am not sure what that variable is called if that is the solution.
Here is how I am rendering it to the page:
private void printChildren(Page currentPage,JspWriter writer, List extraCategoryList)throws IOException{
boolean childPagePrinted=false;
Page categoryPage = null;
Iterator<Page> childIterator = currentPage.listChildren();
while(childIterator.hasNext()) {
Page childPage = childIterator.next();
if(childPage.getProperties().get("showInSitemap") != null){
if(childPage.getProperties().get("sitemapcategory") != null){
extraCategoryList.add(childPage);
}else{
if(!childPagePrinted){
writer.print("<ul>");
childPagePrinted=true;
}
String pageHtml = getPageHtml(childPage);
writer.print(pageHtml);
}
}
printChildren(childPage,writer,extraCategoryList);
}
if(childPagePrinted){
writer.print("</ul>");
}
}
Advice?
That's because in your loop, you still call printChildren(childPage,writer,extraCategoryList);
You need to move this line in the if(childPage.getProperties().get("showInSitemap") != null)
right now it still calls it no matter what is selected.
So it should be like this:
Iterator childIterator = currentPage.listChildren();
while(childIterator.hasNext()) {
Page childPage = childIterator.next();
if(childPage.getProperties().get("showInSitemap") != null){
if(childPage.getProperties().get("sitemapcategory") != null){
extraCategoryList.add(childPage);
}else{
if(!childPagePrinted){
writer.print("<ul>");
childPagePrinted=true;
}
String pageHtml = getPageHtml(childPage);
writer.print(pageHtml);
}
// print the childs if we're printing the parent
printChildren(childPage,writer,extraCategoryList);
}
}
if(childPagePrinted){
writer.print("</ul>");
}
I want to cache state in form page when switching from page to page.
So : I have 3 page with forms and I want to data stays in forms when I switch from one to another.
I found this : https://wiki.eclipse.org/Scout/Concepts/Page_Detail_Form
#Override
protected void execPageActivated() throws ProcessingException {
if (getDetailForm() == null) {
PersonDetailForm form = new PersonDetailForm();
form.setPersonNr(getPersonNr());
setDetailForm(form);
form.startView();
}
}
and says that setDetailForm() caches datas
As already said, attaching a detail form to a page means the detail form will automatically be
hidden when the page gets deactivated and shown when the page gets activated (see
PageDetailFormChanged on Desktop). So the detail form actually gets cached and does not need to
be started more than once per page. This requires that the form does not get closed.
But this don't work for me.
My code is
#Override
protected void execPageActivated() throws ProcessingException {
// / Create and open form
if (getDetailForm() == null) {
MarginCalculationForm form = new MarginCalculationForm();
form.startModify();
setDetailForm(form);
}
super.execPageActivated();
}
but it stays on last page.
For example :
If I have page A,B,C and I open page A it create it self and set it to detailForm(). If I then open page B it is OK too. But if I then click on page A again it check if the detailForm() is not null (and it is not) so it stays on page B (insted of going on page A)
EDIT :
I figure that getDetailForm() is returning the right form but apparently super.execPageActivated() don't work.
I found out what was wrong.
Problem is in DefaultPageChangeStrategy class in Scout. Method pageChanged() is like this :
#Override
public void pageChanged(IOutline outline, IPage deselectedPage, IPage selectedPage) {
if (outline == null) {
return;
}
outline.clearContextPage();
IForm detailForm = null;
ITable detailTable = null;
ISearchForm searchForm = null;
// new active page
outline.makeActivePageToContextPage();
IPage activePage = outline.getActivePage();
if (activePage != null) {
try {
activePage.ensureChildrenLoaded();
}
catch (ProcessingException e1) {
SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
}
if (activePage instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = tablePage.getTable();
}
if (tablePage.isSearchActive()) {
searchForm = tablePage.getSearchFormInternal();
}
}
else if (activePage instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = nodePage.getInternalTable();
}
}
}
// remove first
if (detailForm == null) {
outline.setDetailForm(null);
}
if (detailTable == null) {
outline.setDetailTable(null);
}
if (searchForm == null) {
outline.setSearchForm(null);
}
// add new
if (detailForm != null) {
outline.setDetailForm(detailForm);
}
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
if (searchForm != null) {
outline.setSearchForm(searchForm);
}
}
}
And if it is activePage a AbstractPage (and not AbstractPageWithTable AbstractPageWithNode), detailForm is always null and this break behavior.
So solution is to change AbstractPage with AbstractPageWithNode and add line
setTableVisible(false);
This line is needed because if it's not the firs time launch page will not be presented. (nodePage.getInternalTable() is not null but it is empty so :
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
will present empty page.)
I've little trouble with my simple game.
I'm using this code for menu control:
#pragma strict
var isIZADJI=false;
function OnMouseEnter()
{
renderer.material.color=Color.red;
}
function OnMouseExit()
{
renderer.material.color=Color.white;
}
function OnMouseUp()
{
if(isIZADJI)
{
Application.Quit();
}
else
{
Kontrola_Zivota.ZIVOTI=3;
Application.LoadLevel(1);
}
}
When I click "Play Again" it works fine but when I click "Exit" it just load first level.
Any help here?
I just thought I'd expand on the solution:
I was reading through your code and I see that what you were looking for was a way to identify which button was clicked. I would like to expand on your answer for anyone who want's to know what your solution was. The way to solve this is to create a string variable to check the name of the thing you are clicking (assuming this is GUI Button) and then to change the state of the var isIZADJI based on that eg:
// izlaz[croatian] = exit[english]
// First create a string var for the name of button/GUI/object
var nameOfButton : String;
function OnMouseUp()
{
if(!(nameOfButton == "izlaz"))
{
isIZADJI = false;
}
else
{
isIZDAJI = true;
}
// And then now you can add the rest of your code to quit or load a level
if(isIZADJI)
{
Application.Quit();
}
else
{
Kontrola_Zivota.ZIVOTI=3;
Application.LoadLevel(1);
}
}
I hope this helps anyone else with this problem.
is there a good or proper way to render the output in Play Framework depending on a parameter? Example:
For HTML:
http://localhost:9000/user/get/5?v=HTML // should render HTML template
For JSON:
http://localhost:9000/user/get/5?v=JSON // should render JSON template
I think that a request interceptor could have the ability to achieve this, but I have no clue how to start or where to start :-(
Or perhaps, write a general render method that reads the parameters and output as requested, but this seems to me like overkill?
If /user/5?v=html and /user/5?v=json return two representations of the same resource, they should be the same URL, e.g. /user/5, according to the REST principles.
On client side, you can use the Accept header in your requests to indicate which representation you want the server to send you.
On server side, you can write the following with Play 2.1 to test the value of the Accept header:
public static Result user(Long id) {
User user = User.find.byId(id);
if (user == null) {
return notFound();
}
if (request().accepts("text/html")) {
return ok(views.html.user(user));
} else if (request().accepts("application/json")) {
return ok(Json.toJson(user));
} else {
return badRequest();
}
}
Note that the test against "text/html" should always be written prior to any other content type because browsers set the Accept header of their requests to */* which matches all types.
If you don’t want to write the if (request().accepts(…)) in each action you can factor it out, e.g. like the following:
public static Result user(Long id) {
User user = User.find.byId(id);
return representation(user, views.html.user.ref);
}
public static Result users() {
List<User> users = User.find.all();
return representation(users, views.html.users.ref);
}
private <T> Result representation(T resource, Template1<T, Html> html) {
if (resource == null) {
return notFound();
}
if (request().accepts("text/html")) {
return ok(html.apply(resource));
} else if (request().accepts("application/json")) {
return ok(Json.toJson(resource));
} else {
return badRequest();
}
}
Write 2 methods, use 2 routes (as you don't specify I will use Java samples:
public static Result userAsHtml(Long id) {
return ok(someView.render(User.find.byId(id)));
}
public static Result userAsJson(Long id) {
return play.libs.Json.toJson(User.find.byId(id));
}
routes:
/GET /user/get/:id/html controllers.YourController.userAsHtml(id:Long)
/GET /user/get/:id/json controllers.YourController.userAsJson(id:Long)
next you can just make a link in other view to display user's data
Show details
Get JSON
or something else...
edit #1
you can also use common if or case to determine final output
public static Result userAsV() {
String vType = form().bindFromRequest().get("v");
if (vTtype.equals("HTML")){
return ok(someView.render(User.find.byId(id)));
}
return play.libs.Json.toJson(User.find.byId(id));
}
I wanted the user to be able to be viewed in the browser as html or as json so the accepts method did not work for me.
I solved it by putting a generic renderMethod in a base class with the following style syntax
public static Result requestType( )
{
if( request().uri().indexOf("json") != -1)
{
return ok(Json.toJson(request()));
}
else
{
return ok("Got HTML request " + request() );
}
}