简体   繁体   English

在WebOS上使用带PhoneGap的jQTouch

[英]jQTouch with PhoneGap on webOS

I'm writing an application in PhoneGap that I want to run on iOS, Android, and webOS. 我正在PhoneGap中编写一个要在iOS,Android和WebOS上运行的应用程序。 jQTouch plays nice with everything on iOS and Android, but not webOS. jQTouch可以与iOS和Android上的所有功能兼容,但不适用于webOS。

Since the webOS Mojo framework is based on Prototype (which uses the $ variable), it's necessary to use jQuery in noConflict mode. 由于webOS Mojo框架基于Prototype (使用$变量),因此有必要在noConflict模式下使用jQuery。 I can handle that much. 我能应付那么多。

However, the problem is that I also want to use the jQTouch plugin. 但是,问题在于我也想使用jQTouch插件。 The jqtouch.js file uses $ throughout, causing JavaScript errors when that file is loaded. jqtouch.js文件始终使用$ ,在加载该文件时会导致JavaScript错误。

Is there a way to run the jQTouch plugin (or any plugin for that matter) in my PhoneGap application without interfering with Prototype? 有没有办法在我的PhoneGap应用程序中运行jQTouch插件(或任何与此相关的插件)而不会干扰Prototype?

You should be able to wrap it in a closure and pass jQuery in. For example: 您应该能够将其包装在闭包中并传递jQuery。例如:

(function($){
   alert($);
}("Hello"))

(function($){
   $("foo"); // uses the jQuery rather than $
}(jQuery))

actualy you can get rid of prototyper so there is no conflict. 实际上,您可以摆脱原型开发人员,因此不会发生冲突。 read this exerpt from one of their programming guides: 请从他们的编程指南之一中阅读以下摘录:

Mojo is the standard JavaScript framework that most webOS apps are built with. Mojo是构建大多数WebOS应用程序的标准JavaScript框架。 However, if you aren't using any features within it then it's just costing you startup time. 但是,如果您不使用其中的任何功能,则只会花费启动时间。 You can prevent Mojo from loading by just commenting out the script tag at the top of your index.html page. 您可以通过仅在index.html页面顶部注释掉script标签来阻止Mojo加载。

--> Mojo does one thing that we need however. -> Mojo完成了我们需要做的一件事。 It tells the window manager when the app is fully loaded and ready to go. 它告诉窗口管理器应用程序何时完全加载并准备就绪。 We can do this manually with a simple onLoad event handler. 我们可以使用简单的onLoad事件处理程序手动执行此操作。 Add the following script to the head of the index.html page: 将以下脚本添加到index.html页面的开头:

function onLoad() { if (window.PalmSystem) { window.PalmSystem.stageReady(); 函数onLoad(){如果(window.PalmSystem){window.PalmSystem.stageReady(); } } }}

Then add a call in the body's onload event. 然后在主体的onload事件中添加一个调用。

That's it! 而已! Now the app will load without Mojo and start up much more quickly. 现在,该应用将在没有Mojo的情况下加载,并且启动速度更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM