I am using "CLEditor WYSIWYG HTML Editor v1.4.5"
When I open the window containing the TextArea element I'm using with clEditor, the Editor comes up disabled and it appears that the TextArea element is invisible. I have text in the TextArea element but the text is invisible.
If I right click on the body of the TextArea and select "Inspect Element", the debugger window opens and the Editor becomes enabled and the TextArea becomes visible. Then I close the debugger window and everything appears to be functioning correctly.
HTML:
<div id="maintBody">
<textarea id="woEditor" name="woEditor">This is the test data... is this editable?</textarea>
</div>
Javascript
$("#woEditor").cleditor( {height: "400"});
No CSS
If I comment out the Javascript .cleditor() call, then the TextArea element appears and functions correctly. So there is definately some setting in the editor initialization that is setting this state.
You can access this page at: http://test.nds.link then click on the "Props" Tab in the left column
Does anyone know what would cause the clEditor to come up in a disabled state, making the TextArea element invisible?
I had the same error while I using CLEditor inside a DIV which was toggled via jQuery.
The animation-Parameter cause the error! After I removed it, it works like a charm!
wrong way:
$("#cT_new_form").toggle("slide",700);
right way:
$("#cT_new_form").toggle(700);
So don't use "slide" as animation or CLEditor won't focus after slide!!!
The following fixed this issue for me without having to remove the effects:
cleditor problem with jquery ui effect()?
Related
I have a div that the contenteditable attribute is true,
<div tabindex="1" id="editor" contenteditable="true"></div>
I have another div that acts like a button
<div>Click Me</div>
The problem am having is that after typing inside the editor box, I selected some text and when I clicked on the "click me" div the editor box looses focus and thus removing the highlighted text.
I used in js to programmatically send the focus back
document.getElementById("editor").focus()
But after this the selected text is no more selected the cusor just moves to the beginning of the editor box.
How do I get the focus to make sure the initial selected text is selected again after the click me has been clicked
One solution is setting user-select: none on your button-like div. If the browsers you care about support it, it's the simplest (but as discussed in the comments here, someone reported problems with getting it to work in Safari...)
Otherwise you'll have to save and restore the selection using JS, the text range module of rangy.js is useful for that. Check out https://stackoverflow.com/a/57546051/1026 for a usage example; in your case you'll need to save the selection onblur and restore it after processing the click on the button-like div.
I have an input field with some text, and I am trying to toggle its visibility. The problem I'm running into is that after toggling slide animations on the field, its text is invisible.
When the field is brought into focus though, the text is visible again.
I've tested this on Safari/IE/FF and the input text stays visible, but I cannot figure out why Chrome is acting so odd.
http://jsfiddle.net/f63Et/1/
The problem is that jQuery sets the display of the input to inline-block when it does an .slideDown() and that makes Chrome render it incorrectly.
You have a couple of options, for example wrap the input in a div, or set the display to block
You can try to manually focus it by putting in the slideDown()'s callback:
$(this).focus()
This doesn't answer the question of why Chrome behaves strangely, but, as a workaround, if you enclose your input in a div:
<div id="text"><input type="text" /></div>
Then slideToggle the div:
$(document).on('click', '#slide', function() {
$('#text').slideToggle();
});
That appears to work in Chrome.
As a variant you can use $('input').toggle('slow')
so I have a textarea surrounded by a DIV container:
<div>
<textarea id="code"> some text here </textarea>
</div>
and this textarea is tranformed into a code editor using CodeMirror:
CodeMirror.fromTextArea('code', {
lineNumbers: true,
matchBrackets: true,
mode: 'text/html'
});
the problem is that when the container of the textarea is hidden (some times it is, depending on what the user chooses to display), then after toggling to unhide it the CodeMirror editor doesn't appear like it should. It only shows one line, and you have to actually click inside it to redraw and show properly.
Does anyone know a fix for this?
refresh()
If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it, you should probably follow up by calling this method to ensure CodeMirror is still looking as intended.
from CodeMirror manual (assuming you're using version 2)
I am developing an HTML code editor using simple DIV's and capturing events. When I use this on the iPad the keyboard never pops up since i'm not technically in an editable field.
Is there a way to programatically tell the iPad that I need a keybaord?
If your code is executed via something that was initiated via a user action then it will work.
E.g;
this works (pops keyboard):
<input type='text' id='foo'><div onclick='$("#foo").focus();'>click</div>
this doesn't work (input gets a border but no keyboard pop):
<input type='text' id='foo'>
<script>
window.onload = function() {
$("#foo").focus();
}
</script>
To make the keyboard show on iOS devices you need to focus on an editable element such as an input or a textarea. Furthermore, the element must be visible and the .focus() function must to be executed in response to a user interaction such as a mouse click.
The thing is - we DON'T want the input element to be visible..
I have fiddled with this for quiet some time and eventually got the result I was looking for.
First, create an element you want to use to show the keyboard - in this case a button, and a hidden input element: (Working jsFiddle or Test on a mobile device)
<button id="openKeyboard">Open Keyboard</button>
<input id="hiddenInput" style="visibility: hidden;">
Then use the following javascript:
document.getElementById('openKeyboard').addEventListener('click', function(){
var inputElement = document.getElementById('hiddenInput');
inputElement.style.visibility = 'visible'; // unhide the input
inputElement.focus(); // focus on it so keyboard pops
inputElement.style.visibility = 'hidden'; // hide it again
});
Notes:
I have noticed that iOS safari will automatically scroll and zoom to the area of the input so make sure you use proper viewport and position your input element in a relevant location.
You can use some CSS on your input like setting the opacity, height and width to 0. However, if your input is completely hidden this won't work again, so make sure you leave the padding or border just so there's something to be rendered (even though it won't show up due to the opacity). This also means you shouldn't use display:none to hide it, hidden elements are just not allowed to be focused.
Use the regular keyboard events (keydown, keypress, keyup) on your hidden input to access the user's interaction as you would normally do. Nothing special here.
Place a transparent textarea over the contentEditable div. The keyboard will open, as soon as the user focus the textarea.
Register an event listener on the textarea for the focus event and set the visibilityof the textarea to hidden. This prevents the blinking cursor.
Set the visibility of the textarea back to visible after the blur event occurred.
Register additional event listeners for keydown, keyup, keypressevents and process theses events the same way, as you process them in the contentEditable div.
I have found that calling prompt("Enter some value") does trigger the keyboard on my iPad 2. Not sure if this is helpful in your situation or not.
The answers to this questions suggest that it's not possible: Why doesn't #contenteditable work on the iPhone?
A colleague of mine who was working on a similar project ended up using a textarea for the iPad version of his editor, and contenteditable divs/spans for browsers that support contenteditable. Perhaps something similar would work for you.
Proxy input trick
I figured out another dirty workaround, but works well.
The trick is based on the fact, that if the keyboard is already open, changing the focus will not close the keyboard.
Add a small "proxy invisible input" in top left of the page with position fixed (the fixed position prevents the flicker, also make sure that the field has font-size bigger than 16px to prevent iOS page zoom on focus)
On clicking the button, just .focus() on this invisible field. The keyboard will open...
Show or render your other input fields
Now with the keyboard open just .focus() on the desired input. You can use small setTimeout delay, for example 500ms if needed
Here's a solution for you:
<input id="my-input" type="text" />
<script type="text/javascript">
var textbox = document.getElementById('my-input');
textbox.select();
</script>
I was wondering if there is a way to protect a piece of html or text inside the jquery inline content editor jwysiwyg?
For example, I have a div that I externally insert to the editor and I do not want the user to modify it.
I could not capture the keypress event inside it (iframe security?) and setting the div to readonly or disabled did not work.
Any ideas?
Thanks!
Just add a click event handler for that div so it throws an alert and disables (graying out) the rest of the page; something like a login dialog (check out jQueryUI dialog - http://jqueryui.com/demos/dialog/)
Try it!
To clear the content in the editor use
$('#wysiwyg').wysiwyg('clear');
If you want to set the content of the editor on the fly you can use
$('#wysiwyg').wysiwyg('setContent' response.message);