dom-events

Difference between Events and Functions?

时光怂恿深爱的人放手 提交于 2019-11-30 17:16:00
问题 I am new to Node, and I am struggling to understand the main difference between Events and Functions. Both need to be triggered, so why do we need an Event at all if we have to trigger it anyway? How is it different than having a Function triggered? Example code: var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('event1', function () { console.log('Event 1 executed.'); eventEmitter.emit('event2'); }); eventEmitter.on('event2', function() { console

How to get fullpath of dropped folder from file system

柔情痞子 提交于 2019-11-30 15:51:44
问题 I am trying to implement drag n drop in my application, which need the full path of folder being dropped. I have done something like this <html> <head> <style> #dropzone { height:200px; width: 200px; border: 10px dashed #0c0; background-color:cyan; } </style> </head> <body> <div id="dropzone" droppable="true" ondrop ="drop(event)" ondragenter="return false" ondragover="return false"> </div> <script type="text/javascript"> function drop(e) { e.stopPropagation(); e.preventDefault(); var length

Catch X-Frame-Options Error in javascript

拥有回忆 提交于 2019-11-30 15:07:50
问题 Is there any way to catch an error when loading an iframe from another domain. Here is an example in jsfiddle. http://jsfiddle.net/2Udzu/ . I need to show a message if I receive an error. Here is what I would like to do, but it doesn't work: $('iframe')[0].onerror = function(e) { alert('There was an error loading the iFrame'); } Anyone have any ideas? 回答1: The onerror is applicable only for script errors. Frame content error checking must be done using any other method. Here's one example.

Twitter bootstrap: modal fade

て烟熏妆下的殇ゞ 提交于 2019-11-30 15:07:42
问题 I have a problem with the twitter bootstrap modal... It works fine when I don't have the .fade class on my element. As soon as I add it, the modal does not show up. I tracked down the problem to this line, I think: doAnimate ? this.$backdrop.one(transitionEnd, callback) : callback() doAnimate is webkitTransitionEnd , it looks fine. But I think transitionEnd is never fired, because I try to log something in the callback, and it never gets logged. Any ideas? EDIT: some code The link: <a href="

How to assert a spy is invoked with event on click using jasmine?

不问归期 提交于 2019-11-30 14:47:27
问题 I'm writing a simple click handler and need the event passed in (like so) Thing = function($){ var MyObject = function(opts){ this.opts = opts; }; MyObject.prototype.createSomething = function(){ var that = this; $('#some_dom_element').live('click', function(e) { that.doStuff(e); }); }; MyObject.prototype.doStuff = function(e) { //do some javascript stuff ... e.preventDefault(); }; return MyObject; }(jQuery); Currently in my jasmine spec I've got something to spy on the function I expect gets

Emit event from Directive to Parent element

笑着哭i 提交于 2019-11-30 14:44:53
问题 I have an element in HTML template. I add a directive to it: <div myCustomDirective>HELLO</div> I want that whenever I hover over the div the text inside the div should be changed, but it needs to be done from Directive (mouseover) event. I don't know how to emit event from a Directive and capture inside a parent element. Any help is appreciated. This is angular2 project. 回答1: If myCustomDirective has an output @Output() someEvent:EventEmitter = new EventEmitter(); then you can use <div

Chrome - Break on attributes modification

随声附和 提交于 2019-11-30 13:41:37
I want to break when the class attribute is changed by a script. I tried it with "Break on: attribute modifications" but it doesn't break. Workaround The following code will only work if your browser supports MutationObserver . Open developer tools using F12 and execute the following code in the console: var Spy = /** @class */ (function () { function Spy() { } Spy.observe = function (targetNode) { Spy.observer.observe(targetNode, Spy.config); }; Spy.disconnect = function () { Spy.observer.disconnect(); }; Spy["break"] = function () { debugger; }; Spy.config = { attributes: true, childList:

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

跟風遠走 提交于 2019-11-30 13:03:39
问题 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. 回答1: 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

Emit event from Directive to Parent element

人盡茶涼 提交于 2019-11-30 11:33:58
I have an element in HTML template. I add a directive to it: <div myCustomDirective>HELLO</div> I want that whenever I hover over the div the text inside the div should be changed, but it needs to be done from Directive (mouseover) event. I don't know how to emit event from a Directive and capture inside a parent element. Any help is appreciated. This is angular2 project. If myCustomDirective has an output @Output() someEvent:EventEmitter = new EventEmitter(); then you can use <div myCustomDirective (someEvent)="callSomethingOnParent($event)">HELLO</div> I'd like to add to @GünterZöchbauer's

React onClick - pass event with parameter

╄→гoц情女王★ 提交于 2019-11-30 10:39:47
问题 Without Parameter function clickMe(e){ //e is the event } <button onClick={this.clickMe}></button> With Parameter function clickMe(parameter){ //how to get the "e" ? } <button onClick={() => this.clickMe(someparameter)}></button> I want to get the event . How can I get it? 回答1: Try this <button onClick={(e) => { this.clickMe(e, someParameter) }}>Click Me!</button> And in your function function clickMe(event, someParameter){ //do with event } 回答2: With the ES6, you can do in a shorter way like