How to get which commands are applyed on rich text box, JavaScript - javascript

I have a simple RichText Editor which contains standard operations (Bold|Italic|Underline, Text Alignment, Font type, color and size). I am using execCommand function in JavaScript (more info). So the command buttons are toggle buttons and when the mouse pointer is on the bold text (for example) how to make toggle button pressed. With other words - Has anyone idea how to get applied commands on the text to change the toggle button states. If I am not sufficiently detailed, ask me.
Thanks for reading :)

Related

How to change the size and style of the suggested search terms which opens under the search bar based on the search history?

Background: I wrote a search box like a google search box. However, when I want to search a word, a box opens automatically under the search box, suggesting words based on the history of the words typed in that box. I have not coded the box for the suggestions; it is a browser's feature. The size, shape, and style of the box that provides the suggestions depend on the choice of browser.
Problem: I want to style this box without deactivating the browser suggestion box. In other words, I need to make the width, shape (curves) and shading proportional to the search box that I coded. I am looking only for pure CSS, HTML, and Vanilla Javascript solutions if this is possible at all.
An example is how Google has done it (please see the screenshot):
enter image description here
If this is not possible, then I have to code everything myself. In that case, how can I have access to the history of the previous words which the browser stores?
Your answer is here.
You need to use input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, input:-webkit-autofill:active in CSS to style them.

How do I highlight the parts of the image that is clicked or dragged, and save that area?

I essentially need to have a user online click drag with the mouse or fingers on a picture of the human body to highlight the selected area red. Basically they're selecting areas of the body that hurt.
Then I need to store this information, and use it as needed.
Looking online I just seem to find how to highlight an area on hover like JQuery's maphighlight feature, which isn't what I want.
I'm very new to coding but am learning as I go along.
There are more pseudo-classes than hover. In this case, active or visited.
You could simply change the selected image section to a highlighted version of the same image.
Or add a border CSS property on :visited
To store information use either a made up data-[whatever] attribute,
or use a regular JavaScript variable. Since you'll need JavaScript to use the given variable anyways.
There are fancier solutions.
MAP is great for selecting shapes within an image, but doesn't have a way to highlight that selection.

Javascript: Copy to clipboard in iOS

I'm well aware that iOS Safari doesn't support document.execCommand("copy"). However, I would like to make it as easy as possible for iOS users to copy a block of text.
A user can long-press a word on the page, which will highlight the word. They can then manipulate the selection range to highlight the entire text block, but this can be a bit touchy. Once they have the entire range selected, they get a callout balloon with various options, including copy. I'd like to find a way to simplify this workflow if at all possible.
It's possible to create a button to highlight text for a user with one click. But this doesn't bring up the text options bubble. And when the user long-presses that selection, it reselects just a single word.
Is it possible to highlight an entire text block (with the options bubble) on long press? Are there other ways to make the copy/paste easier for users?

How do I check/pick a font color for good contrast against gradients on a webpage?

So I have, say a button with a gradient from one arbitrary color to another. Is there a systematic way to with code (a) check if the current text color will or will not work and (b) if the current text color doesn't work, is there a way to generate a text color that will work over the gradient? I am changing the gradients of certain buttons, based on user input, and need to update the font color if necessary.
Note, I recognize that this is a fairly well solved problem for solid color backgrounds (for instance, see here: http://www.particletree.com/notebook/calculating-color-contrast-for-legible-text/).
If you're looking for automatic detection, I would maybe start here:
http://khan.github.io/tota11y/
This is a jQuery plug-in that checks background/foreground color for accessibility, on the example if you click the bottom left icon and then click "Contrast" it will point out the issues on your page. It looks like it works with gradients, so perhaps you can modify this in a way that helps you choose your colors.
For more manual approaches:
This chrome plugin says it works with gradients:
https://chrome.google.com/webstore/detail/color-contrast-analyzer/dagdlcijhfbmgkjokkjicnnfimlebcll
Wave:
http://wave.webaim.org

Javascript - Dynamic Tooltip in TextBox

I'm attempting to get the following functionality, but can't seem to find a good way to do it:
There's a textbox where the user inputs some text, for example, "The apple is red." I then want a custom tooltip to appear depending on which word the mouse is hovering over.
So if I mouseover apple, I want to see a tooltip saying Apples are a fruit!, if I hover over red, I want to see Red is a color!, but I don't want anything to happen if I over over either The or is.
Any ideas?
this is (probably) impossible with a normal textbox.
You'd have to use a "contenteditable" element (e.g. div) and wrap words in tags (e.g. span) while user is typing...
Usually tooltips need a target, which must be a html element. I haven't seen a tooltip that you could attach to a single word inside a tag.

Categories