项目作者: johvin

项目描述 :
A simple guideline tool based on which you can quickly implement new features guidelines for website users
高级语言: JavaScript
项目地址: git://github.com/johvin/guideline.git
创建时间: 2018-03-20T08:59:01Z
项目社区:https://github.com/johvin/guideline

开源协议:

下载


New Features Guideline (新功能指引)

Version npm
Build Status
Dependencies
Known Vulnerabilities
License

This is a simple guideline tool based on which you can quickly implement new features guidelines for website users.

Usage

There are two ways to play a guideline, a simple way and an advanced way. The simple way is an encapsulation of the advanced way which can do more setting and control the playing of guideline.

Guideline also supports using keyboard shortcuts to control playback. See the relevant part of API for details

Simple way

  1. const guideline = require('guideline');
  2. const visitTimes = parseInt(localStorage.getItem('visitTimes')) || 0;
  3. if (visitTimes === 0) {
  4. const guideOptions = [{
  5. content: 'Welcome, the new features guidelines come online !'
  6. }, {
  7. element: document.getElementById('notificationwrapper'),
  8. content: 'all system messages and notification is here',
  9. style: 'font-size: 20px; color: red;',
  10. position: 'top'
  11. }, {
  12. element: document.querySelector('.datepicker-hint'),
  13. content: 'datepicker hint will tell you the datepicker\'s date range restriction',
  14. position: 'bottom'
  15. }];
  16. guideline(guideOptions, function () {
  17. console.log('guideline is over');
  18. });
  19. }

Advanced way

  1. const guideline = require('guideline');
  2. // something else ...
  3. const guideOptions = [{
  4. content: 'Welcome, the new features guidelines come online !'
  5. }, {
  6. element: document.getElementById('notificationwrapper'),
  7. content: 'all system messages and notification is here',
  8. style: 'font-size: 20px; color: red;',
  9. position: 'top'
  10. }, {
  11. element: document.querySelector('.datepicker-hint'),
  12. content: 'datepicker hint will tell you the datepicker\'s date range restriction',
  13. position: 'bottom'
  14. }];
  15. const gl = new guideline.Guideline(guideOptions, function (total, played) {
  16. console.log('guideline is over, total valid ', total, 'played ', played);
  17. });
  18. // set hint text maximum width
  19. gl.hintTextMaxWidth = 800
  20. // set hint text font size
  21. gl.hintFontSize = 20
  22. // start the guideline
  23. gl.play();
  24. // autoplay the next hint every 3 seconds
  25. const timer = setInterval(function () {
  26. if (gl.hasNext()) {
  27. gl.next();
  28. } else {
  29. clearInterval(timer);
  30. gl.stop();
  31. }
  32. }, 3000);

API

guideline(configuration, callback)

This is the simple way to play a guideline which accepts two parameters whose description are listed in the relevant sections as follows.

guideline.Guideline Constructor (configuration, callback)

This is the advanced way to play a guideline which parameters are the same as guideline(configuration, callback). It will return a Guideline instance based on whose prototype’s method you can do more control during the playing.

configuration - guideline(configuration)

The configuration item should be an array, each of which is an object.

Configuration Subitem Object

Properties:

  • element (HTMLElement, optional) : the guided element. when element is null, the guideline text is centered relative to the browser window.
  • content (string, required) : the guideline text.
  • position (string, optional, defaults to ‘bottom’) : used to set the location of the guideline text relative to the guided element. enumerated type,value is 'top' or 'bottom'.
  • style (string, optional) : custom style for the guideline text.

callback(total, playedAmount) - guideline(configuration, callback)

callback is a function, which will be invoked when the guideline stops. callback takes two parameters total and playedAmount, representing the total amount of valid hints and the actual playback amount of hints.

Guideline instance properties

  • hintTextMaxWidth (number, defaults to 400) : used to limit the hint text maximum width, unit is pixel.
  • hintFontSize (number, defaults to 24) : used to define the hint text font size, unit is pixel.

Guideline instance method

  • play : start the guideline after doing some settings
  • prev : play the previous hint
  • next : play the next hint, if there’s no more hint, stop the guideline and exit
  • hasNext : tell if there is a follow-up hint
  • stop : stop playing the guideline

Keyboard shortcuts

Guideline supports some keyboard shortcuts to play the next or previous hint as follows.

keyboard action
arrow right play next
enter play next
space play next
arrow left play previous
backspace play previous
esc stop playing

CHANGELOG

CHANGELOG

License

MIT

References