Lovely.IO

The Next Generation of Front-Side

Package Info

Links
Size
1.99 KB (gzipped)
Tags
forms, textarea
Author
Nikolay Nemshilov
License
MIT
Versions
CDN Links
Dependencies

Osom-Area

Osom-Area is custom textarea wrapper for lovely.io, features:

Usage Principles

Hook up the module through the lovely.io interfaces and instantiate the OsomArea class

<textarea id="my-area"></textarea>
<script type="text/javascript">
  Lovely(['osom-area-1.0.0'], function(OsomArea) {
    var area = new OsomArea('#my-area', {options: ...});
  });
</script>

The first parameter can be either a css rule, a raw dom HTMLTextArea object or a lovely.io dom.Input instance.

API Reference

The OsomArea class is inherited from the dom.Input class and has all the same methods.

Additionally it has a shortcut method to work with the selections, called #select

area.select('some text'); // select a matching piece of text
area.select(1, 22);       // select a range

area.select(); // -> returns the current selection range

Also every OsomArea instances has a property called selection with the following API

area.selection.offsets();         // returns the current selection offsets
area.selection.offsets(1,22);     // sets current selection offsets

area.selection.text();            // returns currently selected text
area.selection.text('some text'); // selects matching text in the textarea

area.selection.position();        // returns absolute position of the cursor in the document

area.selection.save();            // saves the current selection range
area.selection.restore();         // restores previously saved selection range

Options

Autocompletion

OsomArea instances have additional method called #autcoplete which can take two types of parameters, a callback function where you can make async calls to the server or an Array of options, so you can hook up Ajax autocompleter kinda like that

Lovely(['osom-area', 'ajax'], function(OsomArea, Ajax) {
  var input = new OsomArea();

  input.autocomplete(function(last_word) {
    Ajax.get('/some-url.json?q='+ last_word, {
      success: function() {
        input.autocomplete(this.responseJSON);
      }
    });
  });
});

Copyright And License

This project is released under the terms of the MIT license

Copyright (C) 2012 Nikolay Nemshilov