-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery.custom-highlight.min.js
1 lines (1 loc) · 2.14 KB
/
jquery.custom-highlight.min.js
1
!function(t,e,n,o){"use strict";function i(e,n){this.element=e,this.settings=t.extend({},a,n),this._defaults=a,this._name=s,this.init()}var s="customHighlight",a={actions:[{test_action:"Test action"}],position:"left",textcolor:"on",backgroundcolor:"off"};t.extend(i.prototype,{init:function(){var e,o;jQuery(n).mousemove(function(t){e=t.pageX,o=t.pageY-10});var i=this;t(this.element).mouseup(function(e){if(""!=i.getSelectedText()){var n=i.add_cs_class(i.getSelectedText()),o="#"+n;if("on"==i.settings.textcolor){var s="#"+Math.random().toString(16).slice(2,8);t("#"+n).css("color",s)}if("on"==i.settings.backgroundcolor){var a="#"+Math.random().toString(16).slice(2,8);if(s!=a)t("#"+n).add(".light").css("color","#3A393C"),t("#"+n).add(".dark").css("color","#FBFBFB"),t("#"+n).css("background-color",a),t("#"+n).colourBrightness();else{var a="#"+Math.random().toString(16).slice(2,8);t("#"+n).add(".light").css("color","#3A393C"),t("#"+n).add(".dark").css("color","#FBFBFB"),t("#"+n).css("background-color",a),t("#"+n).colourBrightness()}}var c,r=(i.settings.actions.length,i.settings.actions);for(var l in r[0])c=l;if("test_action"==c)var d="<button type='button' class='btn' onclick=test_action('"+o+"')>Test Action</button>";else{var g=[];for(var u in r){g.push(r[u]);var h="";for(var f in g){var v=g[f],p=Object.keys(v)[0],m=v[p];h=h+"<button type='button' class='btn' onclick="+p+"('"+o+"')>"+m+"</button> "}var d=h}}t("#"+n).tooltipster({content:d,multiple:!0,position:i.settings.position,delay:100,maxWidth:500,speed:300,interactive:!0,animation:"grow",trigger:"hover",contentAsHTML:!0})}})},getSelectedText:function(){var t=n.all?n.selection.createRange().text:n.getSelection();return t},add_cs_class:function(t){var e=t,o=e.toString(),i=n.createElement("SPAN");i.textContent=" + "+o+" + ",i.classList.add("cs-editing"),i.classList.add("tooltip");var s=e.getRangeAt(0);s.deleteContents(),s.insertNode(i);var a=Math.random().toString(36).slice(2);return i.id="cs-editing-"+a,i.id},test_action:function(){alert("Here's a Test Action!")}}),t.fn[s]=function(e){return this.each(function(){t.data(this,"plugin_"+s)||t.data(this,"plugin_"+s,new i(this,e))})}}(jQuery,window,document);