-
Notifications
You must be signed in to change notification settings - Fork 8
Added on
argument with hover
and click
value.
#12
base: master
Are you sure you want to change the base?
Changes from 1 commit
642a03e
e103c84
ea80797
d64ccd4
732ee2c
25d46d5
bd01061
8a9c30a
532c08f
5c3cdfe
252f7b1
2212939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,9 @@ const createDropdown = (key, opts = {}) => { | |
x: 0, | ||
y: 0, | ||
top: 0, | ||
left: 0 | ||
left: 0, | ||
on: 'click', | ||
timeout: 0 | ||
}; | ||
|
||
const toIntOr = (val, org) => { | ||
|
@@ -179,8 +181,9 @@ const factory = () => { | |
const removeAll = () => | ||
allKeys().forEach(remove); | ||
|
||
const usePosition = (name, tmpl) => | ||
Tracker.afterFlush(positionDropdown(name, tmpl.find(DROPDOWN_TRIGGER))); | ||
const usePosition = (name, tmpl) => { | ||
Tracker.afterFlush(positionDropdown(name, tmpl)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch the whitespace here. |
||
} | ||
|
||
return { | ||
all, | ||
|
@@ -233,7 +236,9 @@ Template.dropdown.onCreated(function() { | |
'left', | ||
'direction', | ||
'persistent', | ||
'animation' | ||
'animation', | ||
'on', | ||
'timeout' | ||
); | ||
|
||
return Dropdowns.create(this.data.name, opts); | ||
|
@@ -278,6 +283,8 @@ Template.dropdown.helpers({ | |
attrs['data-dropdown-left'] = dropdown.left; | ||
attrs['data-dropdown-align'] = dropdown.align; | ||
attrs['data-dropdown-direction'] = dropdown.direction; | ||
attrs['data-dropdown-on'] = dropdown.on; | ||
attrs['data-dropdown-timeout'] = dropdown.timeout; | ||
return attrs; | ||
} | ||
|
||
|
@@ -315,8 +322,13 @@ const positionDropdown = (key, reference) => { | |
} | ||
|
||
const $dropdown = dropdown.element(); | ||
const $el = $(reference); | ||
|
||
|
||
if (typeof(reference) === 'object' && reference instanceof Blaze.TemplateInstance) | ||
var $el = $(reference.find('>')); | ||
else | ||
var $el = $(reference); | ||
|
||
|
||
if ($dropdown.length === 0) { | ||
console.error(`Dropdowns: Couldn't find a dropdown: ${key}`); | ||
return; | ||
|
@@ -376,12 +388,15 @@ const positionDropdown = (key, reference) => { | |
}; | ||
}; | ||
|
||
Dropdowns._timeout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually no need to define this here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrite it to? var timeout; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to declare it – you'll attach it further down, at this line anyway, and JS/Meteor doesn't care if the parameter passed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try. It does not work. |
||
|
||
Template.dropdownTrigger.events({ | ||
click(evt, tmpl) { | ||
if (tmpl.data.on && tmpl.data.on != 'click') return; | ||
if (tmpl.data.on && tmpl.data.on !== 'click') return; | ||
evt.preventDefault(); | ||
const name = tmpl.data.name; | ||
|
||
Meteor.clearTimeout(Dropdowns._timeout); | ||
Dropdowns.hideAllBut(name); | ||
Dropdowns.toggle(name); | ||
Dropdowns.usePosition(name, tmpl); | ||
|
@@ -391,6 +406,7 @@ Template.dropdownTrigger.events({ | |
evt.preventDefault(); | ||
const name = tmpl.data.name; | ||
|
||
Meteor.clearTimeout(Dropdowns._timeout); | ||
Dropdowns.hideAllBut(name); | ||
Dropdowns.show(name); | ||
Dropdowns.usePosition(name, tmpl); | ||
|
@@ -399,8 +415,20 @@ Template.dropdownTrigger.events({ | |
if (tmpl.data.on != 'hover') return; | ||
evt.preventDefault(); | ||
const name = tmpl.data.name; | ||
|
||
Dropdowns.hide(name); | ||
|
||
Meteor.clearTimeout(Dropdowns._timeout); | ||
Dropdowns._timeout = Meteor.setTimeout(() => { | ||
Dropdowns.hide(name); | ||
}, tmpl.data.timeout); | ||
|
||
Dropdowns.get(name).element().hover(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind the whitespace here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? Please example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reasoning for this whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block that starts with |
||
Meteor.clearTimeout(Dropdowns._timeout); | ||
}, function() { | ||
Meteor.clearTimeout(Dropdowns._timeout); | ||
Dropdowns._timeout = Meteor.setTimeout(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please stick to ES2015 arrow functions when possible, thanks :) |
||
Dropdowns.hide(name); | ||
}, tmpl.data.timeout); | ||
}) | ||
} | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an option for timeout really necessary to include in this package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What have you decided with options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to the dropdown, or remove from its default object and leave only in dropdownTrigger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't
timeout
be a hard coded constant somewhere, instead of an option?