All Projects → leodido → ng-caret-aware

leodido / ng-caret-aware

Licence: MIT License
AngularJS directive for caret aware elements

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ng-caret-aware

markee
Visual text selection
Stars: ✭ 22 (+83.33%)
Mutual labels:  caret, cursor
Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+8425%)
Mutual labels:  input, cursor
uchiwa-web
Uchiwa is a simple yet effective open-source dashboard for the Sensu monitoring framework.
Stars: ✭ 17 (+41.67%)
Mutual labels:  angularjs
angular-easy-social-share
An easy way way to share the current page on an AngularJS app with Twitter, Facebook and LinkedIn.
Stars: ✭ 32 (+166.67%)
Mutual labels:  angularjs
WebStore-Spring-MVC
WebStore is a full fledged online shopping system built in Spring-MVC. It uses JSP for view templating and MySql at the database end.
Stars: ✭ 29 (+141.67%)
Mutual labels:  angularjs
angular-environment
AngularJS Environment Plugin
Stars: ✭ 78 (+550%)
Mutual labels:  angularjs
mongoose-graphql-pagination
GraphQL cursor pagination (Relay-like) for Mongoose models.
Stars: ✭ 29 (+141.67%)
Mutual labels:  cursor
wp-testing
WordPress testing plugin
Stars: ✭ 12 (+0%)
Mutual labels:  angularjs
TravelWebApplication-Virtugo
This project is to develop a travel planner system, which describes about the climatic conditions, interesting places to visit, top hotels in the area and some additional features like travel reminders depending on the user’s destination. We have used Angular JS, HTML 5 for front end and Spring boot, MySQL for backend.
Stars: ✭ 21 (+75%)
Mutual labels:  angularjs
ember-phone-input
An Ember.js component to handle international phone numbers
Stars: ✭ 22 (+83.33%)
Mutual labels:  input
tubular
A set of AngularJS directives designed to rapidly build modern web applications
Stars: ✭ 44 (+266.67%)
Mutual labels:  angularjs
vaadin-text-field
The themable Web Component providing input controls. Part of the Vaadin components.
Stars: ✭ 29 (+141.67%)
Mutual labels:  input
ionic4-angular6-crud-example
Building CRUD Mobile App using Ionic 4, Angular 6 and Cordova
Stars: ✭ 50 (+316.67%)
Mutual labels:  angularjs
Swastika-IO-Admin
✔ [ SIOA ] Swastika I/O Admin dashboard template based on Bootstrap 4
Stars: ✭ 18 (+50%)
Mutual labels:  angularjs
Angular-Firebase-Sortable-Table
Angular Firebase Sortable Table is a module that makes tables creation with firebase an easy task.
Stars: ✭ 28 (+133.33%)
Mutual labels:  angularjs
svelte-search
Accessible, customizable Svelte search component
Stars: ✭ 17 (+41.67%)
Mutual labels:  input
angular-openweather-app
A weather forecast app written in AngularJS
Stars: ✭ 54 (+350%)
Mutual labels:  angularjs
ng-loader
Webpack loader for AngularJs components
Stars: ✭ 28 (+133.33%)
Mutual labels:  angularjs
tom-select
Tom Select is the hybrid of a textbox and select box. Forked from selectize.js to provide a framework agnostic autocomplete widget with native-feeling keyboard navigation. Useful for tagging, contact lists, etc.
Stars: ✭ 520 (+4233.33%)
Mutual labels:  input
jquery-rsSliderLens
UI slider control that magnifies the current value
Stars: ✭ 20 (+66.67%)
Mutual labels:  input

Caret aware inputs

Bower Codeship Coveralls branch

AngularJS directive for caret aware elements.

Put it on your HTML elements (inputs or textareas, for now) and it will track the caret (i.e. cursor) exporting its position in a variable (named after the value assigned to the directive attribute) appended to the parent scope.

Moreover, it will expose an API (via its controller) to read and write caret position.

Caret aware directive is designed to be cross-browser.

Weight: < 2KB.

See input demo live here or textarea demo live here.

Releases

Latest release files are in the dist directory of this repository.

Note

At the moment this directive can be used as attribute or as comment.

Usage

Include AngularJS, and the build you desire (e.g., dist/caretaware.min.js).

Then load the leodido.caretAware AngularJS module. E.g.,

var app = angular.module('myAwesomeModule', ['leodido.caretAware']);

Instantiate the directive.

<input type="text" name="myname" caret-aware="cursor"/>

And the parent scope of this element will contain a cursor variable - e.g., $scope.cursor - tracking the caret position of your element's content.

Alternatively you can simply instantiate it this way:

<input type="text" name="myname" caret-aware/>

In such case the parent scope will contain a caret variable - e.g., $scope.caret - tracking the caret position of your input element.

Controller usage

  • Want to use this directive APIs/controller?

See example directory for further details. For example here.

  • Want to use this directive APIs in your custom directive?

Simply require it. E.g.,

var a = angular.module('demo', []);
a.directive('test', function() {
  return {
      restrict: 'A',
      require: ['caretAware'],
      // ...
      link: function(scope, iElem, iAttrs, caretAwareController) {
        // caretAwareController.setPosition(1);
        // ...
      }
  }
});

APIs

This is the public API to manipulate and retrieve the caret position.

/**
 * Retrieve the namespace of the directive instance
 *
 * @return {!string}
 */
caretAwareController.getNamespace()
/**
 * Retrieve the element caret position
 *
 * @return {!number}
 */
caretAwareController.getPosition()
/**
 * Manually set the element caret position and the scope caret variable
 *
 * @param {!number} pos
 * @return {!leodido.controller.Caret}
 * @throws TypeError
 */
caretAwareController.setPosition(pos)
/**
 * Retrive information about the current selection
 *
 * @return {{start: !number, end: !number, length: !number, text: !string}}
 */
caretAwareController.getSelection()

Note

  1. the scope caret variable value - i.e., $scope.caret - is asynchronously bound to the actual element caret position, so during the digest cycle the getPosition() could not reflect the scope caret variable value

  2. in some browser (e.g., Chrome 42.0.2331) can happen that setPosition() will not be instantly applied, so the getPosition() could return the previous value; see this issue.

Installation

Install it via bower.

bower install ng-caret-aware

Or, you can clone this repo and install it locally (you will need npm, of course).

$ git clone [email protected]:leodido/ng-caret-aware.git
$ cd ng-caret-aware/
$ npm install

Distribution

In the dist directory you can find both development and production ready library files:

  1. dev.caretaware.min.js and its sourcemap (i.e., dev.caretaware.min.js.map file) can be used for development purposes

  2. caretaware.min.js is the production version of this AngularJS module

Build

Build is handled through Gulp and performed mainly via Google Closure Compiler.

Need help? Run gulp help!

# Usage
#   gulp [task]
# 
# Available tasks
#   build                                  Build the library 
#    --banner                              Prepend banner to the built file
#    --env=production|development          Kind of build to perform, defaults to production
#  bump                                    Bump version up for a new release 
#   --level=major|minor|patch|prerelease   Version level to increment
#   clean                                  Clean build directory
#   help                                   Display this help text
#   karma                                  Run karma tests
#   lint                                   Lint JS source files
#   protractor                             Run protractor E2E tests
#   version                                Print the library version

Tests

This library has been unit tested for Chrome and Firefox.

At the moment coverage is almost complete.

Furthermore E2E tests are provided for Chrome and Firefox, too.

See test directory for details.

Aknowledgements

  • Thanks to @leogr for his suggestions, and improvements. Particularly for his help fixing issue #14.

  • Thanks for the inspiration to all authors of snippets (that are present on the web) related to the caret management.


Analytics

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].