Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 37 additions & 42 deletions prettyprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var prettyPrint = (function(){

/* Add attributes to el */
if (attrs && attrs.style) {
var styles = attrs.style;
util.applyCSS( el, attrs.style );
delete attrs.style;
}
Expand All @@ -72,10 +71,10 @@ var prettyPrint = (function(){
/* Applies CSS to a single element */
for (var prop in styles) {
if (styles.hasOwnProperty(prop)) {
try{
if (el.style){
/* Yes, IE6 SUCKS! */
el.style[prop] = styles[prop];
}catch(e){}
}
}
}
},
Expand All @@ -93,23 +92,20 @@ var prettyPrint = (function(){
/* colSpan is calculated by length of null items in array */
var colSpan = util.count(cells, null) + 1,
tr = util.el('tr'), td,
attrs = {
style: util.getStyles(cellType, type),
colSpan: colSpan,
onmouseover: function() {
onmouse = function(mousetype){
return function() {
var tds = this.parentNode.childNodes;
util.forEach(tds, function(cell){
if (cell.nodeName.toLowerCase() !== 'td') { return; }
util.applyCSS(cell, util.getStyles('td_hover', type));
util.applyCSS(cell, util.getStyles(mousetype, type));
});
},
onmouseout: function() {
var tds = this.parentNode.childNodes;
util.forEach(tds, function(cell){
if (cell.nodeName.toLowerCase() !== 'td') { return; }
util.applyCSS(cell, util.getStyles('td', type));
});
}
};
},
attrs = {
style: util.getStyles(cellType, type),
colSpan: colSpan,
onmouseover: onmouse('td_hover'),
onmouseout: onmouse('td')
};

util.forEach(cells, function(cell){
Expand Down Expand Up @@ -142,20 +138,16 @@ var prettyPrint = (function(){
headings = headings || [];

/* Creates new table: */
var attrs = {
thead: {
style:util.getStyles('thead',type)
},
tbody: {
style:util.getStyles('tbody',type)
},
table: {
style:util.getStyles('table',type)
}
var attrs = {},
setGetters = function (styleType){
attrs[styleType] = {
style:util.getStyles(styleType,type)
};
return util.el(styleType, attrs[styleType])
},
tbl = util.el('table', attrs.table),
thead = util.el('thead', attrs.thead),
tbody = util.el('tbody', attrs.tbody);
tbl = setGetters('table'),
thead = setGetters('thead'),
tbody = setGetters('tbody');

if (headings.length) {
tbl.appendChild(thead);
Expand Down Expand Up @@ -215,7 +207,7 @@ var prettyPrint = (function(){

}

for (var a = 2, l = arguments.length; a < l; a++) {
for (var a = 2; a < arguments.length; a++) {
util.merge(target, arguments[a]);
}

Expand All @@ -224,7 +216,7 @@ var prettyPrint = (function(){

count: function(arr, item) {
var count = 0;
for (var i = 0, l = arr.length; i< l; i++) {
for (var i = 0; i< arr.length; i++) {
if (arr[i] === item) {
count++;
}
Expand Down Expand Up @@ -272,7 +264,7 @@ var prettyPrint = (function(){
return oType;
}
if (typeof v === 'object') {
return v.jquery && typeof v.jquery === 'string' ? 'jquery' : 'object';
return typeof v.jquery === 'string' ? 'jquery' : 'object';
}
if (v === window || v === document) {
return 'object';
Expand Down Expand Up @@ -313,10 +305,11 @@ var prettyPrint = (function(){
'[DEPTH REACHED]',
'Click to show this item anyway',
function() {
var appendChild = this.parentNode.appendChild;
try {
this.parentNode.appendChild( prettyPrintThis(obj,{maxDepth:1}) );
appendChild( prettyPrintThis(obj,{maxDepth:1}) );
} catch(e) {
this.parentNode.appendChild(
appendChild(
util.table(['ERROR OCCURED DURING OBJECT RETRIEVAL'],'error').addRow([e.message]).node
);
}
Expand All @@ -326,22 +319,24 @@ var prettyPrint = (function(){
},

getStyles: function(el, type) {
type = prettyPrintThis.settings.styles[type] || {};
var styles = prettyPrintThis.settings.styles;
type = styles[type] || {};
return util.merge(
{}, prettyPrintThis.settings.styles['default'][el], type[el]
{}, styles['default'][el], type[el]
);
},

expander: function(text, title, clickFn) {
var onmouse = function (visibility){
return function() {
this.getElementsByTagName('b')[0].style.visibility = visibility;
};
}
return util.el('a', {
innerHTML: util.shorten(text) + ' <b style="visibility:hidden;">[+]</b>',
title: title,
onmouseover: function() {
this.getElementsByTagName('b')[0].style.visibility = 'visible';
},
onmouseout: function() {
this.getElementsByTagName('b')[0].style.visibility = 'hidden';
},
onmouseover: onmouse('visible'),
onmouseout: onmouse('hidden'),
onclick: function() {
this.style.display = 'none';
clickFn.call(this);
Expand Down