jq.mobi问题汇总
先看看用到jqmobi开发的APP列表:http://www.appmobi.com/?q=content/built-appmobi
下面是标准介绍:
jq.mobi是jquery的精简版,不同于jquery.mobile,前者的效率是后者的三倍以上:)
几个缺点
在我的手机上jq.mobi的切换相当流畅,不过也有几个缺点:
1、无法输入中文,在表单中输入的中文无法显示。
解决方案:
#content{ z-index:180; display:block; position:absolute; top:48px; bottom:62px; left:0px;right:0px; overflow:hidden; } /* Accounts for positioning of the content area, which is everything below the header and above the navbar. */
修改jq.ui.css,去掉上面的
overflow:hidden;
2、URL路径过于简略,无法在URL中传递参数,因此无法实现比如
http://a.com/index.html#blog/[blogid]
这样的路径
解决方法:
现阶段只能强行修改 jq.ui.js中的 loadContent函数
期待下一版中有所改进,或者可以采用第三方的URL路由库。
——————————————————————————————————————
20120607update
新版的jqmobi增加了URL历史记录中对于“/”参数的支持,不过支持也是相当的有限
1 loadContent: function(target, newTab, back, transition, anchor) { 2 ... 3 var slashIndex = what.indexOf('/'); 4 var hashLink = ""; 5 if (slashIndex != -1) { 6 // Ignore everything after the slash for loading 7 hashLink = what.substr(slashIndex); 8 what = what.substr(0, slashIndex); 9 } 10 ... 11 window.history.pushState(what.id, what.id, startPath + '#' + what.id + hashLink); 12 $(window).trigger("hashchange", {newUrl: startPath + '#' + what.id + hashLink,oldURL: startPath + "#" + this.activeDiv.id}); 13 ... 14 }
如果想不hack jq.ui.js这个原生的core库的话,基本没有方法
这里有一个讨论,是关于在backbone中使用jqmobi的,其中作者有一段话
Re: using backbone.js with jqmobi - best practice by appmobiIan on Sun Apr 15, 2012 7:56 pm Incorrect. jqMobi does nothing with hashes. It's a query selector library. jqUi doesn't look for a hash change either. If you had read the code (you said you made changes), you'd see that instead we look at anchor clicks and check for a "#id" in the href. That is NOT looking for a hash change event like backbone.js. Sorry, I get short with people who say "You're code doesn't do this. I had to patch it"...because generally they didn't look through the code. If you add "data-ignore-pressed" on anchors, we don't process them at all, so they click through. Not ideal, but you can add them on the fly when processing. 1.02 (which should be released tuesday or wednseday) has a $.ui.customClickHandler function, so you'd do something like below. By returning "true", we skip our click handler CODE: SELECT ALL $.ui.customClickHandler=function(){ return true;}
在最新版中确实有这一部分的代码:
function checkAnchorClick(theTarget) { var parent = false; if (theTarget.tagName.toLowerCase() != "a" && theTarget.parentNode) parent = true, theTarget = theTarget.parentNode; //let's try the parent so <a href="#foo"><img src="whatever.jpg"></a> will work if (theTarget.tagName.toLowerCase() == "a") { var custom=(typeof jq.ui.customClickHandler=="function")?jq.ui.customClickHandler:false; if(custom!==false&&jq.ui.customClickHandler(theTarget.href)){ return true; } if (theTarget.href.toLowerCase().indexOf("javascript:") !== -1 || theTarget.getAttribute("data-ignore")) { ... }
(待续)