How to add a event handler to catch leaflet contextmenu events? - events

I create a context menu like this:
var map = L.map('map', {
minZoom: 2,
maxZoom: 15,
gestureHandling: ControlGestual,
contextmenu: true,
contextmenuWidth: 300,
contextmenuItems: MenuContextual
});
but I also need some code to be executed when the context menu is closed(hidden). I see in the documentation that there is a contextmenu.hide event, but I don't know how to create a handler for this event.
I would appreciate your help. Many thanks in advance.

The event is fired on the map, so add:
map.on('contextmenu.hide', (e)=>{
console.log(e)
});

Related

CKEditor event on element

I'm writing my plugin and I am trying to set an event to an element, that I'll add to the editor. The event should act on the key enter.
Unfortunately, when I try to catch a 'key' or 'keydown' event nothing happens, but if I set 'click' event it's working great.
var element = editor.document.createElement('div');
element.setAttribute('data-type', 'example');
element.on('click', function() {
alert("Hi");
});
editor.insertElement(element);
Can someone help a noob like me ? :D
Thanks
You can only listen to keyboard events in editing hosts (focusable elements). So just add your listener to editable element, e.g.
editor.editable().on( 'keyup', function( evt ) { console.log( 'keyup' ); } );

Click event on view not firing in Titanium Appcelerator

In my controller, I populate a TableView with rows dynamically by building up an array of TableViewRow and populating it with a View & Image.
Here's the code that creates the View & ImageView and a click event on the view:
// Create product image view
var productImageView = Titanium.UI.createView({
borderRadius: 5,
left: 10,
top: 10,
bottom: 10,
width: 130,
backgroundColor: '#FFFFFF',
productName: Name,
imageUrl: ThumbnailUrl,
});
productImageView.add(Titanium.UI.createImageView({
backgroundColor: '#FFFFFF',
defaultImage: 'image-missing',
image: ThumbnailUrl
}));
productImageView.addEventListener('click', function(e) {
if (e.source.productName && e.source.imageUrl) {
Alloy.createController('view_product_image', { ProductName: e.source.productName, ImageUrl: e.source.imageUrl }).getView().open({
modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_COVER_VERTICAL,
modalStyle: Ti.UI.iPhone.MODAL_PRESENTATION_FORMSHEET
});
} else {
console.log('data not set');
}
});
When this code runs, within the table row, I can see the image. When I click it, nothing happens. I tried attaching the click event on the ImageView directly also but still nothing happens.
Any ideas why the click event is not getting fired? Should I be subscribing to a different event instead?
You are not receiving click event because your event source is imageview and it has no productName and imageUrl property.
To receive click event of view, you need to set touchEnabled property to false of your image view.
productImageView.add(Titanium.UI.createImageView({
backgroundColor: '#FFFFFF',
defaultImage: 'image-missing',
image: ThumbnailUrl,
touchEnabled :false
}));
however I think instead of adding a listener to each view you can add a common Listener to tableView and handle the event based on e.source.productName property as suggested by others.
I tried your code and it works for me on iOS and Android.
Maybe, can you show the TableView creation?
However, although your solution is correct, it is preferable and more efficient to add a event listener at your TableView not inside a TableViewRow due the number of listeners that will be created, then to reduce the scope of your click event only to the image, You check if the e.source has the productName and imageURL properties (e.g), otherwise you can infer that the click was outside the image.
Try like this:
$.tableView.addEventListener('click', function(e) {
if (e.source.productName && e.source.imageUrl)
console.log('hit')
});

Marionette composite View appendHtml not triggered

Consider the following Marionette composite View. Does anyone know wy appendHtml event does Not fire:
var TreeView = Backbone.Marionette.CompositeView.extend({
template: "#node-template",
tagName: "ul",
initialize: function(){
this.collection = this.model.nodes;
},
appendHtml: function(collectionView, itemView){
alert('appendHtml triggered');
collectionView.$("li:first").append(itemView.el);
}
});
look at the alert('appendHtml triggered'); Why does it not fire?
Has that been removed?
Look at the docs. Depending on the version of Marionette you are using. Use attachHtml()

Adding Event Listeners to a class of XTemplate elements in a grid

I've a column of XTemplate cells in a Grid Panel. How do I add a click event/listener that applies to all cells on this particular column? What I've tried so far works but applies to ALL clicks on ANY cell in the grid. I can't seem to manipulate the delegate option to filter for a particular class of element.
My code so far:
columns:[
...
{
xtype: 'templatecolumn',
text: 'Approve2',
flex: 1,
dataIndex: 'Approved',
align: 'center',
sortable: false,
tpl: '<input type="checkbox" class="approveCheckbox" />'
},
...
],
initComponent: function () {
this.on('itemclick', this.storeCheckboxVal, this, { delegate: '.approveCheckbox' });
},
...
,
storeCheckboxVal: function (view, record, item, index, event) {
alert(record.data['ID']);
}
AFAIK, delegate works only if you assign handler to DOM Element (not Component). Try this code instead:
initComponent: function () {
this.mon(this.el, 'click', this.storeCheckboxVal, this, { delegate: '.approveCheckbox' });
},
You'll probably need to change your grid's selType to cellmodel. After that, you should be able to listen to the grid view's cellclick. This appears to be undocumented, but I found it using Ext.util.Obersvable.capture(Ext.getCmp('my-grid-id'), console.log) Which is an extremely useful trick to know.
Thanks for the replies all, however I've managed to solve my problem via this solution: Ext JS on click event

How to fire dragend event of a marker in google maps v3?

I want to fire dragend event of a marker in another event say click event on the map. how can I do that?
google.maps.event.addListener(map,'click',function(pt){
posSelectMarker.setPosition(pt.latLng);
//Here I want to fire dragend event.
});
Use event.trigger;
google.maps.event.trigger(markerObject, 'dragend', args);
This is a bit more complete:
theListener = google.maps.event.addListener(posSelectMarker,'dragend',function(event){
console.log(event.latLng);
});
Note that you can get at the object with the event param
Should be:
google.maps.event.addListener
instead of:
google.maps.event.trigger
Quick example:
google.maps.event.addListener(marker_var_name, 'dragend', function(){
alert('drag ended')
});
If you have the marker object, you could call addListener directly to add a dragend event.
var marker = new google.maps.Marker({
...
)};
marker.addListener('dragend', function() {
// do something
});

Resources