1.1.23 • Published 4 years ago

easy-marker v1.1.23

Weekly downloads
63
License
ISC
Repository
github
Last release
4 years ago

easy-marker

easy-marker is a library for marking text in html. An example is as follows:

demo

Install

npm i easy-marker

Usage

import EasyMarker from 'easy-marker'

const easyMarker = new EasyMarker
const container = document.querySelector('xxxx')
easyMarker.create(container)

API

new EasyMarker(options)

Creates an instance of EasyMarker.

ParamTypeDescription
optionsObjectoptions
options.menuItemsArray.<Object>menu item option
options.menuItems[].textstringmenu text
options.menuItems[].handlermenuClickHandlermenu item click handler
options.menuTopOffsetnumber | stringthe offset from the top of the menu relative screen, default 0.

Example

const em = new EasyMarker({
  menuTopOffset:'2rem',
  menuItems: [
    {
      text: '划线笔记',
      handler: function (data) {
        console.log('划线笔记', data, this)
        this.highlightLine(data,1)
      }
    },
    {
      text: '分享',
      handler: (data) => {console.log('分享',data)}
    },
    {
      text: '复制',
      handler: (data) => {console.log('分享',data)}
    }
  ]
 )

 em.create(document.querySelector('.article-body'),
   document.body,
   document.querySelectorAll('.article-body>:not(.text)')

easyMarker.create(containerElement, scrollContainerElement, excludeElements)

Initialization

Kind: instance method of EasyMarker

ParamTypeDescription
containerElementHTMLElementcontainer element
scrollContainerElementHTMLElementscroll container element
excludeElementsArray.<HTMLElement>not included elements

easyMarker.getSelectText() ⇒ string

Get the selected text

Kind: instance method of EasyMarker

easyMarker.highlightLine(selection, id, meta)

Highlight the lines between the specified nodes

Kind: instance method of EasyMarker

ParamTypeDescription
selectionObjectselection
selection.anchorNodeNodestart node
selection.anchorOffsetnumberstart node's text offset
selection.focusNodeNodeend node
selection.focusOffsetnumberstart node's text offset
id*line id
meta*meta information

Example

const id = 2;
const selection = {
  anchorNode: textNodeA,
  anchorOffset: 1,
  focusNode: textNodeB,
  focusOffset: 2
};
const meta = { someKey: 'someValue' };
em.highlightLine(selection, id, meta);

easyMarker.highlightLines(lines)

Highlight multiple lines

Kind: instance method of EasyMarker

ParamType
linesArray.<Object>
[lines[].id]*
[lines[].meta]*
lines[].selectionObject
lines[].selection.anchorNodeNode
lines[].selection.anchorOffsetnumber
lines[].selection.focusNodeNode
lines[].selection.focusOffsetnumber

Example

const id = 2;
const selection = {
  anchorNode: textNodeA,
  anchorOffset: 1,
  focusNode: textNodeB,
  focusOffset: 2
};
const meta = { someKey: 'someValue' };
em.highlightLines([{selection, id, meta}]);

easyMarker.cancelHighlightLine(id) ⇒ boolean

Cancel highlight

Kind: instance method of EasyMarker

ParamTypeDescription
id*line ID

easyMarker.onHighlightLineClick(cb)

Highlight line click handler

Kind: instance method of EasyMarker

ParamType
cbhighlightLineClickHandler

easyMarker.destroy()

Destroy instance

Kind: instance method of EasyMarker

EasyMarker.create(containerElement, scrollContainerElement, excludeElements) ⇒ EasyMarker

Initialization factory

Kind: static method of EasyMarker

ParamTypeDescription
containerElementHTMLElementcontainer element
scrollContainerElementHTMLElementscroll container element
excludeElementsArray.<HTMLElement>not included elements

EasyMarker~menuClickHandler : function

Menu item click handler

Kind: inner typedef of EasyMarker

ParamTypeDescription
selectionObjectselection
selection.anchorNodeNodestart node
selection.anchorOffsetnumberstart node's text offset
selection.focusNodeNodeend node
selection.focusOffsetnumberstart node's text offset

EasyMarker~highlightLineClickHandler : function

Menu item click handler

Kind: inner typedef of EasyMarker

ParamTypeDescription
id*line ID
meta*meta information
selectionObjectselection
selection.anchorNodeNodestart node
selection.anchorOffsetnumberstart node's text offset
selection.focusNodeNodeend node
selection.focusOffsetnumberstart node's text offset
1.1.24-0

4 years ago

1.1.23

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.12.9

4 years ago

0.12.8

4 years ago

0.12.7

4 years ago

0.12.6

4 years ago

0.12.5

4 years ago

0.12.4

4 years ago

0.12.3

4 years ago

0.12.2

4 years ago

0.12.0

4 years ago

0.12.1

4 years ago

0.11.0

4 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.0

6 years ago

0.6.0-0

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago