Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/redux-fr.../redux-co.../assets/js/vendor
File: jsonview.js
// jscs:disable
[0] Fix | Delete
// jshint ignore: start
[1] Fix | Delete
[2] Fix | Delete
/* global console, jsonView */
[3] Fix | Delete
[4] Fix | Delete
/*
[5] Fix | Delete
* ViewJSON
[6] Fix | Delete
* Version 1.0
[7] Fix | Delete
* A Google Chrome extension to display JSON in a user-friendly format
[8] Fix | Delete
*
[9] Fix | Delete
* This is a chromeified version of the JSONView Firefox extension by Ben Hollis:
[10] Fix | Delete
* http://jsonview.com
[11] Fix | Delete
* http://code.google.com/p/jsonview
[12] Fix | Delete
*
[13] Fix | Delete
* Also based on the XMLTree Chrome extension by Moonty & alan.stroop
[14] Fix | Delete
* https://chrome.google.com/extensions/detail/gbammbheopgpmaagmckhpjbfgdfkpadb
[15] Fix | Delete
*
[16] Fix | Delete
* port by Jamie Wilkinson (@jamiew) | http://jamiedubs.com | http://github.com/jamiew
[17] Fix | Delete
* MIT license / copyfree (f) F.A.T. Lab http://fffff.at
[18] Fix | Delete
* Speed Project Approved: 2h
[19] Fix | Delete
*/
[20] Fix | Delete
[21] Fix | Delete
function collapse( evt ) {
[22] Fix | Delete
var collapser = evt.target;
[23] Fix | Delete
var target = collapser.parentNode.getElementsByClassName( 'collapsible' );
[24] Fix | Delete
if ( ! target.length ) {
[25] Fix | Delete
return;
[26] Fix | Delete
}
[27] Fix | Delete
target = target[0];
[28] Fix | Delete
if ( target.style.display === 'none' ) {
[29] Fix | Delete
var ellipsis = target.parentNode.getElementsByClassName( 'ellipsis' )[0];
[30] Fix | Delete
target.parentNode.removeChild( ellipsis );
[31] Fix | Delete
target.style.display = '';
[32] Fix | Delete
} else {
[33] Fix | Delete
target.style.display = 'none';
[34] Fix | Delete
var ellipsis = document.createElement( 'span' );
[35] Fix | Delete
ellipsis.className = 'ellipsis';
[36] Fix | Delete
ellipsis.innerHTML = ' … ';
[37] Fix | Delete
target.parentNode.insertBefore( ellipsis, target );
[38] Fix | Delete
}
[39] Fix | Delete
collapser.innerHTML = (collapser.innerHTML === '-') ? '+' : '-';
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
function addCollapser( item ) {
[43] Fix | Delete
// This mainly filters out the root object (which shouldn't be collapsible).
[44] Fix | Delete
if ( item.nodeName !== 'LI' ) {
[45] Fix | Delete
return;
[46] Fix | Delete
}
[47] Fix | Delete
var collapser = document.createElement( 'div' );
[48] Fix | Delete
collapser.className = 'collapser';
[49] Fix | Delete
collapser.innerHTML = '-';
[50] Fix | Delete
collapser.addEventListener( 'click', collapse, false );
[51] Fix | Delete
item.insertBefore( collapser, item.firstChild );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
function jsonView( id, target ) {
[55] Fix | Delete
this.debug = false;
[56] Fix | Delete
if ( id.indexOf( '#' ) !== - 1 ) {
[57] Fix | Delete
this.idType = 'id';
[58] Fix | Delete
this.id = id.replace( '#', '' );
[59] Fix | Delete
} else if ( id.indexOf( '.' ) !== - 1 ) {
[60] Fix | Delete
this.idType = 'class';
[61] Fix | Delete
this.id = id.replace( '.', '' );
[62] Fix | Delete
} else {
[63] Fix | Delete
if ( this.debug ) {
[64] Fix | Delete
console.log( 'Can\'t find that element' );
[65] Fix | Delete
}
[66] Fix | Delete
return;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
this.data = document.getElementById( this.id ).innerHTML;
[70] Fix | Delete
if ( typeof (target) !== undefined ) {
[71] Fix | Delete
if ( target.indexOf( '#' ) !== - 1 ) {
[72] Fix | Delete
this.targetType = 'id';
[73] Fix | Delete
this.target = target.replace( '#', '' );
[74] Fix | Delete
} else if ( id.indexOf( '.' ) !== - 1 ) {
[75] Fix | Delete
this.targetType = 'class';
[76] Fix | Delete
this.target = target.replace( '.', '' );
[77] Fix | Delete
} else {
[78] Fix | Delete
if ( this.debug ) {
[79] Fix | Delete
console.log( 'Can\'t find the target element' );
[80] Fix | Delete
}
[81] Fix | Delete
return;
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
// Note: now using "*.json*" URI matching rather than these page regexes -- save CPU cycles!
[85] Fix | Delete
// var is_json = /^\s*(\{.*\})\s*$/.test(this.data);
[86] Fix | Delete
// var is_jsonp = /^.*\(\s*(\{.*\})\s*\)$/.test(this.data);
[87] Fix | Delete
// if(is_json || is_jsonp){
[88] Fix | Delete
// Our manifest specifies that we only do URLs matching '.json', so attempt to sanitize any HTML
[89] Fix | Delete
// added by Chrome's "text/plain" or "text/html" handlers.
[90] Fix | Delete
if ( /^\<pre.*\>(.*)\<\/pre\>$/.test( this.data ) ) {
[91] Fix | Delete
if ( this.debug ) {
[92] Fix | Delete
console.log( 'JSONView: data is wrapped in <pre>...</pre>, stripping HTML...' );
[93] Fix | Delete
}
[94] Fix | Delete
this.data = this.data.replace( /<(?:.|\s)*?>/g, '' ); // Aggressively strip HTML.
[95] Fix | Delete
}
[96] Fix | Delete
// Test if what remains is JSON or JSONp.
[97] Fix | Delete
var json_regex = /^\s*([\[\{].*[\}\]])\s*$/; // Ghetto, but it works.
[98] Fix | Delete
var jsonp_regex = /^[\s\u200B\uFEFF]*([\w$\[\]\.]+)[\s\u200B\uFEFF]*\([\s\u200B\uFEFF]*([\[{][\s\S]*[\]}])[\s\u200B\uFEFF]*\);?[\s\u200B\uFEFF]*$/;
[99] Fix | Delete
var jsonp_regex2 = /([\[\{][\s\S]*[\]\}])\)/; // more liberal support... this allows us to pass the jsonp.json & jsonp2.json tests.
[100] Fix | Delete
var is_json = json_regex.test( this.data );
[101] Fix | Delete
var is_jsonp = jsonp_regex.test( this.data );
[102] Fix | Delete
if ( this.debug ) {
[103] Fix | Delete
console.log( 'JSONView: is_json=' + is_json + ' is_jsonp=' + is_jsonp );
[104] Fix | Delete
}
[105] Fix | Delete
if ( is_json || is_jsonp ) {
[106] Fix | Delete
if ( this.debug ) {
[107] Fix | Delete
console.log( 'JSONView: sexytime!' );
[108] Fix | Delete
}
[109] Fix | Delete
// JSONFormatter json->HTML prototype straight from Firefox JSONView
[110] Fix | Delete
// For reference: http://code.google.com/p/jsonview.
[111] Fix | Delete
function JSONFormatter() {
[112] Fix | Delete
// No magic required.
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
JSONFormatter.prototype = {
[116] Fix | Delete
htmlEncode: function( t ) {
[117] Fix | Delete
return t != null ? t.toString().replace( /&/g, '&amp;' ).replace( /"/g, '&quot;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ) : '';
[118] Fix | Delete
}, decorateWithSpan: function( value, className ) {
[119] Fix | Delete
return '<span class="' + className + '">' + this.htmlEncode( value ) + '</span>';
[120] Fix | Delete
}, // Convert a basic JSON datatype (number, string, boolean, null, object, array) into an HTML fragment.
[121] Fix | Delete
valueToHTML: function( value ) {
[122] Fix | Delete
var valueType = typeof value;
[123] Fix | Delete
var output = '';
[124] Fix | Delete
if ( value === null ) {
[125] Fix | Delete
output += this.decorateWithSpan( 'null', 'null' );
[126] Fix | Delete
} else if ( value && value.constructor === Array ) {
[127] Fix | Delete
output += this.arrayToHTML( value );
[128] Fix | Delete
} else if ( valueType === 'object' ) {
[129] Fix | Delete
output += this.objectToHTML( value );
[130] Fix | Delete
} else if ( valueType === 'number' ) {
[131] Fix | Delete
output += this.decorateWithSpan( value, 'num' );
[132] Fix | Delete
} else if ( valueType === 'string' ) {
[133] Fix | Delete
if ( /^(http|https):\/\/[^\s]+$/.test( value ) ) {
[134] Fix | Delete
output += '<a href="' + value + '">' + this.htmlEncode( value ) + '</a>';
[135] Fix | Delete
} else {
[136] Fix | Delete
output += this.decorateWithSpan( '"' + value + '"', 'string' );
[137] Fix | Delete
}
[138] Fix | Delete
} else if ( valueType === 'boolean' ) {
[139] Fix | Delete
output += this.decorateWithSpan( value, 'bool' );
[140] Fix | Delete
}
[141] Fix | Delete
return output;
[142] Fix | Delete
}, // Convert an array into an HTML fragment
[143] Fix | Delete
arrayToHTML: function( json ) {
[144] Fix | Delete
var output = '[<ul class="array collapsible">';
[145] Fix | Delete
var hasContents = false;
[146] Fix | Delete
for ( var prop in json ) {
[147] Fix | Delete
hasContents = true;
[148] Fix | Delete
output += '<li>';
[149] Fix | Delete
output += this.valueToHTML( json[prop] );
[150] Fix | Delete
output += '</li>';
[151] Fix | Delete
}
[152] Fix | Delete
output += '</ul>]';
[153] Fix | Delete
if ( ! hasContents ) {
[154] Fix | Delete
output = '[ ]';
[155] Fix | Delete
}
[156] Fix | Delete
return output;
[157] Fix | Delete
}, // Convert a JSON object to an HTML fragment
[158] Fix | Delete
objectToHTML: function( json ) {
[159] Fix | Delete
var output = '{<ul class="obj collapsible">';
[160] Fix | Delete
var hasContents = false;
[161] Fix | Delete
for ( var prop in json ) {
[162] Fix | Delete
hasContents = true;
[163] Fix | Delete
output += '<li>';
[164] Fix | Delete
output += '<span class="prop">' + this.htmlEncode( prop ) + '</span>: ';
[165] Fix | Delete
output += this.valueToHTML( json[prop] );
[166] Fix | Delete
output += '</li>';
[167] Fix | Delete
}
[168] Fix | Delete
output += '</ul>}';
[169] Fix | Delete
if ( ! hasContents ) {
[170] Fix | Delete
output = '{ }';
[171] Fix | Delete
}
[172] Fix | Delete
return output;
[173] Fix | Delete
}, // Convert a whole JSON object into a formatted HTML document.
[174] Fix | Delete
jsonToHTML: function( json, callback, uri ) {
[175] Fix | Delete
var output = '';
[176] Fix | Delete
if ( callback ) {
[177] Fix | Delete
output += '<div class="callback">' + callback + ' (</div>';
[178] Fix | Delete
output += '<div id="json">';
[179] Fix | Delete
} else {
[180] Fix | Delete
output += '<div id="json">';
[181] Fix | Delete
}
[182] Fix | Delete
output += this.valueToHTML( json );
[183] Fix | Delete
output += '</div>';
[184] Fix | Delete
if ( callback ) {
[185] Fix | Delete
output += '<div class="callback">)</div>';
[186] Fix | Delete
}
[187] Fix | Delete
return this.toHTML( output, uri );
[188] Fix | Delete
}, // Produce an error document for when parsing fails.
[189] Fix | Delete
errorPage: function( error, data, uri ) {
[190] Fix | Delete
// var output = '<div id="error">' + this.stringbundle.GetStringFromName('errorParsing') + '</div>';
[191] Fix | Delete
// output += '<h1>' + this.stringbundle.GetStringFromName('docContents') + ':</h1>';.
[192] Fix | Delete
var output = '<div id="error">Error parsing JSON: ' + error.message + '</div>';
[193] Fix | Delete
output += '<h1>' + error.stack + ':</h1>';
[194] Fix | Delete
output += '<div id="json">' + this.htmlEncode( data ) + '</div>';
[195] Fix | Delete
return this.toHTML( output, uri + ' - Error' );
[196] Fix | Delete
}, // Wrap the HTML fragment in a full document. Used by jsonToHTML and errorPage.
[197] Fix | Delete
toHTML: function( content ) {
[198] Fix | Delete
return content;
[199] Fix | Delete
}
[200] Fix | Delete
};
[201] Fix | Delete
// Sanitize & output -- all magic from JSONView Firefox.
[202] Fix | Delete
this.jsonFormatter = new JSONFormatter();
[203] Fix | Delete
// This regex attempts to match a JSONP structure:
[204] Fix | Delete
// * Any amount of whitespace (including unicode nonbreaking spaces) between the start of the file and the callback name.
[205] Fix | Delete
// * Callback name (any valid JavaScript function name according to ECMA-262 Edition 3 spec).
[206] Fix | Delete
// * Any amount of whitespace (including unicode nonbreaking spaces).
[207] Fix | Delete
// * Open parentheses.
[208] Fix | Delete
// * Any amount of whitespace (including unicode nonbreaking spaces).
[209] Fix | Delete
// * Either { or [, the only two valid characters to start a JSON string.
[210] Fix | Delete
// * Any character, any number of times.
[211] Fix | Delete
// * Either } or ], the only two valid closing characters of a JSON string.
[212] Fix | Delete
// * Any amount of whitespace (including unicode nonbreaking spaces).
[213] Fix | Delete
// * A closing parenthesis, an optional semicolon, and any amount of whitespace (including unicode nonbreaking spaces) until the end of the file.
[214] Fix | Delete
// This will miss anything that has comments, or more than one callback, or requires modification before use.
[215] Fix | Delete
var outputDoc = '';
[216] Fix | Delete
// text = text.match(jsonp_regex)[1]; .
[217] Fix | Delete
var cleanData = '', callback = '';
[218] Fix | Delete
var callback_results = jsonp_regex.exec( this.data );
[219] Fix | Delete
if ( callback_results && callback_results.length === 3 ) {
[220] Fix | Delete
if ( this.debug ) {
[221] Fix | Delete
console.log( 'THIS IS JSONp' );
[222] Fix | Delete
}
[223] Fix | Delete
callback = callback_results[1];
[224] Fix | Delete
cleanData = callback_results[2];
[225] Fix | Delete
} else {
[226] Fix | Delete
if ( this.debug ) {
[227] Fix | Delete
console.log( 'Vanilla JSON' );
[228] Fix | Delete
}
[229] Fix | Delete
cleanData = this.data;
[230] Fix | Delete
}
[231] Fix | Delete
if ( this.debug ) {
[232] Fix | Delete
console.log( cleanData );
[233] Fix | Delete
}
[234] Fix | Delete
// Covert, and catch exceptions on failure.
[235] Fix | Delete
try {
[236] Fix | Delete
// var jsonObj = this.nativeJSON.decode(cleanData); .
[237] Fix | Delete
var jsonObj = JSON.parse( cleanData );
[238] Fix | Delete
if ( jsonObj ) {
[239] Fix | Delete
outputDoc = this.jsonFormatter.jsonToHTML( jsonObj, callback );
[240] Fix | Delete
} else {
[241] Fix | Delete
throw 'There was no object!';
[242] Fix | Delete
}
[243] Fix | Delete
} catch ( e ) {
[244] Fix | Delete
if ( this.debug ) {
[245] Fix | Delete
console.log( e );
[246] Fix | Delete
}
[247] Fix | Delete
outputDoc = this.jsonFormatter.errorPage( e, this.data );
[248] Fix | Delete
}
[249] Fix | Delete
var links = '<style type="text/css">.jsonViewOutput .prop{font-weight:700;}.jsonViewOutput .null{color:red;}.jsonViewOutput .string{color:green;}.jsonViewOutput .collapser{position:absolute;left:-1em;cursor:pointer;}.jsonViewOutput li{position:relative;}.jsonViewOutput li:after{content:\',\';}.jsonViewOutput li:last-child:after{content:\'\';}.jsonViewOutput #error{-moz-border-radius:8px;border:1px solid #970000;background-color:#F7E8E8;margin:.5em;padding:.5em;}.jsonViewOutput .errormessage{font-family:monospace;}.jsonViewOutput #json{font-family:monospace;font-size:1.1em;}.jsonViewOutput ul{list-style:none;margin:0 0 0 2em;padding:0;}.jsonViewOutput h1{font-size:1.2em;}.jsonViewOutput .callback + #json{padding-left:1em;}.jsonViewOutput .callback{font-family:monospace;color:#A52A2A;}.jsonViewOutput .bool,.jsonViewOutput .num{color:blue;}</style>';
[250] Fix | Delete
if ( this.targetType !== undefined ) {
[251] Fix | Delete
this.idType = this.targetType;
[252] Fix | Delete
this.id = this.target;
[253] Fix | Delete
}
[254] Fix | Delete
var el;
[255] Fix | Delete
if ( this.idType === 'class' ) {
[256] Fix | Delete
el = document.getElementsByClassName( this.id );
[257] Fix | Delete
if ( el ) {
[258] Fix | Delete
el.className += el.className ? ' jsonViewOutput' : 'jsonViewOutput';
[259] Fix | Delete
el.innerHTML = links + outputDoc;
[260] Fix | Delete
}
[261] Fix | Delete
} else if ( this.idType === 'id' ) {
[262] Fix | Delete
el = document.getElementById( this.id );
[263] Fix | Delete
if ( el ) {
[264] Fix | Delete
el.className += el.className ? ' jsonViewOutput' : 'jsonViewOutput';
[265] Fix | Delete
el.innerHTML = links + outputDoc;
[266] Fix | Delete
}
[267] Fix | Delete
el.innerHTML = links + outputDoc;
[268] Fix | Delete
}
[269] Fix | Delete
var items = document.getElementsByClassName( 'collapsible' );
[270] Fix | Delete
var len = items.length;
[271] Fix | Delete
[272] Fix | Delete
for ( var i = 0; i < len; i ++ ) {
[273] Fix | Delete
addCollapser( items[i].parentNode );
[274] Fix | Delete
}
[275] Fix | Delete
} else {
[276] Fix | Delete
// console.log("JSONView: this is not json, not formatting."); .
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function