How to disable paste in Cloud9 Ace Code Editor? - ace-editor

I am using CloudA9 Code Editor for my College Project. How can I disable the Paste in Editor.

you can use
stop = function(e) {
e.stopPropagation(); e.preventDefault(); console.log(e)
}
document.querySelector(".ace_editor").addEventListener("paste", stop, true);
or
editor.onPaste = function() { return ""; }
​

Related

How to disable the edit mode in CKEditor 4? (inline-editor)

I need disable edit mode in inline mode.
I try use this code
CKEDITOR.disableAutoInline = false;
var editor = CKEDITOR.inline(elm[0], {
extraAllowedContent: '*',
toolbarStartupExpanded : false,
toolbarCanCollapse : false,
startupFocus: false,
});
editor.on('instanceReady', function (ev) {
var ed = ev.editor;
ed.setReadOnly(true);
editor.removeListener();
});
editor.on('focus', function (event) {
return false;
});
editor.on('blur', function () {
return false;
});
This code hide toolbar, but menu (right mouse click) is enable, and I need full disable (readonly mode) only for 'render content' but I need all plugins, including "code" and quote. (if i use render with "removePlugin "toolbar", my plugins code, quote and etc not render my code correct) any ideas?
Just add:
config.readOnly = true;
Ref: https://ckeditor.com/docs/ckeditor4/latest/guide/dev_readonly.html

Opening a link in CKEditor with one click

I am using CKEditor, I have put a link into a text. Is it possible to go directly to the link when we click (once) on that link inside CKEditor?
Have you tried something like this (jQuery required):
CKEDITOR.on('instanceReady', function(ev) {
$('iframe').contents().click(function(e) {
if(typeof e.target.href != 'undefined') {
window.open(e.target.href, 'new' + e.screenX);
}
});
});
hotfix from https://dev.ckeditor.com/ticket/7145#comment:1
CKEDITOR.on('instanceReady', function (ev) {
$('iframe').contents().click(function (e) {
if (typeof e.target.href !== 'undefined') {
window.open(e.target.href, 'new' + e.screenX);
} else if (typeof e.currentTarget.activeElement.href !== 'undefined') {
window.open(e.currentTarget.activeElement.href, 'new' + e.screenX);
}
});
});

How to hide toolbar in CKEditor inline

I have an application that needs the inline CKEditor but without toolbar. For the inline CKEditor part I have:
CKEDITOR.disableAutoInline = true;
var editor = CKEDITOR.inline('editable', {on: {
instanceReady: function() {periodic();}
}});
var periodic = (function() {
var data, oldData;
return function() {
if ((data = editor.getData()) !== oldData) {
oldData = data;
$.post("update.php", {txt:data});
}
setTimeout(periodic, 1000);
};
})();
Then for the toolbar hiding part I found this: CKEditor 4 Inline: How to hide toolbar on demand?
//Whenever CKEditor loses focus, We will hide the corresponding toolbar DIV.
function hideToolBarDiv(event) {
// Select the correct toolbar DIV and hide it.
//'event.editor.name' returns the name of the DIV receiving focus.
$('#'+event.editor.name+'TBdiv').hide();
}
Problem is that I have no clue how to combine these two together :) I appreciate for any hint. Thank you.
I found another link that seems to solve my problem: Can I use CKEditor without a toolbar?
The script seems to be working alright though I am still not sure if it is a correct way to do it:
CKEDITOR.disableAutoInline = true;
var editor = CKEDITOR.inline('editable', {
removePlugins: 'toolbar',
allowedContent: 'p h1 h2 strong em; a[!href]; img[!src,width,height]'
on: {instanceReady: function() {periodic();}}
});
var periodic = (function() {
var data, oldData;
return function() {
if ((data = editor.getData()) !== oldData) {
oldData = data;
$.post("update.php", {txt:data});
}
setTimeout(periodic, 1000);
};
})();
In my eyes, I have done it in two ways:
1) Using the removePlugins option and just remove the toolbar:
CKEDITOR.inline( 'textarea', {
removePlugins: 'toolbar'
} );
here, you can also use allowedContent to allow the contents for ACF
CKEDITOR.inline( 'editable', {
removePlugins: 'toolbar',
allowedContent: 'p h1 h2 strong em; a[!href]; img[!src,width,height];'
} );
2) Using CSS - Not the standard approach: (little tricky)
Just make css to display:none the toolbar, like
.cke_inner {
display: none;
}
Hope it will help someone.

please help me remove content on paste event

I want to remove the format the content when user paste into ckeditor. I tried this code but it doesn't work.
CKEDITOR.on('instanceReady', function (e) {
editor = e.editor;
editor.on('paste', function (e) {
editor.focus();
editor.document.$.execCommand('SelectAll', false, null );
editor.execCommand('RemoveFormat', editor.getSelection().getNative());
editor.insertHtml('additional content');
});
});
Try adding CKEDITOR.config.forcePasteAsPlainText= true; to config.js, that should solve your problem.
i solved my problem by formating content before set value for textarea
CKEDITOR.on('instanceReady', function(e){
var editor = e.editor;
editor.on('paste', function(e){
setTimeout(function(){
$('body').append("<div id='tmpCt'>"+ editor.getData() +"</div>");
$('#tmpCt div, #tmpCt p, #tmpCt a, #tmpCt span').removeAttr("style");
$('#requiredDescription').val($('#tmpCt').html());
$('#tmpCt').remove();
}, 100);
});
});

How to create a button near the address bar?

I am designing a firefox extension, and I want to add a button near the address bar. And then I need to attach a bookmarklet to that button.
Someone can tell me what APIs do I have to use to create that button and to add the bookmarklet ?
Here's an example that uses Erik Vold's toolbarbutton library to add a button near the addressbar:
const data = require("self").data;
const tabs = require("tabs");
exports.main = function(options) {
var btn = require("toolbarbutton").ToolbarButton({
id: 'my-toolbar-button',
label: 'Add skull!',
image: data.url('skull-16.png'),
onCommand: function() {
if (typeof(tabs.activeTab._worker) == 'undefined') {
let worker = tabs.activeTab.attach({
contentScript: 'self.port.on("sayhello", function() { alert("Hello world!"); })'
});
tabs.activeTab._worker = worker;
}
tabs.activeTab._worker.port.emit("sayhello");
}
});
if (options.loadReason === "install") {
btn.moveTo({
toolbarID: "nav-bar",
forceMove: false // only move from palette
});
}
};
You can also see this as a runnable example on the Add-on Builder site:
https://builder.addons.mozilla.org/addon/1044724/latest/

Resources