Changing footer information - jquery-mobile

I have a set of individual pages. The footer of each page has a button reading "Sign in" which, when tapped, leads the user to the login page. If the login is successful, the user is moved to a different page; if not, they are returned to the login page.
I want to be able to change the "Sign in" label to "Sign out" and its href to the logout page when a successful login occurs. But I don't seem to be able to reference the element.
The html in the footer element is:
<a class="inout ui-link ui-btn" rel="external" href="login.php">
<span class="ui-btn-inner">
<span class="ui-btn-text">Log in</span>
</span>
</a>
Running a simple jq command such as
$('a.inout').attr('href','logout.php');
when the user arrives at the "successful login" page fails to connect.
I'm missing something - I'd appreciate some illumination.
Thanks/B

You can make the call in the jQM pagebeforeshow event handler, so as each new page is loaded, the footer button will be updated:
$(document).on("pagebeforeshow", "#pageid", function(){
$('a.inout').prop('href','logout.php');
});

Related

Ask user to save changes before leaving a web page - Angular JS

I am creating an ASP.net MVC application with C#.
In the main .cshtml page, I am showing a list of user names on the left hand side of the page.
When the user clicks on any Username from the left, it display the "Personal Details" form for that User in a "partial view" on the Right Hand Side of the page.
Current Functionality
There is a "Save" button on the "Personal Details" Partial view form.
User can make changes in the Personal Details and hit Save to save the changes made in the partial view.
Desired Functionality
User makes changes in the Personal Details of any record.
Now, the user forgot to hit Save and clicked on the Other Username from the left hand side.
It should "AUTOMATICALLY SAVE" the changes made in the partial view.
Is it possible to execute the Save button trigger event of the partial view from main view ?
When you want to save the form automatically you can call angular Submit on Other Username click , This snippet shows example of how.
The onUserNameClick() method invokes same angular submit.
function Ctrl($scope) {
$scope.list = [];
$scope.text = 'hello';
$scope.submit = function() {
if ($scope.text) {
$scope.list.push($scope.text);
$scope.text = '';
}
};
}
function onUserNameClick() {
angular.element('#submit').trigger('click');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<div ng-app>
<div ng-controller="Ctrl">
<form ng-submit="submit()">Enter form input values to test
<input type="text" ng-model="text" name="text" />
<input type="submit" id="submit" value="Regular Form Submit" />
<pre>Form values={{list}}</pre>
</form>
</div>
</div>
<button onClick="onUserNameClick()">Other username click</button>

How to find a link that has text nested in a div with Capybara?

I'm trying to find a link in my navbar, nested like so:
<div class="menu logged-out" id="loggedoutmenu">
<a href="/users/auth/twitter?state=navbar_basic" data-no-instant>
<div class="option"> via Twitter</div>
</a>
</div>
I've tried using the following methods and none of them have worked:
find_link("via Twitter")
find_link("via Twitter", {href: "/users/auth/twitter?state=navbar_basic"})
find('div', {class: 'option'})
Not really sure how to grab that element... The main goal is to test the link via click_link.
Edit:
Here's the full HTML structure:
<body>
<div class="top-bar" id="top-bar">
<nav>
<--- other nav elements not listed --->
<div class="navigation-butt desktop" id="navigation-butt">
<div class="menu logged-out" id="loggedoutmenu">
<a href="/users/auth/twitter?state=navbar_basic" data-no-instant>
<div class="option"> via Twitter</div>
</a>
</div>
</div>
</nav>
</div>
</body>
I'm guessing the menu is collapsed and you haven't done anything to open it, so the link isn't actually visible on the page. Assuming you just need to click on the '#loggedoutmenu' item to open the menu you could do something like
find('#loggedoutmenu').click.click_link('via Twitter')
which will click on 'loggedoutmenu' then look for the link inside it, and click the link when found. If clicking on '#loggedoutmenu' isn't how you open the menu then you'll need to provide more info.
Update: You have now indicated that the menu opens on hover - so assuming the user has to hover over an ancestor of the button you want to click you can do
find('<css selector for the visible element the user needs to hover over>').hover.click_link('via Twitter')
Writing my solution as an extension of Thomas Walpole's, which lead me to getting it. Thanks again, Thomas!
find('#navigation-butt').hover.click_link(href:"/users/auth/twitter?state=navbar_basic")
Edit: Updated my answer since the previous explanation was incorrect.

LInk does not work with jquery Mobile

I am using jQuery Mobile and CodeIgniter. In my index page,
http://localhost:8888/hwezemail2/index.php/welcome/student/index
I have a link to another page.
http://localhost:8888/hwezemail2/index.php/welcome/student/myhomework/56
But when I click the link, it will go to the following and does not display.
http://localhost:8888/hwezemail2/index.php/welcome/student/index#/hwezemail2/
index.php/welcome/student/myhomework/56
Then I refresh the page once the url becomes
http://localhost:8888/hwezemail2/index.php/welcome/student/myhomework/56
But it does not display the content. So I refresh it again then it shows the content.
Once it shows, then I don't have any problem. It is only the first time.
My PHP code it the following.
echo '<a href="'. base_url().'index.php/welcome/student/myhomework/'
.$userid.'" data-role="button" data-inline="true" data-transition="pop"
data-icon="star" data-mini="true" data-theme="c">Missed Homework</a>';
I added data-ajax="false" to the link and the problem was solved.

How to use a template for all jQuery Mobile pages?

Behold: a footer template:
<!-- Templates -->
<script type="text/template" id="templateFooter">
<div data-role="navbar">
<ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</script>
In every mobile page I have:
<div data-role="footer" data-position="fixed">footer</div>
The way I'm currently loading the template is:
$(function() {
$('div[data-role=footer]').html($('#templateFooter').html());
$.mobile.activePage.trigger('create');
});
This works, but I don't really like using $(function(), but I need to load it if any page shows, so pageinit or pageshow does not help. I'll be using knockout.js going forward, if that is of any help.
Is there a better way to do this?
function getTemplateFooter() {
//return footer text here
}
$("div:jqmData(role='page')").live("pagebeforecreate",function() {
// get the footer of the page
// if footer doesn't exist on page, insert it where you want it... in this case after role="content"?
var $content =$(this).page().find('div:jqmData(role="content")');
$content.after(getTemplateFooter());
}
there is also a pageshow event, that one fires even if the user navigates to the page, through a back button press etc... it bubbles up to the page div
I use it for pages where lots of dynamic data could change between subsequent visits, or even when the user just presses back

creating a partial view which changes the content of page using commands provided in URL

I am showing a modal popup when someone click login button and then they can enter their credentials, if successful they can move forward but if not an on the modal shows ...
this is working fine ...
but my concern is below submit button I have a link 'Forgot password', and I want it to be action that when user clicks it, it hides the login content and display the retrieve password content in the same and then user enters the details and can get the info he wants ...
can any one give me some code example or something ...
Using jQuery for example...
<div id="loginform">
your form markup..
Forgot password?
</div>
<div id="forgotpassword" style="display:none">
<form id="passwordform">
forgot password markup....
</form>
</div>
<script language="javascript" type="text/javascript">
$('#forgot').click(function () {
$('#loginform').hide();
$('#forgotpassword').show();
return false;
});
</script>
You can then submit the form using the jQuery $.ajax() function and replace the forgot password div with the result etc...

Resources