1.3.3 • Published 7 years ago

ng-qtip2 v1.3.3

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

ng-qtip2

qTip 2 directive for AngularJS.

Features

  • Two way bind support for content and title
  • Remote template file support
  • Customizable delay, trigger types, position, CSS classes and tip position

How to use

Manually include

  1. Make sure the file is included in your HTML:
  2. Load the ngQtip2 module in your app.js's configuration

Using bower

  1. Install with bower

    bower install ng-qtip2
  2. Make sure the file is included in your HTML:

    <script type="text/javascript" src="bower_components/ng-qtip2/ng-qtip2.js"></script>

Overriding default options

You may override any options for qTip tips globally in your module.
Do this by injecting qtipDefaultsProvider inside your app's config stage, and using the setDefaults method.
Example config stage:

angular.module('myApp', ['ngQtip2']).config(function(qtipDefaultsProvider) {
  qtipDefaultsProvider.setDefaults({
    position: {
      adjust: {
        x: 10,
        y: 20
      }
    }
  });
});

Available options

Interpolated means you can assign expressions inside using {{expression}} format to create dynamic content. Non-interpolated are immediately evaluated as they are. For example, qtip-visible expects a boolean condition expression inside (e.g. qtip-visible="title.length > 0" or qtip-visible="true").

OptionTypeDescription
qtiprequired stringThe qTip content. This can be left blank and overridden with other properties such as qtip-content, qtip-title, qtip-selector, and qtip-template.
qtip-contentoptional stringThe qTip content. Overrides qtip.
qtip-titleoptional stringWhen specified, puts the value in qTip's built-in title option.
qtip-visibleoptional default=falseWhether the qTip is visible immediately.
qtip-disableoptional default=falseWhether the qTip is disabled completely. Useful with ng-repeat and conditions inside the repeater, for example.
qtip-fixedoptional default=trueWhether the qTip sticks around after the mouse leaves it (up until a certain qtip-delay is reached)
qtip-delayoptional default=100How long to wait before the qTip disappears after it becomes inactive when the mouseleave hide event is used (i.e, by default), in ms.
qtip-adjust-xoptional default=0Position the qTip more to the left or right, relatively, in pixels. Use a negative value to move it left.
qtip-adjust-yoptional default=0Position the qTip more to the top or bottom, relatively, in pixels. Use a negative value to move it up.
qtip-show-effectoptional default=trueIf false, will disable animating the showing effect of qTip (this is useful when the dynamic positioning shows a flicker and animates the qTip from the side of the element or screen before positioning it correctly).
qtip-hide-effectoptional default=trueIf false, will disable animating the hiding effect of qTip (this is useful when the dynamic positioning shows a flicker and animates the qTip from the side of the element or screen before positioning it correctly).
qtip-modal-styleoptional default={}Set inline style for the qTip. This should be a JS object that contains the JS-esque style properties (such as maxHeight: '100vh')
qtip-tip-styleoptional default={}Set inline style for the qTip's tip. This should be a JS object that contains the JS-esque style properties (such as maxHeight: '100vh'), and may also contain tip specific implementations (such as mimic, and corner).
qtip-classoptional default=''Classes to use for the qTip, you can use these to style the qTip easier with CSS.
qtip-selectoroptional interpolatedCSS selector for element to use. When specified, the element found using the selector and jQuery will override any other content specified.
qtip-templateoptional interpolatedRemote template to use for qTip. When specified, the template will be used for the qTip content and will override any other content specified. Use in conjuction with qtip-template-object
qtip-template-objectoptionalWill assign a model to the qTip template for use inside the template's content. You can reference this using {{object}} inside the template.
qtip-eventoptional interpolatedWhat event triggers the qTip to show up.
qtip-event-outoptional interpolatedWhat event triggers the qTip to hide after being shown.
qtip-showoptionalObject for the qtip 'show' option (see qTip docs). Will override qtip-event
qtip-hideoptionalObject for the qtip 'hide' option (see qTip docs). Will override qtip-event-out
qtip-myoptional interpolatedqTip bubble tip position relative to the qTip. "Put my tip at the qTip's..."
qtip-atoptional interpolatedqTip bubble tip position relative to the qTip. "Put my tip at the qTip's..."
qtip-persistentoptional default=trueIf false, qTip will be re-rendered next time it is open.
qtip-optionsoptionalObject for the entire qtip initializer. This will merge itself into the other options specified in this table, overriding any existing keys. This is to explicitly override any options that are not handled the way you expect within these options, or to use options that are not yet implemented.
qtip-apioptionalPass an empty reference object to this attribute to get back an "api" object (see below for api documentation)

API Object

access the api by adding a scope object to qtip-api

<span qtip="Hi!" qtip-api="tip"></span>

and then access it in your code:

$scope.tip.api().get("position.my")

Because of the way qtip2 works, the api won't be available until you first render it. This means that it won't be ready until the user showed it (hovered on the associated directive) or you've passed to the options {prerender: true} which will force qtip2 to render the qtip on page load.

the qtip-api object has 3 methods:

  • isReady()

    Returns true/false because of the way qtip2 works, the api won't be available until you first render it. isReady() will tell you if the api object is ready for use

  • api()

    Returns a qtip2 api object for a full documentation about the api object, see: http://qtip2.com/api

  • apiPromise()

    Returns a $q promise holding the api object upon resolve example:

    $scope.tip.apiPromise().then(function(api) {
      console.log(api.get("content"));
    });

Examples

1. Regular qTip

<span qtip="Hi there, {{name}}!">{{name}}</span>

2. Immediately visible qTip

<span qtip="Woah!" qtip-visible="true">Keanu</span>

3. qTip from template, with multiple objects

<span qtip qtip-template="my_remote_template.html"
      qtip-template-object="{person: myPerson, callback: myCallback}">
    {{person.name}}
</span>
my_remote_template.html
<span ng-click="object.callback(person)">
    Hi {{object.person.name}}, you are {{object.person.age | pluralize:'year'}} old!
</span>

4. Dynamic qTip position

<ul>
    <li ng-repeat="person in people track by $index"
        qtip="{{$index}}"
        qtip-my="{{getQtipMy($index)}}"
        qtip-at="top {{$index > 15 ? 'center' : 'bottom'}}">
        {{person.name}}
    </li>
</ul>

Contributing

  1. Fork this repository
  2. Make the desired changes
  3. Test your implementations, and that nothing was broken
  4. To auto-compile JS from Coffee, copy pre-commit.hook to .git/hooks
  5. Commit & Push to your fork (auto-compile should do its magic during commit)
  6. Create a pull request