Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/recipe-fiddle.git
String.prototype.hashCode=function(){var b=0,e=0,g=this.length,f;if(0<g)for(;e<g;)f=this.charCodeAt(e),b=(b<<5)-b+f,b|=0,e++;return b};function getURLParameter(b){return decodeURIComponent((RegExp("[?|&]"+b+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[void 0,""])[1].replace(/\+/g,"%20"))||""}
(function(b,e,g){b.Editor=function(f,g){var d=this,h=b(f),k=b.extend({},b.Editor.defaults,g);b("ol").text().hashCode();this.getCaretNode=function(){var a,c;if(document.selection&&document.selection.createRange)return a=document.selection.createRange(),a.parentElement();if(e.getSelection&&(c=e.getSelection(),c.getRangeAt?0<c.rangeCount&&(a=c.getRangeAt(0)):(a=document.createRange(),a.setStart(c.anchorNode,c.anchorOffset),a.setEnd(c.focusNode,c.focusOffset),a.collapsed!==c.isCollapsed&&(a.setStart(c.focusNode,
c.focusOffset),a.setEnd(c.anchorNode,c.anchorOffset))),a))return a=a.commonAncestorContainer,3===a.nodeType?a.parentNode:a};this.getCaretPosition=function(a){a=a||d.getCaretNode();var c=0,b=a.ownerDocument||a.document,e=b.defaultView||b.parentWindow,f=b.selection;"undefined"!==typeof e.getSelection?(c=e.getSelection().getRangeAt(0),b=c.cloneRange(),b.selectNodeContents(a),b.setEnd(c.endContainer,c.endOffset),c=b.toString().length):f&&"Control"!==f.type&&(c=f.createRange(),b=b.body.createTextRange(),
b.moveToElementText(a),b.setEndPoint("EndToEnd",c),c=b.text.length);return c};this.setCaretPositionEnd=function(a){a=a||d.getCaretNode();var b;document.createRange?(b=document.createRange(),b.selectNodeContents(a),b.collapse(!1),a=e.getSelection(),a.removeAllRanges(),a.addRange(b)):document.selection&&(b=document.body.createTextRange(),b.moveToElementText(a),b.collapse(!1),b.select())};this.normalize=function(){var a;b("p,div").replaceWith("<ol><li></li></ol>");a=b("ol:gt(0)").remove().children("li").appendTo("ol:eq(0)");
0===b("ol").length&&b(document.body).prepend("<ol><li></li></ol>");b("ol").nextAll().remove();b("ol").prevAll().remove();0===b("ol").children().length&&(a=b("<li></li>"),b("ol").append(a));a.is("li")&&d.setCaretPositionEnd(a[0]);b("li:empty").append("\u200b")};this.doNormalization=function(){setTimeout(function(){d.normalize()},32)};this.getStyle=function(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView.getComputedStyle(a,null)?document.defaultView.getComputedStyle(a,null).getPropertyValue(b):
""};this.toText=function(a){var b="",e=0,f=a.childNodes.length;if(3===a.nodeType)b=a.nodeValue.replace(/\s+/g," "),b=b.replace(/[\u200b]*/g,"");else{for(;e<f;)b+=d.toText(a.childNodes[e]),e++;e=d.getStyle(a,"display");if("BR"===a.tagName||"HR"===a.tagName||e.match(/^block/)||e.match(/list/)||e.match(/row/))b+="\n"}return b};this.paste=function(){var a=d.toText(document.body),a=a.replace(/^\s*[\r\n]/gm,""),a=a.replace(/(\.) +/g,"$1\n"),a=a.replace(/^\s\s*/gm,"").replace(/\s\s*$/gm,""),a=a.replace(/^\d+[\.\)]\s?([^\d])/gm,
"$1"),a=a.replace(/(.+)[\r\n]*/g,"<li>$1</li>\n");0===a.length&&(a="<li></li>");h.html("<ol>"+a+"</ol>")};this.initPasteHooks=function(){h.on("paste",function(a){setTimeout(function(){d.paste()},64)})};this.initKeyboardHooks=function(){h.on("keydown",function(a){var c=a.keyCode||a.which,e=!0,f=b(d.getCaretNode());if(16===c||17===c)return e;(f.is("html")||f.is("body"))&&d.setCaretPositionEnd(b("li").first()[0]);switch(c){case 8:case 46:d.doNormalization();break;case 116:d.save();break;case 13:e=a.shiftKey?
!1:d.doNormalization()}d.maxItemLength();return e})};this.initCursorPosition=function(){var a=b("li:first");a&&(d.setCaretPositionEnd(a[0]),a.focus())};this.initTimerHooks=function(){setInterval(function(){d.save()},1E3*k.saveInterval);setInterval(function(){d.maxItemLength()},1E3*k.maxItemLengthInterval);e.onbeforeunload=function(){d.save()};h.on("focusout",function(){d.save()})};this.hashText=function(){return b(document.body).text().hashCode()};this.isDirty=function(){return d.hashText()!==d.dHash};
this.clean=function(){d.dHash=d.hashText()};this.save=function(){if(d.isDirty()){d.clean();var a=b.trim(d.toText(b("ol")[0]));1<a.length&&b.post(k.postPage,{command:"instruction-accept",instructions_group_id:getURLParameter("id"),steps:a})}};this.maxItemLength=function(){b("li").each(function(){b(this).text().length>k.maxItemLength?b(this).addClass("maxLength"):b(this).removeClass()})};this.maxItems=function(){};this.itemListSplit=function(){};this.initialize=function(a,b){this.initKeyboardHooks();
this.initPasteHooks();this.initTimerHooks();this.initCursorPosition()};this.initialize(f,g)};b.fn.Editor=function(e){return this.each(function(){new b.Editor(this,e)})};b.Editor.defaults={maxItemLength:200,maxItemLengthInterval:0.5,maxItems:50,saveInterval:10,postPage:"index.php"}})(jQuery,window);$(document).ready(function(){$(document.body).Editor()});