Best way to set .focus() on an InputElement in my overlay/dialog Polymer element? - dart-polymer

I have a button that brings up a dialog overlay with a standard <input> in it. The dialog is a Polymer element. How do I set the focus of the element? I tried doing it in the toggleOverlay() method that opens the overlay, and in the attached() that I learned is actually called even before the overlay is open.
InputElement get subject => $['subject'];
subject.focus();
Where and how do I get this to work? Related to polymer focus() on <paper-input> or <core-input> element?

Related

Is there an HTML DOM equivalent to JqueryUI selectable?

Since there are HTML DOM attributes to make an element draggable, droppable and resizable, is there something like it for selectable?
I want to remove JQueryUI dependency (and not replace it with another library) since we don't use the widgets anymore, just the convenience methods for widget handling. When I keep selectable, widgets don't respond to the HMTL attribute settings (Jquery UI takes over drag/drop/resize).

Triggering events when clicking away from a focused Select2

I have a need to capture an event (like a click) on a object that is elsewhere on the page and not a child of the select2 object while the select2 object has focus and is showing results. When the select2 results object is focused, I cannot click on a button/anchor elsewhere on the page and have it perform its action. It merely closes the select2 object.
Is there a way to do this? Here is a demo that shows this behavior: http://codepen.io/anon/pen/JoJobW
<!-- Javascript snippet -->
$(document).ready(function() {
$("#e1").select2();
$("#e2").click(function(){
alert("click!");
e.preventDefault();
});
});
<!-- HTML snippet -->
<select id="e1"></select>
Click here when select2 is focused
Using select2 v3.5.2 and jQuery 1.11.0
Select2 places a "mask" element behind the drop-down that captures the mouse click. Others have complained about this.
Here is a jsfiddle that shows the mask element.
You could try to remove the mask element when the drop-down is opened.
$('#e1').select2().on('select2-open', function() {
$('.select2-drop-mask').remove();
});
Of course, this means the drop-down will not close when the user clicks off of it, but you could add an event handler on the document (or body) to do that.
$(document).click(function() {
$("#e1").select2('close');
});
You have to make sure the click event on the other element does not propagate to the document in that case.
$('#e2').click(function() {
alert('click!');
return false; // Prevent default action and stop propagation.
});
jsfiddle

Angular dart click event on <a> href that is wrapped in shadow dom is retargeted to wrapper

In Angular dart tutorial Chapter_06, the default router is based on hash. After change it to Html 5 push state, the route on edit button which is inside of view_recipe_component does not work.
After check a while, it turns out it is because, the link of edit button is inside of shadow dom, so the click event is retargeted to <view-recipe> element (the wrapper of shadow dom). Then the DefaultWindowClickHandler can't get desired element, therefore it does not fall into router's control.
So what should I do to handle this event retargeting in shadow dom in router of angular dart? or is there any existing solution in angular dart?

Can't stop the drop event from propagating

I want to drop a small pattern into a div or into the body and have the background for that div or the body, whichever received the pattern, repeat the pattern in x and y. See jsfiddle . If I drag the pattern from the Gallery div and drop it in the body, just the body gets the background pattern. Great! That works. But if I drop the pattern into the canvas div, both the body and the canvas get the pattern. How can I just have the canvas get the pattern when it's the drop target. I tried every way I know, at the end of the drop handler, to stop propagation . . .
e.stopPropagation();
e.stopImmediatePropagation();
return false;
but nothing is working.
Thanks for any help.
You had it almost right. I've modified your fiddle to show the change.
You needed to add the greedy property in the thumb_dropOps object. Modify your function to be the following:
var thumb_dropOps = {
drop : thumb_drop,
accept : '#pattern',
greedy: true
};
Here is a reference link: jQuery UI - Droppable API Docs
Per the jQuery UI Documentation:
By default, when an element is dropped on nested droppables, each droppable will receive the element. However, by setting this option to true, any parent droppables will not receive the element. The drop event will still bubble normally, but the event.target can be checked to see which droppable received the draggable element.

message in empty <div> to drag

I am working on drag and drop tool using jQuery UI's sortable widget.
I'd like to add a message into an empty div where something can be dragged into, like: "drag here". I'd like to remove this message as soon as something is in that div. There will be times when the page loads with something already in that div, so it can't be only on action, but onload needs to check it too.
How do I go about it?
Here's my code:
$("#divFrom, #divTo").sortable({
connectWith: '.connectedSortable'
}).disableSelection();
You should be able to set up a draggable, and droppable and tap into droppable's drop event handler, which is fired when an item is dropped:
$("#target").droppable({
drop: function() {
// Empty the droppable div:
$(".message").remove();
}
});
Demo here: http://jsfiddle.net/andrewwhitaker/rUgJF/2/
As for doing something similar on load, if you provided your markup it would make providing a solution a little easier (is there a specific element inside the droppable div that you could check for?)
Hope that helps.

Resources