Sammy.js intercepts all click events - sammy.js

I am using knockout and sammy together. I have a mobile page where i declared
$.sammy('#portal', function(){.....}).
outside '#portal' I have a regular anchor
friends.
The issue is that when i click the anchor the url is updated but the page stays at the original page where i have sammy loaded....I thought that sammy will only trigger if the event was coming from '#portal'. Does someone knows why the page is being locked and not redirecting?

Try using '/' instead of '' for your sammy default route.

Related

how to create middleware in laravel

I have created the project which has login page login.blade.php which has only Regno to login-in.
once it login is the success it will redirect to home.blade.php and it followed by 4 more pages when clicking of next button in each page
page2.blade.php,page3.blade.php,page4.blade.php,page5.blade.php and finally, it should redirect to login page itself. The problem is the browser back button should not allow it to go back to the previous page.
can anyone suggest me how to create middleware for this?
thank you.
The browser's back button is not controlled by the server, where Laravel runs. There is no way for you to block it or interact with it in any way inside your PHP code.
What you can do is send XMLHHTTPRequest (XHR) with JavaScript. They ensure that on a button click you will stay on the same page in the browser and then your JS-code can read the server response (your rendered page templates) and replace the current content with the one from that response. You can read more on this when you google for AJAX, e.g. this article: https://www.sitepoint.com/use-jquerys-ajax-function/
Read this thing. I once implemented in the same way. By setting cache control in response header.
https://stackoverflow.com/a/51821808/10239067

Issue with laravel route with Ajax

I have my main container (app.blade.php) and inside it I have my home.blade, inside there is a container that refreshes with ajax after clicking an item in the sidenav menu. If you click one of those items when the session has expired, a middleware redirects you to the login (or at least it’s meant to). This should happen
God login
The issue is that, when that event happens, it renders the login inside of the container refreshed with ajax, like in the picture below. Any idea of how to solve this?
Bad login
(Sorry if i have issues in my writing, i am still learning english and in stackoverflow in spanish nobody helps :/)
Your "middleware" is working OK, it is doing what is meant to do: Any petition to the server is transformed in a redirection to your login page. However, you are making an async call. I guess you are rendering whatever the result is in a container, resulting in your "bad login".
A possible solution is to add some parameter to your ajax requests in order to catch it on the server side and send you an error status instead of a redirection, then in your page handle that error as a browser redirection to your login.

Facebook like button's iframe not expanded after ajax request

I'm adding a facebook share button to each post on a Wordpress (Using Facebook Share Button New plugin), it works ok for each post/page except when i'm loading them trough ajax, the result it's a normal Facebook like button but the popup (to write a comment) appears inside the button it is not expanded.
To check go to: http://iwanttobeher.com/ and then click on any face at the bottom of the page, then test the like button and you'll see what happens.
I don't know what to do, i tried to FB.XFBML.parse() after loading the content but the result is the same.
Switching to HTML5 didn't help in our case. What did was to remove the FB object just prior to new content being inserted into the page via Ajax:
delete FB;
wrapper.html(response.data);
We reload full pages via Ajax and so new page content recreates the FB object and re-initializes XFBML anyway. Not sure if this workaround would work if we reloaded only parts of the page though.
The original answer is here.
I've managed to fix it by changing the implementation to HTML5 instead Iframe or XFBML using Facebook's tool to generate like buttons: https://developers.facebook.com/docs/reference/plugins/like/

How to do ajax loading with URL change but not page redirection?

If you carefully notice facebook, you will understand that the when you visit one page to another then the whole page is not refreshed or redirected but the URL changes when navigating to new page. It is more clear when chat windows are open, they remains static during page loading. As other website does this by using the # but facebook does not.
There is another example came to me: http://www.davidwalsh.name/. Visit the site and open other pages within their site and you will understand what I mean. Don't forget to notice the URL change.
How they do this?
Added More: I want a way that the page content will be loaded with ajax, change the URL for bookmark feature but when changing URL it should not reload / refresh the page by not using # (hash).
You have two questions:
For the URL change you can put the path instead of the # in the href property of the anchor (e.g /otherlink).
For opening the chat or opening some div does not require to send it in the url, its the onclick event on the div and its expands. Also the chat remains open may be thay set cookie or flag when the chat is first time opened and checking and changing the chat with flag they are setting.
As suggested by #andytuba
For Facebook, Google "hash navigation ajax".
For DavidWalsh, google "history API".

Blocking a Route or URL in Sammy

I am new to Sammy and I would like to know if there is a way to block Sammy from redirecting to a specific route or URL.
There is a method called "setLocation" that is called everytime a redirection is needed. I would like to block the acces to one or more URL.
Can Sammy do it ???
Thanks in advance
Sammy can only do this on known routes buy using the 'before' method on the sammy object (see the sammy docs). In the before you can check if navigation is enabled
Any other url (www.google.com, www.yourdomain/sammysinglepageapp2 etc) cannot be blocked
Consider using Sammy.around(callback) as defined here:
Sammy.js docs: Sammy.Application around(callback)
For a more detailed response, see Cancel route using Sammy.js without affecting history

Resources