How to catch mouse click on RichFaces notifyMessage element? - javascript

I have RichFaces notify message element like
<rich:notifyMessages sticky="true" showCloseButton="false"/>
I want to implement ability to close notification popup by mouse click. Of course I can use showCloseButton="true", but I think little cross in top right corner of popup is not so comfortable to use. Is there any way to catch mouse click event above notifyMessage element?
RichFaces version is 4.2.1.Final
Thanks.

Probably the easiest is this:
<rich:notifyMessages … onclick="$(this).find('.rf-ntf-cls').triggerHandler('click');"/>
RichFaces use the Pines notify plugin but the messages don't seem to support this "remote" closing directly.

User Makhiel was on the right way. Actually you should add click handler for div with class rf-ntf-cls, description of all used classes could be found here.
The main problem is that such popup elements could be added after page was ready, so you should add click handlers after popup was added.
In my case I called function
jQuery('.rf-ntf-cnt').click(function(){jQuery(this).css({visibility:'hidden'})})
in the end of the call which produced popup. I'm not a guru of js and I'm not sure that this is the best way for close popup, but I think that idea is clear.

Related

How can I stop the effects of the users clicks?

I am making a chrome extension to edit properties of images that are clicked on. I am using a package called element picker to select the images (this is triggered through an html button in a popup). The code works and I can change the properties of the image. However the package does not stop whatever action is linked to the image, which can often lead to the user being taken to a new page. How can I stop any of the actions of the users click between the time they press the button in the popup and they have selected an image?
Thank you in advance.
var elementPicker = require('element-picker')
function onClick(elt) {
[.....]
}
elementPicker.init({ onClick })
I don't usually recommend using this but CSS pointer-events can solve this problem. The idea is that any element with pointer-events:none will ignore any interactions. This works to block default HTML interactions like <a> or <button> as well as any javascript actions attached to the element.
This is the technique frequently used with a modal window to prevent clicks from going "through" the area around a modal. It should also work for what you described.
You could either set that style on the image element or on All Elements by using the * {styles...} selector. If you go the "all" route, you'll need to explicitly re-enable pointer-events on any elements in your extension interface that you still need actionable by using the 'auto' property.
Remember to reset pointer events when your extension is finished * {pointer-events: initial;} or you'll leave the page completely in-actionable.
If there is an Event object being passes through to the function then you could use the Event.preventDefault() function.
This function stops any default behavior and allows you to handle the event in your own manner.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

how to trigger the woocommerce product gallery lightbox to open using JS

I am trying bind a click listener to something which will open the woocommerce product gallery lightbox view.
Basically I want to re-create the functionality of the click on that little magnifying glass icon: (top right)
I am able to use jQuery to trigger the click event for that element...
$('body').on('click', '.myElems', function(){
$(".woocommerce-product-gallery__trigger").click();
});
... and this works well enough. But there's something unsettling about relying on the existence of this other element and then virtually clicking on it.
Is there a way to open the lightbox up with a function call?
--
My example uses jQuery for convenience since this is wordpress, but vanilla JS answers are fine.
After being stuck for a while with this issue.
I have found out that there is a click trigger with href = #tab-description , I think to open the product description.
So if you
jQuery("a:not('a[href$=\"tab-description\"]')").click(function (e) {
// Any Click event that is not tab-description
}
You can edit the selector inside the jQuery() to suit your use case. but this will need some more handling as it will be triggered on menu clicks, in this case you will have to handle more conditions you can use unload idn if you want your js to execute before leaving the page

Binding a popup to a control

I have a LeafletJS control that renders a button. I want the button, when clicked, to open a popup on its position. So far I've tried calling the .bindPopup method on the control itself, which WebStorm seems to approve of, but the browser tells me that this method doesn't exist. What would be the preferred way to accomplish this task?
Leaflet controls don't implement the .bindPopup function.
Instead, you might find some luck looking at how the layers control works, it collapses/expands based on mouse events. You could potentially do something similar with your control, and show/hide your popup based on the click event and toggling a display: none css property.

javascript how to determine what is cancelling an event

I have jquery, bootstrap included in a page I'm writing. It's a complex page. The problem I'm having is with Internet Explorer not seeing mousedown event. Chrome and FF both see the event just fine but not IE.
I wrote a test page with the event and it worked just fine in IE. So my question is...
Is there a way through the developer tools to determine what is cancelling an event?
I have a suspicion that one of the many .js files I've included is cancelling the mousedown event and IE isn't seeing it anymore. Chrome and FF does though. So I'm not 100% that it's being cancelled but it's my only guess I can come up with.
Code is really irrelevant since it's all of jquery and bootstrap. However, I am playing with divs that are draggable and resizeable. That's why I need to use jquery. The bootstrap is used because I also have a wysiwyg editor on the page.
Please don't recommend click. I need mousedown. When the mouse is down the border around the draggable and resizeable div turns red and I have some code that selects that div to capture top, left, width, and height as it's being moved and resized.
If click was selected as the event, the user would have to click the div box first then click and hold to move it. That's not a user friendly interface.
Any help is greatly appreciated.
What do you exactly mean as cancel, .preventDefault() or .stopPropagation? If we are talking about preventDefault - you should still be able to add event listener to parent container and then see your event object - it might have some data to traceback. Alternative would to override jQuery .on method and see who actually subscribes to the event.
After little more thinking - add another listener BEFORE the malicious one, to do that insert document-ready handler with event binding right after jquery loading code. In your new mousedown handler try to override problematic method of the event.
UPDATE:
you should try to check all events attached to your element one by one. To do that - check this post jQuery find events handlers registered with an object
In short - try using jQuery._data( elem, "events" ); to see attached event listeners and inspect their code in your code base. After you find the reason it will be much easier to reach the desired functionality. Before that it is just a guesswork.

Selenium click event does not trigger angularjs event

I have this page where an angularjs modal-content popup, in there i fill up some fields and click save. After save is initiated, popup should dissapear an event should happen and so on.
My selenium test does all that perfectly except that when it clicks on the save button, popup dissapears but no event is triggered or saved so when i open up the window again everything is empty. I've tried stuff that i know with selenium and it still doesn't work. Can anyone help me out here?
This is the save button:
<button class="save-button" data-ng-click="onSettingsSave()" ng-hide="readOnlyMode || !canSave()">Save</button>
Stuff i've tried:
var saveButton = driver.FindElement(By.CssSelector("button.save-button"));
saveButton.Click();
var saveButton = driver.FindElement(By.XPath(saveXpath));
saveButton.SendKeys(Keys.Enter);
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].focus();",saveButton);
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();",saveButton );
Try force clicking the element using pure JS:
driver.execute_script("arguments[0].click();", yourElement)
You can't use $ as a shortcut for document.querySelector in a script like that.
driver.ExecuteScript("document.querySelector('#base_element_id div input').click()");
Also this probably won't trigger an onClick in react / angular
Like the OP I have tried everything I can think of to get Selenium to trigger client side javascript events. I've seen some posts across the web of people having partial success where it randomly works; in my case it never works.
Selenium does successfully trigger the browsers primary click action, be it checking a checkbox or pressing a button, but it does not trigger any attached client side javascript events.
Both the native element.Click() method in selenium, and the abstracted ExecuteScript with arguments method of clicking as suggested by #csaladenes have the same result.
The only solution I have found so far is to use pure JS through that same ExecuteScript method; basically avoid the overload with params selenium can embed.
driver.ExecuteScript("$('#base_element_id div input').click()");
In my case I am using the JQuery that is already on my page to make locating the element easier, but any form of truly pure JS should do the same thing.
EDIT:
After some additional testing, it turns out that my "fix" really did nothing. However, performing the same click more than once did cause the client side events to fire.
In my case I am checking a checkbox, so I needed to perform the click 3 times to leave it in the correct state and still have the client side events run.
This is very odd, and definitely needs some more work to figure out where the issue is at that makes this necessary.
Edit 2:
I think I have finally found a solution, and at least partial answer, that does not make me cringe.
It seems as though Selenium has an issue where sometimes it "loses" the focus of the browser. Considering how consistent and repeatable my issue is I don't think focus is the only problem in my case, however the solution works pretty well.
I was able to get the immediate parent of my checkbox, which was a div element, click that first to return focus to the page, then click the checkbox. After that sequence of events the client side events worked correctly.

Categories