Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

enables AngularJS to use any jQuery, implementing issue #608 #2163

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = function(grunt) {
test: {
jqlite: 'testacular-jqlite.conf.js',
jquery: 'testacular-jquery.conf.js',
forcejqlite: 'testacular-force-jqlite.conf.js',
modules: 'testacular-modules.conf.js',
//NOTE run grunt test:e2e instead and it will start a webserver for you
end2end: 'testacular-e2e.conf.js'
Expand Down
31 changes: 28 additions & 3 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ angularFiles = {
'jstdExclude': [
'test/jquery_alias.js',
'src/angular-bootstrap.js',
'src/ngScenario/angular-bootstrap.js'
'src/ngScenario/angular-bootstrap.js',
'test/force_jqlite.js'
],

'jstdScenario': [
Expand Down Expand Up @@ -194,12 +195,36 @@ angularFiles = {

'example/personalLog/test/*.js'
],

'jstdForceJqlite': [
'lib/jasmine/jasmine.js',
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
'lib/jquery/jquery.js',
'test/force_jqlite.js',
'@angularSrc',
'src/publishExternalApis.js',
'@angularSrcModules',
'@angularScenario',
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
'@angularTest',
'example/personalLog/*.js',

'example/personalLog/test/*.js'
],

'jstdJqueryExclude': [
'src/angular-bootstrap.js',
'src/ngScenario/angular-bootstrap.js',
'test/jquery_remove.js'
]
'test/jquery_remove.js',
'test/force_jqlite.js'
],

'jstdForceJqliteExclude': [
'src/angular-bootstrap.js',
'src/ngScenario/angular-bootstrap.js',
'test/jquery_remove.js',
'test/jquery_alias.js'
],
};

if (exports) {
Expand Down
4 changes: 4 additions & 0 deletions docs/content/guide/bootstrap.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ If you need to have more control over the initialization process, you can use a
bootstrapping method instead. Examples of when you'd need to do this include using script loaders
or the need to perform an operation before Angular compiles a page.

By default, Angular includes jQuery if it finds it, otherwise it reverts to using the included
jQuery lite. You can override this behavior by using the `window.angularjsUseJquery` variable
before the script tab loading Angular. You can make this variable point to any existing jQuery
instance, or just set it to `"internal"` if you want to use the included jQuery anyway.

Here is an example of manually initializing Angular. The example is equivalent to using the {@link
api/ng.directive:ngApp ng-app} directive.
Expand Down
10 changes: 8 additions & 2 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,14 @@ function snake_case(name, separator){
}

function bindJQuery() {
// bind to jQuery if present;
jQuery = window.jQuery;
// bind to any given jQuery - useful to include the internal one anyway
if (!window.angularjsUseJquery) {
jQuery = window.jQuery;
} else if (window.angularjsUseJquery === 'internal') {
jQuery = null;
} else {
jQuery = window.angularjsUseJquery;
}
// reset to jQuery or default to us.
if (jQuery) {
jqLite = jQuery;
Expand Down
5 changes: 5 additions & 0 deletions test/force_jqlite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var angularjsUseJquery = 'internal',
_jQuery = jQuery,
_jqLiteMode = true;
14 changes: 14 additions & 0 deletions testacular-force-jqlite.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var angularFiles = require(__dirname + '/angularFiles.js');

files = angularFiles.mergeFiles(JASMINE, JASMINE_ADAPTER, 'jstdForceJqlite');
exclude = ['**/*jasmine*/**', '**/*jstd*/**'].concat(angularFiles.files.jstdForceJqliteExclude);

autoWatch = true;
logLevel = LOG_INFO;
logColors = true;
browsers = ['Chrome'];

junitReporter = {
outputFile: 'test_out/jquery.xml',
suite: 'jQuery'
};