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 f47c2225fd280cb31d3a6170956bab684758d75c 1 parent 24fd0ae
authored August 02, 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
 

0 notes on commit f47c222

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