custom-events

Typescript: How to convert a string to a type

限于喜欢 提交于 2020-11-24 13:35:17
问题 I am creating a bunch of web components and each of them can emit custom events. As an example here are two simple examples: //MyButton emits 'myButtonPressed' and detail of this type: interface ButtonDetailType { id: string; } //MySlider emits 'mySliderChanging' and details of this type: interface SliderChangingDetailType { id: string; value: number; } emits 'mySliderChanged' and details of this type: interface SliderChangedDetailType { id: string; oldValue: number; newValue: number; } To

Typescript: How to convert a string to a type

☆樱花仙子☆ 提交于 2020-11-24 13:33:36
问题 I am creating a bunch of web components and each of them can emit custom events. As an example here are two simple examples: //MyButton emits 'myButtonPressed' and detail of this type: interface ButtonDetailType { id: string; } //MySlider emits 'mySliderChanging' and details of this type: interface SliderChangingDetailType { id: string; value: number; } emits 'mySliderChanged' and details of this type: interface SliderChangedDetailType { id: string; oldValue: number; newValue: number; } To

Typescript: How to convert a string to a type

北战南征 提交于 2020-11-24 13:31:28
问题 I am creating a bunch of web components and each of them can emit custom events. As an example here are two simple examples: //MyButton emits 'myButtonPressed' and detail of this type: interface ButtonDetailType { id: string; } //MySlider emits 'mySliderChanging' and details of this type: interface SliderChangingDetailType { id: string; value: number; } emits 'mySliderChanged' and details of this type: interface SliderChangedDetailType { id: string; oldValue: number; newValue: number; } To

Is it possible to re-create a “onClick event” using custom events in javascript?

痴心易碎 提交于 2020-01-06 22:00:50
问题 I'm trying to learn about custom events and I got curious. Could you create the onClick event verbatim but written in a Custom Event? ex. create an element: <h1 id="clicky">click here</h1> Create a custom event that is the same as click event? obj = document.getElementById('clicky'); obj.addEventListener("fakeClick", function(e) { console.log(e.detail) }); var event = new CustomEvent("fakeClick", { detail: { hazcheeseburger: true } }); obj.dispatchEvent(event); Heres a JSFiddle 回答1: it

HTML5 DragDrop dataTransfer.types not set after event.dataTransfer.setData(mimeType, angular.toJson(item)) in chrome

家住魔仙堡 提交于 2019-12-25 09:09:16
问题 I am using druska/native_js_drag_and_drop_helper.js to automate angular-drag-and-drop-lists Issue : Even after event.dataTransfer.setData(mimeType,angular.toJson(item)) dataTransfer.types is not set or probably not allowed to read in dragstart and drop event Observation : during manual drag drop dragstart event dataTransfer {dropEffect: "none", effectAllowed: "move", items: DataTransferItemList, types: Array(1), files: FileList} dropEffect:"move" effectAllowed:"move" files:FileList items

Problems with ASP.NET and custom events

最后都变了- 提交于 2019-12-25 02:43:01
问题 I have a problem when handling the ReceiveCompleted event of a MessageQueue in ASP.NET. It catches it successfully, but every changes applied to the Controls of the page have no effect. This is what I've got: .ASPX <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp

jquery custom events return value

倾然丶 夕夏残阳落幕 提交于 2019-12-24 08:48:54
问题 I am trying to learn more about jquery custom events so I have made this simple code to make tests: <!DOCTYPE html> <html> <head> <title>Jquery custom events</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> $(function(){ $('#link1').click(function(){ var that = $(this); $.ajax({ url: "http://localhost/jquery/index.html", beforeSend: function(event){ // if returned false, stops ajax request return that.trigger('ajax:beforesend',[{p1: '1'}

How to trigger custom event with jQuery?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 04:04:24
问题 I'm attaching a custom event handler to the body in jQuery's ready method. Afterwards I immediately trigger the custom event but nothing seems to happen. $(function(){ $("body").on("test", function(){ alert("test triggered"); } $("body").trigger("test"); } 回答1: Firstly you have a syntax error $(function(){ $("body").on("test", function(){ alert("test triggered"); }); < ---- Missing this $("body").trigger("test"); }); Secondly you cannot trigger the event from the console , as $(function() {})

Trigger event with parameters

a 夏天 提交于 2019-12-20 10:28:18
问题 This is pretty annoying. I want to just trigger an event in javascript. I need to pass the event object into the parameters as usual and an additional custom parameter. In jQuery, this would be super easy: $('#element').trigger('myevent', 'my_custom_parameter'); But I don't want to use this however. Every other question I have found relating to this has just suggested 'use jQuery!' It's for a plugin I'm developing and to require jQuery for one method is pretty silly. Can anyone point to a way

jQuery: How do I use event.preventDefault() with custom events?

你说的曾经没有我的故事 提交于 2019-12-20 09:15:05
问题 How can I know in my triggering code that preventDefault has been called? $(document).trigger('customEvent', params); if (/* ??? */) doDefaultActions(); 回答1: trigger() can also take an event object, so if you can create an event object, like so: var event = jQuery.Event("customEvent"); $(document).trigger(event); then you can check after the trigger to see if preventDefault() has been called like so: var prevented = event.isDefaultPrevented(); 回答2: If you're asking how to find out whether or