Permalink
Browse files

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

…querySelector
  • Loading branch information...
1 parent 62cfb15 commit 09320d3a812daa673cdf7a734bee396cbe1e88f2 steve committed with sroussey Aug 2, 2012
Showing with 24 additions and 4 deletions.
  1. +24 −4 extension/content/firebug/console/commandLine.js
@@ -1049,14 +1049,34 @@ Firebug.CommandLine.CommandHandler = Obj.extend(Object,
function FirebugCommandLineAPI(context)
{
- this.$ = function(id) // returns unwrapped elements from the page
+ this.$ = function(selector, start) // returns unwrapped elements from the page
{
- return Wrapper.unwrapObject(context.baseWindow.document).getElementById(id);
+ var result;
+ if (start && start.querySelector && (start.nodeType == 1 || start.nodeType == 9 || start.nodeType == 11))
+ result = start.querySelector(selector);
+ else
+ {
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelector(selector);
+ if (result == null && (selector||"")[0] !== "#")
+ {
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelector("#" + selector);
+ if (result != null)
+ {
+ Firebug.Console.log("The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $(\"#" + selector + "\")", context, "warn");
+ result = null;
+ }
+ }
+ }
+ return result;
};
- this.$$ = function(selector) // returns unwrapped elements from the page
+ this.$$ = function(selector, start) // returns unwrapped elements from the page
{
- var result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
+ var result;
+ if (start && start.querySelectorAll && (start.nodeType == 1 || start.nodeType == 9 || start.nodeType == 11))
+ result = start.querySelectorAll(selector);
+ else
+ result = Wrapper.unwrapObject(context.baseWindow.document).querySelectorAll(selector);
return Arr.cloneArray(result);
};

0 comments on commit 09320d3

Please sign in to comment.