LT-275: Making common animation labels act as normal labels when clicked
This commit is contained in:
parent
5a9379e6c3
commit
cc8f486204
@ -46,7 +46,6 @@ Package.onUse(function(api) {
|
|||||||
'styles/components/dialog.styl',
|
'styles/components/dialog.styl',
|
||||||
'styles/components/radio.styl',
|
'styles/components/radio.styl',
|
||||||
'styles/components/select2.styl',
|
'styles/components/select2.styl',
|
||||||
'styles/components/selectTree.styl',
|
|
||||||
'styles/components/states.styl'
|
'styles/components/states.styl'
|
||||||
], 'client');
|
], 'client');
|
||||||
|
|
||||||
|
|||||||
@ -177,7 +177,7 @@ Template.measureFlow.events({
|
|||||||
|
|
||||||
'click .select-tree-common label'(event, instance) {
|
'click .select-tree-common label'(event, instance) {
|
||||||
// Set the common section clicked flag
|
// Set the common section clicked flag
|
||||||
instance.commonClicked = true;
|
instance.commonClicked = event.currentTarget;
|
||||||
},
|
},
|
||||||
|
|
||||||
'change .select-tree-root'(event, instance) {
|
'change .select-tree-root'(event, instance) {
|
||||||
@ -193,39 +193,44 @@ Template.measureFlow.events({
|
|||||||
|
|
||||||
'click .tree-leaf input'(event, instance) {
|
'click .tree-leaf input'(event, instance) {
|
||||||
const $target = $(event.currentTarget);
|
const $target = $(event.currentTarget);
|
||||||
const $label = $target.closest('label');
|
let $label = $target.closest('label');
|
||||||
const $treeRoot = $label.closest('.select-tree-root');
|
const $treeRoot = $label.closest('.select-tree-root');
|
||||||
const $container = $treeRoot.find('.tree-options:first');
|
const $container = $treeRoot.find('.tree-options:first');
|
||||||
|
let labelOffset;
|
||||||
|
|
||||||
// Check if the targe click was a label inside common section
|
// Check if the clicked target was a label inside common section
|
||||||
if (instance.commonClicked) {
|
if (instance.commonClicked) {
|
||||||
const labelTop = $label.position().top;
|
$label = $(instance.commonClicked);
|
||||||
const containerCenter = Math.round($container.height() / 2);
|
labelOffset = $label.data('offset');
|
||||||
const labelCenter = Math.round($label.height() / 2);
|
} else {
|
||||||
|
labelOffset = $label.offset();
|
||||||
// Scroll the options container to make the target input visible
|
|
||||||
$container.scrollTop(labelTop - containerCenter + labelCenter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the measure flow state to selected
|
// Change the measure flow state to selected
|
||||||
instance.state.set('selected');
|
instance.state.set('selected');
|
||||||
|
|
||||||
// Get the clicked label window offset
|
|
||||||
const labelOffset = $label.offset();
|
|
||||||
|
|
||||||
// Wait for the DOM re-rendering
|
// Wait for the DOM re-rendering
|
||||||
Tracker.afterFlush(() => {
|
Tracker.afterFlush(() => {
|
||||||
// Get the measure flow div
|
// Get the measure flow div
|
||||||
const $measureFlow = instance.$('.measure-flow');
|
const $measureFlow = instance.$('.measure-flow');
|
||||||
|
|
||||||
// Subtract the label box shadow height from the label's position
|
// Adjust the label position
|
||||||
|
if (instance.commonClicked) {
|
||||||
labelOffset.top -= 10;
|
labelOffset.top -= 10;
|
||||||
|
labelOffset.left -= 12;
|
||||||
|
} else {
|
||||||
|
labelOffset.top -= 10;
|
||||||
|
}
|
||||||
|
|
||||||
// Reposition the measure flow based on the clicked label position
|
// Reposition the measure flow based on the clicked label position
|
||||||
$measureFlow.css(labelOffset);
|
$measureFlow.css(labelOffset);
|
||||||
|
|
||||||
// Resize the copied label with same width of the clicked one
|
// Resize the copied label with same width of the clicked one
|
||||||
$measureFlow.children('.tree-leaf').width($label.outerWidth());
|
// $measureFlow.children('.tree-leaf').width($label.outerWidth());
|
||||||
|
$measureFlow.children('.tree-leaf').width(212);
|
||||||
|
|
||||||
|
// Reset the flag to avoid wrong positioning when clicking normal labels again
|
||||||
|
instance.commonClicked = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait the fade-out transition and remove the selectTree component
|
// Wait the fade-out transition and remove the selectTree component
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import './mixin.js';
|
import './mixin.js';
|
||||||
|
|
||||||
import './selectTree.html';
|
import './selectTree.html';
|
||||||
|
import './selectTree.styl';
|
||||||
import './selectTree.js';
|
import './selectTree.js';
|
||||||
import './selectTreeCommon.html';
|
import './selectTreeCommon.html';
|
||||||
import './selectTreeCommon.js';
|
import './selectTreeCommon.js';
|
||||||
|
|||||||
@ -57,6 +57,11 @@ $gray6 = #303030
|
|||||||
&>.tree-inputs>label.tree-node:not(.active)
|
&>.tree-inputs>label.tree-node:not(.active)
|
||||||
border-color: transparent
|
border-color: transparent
|
||||||
|
|
||||||
|
&.common-clicked .tree-leaf.active
|
||||||
|
background-color: transparent
|
||||||
|
box-shadow: none
|
||||||
|
color: transparent
|
||||||
|
|
||||||
.select-tree-root
|
.select-tree-root
|
||||||
display: inline-block
|
display: inline-block
|
||||||
position: relative
|
position: relative
|
||||||
@ -194,6 +199,9 @@ $gray6 = #303030
|
|||||||
line-height: 20px
|
line-height: 20px
|
||||||
margin: 12px 0 16px
|
margin: 12px 0 16px
|
||||||
|
|
||||||
|
div.labels
|
||||||
|
position: relative
|
||||||
|
|
||||||
label
|
label
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
display: block
|
display: block
|
||||||
@ -2,9 +2,11 @@
|
|||||||
<div class="select-tree-common">
|
<div class="select-tree-common">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h5 class="title">Common</h5>
|
<h5 class="title">Common</h5>
|
||||||
|
<div class="labels">
|
||||||
{{#each item in items}}
|
{{#each item in items}}
|
||||||
<label for="{{this.storageKey}}_{{encodeId item.value}}">{{item.label}}</label>
|
<label for="{{this.storageKey}}_{{encodeId item.value}}">{{item.label}}</label>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -9,6 +9,9 @@ Template.selectTreeCommon.events({
|
|||||||
// Get the clicked label
|
// Get the clicked label
|
||||||
const $target = $(event.currentTarget);
|
const $target = $(event.currentTarget);
|
||||||
|
|
||||||
|
// Store the offset position for further use
|
||||||
|
$target.data('offset', $target.offset());
|
||||||
|
|
||||||
// Build the input selector based on the label target
|
// Build the input selector based on the label target
|
||||||
const inputSelector = '#' + $target.attr('for');
|
const inputSelector = '#' + $target.attr('for');
|
||||||
|
|
||||||
@ -23,6 +26,9 @@ Template.selectTreeCommon.events({
|
|||||||
// Wait for options rerendering
|
// Wait for options rerendering
|
||||||
|
|
||||||
Tracker.afterFlush(() => {
|
Tracker.afterFlush(() => {
|
||||||
|
const $treeRoot = treeInstance.$('.select-tree-root:first').first();
|
||||||
|
$treeRoot.addClass('common-clicked');
|
||||||
|
|
||||||
// Wait for components initialization
|
// Wait for components initialization
|
||||||
Meteor.defer(() => $(inputSelector).click());
|
Meteor.defer(() => $(inputSelector).click());
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user