jQuery mobile popup dynamic URL - jquery-mobile

I have problem of dynamically URL in a popup. Here my code:
<!-- content -->
<ul data-role="listview">
<li data-role="list-divider">Group 1</li>
<li data-icon="false">List 1a</li>
<li data-icon="false">List 1b</li>
<li data-role="list-divider">Group 2</li>
<li data-icon="false">List 2a</li>
</ul><!-- /content -->
<!-- popup-menu -->
<div data-role="popup" id="popup-menu">
<ul data-role="listview" style="min-width:210px;">
<li data-role="divider">Choose an action</li>
<li>View details</li>
<li>Share</li>
</ul>
</div><!-- /popup-menu -->
Basically, when I click link on my popup, I'll go to the page where the callee's url is.
So, if I click List 1a the popup shows, then I click View details the page direct me to URL person.php?id=1
How can I do that?
I could just create popup divs multiple times according to the number of the list, but I think it's a waste of DOM object (my last resort if I don't find any elegant solution)
Thanks

Since you actually need to pass only an id of a person to your popup you can achieve your goal this way:
First of all simplify your listview markup and store an id in data-id attribute of an anchor of a listview item
<ul data-role="listview" id="list">
<li data-role="list-divider">Group 1</li>
<li data-icon="false">List 1a</li>
<li data-icon="false">List 1b</li>
<li data-role="list-divider">Group 2</li>
<li data-icon="false">List 2a</li>
</ul>
and add an id tag to 'View Details` anchor in your popup for easier access later on
<li><a id="details" href="#">View details</a></li>
Second on click() event store current id to a globally available variable (let's call it currentId) and programmatically open the popup.
var currentId = 0;
...
$('#page').on('pageinit', function(){
$('#list li a').click(function(e){
e.preventDefault();
currentId = $(this).attr("data-id");
$("#popup-menu").popup("open", {transition:"slideup"} );
});
});
Third in popupbeforeposition event construct your url and assign it to appropriate anchor.
var baseURL = "person.php?id=";
...
$('#popup-menu').on('popupbeforeposition', function(){
$("#details").attr("href", baseURL + currentId);
});
And finally here is working jsFiddle for you.

Related

how to hide / show menu items dynamically in popup in jquery mobile

I have a popup menu like this:
Menu
<div data-role="popup" class="popup" id="MenuBeobListe" data-theme="a">
<ul data-role="listview" data-inset="true" style="min-width:210px;">
<li data-role="list-divider">MenĂ¼:</li>
<li class="admin"><a class="menu_artengruppen_importieren" href="#">Artengruppen importieren</a></li>
<li class="admin"><a class="menu_arten_importieren" href="#">Arten importieren</a></li>
<li><a class="menu_hierarchischer_modus" href="#">hierarchischer Modus</a></li>
<li><a class="menu_felder_verwalten" href="#">Felder verwalten</a></li>
<li><a class="menu_beob_exportieren" href="#">Beobachtungen exportieren</a></li>
<li><a class="menu_einstellungen" href="#">Einstellungen</a></li>
<li><a class="menu_neu_anmelden" href="#">neu anmelden</a></li>
</ul>
</div>
When an admin logs in to my app I want to set additional menu items visible. These items are already included in the html and have class "admin". They are initially hidden like this:
.popup .admin {
display: none;
}
After an admin logs in I try to show them like this:
$(".popup").find(".admin").css("display", "block");
$(".popup").popup();
This doesn't work even though if I run
$(".popup").find(".admin").css("display", "block");
directly in the browser, the menu-items for admins are shown.
Can you help please?

Kendo UI Mobile - How to display 2 listview on a view?

I want to show a view with 2 listview like this:
But when I implement by Kendo UI Mobile with:
<div id="cptTab" data-role="view" data-title="Billing" data-layout="billing-layout">
<header data-role="header">
<div data-role="navbar">
<span data-role="view-title">CPT</span>
<a data-align="left" data-role="button" href="#censusmainTab">Census</a>
<a data-align="right" data-role="button" data-click="onNavigateToAddCpt">+</a>
</div>
</header>
<div>
Patient:
<label>
<input readonly="true" class="PatientNameLabel" />
</label>
</div>
<div>NEW CPT's</div>
<ul data-role="listview" id="cptsListView" data-click="onCPTItemClicked" />
<div>PREVIOUS CPT's</div>
<ul data-role="listview" id="cptsPreviousListView" data-click="onPreviousCPTItemClicked" />
</div>
But it display like this, it's missing 2nd listview (Previous listview):
Please let me know if I did something wrong or it's a bug of Kendo UI Mobile.
Thanks
You could use
<ul data-role="listview" data-type="group" id="ListView" data-click="onItemClicked"/>
to create two group, the first for new CPT's and the second for previous CPT's.
The function onItemClicked should change its behaviour according to which group is clicked.
see the documentation for better details
Try this code
<ul data-role="listview" data-style="inset" data-type="group">
<li>NEW CPT's
<ul>
<li>
<a> 1 st item in 1st list view </a>
</li>
</ul>
</li>
<li>PREVIOUS CPT's
<ul>
<li>
<a >1 st item in 2nd list view </a>
</li>
<li>
<a >2nd item in 2nd list view </a>
</li>
</ul>
</li>
</ul>
For live demo click Here

Collapsible listview in a jquery mobile external panel not displaying correctly

Can anyone please help me?
I'm trying to create a menu inside an external jquery mobile panel. This is JQM 1.4.0 that supports external panels.
I have a collapsible listview inside the external panel. There is some kind of inset applied that I don't seem to be able to get rid off for submenu3 and inside it as well.
Please check out my fiddle: http://jsfiddle.net/UHYz9/2/
Here's the html:
<div data-role="page" class="jqm-demos" data-quicklinks="true">
<div data-role="header">
<h1>External panels</h1>
</div>
<div role="main" class="ui-content jqm-content jqm-fullwidth">
Open External Panel
</div>
</div>
<div data-role="panel" id="externalpanel" data-position="left" data-display="reveal" data-theme="a">
<h3>Menu</h3>
<ul data-role="listview" style="padding-right: 8px">
<li>Submenu 1</li>
<li>Submenu 2</li>
<li data-role="collapsible" data-iconpos="right" data-inset="false">
<h2>Submenu 3</h2>
<ul data-role="listview">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Submenu 4</li>
<li>Submenu 5</li>
</ul>
</div>
Here's the js:
$(function() {
$("body>[data-role='panel']").panel();
$("#externalpanel ul").listview();
$("#externalpanel").trigger("create");
});
For this to work, please include the following css and js links:
http://demos.jquerymobile.com/1.4.0/css/themes/default/jquery.mobile-1.4.0.min.css
http://demos.jquerymobile.com/1.4.0/js/jquery.js
http://demos.jquerymobile.com/1.4.0/js/jquery.mobile-1.4.0.min.js
Thanks a lot!
You need to wrap contents on panel in <div data-role="content"> or `.
To enhance content of panel or any other div, use .enhanceWithin().
$(function () {
$("body>[data-role='panel']").panel().enhanceWithin();
});
Demo

jQuery Mobile - Popup in nested list view

I try to create a listview where elements with no children can have an edit button. When the user clicks to this button a popup menu should appear.
Here is the code inside a singe JQM page.
<div data-role="content">
<ul data-role="listview">
<li>
<h3>Colors</h3>
<ul>
<li>Blue
<p class="edit">
<a href="#" onclick="openEditMenu()" data-role="button"
data-icon="gear" data-inline="true" data-iconpos="notext">Edit</a>
</p>
</li>
<li>Orange</li>
<li>Purple</li>
</ul>
</li>
<li><h3>Item</h3>
<p class="edit">
<a href="#" onclick="openEditMenu()" data-role="button"
data-icon="gear" data-inline="true" data-iconpos="notext">Edit</a>
</p></li>
</ul>
</div>
<div data-role="popup" id="popupMenu">
<ul data-role="listview" data-inset="true" >
<li data-role="divider" data-theme="a">Edit Element</li>
<li>Edit</li>
...
</ul>
</div>
<script>
function openEditMenu() {
$('#popupMenu').popup('open');
}
</script>
On the first level this works like expected. If you navigate to the second level of the nested list, the popup is not shown.
I saw that popups in JQM has to be placed on the same page. It seems that JQM does not find the popup on the subpages of the listview.
Has somebody realized successfully such a solution or it is not possible with the popup feature of JQM 1.2?
On jsfiddle you can find my example code.
Thanks for tipps or suggestions.
As you said in the comments above, from the jQm documentation 'A popup div has to be nested inside the same page as the link.'.
What you could try is clone the popup and attach it to the other page. Then you have re-initialize and open it.
You could try something like:
var nestedLiPage = $(".ui-page-active");
$('#popupMenu').clone().appendTo(nestedLiPage).popup().popup('open');
[Solved]
http://jsfiddle.net/F9awk/
function openEditMenu() {
var nestedLiPage = $(".ui-page-active");
$('#popupMenu').clone().appendTo(nestedLiPage).popup().popup('open');
}

Rounded check box using Jquery mobile

I am trying to create rounded style checkbox using Jquery mobile. In the below link, under multiple selects, choose option select menu i saw this type of checkbox. Is it possible to create that type of checkbox in listview of JQM?
http://jquerymobile.com/test/docs/forms/selects/custom.html#&ui-state=dialog
Thanks...
<ul data-role="listview" id="options">
<li data-icon="checkbox-off"><a>test</a></li>
<li data-icon="checkbox-on"><a>test</a></li>
</ul>
This code snippet makes round edges for listview, you can have any element inside it:
<ol data-role="listview">
<li class="ui-corner-bottom ui-corner-top" data-theme="a" >List Item 1</li>
<li class="ui-corner-bottom ui-corner-top" data-theme="a">List Item 2</li>
<li class="ui-corner-bottom ui-corner-top" data-theme="a">List Item 3</li>
</ol>
See the Demo here
http://jsfiddle.net/qXr79/5/

Resources