
Show HN: Behave.js – Coding Behaviors for textarea elements - jakiestfu
http://jakiestfu.github.com/Behave.js/
======
danso
Ok I'll be the pendant that says it...you _probably_ can't appropriate the
image of Austin Powers for your open source library. Not that Mike Myers seems
the type to flip out about it, but his movie studio probably is.

Otherwise, great work...and it behaves reasonably well even on iOS

~~~
codewright
I'll be the pedant to mention that a pendant is worn around the neck.

You like this? On-demand editing services: chris@edithero.com

Clickable: <http://www.edithero.com/>

~~~
aarondf
Good hustling! (Serious, not sarcastic.)

Your comment was funny and provided value (now I know about your service).
Well played.

~~~
jgj
It's funny, in another thread he got voted down as close to #f6f6ef as I've
ever seen and scolded to boot

~~~
danso
For the record, I approve and upvoted. I had half-written a comeback but
decided I was not actually clever and that I deserve to be mocked. "Pendant"
indeed.

~~~
codewright
Thanks everybody! I'll do a Show HN post after we finish fiddling with some
conversion tracking bits.

Getting scolded by a 3 karma account was fun :)

------
Permit
I like this a lot. I really wish they'd add the tab functionality to Stack
Overflow. I can't count the times I've tabbed out of the text box there.

------
evincarofautumn
You should have the option to make backspace delete a full level of
indentation, if soft tabs are on.

~~~
MasterScrat
Keeping the indentation level on new lines would be nice too.

~~~
jakiestfu
Indentation levels should be converting line to line, is it not for you?

~~~
MasterScrat
Nope (Chrome 24.0.1312.56 on OS X 10.6.8).

------
nbashaw
This is awesome. I'm using <http://ace.ajax.org/> right now in production and
it's a huge heavyweight pain (but still the best thing out there). If only
this had syntax highlighting i'd switch in an instant.

~~~
chr1
Maybe you'll like <http://kueblc.github.com/LDT/examples/generic.html>? but if
you fix undo, add bracket matching, etc it will become huge too.

Also wanted to ask why do you think that ace is a pain? I agree that it's big,
but seems to work ok?

~~~
TomasSedovic
Thanks so much for the LDT link, it's exactly what I was looking for (and
thought impossible).

I can't speak for the GP, but my problem with ACE et al. is that they replace
the textarea with their own HTML structure (e.g. a div for every line). I
understand the reason why, but it means they have to reimplement all the
textbox behaviour and they never get it completely right.

For example: when I double-click on a word in the textbox I'm writing this in,
and then middle-click somewhere else, the word gets pasted there.

In ACE, it pastes a different text in a different location.

ACE is brilliant if you want to a full-fledged text editor. But it's an
overkill if all you need is a normal textarea with some colours.

------
thewarrior
Really good work . Was reading your code to catch up on some javascript , but
didn't understand what you're doing here . Surely this is a bug ?

[https://github.com/jakiestfu/Behave.js/blob/master/behave.js...](https://github.com/jakiestfu/Behave.js/blob/master/behave.js#L211)

------
evoxed
Hey, this looks handy! I just wrote something kinda similar as part of an ad-
hoc UI layer that just had to be done in HTML/JS. At first I was horrified,
but by a couple hundred lines in I realized how nice it would feel to finally
tame those meager input boxes into full on forces of good. ;)

------
fidz
Just curious who is the person in the background page?

~~~
tantalor
<https://www.google.com/search?q=austin+powers>

------
jamiebicknell
Good work, like it a lot. I almost feel allowing tabs should be a browser
based setting, I'd have it enabled, but I can imagine other people wouldn't
never need to use a tab.

I built something similar for keeping indentation/bullets/lists on new lines
to assist with Markdown in an ordinary textarea ->
<http://jamiebicknell.github.com/Markdown-Helper/>

ps: long time lurker, first time poster.

~~~
jakiestfu
The option to disable tabs behavior is there. When to do that is up to you;]

------
valgaze
Great tool and I'm enamored with the layout- scrolling background, AP stays
with you.

Not sure how to repeat it every time but weird artifact quirk if one scrolls
to the bottom on iPad safari & scrolls back up:
<http://i.imgur.com/Hby2ZsL.jpg>

~~~
tantalor
The layout might be familiar,

<http://meyerweb.com/eric/css/edge/complexspiral/demo.html>

The Internet Archive pegs that page to October 2001. That's like 4 or 5
Internets ago.

~~~
nbashaw
That's just background-position: fixed; The background in this page scrolls
but austin powers is position: fixed; bottom: 0; left: 0;

------
WickyNilliams
Question: What does this do for accessibility if navigating with a keyboard?
How would one genuinely tab out of the field?

Suggestion: Big notice somewhere saying "NO JQUERY DEPENDENCY". Things are so
bad these days I assume jQuery dependency until I see something stating
otherwise!

------
jakiestfu
Since posting and receiving positive feedback, I have added support for
unindentation, and multi-line indent/unindent. Will see about adding more
features tomorrow! Want to keep this light, it's almost there though. Next is
IE support.

------
Ygg2
Auto expanding for ', [, { (, " is great, but this should be configurable on a
language basis. In other languages it's not uncommon to have things like
`<http://uri.com`> or |Special syntax|

------
kalms
This is extremely cool. Thank you!

Sidenote: The name conflicts a bit with
<http://kennknowles.github.com/behave.js/> \- Not sure if that matters to you.

------
bink-lynch
This is great! I removed Ace because it was too heavy for my purpose.

Indent Issue:

Type in at least 3 lines, highlight the middle lines using shift+down-arrow,
tab(indent), notice the line below the highlighted lines indents too.

~~~
jakiestfu
I see what you're talking about. Coda and Aptana both do the same thing, and
the reason is you're selecting the \n new line character when you do
shit+down-arrow. Try shift + down-arrow + left-arrow

~~~
bink-lynch
True; I am getting my habits from Sublime Text 2 and Eclipse. These don't
indent the unhighlighted line below. Guess there are two ways to go :)

------
hilti
Great landing page. Just add syntax highlighting and it'll be perfect.

------
user24
It absolutely crashed Firefox 18.0.1 under Mac. I typed

hgjj]{return}{return}{return}{return}

and it just beachballed. I had to force quit the browser. Happened the second
time I tried it too.

~~~
chewmieser
Chromium 24.0.1302.0 (162733) on OS X 10.8.2: Same issue as above, although I
just had to close out the tab instead of forcing the browser to close.

The issue is with the ']', and ONLY after I hit the return key. The entire
page becomes unresponsive afterwards.

~~~
jakiestfu
Fixed!

------
DoubleCluster
Ohh... shiny!

Can we also get Elastic tabstops? <http://nickgravgaard.com/elastictabstops/>

~~~
jakiestfu
How would you want the definition to be? How would you "activate" elastic tab
stops?

------
tantalor
> var editor = new Behave({

> var editor = Behave({

Is it a constructor or not?

~~~
state
I wish it could be var editor = now Behave({

~~~
jeffmess
var editor = oh Behave({

------
ctruman
<http://www.youtube.com/watch?v=F1lJFlB-89Q>

------
tantalor
Auto indent should indent when a newline is nested in parentheses, like this:

    
    
      foo(1,
          2,
          3)

~~~
jakiestfu
Right now, it is easy to add support for indentation breaks, but it would
function like braces or brackets. I'll look into this for parenthesis
tomorrow, thanks!

------
BOSH
I like it very much. Simple and elegant solution. Will try to find a use for
this lib.

------
est
Now please add mouse-hover hint box, dropdown list for auto completion and I
am sold

~~~
visarga
If only TextWrangler had auto-completion and auto-pairing of brackets and
quotes.

~~~
bink-lynch
Have you looked at Sublime Text 2?

<http://www.sublimetext.com/2>

I switched about a year ago and I am very pleased.

EDIT: This shows it off better: <http://www.sublimetext.com/>

------
justplay
It is cool but it will more cool if you add highlighting.

~~~
Narretz
Ideally, highlighting should be pluggable into the textarea from another
source.

~~~
justplay
Certainly,but it'll more awesome if it included by default. It will give a
more IDE type look .

------
culshaw
I can't seem to get it to work on Chrome(24) on a Mac :(

~~~
bink-lynch
Works for me on Mac/Chrome 24.0.1312.56.

------
thomasfl
Works great! Seems to have issues with IE 9 though.

------
apathetic
When you undo, it's undoing it very weirdly.

------
swah
This is my FUD regarding adopting AngularJS: most exciting things in
Javascript world happen either in the jQuery world, or on top of bare-bones
Javascript.

------
solarbunny
Try to type in: {}]]] and press Enter...

~~~
wheaties
Ok, looks like you found a bug which sends things into an infinite loop.

------
Inversechi
Awesome - Well done!

