-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.objectCSS.js
More file actions
94 lines (82 loc) · 2.5 KB
/
jquery.objectCSS.js
File metadata and controls
94 lines (82 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* objectCSS plugin for jQuery
* v1.0
* Highlight your abstracted Objects.
*
* By Bill Keler, ghettocooler.net
*
*/
/**
* Usage:
*
* From JavaScript, use:
* $(<select>).objectCSS({depth: <x>});
* where:
* <select> is the DOM node selector, e.g. ".media"
* <x> is 0, 1 or 2, representing the level of the objects children that you'd like visualized
*/
(function($) {
// jQuery plugin definition
$.fn.objectCSS = function(params) {
// merge default and user parameters
params = $.extend( {depth: 0}, params);
this.each(function() {
parentClass = $(this).attr('class');
if (parentClass == undefined) {
var parentClass = '';
} else {
parentClass = '.'+ parentClass;
parentClass = parentClass.replace(/ /g, '.');
}
console.log(parentClass);
$(this).not('.css-obj').css({
'outline' : '1px dotted red',
'position' : 'relative',
}).prepend('<div class="css-obj css-obj-parent">'+ parentClass +'</div>');
if (params.depth >= '1') {
$(this).children().not('.css-obj').each(function() {
var thisClass = $(this).attr('class');
if (thisClass == undefined) {
var thisClass = '';
} else {
thisClass = '.'+ thisClass;
thisClass = thisClass.replace(/ /g, '.');
}
$(this).addClass('css-obj-child-parent')
.prepend('<div class="css-obj css-obj-child">'+ thisClass +'</div>');
});
};
if (params.depth >= '2') {
$(this).children().not('.css-obj').children().not('.css-obj').each(function() {
var thisTag = this.nodeName.toLowerCase();
var thisClass = $(this).attr('class');
if (thisClass == undefined) {
var thisClass = '';
} else {
thisClass = '.'+ thisClass;
thisClass = thisClass.replace(/ /g, '.');
}
$(this).addClass('css-obj-child2-parent').prepend('<div class="css-obj css-obj-child2">'+ thisTag + thisClass +'</div>');
});
};
});
// allow jQuery chaining
return this;
};
})(jQuery);
/*
// for each object, accept an array of parent elements
$('.media').css({
'outline' : '1px dotted green',
'position' : 'relative',
}).prepend('<div class="css-obj css-obj-parent">.media</div>');
// Get class-names of each direct sibling
var directSibling = '';
// accept # of children that are highlightable
$('.media > *').not('.css-obj').each(function() {
directSibling = $(this).attr('class');
$(this).css({
'outline' : '1px dotted red',
}).prepend('<div class="css-obj css-obj-child">.'+ directSibling +'</div>');
});
*/