Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 19 additions & 12 deletions src/data/local_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,25 @@ import p5 from '../core/main';
* </code>
* </div>
*/
p5.prototype.storeItem = function(key, value) {
p5.prototype.storeItem = function (key, value) {
if (typeof key !== 'string') {
console.log(
`The argument that you passed to storeItem() - ${key} is not a string.`
p5._friendlyError(
`The argument that you passed to storeItem() - ${key} is not a string.`,
'storeItem'
);
}
if (key.endsWith('p5TypeID')) {
console.log(
`The argument that you passed to storeItem() - ${key} must not end with 'p5TypeID'.`
p5._friendlyError(
`The argument that you passed to storeItem() - ${key} must not end with 'p5TypeID'.`,
'storeItem'
);
}

if (typeof value === 'undefined') {
console.log('You cannot store undefined variables using storeItem().');
p5._friendlyError(
'You cannot store undefined variables using storeItem().',
'storeItem'
);
}
let type = typeof value;
switch (type) {
Expand Down Expand Up @@ -276,12 +281,13 @@ p5.prototype.storeItem = function(key, value) {
* </code>
* </div>
*/
p5.prototype.getItem = function(key) {
p5.prototype.getItem = function (key) {
let value = localStorage.getItem(key);
const type = localStorage.getItem(`${key}p5TypeID`);
if (typeof type === 'undefined') {
console.log(
`Unable to determine type of item stored under ${key}in local storage. Did you save the item with something other than setItem()?`
p5._friendlyError(
`Unable to determine type of item stored under ${key} in local storage. Did you save the item with something other than setItem()?`,
'getItem'
);
} else if (value !== null) {
switch (type) {
Expand Down Expand Up @@ -442,10 +448,11 @@ p5.prototype.clearStorage = function () {
* </code>
* </div>
*/
p5.prototype.removeItem = function(key) {
p5.prototype.removeItem = function (key) {
if (typeof key !== 'string') {
console.log(
`The argument that you passed to removeItem() - ${key} is not a string.`
p5._friendlyError(
`The argument that you passed to removeItem() - ${key} is not a string.`,
'removeItem'
);
}
localStorage.removeItem(key);
Expand Down
30 changes: 23 additions & 7 deletions src/data/p5.TypedDict.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ p5.TypedDict = class TypedDict {
if (this.data.hasOwnProperty(key)) {
return this.data[key];
} else {
console.log(`${key} does not exist in this Dictionary`);
p5._friendlyError(
`${key} does not exist in this Dictionary`,
'p5.TypedDict.get'
);
}
}

Expand All @@ -191,7 +194,10 @@ p5.TypedDict = class TypedDict {
if (this._validate(value)) {
this.data[key] = value;
} else {
console.log('Those values dont work for this dictionary type.');
p5._friendlyError(
"Those values don't work for this dictionary type.",
'p5.TypedDict.set'
);
}
}

Expand Down Expand Up @@ -235,9 +241,10 @@ p5.TypedDict = class TypedDict {
} else if (typeof key !== 'undefined') {
this.set(key, value);
} else {
console.log(
p5._friendlyError(
'In order to create a new Dictionary entry you must pass ' +
'an object or a key, value pair'
'an object or a key, value pair',
'p5.TypedDict.create'
);
}
}
Expand Down Expand Up @@ -459,7 +466,10 @@ p5.NumberDict = class NumberDict extends p5.TypedDict {
if (this.data.hasOwnProperty(key)) {
this.data[key] += amount;
} else {
console.log(`The key - ${key} does not exist in this dictionary.`);
p5._friendlyError(
`The key - ${key} does not exist in this dictionary.`,
'p5.NumberDict.add'
);
}
}

Expand Down Expand Up @@ -509,7 +519,10 @@ p5.NumberDict = class NumberDict extends p5.TypedDict {
if (this.data.hasOwnProperty(key)) {
this.data[key] *= amount;
} else {
console.log(`The key - ${key} does not exist in this dictionary.`);
p5._friendlyError(
`The key - ${key} does not exist in this dictionary.`,
'p5.NumberDict.mult'
);
}
}

Expand All @@ -536,7 +549,10 @@ p5.NumberDict = class NumberDict extends p5.TypedDict {
if (this.data.hasOwnProperty(key)) {
this.data[key] /= amount;
} else {
console.log(`The key - ${key} does not exist in this dictionary.`);
p5._friendlyError(
`The key - ${key} does not exist in this dictionary.`,
'p5.NumberDict.div'
);
}
}

Expand Down
49 changes: 26 additions & 23 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ p5.prototype._wrapElement = function (elt) {
const children = Array.prototype.slice.call(elt.children);
if (elt.tagName === 'INPUT' && elt.type === 'checkbox') {
let converted = new p5.Element(elt, this);
converted.checked = function(...args) {
converted.checked = function (...args) {
if (args.length === 0) {
return this.elt.checked;
} else if (args[0]) {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ p5.prototype.createButton = function (label, value) {
* </code>
* </div>
*/
p5.prototype.createCheckbox = function(...args) {
p5.prototype.createCheckbox = function (...args) {
p5._validateParameters('createCheckbox', args);

// Create a container element
Expand All @@ -1121,7 +1121,7 @@ p5.prototype.createCheckbox = function(...args) {
//checkbox must be wrapped in p5.Element before label so that label appears after
const self = addElement(elt, this);

self.checked = function(...args) {
self.checked = function (...args) {
const cb = self.elt.firstElementChild.getElementsByTagName('input')[0];
if (cb) {
if (args.length === 0) {
Expand Down Expand Up @@ -1328,7 +1328,7 @@ p5.prototype.createCheckbox = function(...args) {
* @return {p5.Element}
*/

p5.prototype.createSelect = function(...args) {
p5.prototype.createSelect = function (...args) {
p5._validateParameters('createSelect', args);
let self;
let arg = args[0];
Expand Down Expand Up @@ -1597,7 +1597,7 @@ p5.prototype.createSelect = function(...args) {

//counter for unique names on radio button
let counter = 0;
p5.prototype.createRadio = function(...args) {
p5.prototype.createRadio = function (...args) {
// Creates a div, adds each option as an individual input inside it.
// If already given with a containerEl, will search for all input[radio]
// it, create a p5.Element out of it, add options to it and return the p5.Element.
Expand Down Expand Up @@ -2052,8 +2052,9 @@ p5.prototype.createFileInput = function (callback, multiple = false) {

// If File API's are not supported, throw Error
if (!(window.File && window.FileReader && window.FileList && window.Blob)) {
console.log(
'The File APIs are not fully supported in this browser. Cannot create element.'
p5._friendlyError(
'The File APIs are not fully supported in this browser. Cannot create element.',
'createFileInput'
);
return;
}
Expand Down Expand Up @@ -2412,7 +2413,7 @@ if (navigator.mediaDevices.getUserMedia === undefined) {
* </code>
* </div>
*/
p5.prototype.createCapture = function(...args) {
p5.prototype.createCapture = function (...args) {
p5._validateParameters('createCapture', args);

// return if getUserMedia is not supported by the browser
Expand Down Expand Up @@ -2454,7 +2455,7 @@ p5.prototype.createCapture = function(...args) {
domElement.src = window.URL.createObjectURL(stream);
}
}
catch(err) {
catch (err) {
domElement.src = stream;
}
}).catch(e => {
Expand Down Expand Up @@ -2485,7 +2486,7 @@ p5.prototype.createCapture = function(...args) {

if (callback) callback(domElement.srcObject);
});
videoEl.flipped=flipped;
videoEl.flipped = flipped;
return videoEl;
};

Expand Down Expand Up @@ -2965,7 +2966,7 @@ p5.Element.prototype.center = function (align) {
* @param {boolean} [append] whether to append HTML to existing
* @chainable
*/
p5.Element.prototype.html = function(...args) {
p5.Element.prototype.html = function (...args) {
if (args.length === 0) {
return this.elt.innerHTML;
} else if (args[1]) {
Expand Down Expand Up @@ -3035,7 +3036,7 @@ p5.Element.prototype.html = function(...args) {
* @param {String} [positionType] it can be static, fixed, relative, sticky, initial or inherit (optional)
* @chainable
*/
p5.Element.prototype.position = function(...args) {
p5.Element.prototype.position = function (...args) {
if (args.length === 0) {
return { x: this.elt.offsetLeft, y: this.elt.offsetTop };
} else {
Expand All @@ -3060,7 +3061,7 @@ p5.Element.prototype.position = function(...args) {
};

/* Helper method called by p5.Element.style() */
p5.Element.prototype._translate = function(...args) {
p5.Element.prototype._translate = function (...args) {
this.elt.style.position = 'absolute';
// save out initial non-translate transform styling
let transform = '';
Expand Down Expand Up @@ -3092,7 +3093,7 @@ p5.Element.prototype._translate = function(...args) {
};

/* Helper method called by p5.Element.style() */
p5.Element.prototype._rotate = function(...args) {
p5.Element.prototype._rotate = function (...args) {
// save out initial non-rotate transform styling
let transform = '';
if (this.elt.style.transform) {
Expand Down Expand Up @@ -3479,7 +3480,7 @@ p5.Element.prototype.removeAttribute = function (attr) {
* @param {String|Number} value
* @chainable
*/
p5.Element.prototype.value = function(...args) {
p5.Element.prototype.value = function (...args) {
if (args.length > 0) {
this.elt.value = args[0];
return this;
Expand Down Expand Up @@ -3936,7 +3937,10 @@ p5.Element.prototype.drop = function (callback, fxn) {
this
);
} else {
console.log('The File APIs are not fully supported in this browser.');
p5._friendlyError(
'The File APIs are not fully supported in this browser.',
'drop'
);
}

return this;
Expand Down Expand Up @@ -4022,10 +4026,10 @@ p5.Element.prototype.draggable = function (elmMove) {
closeDragElementEvt = isTouch ? 'touchend' : 'mouseup',
elementDragEvt = isTouch ? 'touchmove' : 'mousemove';

if(elmMove === undefined){
if (elmMove === undefined) {
elmMove = this.elt;
elmDrag = elmMove;
}else if(elmMove !== this.elt && elmMove.elt !== this.elt){
} else if (elmMove !== this.elt && elmMove.elt !== this.elt) {
elmMove = elmMove.elt;
elmDrag = this.elt;
}
Expand All @@ -4036,11 +4040,11 @@ p5.Element.prototype.draggable = function (elmMove) {
function dragMouseDown(e) {
e = e || window.event;

if(isTouch){
if (isTouch) {
const touches = e.changedTouches;
px = parseInt(touches[0].clientX);
py = parseInt(touches[0].clientY);
}else{
} else {
px = parseInt(e.clientX);
py = parseInt(e.clientY);
}
Expand All @@ -4053,13 +4057,13 @@ p5.Element.prototype.draggable = function (elmMove) {
function elementDrag(e) {
e = e || window.event;

if(isTouch){
if (isTouch) {
const touches = e.changedTouches;
x = px - parseInt(touches[0].clientX);
y = py - parseInt(touches[0].clientY);
px = parseInt(touches[0].clientX);
py = parseInt(touches[0].clientY);
}else{
} else {
x = px - parseInt(e.clientX);
y = py - parseInt(e.clientY);
px = parseInt(e.clientX);
Expand Down Expand Up @@ -5386,7 +5390,6 @@ class MediaElement extends p5.Element {
removeCue(id) {
for (let i = 0; i < this._cues.length; i++) {
if (this._cues[i].id === id) {
console.log(id);
this._cues.splice(i, 1);
}
}
Expand Down
Loading