I'm using smiley helper to display and store smileys. Smileys 've displayed in a generated table view. Click on the smiley,corresponding text gets displayed not the smiley. Here is my code in Library,
public function get_smiles()
{
$CI =& get_instance();
$CI->load->helper('smiley');
$CI->load->library('table');
$image_array = get_clickable_smileys('images/smileys/', 'editor-textarea');
$col_array = $CI->table->make_columns($image_array, 8);
$array['smiley_table'] = $CI->table->generate($col_array);
return $array['smiley_table'];
}
In view,
<?php echo smiley_js(); ?>
<textarea name="editor-textarea" class="editor-textarea" id="editor-textarea"><textarea>
<ul>
<li>
<?php $smiles = $this->common->get_smiles(); ?>
<?php echo $smiles; ?>
</li>
How do I solve this?
Smiley js
<script type="text/javascript">
/*<![CDATA[ */var smiley_map = {};
function insert_smiley(smiley, field_id) {
var el = document.getElementById(field_id), newStart;
if ( ! el && smiley_map[field_id]) {
el = document.getElementById(smiley_map[field_id]);
if ( ! el)
return false;
}
el.focus();
smiley = " " + smiley;
if ('selectionStart' in el) {
newStart = el.selectionStart + smiley.length;
el.value = el.value.substr(0, el.selectionStart) +
smiley +
el.value.substr(el.selectionEnd, el.value.length);
el.setSelectionRange(newStart, newStart);
}
else if (document.selection) {
document.selection.createRange().text = smiley;
}
}// ]]>
</script>
After testing it, I've found that it is working as it should.
You can't add an image to the text area. Looking at the JS, it will add the text version of the smiley. Example of one, you can see the '%-P'.
<a href="javascript:void(0);" onclick="insert_smiley('%-P', 'editor-textarea')"><img src="assets/images/smileys/tongue_rolleye.gif" alt="tongue rolleye" style="width: 19; height: 19; border: 0;"></a>
Depending on your needs, it is your job to show the smiley on submission, so if it is a comments section for example you'd need to parse it on page load or via an AJAX callback on submit.
You need to convert the text version of the emoji into the correct image. You can do this with a CI function.
parse_smileys([$str = ''[, $image_url = ''[, $smileys = NULL]]])
Hope this helps.
Edit: Here's how to use it.
echo parse_smileys(':-)', 'assets/images/smileys/');
This is parsing the text version of the smiley which you will need to store somewhere, then it goes into the function and you also need to pass the location of the smiley images. Here's it working in my CI program, the single smiley has been parsed from the code sample above.