read data from json file

This commit is contained in:
MathuraMG 2016-08-15 18:06:09 -04:00
parent 87de5a2188
commit 9c03efcef2
7 changed files with 57 additions and 18799 deletions

View file

@ -89,8 +89,6 @@ class Editor extends React.Component {
this._cm.setOption('mode', 'htmlmixed'); this._cm.setOption('mode', 'htmlmixed');
} }
} }
console.log('componentDidUpdate in editor');
} }
componentWillUnmount() { componentWillUnmount() {

View file

@ -128,12 +128,11 @@ class PreviewFrame extends React.Component {
}); });
if (this.props.textOutput || this.props.isTextOutputPlaying) { if (this.props.textOutput || this.props.isTextOutputPlaying) {
console.log(htmlFile);
const htmlHead = htmlFile.match(/(?:<head.*?>)([\s\S]*?)(?:<\/head>)/gmi); const htmlHead = htmlFile.match(/(?:<head.*?>)([\s\S]*?)(?:<\/head>)/gmi);
const headRegex = new RegExp('head', 'i'); const headRegex = new RegExp('head', 'i');
let htmlHeadContents = htmlHead[0].split(headRegex)[1]; let htmlHeadContents = htmlHead[0].split(headRegex)[1];
htmlHeadContents = htmlHeadContents.slice(1, htmlHeadContents.length - 2); htmlHeadContents = htmlHeadContents.slice(1, htmlHeadContents.length - 2);
htmlHeadContents += '<script src="/data.js"></script>\n'; htmlHeadContents += '<script src="/loadData.js"></script>\n';
htmlHeadContents += '<script src="/interceptor-functions.js"></script>\n'; htmlHeadContents += '<script src="/interceptor-functions.js"></script>\n';
htmlHeadContents += '<script src="/intercept-p5.js"></script>\n'; htmlHeadContents += '<script src="/intercept-p5.js"></script>\n';
htmlHeadContents += '<script type="text/javascript" src="http://chir.ag/projects/ntc/ntc.js"></script>'; htmlHeadContents += '<script type="text/javascript" src="http://chir.ag/projects/ntc/ntc.js"></script>';

View file

@ -1,4 +1,4 @@
import React, { PropTypes } from 'react'; import React from 'react';
class TextOutput extends React.Component { class TextOutput extends React.Component {
componentDidMount() { componentDidMount() {
@ -6,23 +6,39 @@ class TextOutput extends React.Component {
} }
render() { render() {
return ( return (
<div className="textoutput" id="canvas-sub" tabIndex="0" role="region"> <section
className="textoutput"
id="canvas-sub"
tabIndex="0"
role="main"
aria-label="text-output"
title="canvas text output"
>
<section id="textOutput-content"> <section id="textOutput-content">
</section> </section>
<div tabIndex="0" role="region" id="textOutput-content-summary"> <p
</div> tabIndex="0"
<div tabIndex="0" role="region" id="textOutput-content-details"> role="main"
</div> id="textOutput-content-summary"
<table id="textOutput-content-table"> aria-label="text output summary"
>
</p>
<p
tabIndex="0"
role="main"
id="textOutput-content-details"
aria-label="text output summary details"
>
</p>
<table
id="textOutput-content-table"
summary="text output object details"
title="output details"
>
</table> </table>
</div> </section>
); );
} }
} }
// TextOutput.propTypes = {
// lintMessages: PropTypes.array.isRequired,
// lineNo: PropTypes.string.isRequired,
// };
export default TextOutput; export default TextOutput;

View file

@ -204,6 +204,7 @@ class IDEView extends React.Component {
<div> <div>
<div className="preview-frame-overlay" ref="overlay"> <div className="preview-frame-overlay" ref="overlay">
</div> </div>
<div>
{(() => { {(() => {
if (this.props.preferences.textOutput || this.props.ide.isTextOutputPlaying) { if (this.props.preferences.textOutput || this.props.ide.isTextOutputPlaying) {
return ( return (
@ -212,6 +213,7 @@ class IDEView extends React.Component {
} }
return ''; return '';
})()} })()}
</div>
<PreviewFrame <PreviewFrame
htmlFile={this.props.htmlFile} htmlFile={this.props.htmlFile}
jsFiles={this.props.jsFiles} jsFiles={this.props.jsFiles}

File diff suppressed because it is too large Load diff

View file

@ -1,24 +1,27 @@
var textOutputElement; var textOutputElement;
var canvasLocation =''; var canvasLocation ='';
funcNames = refData["classitems"].map(function(x){ funcNames = allData["classitems"].map(function(x){
if(x["overloads"]) {
tempParam = x["overloads"][0]["params"];
} else {
tempParam = x["params"];
}
return { return {
name: x["name"], name: x["name"],
params: x["params"], params: tempParam,
class: x["class"], class: x["class"],
module: x["module"], module: x["module"],
submodule: x["submodule"] submodule: x["submodule"]
}; };
}); });
funcNames = funcNames.filter(function(x) { funcNames = funcNames.filter(function(x) {
var className = x["class"]; var className = x["class"];
return (x["name"] && x["params"] && (className==='p5')); return (x["name"] && x["params"] && (className==='p5'));
}) })
funcNames.forEach(function(x){ funcNames.forEach(function(x){
let document = parent.document; var document = parent.document;
var originalFunc = p5.prototype[x.name]; var originalFunc = p5.prototype[x.name];
p5.prototype[x.name] = function(){ p5.prototype[x.name] = function(){
orgArg = arguments; orgArg = arguments;

17
static/loadData.js Normal file
View file

@ -0,0 +1,17 @@
var allData;
function fetchJSONFile(path, callback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
var data = JSON.parse(httpRequest.responseText);
if (callback) callback(data);
}
}
};
httpRequest.open('GET', path,false);
httpRequest.send();
}
fetchJSONFile('https://rawgit.com/processing/p5.js-website/master/reference/data.json', function(data){
allData = data;
});