copy over events
See original GitHub issueWhenever we morph elements we should probs be copying over the events. From yo-yo:
// update-events.js
module.exports = [
// attribute events (can be set with attributes)
'onclick',
'ondblclick',
'onmousedown',
'onmouseup',
'onmouseover',
'onmousemove',
'onmouseout',
'ondragstart',
'ondrag',
'ondragenter',
'ondragleave',
'ondragover',
'ondrop',
'ondragend',
'onkeydown',
'onkeypress',
'onkeyup',
'onunload',
'onabort',
'onerror',
'onresize',
'onscroll',
'onselect',
'onchange',
'onsubmit',
'onreset',
'onfocus',
'onblur',
'oninput',
// other common events
'oncontextmenu',
'onfocusin',
'onfocusout'
]
// copy.js
function copier (f, t) {
// copy events:
var events = opts.events || defaultEvents
for (var i = 0; i < events.length; i++) {
var ev = events[i]
if (t[ev]) { // if new element has a whitelisted attribute
f[ev] = t[ev] // update existing element
} else if (f[ev]) { // if existing element has it and new one doesnt
f[ev] = undefined // remove it from existing element
}
}
// copy values for form elements
if ((f.nodeName === 'INPUT' && f.type !== 'file') || f.nodeName === 'TEXTAREA' || f.nodeName === 'SELECT') {
if (t.getAttribute('value') === null) t.value = f.value
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to Automatically Copy Events From One Google ... - Zapier
Google makes it easy to share an entire calendar, but there's no obvious way to copy all your events from one calendar to...
Read more >How to Copy or Import Google Calendars - Lifewire
To copy single events: Select event > pencil icon > More Actions in upper-right corner > Copy to. This article explains how to...
Read more >How to Copy Events in Outlook Calendar
1. Launch Outlook and click the “Calendar” link at the bottom of the screen. · 2. Scroll to the date of the event...
Read more >Element: copy event - Web APIs | MDN
The copy event fires when the user initiates a copy action through the browser's user interface. The event's default action is to copy...
Read more >How to move, copy or duplicate Calendar events to another ...
Copy events to another calendar on Mac · 1) Either right-click on the event or click Edit from the menu bar and pick...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@kristoferjoseph looping should be rare tho; if we implement
morphdom
’s.isSameNode()
trick then only the hot path will ever be looped for equal nodes only which even pessimistically isn’t that many nodes.Optimistically it should be fine I think; doing the existing approach of
yo-yo
we’re already miles ahead of every rendering engine in terms of perf so I’m not too worried for real world perf, even though from a purist standpoint I wholly agree with what you’re saying - maybe mark it as something to revisit later?Looks like you can copy over only the events being used by an element, but it requires looping over the elements keys. That may be faster than iterating over a longer list of event types, but I am not sure. https://github.com/kristoferjoseph/nanomorph/blob/master/morph.js#L16