requirejs

Auto defining a custom JS Library in BackboneJS

早过忘川 提交于 2019-12-11 05:58:07
问题 I've created an JS library to handle all my API calls. Is there a way to automatically include this in all my views as api without needing to define it at the top of each view? I've tried adding it to the main js file, but that doesn't seem to carry into the views. 回答1: Each Backbone model should handle its API endpoint communications and each module should only require the models it depends on. Otherwise, it goes against the point of making your code more modular. That being said, if you

Require.js with jQueryMobile-Router

我的未来我决定 提交于 2019-12-11 05:45:57
问题 I load require.js with jQuery included like this in my html: <script data-main="requires" src="lib/require-jquery.js"></script> The content of my requires.js: require.config( { paths: { "jquery.mobile": "lib/jquery.mobile", "jquery.mobile.router": "lib/jquery.mobile.router" }, shim: { "jquery.mobile" : { "exports": "$.mobile" }, "jquery.mobile.router": { "deps": [ "jquery.mobile" ], "exports": "$.mobile.Router" } } } ); require(["jquery.mobile.router" ], function() { require(["router"]); } );

How to load ace editor with requirejs from CDN?

旧巷老猫 提交于 2019-12-11 04:22:46
问题 I am trying to load the ace editor from a CDN with requirejs. Here is a plunkr which illustrates my problem. Ace is not defined in the following case: requirejs.config({ paths: { ace: ['//cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace'] } }) $('h1').text("loading ace..."); requirejs([ 'ace'], function(ace) { $('h1').text("ace loaded.") console.log(ace) ace.edit('#editor') return }) 回答1: you need to define ace as a path to the folder that contains ace.js and require "ace/ace" requirejs.config({

how to set backbone fetch callback method

佐手、 提交于 2019-12-11 04:07:31
问题 How do you set the jsonpCallback function name for the fetch method of backbonejs? To add to the problem is I also using requireJS so i am trying not to have a global function and follow the AMD pattern. The reason I can't use the auto generated method name from jquery is the developer of the api I am using want's to have a static name of for the callback method for caching reasons. Sample Code define([ 'jquery', 'underscore', 'backbone', 'marionette', 'paginator', 'models/item'], function($,

RequireJS modules loading out of order when loading one module into another

我怕爱的太早我们不能终老 提交于 2019-12-11 04:07:14
问题 I have written a web application which uses requirejs for AMD: require(dependencies, function(dependencies) { (function($) { $.fn.plugin = function(options) { return this; }; })(window.jQuery); }); I then used almond and r.js to compile it into a single javascript file, using the build config: ({ baseUrl: ".", paths: { 'jquery' : 'vendor/jquery-1.9.1.min' 'almond' : "../node_modules/almond/almond" }, name : "almond", include : "main", out : "plugin.js", wrap : true }) Next, I want to use this

Load prototype enhancements with require.js

让人想犯罪 __ 提交于 2019-12-11 03:17:39
问题 I am using require.js to load my modules which generally works fine. Nevertheless, I do have two additonal questions: 1) If you have a module that is like a helper class and defines additional methods for existing prototypes (such as String.isNullOrEmpty ), how would you include them? You want to avoid using the reference to the module. 2) What needs to be changed to use jQuery, too. I understand that jQuery needs to be required but do I also need to pass on $ ? Thanks! 回答1: 1) If you have a

Always require certain dependencies in RequireJS

痞子三分冷 提交于 2019-12-11 03:05:30
问题 I'm working on a Backbone project and I'm loading jQuery , Underscore and Backbone with RequireJS . I find myself typing this pattern over and over again in all the modules: define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) { ... Is there a way or workaround to make these 3 libraries available to all modules without explicitly requiring them so I can concentrate on requiring extra things? I though about loading this dependencies stack within script tags and use RequireJS

Google Closure Compiler Includes

穿精又带淫゛_ 提交于 2019-12-11 03:04:55
问题 I've been using google closure compiler for a little bit with my projects, it's awesome! I've been trying to find out whether or not you can do "includes" in a javascript file that includes other javascript files. I'm trying to have 1 javascript file that "includes" all the files I need then compiles, much like you can do with a LESS import statement, ("@import "../less/bootstrap") for example. Is this possible? - Or do you have to provide the list of source files at time of compilation in

'angular' is undefined on IE10

人走茶凉 提交于 2019-12-11 03:03:41
问题 I have developed an AngularJs, RequireJs application with PHP as back-end and is hosted on WAMP server. Server machine name is "ICC-Server" and alias is "iccportal" and domain is "ip.bombay". When I access the portal with http://iccportal.ip.bombay on IE10 and Chrome it works well. But If I try to access the same portal without domain name ( http://iccportal) , I get following error. SCRIPT5009: 'angular' is undefined app.js, line 4 character 1 SCRIPT5009: 'angular' is undefined main.js, line

How to mock inline requirejs dependencies with squire for unit testing?

夙愿已清 提交于 2019-12-11 03:03:40
问题 I'm using requirejs with inline requires, for instance: define(['someDep'], function(someDep) { return { someFn: function() { require(['anotherDep'], function(anotherDep) { anotherDep.anotherFn(); }); } } }); In my particular case, I cannot include anotherDep in the define. When testing with mocha, I have a test case like this: define(['squire'], function(Squire) { var squire = new Squire(); describe('testcase', function() { it('should mock anotherDep', function(done) { var spy = sinon.spy();