Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5764: Change JSTerm's $ helper function from getElementById to …

…querySelector
  • Loading branch information...
commit 4bbd8f99bb7c87a7bfff113b013d81efa36e798b 1 parent 893d740
authored August 02, 2012 sroussey committed August 04, 2012
28  extension/content/firebug/console/commandLine.js
@@ -1043,14 +1043,34 @@ Firebug.CommandLine.CommandHandler = Obj.extend(Object,
1043 1043
 
1044 1044
 function FirebugCommandLineAPI(context)
1045 1045
 {
1046  
-    this.$ = function(id)  // returns unwrapped elements from the page
  1046
+    this.$ = function(selector, start)  // returns unwrapped elements from the page
1047 1047
     {
1048  
-        return Wrapper.unwrapObject(context.baseWindow.document).getElementById(id);
  1048
+        var result;
  1049
+        if (start && start.querySelector && (start.nodeType == 1 || start.nodeType == 9 || start.nodeType == 11))
  1050
+            result = start.querySelector(selector);
  1051
+        else
  1052
+        {
  1053
+            result = Wrapper.unwrapObject(context.baseWindow.document).querySelector(selector);
  1054
+            if (result == null && (selector||"")[0] !== "#")
  1055
+            {
  1056
+                result = Wrapper.unwrapObject(context.baseWindow.document).querySelector("#" + selector);
  1057
+                if (result != null)
  1058
+                {
  1059
+                    Firebug.Console.log("The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $(\"#" + selector + "\")", context, "warn");
  1060
+                    result = null;
  1061
+                }
  1062
+            }
  1063
+        }
  1064
+        return result;
1049 1065
     };
1050 1066
 
1051  
-    this.$$ = function(selector) // returns unwrapped elements from the page
  1067
+    this.$$ = function(selector, start) // returns unwrapped elements from the page
1052 1068
     {
1053  
-        var result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
  1069
+        var result;
  1070
+        if (start && start.querySelectorAll && (start.nodeType == 1 || start.nodeType == 9 || start.nodeType == 11))
  1071
+            result = start.querySelectorAll(selector);
  1072
+        else
  1073
+            result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
1054 1074
         return Arr.cloneArray(result);
1055 1075
     };
1056 1076
 

3 notes on commit 4bbd8f9

Sebastian Zartner
Collaborator

Three points:

  • $() doesn't seem to work for me as expected (try $(".class1") on Joe's test case)
  • Better use constants instead of magic numbers.
  • Add a comment that the warning should be removed in a future version

Sebastian

Steven Roussey
Owner
  • Wow, that is an old page of Joe's! It also loads prototype.js on the page, so Firebug will use that version of $, of course. I deal with more PrototypeJS stuff than jQuery stuff, believe it or not. So, yeah, this is a problem with the two JS libs defining incompatible versions, and our switching around. This is an example of the bogus bug reports you will get. ;)

  • Yeah, I will change if we decide to keep this functionality (or before)

  • Yes, one release later I think, we should pull the warning. I'll comment it up.

Sebastian Zartner
Collaborator
  • Wow, that is an old page of Joe's!

Yes. Though I use it a lot for reproducing issues.

It also loads prototype.js on the page, so Firebug will use that version of $

Oh my! I totally forgot about that! Sorry, Steven! So I tested it on other sites and it's working as expected.

This is an example of the bogus bug reports you will get. ;)

Right. I wonder why we don't get this kind of reports more often already...

  • Yeah, I will change if we decide to keep this functionality (or before)

  • Yes, one release later I think, we should pull the warning. I'll comment it up.

Good.

Sebastian

Please sign in to comment.
Something went wrong with that request. Please try again.