Hi,
I am new to js and jquery. Usually I try to learn things by fullfilling a certain task and read the docs/manuals as much as possible to do so.
Currently, I try to get a textarea element to behave a little more like a desktop text editor.
It should be able to write a tab in the textarea when pressing tab and when pressing enter it should be able to intend the cursor in the new line if the current line is intendend.
I found the the plugin "tabby" which works fine with TAB and SHIFT+TAB. For the behavior of enter I currently try to modify the tabby plugin but somehow Im not getting to the point after enter was pressed.
So far, it counts the tabs at the beginning of the line where enter is pressed...and since then I try to find point where to proceed with either writing the new line and the tabs and prevent the default behavior of enter or let the default enter behavior happen and write the counted tabs to the new line after enter was pressed
I hope you could help me out here, maybe I missed something while reading the basics or its to advanced, I don't know, but Im stuck. :-)
To make myself more clear I will add the code of the tabby plugin Im modifing, shortend and commented. This should give you the most precise idea of what Im trying to do.
Thanks in advance...
- (function($) {
- $.fn.tabby = function(options) {
- var opts = $.extend({}, $.fn.tabby.defaults, options);
- var pressed = $.fn.tabby.pressed;
-
- return this.each(function() {
- $this = $(this);
- var options = $.meta ? $.extend({}, opts, $this.data()) : opts;
- var enter = false;
- var intends = 0;
-
- $this.bind('keydown',function (e) {
- var kc = $.fn.tabby.catch_kc(e);
- if (16 == kc) pressed.shft = true;
- if (17 == kc) {/*...*/}
- if (18 == kc) { /*...*/ }
- if (9 == kc && !pressed.ctrl && !pressed.alt) {/*...*/}
- //enter
- if (13 == kc) {
- //passes a HTMLTextAreaElement object
- intends = process_enter ($(e.target).get(0));
- /*
- returns the number of intends, now my problem:
- I assume that I need to write the conuted tabs
- in the new line right after the keydown event
- when the cursor set to the new line
- ...but where???
- */
- }
- }).bind('keyup',function (e) {/*...*/
- }).bind('blur',function (e) {/*...*/
- });
- });
- };
- $.fn.tabby.catch_kc = function(e) { /*...*/ };
- $.fn.tabby.pressed = {/*...*/};
-
- function debug($obj) { /*...*/};
- function process_enter (o) {
- /*
- counts the tabs at the bginning of the line
- */
- };
-
- function process_keypress (o,shft,options) {/*...*/}}
-
- // plugin defaults
- $.fn.tabby.defaults = {tabString : String.fromCharCode(9)};
-
- function gecko_tab (o, shft, options) {/*...*/}
- function ie_tab (o, shft, options) {/*...*/}
- })(jQuery);
I hope it's explained enough and understandable.
Please let me know if not!
Cheers,
anyrandomusername