How to create a textbox to accept emoticon in QML? - javascript

i am trying to create a textbox which will accept a emoticon image as part of its text.
Any sugestions?

Tell your textbox that you want it to display rich text. When you write text, replace your emoticons with HTML <img> tags pointing to the emoticon picture.
Edit : example with a smiley example (:-))
In your text box, you want to replace the :-) smiley with this picture : . Assume that the picture is in a file called "smile.jpg". When you write text, replace :-) by <img src="my/path/to/smile.jpg" alt=":-)"/>. When you write a backspace to erase the smiley, you can replace the whole HTML <img> tag by :- (:-) without the final ))

Related

Replace Emoji with image while preserving it as an Emoji

I'd like to replace Emojis on my website with custom images. That itself would not be a problem in PHP:
$string = "This is a laughing emoji 😂";
echo str_replace($string, "😂", ":'D"); //or replace with an image
However, how do I manage that if someone copies the text, they will be able to copy the text with the emoji and not the replaced image? Like keeping the char 😂 😂 but only changing the outcome so they will look the same for every user. Is that even possible at all?
One way to do this would be to replace the emoji with an <img> image tag, but set the alt attribute of the image to the original emoji. Then, if the result is copied somewhere that only accepts text, the alt text will be used.
"Run" this snippet to see an example:
Hello <img alt="😀" src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7"> world!
<br/>
<textarea cols="25" rows="3">Paste here</textarea>
The emoji between the two words will look like a Gmail emoji, until you copy the entire line of text somewhere.
Of course, you can use a normal URL instead of a data: URL.
No, each system has its own sets of fonts ( including emojis ) which is why they appear different on android vs iOS. The only way you would be able to add something would be outside of the system typeface, i.e. icon sets. You could either include images or links to images.
<img src="imageLocation" alt="altTextorImage">

How to replace a text with hyperlink using javascript?

I want to replace a word with hyperlink on every post. So i used this code.
document.body.innerHTML = document.body.innerHTML.replace('Ronaldo', 'Ronaldo');
This code is working properly but the issue is, it's also replacing Ronaldo in title and in heading. I don't want that. I want that code to only replace words in post-body and not on post-title or <h> tags
I'm tagging jquery and ajax because they too know javascript.
You are selecting whole body with : document.body;
when you can just select the specific one by using: document.getElementById("yourId");
and replaces it's Ronaldo.

Creating tag labels inside an editable div

What I am trying to do is to create a front-end editable tagbox (editable div). Whenever a user types a word into that box and presses , this box will change that word into a colorful label. The problem I am having is:
User types the first word in, presses the comma key.
The word is then wrapped in <a> tags.
User types the second word in, presses the comma key.
Now I have to leave the first wrapped word as it is and take only the second word into consideration to wrap it into an <a> tag as well. It's extremely tricky to me, I have no idea how to leave the first <a> tag alone and select "free" words for wrapping. This also means wrapping more than one word into a single <a> tag whenever the user decides to put a two-word tag. It has to work with any number of tags.
Could you please point me in the right direction? I am trying to solve this with jQuery. I don't necessarily need the code itself, because I know how to write it, I just need to come up with the right algorithm in my brain.
Alright, as requested :)
Depending on whether you keep the commas in the field after replacing or not, split the inner HTML of the editable content by comma and/or .
Try following
function wrapInLink(container){
var link_text = $(container).text().split(',').slice(-1).pop(); // finding the string for replacing with anghor tag
var html = $(container).html(); // getting the container html
html = html.replace(link_text, "<a href='link_to_be_given'>" + link_text + "</a>"); // replacing the link text with anchor tag
$(container).html(html); // replacing the container's html
}

Replace bbcode tags with HTML equivalent

I want to make a script that previews your entered bbcode text as it will appear when posted, but I'm not sure how to do that.
Basically if a user enters in a textarea the following:
[b]This[/b] is some [url=http://google.com]sample[/url] text.
I want to show the user a preview of the above; like this:
This is some sample text.
The preview will just be a separate <p> somewhere on the page. I was first considering just replacing all brackets [ ] with < > but this would only work for certain tags. The url-tag for example is quite different from the HTML equivalent.
So I'm stuck. Any ideas if this is possible with javascript or jQuery?
EDIT: I should note that the tags I'm interested in are: b, i, u, url, color, and size.

javascript text replacement

i am using jquery replaceText plugin. with this plugin i can successfully replace text of an element like this:
<div>some text to be replaced here.</div>
<script type="text/javascript">
$(function(){
$("div").replaceText("some text to be replaced here", "a new text for replacement");
})
</script>
however when that div becomes something like this:
<div>some text to be replaced here.</div>
the replacement is not working.
how should i proceed here?
When operating on the HTML of the page, all the tags are in the HTML stream so you can't just do a direct replacement of only the text without allowing for intervening tags.
It isn't matching "some text to be replaced here" because that string of text doesn't exist as a single string of text in this HTML:
div>some text to be replaced here.</div>
You would have to replace individual pieces of text that actually exist as individual streams of text like "some text to be " and "replaced".
So you want to replace a subset of text with another subset of text and you want to work across nodes.
Looks like you want a Range.
So you just have to make a new Range using document.createRange(). Make it point to where you content starts.
So just find the start node and the start offset somehow then call range.setStart(node, offset). I would presume the node will be your container and the offset is just calculated.
Then call range.extractContents() to remove the original text from the DOM.
Then just range.insertNode(textNode) to insert the next text into the DOM.

Categories