dom-events

AngularJS: Is ng-click “a good practice”? Why is there no ng-{event} in AngularJS?

╄→гoц情女王★ 提交于 2019-11-30 10:21:36
问题 I just started to learn AngularJS and struggle with some concepts of AngularJS. It would be great if somebody could explain me some points... I understand that ng-click is technically not the same as onclick (see here), but both are placed in the markup. I thought that would be a "bad practice"? Why is this one of the core concepts of AngularJS, if most people say this is "bad"? I thought it would be better to select the DOM element from JavaScript and not to place logic in the markup. If ng

How to get Property value from a Javascript object

僤鯓⒐⒋嵵緔 提交于 2019-11-30 10:14:33
I have a JavaScript object. var obj = { Id: "100", Name: "John", Address: {Id:1,Name:"Bangalore"} } var dataToRetrieve= "Name"; function GetPropertyValue(object,dataToRetrieve){ return obj[dataToRetrieve] } var retval = GetPropertyValue(obj,dataToRetrieve) This works fine. But if I try to get the value of property value of "Address.Name" , Like : var dataToRetrieve = "Address.Name"; it shows undefined . Note : The property variable is set by user from HTML And it can be changed according to user requirement(which property value he wants). What I want to achieve : 1) If dataToRetrieve = "Name"

How to generate a right-click event in all browsers

落花浮王杯 提交于 2019-11-30 08:50:39
问题 A little context: The app I'm working on has a right-click context menu for certain objects on the screen. The current design as that each of these objects listens for a right-click, sends an AJAX request to get the context data for that object, uses that data to create a PopupMenu2 from Dojo 0.4.3 (I know!), and then generates a right-click to launch the Dojo menu. I'm trying to figure out a way to generate a right-click event for all browsers. Currently, we only support IE and use the

Detect Whether an Event is Triggered by User and not programmatically

穿精又带淫゛_ 提交于 2019-11-30 08:25:19
问题 Well this question has been asked before but in context of jQuery. In jQuery we can check it by originalEvent property of event Object (link) which tells whether its a manual or programmed event . In my case I am using Javascript Event listeners and triggers . Can we differentiate between the two kind of events (programmed and manual) in this case? If not then any workarounds? My Listeners: function setUpListeners(){ _cellViewWrapper.addEventListener('mousedown',mouseDownHandler,false);

How can I generate a keyup event with a specific keycode in IE8?

走远了吗. 提交于 2019-11-30 07:32:42
问题 I need to generate keyup events in IE 8 using native DOM functions (no jQuery). The following code generates, fires, and receives the event, but the keyCode is always 0. How do I properly pass the keyCode? <form><input id="me" type="submit" /></form> <script type="text/javascript"> var me = document.getElementById("me"); me.attachEvent("onkeyup", function(e) { alert(e.keyCode); // => 0 }); document.getElementById("me").fireEvent('onkeyup', 13); </script> 回答1: Figured it out. The solution is

Using mobile events in Angular2

两盒软妹~` 提交于 2019-11-30 07:27:06
问题 I was wondering if I could get some help in regards to events for mobile devices. I was looking around for a way to bind functions to swipe events in Angular 2. I saw in this this issue on Github that mentions that Angular 2 uses Hammer.js for mobile event handling. I'm having some trouble getting the event to work because I get the following error: EXCEPTION: Hammer.js is not loaded, can not bind swipeleft event A snippet of my code is below: import {Component, View, AfterContentInit} from

Firing and capturing custom events

蓝咒 提交于 2019-11-30 05:02:35
Imagine this scenario (it's really just a scenario): I have a global counter that gets incremented on every mouse click. when I reach 50 clicks, I want to fire a custom event named 'reachedCount' I want to register my window object to capture that event with something like window.addEventListener('reachedCount', function(args){alert(args.count);}, false) So, my problems are that I don't know, and can't find anywhere how I can pass arguments to my eventHandler. Also, I had tried the method Rikudo posted, but it doesn't work in IE lt 9. Is this possible? How? Using Rikudo Sennin's answer, you

How to bind a handler to a selection change on window?

天大地大妈咪最大 提交于 2019-11-30 04:59:30
Basically I need to know when the window.getSelection() has changed and bind a handler to this event. Ideas? OBS: Please note that I'm not looking to bind a selection change on a INPUT or TEXTAREA. I'm talking about any selection in the window. 2019 update All major browsers now support the selectionchange event , which does the job. Firefox was the last browser to get it, and it has had it without a configuration flag since version 52 (released in March 2017). Original answer There is no cross-browser way of detecting changes to the selection. IE (since version 5.5, I think) and WebKit/Blink

Drag with mootools on mobile

白昼怎懂夜的黑 提交于 2019-11-30 03:51:33
问题 Is there a way to make to work the mootools class "Drag" on Safari mobile? Please don't link me to other frameworks. 回答1: Here was my solution to making Mootools Drag support touch events. This method didn't require me to edit the mootools more file since i used Class.refactor (This is only tested with Mootools v.1.3.1) -- it also does not break the usual click events Class.refactor(Drag, { attach: function(){ this.handles.addEvent('touchstart', this.bound.start); return this.previous.apply