So the issue at hand is to have a constantly moving slider in jQuery Mobile alpha 4.1 as if listening to a song or watching a show. Basically a progress bar in which the user can also enter input. Much like one on a regular mobile device's music player. Does anyone have an idea on how to do this?
Example:
(Not sure if this will work with Alpha 4.1 but might give you and idea on how to make yours work)
http://jsfiddle.net/zPVVq/
JS
$('#movingSlider').live('click', function() {
var started = false;
var speed = 1500;
var duration = new Array();
for(i = $(this).val(); i <= $(this).attr('max'); i++){
duration.push(i);
}
$.each(duration,function() {
var moveSlider = function() {
newValue = parseInt($('#movingSlider').val(), 10) + 1;
$('#movingSlider').val(newValue).delay(speed).slider('refresh');
}
setTimeout(moveSlider,0);
});
});
$('#resetSlider').click(function() {
$('#movingSlider').val(0); });
HTML
<div data-role="page" id="home">
<div data-role="content">
<label for="slider-0">Click slider value to start --></label>
<input type="range" name="slider" id="movingSlider" value="0" min="0" max="1000" />
Reset Slider
</div>
</div>
Related
Is there a possibility to have a number input with minus-button on the left and plus-button on the right? Or maybe also -- ++ to change value in bigger steps.
I know that I'm not the first one asking this but:
This solution is not displaying correctly in the first turn and jQuery-Mobile-Stepper-Widget from Github (can't post another link because I'm new) does not work with current version of jQuery Mobile.
The result should look like the screenshot in this question: Has anyone implemented jQuery Mobile Add (+/-) Button Number Incrementers? respectively horizontal grouped buttons in jQuery Mobile
Any ideas or new snippets, working with current version of jQuery mobile?
Here is a hint, the rest is purely CSS job and extra JS codes to control the value, e.g. maximum, minimum...etc.
HTML
<div data-role="controlgroup" data-type="horizontal" data-mini="true">
<button id="plus" data-inline="true">+</button>
<input type="text" id="number" value="0" disabled="disabled" />
<button id="minus" data-inline="true">-</button>
</div>
Code
$('#plus').unbind('click').bind('click', function () {
var value = $('#number').val();
value++;
$('#number').val(value);
});
$('#minus').unbind('click').bind('click', function () {
var value = $('#number').val();
value--;
$('#number').val(value);
});
JSFiddle
In jQM the input type number does the most of the magic you want
<input type="number" name="number" value="0"/>
If you require more fancy styling you have to follow Omar's code
<i onclick="qty('plus');" class="fa fa-plus c_pointer"></i>
<input type="text" id="prdqty" name="qty" value="1" placeholder="1">
<i onclick="qty('minus');" class="fa fa-minus c_pointer"></i>
function qty(val){
pqty = $('#prdqty').val();
if (val == "plus") {
var newVal = parseFloat(pqty) + 1;
} else {
if (pqty > 1) {
var newVal = parseFloat(pqty) - 1;
} else {
newVal = 1;
}
}
$('#prdqty').val(newVal);
}
Im using the jQuery Mobile Filter List:
http://jquerymobile.com/test/docs/lists/lists-search-with-dividers.html
Is it possible to move the position of the input field so I can put it into a div already on my page?
Using jQuery's appendTo seems to work fine but its kind of a hacky solution. Thanks
this is what I found while searching for solution to a similar problem.
HTML code example:
<div data-role="page" id="page-id">
<div data-role="content">
<div data-role="fieldcontain">
<input type="search" name="password" id="search" value="" />
</div>
<div class="filter-div" data-filter="one">1</div>
<div class="filter-div" data-filter="two">2</div>
<div class="filter-div" data-filter="three">3</div>
<div class="filter-div" data-filter="four">4</div>
<div class="filter-div" data-filter="five">5</div>
</div>
</div>
JS code example:
$(document).delegate('#page-id', 'pageinit', function () {
var $filterDivs = $('.filter-div');
$('#search').bind('keyup change', function () {
if (this.value == '') {
$filterDivs.slideDown(500);
} else {
var regxp = new RegExp(this.value),
$show = $filterDivs.filter(function () {
return ($(this).attr('data-filter').search(regxp) > -1);
});
$filterDivs.not($show).slideUp(500);
$show.slideDown(500);
}
});
});
This way you can place your input text box anywhere on your page and it should properly filter a list of items you want.
JSFiddle DEMO: http://jsfiddle.net/cZW5r/30/
I have just encountered a strange problem when using jQuery Mobile.
I have a link inside a form element label - a checkbox label to be exact but the link does not work.
I have tried reading the docs but can't seem to find anything on it.
Here is my markup:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<input type="checkbox" class="cbox" name="OptIn" id="OptIn"/>
<label for="OptIn">Receive E-mails From Us</label>
<input type="checkbox" value="1" class="cbox" name="tandc" id="tandc"/>
<label for="tandc">I agree to the <a href="/tandcs.html" target="_BLANK" >Terms & Conditions</a></label>
</fieldset>
</div>
When the link is clicked it just toggles the checkbox state.
UPDATE
Just realised I can open the link by right clicking but obviously on a mobile device that's not very useful....
this is the correct solution for mobile and non mobile browsers
$('.ui-checkbox a').bind("tap click", function( event, data ){
event.stopPropagation();
$.mobile.changePage($(this).attr('href'));
});
Had the same problem and solved it using:
$('.ui-btn-text a').click(function(event) {
var $this = $(this);
window.open($this.attr('href'), $this.attr('target'));
});
So if any link within a button-text is clicked it will be opened in a new window. If you want it in the same window just use $.mobile.changePage as Phil showed.
I tried the above mentioned solutions on jQuery Mobile 1.1.0 with jQuery 1.7.2 without success.
After a bit of tinkering and reading into the new jQuery event functions I came up with my own solution to make all anchors in labels clickable without loosing jQuery Mobile default behaviour on the rest of the label:
jQuery('label').each(function(){
var e = jQuery(this).data('events');
jQuery('.agree label').undelegate();
jQuery('.agree label *:not(a)').delegate(e);
});
use on() and off() instead
$('label').each(function(){
var e = $(this).data('events');
$('label').off();
$('label').not('a').on(e);
});
There a some improvements that can be made but here is a rough draft:
http://jsfiddle.net/KADqA/
JS
$('.ui-btn-text').click(function(event) {
var checked = $("#tandc[type='checkbox']").is(":checked");
var $this = $(this);
if($this.children('a').length) {
$.mobile.changePage('#tc', {
transition : 'pop',
role : 'dialog'
});
}
stateOfCheckbox(checked);
});
function stateOfCheckbox(checked) {
$('#home').live( 'pagebeforeshow',function(event){
$("#tandc[type='checkbox']").attr("checked",checked).checkboxradio("refresh");
});
}
HTML
<div data-role="page" id="home">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<input type="checkbox" class="cbox" name="OptIn" id="OptIn"/>
<label for="OptIn">Receive E-mails From Us</label>
<input type="checkbox" value="1" class="cbox" name="tandc" id="tandc"/>
<label for="tandc">I agree to the <a href="#tc" data-rel="dialog" >Terms & Conditions</a></label>
</fieldset>
</div>
</div>
<div data-role="page" id="tc">
<div data-role="header">
<h1>T and C</h1>
</div>
Read me
</div>
You could also just override the event:
$('.ui-checkbox a').click(function(e) {
e.stopPropagation();
})
On Android the solutions above did not work on Android.
It only works when using on pagecreate and without event delegation.
$(document).on('pagecreate', function(event, ui) {
$(".ui-checkbox a").on("click tap", function() {
$(':mobile-pagecontainer').pagecontainer('change', this.href);
return false;
});
} );
This is posible solution if you want to open the link in a popup.
$('.ui-checkbox a').bind('click tap', function (event) {
event.stopPropagation();
$($(this).attr('href')).popup('open');
});
Add Id or class into parent label have a tag
and using script of #alex dms
$('#field-contain label a').bind("tap click", function( event, data ){
event.stopPropagation();
$.mobile.changePage($(this).attr('href'));
});
Try it, work perfecly on my mobile and desktop
https://jsfiddle.net/vulieumang/p91zhmnp/
I've been looking at the:
data-filter="true"
option for filtering a list based on what is entered into a search box using Jquery mobile.
I'd like to do the same except hook in the ability to use an ajax get() to populate the list. Does anyone know how to go about doing this or an example anywhere of it being achieved. I've not seen anything on the JQ mobile site.
Thanks.
I couldn't find anything built in that does what you ask, but I was able to achieve this using a simple ajax request and manually filling the list. I started with a text box for the search field, and an empty ul
<div data-role="fieldcontain">
<label for="search">Search:</label>
<input type="search" name="search" id="search" value=""/>
</div>
<ul id="results" data-role="listview">
</ul>
This script block will send an ajax request after each key press, it might be better to add a delay though. It will abort the previous request if still loading and the person types another key. Not perfect, but its a start.
<script>
var last, last_xhr;
var x = $('#search').live('keyup change', function () {
if (last == $(this).val()) return;
last = $(this).val();
$.mobile.showPageLoadingMsg();
if (last_xhr) {
last_xhr.abort();
}
last_xhr = $.get('/Search', { q: last }, function (data) {
last_xhr = undefined;
var list = $('#wines').empty();
$.each(data, function (i, val) {
var el = $('<li data-theme="c" />');
el.append($('' + val.Name + ''));
list.append(el);
});
list.listview('refresh');
$.mobile.hidePageLoadingMsg();
});
});
</script>
The most important bit is calling refresh otherwise it doesn't apply the theme.
list.listview('refresh');
i"ve been hunting the docs and can't seem to find a way to make a scrollable horizontal navbar in jQuery mobile has anybody accomplished this yet ?
here's what i have for navbar so far
<div data-role="header" data-scroll="x">
<ul>
<li class="logo"><img src="img/iphoneheader.gif" alt="Penn State Live" /></li>
<li id="link">Colleges</li>
<li>Campuses</li>
<li>Faculty and Staff</li>
<li>Of Interest</li>
<li>Photos</li>
<li>Video</li>
<li>Newswire Subscription</li>
<li>PSUTXT</li>
</ul>
</div>
I guess this is what you want.
HTML.
<div class="categories">
<ul>
<li><span>ABC</span></li>
<li><span>DEF</span></li>
<li><span>GHI</span></li>
<li><span>JKL</span></li>
</ul>
</div>
JQuery
$(function(){
var step = 1;
var current = 0;
var maximum = $(".categories ul li").size();
var visible = 2;
var speed = 500;
var liSize = 120;
var height = 60;
var ulSize = liSize * maximum;
var divSize = liSize * visible;
$('.categories').css("width", "auto").css("height", height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
$(".categories ul li").css("list-style","none").css("display","inline");
$(".categories ul").css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute").css("white-space","nowrap").css("margin","0px").css("padding","5px");
$(".categories").swipeleft(function(event){
if(current + step < 0 || current + step > maximum - visible) {return; }
else {
current = current + step;
$('.categories ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
$(".categories").swiperight(function(){
if(current - step < 0 || current - step > maximum - visible) {return; }
else {
current = current - step;
$('.categories ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});
});
Also, try out: http://kryops.de/jqm/tabs/demo
This looks really promising and performance is great on mobile.
I know it's not what you're looking for but:
Live Example: http://jsfiddle.net/9zuxH/10/
<div data-role="page" data-theme="b" id="jqm-home">
<ul >
<li data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<div class="logo"><img src="img/iphoneheader.gif" alt="Penn State Live" /></div>
<div id="link">Colleges</div>
Campuses
Faculty and Staff
Of Interest
Photos
Video
Newswire Subscription
PSUTXT
</fieldset>
</li>
</ul>
</div>
Documentation: jquerymobile.com/demos/1.0a4.1/docs/lists/lists-forms-inset.html
UPDATED the example: http://jsfiddle.net/9zuxH/21/
A little better
This is after ypur lst comment, so I'll be addressing the need to scroll the navbar with a finger.
You pointed to an implementation that has problems. There are others.
I have used this once:
http://plugins.jquery.com/project/jQclickNScroll
for a desktop touchscreen. (not sure how it behaves on mobile)
It worked with a hrefs and it has an option allowHiliting:true that turns off preventing other events passing through
And there's this:
http://digitalillusion.altervista.org/wordpress/pages/dragscroller/viewport-test.html
Stumbled across this while researching the same issue. Haven't tried it yet but it looks pretty handy
http://darsa.in/sly/