hrss/web/static/js/jquery-getpath.js

23 lines
698 B
JavaScript
Raw Normal View History

2018-10-24 23:57:41 +02:00
jQuery.fn.extend({
getPath: function( path ) {
// The first time this function is called, path won't be defined.
if ( typeof path == 'undefined' ) path = '';
// If this element is <html> we've reached the end of the path.
if ( this.is('html') )
return 'html' + path;
// Add the element name.
var cur = this[0].nodeName.toLowerCase();
2018-10-25 12:03:14 +02:00
// Determine the path.
2018-10-24 23:57:41 +02:00
var cls = this.attr('class');
// Add any classes.
if ( typeof cls != 'undefined' )
cur += '.' + cls.split(/[\s\n]+/).join('.');
// Recurse up the DOM.
return this.parent().getPath( ' > ' + cur + path );
}
});