热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

负载jquery.mobile。与requirejsiscrollview优化器-Loadjquery.mobile.iscrollviewwithrequirejsoptimizer

Ihaveaworkingprojectwithjquery,jquerymobileandrequireJS(2.0).NowIhaveaproblemwithi

I have a working project with jquery, jquery mobile and requireJS (2.0). Now I have a problem with integrating jquery.mobile.iscrollview into the requireJS world.

我有一个使用jquery、jquery mobile和requireJS(2.0)的工作项目。现在我有一个整合jquery.mobile的问题。让我们进入到requireJS的世界。

My requirejs configuration looks like this:

我的requirejs配置是这样的:

(function (require) {
    "use strict";
    require.config({
        paths:{
            'angular':'../external-libs/angular-1.0.3',
            'jquery':'../external-libs/jquery-1.7.2',
            'jquery.mobile':'../external-libs/jquery.mobile-1.2.0',
            'adapter': '../external-libs/jquery-mobile-angular-adapter-1.2.0',
            'moment': '../external-libs/moment-1.6.2.min',
            'iscroll': '../external-libs/iscroll',
            'iscrollview': '../external-libs/jquery.mobile.iscrollview'
        },
        shim:{
            'angular':{ deps:['jquery'], exports:'angular' },
            'iscroll':{ deps:['jquery'], exports:'iscroll' },
            'iscrollview':{ deps:['jquery.mobile', 'iscroll'], exports:'iscrollview' }
        }
    });

    require([
        "jquery",
        "jquery.mobile",
        "adapter",
        "moment",
        "iscroll",
        "iscrollview",
        "myApp"
    ], function () {
    //
    });
  }(require));

That is working very well, as long as the requireJS optimizer hasn't run for production mode where only one big JS file should be served to clients. Even when setting the optimizer to don't optimize anything (optimize: none) so its only concatinating all js files together, its not working.

这很好,只要requireJS优化器没有运行在生产模式下,只有一个大JS文件应该提供给客户端。即使在设置优化器时,也不能优化任何东西(优化:none),所以它只会将所有js文件整合在一起,而不是工作。

The error message when loading the site is

加载站点时出错信息。

Uncaught TypeError: Cannot read property 'ignoreContentEnabled' of undefined

未捕获的类型错误:无法读取未定义的属性“ignoreContentEnabled”。

It happens in the file "jquery.mobile.iscrollview.js" and its obvious from the code that the $.mobile object is not yet available at the time of parsing the file, as that is created only after the jquery ready event (I think).

它发生在文件“jquery.mobile.iscrollview”中。和它从代码中显而易见的$。在解析文件时,移动对象还没有可用,因为只有在jquery就绪事件(我认为)之后才创建。

Any idea how to fix this?

你知道怎么解决这个问题吗?

Thanks!

谢谢!

Marco

马可

2 个解决方案

#1


2  

Have solved it by myself now by converting jquery.mobile.iscrollview to a AMD module. Like so:

现在通过转换jquery.mobile解决了这个问题。对AMD模块的iscrollview。像这样:

 define(function () {


    function iScrollView($) {
        //here comes the iscrollview code, but without event handler to pagecreate
    }

    jQuery(document).bind("pagecreate", function (e) {
        "use strict";
        iScrollView(jQuery); //this is doing the init stuff that normally happens
                             //when script is loaded, lines after this are the 
                             //original event handler

        var elements = jQuery(e.target).find(":jqmData(iscroll)");
        elements.iscrollview();
    });

    return iScrollView;

});

#2


0  

Chances are the issue here is timing of loading vs running of jQuery core. (That's why I personally prefer CurlJS. Never had a timing problem with it)

这里的问题是加载和运行jQuery核心的时间。这就是为什么我更喜欢CurlJS。它从来没有时间问题

Still, if the nuttiness of the configuration system is letting you down, take control into your own hands and declare the order explicitly:

不过,如果配置系统的nuttiness让您失望,那么您可以控制自己的手,并明确地声明:

require.config({
    paths:{
        'angular':'../external-libs/angular-1.0.3',
        'jquery':'../external-libs/jquery-1.7.2',
        'jquery.mobile':'../external-libs/jquery.mobile-1.2.0',
        'adapter': '../external-libs/jquery-mobile-angular-adapter-1.2.0',
        'moment': '../external-libs/moment-1.6.2.min',
        'iscroll': '../external-libs/iscroll',
        'iscrollview': '../external-libs/jquery.mobile.iscrollview'
    }
});

require(["jquery"], function($){
    require(["angular", "jquery.mobile"], function(angular){
        require(["adapter","iscroll"], function(){
            require(["myApp","moment","iscrollview"], function(myApp){
                // do something with
                myApp, $, angular
            })
        })
    })
})

I don't know what 'moment' is, so put it last, as, based on your shim structure, it does not depend on anything.

我不知道“时刻”是什么,所以把它放在最后,因为根据你的shim结构,它不依赖于任何东西。


推荐阅读
author-avatar
真理往往是废话
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有