Giter VIP home page Giter VIP logo

angular-onselect's Introduction

Angular On Select Directive

license:mit Travis Coveralls npm npm Bower

Directive that allows for click-and-drag or just a click for highlighting words within any container regardless of type. The on-select attribute value is evaluated whenever a word or a group of words have been highlighted. The selection object is passed in as selection in the evaluated component.

Additionally, if auto-highlight is also present, upon selection the selected text is automatically highlighted. This is * effectively the same as calling selection.highlight(..) with some basic defaults.

If snap-to-word is present, the selected text is expanded to include whole words (including punctuation). If snap-to-word is turned on, simply clicking on a word is the same as highlighting the whole word.

Example Usage

The below example shows how to use on-select to automatically highlight a word and then after 2000ms the highlight is removed. This is a running demo here.

angular.module('example', ['onSelect'])
  .controller('ExampleController', function() {
    var vm = this;
    vm.handler = handler;
    return this;

    function handler(selection) {
      setTimeout(function() {
        selection.removeHighlight();
      }, 2000);
    };
  });
<div ng-controller="ExampleController as vm">
  <div on-select="vm.handler(selection);" auto-highlight snap-to-word>
    Bacon ipsum dolor amet ut beef ribs culpa...
  </div>
</div>

Installation

$ npm install --save angular-onselect

   -- or --

$ bower install --save angular-onselect

Submitting Issues

Please file a github issue for any problems or feature requests.

Contributing

See Contributing

License

Licensed under MIT

angular-onselect's People

Contributors

clarkmalmgren avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular-onselect's Issues

Better Interface for Creating a Custom Highlighter

The block is created using the fundamental javascript function document.createElement(tagname).

So a custom highlighter is a authored weirdly:

function onSelect(selection) {
  selection.highlight('div', function(span) {
    span.className = 'well well-sm well-warning inline-block';
    span.setAttribute('ng-click', 'vm.handleReclick();');
  }
}

It just looks ugly. Instead, I'd like to see:

function onSelect(selection) {
  selection.highlight('<span class="well well-sm well-warning inline-block" ng-click="vm.handleReclick();"></span>');
}

I think that this could be accomplished by using $compile(), but I have not verified that yet.

n00b readable contributing guidelines

Starting from

  1. fork and clone the repository
  2. npm install or some such thing
  3. start a web server?

I'm not exactly sure what's involved here, but I'm a complete n00b that will actively contribute to this project if I can just figure out how to get started :)

Minification issue

I have a minification issue. After minification, I get this error

Unknown provider: eProvider <- e <- onSelectDirective

The minified version looks like this:

function() {
    "use strict";
    angular.module("onSelect", [])
}(),
function() {
    function e(e) {
        return {
            restrict: "A",
            scope: !1,
            link: function(t, n, r) {
                var i = {
                    snapToWord: "snapToWord"in r,
                    highlight: "autoHighlight"in r
                };

Here's a possible solution:

http://stackoverflow.com/a/13459722/3419300

Unfortunately I don't have experience on building directives, so before putting time on it maybe somebody else is able to find an easy solution (if nobody is able, I'll try by myself of course)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.