Skip to content

Commit 964e685

Browse files
darbicusPomax
authored andcommitted
- adding print and println
- point to the new print and println - firefox and chrome now display correctly - rebase and fixes for new build system
1 parent c670285 commit 964e685

File tree

8 files changed

+613
-451
lines changed

8 files changed

+613
-451
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Processing.js",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"main": "processing.js",
55
"ignore": [
66
"bundle",

lib/Browser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = (function fakeBrowser() {
1818
return {
1919
localName: tag,
2020
style: {},
21-
setAttribute: __empty_func__
21+
setAttribute: __empty_func__,
22+
appendChild: __empty_func__
2223
};
2324
};
2425

@@ -138,6 +139,9 @@ module.exports = (function fakeBrowser() {
138139
cursor: {}
139140
}
140141
},
142+
querySelector: function(selector) {
143+
return createElement(selector);
144+
},
141145
defaultView: {
142146
getComputedStyle: function() {
143147
return { getPropertyValue: function() { return ""; } };

processing.js

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ window.Processing = require('./src/')(Browser);
2525
},{"./src/":27}],2:[function(require,module,exports){
2626
module.exports={
2727
"name": "Processing.js",
28-
"version": "1.4.5",
28+
"version": "1.4.6",
2929
"dependencies": {
3030
"argv": "~0.0.2",
3131
"browserify": "~2.18.1",
@@ -7652,6 +7652,8 @@ module.exports = function setupParser(Processing, options) {
76527652
var defaultScope = options.defaultScope,
76537653
PConstants = defaultScope.PConstants,
76547654
aFunctions = options.aFunctions,
7655+
Browser = options.Browser,
7656+
document = Browser.document,
76557657
undef;
76567658

76577659
// Processing global methods and constants for the parser
@@ -9378,6 +9380,90 @@ module.exports = function setupParser(Processing, options) {
93789380
return sketch;
93799381
};
93809382

9383+
// the logger for println()
9384+
var PjsConsole = function (document) {
9385+
var e = {}, added = false;
9386+
e.BufferMax = 200;
9387+
e.wrapper = document.createElement("div");
9388+
e.wrapper.setAttribute("style", "opacity:.75;display:block;position:fixed;bottom:0px;left:0px;right:0px;height:50px;background-color:#aaa");
9389+
e.dragger = document.createElement("div");
9390+
e.dragger.setAttribute("style", "display:block;border:3px black raised;cursor:n-resize;position:absolute;top:0px;left:0px;right:0px;height:5px;background-color:#333");
9391+
e.closer = document.createElement("div");
9392+
e.closer.onmouseover = function () {
9393+
e.closer.style.setProperty("background-color", "#ccc");
9394+
};
9395+
e.closer.onmouseout = function () {
9396+
e.closer.style.setProperty("background-color", "#ddd");
9397+
};
9398+
e.closer.innerHTML = "✖";
9399+
e.closer.setAttribute("style", "opacity:.5;display:block;border:3px black raised;position:absolute;top:10px;right:30px;height:20px;width:20px;background-color:#ddd;color:#000;line-height:20px;text-align:center;cursor:pointer;");
9400+
e.javaconsole = document.createElement("div");
9401+
e.javaconsole.setAttribute("style", "overflow-x: auto;display:block;position:absolute;left:10px;right:0px;bottom:5px;top:10px;overflow-y:scroll;height:40px;");
9402+
e.wrapper.appendChild(e.dragger);
9403+
e.wrapper.appendChild(e.javaconsole);
9404+
e.wrapper.appendChild(e.closer);
9405+
e.dragger.onmousedown = function (t) {
9406+
e.divheight = e.wrapper.style.height;
9407+
if (document.selection) document.selection.empty();
9408+
else window.getSelection().removeAllRanges();
9409+
var n = t.screenY;
9410+
window.onmousemove = function (t) {
9411+
e.wrapper.style.height = parseFloat(e.divheight) + (n - t.screenY) + "px";
9412+
e.javaconsole.style.height = parseFloat(e.divheight) + (n - t.screenY) - 10 + "px"
9413+
};
9414+
window.onmouseup = function (t) {
9415+
if (document.selection) document.selection.empty();
9416+
else window.getSelection().removeAllRanges();
9417+
e.wrapper.style.height = parseFloat(e.divheight) + (n - t.screenY) + "px";
9418+
e.javaconsole.style.height = parseFloat(e.divheight) + (n - t.screenY) - 10 + "px";
9419+
window.onmousemove = null;
9420+
window.onmouseup = null;
9421+
};
9422+
};
9423+
e.BufferArray = [];
9424+
e.print = e.log = function (t) {
9425+
// var oldheight = e.javaconsole.scrollHeight-e.javaconsole.scrollTop;
9426+
if (e.BufferArray[e.BufferArray.length - 1]) e.BufferArray[e.BufferArray.length - 1] += (t) + "";
9427+
else e.BufferArray.push(t);
9428+
e.javaconsole.innerHTML = e.BufferArray.join('');
9429+
if (e.wrapper.style.visibility === "hidden") {
9430+
e.wrapper.style.visibility = "visible";
9431+
}
9432+
//if (e.BufferArray.length > e.BufferMax) e.BufferArray.splice(0, 1);
9433+
//else e.javaconsole.scrollTop = oldheight;
9434+
if (e.wrapper.style.visibility === "hidden") {
9435+
e.wrapper.style.visibility = "visible"
9436+
}
9437+
};
9438+
e.println = function (t) {
9439+
if(!added) { document.body.appendChild(e.wrapper); }
9440+
e.print(t);
9441+
e.BufferArray.push('<br/>');
9442+
e.javaconsole.innerHTML = e.BufferArray.join('');
9443+
if (e.wrapper.style.visibility === "hidden") {
9444+
e.wrapper.style.visibility = "visible";
9445+
}
9446+
if (e.BufferArray.length > e.BufferMax) e.BufferArray.splice(0, 1);
9447+
else e.javaconsole.scrollTop = e.javaconsole.scrollHeight;
9448+
if (e.wrapper.style.visibility === "hidden") {
9449+
e.wrapper.style.visibility = "visible";
9450+
}
9451+
};
9452+
e.showconsole = function () {
9453+
e.wrapper.style.visibility = "visible";
9454+
};
9455+
e.hideconsole = function () {
9456+
e.wrapper.style.visibility = "hidden";
9457+
};
9458+
e.closer.onclick = function () {
9459+
e.hideconsole();
9460+
};
9461+
e.hideconsole();
9462+
return e;
9463+
};
9464+
9465+
Processing.logger = new PjsConsole(document);
9466+
93819467
// done
93829468
return Processing;
93839469
};
@@ -13903,18 +13989,7 @@ module.exports = function setupParser(Processing, options) {
1390313989
* @see #print
1390413990
*/
1390513991
p.println = function(message) {
13906-
var bufferLen = logBuffer.length;
13907-
var bufferMsg = "";
13908-
if (bufferLen) {
13909-
bufferMsg = logBuffer.join("");
13910-
logBuffer.length = 0; // clear log buffer
13911-
}
13912-
13913-
if (arguments.length === 0 && bufferLen === 0) {
13914-
Processing.logger.log(bufferMsg + "");
13915-
} else if (arguments.length !== 0) {
13916-
Processing.logger.log(bufferMsg + message);
13917-
}
13992+
Processing.logger.println(message);
1391813993
};
1391913994
/**
1392013995
* The print() function writes to the console area of the Processing environment.
@@ -13924,7 +13999,7 @@ module.exports = function setupParser(Processing, options) {
1392413999
* @see #join
1392514000
*/
1392614001
p.print = function(message) {
13927-
logBuffer.push(message);
14002+
Processing.logger.print(message);
1392814003
};
1392914004

1393014005
// Alphanumeric chars arguments automatically converted to numbers when
@@ -21481,7 +21556,7 @@ module.exports = function buildProcessingJS(Browser, testHarness) {
2148121556
}),
2148221557

2148321558
XMLElement = source.XMLElement({
21484-
Browser:Browser,
21559+
Browser: Browser,
2148521560
XMLAttribute: XMLAttribute
2148621561
}),
2148721562

@@ -21500,10 +21575,10 @@ module.exports = function buildProcessingJS(Browser, testHarness) {
2150021575
}),
2150121576

2150221577
PShapeSVG = source.PShapeSVG({
21503-
CommonFunctions:CommonFunctions,
21504-
PConstants:PConstants,
21505-
PShape:PShape,
21506-
XMLElement:XMLElement,
21578+
CommonFunctions: CommonFunctions,
21579+
PConstants: PConstants,
21580+
PShape: PShape,
21581+
XMLElement: XMLElement,
2150721582
colors: source.colors
2150821583
}),
2150921584

@@ -21521,14 +21596,15 @@ module.exports = function buildProcessingJS(Browser, testHarness) {
2152121596
}),
2152221597

2152321598
Processing = source.Processing({
21524-
defaultScope:defaultScope,
21525-
Browser:Browser,
21526-
extend:source.extend,
21527-
noop:noop
21599+
defaultScope: defaultScope,
21600+
Browser: Browser,
21601+
extend: source.extend,
21602+
noop: noop
2152821603
});
2152921604

2153021605
// set up the Processing syntax parser
2153121606
Processing = source.setupParser(Processing, {
21607+
Browser: Browser,
2153221608
aFunctions: testHarness,
2153321609
defaultScope: defaultScope
2153421610
});

0 commit comments

Comments
 (0)