EasyUI Forum
May 14, 2024, 07:51:14 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Copy/Paste button in Easyui texteditor  (Read 4841 times)
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« on: August 04, 2018, 04:38:51 AM »

I am trying to extend the text-editor extension toolbar to include copy and paste button. But this is not working.

Code:
$(function(){
            $('#te').texteditor({
                toolbar:['bold','italic','underline','justifyleft','justifycenter','justifyright','-','insertimage','Paste','Copy']
            });
    });

$.extend($.fn.texteditor.defaults.commands, {
    'Paste': {
        type: 'linkbutton',
        iconCls: 'icon-paste',
        onClick: function(){
            $(this).texteditor('getEditor').texteditor('execCommand','paste');
        }
    }
});
$.extend($.fn.texteditor.defaults.commands, {
    'Copy': {
    type: 'linkbutton',
    iconCls: 'icon-copy',
    onClick: function(){
            $(this).texteditor('getEditor').texteditor('execCommand','copy');
        }
    }
});

I am using the latest version of firefox.

// var result = document.queryCommandSupported('copy');
// console.log(result); return true
// var result = document.queryCommandSupported('Paste');
// console.log(result); return false

Please help.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 05, 2018, 02:18:00 AM »

The 'paste' command does not supported in many browsers. The alternative solution is to store the current selected text and then insert into the editor when the 'paste' button is pressed. Please refer to the code below:
Code:
$.extend($.fn.texteditor.defaults.commands, {
'Paste': {
type: 'linkbutton',
iconCls: 'icon-paste',
onClick: function(e){
var s = $('#myclipboard').html();
$(this).texteditor('getEditor').texteditor('insertContent', '<span>'+s+'</span>');
}
}
});
$.extend($.fn.texteditor.defaults.commands, {
'Copy': {
type: 'linkbutton',
iconCls: 'icon-copy',
onClick: function(){
var s = window.getSelection();
var cb = $('#myclipboard');
if (!cb.length){
cb = $('<div id="myclipboard" style="display:none"></div>').appendTo('body');
}
cb[0].innerHTML = s;
}
}
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!