项目作者: Shai1436

项目描述 :
A highly customizable action popover for the selected text
高级语言: JavaScript
项目地址: git://github.com/Shai1436/TextPopover.js.git
创建时间: 2019-05-01T16:43:47Z
项目社区:https://github.com/Shai1436/TextPopover.js

开源协议:MIT License

下载



Text Popover



A javascript snippet which provides a highly customizable popover with a set of options, over the selected portion of text.


Live Demo

Usage

To get started with Selection.js, download the Script and add it to your project

Basic Usage

  1. <script src="text-popover.min.js"></script>
  2. <script>
  3. var popover = new TextPopover();
  4. popover.init();
  5. </script>

Advanced Usage

  1. <script src="text-popover.min.js"></script>
  2. <script>
  3. var popover = new TextPopover();
  4. popover
  5. .configPopoverButtons({ //enables the popover actions (Boolean)
  6. facebook: true,
  7. twitter: true,
  8. search: true,
  9. copy: true,
  10. speak: true
  11. })
  12. .configPopover({
  13. bgColor: 'crimson', //sets the background color (Hexadecimal color )
  14. iconColor: 'white', //sets the icon color (Hexadecimal color)
  15. hideArrow: false, //hides the little arrow icon at the bottom of the popover (Boolean)
  16. showTooltip: true, //shows the tooltip for each action (Boolean)
  17. iconTransition: true, //enables the icon transition (Boolean)
  18. popoverShadow: '0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);' //set the box-shadow css property for the popover (CSS string)
  19. })
  20. .init();
  21. </script>

Adding a custom popover action

  1. <script src="text-popover.min.js"></script>
  2. <script>
  3. var customAction = {
  4. name: 'save_notes', //name of the action
  5. tooltip: 'Save_Notes', //currently only single word tooltip is supported
  6. custom_attr: 'other details', //you can add any number of custom attributes
  7. icon: `<i class="far fa-edit text_popover_icon"></i>`, // you can use fontawesome or other icons or you can paste the icon's svg string directly. You just have to add the 'text_popover_icon' class. In some cases, the icon might not be formatted correctly. So you have debug and add appropriate styles.
  8. handlerFn: function () {
  9. console.log(this.selectedText); //stores the selected text.
  10. console.log(this.save_notes.custom_attr); //this.[customAction.name] refers to customAction object.
  11. //code to save the selected text for the user
  12. return false;
  13. }
  14. };
  15. var popover = new TextPopover();
  16. popover.addPopoverButton(customAction)
  17. .init();
  18. </script>

Result


Screenshot for the popover