trigger javascript function when a key is pressed in fckeditor - javascript

I need to trigger a custom javascript function when something is typed into FCKeditor 2 textarea. However, I have searched far and wide and can't find an answer to this. Would like to do something like add onkeypress="customfunction()" to the textarea somehow.
Thanks for any help!

managed to find something in the end using some hints of words. Here is how to do an onkeypress even on FCKeditor 2.0. You need to load this javascript AFTER the editor code is called:
function FCKeditor_OnComplete(editorInstance){
if (document.all) { // If Internet Explorer.
editorInstance.EditorDocument.attachEvent("onkeydown", function(event){alert('key was pressed');} ) ;
} else { // If Gecko.
editorInstance.EditorDocument.addEventListener( 'keypress', function(event){alert('key was pressed')}, true ) ;
}
}

This seems to work:
CKEDITOR.instances.<yourEditorname>.document.on('key', function(event) { });
Found here: http://cksource.com/forums/viewtopic.php?t=18286

Related

How unfocus on jQuery for is(':focus')

Sorry for my poor English.
I'm using jQuery plugin slick. It contain some code
_isSlideOnFocus =_.$slider.find('*').is(':focus');
...
if(_isSlideOnFocus) {
//some code that i don't want to execute
}
Plugin gives ability to execute callback right before upper code will execute. So i can unfocus elements, but i don't know how.
In browser console right before upper code i try
_.$slider.find('*').blur();
_.$slider.find('*').each(function() {$(this).blur()});
_.$slider.find('*').trigger('blur');
but it don't work's.
i try in console
_.$slider.find(':focus'); //empty jQuery object
_.$slider.find('*').each(function() {
console.log($(this).is(':focus')); //false for all elements
});
_.$slider.find('*').is(':focus') //but this one returns true
Even if I try
_.$slider.find('*').each(function() {
if($(this).is(':focus')) {
$(this).blur();
console.log($(this).is(':focus'));
}
});
console logs true, so as I can see blur is not working for is(':blur')
How can i blur all elements in $slider? Thank's for help
Here the fiddle. My code in the end of js block. Subject plugin code is in the Slick.prototype.activateADA function in the end of plugin.
I have found the solution. I was using the old jQuery version 1.7. After updating jQuery to 1.9 blur works.
I did this:
$('.ui-slider-handle').blur();

Disable Firefox auto-search when using keypress() in JS

Question:
I am running a function where you press the keys C or M using the keypress() function and every time I press one of those keys, the letter is marked automatically in Firefox. Is there a way to disable this using JavaScript or is this something Firefox does by default?
I have tried to look for an answer using Google but it seems no one has had this issue before using the keypress() function in JS.
Code:
<script type="text/javascript">
$(document).ready(function()
{
var once = false;
$(window).keypress(function(e)
{
if(!once)
{
if (e.which == 99)
{
once = true;
$("input#left").val( 1 );
$("form").submit();
}
else if (e.which == 109)
{
once = true;
$("input#right").val( 1 );
$("form").submit();
}
}
});
});
</script>
Thanks in advance for any tips!
Just call preventDefault():
$(window).keypress(function(e)
{
e.preventDefault()
// other code
}
There are a few ways of handling this. If you call e.preventDefault() you should be covered, however that's not your only option.
HTML5 introduced many new tags and attributes into markup, one of them being an autocomplete attribute for text fields. If you add this to your HTML (<input type='text' id='myInput' autocomplete='off'>) you should be covered as well. You can't always rely on your user having support for HTML5, but this is still an easy solution to your problem.
It can't hurt you to implement both of these small changes in your code.

onBeforeUnload/unload

In Javascript, I keep seeing posts about how one should not try to use onBeforeUnload or unload() in jQuery, citing security issues. Could someone explain in greater detail what these issues are?
On that note, I have also found that neither of these work in any browser I've tried. Even something simple like this:
$(window).unload(function(){
alert('hello');
});
Is this intentional, or no?
You might have mixed it up with the issues concerning usability??
I use it as native js
window.onunload = function(e) {
return 'Dialog text here.';
};
You con't use an Alert inside your function for simple raison that onunload is a pop-up so the display your text (HELLO) just but it in the return or try this:
window.addEventListener("beforeunload", function(event) {
event.returnValue = 'hello';
});

Error with regex in jquery

I want to validate my textbox on keypress event. As I am newbie with jquery, I searched on google and found one jquery plugin named 'limitkeypress'.
This is my code:
$(document).ready(function() {
$("#title").limitkeypress({ rexp: /^[A-Za-z]*$/ });
});
Plugin library is:
http://brianjaeger.com/process.php
It's giving me the following error
$("#title").limitkeypress is not a function
When I checked the library on jsfiddle it shows me dozens of errors. Is there any other validation library or plugin?
EDIT Thanks everyone for your valuable comment. Finally I got the solution. Though I was including file correctly. but don't know Y it was not working. I wrote jQuery.noConflict(); and all the problem is solved. What exactly it work. Please let me know, though I read but doubt still I have doubt.
regexp is ok:
'buGaGa'.match(/^[A-Za-z]*$/);
$("#title").limitkeypress is not a function probably you forget to inlude library or wrong path.
Check it in Firebug( Net -> All ) lib must be highlight in black, not red.
Made a demo: http://jsfiddle.net/tTASy/
plugin seems to work fine.
Check your path to the script. if you paste a link to your page we could help you more specifically.
You can do this in jQuery like this without the plugin..
$("#your_textbox").keypress(function() {
var length = this.value.length;
if(length >= MIN && length <= MAX) {
$("#your_submit").removeAttr("disabled");
$("#your_validation_div").hide();
} else {
$("#your_submit").attr("disabled", "disabled");
$("#your_validation_div").show();
}
});

change this to jquery

How would I change the below to jquery? It works in IE but not Firefox so I am hoping if I change it to jquery it will work for both.
THIS
function subform() {
if (parent.option_view.document.vform_.dispatchEvent('onsubmit') != false) {
parent.option_view.document.vform_.submit();
}
}
AND THIS
img class="save_bttn" src="/images/save.gif" height="16" width="16" border="0" onclick="subform()"
IS INSIDE ONE CHILD FRAME
and
It is trying to init in another child frame that is why its going to parent option_view.
*note: I was not trying to scream with the caps I was just trying to show where talking was and where the javascript is
Maybe:
$("#vform_").submit();
?
fireEvent is a IE only feature. I don't think including JQuery just to fix this is the best solution. (why add more download time/process time if you can avoid it). Switch to using The W3C equivalent: dispatchEvent.
Take a look at http://www.howtocreate.co.uk/tutorials/javascript/domevents on how to use EventListener...
There are two ways I would suggest you do this, the first with jquery, the second without:
$('.save_bttn').bind('click', function(e) {
if (parent.option_view.document.vform_.dispatchEvent('onsubmit') != false) {
parent.option_view.document.vform_.submit();
}
});
The other is:
<img class="save_bttn" id='somebutton' ... />
document.getElementById('somebutton').onclick = function(e) {
// if(...)
}
I would think that your using this subform() function means that there is something flawed in your approach. I am not certain why you have needed dispatchEvent, as you could have just submitted directly from the onclick event handler, but these should work, or, at least, be close enough so that someone here can correct me. :)

Categories

Resources