dtbrd80422 2018-02-26 10:51
浏览 36

笑脸不显示在输入框codeigniter中

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>
  • 写回答

1条回答 默认 最新

  • douba2011 2018-02-26 12:23
    关注

    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.

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题