jQuery mobile dropdownlist doesn't hides with http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js - jquery-mobile

Got this ddl and it works fine with this version of jQm "http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js":
But if I change it to 1.2.0 the items never hides. Anyone seen this problem?
<asp:DropDownList ID="LanguageDropDownList" OnSelectedIndexChanged="LanguageDropDownList_OnSelectedIndexChanged"
data-native-menu="false" AutoPostBack="true" runat="server">
</asp:DropDownList>

jQuery Mobile and asp.net web forms fundamentally don't work together. The postback model and jQuery Mobile's ajax form loading and navigation are incompatible. Move to MVC or turn off ajax.
Make sure to invoke this code before jQuery Mobile initializes. (Include it before the tag that references jQuery Mobile.)
<script src="jquery.js"></script>
<script>
$(document).bind("mobileinit", function() {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="jquery-mobile.js"></script>
http://jquerymobile.com/demos/1.2.0/docs/api/globalconfig.html

Related

Intel XDK jquery mobile go back to previous sub page

I am using Intel XDK with jquery mobile and I am trying to override the hardware back button because it is not working. I am not sure how much of my code I can post. I do have a complicated app though. I have three html files. With an index.html with links (hrefs) to page one and page two. In index.html I have this code
script src="intelxdk.js"></script>
<script src="cordova.js"></script>
<script src="xhr.js"></script>
<script src="js/jquery.min.js"></script> <!-- jQuery v2.1.1 -->
<script src="jqm/jquery.mobile-min.js"></script> <!-- jQuery Mobile 1.4.2 -->
<script type="text/javascript">
/* Intel native bridge is available */
var onBackKeyDown = function() {
$.mobile.goBack();
}
var onDeviceReady = function() {
intel.xdk.device.hideSplashScreen();
intel.xdk.display.useViewport;
intel.xdk.device.addVirtualPage();
document.addEventListener("intel.xdk.device.hardware.back", onBackKeyDown, false);
};
document.addEventListener("intel.xdk.device.ready",onDeviceReady,false);
</script>
On page one and page two currently I have about ten subpages each (more to come) and I definitely want to back able to go back to the previous subpage. I have done kind of a lot of work with jquery mobile so far and I hope I don't have to switch to App Framework just to get the back button to work. Thanks for any help, let me know if you need any more html code or JS.

ajax links getting mis-handled

I have an asp.net mvc 4 with jquery-mobile app.
On one page (url: /StatementBatch ), I have a list of batches, which are simply links to the batch details page (url: /StetementBatch/Details/4 ).
<li>
<a href="/StatementBatch/Details/4">
<h3>January 2012</h3>
<div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div>
<div style="float: right; width: 30%;">Completed</div>
<p class="ui-li-aside"><strong>1277</strong></p>
</a>
</li>
The oddity is that once the link is clicked, and the details page renders, the browsers current url is now http://localhost:49457/StatementBatch#/StatementBatch/Details/4
What do I need to change in the app to get this behavior fixed?
My guess is that its some sort of ajax loading related problem, but my shared _Layout.cshtml file contains $.mobile.ajaxEnabled = false;, which I expected would kill all ajax loading, but I've obviously mis-interpreted that one.
Thanks!
I suspect this may be the answer
jQuery Mobile ajaxEnabled doesn't work?
Will test and see if I can make it work
moving the mobileinit binding to after jquery, but before jquery-mobile does the trick. This appears to be a bug in MVC4's (new) mobile web application template, which simply bundles all the scripts together
This fails....
<link href="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>
<script>
$(document).bind("mobileinit", function() {
// As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
// when navigating from a mobile to a non-mobile page, or when clicking "back"
// after a form post), hence disabling it.
$.mobile.ajaxEnabled = false;
});
</script>
But this works....
<link href="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script>
$(document).bind("mobileinit", function() {
// As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
// when navigating from a mobile to a non-mobile page, or when clicking "back"
// after a form post), hence disabling it.
$.mobile.ajaxEnabled = false;
});
</script>
<script src="../../Scripts/jquery.mobile-1.1.0.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
<script src="../../Scripts/modernizr-2.5.3.js" type="text/javascript"></script>
Thanks...
That is the default behaviour if you use jQuery mobile. jQuery mobile will enable all your links to be ajaxified. That means it will load content of the linked page via ajax and update the url. If you want to disable a link to be ajaxified, you can add rel attribute with external as value
This will open without ajax
This will do a normal page opening so your urls will updated based on the new page.
Alternatively you can use data-ajax="false" as well
This link also will open without ajax
this link has more info about it http://jquerymobile.com/test/docs/pages/page-links.html
That is strange. If $.mobile.ajaxEnabled = false; is set then it should not generate ajax links. Please check whether your view is using some other master page which has got this setting enabled. Look for "_ViewStart.cshtml" under the corresponding view directory to see which master it is linked to.
In order to disable Ajax behavior for a particular hyperlink use data-ajax="false" attribute. Like below
<a href="/StatementBatch/Details/4" data-ajax="false">
<h3>January 2012</h3>
<div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div>
<div style="float: right; width: 30%;">Completed</div>
<p class="ui-li-aside"><strong>1277</strong></p>
</a>

jQuery Mobile ajaxEnabled doesn't work?

Running latest release of jQuery Mobile (1.0.1), and do not want to use AJAX for page navigation.
I added the following code which according to jQuery Mobile website should stop the use of AJAX:
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
But it still uses AJAX and adds the hash (# ) to URLs.
How can I disable the use of AJAX?
Just a guess, but are you binding to mobileinit before jQuery Mobile is loaded?
As stated in the documentation, you'll want to load the JavaScript files in this order:
<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

defaultPageTransition on ASP.net MVC4 with jQuery Mobile

I'm using ASP.net MVC4 with jquery mobile.
i'm trying to change the transition page effect setting $.mobile.defaultPageTransition to 'none' in 'mobileinit' bind, but nothing happens and the default transition (slide) persists!
I even tried alter jquery.mobile-1.0.js directly and nothing changes too.
anyone have any tips?
Are you binding to mobileinit in the correct place?
<script src="jquery.js"></script>
<script>
$(document).bind("mobileinit", function(){
$.mobile.defaultPageTransition = 'none';
});
</script>
<script src="jquery-mobile.js"></script>
Notice jQuery Core gets loaded first, then we bind to the mobileinit event, then the jQuery Mobile JS file is loaded.
Docs: http://jquerymobile.com/demos/1.1.0-rc.1/docs/api/globalconfig.html
Here is a demo: http://jsfiddle.net/JczRj/

How to initialize pages in jquery mobile? pageinit not firing

What's the right way to initialize objects on a jquery mobile page? The events docs say to use "pageInit()" with no examples of that function, but give examples of binding to the "pageinit" method (note case difference). However, I don't see the event firing at all in this simple test page:
<html>
<body>
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
<div data-role="page" id="myPage">
test
</div>
<script>
$("#myPage").live('pageinit',function() {
alert("This never happens");
});
</script>
</body>
</html>
What am I missing? I should add that if you change pageinit to another event like pagecreate this code works.
---- UPDATE ----
This bug is marked as "closed" in the JQM issue tracker. Apparently opinions differ about whether this is working properly or not.
It started working when I embedded script within page div:
<body>
<div id="indexPage" data-role="page">
<script type="text/javascript">
$("#indexPage").live('pageinit', function() {
// do something here...
});
</script>
</div>
</body>
Used jQuery Mobile 1.0RC1
.live() is deprecated, suggestion is to use .on() in jQuery 1.7+ :
<script type="text/javascript">
$(document).on('pageinit', '#indexPage', function(){
// code
});
</script>
Check the online doc for more information about .on(): http://api.jquery.com/on/
Turns out this is a bug in 1.0b3 that is fixed in the current head. So if you want a fix now, you gotta grab the latest from git. Or wait for the next release.
jQuery(document).live('pageinit',function(event){
centerHeaderDiv();
updateOrientation();
settingsMenu.init();
menu();
hideMenuPopupOnBodyClick();
})
This is working now. Now all page transitions and all JQM AJAX functionality would work along with your defined javascript functions! Enjoy!
pageinit will not fire in case it is on secondary pages ( NOT MAIN page ) if it is written in common <script> tag...
I have such a problem - on secondary pages that are not loaded with 'rel="external"', the code in the common <script> tag is never executed...
really this code is always executed...
<body>
<div id="indexPage" data-role="page">
<script type="text/javascript">
$("#indexPage").live('pageinit', function() {
// do something here...
});
</script>
</div>
</body>
althrough if you made "tabbed interface", using of "pageshow" is better
I had to put the script in the HTML page section which to me is a bug. It is loaded normally in a browser (not via AJAX) and all on a single page including javascript. We're not supposed to have to use document ready.
The easiest way I found to deal with this was to use JQM + Steal. It works like a charm as long as you put:
<script type='text/javascript' src='../steal/steal.js?mypage'></script>
Inside of the data-role='page' div.
Then use AJAX to connect anything that can use the same mypage.js and use an external link (by using the rel="external" tag) to anything that requires a different steal page.
#Wojciech BaƄcer
From the jQuery docs:
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().
Try this:
$('div.page').live('pageinit', function(e) {
console.log("Event Fired");
});
$(document).on("pageinit", "#myPage", function(event) {
alert("This page was just enhanced by jQuery Mobile!");
});
The events don't fire on the initial page, only on pages you load via Ajax. In the above case you can just:
<script>
$(document).ready(function() {
alert("This happens");
});
</script>

Resources