requirejs

Adding RequireJS module that uses jquery on a page that already has jquery as a global

旧时模样 提交于 2019-12-10 18:06:55
问题 I have an add-on to an application (call it appX) that allows users to create their own customizations using javascript, css and appX's webservices api. Usually customizations are small and do not involve a lot of external libraries/plugins but when they do have external libs the typical users' library of choice is jQuery. In the next version of appX they are using jQuery natively which I know is going to break some of the customizations. So I have a need to modularize this situation. I have

How to convert jquery boilerplate into require boilerplate?

喜夏-厌秋 提交于 2019-12-10 17:42:33
问题 How can I convert or put jquery namespace plugin into require boilerplate? For intstance, This is my standard jquery boilerplate usually, // A namepace structure: (function($){ // Initial setting. var pluginName = 'BR_account'; var storageName = 'plugin_' + pluginName; var methods = { init : function( options ) { console.log("this is a jquery plugin boilerplate in requirejs boilerplate"); // nothing returned. } }; $.fn[pluginName] = function( method ) { if ( methods[method] ) { return methods

Testing requireJS methods async with Jasmine

南笙酒味 提交于 2019-12-10 16:47:57
问题 I am trying to test a function that requires a module using jasmine and requirejs . Here is a dummy code: define("testModule", function() { return 123; }); var test = function() { require(['testModule'], function(testModule) { return testModule + 1; }); } describe("Async requirejs test", function() { it("should works", function() { expect(test()).toBe(124); }); }); It fails, because it is an async method. How can I perform a test with it? Note: I dont want to change my code, just my tests

AngularJS template. Inner JS not execute

白昼怎懂夜的黑 提交于 2019-12-10 16:32:52
问题 I have many template html page, which include js code. JS do not execute when my RouteProvider loads one of this template. I do not want to use eval. I can write my code at outer .js files and use requireJS, but I dont know how I can deactivate my "unused" js file with requireJS. Can you tell me how can I execute my JS code at my loaded template page? 回答1: In the current version (1.0.4 and 1.1.2) AngularJS will not execute any JavaScript code contained in a partial specified via templateUrl

Handling prerequsites load failure in RequireJS require function

给你一囗甜甜゛ 提交于 2019-12-10 14:58:23
问题 I'm using RequireJS for AMD. Using this code I execute my function after ensuring the module1 is loaded: require(['module1'], function (module1) { if (module1) { // My function code... } ); In some cases the module1 is not available (mostly because of access security). I want to handle what happens if module1 failed to load. Using some code like: require(['module1'], function (module1) { if (module1) { // My function code... } ) .fail(function(message) { console.log('error while loading

Relative paths using requirejs in combination with Typescript and AMD

送分小仙女□ 提交于 2019-12-10 14:55:40
问题 There are several Javascript files, organized in folders Scripts/folder1, Scripts/folder2, ... With requirejs.config.baseUrl a folder is defined as the default, for example Scripts/folder1. Then in requirejs.config.paths some files are addressed with just the filename, and some are addressed with a relative path (like ../folder2/blabla). When coding the Typescipt file folder2/blabla.ts we need the module "math" from folder1. So we write import MOD1 = module("../folder1/math"); Regarding

Limit line length with requirejs + uglify

旧街凉风 提交于 2019-12-10 14:54:10
问题 We're using requirejs.optimize(config) with uglify2 in our build scripts to minify our production JavaScript code. We want to limit the minified line length to about 80 chars, so that it will be easier to debug JavaScript errors even from the production code. (Most browsers only report the line number, not the column, in the onerror handler, so source maps do not help.) Uglify2 contains the max-line-len option in the beautifier options. I've tried many different combinations of the following

How can I use a videojs plugin when I also use RequireJS

ⅰ亾dé卋堺 提交于 2019-12-10 13:45:58
问题 I'm working on a website that includes some JS code that I do not control. That code uses RequireJS to load dependencies and all. Disclaimer: I'm a RequireJS noob. I understand the basics, but that's pretty much it... In my website, I need to use VideoJS. VideoJS can work with, or without RequireJS but from what I understand, if RequireJS is used somewhere in the page, I cannot use VideoJS without it. So I'm loading VideoJS with RequireJS like this: var MyRequire = requirejs.config({ baseUrl:

Multiple conditions with yepnope

不打扰是莪最后的温柔 提交于 2019-12-10 13:27:54
问题 I use yepnope.js as a resource loaded. I want to execute code in my JS module only when all the dependencies for that module have been loaded. I do not want to load JS dependencies that already been loaded. Suppose, I have dependencies D1.js and D2.js. I tried yepnope({ load: ['D1.js', 'D2.js], complete: function() { //execute my code here } }); That works, but, resources are loaded every time, even if they were already loaded before. If I do multiple tests like that: yepnope([{ test: $().d1,

Plone5 Mockup Widgets like pat-pickadate not working for dynamically generated content

霸气de小男生 提交于 2019-12-10 13:23:07
问题 Assume the following silly code fragment in a plone 5 page template: <input id="foo" class="pat-pickadate" /> <input id="bar" /> <script type="text/javascript" > $('#bar').click( function () { $('#bar').addClass("pat-pickadate"); }); </script> You will get two inputs. The first is a nice calendar input and the second is empty at start. After clicking the second input its class will be set to "pat-pickadate" - like the first - but no calendar is rendered. I came across this while trying to