Switch button using paper js not work - paperjs

I'm trying to make a simple image editor using canvas. My code is here http://jsfiddle.net/qrd3muyh/.
How to make the switch button to work? If I run it in my localhost, I got these error when clicking the button pencil : Uncaught TypeError: undefined is not a function
And when clicking the circle button : Uncaught ReferenceError: myCircle is not defined.
Why does it happen and any clue to solve it? Many thanks before..

The reason for this is because all PaperScript tags become a scoped object (referred to as a PaperScope). The reason you are getting the undefined error is because the jQuery callback function has no reference to myCircle, etc.
To resolve this, you should access the currently active paper scopes via the paper object.
$('#pencil').on('click', function(){
console.log(paper.tools); # See how many tools are in your paper object
paper.tools[1].activate(); # Activate one of them.
});
$('#circle').on('click', function(){
paper.tools[0].activate(); # Activate the other.
});
To get the currently active tool, you can do this:
$('#pencil').on('click', function(){
var current = paper.tool; # Access currently active tool.
current.remove(); # remove this tool
});
Here is some good reading about the PaperScopes.

Related

Uncaught TypeError: e.dispatchEvent is not a function Elementor Wordpress frontend.min.js

I am getting this error when trying to open Elementor with my custom theme meaning that Elementor page builder won't open. Has anyone come across this before?
Uncaught TypeError: e.dispatchEvent is not a function
at Function.dispatch (frontend.min.js?ver=3.6.5:2:34013)
at Frontend.init (frontend.min.js?ver=3.6.5:2:8627)
at Editor.initFrontend (editor.min.js?ver=3.6.5:2:322468)
at Editor.onPreviewLoaded (editor.min.js?ver=3.6.5:2:335102)
at Editor.onPreviewLoaded (editor.min.js?ver=3.6.5:2:344642)
at HTMLIFrameElement.dispatch (load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,moxiejs,plupload&ver=5.9.3:2:43064)
at HTMLIFrameElement.v.handle (load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils,moxiejs,plupload&ver=5.9.3:2:41048)
This is a jquery issue. I had the same error, it was because jquery was loaded twice, two versions. The one that was puzzling me was getting loaded by GTM, so I couldn't find it in the code.
Michael is right I had the same issue. But the jQuery was hidden in a .js file within the theme.
So just double check jQuery isn't being loaded twice within your themes .js files.
When I found the second copy and removed it, I was receiving an error regarding the "$ is not a function".
jQuery(function($) {
/* Rest of code in file goes here
});
If you are getting the element from a jquery function, you need to extract the raw DOM element first
var e = $("#item1");
var d = e[0];
d.dispatchEvent(new Event('change',{ 'bubbles': true }));

Selenium (RSelenium) giving StaleElementReference clicking an element just recently searched

I'm trying to get some Selenium tests against Shiny app that has some notifications. I have a following function I would call to close all notifications that are there, and the reference to the element is fetched just before the click is called.
close_notifications <- function() {
buttons <- remDr$findElements(using = "xpath", "//[#id='shiny-notification-panel']///div[contains(text(),'×')]")
close_function <- function(btn) {
btn$clickElement()
}
lapply(buttons, close_function)
}
However when there is a notifcation visible in the app and I try to call it, I'll get the following error regarding it.
Error: Test failed:
* Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
What might be the reason I'm getting this error, even when the reference is fetched just before trying to click the button? Notification duration itself is quite long so it doesn't disappear in the UI even when I get the StaleElementReference. I'm not sure if Shiny changes something under the hood so that it's not the same DOM element, however, I guess that shouldn't be the case when I'm trying to press the button just after looking it up with the Selenium driver.

Using `within` in custom helpers

I'm using CodeceptJS and I'm trying to write a custom helper that asserts an text and clicks "OK". This dialog pops up as a iframe modal to consent with cookies.
If I write following steps in my scenario
I.amOnPage('/some-path');
within({frame: '#iframeID'}, () => {
I.see('Headline text for dialog');
I.click('OK');
});
// ...
...my test seems to work just fine.
But when I make an custom helper out of that and configure it properly so I can use it:
const { Helper } = codeceptjs;
class CookieConsent extends Helper {
consentWithCookies() {
const { Puppeteer } = this.helpers;
within({frame: '#iframeID'}, () => {
Puppeteer.see('Headline text for dialog');
Puppeteer.click('OK');
});
}
}
module.exports = CookieConsent;
...and use it as a step:
I.amOnPage('/some-path');
I.consentWithCookies();
// ...
...it doesn't seem to work as the consent dialog doesn't get clicked away as it was when implementing this directly in the scenario. According to some console.log() debugging the within callback doesn't get called at all. Console doesn't throw any errors about undefined within or anything suspicious.
I suspect that using within in a custom helper isn't working or I'm doing something wrong that I can't figure out from the documentation.
This warning at documentation doesn't really clarify when within is being used incorrectly, and using await doesn't help the problem.
within can cause problems when used incorrectly. If you see a weird behavior of a test try to refactor it to not use within. It is recommended to keep within for simplest cases when possible. Since within returns a Promise, it may be necessary to await the result even when you're not intending to use the return value.
iFrames can be a pain to work without when it comes down to automation. There are a number of factors that can make an iFrame unreachable to a framework such as cross-domain iFrames, commonly used for increased security on the content served.
Now to fix your issue, all you have to do is use switchTo() - Docs in CodeceptJS which is a function available for all helpers made available. The order should be
I.switchTo('your iframe');
..... some actions here;
I.switchTo(); // You do this so that you get out of the iFrame context when done

White-Blank page on Wordpress - Uncaught TypeError: $(...).onePageNav is not a function

I have encountered a problem today out of the blue. My site wont load on Chrome(It loads on safari, explorer). It only loads a blank white page and after 3-4 minutes it MAY open the content. The URL is: https://premonition.ai/newsite/wordpress.
Checking on the console I got this message (only when the screen is white)
Uncaught TypeError: $(...).onePageNav is not a function
at VM1047 general.js?ver=4.7.1:92
at HTMLDocument.<anonymous> (VM1047 general.js?ver=4.7.1:97)
at i (jquery.js?ver=1.12.4:2)
at Object.add [as done] (jquery.js?ver=1.12.4:2)
at a.fn.init.n.fn.ready (jquery.js?ver=1.12.4:2)
at VM1047 general.js?ver=4.7.1:38
When I click in one of the sub-errors I get this https://snag.gy/NhoP05.jpg.
I thought the error was from a plugin (Page scroll to id), but I didn't find the onePageNav function anywhere on the files of the plugin.
Can I somehow delete the whole function? Can I overwrite it?
Thank you,
Tom
Seems like you have used One page Nav jquery. If you want to delete it, go to the js flie general.js and remove the onePageNav function. If you want to make it work then follow these points-
Check whether you have included the onePageNav jquery, if not
done, then please include it under your header file below the
wp_head() function.
Bind the onePageNav under this function-
$( document ).ready(function() {
//your function
}
Hope, this will help you.

Simple Button in javascript isn't working, tried hosts of things, not sure why

Now first, i'm not even sure if you can do this; but with my limited knowledge of functions, I wanted to create a button that will display both an object in the console and on the document. I figured, it would be easier to try to run in the console first but, I just keep getting an error: button help
So basically, can i run a simple function in both the console and in the document with simple button, and how would i tailor my code here to do that?
As the error says, it cannot find your function. Add this to your code:
<button onclick="window.displayState()">
And this in your js:
window.displayState = function() {
console.log("here");
};

Resources