Skip to content

Instantly share code, notes, and snippets.

@cers
Created March 19, 2009 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cers/81748 to your computer and use it in GitHub Desktop.
Save cers/81748 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "selector",
description: "Finds a selector that will match element currently hovered, and highlights all matches",
execute: function() {
CmdUtils.loadJQuery(function(){
var d = CmdUtils.getDocumentInsecure();
var w = CmdUtils.getWindowInsecure();
myId = function(me){ return me.id ? '#' + me.id : '' }
myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' }
myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' }
breadcrumbs = function(me){
var path = [myTag(me) + myId(me) + myClass(me)];
w.jQuery(me).parents().each(function() {
path[path.length] = myTag(this) + myId(this) + myClass(this);
});
path.reverse();
return path.join(' > ').replace(/.ubiquityHighlight/g,"");
}
if (!d.getElementById("ubiquityCss"))
w.jQuery('head').append('<style id="ubiquityCss" type="text/css">.ubiquityHighlight {border: 1px blue solid !important;}</style>');
w.jQuery("*").each(function(){
w.jQuery(this).mouseover(function(e){
w.jQuery("*").removeClass("ubiquityHighlight");
var path = breadcrumbs(this);
w.jQuery(path).addClass("ubiquityHighlight");
e.stopPropagation();
});
w.jQuery(this).mouseout(function(e){
w.jQuery(this).removeClass("ubiquityHighlight");
});
w.jQuery(this).click(function(e){
displayMessage(breadcrumbs(this));
e.stopPropagation();
e.preventDefault();
return false;
});
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment