SystemJS - Provide JQuery global object - systemjs

I have a project which is a mix of new code and old libraries, some of which is based on JQuery and JQuery plugins. I'm facing some issues where some plugins are using the global object ($) to integrate, and other are doing require("jquery") or the equivalent. This appears to be fetching two different instances of JQuery.
Because of some existing code, I need the global object to be there. However, to support my newer code I want anything that requires or imports 'jquery' to be provided the window.jQuery object instead of trying to load an external module.
Can I do this with SystemJS?

Did you try the SystemJS-Adapter-Modules? Create a file jquery.js and reference the globally loaded jQuery function:
module.exports = window.jQuery;
When you import "jquery" you should get a reference to the already loaded jQuery function.
SystemJS-Adapter-Modules

Related

what is the purpose of these angular2 imports?

I am a newbie in angular2 and want to know the purpose of following imports we do in our angular2 app.
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
so my questions regarding these imports are:
what are these imports for?
does the sequence of these imports metter?
are there any other useful imports that we must be aware of?
Thanks in advance.
I don't see any imports in your code sample. Its just including the files of various libraries into web page. If you read some of them one by one:
es6-shim.min.js - adds ES6 language features to browsers (full list)
Rx.js adds Observables library (GitHub RxJS)
http.dev.js - adds angular2 $http module to make requests
So you can google each of the names and figure out for yourself if that's applicable for your project.
More on modules and actual imports in ES2015/ES6 you can read here https://ponyfoo.com/articles/es6-modules-in-depth for example.
"useful imports that we must be aware of?"
Totally depends on your needs. By I assume angular2.dev.js and http.dev.js would be a good to start.
"does the sequence of these imports matter?"
Not now, but only if you're using proper module system so that browser can load missing parts before executing the blocks that depend on them. And also the loader file (system.js/require.js) should be in the first before all the other files.
Here are the details about what you specified in your script elements:
The two first files aren't necessary if you use TypeScript and have configuted ES5 output.
angular2-polyfills.js - Contains ZoneJS (to trigger change detection - see What is the Angular2 equivalent to an AngularJS $watch?) and reflect-metadata (to set metadata on objects from decorators)
system.src.js - SystemJS, the library that manages modules. In short when you use import and export in TypeScript the corresponding compiled code relies on it.
Rx.js - RxJS, a library that provides an implementation of Reactive Programming concepts. In short, it provides an implementArion of observables and their operators. EventEmitters, HTTP rely on this.
angular2.dev.js - Angular2 core bundle
http.dev.js - HTTP support of Angular2

ember-cli#0.2.0 component templates in an addon

I'm wondering what the convention to use is when creating a component inside an addon project... If I generate a component in my addon project using ember-cli#0.2.0, the blueprint will create a js file in addon/components, a template in addon/templates/components, and a js file in app/components. The part I'm not real clear about is where templates should live for these components. If my component template requires a partial, I need to put the partial template in the app/templates directory. If it lives in the addon/templates directory, it can't be resolved. So the question is this: Is it best to put all the templates (the component template and the partials) in the app/templates directory or leave the component template in the addon/templates/components directory and the partial in the app/templates directory? The latter feels slightly disorganized and the former seems more correct only because of the behavior of the blueprint. Anyone have any insight?
Thanks in advance.
Ember-cli is under heavy development so a lot of the file structure is likely to change soon, but here on some insights on the current state of the folder structure and why it is arranged the way it is:
The app/ folder is what gets directly imported into your application. Helpers are pulled from here, which is why you have to have a file for each of your components in this folder. Additionally templates will get pulled from the main application here, and as such they will be accessible in the ways that templates are normally accessible in an ember app (render, partial, and standard resolution).
Some people choose to place all of their components code in app/, but this is a bad idea because the addon/ folder exists not only as a separation of your addons code, but as a way for it to be imported using ES6 imports. So, while you can't directly access the components under addon/components/, you can import them into your application like so:
import SomeComponent from 'some-addon/components/some-component'
This is very useful for addon consumers if they want to extend an addon to add some functionality.
Templates in addon get precompiled in the build tree, which makes addons a bit more robust (for instance if they are using a different version of htmlbars they will still be compatible with the base app). However, they are not accessible via the resolver, so you have to import them manually in your addon's components, which is why the blueprint for addon components looks like the following:
import Ember from 'ember';
import layout from '../templates/components/some-component';
export default Ember.Component.extend({
layout: layout
});
Styles for addons can either be placed in addon/styles/ or app/styles/. In addon/styles/ they are also precompiled and included in the application by default. I highly recommend including styles in app/styles because this makes them accessible using preprocessor imports in the base application:
#import some-addon/main.css
This makes them completely optional to users of the addon, without resorting to app.import and config trickery (which is good because nested addons _do not support app.import. Don't use it.)
NOTE: They are not automatically namespaced, so you should put your styles in a folder to make sure they aren't conflicting with other addons styles.
In summary:
Any addon code that does not need to be directly accessible by the base app via helpers, initializers, etc. Should live in addon/
Anything you want to be accessible by ES6 imports should live in addon/
Templates should live in addon/templates/ and be imported manually
Component stubs, initializers, and other files that should be included in the standard Ember build chain should live in app/
Styles should live in app/styles/ and should be namespaced in a folder (e.g. app/styles/some-addon/)
Don't use app.import.

Exporting a class and its methods in GWT for use in native JavaScript

I'm developing a GWT project at the moment and it's been up and running for a while. New functionality that is to be added require extensive testing, visualizing and simulating of a specific algorithm. I would like to export that specific algorithm so that I may call it directly from JavaScript and do some canvas magic.
How can I export a number of classes for direct use in JavaScript from a GWT project?
I've tried using the GWT exporter, following the Getting Started section closely.
I've noticed that my output directory contains a new generator class (TestClassExporterImpl.java) but the final JavaScript output contains no trace of my TestClass or the exported methods.
I'm sure I've made a mistake somewhere on the way or didn't understand the GWT exporter correctly.
Try to disable obfuscation, it will create the same names in Javascript as in the original Java code

How can I expose plugin functions to docpad partials?

tldr; Is there a way to expose functions defined in one plugin for another plugin to use?
I'm trying to use the tagging plugin (https://github.com/rantecki/docpad-plugin-tagging) within a partial.
I have a Jade partial setup as follows:
.post-tags
| Posted in
each tag in tags
a(href=getTagUrl(tag))= tag + ' '
where getTagUrl is a function defined by the tagging plugin. The problem is that the partial has no knowledge and this partial does not render.
As v2.8.0+ of the partials plugin now includes the template data by default (you don't have to manually specify it's inclusion anymore), try running docpad update in your project's root directory and trying again. Otherwise, we'll probably have to see the source code of your project to help isolate the issue.
It's because partial do not have access by default to templateData, the object holding the getTagUrl helper. You have to pass it explicitly to the partial.
Here's a similar answer provided for the eco templating language :
https://stackoverflow.com/a/16631649/232943

How to use backbone js with some legacy plugins?

I've working on a project and I'm using some jquery plugins, right now I'm trying to update my code to use backboje js but it's not clear how to put together those old plugins with backbone js.
the most important plugin I want to use is jcvl (http://code.google.com/p/jcvl/) but I'm trying to put this question general to get more ideas about how to integrate any pluggin with backbone.
Backbone only creates one global variable, Backbone, so there shouldn't be any conflicts with any jQuery plugins. Backbone also depends on Underscore.js, which also only creates one global variable, _, so it also shouldn't cause any conflicts. And if there is a conflict, both Backbone and Underscore.js offer you a noConflict() option.
I've been using Backbone with jQuery plugins for a while and haven't encountered any problems. You would use the plugin in the same way as before you introduced Backbone. For example:
var MyView = Backbone.View.extend({
render: function(){
$(this.el).html('<div class="foo"></div>');
this.$('.foo').somejQueryPlugin();
}
});