To get started, use
bower install ment.io --save or
npm install ment.io --saveThen add 'mentio' to your app’s module dependency list.
Directives
mentio For the mentio directive, specification of options can either be done inline, within the same element for one triggering character, or using a series of configurations if there are a multiple applicable triggering characters.
When detecting user input that should show a typeahead menu, the following rules apply:
- A specified trigger character is present in the text preceding the current caret location (e.g. @)
- A space precedes the trigger character
- The text following the trigger character contains no spaces up to the current caret location When a match is found, the current text after the trigger character is assigned to the scope property specified in the
mentio-typed-term attribute if present. It is only possible for one trigger character to cause a menu to show at a time. Also, only one menu will display on a given page at a time.
Definition of menu behavior for each desired trigger character can be specified with separate
mentio-menu directives. However the
mentio directive does not require separate
mentio-menu directives. If only one trigger character is needed, the
mentio-trigger-char,
mentio-items,
mentio-template-url,
mentio-search, and
mentio-select attributes from the
mentio-menu directive can be specified directly along side the
mentio directive.
To support macro expansion, a translation table to use for macros can be assigned through the
macros attribute which will expand typed sequences of characters into predefined strings of HTML or text.
Attributes
ng-model Required. An ngModel is required on the element for mentio to be able to operate.
mentio-id Optional. An angular expression representing the ID of the mentio element. This value is matched by the
mentio-for attribute on any separate
mentio-menu elements. If no
mentio-id is specified, the
id html attribute will be used to match
mentio-for. The
mentio-id is unnecessary if there is only one trigger character and all attributes are specified on the
mentio directive.
mentio-typed-term Optional. If specified, binds a scope property that will be assigned the current value of the typed term when the mentio menu is active.
mentio-macros Optional. Specifies a JSON map of macro translations. The key should be a simple sequence of characters, not including spaces. The key will be matched case-insensitive. When a match is detected, the value in the macro table will be expanded in place of the macro the user typed. An example from the sample demo in
scripts.js:
$scope.macros = { 'brb': 'Be right back', 'omw': 'On my way', '(smile)' : '<img src="http://a248.e.akamai.net/assets.github.com/images/icons/emoji/smile.png"' + ' height="20" width="20">' };mentio-require-leading-space Optional. When true, specifies that the menu will only be displayed if the trigger character is preceded by a space. This option can benefit the user by disambiguating typeahead text from other text that might normally contain the configured trigger character, but for some languages like Chinese, spaces cannot be required.
mentio-iframe-element Optional. Specifies an iframe DOM element within which the ment.io menu will be shown. This is useful for situations where the actual control is a textarea, but the editor is presented in an iframe, like TinyMCE.
mentio-select-not-found Optional. Will run the mentio-select function passing a the
typedText scope variable in the label property of a JSON object when the typedText will become empty (after a space was typed, for instance). This is useful for creating new items dynamically even if they do not exist in your backend service yet (e.g. tags).
Provided Scope Properties
typedTerm The typedTerm scope property is bound to the text currently after the trigger char. This can be referenced from within the
mentio-menu template to highlight text when presenting menu items.