dom-events

Does a MutationOberserver callback fire within the same animation frame in which observed elements were modified? [closed]

喜夏-厌秋 提交于 2019-12-06 11:02:00
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last month . Suppose I make changes to an element inside a frame created with window.requestAnimationFrame and that the modified element is being observed by a MutationObserver . Does the MutationOberserver 's change handler fire within the same frame and before the browser does rendering that comes after the frame? (I can imagine that this may not be true with some polyfills. I'm curious to know if there's any guarantee that

Simple event system using JavaScript (ES5) - JS Custom Event

自作多情 提交于 2019-12-06 09:36:56
Instructions: make this code work without modifying snippet it in any way. Use only plain old JavaScript and no third-party libraries. Write new code that enables the code below to work properly. Hint: Feel free to extend native objects... even though it's typically a bad practice. // Start with an object, any object var myObject = {}; // Register an event on your object using // an `on` method myObject.on('myEvent', function(data) { // Log the data passed to the callback console.log(data); }); // Trigger the event using a `trigger` method. // Include some data when you trigger the event.

How to check if mouse click event is simulated or is native? (non-jQuery way)

℡╲_俬逩灬. 提交于 2019-12-06 09:01:21
问题 With jQuery it's easy. With pure JavaScript isn't, at least it isn't easy to find out how. if (event.clientX && event.clientY) { ... } gives kind-of detection, but it's not 100% accurate. 回答1: There is a way, but it's quite controversial IMHO. Try this: HTMLElement.prototype.dispatchEvent = (function(dispev) { return function(event) { // Do your stuff dispev.call(this, event); }; })(HTMLElement.prototype.dispatchEvent); With this, you're able to catch every call to dispatchEvent when a

React, ineffiencies of binding a new function for each event

一曲冷凌霜 提交于 2019-12-06 08:12:33
My friend and I are having an argument. In the interest of full disclosure, I'm the one who's a big fan of React and its benefits. In React components, when attaching a DOM event to each element in a list of elements, the traditional pattern is to bind() the generic click handler with the values you want to pass along to that function as parameters. As written below: <button onClick={this.onButtonClick.bind(this, buttonIndex)}></button> where buttonIndex is some value that changes as the list of buttons is iterated over. This pattern allows onButtonClick to be generic, and expect buttonIndex

Onsubmit event silently killed by onchange

给你一囗甜甜゛ 提交于 2019-12-06 07:53:35
问题 Onsubmit event can silently kill onchange event, if called simultaneously. I assume race condition in js engine. Tested in chrome, FF3, FF6 and IE9. To reproduce you need to change contents of input and click on submit button. Do not make any additional clicks between input change and submit button click. <div id="somediv"> <div>one</div> <div>two</div> </div> <form method="POST" id="someform"> <input type="text" name="input1" id="someinput" value="change me" /> <input type="submit" /> </form

JavaScript EventListener “pointerMove”: points per second

試著忘記壹切 提交于 2019-12-06 07:38:33
I have an element with a "pointerMove" EventListener added to it. Now when moving my mouse around, I can measure the number of data points "pointerMove" delivers per second (pps) by counting the total number of points drawn since "pointerDown" and dividing this by the time that passed since "pointerDown". So far, so good. What is strange though is the fact that I get a higher pps rate when the developer console is opened. Example: Pressing my mouse button and then moving the cursor around chaotically gives me about 60pps. But when opening the developer console and then doing exactly the same,

How to implement Chrome extension 's chrome.tabs.sendMessage API in Firefox addon

十年热恋 提交于 2019-12-06 06:29:28
问题 I'm working on a Firefox addon development with Addon-Builder. I have no idea about how to implement Chrome extension 's chrome.tabs.sendMessage API in Firefox addon. The code is like this (the code is in the background.js, something like main.js in the Firefox addon): function sendMessageToTabs(message, callbackFunc){ chrome.tabs.query({}, function(tabsArray){ for(var i=0; i<tabsArray.length; i++){ //console.log("Tab id: "+tabsArray[i].id); chrome.tabs.sendMessage(tabsArray[i].id,message

Click event on button is trigged when submitting a form with enter

淺唱寂寞╮ 提交于 2019-12-06 00:42:27
问题 I have a form with two buttons, one input[type=submit] and one plain button which is the cancel button. I have two event handlers, one bound to the form on submit and one bound to the button on click . When I submit the form by pressing enter in an input the click event on the button fires (and before the submit event I might add), why is this? This happens in both gecko and webkit. Here's a working example: http://jsfiddle.net/q3JPR/ If you submit by pressing enter I want the submit event to

Firefox extension is sending Javascript Array as an Object instead

若如初见. 提交于 2019-12-05 22:06:07
I have problem passing JavaScript arrays to an Add-On, which I'm writing in Add-on Builder . To communication I'm using events and sending an event with an array, but the Add-on (Content Script) gets an object, not an array. This is event: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script type=

Closure issue with Listener and Google Maps markers

北城以北 提交于 2019-12-05 21:58:26
I want to add a Listener event to each generated marker, so that when you click a marker you are redirected to the permalink url. With the code below the permalink value is the same for every marker(it get's the last value). I've read about closure problems and that seems to be what I'm having. I don't really get the examples I've looked at though. Can somebody take a look at my code and point me in the right direction? Any help is greatly appreciated! downloadUrl("http://localhost/map/generatexml.php", function(data) { var xml = parseXml(data); var markers = xml.documentElement