From 930ee2df7d1bd0c0d24822da84f1ac89ec920f7e Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Sun, 14 May 2017 15:20:27 -0300 Subject: [PATCH 1/2] refactor(jQlite): add the ability to use query selector without jQuery `angular.element` threw an error if we tried to use query selector directly without jQuery. I thought that this was a silly little fix for the framework. A lot of the projects that I've worked for the past years are only including jQuery to use query selectors on the app (I know that are options for this), and I'm only making this PR because I think it's unnecessary to use `angular.element(document).find()` to accomplish such a small thing and to get the jQlite wrapper with the goodies. Now we can do this, without jQuery: `angular.element('.something')` And get the same result. --- src/jqLite.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jqLite.js b/src/jqLite.js index f7913ac4312f..1b2abf2f0ffd 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -45,9 +45,9 @@ *
**Note:** All element references in AngularJS are always wrapped with jQuery or * jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
* - *
**Note:** Keep in mind that this function will not find elements - * by tag name / CSS selector. For lookups by tag name, try instead `angular.element(document).find(...)` - * or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`.
+ *
**Note:** This function will find elements + * by tag name / CSS selector and wrap it in a jQlite object, or in a jQuery object if it's available. You can also query the DOM like `angular.element(document).find(...)` + * or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`, without the wrapper.
* * ## AngularJS's jqLite * jqLite provides only the following jQuery methods: @@ -284,7 +284,7 @@ function JQLite(element) { } if (!(this instanceof JQLite)) { if (argIsString && element.charAt(0) !== '<') { - throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element'); + return new JQLite(document.querySelector(element)); } return new JQLite(element); } From ecb0569ad1fa143117751f1b2b3147fdd8880ec6 Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Wed, 11 Oct 2017 13:35:49 -0300 Subject: [PATCH 2/2] refactor(jQuery): call window before using document use the window to call document as instructed --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jqLite.js b/src/jqLite.js index 1b2abf2f0ffd..bd53fbfbc48b 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -284,7 +284,7 @@ function JQLite(element) { } if (!(this instanceof JQLite)) { if (argIsString && element.charAt(0) !== '<') { - return new JQLite(document.querySelector(element)); + return new JQLite(window.document.querySelector(element)); } return new JQLite(element); }