Reputation: 1472
I'm trying to apply Froala editor on the button tag. But I want it to open using the wrapper div click. I've added the two demos on this question, please check and anyone is knowing the solutions, please help me.
Demo1:
// find elements
var banner = $("#banner-message")
var button = $("button")
// handle click and add class
button.on("click", function(){
new FroalaEditor('#editor', {
events: {
contentChanged: function () {
console.log ('content changed....');
}
}
});
});
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/froala_editor.pkgd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/froala_editor.pkgd.min.css" rel="stylesheet"/>
<div id="banner-message">
<p>Hello World</p>
<button id="editor">Change text</button>
</div>
This first snippet will open the buttontext in popup to edit on second click.
Demo2:
// find elements
var banner = $("#banner-message")
var button = $("button")
// handle click and add class
banner.on("click", function(){
new FroalaEditor('#editor', {
events: {
contentChanged: function () {
console.log ('content changed');
}
}
})
})
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/froala_editor.pkgd.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/froala_editor.pkgd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="banner-message">
<p>Hello World</p>
<button id="editor">Change color</button>
</div>
Here in the second demo, I've used the wrapper click event to initialize the froala editor.
My Need: On the click of banner-message div I want to open the froala editor popup to edit the button content.
If anyone can help me to resolve this issue it would be great. Thanks in advance.
Upvotes: 2
Views: 649
Reputation: 101
Here is the code that you can try:
var test= new FroalaEditor('#editor', {
events: {
contentChanged: function () {
console.log ('content changed');
}
}
});
also, a running Jsfiddle sample: click here
Upvotes: 1