Convert emails to buttons inside contentEditable - javascript

I'm trying to convert emails to buttons inside a contentEditable using Regex, but I'm realizing it will need too much time for me to handle cursor location, to add a delete functionality, etc. What I expect look like it:
My first idea was to use a textarea, floating in a div. That was maybe a better idea.
But... Is there some well-known open libraries to achieve it? I've seen a lot of tag libraries that can act like the tag bar on SO, but I'm searching for something that takes:
A container
A regex to match something
Convert it to button
Delete it on backspace press.

How about the fcbkcomplete plugin?

Related

Building a wordcloud around an element in Javascript

I need to create a word cloud that looks like the following,
The bordered element is a button, and the elements around are supposed to be a wordcloud.
I have been able to use a react-wordcloud library for the just the word cloud but putting an element in between has left me in a fix.
One method I can think of is using an div as overlay, but the clear downside I can think is that I will have no control over the what will lie beneath the button.
I am out of ideas as in how to achieve this, and any help will be appreciable

Jquery/Javascript add emoticon to input

I am using Jquery, php and html5. Either an input field or a textarea is used and for both i always run into the same problem: inserting emoticons / smileys: they won't. They only seem to want to add straight up text, nothing else.
I've googled and googled even tried to code something which adds the value of the key pressed to a div (and therefor have the potential to not insert :-) but insert a smiley instead), but that doesn't seem to be ideal.
Do any of you know how to do this properly and would like to show me how?
Really at a loss here....I would be very grateful for any help.
First of all - font letter is graphic object and smile picture is graphic object ))
Most simple way - just using font with smiles instead of regular font.
Take a look for http://www.fontspace.com/category/emotions, for example.

Grabbing the sentence that a selected word appears in

Using Javascript, I need to allow a user to double click a word on a page and retrieve the sentence that it appears in. Not just any sentence, but that specific one. I've toyed with retrieving all sentences that that word appears in and somehow choosing the correct sentence, so maybe that's an option.
I've scoured the web looking for this beast, and I've thought a lot about it. Some have recommended using Rangy but I haven't been able to find the functionality I'm looking for, or even functionality that would help me get where I need to be.
Any ideas?
You could turn your page into one or multiple read-only textareas, use clever CSS styling to mask it, then use the onselect event as described here: Detect selected text in a text area with javascript
Depends of course, how your page looks like and where it's used.

How do I format an HTML text field to use multiple styles?

I'm looking for a way to apply some formatting to a single-line text input field in JavaScript. It would work like this:
The user types in a formula, such as:
(7 + 3) ^ x
As the user types, my code would format it using colour to look like this:
I can do the necessary parsing but I don't know how to apply these styles to the user's text as they edit.
I've been struggling to find the right thing to Google for. My searches mostly lead me to full-blown text editors.
Is there such a component? If not, can I achieve this with a <input type="text"...> field?
Out of curiosity I built this: http://jsfiddle.net/hunter/npbDL/
This catches key strokes and inserts a span-wrapped character into an element. If the character maps to an item in the character-to-class collection it also gives that span the class specified.
It also handles enter and backspace.
You can probably take it from there...
I think the only way you can achieve the styling you want is by wrapping HTML tags around individual characters then styling the tags, and I don’t think you can do that inside an <input type="text">.
There is the widely-supported contenteditable attribute which makes most elements editable, but I’m not sure that it allows this either. If no-one else provides a better answer, you might want to view source on the last example here: http://www.hyperwrite.com/Articles/contenteditable.aspx
You can't format a text field with various colors. You might be able to use colors in WYSIWYG editors... or Flash.
I don't think you can change of individual characters in any <input> nor <textarea>. Look into source code of Etherpad for example - it uses similar system (not exactly the same - it highlights other stuff) and it might help you.

Ondrag ROT-13/ROT-47 decode

I have a little website where I would like to obfuscate some text to protected spoiling of users that accidentally read it untimely.
Much like the keywords on imdb were, where you have to rollover to reveal them.
I thought it would be a nice and interactive way to reveal the text if its marked.
Example:
How does a programmer express
h(is)|(er) love? Zl srryvatf sbe lbh
ner uneqpbqrq.
Now you would drag mark the obfuscated text much like you would get ready to copy it to your clipboard, and it should reveal.
Is there a way to do this? My current problem is a way to determine the current selection in javascript.
There is one tricky way I can think of with only CSS:
Use the same color text as the background color! Then when users highlight, the text is revealed. You would need to outline or draw attention to the part that they need to highlight to make it obvious.
Another way:
Stuff the rot13 into a readonly text input, and attach a select event with an AJAX call that decodes it. Will only work for smaller bits of spoiler text that fit in the input. You could try this with a textarea but it doesn't accept the readonly attribute (maybe doesn't matter).
There are many many other ways to do this (hide/show divs for example), but these are the closest/simplest ways I could think that match your requirement of selecting text to trigger the spoiler.
EDIT: With the background color solution, you would not want to encode the text, just make it "invisible" until it's highlighted. It's actually a pretty cheesy solution, and there are many others that are better, but the good part is that it is css only. Honestly I think forcing a complete highlight will be a pain for your users, just store the rot13 value in one place, the real value in another (hidden span maybe), and use js to swap them out on click or something. No need to actually process the decoding separately. You could probably do this with CSS alone and some smart :hover or :focus selectors.
EDIT2: For some reason it didn't occur to me that you can do rot13 decoding with javascript alone, I'm coming from the php world so now I feel pretty foolish. Sorry I didn't answer your question better, but hopefully some of this is useful. GL!
jCarat (jQuery Caret Plugin) should cover your needs.

Categories

Resources