RequireJS内置文件不起作用。在建成之前工作

时间:2014-04-04 02:53:12

标签: javascript jquery requirejs r.js requirejs-optimizer

我在构建requireJS文件时需要一些帮助。我将提出一些代码片段 和我建的文件

JS档案

require.config({
    paths: {
        'bootstrap': ['//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min'],
        'jquery' : '/cp-front/js/jquery-1.9.1/jquery.min',
        'core' : '/cp-front/js/custom/core'
    }
});
require([
    'bootstrap'
    , 'core/ajaxLoader'
],
function (
    bootstrap
    , ajaxLoader
    ) {

    $(document).ready(function () {
        $("#modalLoader").ajaxLoader({
            title: 'Sending Request',
            text: 'Delivering your message...'
        });
    });
});

JS模块

define("core/ajaxLoader", ['jquery', 'bootstrap'],
    function ($, bootstrap) {
        var _settings = null;
        var methods = {
            init: function (options) {
                var element = this;
                var settings = $.extend({
                    prefix: '',
                    title: 'Loading',
                    text: '',
                    timeout: 120000,
                    finishLoading: function(prefix){}
                }, options);
                _settings = settings;
                var $element = $(element);
                $element.html(
                    [
                        '<div class="modal fade js-mod-ajaxloader" id="modalAjaxLoader' + _settings.prefix + '" tabindex="-1" role="dialog" aria-labelledby="modalAjaxLoader' + _settings.prefix + 'Label"  data-backdrop="static" data-keyboard="false" aria-hidden="true">',
                        '<div class="modal-dialog">',
                        '<div class="modal-content">',
                        '<div class="modal-body">',
                        '<div class="full-block">',
                        '<h2>' + _settings.title + '</h2>',
                        '</div>',
                        '<div class="full-block">',
                        '<span class="loader-img"><img src="/img/ajax-loader.gif" /> </span><span id="modalAjaxLoaderText' + settings.prefix + '"></span>',
                        '</div>',
                        '</div>',
                        '</div>',
                        '</div>',
                        '</div>'
                    ].join(''));
                if(settings.text){
                    $("#modalAjaxLoaderText" + settings.prefix).text(settings.text);
                };

                //popup the loader
                $('#modalAjaxLoader' + settings.prefix).modal();
                setTimeout(function(){
                    methods._closeAjaxLoader(settings.prefix);
                }, settings.timeout);
            },
            _closeAjaxLoader: function(prefix){
                $('#modalAjaxLoader' + prefix).modal('hide');
            },
            finishLoading: function(prefix){
                methods._closeAjaxLoader(prefix)
            }
        };
        $.fn.ajaxLoader = function (methodOrOptions) {
            if (methods[methodOrOptions]) {
                return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1));
            } else if (typeof methodOrOptions === 'object' || !methodOrOptions) {
                return methods.init.apply(this, arguments);
            } else {
                $.error('Method ' + method + ' does not exist');
            }

            $(element).load(function () {
            });
        };
    });

构建文件

({
    baseUrl: ".",
    name: "eyexsolution",
    out: "eyexsolution-built.js",
    paths: {
        'bootstrap' : "empty:",
        'jquery' : '../../cp-front/js/jquery-1.9.1/jquery.min',
        'core' : '../../cp-front/js/custom/core'
    }
})

内置文件(最终输出)

jQuery(function(e){e(document).ready(function(){var t=[],n=[],r=[],i=0,s="",o="",u="",a=null,f=0,l=0,c=0,h=0;e(window).scroll(function(t){var n=e(this).scrollTop();n>i?s="down":s="up",i=n}),e.fn.stickUp=function(t){e(this).addClass("stuckMenu");var n=0;if(t!=null){for(var i in t.parts)t.parts.hasOwnProperty(i)&&(r[n]=t.parts[n],n++);n==0&&console.log("error:needs arguments"),o=t.itemClass,u=t.itemHover,t.topMargin!=null?t.topMargin=="auto"?h=parseInt(e(".stuckMenu").css("margin-top")):isNaN(t.topMargin)&&t.topMargin.search("px")>0?h=parseInt(t.topMargin.replace("px","")):isNaN(parseInt(t.topMargin))?(console.log("incorrect argument, ignored."),h=0):h=parseInt(t.topMargin):h=0,a=e("."+o).size()}f=parseInt(e(this).height()),l=parseInt(e(this).css("margin-bottom")),c=parseInt(e(this).next().closest("div").css("margin-top")),vartop=parseInt(e(this).offset().top)},e(document).on("scroll",function(){varscroll=parseInt(e(document).scrollTop());if(a!=null)for(var t=0;t<a;t++){n[t]=e("#"+r[t]+"").offset().top;function i(t){contentView=e("#"+r[t]+"").height()*.4,testView=n[t]-contentView,varscroll>testView?(e("."+o).removeClass(u),e("."+o+":eq("+t+")").addClass(u)):varscroll<50&&(e("."+o).removeClass(u),e("."+o+":eq(0)").addClass(u))}s=="down"&&varscroll>n[t]-50&&varscroll<n[t]+50&&(e("."+o).removeClass(u),e("."+o+":eq("+t+")").addClass(u)),s=="up"&&i(t)}vartop<varscroll+h&&(e(".stuckMenu").addClass("isStuck"),e(".stuckMenu").next().closest("div").css({"margin-top":f+l+c+"px"},10),e(".stuckMenu").css("position","fixed"),e(".isStuck").css({top:"0px"},10,function(){})),varscroll+h<vartop&&(e(".stuckMenu").removeClass("isStuck"),e(".stuckMenu").next().closest("div").css({"margin-top":c+"px"},10),e(".stuckMenu").css("position","relative"))})})}),define("stickup",function(){}),require.config({paths:{bootstrap:["//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min"],stickup:"/cp-front/js/jquery.stickup.min"}}),require(["bootstrap","stickup"],function(e,t){$(document).ready(function(){$(".navbar-sub").stickUp({parts:{0:"about-us",1:"our-innovation",2:"community",3:"locate-us"},itemClass:"about-items",itemHover:"active"}),$(".nav li a").each(function(){$(this).click(function(){var e=$(this).attr("data-scroll");$("html, body").animate({scrollTop:$("#"+e).offset().top-48},500)})})})}),define("index",function(){});

我收到如下错误消息

未捕获TypeError:对象[object Object]没有方法&#39; ajaxLoader&#39;

我正在使用r.js,require-jquery。

我认为我没有正确使用requireJS构建,有什么样的灵魂可以指导我吗?请!

谢谢

0 个答案:

没有答案