Page redirection issues with a popup/button (jQuery mobile) - jquery-mobile

I've created a button
<a data-role="button">
inside a Popup. Here is Popup:
<div data-role="popup" id="popupRegister" data-theme="a" data-dismissible="false">
<div data-role="header" data-theme="b" class="ui-header ui-bar-b"
role="banner">
<h1 class="ui-title" role="heading" aria-level="1">Success!!</h1>
</div>
<div data-role="" data-theme="a" class="ui-body-a"
role="main" style="padding:15px;">
<h1>Thank you for regestering with us.</h1>
<p>You may now continue to the app.</p>
<!-- this is the button -->
<a href="#" id="takeMeHome" data-role="button" data-rel="back"
data-theme="a" data-inline="true"
data-corners="true" data-shadow="true"
data-iconshadow="true" data-wrapperels="span"
class="ui-btn ui-shadow ui-btn-corner-all ui-btn-inline ui-btn-up-a">
<span class="ui-btn-inner"><span class="ui-btn-text">GO</span></span>
</a>
</div>
</div>
When I click the button, console.log is responding but page does not redirect. Why?
Here is how I redirect:
$("#takeMeHome").click( function(){
console.log("lets go home");
//window.location.href = "home.html";
//localStorage.registered=true;
//window.location.replace("home.html");
window.location.href = ("home.html");
});

Replace
window.location.href = ("home.html");
with
$.mobile.changePage('home.html');
And add data-history="false" to popup div.

Related

Dialog close went to previous page

Expected Scenario: I have two div in one page one is popup and other is the main page. When I click on popup popup should open and when i click close on pop up it should show the other div
Actual Scenario: WHen I close it doesnot show the other div instead it goes to the previous page
Using Jquery Mobile 1.3.0
$.mobile.changePage("#publishlogonmanage", { role: "dialog", transition:"slideup",reload:false,reverse: false,changeHash: false });
PopUP COde
<div data-role="page" id="publishlogonmanage" data-history="false" data-overlay-theme="b" data-theme="b">
<div data-role="header" data-theme="a">
<a data-icon="delete" id="logonClose" data-mini="true" data-theme="a" data-rel="back" data-role="button" class="ui-btn-left"></a>
<a data-icon="delete" data-theme="a" data-transition="flip" data-rel="back" data-mini="true" data-role="button" class="ui-btn-left" style="width:80px;" >Close</a>
</div>
<div data-role="content" style="padding: 0; margin: 0; background: #FFFFFF;">
This is Body
</div>
</div>
Main Page:
<div data-role="page" data-theme="b" id="MobilePage" data-overlay-theme="b">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="a">
<div style="float: left; margin-left: 5px;"> Back</div>
<h1 id="title"> 10 </h1>
</div>
<div data-role="content" class="master-wrapper-page">
This is body
<div style="margin-top:7px;display:none;float: right !important; margin-left: 0px !important;overflow:ellipsis;white-space: nowrap;" data-close-btn="right" id="ManageLogon" data-mini="true" onclick="LoadDialog();" data-rel="popup"></div><img src="../../../images/logon-E.png" style="1px solid #666666;margin-top:3px;margin-right:-5px float: right;height:30px;width:30px;" id="logonexp" /></div>
</div>
</div>

Delete list element from a confirmation popup

I have a list with delete button for each element , when the user click on the delete button a confirmation dialog appear ,if the user press the OK button i want to delete the list element my problem is how to get the <li> list element index in order to remove it from the list , my code not return the correct index , please help me ..
<div data-role="page">
<div data-role="content">
<ul data-role="listview" id="employeesList" data-inset="true" data-split- icon="delete">
<li><a href="#">
<font class="line1" > Emp1Name</font>
<font class="line2" >Emp1Salary</font>
</a><a href="#DeleteConfirm" data-rel="popup" data-position-to="window" data- transition="pop" >Delete</a></li>
<li><a href="#">
<font class="line1" > Emp2Name</font>
<font class="line2" >Emp2Salary</font>
</a>Delete</li>
</ul>
<div data-role="popup" id="DeleteConfirm" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="width:400px;height:200px;" class="ui-corner-all">
<div data-theme="c" style="text-align:center;float:center;height:53px;padding-top:13px;" >
<font size="6px" >Delete</font>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<font size="5px" >Do you want to delete this Employee?</font>
<BR>
<div style="text-align:center;font-size: 22px;" >
<input type="button" id="No" data-inline="true" data-icon="delete" data-theme="c" value="No " />
<input type="button" id="Yes"data-inline="true" data-icon="check" data- theme="c" value=" Yes" data-corners="false"/>
</div>
</div>
</div>
</div>
Java script code:
var SelectedLi ;
$('#DeleteConfirm').on('click',function(){
SelectedLi= $(this).parent().index();
});
$('#Yes').on('click',function(){
$('#employeesList').remove(SelectedLi);
$('#DeleteConfirm').popup('close');
});
$('#No').on('click' ,function(){
$('#DeleteConfirm').popup('close');
});
You have mistake in binding event to split button, it should be as follows:
var SelectedLi ='' ;
$('[href=#DeleteConfirm]').on('click',function (e) {
// store parent of clicked button
SelectedLi = $(this).closest("li");
});
$('#Yes').on('click',function(){
$(SelectedLi).remove();
$('#employeesList').listview("refresh");
$('#DeleteConfirm').popup('close');
});
$('#No').on('click' ,function(){
$('#DeleteConfirm').popup('close');
});
Demo
This is how I do my popup:
HTML:
<div data-role="popup" id="sterge" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="max-width:400px;" class="ui-corner-all">
<div data-role="header" data-theme="b" class="ui-corner-top">
<h1>Delete?</h1>
</div>
<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
<h3 class="ui-title">To Delete Product from Bonus?</h3>
<p>This action cannot be undone.</p>
<input id="giveupButton" data-inline="true" type="button" value="Cancel"/>
<input id="delButton" data-inline="true" onclick="deletebonusproduct();" data-theme="b" type="button" value="Delete"/>
</div>
</div>
JS:
$(document.body).on('click', '.del' ,function(){
li = $(this).parent();
$('#sterge').popup("open");
});
$(document.body).on('click', '#delButton' ,function(){
$('#sterge').popup("close");
li.remove();
});
$(document.body).on('click', '#giveupButton' ,function(){
$('#sterge').popup("close");
});

ajax implement on internal pages jquery mobile

im making an internal page jquery mobile ive search question here in stackover but those are not similar to mine.i want to know if it is possible to use ajax in loading internal pages.i want to load my about1 page and about2 page in the about page here is my sample code:
<!-- start about -->
<div data-role="page" id="about" data-url="about" data-theme="a">
<div data-theme="a" data-role="header" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >
Header
</h3>
<!-- working back button go back -->
<a data-role="button" data-rel="back" class="ui-btn-left ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Back
</span></span></a>
<a data-role="button" href="#home" class="ui-btn-right ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Home
</span></span></a>
</div>
<div data-role="header" data-icon="bars" data-theme="d" class="ui-header ui-bar-b" >
<h1 class="ui-title" >About</h1>
</div>
<!-- start ajax -->
<ul data-role="listview" data-theme="a" id="mylist" class="ui-listview">
<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="a" class="ui-btn ui-btn-up-a ui-btn-icon-right ui-li-has-arrow ui-li ui-screen-hidden">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
about
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow">
</span>
</div>
</li>
<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="a" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-a">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
about
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span>
</div>
</li>
<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="a" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-last ui-btn-up-a">
<div class="ui-btn-inner ui-li">
<div class="ui-btn-text">
about2
</div>
<span class="ui-icon ui-icon-arrow-r ui-icon-shadow"> </span>
</div>
</li>
</ul>
<!-- end ajax -->
<div data-theme="a" data-role="footer" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >Footer</h3>
</div>
</div>
<!-- end about -->
<!-- start about1 -->
<div data-role="page" id="about1" data-url="about1">
<div data-theme="a" data-role="header" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >
Header
</h3>
<!-- working back button go back -->
<a data-role="button" data-rel="back" class="ui-btn-left ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Back
</span></span></a>
<a data-role="button" href="#home" class="ui-btn-right ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Home
</span></span></a>
</div>
<div data-role="header" data-icon="bars" data-theme="d" class="ui-header ui-bar-b" >
<h1 class="ui-title" >About1</h1>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >Footer</h3>
</div>
</div>
<!-- end about1 -->
<!-- start about2 -->
<div data-role="page" id="about2" data-url="about2">
<div data-theme="a" data-role="header" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >
Header
</h3>
<!-- working back button go back -->
<a data-role="button" data-rel="back" class="ui-btn-left ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Back
</span></span></a>
<a data-role="button" href="#home" class="ui-btn-right ui-btn ui-shadow ui-btn-corner-all ui-btn-up-a" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a"><span class="ui-btn-inner"><span class="ui-btn-text">
Home
</span></span></a>
</div>
<div data-role="header" data-icon="bars" data-theme="d" class="ui-header ui-bar-b" >
<h1 class="ui-title" >About2</h1>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" class="ui-footer ui-bar-a ui-footer-fixed slideup" >
<h3 class="ui-title" >Footer</h3>
</div>
</div>
<!-- end about2-->
If you want to do jquery mobile page load as AJAX,
Your AJAX should be,
$( "#your_success_ele_id1" ).load( "about1.html", function() {
$('#your_success_ele_id1').trigger('create');
});
$( "#your_success_ele_id2" ).load( "about2.html", function() {
$('#your_success_ele_id2').trigger('create');
});
trigger('create') should be used, otherwise you will get an normal html page
This you can use for onclick of an element.

How to show pages on right side with panel in jquery mobile

I am able to implement panel .But i need my pages should display with panel.Actually when i click panel button's then it hide panel .show page on whole screen .But i need to show page with panel.
Here is my code.
http://jsfiddle.net/ravi1989/TXRjk/2/
Jump to second page
Jump to third page
First Page
Next
Open Pannel
<div data-role="page" id="second">
<div data-role="panel" id="mypanel">
Jump to first page
Jump to third page
</div>
<div data-theme="a" data-role="header">
<h3>
Second Page
</h3>
Back
</div>
<div data-role="content">
<a data-role="button" id="open-panel">Open Pannel</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
<div data-role="page" id="third">
<div data-role="panel" id="mypanel">
Jump to first page
Jump to second page
</div>
<div data-theme="a" data-role="header">
<h3>
Third Page
</h3>
Back
</div>
<div data-role="content">
<a data-role="button" id="open-panel">Open Pannel</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
I think it should be what you're wanting:
<div data-role="page" id="index">
<div data-role="panel" id="mypanel">
Jump to index page
Jump to second page
Jump to third page
</div>
<div data-theme="a" data-role="header">
<h3 id="header-page">
First Page
</h3>
</div>
<div data-role="content" id="content-page">
<a data-role="button" href="#mypanel">Open Pannel</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" id="footer-page">
.
</div>
</div>
<div class="soHide" id="index">
<div data-theme="a" data-role="header">
<h3 id="header-index">
First Page
</h3>
</div>
<div data-role="content" id="content-index">
<a data-role="button" href="#mypanel">Open Pannel</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" id="footer-index">
.
</div>
</div>
<div class="soHide" id="second">
<div data-theme="a" data-role="header">
<h3 id="header-second">
Second Page
</h3>
</div>
<div data-role="content" id="content-second">
<p>this is a second page</p>
<a data-role="button" href="#mypanel">Open Pannel again</a>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" id="footer-second">
footer second page
</div>
</div>
<div class="soHide" id="third">
<div data-theme="a" data-role="header">
<h3 id="header-third">Third Page</h3>
</div>
<div data-role="content" id="content-third">
<a data-role="button" id="open-panel">Open Pannel one more time</a>
<p>it's third!</p>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" id="footer-third">
it's some third footer page
</div>
</div>
and this javascript:
$(document).on('click', '.btnPages', function(){
var page = $(this).attr('data-idpage');
var header = $("#header-"+page).html();
var content = $("#content-"+page).html();
var footer = $("#footer-"+page).html();
// apply
$("#header-page").html(header).trigger('create');
$("#content-page").html(content).trigger('create');
$("#footer-page").html(footer).trigger('create');
});
and this css:
.ui-panel-animate {
transition: transform 1350ms ease 0s !important;
}
.soHide { display: none; }
and this functional example http://jsfiddle.net/wgbn/Hxy37/

jQueryMobile : How to add contents to Collapsible Div Dynamically

I have a collapsible-set div and within that 2 collapsible divs.
And I have to dynamically add elements to these collapsible divs dynamically, when clicking a plus button. I have tried many codes, but didn't work. Could you please tell me how to do that?
HTML Code
<div data-role="content">
<div data-role="collapsible-set" id="setAllCategory">
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u" id="setCategory1">
<h1 ><label>Food</label>
<a data-role="button" id="btnAddSubCat1" name="btnAddSubCat1" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u" id="setCategory2">
<h1 ><label>Dress</label>
<a data-role="button" id="btnAddSubCat2" name="btnAddSubCat2" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
</div>
</div>
JavaScript
var subCatObject = "<div class='ui-grid-b'>"
subCatObject +="<div class='ui-block-a'><label>Hi</label></div>"
subCatObject +="<div class='ui-block-b'><a href='#' data-role='button' data-iconpos='notext' data-icon='edit'></a></div>"
subCatObject +="<div class='ui-block-c'><a href='#' data-role='button' data-iconpos='notext' data-icon='delete'></a></div>"
subCatObject +="</div>";
$('#btnAddSubCat1').click(function (){
var temp = $(subCatObject);
$(temp).appendTo('#setCategory1').page();
$("#setCategory1").collapsibleset('refresh');
});
I changed your HTML as below
<div data-role="page" id="home">
<div data-role="content">
<div data-role="collapsible-set" id="setAllCategory" data-content-theme="d">
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u"
id="setCategory1">
<h1><label>Food</label>
<a data-role="button" id="btnAddSubCat1" name="btnAddSubCat1" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
<div id="setCategoryContent1"></div>
</div>
<div data-role="collapsible" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u"
id="setCategory2">
<h1><label>Dress</label>
<a data-role="button" id="btnAddSubCat2" name="btnAddSubCat2" data-rel="popup" href="#" data-icon="plus" data-iconpos="notext" style="float:right;" ><a/></h1>
</div>
</div>
</div>
</div>
and your javascript as below
var subCatObject = "<div class='ui-grid-b'>"
subCatObject += "<div class='ui-block-a'><label>Hi</label></div>"
subCatObject += "<div class='ui-block-b'><a href='#' data-role='button' data-iconpos='notext' data-icon='edit'></a></div>"
subCatObject += "<div class='ui-block-c'><a href='#' data-role='button' data-iconpos='notext' data-icon='delete'></a></div>"
subCatObject += "</div>";
$('#btnAddSubCat1').bind('click', function () {
$("#setCategoryContent1").html(subCatObject);
$('#home').trigger('create');
});
I hope you will be able to take up from here.
Check out the working fiddle here http://jsfiddle.net/PKeSB/2/

Resources