Files
sean 0e8a8b3028
Some checks failed
deploy-testing / deploy (push) Has been cancelled
Initial testing snapshot
2026-11-17 16:15:01 -05:00

15 lines
6.5 KiB
JavaScript

var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(c,e,a){c instanceof String&&(c=String(c));for(var b=c.length,d=0;d<b;d++){var f=c[d];if(e.call(a,f,d,c))return{i:d,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,e,a){c!=Array.prototype&&c!=Object.prototype&&(c[e]=a.value)};
$jscomp.getGlobal=function(c){return"undefined"!=typeof window&&window===c?c:"undefined"!=typeof global&&null!=global?global:c};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(c,e,a,b){if(e){a=$jscomp.global;c=c.split(".");for(b=0;b<c.length-1;b++){var d=c[b];d in a||(a[d]={});a=a[d]}c=c[c.length-1];b=a[c];e=e(b);e!=b&&null!=e&&$jscomp.defineProperty(a,c,{configurable:!0,writable:!0,value:e})}};
$jscomp.polyfill("Array.prototype.find",function(c){return c?c:function(c,a){return $jscomp.findInternal(this,c,a).v}},"es6","es3");
(function(c){var e=function(a,b){this.init(a,b)};e.prototype={init:function(a,b){this.$el=a;"function"===this.getType(b)&&(b={highlight:b});"custom"===this.getType(b)?(this.highlight=b,this.generate()):console.error("valid config object not provided")},getType:function(a){var b=typeof a;if(a){if(Array.isArray(a))return 2===a.length&&"number"===typeof a[0]&&"number"===typeof a[1]?"range":"array";if("object"===b){if(a instanceof RegExp)return"regexp";if(a.hasOwnProperty("highlight"))return"custom"}else if("function"===
b||"string"===b)return b}else return"falsey";return"other"},generate:function(){this.$el.addClass("hwt-input hwt-content").on("input.hwt",this.handleInput.bind(this)).on("scroll.hwt",this.handleScroll.bind(this));this.$highlights=c("<div>",{class:"hwt-highlights hwt-content"});this.$backdrop=c("<div>",{class:"hwt-backdrop"}).append(this.$highlights);this.$container=c("<div>",{class:"hwt-container"}).insertAfter(this.$el).append(this.$backdrop,this.$el).on("scroll",this.blockContainerScroll.bind(this));
this.fixPadding();this.isGenerated=!0;this.handleInput()},detectBrowser:function(){var a=window.navigator.userAgent.toLowerCase();return-1!==a.indexOf("firefox")?"firefox":a.match(/msie|trident\/7|edge/)?"ie":a.match(/ipad|iphone|ipod/)&&-1===a.indexOf("windows phone")?"ios":"other"},fixPadding:function(){var a=this.$el.css(["padding-top","padding-right","padding-bottom","padding-left"]),b=this.$el.css(["line-height","font-size"]);this.$backdrop.css({padding:"0","border-width":"0"});this.$highlights.css({"padding-top":a["padding-top"],
"padding-right":a["padding-right"],"padding-bottom":a["padding-bottom"],"padding-left":a["padding-left"]}).css({"line-height":b["line-height"],"font-size":b["font-size"]});this.$highlights.find("mark").css({"line-height":b["line-height"],"font-size":b["font-size"]})},fixFirefox:function(){var a=this.$highlights.css(["padding-top","padding-right","padding-bottom","padding-left"]),b=this.$highlights.css(["border-top-width","border-right-width","border-bottom-width","border-left-width"]);this.$highlights.css({padding:"0",
"border-width":"0"});this.$backdrop.css({"margin-top":"+="+a["padding-top"],"margin-right":"+="+a["padding-right"],"margin-bottom":"+="+a["padding-bottom"],"margin-left":"+="+a["padding-left"]}).css({"margin-top":"+="+b["border-top-width"],"margin-right":"+="+b["border-right-width"],"margin-bottom":"+="+b["border-bottom-width"],"margin-left":"+="+b["border-left-width"]})},fixIOS:function(){this.$highlights.css({"padding-left":"+=3px","padding-right":"+=3px"})},handleInput:function(){var a=this.$el.val();
a=this.getRanges(a,this.highlight);a=this.removeStaggeredRanges(a);a=this.getBoundaries(a);this.renderMarks(a)},getRanges:function(a,b){switch(this.getType(b)){case "array":return this.getArrayRanges(a,b);case "function":return this.getFunctionRanges(a,b);case "regexp":return this.getRegExpRanges(a,b);case "string":return this.getStringRanges(a,b);case "range":return this.getRangeRanges(a,b);case "custom":return this.getCustomRanges(a,b);default:if(b)console.error("unrecognized highlight type");else return[]}},
getArrayRanges:function(a,b){a=b.map(this.getRanges.bind(this,a));return Array.prototype.concat.apply([],a)},getFunctionRanges:function(a,b){return this.getRanges(a,b(a))},getRegExpRanges:function(a,b){for(var d=[],c;(c=b.exec(a),null!==c)&&(d.push([c.index,c.index+c[0].length]),b.global););return d},getStringRanges:function(a,b){var d=[];a=a.toLowerCase();b=b.toLowerCase();for(var c=0;c=a.indexOf(b,c),-1!==c;)d.push([c,c+b.length]),c+=b.length;return d},getRangeRanges:function(a,b){return[b]},getCustomRanges:function(a,
b){a=this.getRanges(a,b.highlight);b.className&&a.forEach(function(a){a.className=a.className?b.className+" "+a.className:b.className});return a},removeStaggeredRanges:function(a){var b=[];a.forEach(function(a){b.some(function(b){return(a[0]>b[0]&&a[0]<b[1])!==(a[1]>b[0]&&a[1]<b[1])})||b.push(a)});return b},getBoundaries:function(a){var b=[];a.forEach(function(a){b.push({type:"start",index:a[0],className:a.className});b.push({type:"stop",index:a[1]})});this.sortBoundaries(b);return b},sortBoundaries:function(a){a.sort(function(a,
c){return a.index!==c.index?c.index-a.index:"stop"===a.type&&"start"===c.type?1:"start"===a.type&&"stop"===c.type?-1:0})},renderMarks:function(a){var b=this.$el.val();a.forEach(function(a,c){c="start"===a.type?"{{hwt-mark-start|"+c+"}}":"{{hwt-mark-stop}}";b=b.slice(0,a.index)+c+b.slice(a.index)});b=b.replace(/\n(\{\{hwt-mark-stop\}\})?$/,"\n\n$1");b=b.replace(/</g,"&lt;").replace(/>/g,"&gt;");"ie"===this.browser&&(b=b.replace(/ /g," <wbr>"));b=b.replace(/\{\{hwt-mark-start\|(\d+)\}\}/g,function(b,
c){return(b=a[+c].className)?'<mark class="'+b+'">':"<mark>"});b=b.replace(/\{\{hwt-mark-stop\}\}/g,"</mark>");this.$highlights.html(b);this.fixPadding()},handleScroll:function(){var a=this.$el.scrollTop();this.$backdrop.scrollTop(a);a=this.$el.scrollLeft();this.$backdrop.css("transform",0<a?"translateX("+-a+"px)":"")},blockContainerScroll:function(){this.$container.scrollLeft(0)},destroy:function(){this.$backdrop.remove();this.$el.unwrap().removeClass("hwt-text hwt-input").off("hwt").removeData("hwt")}};
c.fn.highlightWithinTextarea=function(a){return this.each(function(){var b=c(this),d=b.data("hwt");if("string"===typeof a)if(d)switch(a){case "update":d.handleInput();break;case "destroy":d.destroy();break;default:console.error("unrecognized method string")}else console.error("plugin must be instantiated first");else d&&d.destroy(),d=new e(b,a),d.isGenerated&&b.data("hwt",d)})}})(jQuery);