js-amd

require.js + backbone.js: How to structure modules that have an initialize function?

坚强是说给别人听的谎言 提交于 2019-12-21 05:32:05
问题 I have an application with three pages (which are single-page interfaces). The pages have similar but not identical functionality. So I want to have javascript-modules that provide the common functionality. Then each page may customize/overwrite parts of the common functionality. I'm using backbone.js, so what I do is: load the files containing the common Models, Views, Collections etc. load app-specific files that customize/overwrite parts of step 1 call an init() function that instanciates

How to load Google Maps API with RequireJS?

寵の児 提交于 2019-12-17 21:44:19
问题 I am struggling to load gmaps api with requireJS . This is what I've tried: requirejs.config({ urlArgs: "noCache=" + (new Date).getTime(), paths : { "jquery": "vendor/jquery-1.8.2.min", "bootstrap": "vendor/bootstrap.min", "underscore": "libs/underscore-min", "backbone": "libs/backbone-min", "template": "libs/template", "gmaps": "http://maps.google.com/maps/api/js?v=3&sensor=false" }, shim: { 'backbone': { deps: ['jquery', 'underscore'], exports: 'Backbone' }, 'underscore': { exports: '_' },

How to achieve lazy loading with RequireJS?

十年热恋 提交于 2019-12-17 15:13:16
问题 We're building a non-trival web application using Backbone, RequireJS and Handlebars, and well, I'm just curious. At the moment, each of our models sorta looks like this: define(['Backbone', 'js/thing/a', 'js/thing/b', 'js/lib/bob'], function(a, b, bob) { return Backbone.Router.extend({ // stuff here }); }); where thing/a, thing/b both have their own dependencies, for example on Handlebars templates, etc. What happens now is that in my main.js, all of the 'top-level' routers are loaded and

requirejs: Build settings for a common.js module along with a main.js module where the result will be only two .js files served

a 夏天 提交于 2019-12-13 04:34:37
问题 When following the general setup of example-multipage provided in the docs the common.js module seems to cause dependencies to make async XMLHttpRequest calls. my directory structure is: |-static |-core |-js |-myApp.js |-require.js |-common.js |-app.build.js |-app |-myApp.js |-vendor |-js |-jquery.js |-bootstrap.js |-fancybox.js contents of common.js: require.config({ baseUrl: "/static/core/js", paths: { 'jquery':'../../vendor/jquery/1.7.2/jquery', 'bootstrap':'../../vendor/bootstrap/2.2.2/js

Load requireJS module inline the HTML body?

二次信任 提交于 2019-12-10 12:32:58
问题 I am integrating RequireJS in a CMS so I placed this on the bottom of my page template: <html> <body> {Placeholder1} <script src="scripts/require.js" data-main="scripts/main"></script> {Placeholder2} </body> </html> Then on each page, I would like to create a function that leverages RequireJS. So I tried placing this on the bottom of the page: <html> <body> <h1>Home</h1> <div class="slider">Slider content</div> <script src="scripts/require.js" data-main="scripts/main"></script> <script type=

Backbone Marionette: Marionette.Application causing Require.js module load error, “'Error: Module name 'App' has not been loaded yet for context: _”

为君一笑 提交于 2019-12-10 00:12:23
问题 I'm trying to include the App instance to use it's event aggregator as shown here I get an error when I include the instance in a view. Kicking things off in the Requirejs config file, from App.Bootloader.js: require(['App'], function (App){ App.start(); }); from App.js: define(function (require){ //...requisite includes $, _, Backbone, Marionette ... var Layout = require('Layout'); var App = new Marionette.Application(); App.addRegions({ main: '#view_content' }); App.addInitializer(function

How to write a module that works with Node.js, RequireJS as well as without them

烂漫一生 提交于 2019-12-09 09:28:40
问题 I am working on a JavaScript library for JSON/XML processing. My library works in browser as well as Node.js (with xmldom and xmlhttprequest modules). One of the users recently asked for RequireJS support. I have taken a look at the RequireJS/AMD thing and think it is a good approach so I'd like to provide this. However I'd like to retain the portability: my library must work in browsers (with and without RequireJS) as well as Node.js. And in the browser environment I don't depend on xmldom

require js remove definition to force reload

别说谁变了你拦得住时间么 提交于 2019-12-09 06:07:13
问题 For testing purposes I am trying to remove some amd modules and reload updated versions from the server - with the goal of not refreshing the browser. I am currently doing the following but the browser still doesn't reload the items from the network. var scripts = document.getElementsByTagName('script'); var context = require.s.contexts['_']; for (var key in context.defined) { if(key.indexOf("tests")>-1){ requirejs.undef(key); for (var i = scripts.length - 1; i >= 0; i--) { var script =

When attempting to create a custom data adapter for a select2 combo box, what is causing “Uncaught TypeError baseName split is not a function”?

拟墨画扇 提交于 2019-12-08 10:02:37
问题 I would like to use a select2 combobox with pagination for a local data array (no ajax call). To that end I'm looking at custom DataAdapter. The code to initialise the custom adapter fails. I've tried creating a custom data adapter similar to this answer. When adding the custom data adapter to the select2 object $.fn.select2.amd.require( 'select2/data/customAdapter', ['select2/data/array', 'select2/utils'] I get this error (in chrome and firefox) jquery-3.4.1.js:3850 Uncaught TypeError:

How do I use uncompressed files in Dojo 1.7?

筅森魡賤 提交于 2019-12-07 17:18:41
问题 I've created a Dojo module which depends on dojox/data/JsonRestStore like this: define("my/MyRestStore", ["dojo/_base/declare", "dojox/data/JsonRestStore"], function(declare, JsonRestStore) { var x = new JsonRestStore({ target: '/items', identifier: 'id' }); ... which is fine. But now I want to have the the uncompressed version of the JsonRestStore code loaded so that I can debug it. I can't find any documentation on how to do this, but since there is a file called 'JsonRestStore.js