Preventing the contents of draggable polymer elements from being selectable - polymer

I have a polymer element defined as follows
<polymer-element name="draggable-list-item" >
<template>
<core-style ref="draggable-list-item"></core-style>
<div id="row-container" draggable="true">
<content></content>
</div>
</template>
<script type="application/dart" src="draggable_list_item.dart"></script>
</polymer-element>
I know that for normal elements (non polymer / web component) that I need to add a style like
[draggable] {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
And everything is awesome
I can't get this to work with polymer. I can drag the item if I select it outside of the contents of the child polymer element. But not over it. I've tried various variants of
[draggable] /deep/ * {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
but nothing seems to work

Related

How to make div and img unselectable [duplicate]

This question already has answers here:
How to disable text selection highlighting
(45 answers)
Closed 1 year ago.
I can't make that code unselectable. How can I change it?
I tried placing user-select: none in all of css classes, but it's still selectable.
<div class="outer">
<a href="/">
<img src="/wp-content/themes/theme/assets/img/logo.png">
</a>
</div>
user-select is not supported in all browsers without prefix. Try this:
.outer {
user-select: none;
-webkit-user-select: none; /* Safari 3.1+ */
-moz-user-select: none; /* Firefox 2+ */
-ms-user-select: none; /* IE 10+ */
}
This was answered here, I can't post it in chat yet, sorry: How to make HTML Text unselectable
Long story short:
.outer {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

Stop user-selection in Bootstrap navbar

I would like to prevent user-selection to be possible on a Boostrap navbar, such as :
http://getbootstrap.com/examples/navbar-fixed-top/
How to stop user-selection ?
I tried user-select: none; but it fails if you do CTRL-A.
Note : I don't want to stop user to copy text on the page, but I want to provide better user experience by avoiding selection of navbar elements.
In bootstrap 4.5 and above, you can just use class="user-select-none"
You could do it like this:
Bootply - DEMO
.navbar {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
More Info:
Mozilla MDN user-select
CSS-Tricks user-select
Solution 2: Disable user selection when press CTRL+A
You could also do it by set the ::selection background color to none
Bootply - DEMO
div.navbar *::-moz-selection {
background: none !important;
}
div.navbar *::selection {
background: none !important;
}
.navbar {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}

Disable html tooltip on d3 bubble chart?

If you look at this example: http://bl.ocks.org/mbostock/4063269
When you mouseover the circle text, there is an html tooltip that pops up. Is there any way to disable this?
I thought using css would resolve the issue:
body {
font-family: Trebuchet, sans-serif;
color: black;
font-size: 14px;
font-weight: normal;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
but no luck.
The tooltip is shown by the browser based on the title attribute. If you remove the line of JavaScript that adds this, the tooltip will no longer appear.

How can I prevent these 'selected' artifacts on HTML elements?

Sometimes clicking isn't perfect, the mouse might move slightly and the button/elements end up with little 'selected' artifacts around them as seen here:
Of course clicking somewhere gets rid of it, but it's kind of annoying and looks crappy. Is there any way I can disable this so that the app seems more solid?
HTML/CSS:
<td id="controls">
<span id="ccw" class="menuitem"></span>
<span id="cw" class="menuitem"></span>
<span id="zin" class="menuitem"></span>
<span id="zout" class="menuitem"></span>
</td>
#cw{
background-image:url('icons/rotatecw.png');
}
#ccw{
background-image:url('icons/rotateccw.png');
}
#zin{
background-image:url('icons/zoom_in.png');
margin-top: 2px;
}
#zout{
background-image:url('icons/zoom_out.png');
margin-top: 2px;
}
.menuitem{
background-repeat:no-repeat;
width: 32px;
height: 16px;
display: inline-block;
}
In many browsers (except Opera and IE before IE10), you can use user-select with its various browser-prefixes. See MDN docu for details.
.controls {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}

Preventing images and text to be selected

I have an image being hacked in as a background image (as shown here). I've noticed that if I drag my mouse over it though, it selected the image so that it can't be deselected. I've tried the following code to no avail:
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
}
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
#content {
position:relative;
z-index:1;
top:0px;
left:0px;
}
*.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
</style>
Any ideas?
Add this to your style sheet
.selectDisable {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
.selectEnable {
-webkit-user-select: text;
-khtml-user-select: text;
-moz-user-select: text;
-o-user-select: text;
user-select: text;
}
Just add the class selectDisable to the element you want to prevent from being selected.
The drag effect occurs on webkit(chrome, safari, opera). It does not happen on Firefox.
Don't this apply to your whole document if you have textual content because then you won't be able to select text, which is not very user-friendly.
You could also prevent dragging by adding another empty div on top of your image with the same selectDisable class.
Here is a working example:
http://jsfiddle.net/xugy6shd/3/
draggable="false" worked for me
If you load image as div's background you can't select it.
EDIT
<div style="background-image: url(../images/test-background.gif); height: 200px; width: 400px; border: 1px solid black;"> </div>
If you are using jQuery I've written a tiny jQuery plugin - wrapper that does pretty much what ppumkin wrote:
(plugin is in js part along with an example usage) http://jsfiddle.net/gryzzly/HtvB8/