forked from raghunandangupta1992/CollaborativeTextEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirepad-min.js
3 lines (3 loc) · 82.7 KB
/
firepad-min.js
1
2
3
var Firepad=function(){var t=t||{};t.utils={},t.utils.makeEventEmitter=function(t,e){t.prototype.allowedEvents_=e,t.prototype.on=function(t,e,r){this.validateEventType_(t),this.eventListeners_=this.eventListeners_||{},this.eventListeners_[t]=this.eventListeners_[t]||[],this.eventListeners_[t].push({callback:e,context:r})},t.prototype.off=function(t,e){this.validateEventType_(t),this.eventListeners_=this.eventListeners_||{};for(var r=this.eventListeners_[t]||[],n=0;r.length>n;n++)if(r[n].callback===e)return r.splice(n,1),void 0},t.prototype.trigger=function(t){this.eventListeners_=this.eventListeners_||{};for(var e=this.eventListeners_[t]||[],r=0;e.length>r;r++)e[r].callback.apply(e[r].context,Array.prototype.slice.call(arguments,1))},t.prototype.validateEventType_=function(t){if(this.allowedEvents_){for(var e=!1,r=0;this.allowedEvents_.length>r;r++)if(this.allowedEvents_[r]===t){e=!0;break}if(!e)throw Error('Unknown event "'+t+'"')}}},t.utils.elt=function(e,r,n){var i=document.createElement(e);if("string"==typeof r)t.utils.setTextContent(i,r);else if(r)for(var o=0;r.length>o;++o)i.appendChild(r[o]);for(var s in n||{})i.setAttribute(s,n[s]);return i},t.utils.setTextContent=function(t,e){t.innerHTML="",t.appendChild(document.createTextNode(e))},t.utils.on=function(t,e,r,n){t.addEventListener?t.addEventListener(e,r,n||!1):t.attachEvent&&t.attachEvent("on"+e,r)},t.utils.off=function(t,e,r,n){t.removeEventListener?t.removeEventListener(e,r,n||!1):t.detachEvent&&t.detachEvent("on"+e,r)},t.utils.preventDefault=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},t.utils.stopPropagation=function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},t.utils.stopEvent=function(e){t.utils.preventDefault(e),t.utils.stopPropagation(e)},t.utils.stopEventAnd=function(e){return function(r){return e(r),t.utils.stopEvent(r),!1}},t.utils.trim=function(t){return t.replace(/^\s+/g,"").replace(/\s+$/g,"")},t.utils.assert=function(t,e){if(!t)throw Error(e||"assertion error")},t.utils.log=function(){if("undefined"!=typeof console&&console.log!==void 0){for(var t=["Firepad:"],e=0;arguments.length>e;e++)t.push(arguments[e]);console.log.apply(console,t)}};var t=t||{};t.Span=function(){function t(t,e){this.pos=t,this.length=e}return t.prototype.end=function(){return this.pos+this.length},t}();var t=t||{};t.TextOp=function(){function e(t){this.type=t,this.chars=null,this.text=null,this.attributes=null,"insert"===t?(this.text=arguments[1],r.assert("string"==typeof this.text),this.attributes=arguments[2]||{},r.assert("object"==typeof this.attributes)):"delete"===t?(this.chars=arguments[1],r.assert("number"==typeof this.chars)):"retain"===t&&(this.chars=arguments[1],r.assert("number"==typeof this.chars),this.attributes=arguments[2]||{},r.assert("object"==typeof this.attributes))}var r=t.utils;return e.prototype.isInsert=function(){return"insert"===this.type},e.prototype.isDelete=function(){return"delete"===this.type},e.prototype.isRetain=function(){return"retain"===this.type},e.prototype.equals=function(t){return this.type===t.type&&this.text===t.text&&this.chars===t.chars&&this.attributesEqual(t.attributes)},e.prototype.attributesEqual=function(t){for(var e in this.attributes)if(this.attributes[e]!==t[e])return!1;for(e in t)if(this.attributes[e]!==t[e])return!1;return!0},e.prototype.hasEmptyAttributes=function(){var t=!0;for(var e in this.attributes){t=!1;break}return t},e}();var t=t||{};t.TextOperation=function(){"use strict";function e(){return this&&this.constructor===e?(this.ops=[],this.baseLength=0,this.targetLength=0,void 0):new e}function r(t){var e=t.ops;switch(e.length){case 1:return e[0];case 2:return e[0].isRetain()?e[1]:e[1].isRetain()?e[0]:null;case 3:if(e[0].isRetain()&&e[2].isRetain())return e[1]}return null}function n(t){return t.ops[0].isRetain()?t.ops[0].chars:0}var i=t.TextOp,o=t.utils;return e.prototype.equals=function(t){if(this.baseLength!==t.baseLength)return!1;if(this.targetLength!==t.targetLength)return!1;if(this.ops.length!==t.ops.length)return!1;for(var e=0;this.ops.length>e;e++)if(!this.ops[e].equals(t.ops[e]))return!1;return!0},e.prototype.retain=function(t,e){if("number"!=typeof t||0>t)throw Error("retain expects a positive integer.");if(0===t)return this;this.baseLength+=t,this.targetLength+=t,e=e||{};var r=this.ops.length>0?this.ops[this.ops.length-1]:null;return r&&r.isRetain()&&r.attributesEqual(e)?r.chars+=t:this.ops.push(new i("retain",t,e)),this},e.prototype.insert=function(t,e){if("string"!=typeof t)throw Error("insert expects a string");if(""===t)return this;e=e||{},this.targetLength+=t.length;var r=this.ops.length>0?this.ops[this.ops.length-1]:null,n=this.ops.length>1?this.ops[this.ops.length-2]:null;return r&&r.isInsert()&&r.attributesEqual(e)?r.text+=t:r&&r.isDelete()?n&&n.isInsert()&&n.attributesEqual(e)?n.text+=t:(this.ops[this.ops.length-1]=new i("insert",t,e),this.ops.push(r)):this.ops.push(new i("insert",t,e)),this},e.prototype["delete"]=function(t){if("string"==typeof t&&(t=t.length),"number"!=typeof t||0>t)throw Error("delete expects a positive integer or a string");if(0===t)return this;this.baseLength+=t;var e=this.ops.length>0?this.ops[this.ops.length-1]:null;return e&&e.isDelete()?e.chars+=t:this.ops.push(new i("delete",t)),this},e.prototype.isNoop=function(){return 0===this.ops.length||1===this.ops.length&&this.ops[0].isRetain()&&this.ops[0].hasEmptyAttributes()},e.prototype.clone=function(){for(var t=new e,r=0;this.ops.length>r;r++)this.ops[r].isRetain()?t.retain(this.ops[r].chars,this.ops[r].attributes):this.ops[r].isInsert()?t.insert(this.ops[r].text,this.ops[r].attributes):t["delete"](this.ops[r].chars);return t},e.prototype.toString=function(){var t=Array.prototype.map||function(t){for(var e=this,r=[],n=0,i=e.length;i>n;n++)r[n]=t(e[n]);return r};return t.call(this.ops,function(t){return t.isRetain()?"retain "+t.chars:t.isInsert()?"insert '"+t.text+"'":"delete "+t.chars}).join(", ")},e.prototype.toJSON=function(){for(var t=[],e=0;this.ops.length>e;e++)this.ops[e].hasEmptyAttributes()||t.push(this.ops[e].attributes),"retain"===this.ops[e].type?t.push(this.ops[e].chars):"insert"===this.ops[e].type?t.push(this.ops[e].text):"delete"===this.ops[e].type&&t.push(-this.ops[e].chars);return 0===t.length&&t.push(0),t},e.fromJSON=function(t){for(var r=new e,n=0,i=t.length;i>n;n++){var s=t[n],a={};"object"==typeof s&&(a=s,n++,s=t[n]),"number"==typeof s?s>0?r.retain(s,a):r["delete"](-s):(o.assert("string"==typeof s),r.insert(s,a))}return r},e.prototype.apply=function(t,e,r){var n=this;if(e=e||[],r=r||[],t.length!==n.baseLength)throw Error("The operation's base length must be equal to the string's length.");for(var i,s,a=[],h=0,u=0,c=this.ops,l=0,p=c.length;p>l;l++){var d=c[l];if(d.isRetain()){if(u+d.chars>t.length)throw Error("Operation can't retain more characters than are left in the string.");for(a[h++]=t.slice(u,u+d.chars),i=0;d.chars>i;i++){var f=e[u+i]||{},g={};for(s in f)g[s]=f[s],o.assert(g[s]!==!1);for(s in d.attributes)d.attributes[s]===!1?delete g[s]:g[s]=d.attributes[s],o.assert(g[s]!==!1);r.push(g)}u+=d.chars}else if(d.isInsert())for(a[h++]=d.text,i=0;d.text.length>i;i++){var m={};for(s in d.attributes)m[s]=d.attributes[s],o.assert(m[s]!==!1);r.push(m)}else u+=d.chars}if(u!==t.length)throw Error("The operation didn't operate on the whole string.");var v=a.join("");return o.assert(v.length===r.length),v},e.prototype.invert=function(t){for(var r=0,n=new e,i=this.ops,o=0,s=i.length;s>o;o++){var a=i[o];a.isRetain()?(n.retain(a.chars),r+=a.chars):a.isInsert()?n["delete"](a.text.length):(n.insert(t.slice(r,r+a.chars)),r+=a.chars)}return n},e.prototype.compose=function(t){function r(t,e,r){var n,i={};for(n in t)i[n]=t[n];for(n in e)r&&e[n]===!1?delete i[n]:i[n]=e[n];return i}var n=this;if(n.targetLength!==t.baseLength)throw Error("The base length of the second operation has to be the target length of the first operation");for(var i,o=new e,s=n.clone().ops,a=t.clone().ops,h=0,u=0,c=s[h++],l=a[u++];;){if(c===void 0&&l===void 0)break;if(c&&c.isDelete())o["delete"](c.chars),c=s[h++];else if(l&&l.isInsert())o.insert(l.text,l.attributes),l=a[u++];else{if(c===void 0)throw Error("Cannot compose operations: first operation is too short.");if(l===void 0)throw Error("Cannot compose operations: first operation is too long.");if(c.isRetain()&&l.isRetain())i=r(c.attributes,l.attributes),c.chars>l.chars?(o.retain(l.chars,i),c.chars-=l.chars,l=a[u++]):c.chars===l.chars?(o.retain(c.chars,i),c=s[h++],l=a[u++]):(o.retain(c.chars,i),l.chars-=c.chars,c=s[h++]);else if(c.isInsert()&&l.isDelete())c.text.length>l.chars?(c.text=c.text.slice(l.chars),l=a[u++]):c.text.length===l.chars?(c=s[h++],l=a[u++]):(l.chars-=c.text.length,c=s[h++]);else if(c.isInsert()&&l.isRetain())i=r(c.attributes,l.attributes,!0),c.text.length>l.chars?(o.insert(c.text.slice(0,l.chars),i),c.text=c.text.slice(l.chars),l=a[u++]):c.text.length===l.chars?(o.insert(c.text,i),c=s[h++],l=a[u++]):(o.insert(c.text,i),l.chars-=c.text.length,c=s[h++]);else{if(!c.isRetain()||!l.isDelete())throw Error("This shouldn't happen: op1: "+JSON.stringify(c)+", op2: "+JSON.stringify(l));c.chars>l.chars?(o["delete"](l.chars),c.chars-=l.chars,l=a[u++]):c.chars===l.chars?(o["delete"](l.chars),c=s[h++],l=a[u++]):(o["delete"](c.chars),l.chars-=c.chars,c=s[h++])}}}return o},e.prototype.shouldBeComposedWith=function(t){if(this.isNoop()||t.isNoop())return!0;var e=n(this),i=n(t),o=r(this),s=r(t);return o&&s?o.isInsert()&&s.isInsert()?e+o.text.length===i:o.isDelete()&&s.isDelete()?i+s.chars===e||e===i:!1:!1},e.prototype.shouldBeComposedWithInverted=function(t){if(this.isNoop()||t.isNoop())return!0;var e=n(this),i=n(t),o=r(this),s=r(t);return o&&s?o.isInsert()&&s.isInsert()?e+o.text.length===i||e===i:o.isDelete()&&s.isDelete()?i+s.chars===e:!1:!1},e.transformAttributes=function(t,e){var r,n={},i={},s={};for(r in t)s[r]=!0;for(r in e)s[r]=!0;for(r in s){var a=t[r],h=e[r];o.assert(null!=a||null!=h),null==a?i[r]=h:null==h?n[r]=a:a===h||(n[r]=a)}return[n,i]},e.transform=function(t,r){if(t.baseLength!==r.baseLength)throw Error("Both operations have to have the same base length");for(var n=new e,i=new e,o=t.clone().ops,s=r.clone().ops,a=0,h=0,u=o[a++],c=s[h++];;){if(u===void 0&&c===void 0)break;if(u&&u.isInsert())n.insert(u.text,u.attributes),i.retain(u.text.length),u=o[a++];else if(c&&c.isInsert())n.retain(c.text.length),i.insert(c.text,c.attributes),c=s[h++];else{if(u===void 0)throw Error("Cannot transform operations: first operation is too short.");if(c===void 0)throw Error("Cannot transform operations: first operation is too long.");var l;if(u.isRetain()&&c.isRetain()){var p=e.transformAttributes(u.attributes,c.attributes);u.chars>c.chars?(l=c.chars,u.chars-=c.chars,c=s[h++]):u.chars===c.chars?(l=c.chars,u=o[a++],c=s[h++]):(l=u.chars,c.chars-=u.chars,u=o[a++]),n.retain(l,p[0]),i.retain(l,p[1])}else if(u.isDelete()&&c.isDelete())u.chars>c.chars?(u.chars-=c.chars,c=s[h++]):u.chars===c.chars?(u=o[a++],c=s[h++]):(c.chars-=u.chars,u=o[a++]);else if(u.isDelete()&&c.isRetain())u.chars>c.chars?(l=c.chars,u.chars-=c.chars,c=s[h++]):u.chars===c.chars?(l=c.chars,u=o[a++],c=s[h++]):(l=u.chars,c.chars-=u.chars,u=o[a++]),n["delete"](l);else{if(!u.isRetain()||!c.isDelete())throw Error("The two operations aren't compatible");u.chars>c.chars?(l=c.chars,u.chars-=c.chars,c=s[h++]):u.chars===c.chars?(l=u.chars,u=o[a++],c=s[h++]):(l=u.chars,c.chars-=u.chars,u=o[a++]),i["delete"](l)}}}return[n,i]},e}();var t=t||{};t.AnnotationList=function(){function e(t,e){if(!t)throw Error("AnnotationList assertion failed"+(e?": "+e:""))}function r(t,e){this.pos=t,this.length=e.length,this.annotation=e.annotation,this.attachedObject_=e.attachedObject}function n(t,e){this.pos=t,this.length=e.length,this.annotation=e.annotation,this.node_=e}function i(t){this.head_=new o(0,a),this.changeHandler_=t}function o(t,e){this.length=t,this.annotation=e,this.attachedObject=null,this.next=null}var s=t.Span;r.prototype.getAttachedObject=function(){return this.attachedObject_},n.prototype.attachObject=function(t){this.node_.attachedObject=t};var a={equals:function(){return!1}};return i.prototype.insertAnnotatedSpan=function(t,r){this.wrapOperation_(new s(t.pos,0),function(n,i){e(!i||null===i.next);var s=new o(t.length,r);if(i){e(t.pos>n&&t.pos<n+i.length);var h=new o(0,a);return h.next=new o(t.pos-n,i.annotation),h.next.next=s,s.next=new o(n+i.length-t.pos,i.annotation),h.next}return s})},i.prototype.removeSpan=function(t){0!==t.length&&this.wrapOperation_(t,function(r,n){e(null!==n);var i=new o(0,a),s=i;for(t.pos>r&&(s.next=new o(t.pos-r,n.annotation),s=s.next);t.end()>r+n.length;)r+=n.length,n=n.next;var h=r+n.length-t.end();return h>0&&(s.next=new o(h,n.annotation)),i.next})},i.prototype.updateSpan=function(t,r){0!==t.length&&this.wrapOperation_(t,function(n,i){e(null!==i);var s=new o(0,a),h=s,u=n,c=t.pos-u;for(e(i.length>c),c>0&&(h.next=new o(c,i.annotation),h=h.next,u+=h.length);null!==i&&t.end()>=n+i.length;){var l=n+i.length-u;h.next=new o(l,r(i.annotation,l)),h=h.next,n+=i.length,i=i.next,u=n}var p=t.end()-u;return p>0&&(e(i.length>p),h.next=new o(p,r(i.annotation,p)),h=h.next,u+=h.length,h.next=new o(n+i.length-u,i.annotation)),s.next})},i.prototype.wrapOperation_=function(t,e){if(0>t.pos)throw Error("Span start cannot be negative.");var i,s=[],a=[],h=this.getAffectedNodes_(t);null!==h.start?(i=h.end.next,h.end.next=null):i=h.succ;var u=e(h.startPos,h.start),c=!1,l=!1;if(u){this.mergeNodesWithSameAnnotations_(u);var p;for(h.pred&&h.pred.annotation.equals(u.annotation)?(c=!0,u.length+=h.pred.length,h.beforePred.next=u,p=h.predPos):(h.beforeStart.next=u,p=h.startPos);u.next;)a.push(new n(p,u)),p+=u.length,u=u.next;h.succ&&h.succ.annotation.equals(u.annotation)?(u.length+=h.succ.length,l=!0,u.next=h.succ.next):u.next=i,a.push(new n(p,u))}else h.pred&&h.succ&&h.pred.annotation.equals(h.succ.annotation)?(c=!0,l=!0,u=new o(h.pred.length+h.succ.length,h.pred.annotation),h.beforePred.next=u,u.next=h.succ.next,a.push(new n(h.startPos-h.pred.length,u))):h.beforeStart.next=i;c&&s.push(new r(h.predPos,h.pred));for(var d=h.startPos,f=h.start;null!==f;)s.push(new r(d,f)),d+=f.length,f=f.next;l&&s.push(new r(d,h.succ)),this.changeHandler_(s,a)},i.prototype.getAffectedNodes_=function(t){for(var e={},r=null,n=this.head_,i=n.next,o=0;null!==i&&t.pos>=o+i.length;)o+=i.length,r=n,n=i,i=i.next;if(null===i&&(0!==t.length||t.pos!==o))throw Error("Span start exceeds the bounds of the AnnotationList.");for(e.startPos=o,e.start=0===t.length&&t.pos===o?null:i,e.beforeStart=n,o===t.pos&&o>0?(e.pred=n,e.predPos=o-n.length,e.beforePred=r):e.pred=null;null!==i&&t.end()>o;)o+=i.length,n=i,i=i.next;if(t.end()>o)throw Error("Span end exceeds the bounds of the AnnotationList.");return e.end=0===t.length&&t.end()===o?null:n,e.succ=o===t.end()?i:null,e},i.prototype.mergeNodesWithSameAnnotations_=function(t){if(t)for(var e=null,r=t;r;)e&&e.annotation.equals(r.annotation)?(e.length+=r.length,e.next=r.next):e=r,r=r.next},i.prototype.forEach=function(t){for(var e=this.head_.next;null!==e;)t(e.length,e.annotation,e.attachedObject),e=e.next},i.prototype.getAnnotatedSpansForPos=function(t){for(var e=0,n=this.head_.next,i=null;null!==n&&t>=e+n.length;)e+=n.length,i=n,n=n.next;if(null===n&&e!==t)throw Error("pos exceeds the bounds of the AnnotationList");var o=[];return e===t&&i&&o.push(new r(e-i.length,i)),n&&o.push(new r(e,n)),o},i.prototype.getAnnotatedSpansForSpan=function(t){if(0===t.length)return[];for(var e=[],r=this.getAffectedNodes_(t),n=r.startPos,i=r.start;null!==i&&t.end()>n;){var o=Math.max(n,t.pos),a=Math.min(n+i.length,t.end()),h=new s(o,a-o);h.annotation=i.annotation,e.push(h),n+=i.length,i=i.next}return e},i.prototype.count=function(){for(var t=0,r=this.head_.next,n=null;null!==r;)n&&e(!n.annotation.equals(r.annotation)),n=r,r=r.next,t++;return t},o.prototype.clone=function(){var t=new o(this.spanLength,this.annotation);return t.next=this.next,t},i}();var t=t||{};t.Cursor=function(){"use strict";function t(t,e){this.position=t,this.selectionEnd=e}return t.fromJSON=function(e){return new t(e.position,e.selectionEnd)},t.prototype.equals=function(t){return this.position===t.position&&this.selectionEnd===t.selectionEnd},t.prototype.compose=function(t){return t},t.prototype.transform=function(e){function r(t){for(var r=t,n=e.ops,i=0,o=e.ops.length;o>i&&(n[i].isRetain()?t-=n[i].chars:n[i].isInsert()?r+=n[i].text.length:(r-=Math.min(t,n[i].chars),t-=n[i].chars),!(0>t));i++);return r}var n=r(this.position);return this.position===this.selectionEnd?new t(n,n):new t(n,r(this.selectionEnd))},t}();var t=t||{};t.FirebaseAdapter=function(){function e(t,e,r){this.ref_=t,this.ready_=!1,this.firebaseCallbacks_=[],this.zombie_=!1,this.document_=new o,this.revision_=0,this.pendingReceivedRevisions_={},this.setUserId(e),this.setColor(r);var n=this;this.firebaseOn_(t.root().child(".info/connected"),"value",function(t){t.val()===!0&&n.initializeUserData_()},this),setTimeout(function(){n.monitorHistory_()},0),this.on("ready",function(){n.monitorCursors_()})}function r(t,e){if(!t)throw Error(e||"assertion error")}function n(t){if(0===t)return"A0";for(var e="";t>0;){var r=t%h.length;e=h[r]+e,t-=r,t/=h.length}var n=h[e.length+9];return n+e}function i(t){r(t.length>0&&t[0]===h[t.length+8]);for(var e=0,n=1;t.length>n;n++)e*=h.length,e+=h.indexOf(t[n]);return e}var o=t.TextOperation,s=t.utils,a=100;s.makeEventEmitter(e,["ready","cursor","operation","ack","retry"]),e.prototype.dispose=function(){this.removeFirebaseCallbacks_(),this.userRef_.child("cursor").remove(),this.userRef_.child("color").remove(),this.ref_=null,this.document_=null,this.zombie_=!0},e.prototype.setUserId=function(t){this.userRef_&&(this.userRef_.child("cursor").remove(),this.userRef_.child("cursor").onDisconnect().cancel(),this.userRef_.child("color").remove(),this.userRef_.child("color").onDisconnect().cancel()),this.userId_=t,this.userRef_=this.ref_.child("users").child(t),this.initializeUserData_()},e.prototype.isHistoryEmpty=function(){return r(this.ready_,"Not ready yet."),0===this.revision_},e.prototype.sendOperation=function(t,e){function i(t,e,r){o.ref_.child("history").child(t).transaction(function(t){return null===t?e:void 0},function(n,a){if(n){if("disconnect"!==n.message)throw s.log("Transaction failure!",n),n;o.sent_&&o.sent_.id===t&&setTimeout(function(){i(t,e,r)},0)}else a&&o.sendCursor(r)},!1)}var o=this;if(!this.ready_)return this.on("ready",function(){o.trigger("retry")}),void 0;r(this.document_.targetLength===t.baseLength,"sendOperation() called with invalid operation.");var a=n(this.revision_);this.sent_={id:a,op:t},i(a,{a:o.userId_,o:t.toJSON()},e)},e.prototype.sendCursor=function(t){this.userRef_.child("cursor").set(t),this.cursor_=t},e.prototype.setColor=function(t){this.userRef_.child("color").set(t),this.color_=t},e.prototype.getDocument=function(){return this.document_},e.prototype.registerCallbacks=function(t){for(var e in t)this.on(e,t[e])},e.prototype.initializeUserData_=function(){this.userRef_.child("cursor").onDisconnect().remove(),this.userRef_.child("color").onDisconnect().remove(),this.sendCursor(this.cursor_||null),this.setColor(this.color_||null)},e.prototype.monitorCursors_=function(){function t(t){var e=t.name(),n=t.val();r.trigger("cursor",e,n.cursor,n.color)}var e=this.ref_.child("users"),r=this,n={};this.firebaseOn_(e,"child_added",t),this.firebaseOn_(e,"child_changed",t),this.firebaseOn_(e,"child_removed",function(t){var e=t.name();r.firebaseOff_(t.ref(),"value",n[e]),r.trigger("cursor",e,null)})},e.prototype.monitorHistory_=function(){var t=this;this.ref_.child("checkpoint").once("value",function(e){if(!t.zombie_){var r=e.child("id").val(),n=e.child("o").val(),o=e.child("a").val();null!=n&&null!=r&&null!==o?(t.pendingReceivedRevisions_[r]={o:n,a:o},t.checkpointRevision_=i(r),t.monitorHistoryStartingAt_(t.checkpointRevision_+1)):(t.checkpointRevision_=0,t.monitorHistoryStartingAt_(t.checkpointRevision_))}})},e.prototype.monitorHistoryStartingAt_=function(t){var e=this.ref_.child("history").startAt(null,n(t)),r=this;setTimeout(function(){r.firebaseOn_(e,"child_added",function(t){var e=t.name();r.pendingReceivedRevisions_[e]=t.val(),r.ready_&&r.handlePendingReceivedRevisions_()}),e.once("value",function(){r.handleInitialRevisions_()})},0)},e.prototype.handleInitialRevisions_=function(){r(!this.ready_,"Should not be called multiple times."),this.revision_=this.checkpointRevision_;for(var t=n(this.revision_),e=this.pendingReceivedRevisions_;null!=e[t];){var i=this.parseRevision_(e[t]);i?this.document_=this.document_.compose(i.operation):s.log("Invalid operation.",""+this.ref_,t,e[t]),delete e[t],this.revision_++,t=n(this.revision_)}this.trigger("operation",this.document_),this.ready_=!0;var o=this;setTimeout(function(){o.trigger("ready")},0)},e.prototype.handlePendingReceivedRevisions_=function(){for(var t=this.pendingReceivedRevisions_,e=n(this.revision_),r=!1;null!=t[e];){this.revision_++;var i=this.parseRevision_(t[e]);i?(this.document_=this.document_.compose(i.operation),this.sent_&&e===this.sent_.id?this.sent_.op.equals(i.operation)&&i.author===this.userId_?(0===this.revision_%a&&this.saveCheckpoint_(),this.sent_=null,this.trigger("ack")):(r=!0,this.trigger("operation",i.operation)):this.trigger("operation",i.operation)):s.log("Invalid operation.",""+this.ref_,e,t[e]),delete t[e],e=n(this.revision_)}r&&(this.sent_=null,this.trigger("retry"))},e.prototype.parseRevision_=function(t){if("object"!=typeof t)return null;if("string"!=typeof t.a||"object"!=typeof t.o)return null;var e=null;try{e=o.fromJSON(t.o)}catch(r){return null}return e.baseLength!==this.document_.targetLength?null:{author:t.a,operation:e}},e.prototype.saveCheckpoint_=function(){this.ref_.child("checkpoint").set({a:this.userId_,o:this.document_.toJSON(),id:n(this.revision_-1)})},e.prototype.firebaseOn_=function(t,e,r,n){return this.firebaseCallbacks_.push({ref:t,eventType:e,callback:r,context:n}),t.on(e,r,n),r},e.prototype.firebaseOff_=function(t,e,r,n){t.off(e,r,n);for(var i=0;this.firebaseCallbacks_.length>i;i++){var o=this.firebaseCallbacks_[i];if(o.ref===t&&o.eventType===e&&o.callback===r&&o.context===n){this.firebaseCallbacks_.splice(i,1);break}}},e.prototype.removeFirebaseCallbacks_=function(){for(var t=0;this.firebaseCallbacks_.length>t;t++){var e=this.firebaseCallbacks_[t];e.ref.off(e.eventType,e.callback,e.context)}this.firebaseCallbacks_=[]};var h="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";return e}();var t=t||{};t.RichTextToolbar=function(){function e(t){this.imageInsertionUI=t,this.element_=this.makeElement_()}var r=t.utils;return r.makeEventEmitter(e,["bold","italic","underline","strike","font","font-size","color","left","center","right","unordered-list","ordered-list","todo-list","indent-increase","indent-decrease","undo","redo","insert-image"]),e.prototype.element=function(){return this.element_},e.prototype.makeButton_=function(t,e){var n=this;e=e||t;var i=r.elt("a",[r.elt("span","",{"class":"firepad-tb-"+e})],{"class":"firepad-btn"});return r.on(i,"click",r.stopEventAnd(function(){n.trigger(t)})),i},e.prototype.makeElement_=function(){var t=this,e=this.makeFontDropdown_(),n=this.makeFontSizeDropdown_(),i=this.makeColorDropdown_(),o=[r.elt("div",[e],{"class":"firepad-btn-group"}),r.elt("div",[n],{"class":"firepad-btn-group"}),r.elt("div",[i],{"class":"firepad-btn-group"}),r.elt("div",[t.makeButton_("bold"),t.makeButton_("italic"),t.makeButton_("underline"),t.makeButton_("strike","strikethrough")],{"class":"firepad-btn-group"}),r.elt("div",[t.makeButton_("unordered-list","list-2"),t.makeButton_("ordered-list","numbered-list"),t.makeButton_("todo-list","list")],{"class":"firepad-btn-group"}),r.elt("div",[t.makeButton_("indent-decrease"),t.makeButton_("indent-increase")],{"class":"firepad-btn-group"}),r.elt("div",[t.makeButton_("left","paragraph-left"),t.makeButton_("center","paragraph-center"),t.makeButton_("right","paragraph-right")],{"class":"firepad-btn-group"})];t.imageInsertionUI&&o.push(r.elt("div",[t.makeButton_("insert-image")],{"class":"firepad-btn-group"}));var s=r.elt("div",o,{"class":"firepad-toolbar"});return s},e.prototype.makeFontDropdown_=function(){for(var t=["Arial","Comic Sans MS","Courier New","Impact","Times New Roman","Verdana"],e=[],n=0;t.length>n;n++){var i=r.elt("span",t[n]);i.setAttribute("style","font-family:"+t[n]),e.push({content:i,value:t[n]})}return this.makeDropdown_("Font","font",e)},e.prototype.makeFontSizeDropdown_=function(){for(var t=[9,10,12,14,18,24,32,42],e=[],n=0;t.length>n;n++){var i=r.elt("span",""+t[n]);i.setAttribute("style","font-size:"+t[n]+"px; line-height:"+(t[n]-6)+"px;"),e.push({content:i,value:t[n]})}return this.makeDropdown_("Size","font-size",e,"px")},e.prototype.makeColorDropdown_=function(){for(var t=["black","red","green","blue","yellow","cyan","magenta","grey"],e=[],n=0;t.length>n;n++){var i=r.elt("div");i.className="firepad-color-dropdown-item",i.setAttribute("style","background-color:"+t[n]),e.push({content:i,value:t[n]})}return this.makeDropdown_("Color","color",e)},e.prototype.makeDropdown_=function(t,e,n,i){function o(){l||(c.style.display="block",r.on(document,"click",s,!0),l=!0)}function s(){l&&(c.style.display="",r.off(document,"click",s,!0),l=!1),p=!0,setTimeout(function(){p=!1},0)}function a(t,n){"object"!=typeof t&&(t=document.createTextNode(t+""));var o=r.elt("a",[t]);r.on(o,"click",r.stopEventAnd(function(){s(),h.trigger(e,n+i)})),c.appendChild(o)}i=i||"";var h=this,u=r.elt("a",t+" ▾",{"class":"firepad-btn firepad-dropdown"}),c=r.elt("ul",[],{"class":"firepad-dropdown-menu"});u.appendChild(c);for(var l=!1,p=!1,d=0;n.length>d;d++){var f=n[d].content,g=n[d].value;a(f,g)}return r.on(u,"click",r.stopEventAnd(function(){p||o()})),u},e}();var t=t||{};t.WrappedOperation=function(){"use strict";function t(t,e){this.wrapped=t,this.meta=e}function e(t,e){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}function r(t,r){if(t&&"object"==typeof t){if("function"==typeof t.compose)return t.compose(r);var n={};return e(t,n),e(r,n),n}return r}function n(t,e){return t&&"object"==typeof t&&"function"==typeof t.transform?t.transform(e):t}return t.prototype.apply=function(){return this.wrapped.apply.apply(this.wrapped,arguments)},t.prototype.invert=function(){var e=this.meta;return new t(this.wrapped.invert.apply(this.wrapped,arguments),e&&"object"==typeof e&&"function"==typeof e.invert?e.invert.apply(e,arguments):e)},t.prototype.compose=function(e){return new t(this.wrapped.compose(e.wrapped),r(this.meta,e.meta))},t.transform=function(e,r){var i=e.wrapped.constructor.transform,o=i(e.wrapped,r.wrapped);return[new t(o[0],n(e.meta,r.wrapped)),new t(o[1],n(r.meta,e.wrapped))]},t}();var t=t||{};t.UndoManager=function(){"use strict";function t(t){this.maxItems=t||50,this.state=r,this.dontCompose=!1,this.undoStack=[],this.redoStack=[]}function e(t,e){for(var r=[],n=e.constructor,i=t.length-1;i>=0;i--){var o=n.transform(t[i],e);"function"==typeof o[0].isNoop&&o[0].isNoop()||r.push(o[0]),e=o[1]}return r.reverse()}var r="normal",n="undoing",i="redoing";return t.prototype.add=function(t,e){if(this.state===n)this.redoStack.push(t),this.dontCompose=!0;else if(this.state===i)this.undoStack.push(t),this.dontCompose=!0;else{var r=this.undoStack;!this.dontCompose&&e&&r.length>0?r.push(t.compose(r.pop())):(r.push(t),r.length>this.maxItems&&r.shift()),this.dontCompose=!1,this.redoStack=[]}},t.prototype.transform=function(t){this.undoStack=e(this.undoStack,t),this.redoStack=e(this.redoStack,t)},t.prototype.performUndo=function(t){if(this.state=n,0===this.undoStack.length)throw Error("undo not possible");t(this.undoStack.pop()),this.state=r},t.prototype.performRedo=function(t){if(this.state=i,0===this.redoStack.length)throw Error("redo not possible");t(this.redoStack.pop()),this.state=r},t.prototype.canUndo=function(){return 0!==this.undoStack.length},t.prototype.canRedo=function(){return 0!==this.redoStack.length},t.prototype.isUndoing=function(){return this.state===n},t.prototype.isRedoing=function(){return this.state===i},t}();var t=t||{};t.Client=function(){"use strict";function t(){this.state=i}function e(){}function r(t){this.outstanding=t}function n(t,e){this.outstanding=t,this.buffer=e}t.prototype.setState=function(t){this.state=t},t.prototype.applyClient=function(t){this.setState(this.state.applyClient(this,t))},t.prototype.applyServer=function(t){this.setState(this.state.applyServer(this,t))},t.prototype.serverAck=function(){this.setState(this.state.serverAck(this))},t.prototype.transformCursor=function(t){return this.state.transformCursor(t)},t.prototype.serverRetry=function(){this.setState(this.state.serverRetry(this))},t.prototype.sendOperation=function(){throw Error("sendOperation must be defined in child class")},t.prototype.applyOperation=function(){throw Error("applyOperation must be defined in child class")},t.Synchronized=e,e.prototype.applyClient=function(t,e){return t.sendOperation(e),new r(e)},e.prototype.applyServer=function(t,e){return t.applyOperation(e),this},e.prototype.serverAck=function(){throw Error("There is no pending operation.")},e.prototype.serverRetry=function(){throw Error("There is no pending operation.")},e.prototype.transformCursor=function(t){return t};var i=new e;return t.AwaitingConfirm=r,r.prototype.applyClient=function(t,e){return new n(this.outstanding,e)},r.prototype.applyServer=function(t,e){var n=e.constructor.transform(this.outstanding,e);return t.applyOperation(n[1]),new r(n[0])},r.prototype.serverAck=function(){return i},r.prototype.serverRetry=function(t){return t.sendOperation(this.outstanding),this},r.prototype.transformCursor=function(t){return t.transform(this.outstanding)},t.AwaitingWithBuffer=n,n.prototype.applyClient=function(t,e){var r=this.buffer.compose(e);return new n(this.outstanding,r)},n.prototype.applyServer=function(t,e){var r=e.constructor.transform,i=r(this.outstanding,e),o=r(this.buffer,i[1]);return t.applyOperation(o[1]),new n(i[0],o[0])},n.prototype.serverRetry=function(t){var e=this.outstanding.compose(this.buffer);return t.sendOperation(e),new r(e)},n.prototype.serverAck=function(t){return t.sendOperation(this.buffer),new r(this.buffer)},n.prototype.transformCursor=function(t){return t.transform(this.outstanding).transform(this.buffer)},t}();var t=t||{};t.EditorClient=function(){"use strict";function e(t,e){this.cursorBefore=t,this.cursorAfter=e}function r(t,e){this.id=t,this.editorAdapter=e,this.li=document.createElement("li")}function n(t,e){s.call(this),this.serverAdapter=t,this.editorAdapter=e,this.undoManager=new h,this.clients={};var r=this;this.editorAdapter.registerCallbacks({change:function(t,e){r.onChange(t,e)},cursorActivity:function(){r.onCursorActivity()},blur:function(){r.onBlur()}}),this.editorAdapter.registerUndo(function(){r.undo()}),this.editorAdapter.registerRedo(function(){r.redo()}),this.serverAdapter.registerCallbacks({ack:function(){r.serverAck()},retry:function(){r.serverRetry()},operation:function(t){r.applyServer(t)},cursor:function(t,e,n){if(r.serverAdapter.userId_!==t){var i=r.getClientObject(t);e?(i.setColor(n),i.updateCursor(r.transformCursor(a.fromJSON(e)))):i.removeCursor()}}})}function i(t,e){function r(){}r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function o(t){return t[t.length-1]}var s=t.Client,a=t.Cursor,h=t.UndoManager,u=t.WrappedOperation;return e.prototype.invert=function(){return new e(this.cursorAfter,this.cursorBefore)},e.prototype.compose=function(t){return new e(this.cursorBefore,t.cursorAfter)},e.prototype.transform=function(t){return new e(this.cursorBefore?this.cursorBefore.transform(t):null,this.cursorAfter?this.cursorAfter.transform(t):null)},r.prototype.setColor=function(t){this.color=t},r.prototype.updateCursor=function(t){this.removeCursor(),this.cursor=t,this.mark=this.editorAdapter.setOtherCursor(t,this.color,this.id)},r.prototype.removeCursor=function(){this.mark&&this.mark.clear()},i(n,s),n.prototype.getClientObject=function(t){var e=this.clients[t];
return e?e:this.clients[t]=new r(t,this.editorAdapter)},n.prototype.applyUnredo=function(t){this.undoManager.add(this.editorAdapter.invertOperation(t)),this.editorAdapter.applyOperation(t.wrapped),this.cursor=t.meta.cursorAfter,this.cursor&&this.editorAdapter.setCursor(this.cursor),this.applyClient(t.wrapped)},n.prototype.undo=function(){var t=this;this.undoManager.canUndo()&&this.undoManager.performUndo(function(e){t.applyUnredo(e)})},n.prototype.redo=function(){var t=this;this.undoManager.canRedo()&&this.undoManager.performRedo(function(e){t.applyUnredo(e)})},n.prototype.onChange=function(t,r){var n=this.cursor;this.updateCursor();var i=this.undoManager.undoStack.length>0&&r.shouldBeComposedWithInverted(o(this.undoManager.undoStack).wrapped),s=new e(this.cursor,n);this.undoManager.add(new u(r,s),i),this.applyClient(t)},n.prototype.updateCursor=function(){this.cursor=this.editorAdapter.getCursor()},n.prototype.onCursorActivity=function(){var t=this.cursor;this.updateCursor(),t&&this.cursor.equals(t)||this.sendCursor(this.cursor)},n.prototype.onBlur=function(){this.cursor=null,this.sendCursor(null)},n.prototype.sendCursor=function(t){this.state instanceof s.AwaitingWithBuffer||this.serverAdapter.sendCursor(t)},n.prototype.sendOperation=function(t){this.serverAdapter.sendOperation(t,this.cursor)},n.prototype.applyOperation=function(t){this.editorAdapter.applyOperation(t),this.updateCursor(),this.undoManager.transform(new u(t,null))},n}();var e,t,r=function(t,e){return function(){return t.apply(e,arguments)}},n=[].slice;(t===void 0||null===t)&&(t={}),t.ACEAdapter=e=function(){function e(t){this.ace=t,this.onCursorActivity=r(this.onCursorActivity,this),this.onBlur=r(this.onBlur,this),this.onChange=r(this.onChange,this),this.aceSession=this.ace.getSession(),this.aceDoc=this.aceSession.getDocument(),this.aceDoc.setNewLineMode("unix"),this.grabDocumentState(),this.ace.on("change",this.onChange),this.ace.on("blur",this.onBlur),this.ace.on("focus",this.onCursorActivity),this.aceSession.selection.on("changeCursor",this.onCursorActivity)}return e.prototype.ignoreChanges=!1,e.prototype.grabDocumentState=function(){return this.lastDocLines=this.aceDoc.getAllLines(),this.lastCursorRange=this.aceSession.selection.getRange()},e.prototype.detach=function(){return this.ace.removeListener("change",this.onChange),this.ace.removeListener("blur",this.onBlur),this.ace.removeListener("focus",this.onCursorActivity),this.aceSession.selection.removeListener("changeCursor",this.onCursorActivity)},e.prototype.onChange=function(t){var e;return this.ignoreChanges?void 0:(e=this.operationFromACEChange(t),this.trigger.apply(this,["change"].concat(n.call(e))),this.grabDocumentState())},e.prototype.onBlur=function(){return this.ace.selection.isEmpty()?this.trigger("blur"):void 0},e.prototype.onCursorActivity=function(){return this.trigger("cursorActivity")},e.prototype.operationFromACEChange=function(e){var r,n,i,o,s,a,h,u,c;return n=e.data,"insertLines"===(u=n.action)||"removeLines"===u?(h=n.lines.join("\n")+"\n",r=n.action.replace("Lines","")):(h=n.text,r=n.action.replace("Text","")),a=this.indexFromPos(n.range.start),s=this.lastDocLines.join(this.aceDoc.$autoNewLine).length-a,"remove"===r&&(s-=h.length),o=(new t.TextOperation).retain(a).insert(h).retain(s),i=(new t.TextOperation).retain(a)["delete"](h).retain(s),"remove"===r&&(c=[i,o],o=c[0],i=c[1]),[o,i]},e.prototype.applyOperationToACE=function(t){var e,r,n,i,o,s,a,h,u;for(null==this.aceRange&&(this.aceRange=(null!=(h=ace.require)?h:require)("ace/range").Range),r=0,u=t.ops,s=0,a=u.length;a>s;s++)n=u[s],n.isRetain()?r+=n.chars:n.isInsert()?(this.aceDoc.insert(this.posFromIndex(r),n.text),r+=n.text.length):n.isDelete()&&(e=this.posFromIndex(r),o=this.posFromIndex(r+n.chars),i=this.aceRange.fromPoints(e,o),this.aceDoc.remove(i));return this.grabDocumentState()},e.prototype.posFromIndex=function(t){var e,r,n,i,o;for(o=this.aceDoc.$lines,r=n=0,i=o.length;i>n&&(e=o[r],!(e.length>=t));r=++n)t-=e.length+this.aceDoc.$autoNewLine.length;return{row:r,column:t}},e.prototype.indexFromPos=function(t,e){var r,n,i,o;for(null==e&&(e=this.lastDocLines),n=0,r=i=0,o=t.row;o>=0?o>i:i>o;r=o>=0?++i:--i)n+=this.lastDocLines[r].length+this.aceDoc.$autoNewLine.length;return n+=t.column},e.prototype.getValue=function(){return this.aceDoc.getValue()},e.prototype.getCursor=function(){var e,r,n,i;try{n=this.indexFromPos(this.aceSession.selection.getRange().start,this.aceDoc.$lines),r=this.indexFromPos(this.aceSession.selection.getRange().end,this.aceDoc.$lines)}catch(o){e=o,n=this.indexFromPos(this.lastCursorRange.start),r=this.indexFromPos(this.lastCursorRange.end)}return n>r&&(i=[r,n],n=i[0],r=i[1]),new t.Cursor(n,r)},e.prototype.setCursor=function(t){var e,r,n,i;return null==this.aceRange&&(this.aceRange=(null!=(n=ace.require)?n:require)("ace/range").Range),r=this.posFromIndex(t.position),e=this.posFromIndex(t.selectionEnd),t.position>t.selectionEnd&&(i=[e,r],r=i[0],e=i[1]),this.aceSession.selection.setSelectionRange(new this.aceRange(r.row,r.column,e.row,e.column))},e.prototype.setOtherCursor=function(t,e,r){var n,i,o,s,a,h,u,c=this;return null==this.otherCursors&&(this.otherCursors={}),o=this.otherCursors[r],o&&(o.start.detach(),o.end.detach(),this.aceSession.removeMarker(o.id)),h=this.posFromIndex(t.position),s=this.posFromIndex(t.selectionEnd),t.selectionEnd<t.position&&(u=[s,h],h=u[0],s=u[1]),n="other-client-selection-"+e.replace("#",""),a=t.position===t.selectionEnd,a&&(s.column+=1,n=n.replace("selection","cursor")),i="."+n+" {\n position: absolute;\n background-color: "+(a?"transparent":e)+";\n border-left: 2px solid "+e+";\n}",this.addStyleRule(i),this.otherCursors[r]=o=new this.aceRange(h.row,h.column,s.row,s.column),o.start=this.aceDoc.createAnchor(o.start),o.end=this.aceDoc.createAnchor(o.end),o.id=this.aceSession.addMarker(o,n,"text"),{clear:function(){return o.start.detach(),o.end.detach(),c.aceSession.removeMarker(o.id)}}},e.prototype.addStyleRule=function(t){var e;if("undefined"!=typeof document&&null!==document&&(this.addedStyleRules||(this.addedStyleRules={},e=document.createElement("style"),document.documentElement.getElementsByTagName("head")[0].appendChild(e),this.addedStyleSheet=e.sheet),!this.addedStyleRules[t]))return this.addedStyleRules[t]=!0,this.addedStyleSheet.insertRule(t,0)},e.prototype.registerCallbacks=function(t){this.callbacks=t},e.prototype.trigger=function(){var t,e,r,i;return e=arguments[0],t=arguments.length>=2?n.call(arguments,1):[],null!=(r=this.callbacks)?null!=(i=r[e])?i.apply(this,t):void 0:void 0},e.prototype.applyOperation=function(t){return t.isNoop()||(this.ignoreChanges=!0),this.applyOperationToACE(t),this.ignoreChanges=!1},e.prototype.registerUndo=function(t){return this.ace.undo=t},e.prototype.registerRedo=function(t){return this.ace.redo=t},e.prototype.invertOperation=function(t){return t.invert(this.getValue())},e}();var t=t||{};t.AttributeConstants={BOLD:"b",ITALIC:"i",UNDERLINE:"u",STRIKE:"s",FONT:"f",FONT_SIZE:"fs",COLOR:"c",BACKGROUND_COLOR:"bc",ENTITY_SENTINEL:"ent",LINE_SENTINEL:"l",LINE_INDENT:"li",LINE_ALIGN:"la",LIST_TYPE:"lt"};var t=t||{};t.EntityManager=function(){function e(){this.entities_={}}return e.prototype.register=function(e,r){t.utils.assert(r.render,"Entity options should include a 'render' function!"),t.utils.assert(r.fromElement,"Entity options should include a 'fromElement' function!"),this.entities_[e]=r},e.prototype.renderToElement=function(t,e){return this.tryRenderToElement_(t,"render",e)},e.prototype.exportToElement=function(t){var e=this.tryRenderToElement_(t,"export")||this.tryRenderToElement_(t,"getHtml")||this.tryRenderToElement_(t,"render");return e.setAttribute("data-firepad-entity",t.type),e},e.prototype.fromElement=function(e){var r=e.getAttribute("data-firepad-entity");if(r||(r=e.nodeName.toLowerCase()),r&&this.entities_[r]){var n=this.entities_[r].fromElement(e);return new t.Entity(r,n)}},e.prototype.tryRenderToElement_=function(e,r,n){var i=e.type,o=e.info;if(this.entities_[i]&&this.entities_[i][r]){var s=this.entities_[i][r](o,n);if(s){if("string"==typeof s){var a=document.createElement("div");return a.innerHTML=s,a.childNodes[0]}if("object"==typeof s)return t.utils.assert(s.nodeType!==void 0,"Error rendering "+i+" entity. render() function"+" must return an html string or a DOM element."),s}}},e}();var t=t||{};t.Entity=function(){function e(t,r){return this instanceof e?(this.type=t,this.info=r||{},void 0):new e(t,r)}var r=t.AttributeConstants,n=r.ENTITY_SENTINEL,i=n+"_";return e.prototype.toAttributes=function(){var t={};t[n]=this.type;for(var e in this.info)t[i+e]=this.info[e];return t},e.fromAttributes=function(t){var r=t[n],o={};for(var s in t)0===s.indexOf(i)&&(o[s.substr(i.length)]=t[s]);return new e(r,o)},e}();var t=t||{};t.RichTextCodeMirror=function(){function e(t,e,r){this.codeMirror=t,this.options_=r||{},this.entityManager_=e,this.currentAttributes_=null;var n=this;this.annotationList_=new o(function(t,e){n.onAnnotationsChanged_(t,e)}),this.initAnnotationList_(),i(this,"onCodeMirrorBeforeChange_"),i(this,"onCodeMirrorChange_"),i(this,"onCursorActivity_"),this.codeMirror.on("beforeChange",this.onCodeMirrorBeforeChange_),this.codeMirror.on("change",this.onCodeMirrorChange_),this.codeMirror.on("cursorActivity",this.onCursorActivity_),this.changeId_=0,this.outstandingChanges_={},this.dirtyLines_=[]}function r(t){this.attributes=t||{}}function n(t){for(var e in t)return!1;return!0}function i(t,e){var r=t[e];t[e]=function(){r.apply(t,arguments)}}var o=t.AnnotationList,s=t.Span,a=t.utils,h=t.AttributeConstants,u="cmrt-",c="cmrt-",l={c:"color",bc:"background-color",fs:"font-size",li:function(t){return"margin-left: "+40*t+"px"}},p={};a.makeEventEmitter(e,["change","attributesChange","newLine"]);var d="";e.LineSentinelCharacter=d;var f="";return e.EntitySentinelCharacter=f,e.prototype.detach=function(){this.codeMirror.off("beforeChange",this.onCodeMirrorBeforeChange_),this.codeMirror.off("change",this.onCodeMirrorChange_),this.codeMirror.off("cursorActivity",this.onCursorActivity_),this.clearAnnotations_()},e.prototype.toggleAttribute=function(t,e){var r=e||!0;if(this.emptySelection_()){var n=this.getCurrentAttributes_();n[t]===r?delete n[t]:n[t]=r,this.currentAttributes_=n}else{var i=this.getCurrentAttributes_(),o=i[t]!==r?r:!1;this.setAttribute(t,o)}},e.prototype.setAttribute=function(t,e){var r=this.codeMirror;if(this.emptySelection_()){var n=this.getCurrentAttributes_();e===!1?delete n[t]:n[t]=e,this.currentAttributes_=n}else this.updateTextAttributes(r.indexFromPos(r.getCursor("start")),r.indexFromPos(r.getCursor("end")),function(r){e===!1?delete r[t]:r[t]=e}),this.updateCurrentAttributes_()},e.prototype.updateTextAttributes=function(t,e,i,o,a){var u={},c=u,l=t,p=this;this.annotationList_.updateSpan(new s(t,e-t),function(t,e){var s={};for(var u in t.attributes)s[u]=t.attributes[u];(!s[h.LINE_SENTINEL]||a)&&i(s);var d={},f={};return p.computeChangedAttributes_(t.attributes,s,d,f),n(d)||(c.next={start:l,end:l+e,attributes:d,attributesInverse:f,origin:o},c=c.next),l+=e,new r(s)}),u.next&&this.trigger("attributesChange",this,u.next)},e.prototype.computeChangedAttributes_=function(t,e,r,n){var i,o={};for(i in t)o[i]=!0;for(i in e)o[i]=!0;for(i in o)i in e?i in t?t[i]!==e[i]&&(r[i]=e[i],n[i]=t[i]):(r[i]=e[i],n[i]=!1):(r[i]=!1,n[i]=t[i])},e.prototype.toggleLineAttribute=function(t,e){var r,n=this.getCurrentLineAttributes_();r=t in n&&n[t]===e?!1:e,this.setLineAttribute(t,r)},e.prototype.setLineAttribute=function(t,e){this.updateLineAttributesForSelection(function(r){e===!1?delete r[t]:r[t]=e})},e.prototype.updateLineAttributesForSelection=function(t){var e=this.codeMirror,r=e.getCursor("start"),n=e.getCursor("end"),i=r.line,o=n.line,s=e.getLine(o),a=this.areLineSentinelCharacters_(s.substr(0,n.ch));o>i&&a&&o--,this.updateLineAttributes(i,o,t)},e.prototype.updateLineAttributes=function(t,e,r){for(var n=t;e>=n;n++){var i=this.codeMirror.getLine(n),o=this.codeMirror.indexFromPos({line:n,ch:0});if(i[0]!==d){var s={};s[h.LINE_SENTINEL]=!0,r(s),this.insertText(o,d,s)}else this.updateTextAttributes(o,o+1,r,null,!0)}},e.prototype.replaceText=function(t,e,r,n,i){this.changeId_++;var o=c+this.changeId_;this.outstandingChanges_[o]={origOrigin:i,attributes:n};var s=this.codeMirror,a=s.posFromIndex(t),h="number"==typeof e?s.posFromIndex(e):null;s.replaceRange(r,a,h,o)},e.prototype.insertText=function(t,e,r,n){this.replaceText(t,null,e,r,n)},e.prototype.removeText=function(t,e,r){var n=this.codeMirror;n.replaceRange("",n.posFromIndex(t),n.posFromIndex(e),r)},e.prototype.insertEntityAtCursor=function(t,e,r){var n=this.codeMirror,i=n.indexFromPos(n.getCursor("head"));this.insertEntityAt(i,t,e,r)},e.prototype.insertEntityAt=function(e,r,n,i){this.codeMirror,this.insertEntity_(e,new t.Entity(r,n),i)},e.prototype.insertEntity_=function(t,e,r){this.replaceText(t,null,f,e.toAttributes(),r)},e.prototype.getAttributeSpans=function(t,e){for(var r=[],n=this.annotationList_.getAnnotatedSpansForSpan(new s(t,e-t)),i=0;n.length>i;i++)r.push({length:n[i].length,attributes:n[i].annotation.attributes});return r},e.prototype.end=function(){var t=this.codeMirror.lineCount()-1;return this.codeMirror.indexFromPos({line:t,ch:this.codeMirror.getLine(t).length})},e.prototype.getRange=function(t,e){var r=this.codeMirror.posFromIndex(t),n=this.codeMirror.posFromIndex(e);return this.codeMirror.getRange(r,n)},e.prototype.initAnnotationList_=function(){var t=this.end();0!==t&&this.annotationList_.insertAnnotatedSpan(new s(0,t),new r)},e.prototype.onAnnotationsChanged_=function(t,e){for(var r,n={},i=0;t.length>i;i++){var o=t[i].annotation.attributes;h.LINE_SENTINEL in o&&(n[this.codeMirror.posFromIndex(t[i].pos).line]=!0),r=t[i].getAttachedObject(),r&&r.clear()}for(i=0;e.length>i;i++){var s=e[i].annotation,a=h.LINE_SENTINEL in s.attributes,u=h.ENTITY_SENTINEL in s.attributes,c=this.codeMirror.posFromIndex(e[i].pos);if(a)n[c.line]=!0;else if(u)this.markEntity_(e[i]);else{var l=this.getClassNameForAttributes_(s.attributes);if(""!==l){var p=this.codeMirror.posFromIndex(e[i].pos+e[i].length);r=this.codeMirror.markText(c,p,{className:l}),e[i].attachObject(r)}}}for(var d in n)this.dirtyLines_.push(this.codeMirror.getLineHandle(Number(d))),this.queueLineMarking_()},e.prototype.queueLineMarking_=function(){if(null==this.lineMarkTimeout_){var t=this;this.lineMarkTimeout_=setTimeout(function(){t.lineMarkTimeout_=null;for(var e=[],r=0;t.dirtyLines_.length>r;r++){var n=t.codeMirror.getLineNumber(t.dirtyLines_[r]);e.push(Number(n))}t.dirtyLines_=[],e.sort(function(t,e){return t-e});var i=-1;for(r=0;e.length>r;r++){var o=e[r];o>i&&(i=t.markLineSentinelCharactersForChangedLines_(o,o))}},0)}},e.prototype.addStyleWithCSS_=function(t){var e=document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t)),e.appendChild(r)},e.prototype.getClassNameForAttributes_=function(e){var r="";for(var n in e){var i=e[n];if(n===h.LINE_SENTINEL)t.utils.assert(i===!0,"LINE_SENTINEL attribute should be true if it exists.");else{var o=(this.options_.cssPrefix||u)+n;if(i!==!0){n!==h.FONT_SIZE||"string"==typeof i&&-1!==i.indexOf("px",i.length-2)||(i+="px");var s=(""+i).toLowerCase().replace(/[^a-z0-9-_]/g,"-");if(o+="-"+s,l[n]&&(p[n]||(p[n]={}),!p[n][s])){p[n][s]=!0;var a=l[n],c="function"==typeof a?a(i):a+": "+i,d=n==h.LINE_INDENT?"pre."+o:"."+o;this.addStyleWithCSS_(d+" { "+c+" }")}}r=r+" "+o}}return r},e.prototype.markEntity_=function(e){for(var r=e.annotation.attributes,n=t.Entity.fromAttributes(r),i=this.codeMirror,o=[],s=0;e.length>s;s++){var a=i.posFromIndex(e.pos+s),h=i.posFromIndex(e.pos+s+1),u={collapsed:!0,atomic:!0,inclusiveLeft:!1,inclusiveRight:!1},c=this.createEntityHandle_(n,e.pos),l=this.entityManager_.renderToElement(n,c);l&&(u.replacedWith=l);var p=i.markText(a,h,u);o.push(p),c.setMarker(p)}e.attachObject({clear:function(){for(var t=0;o.length>t;t++)o[t].clear()}}),this.queueRefresh_()},e.prototype.queueRefresh_=function(){var t=this;this.refreshTimer_||(this.refreshTimer_=setTimeout(function(){t.codeMirror.refresh(),t.refreshTimer_=null},0))},e.prototype.createEntityHandle_=function(e,r){function n(){if(a){var t=a.find();return t?h.codeMirror.indexFromPos(t.from):null}return r}function i(){var t=n();null!=t&&(h.codeMirror.focus(),h.removeText(t,t+1))}function o(r){var o=n();i(),h.insertEntity_(o,new t.Entity(e.type,r))}function s(t){a=t}var a=null,h=this;return{find:n,remove:i,replace:o,setMarker:s}},e.prototype.lineClassRemover_=function(t){var e=this.codeMirror,r=e.getLineHandle(t);return{clear:function(){e.removeLineClass(r,"text",".*")}}},e.prototype.emptySelection_=function(){var t=this.codeMirror.getCursor("start"),e=this.codeMirror.getCursor("end");return t.line===e.line&&t.ch===e.ch},e.prototype.onCodeMirrorBeforeChange_=function(t,e){if("+input"===e.origin||"paste"===e.origin){for(var r=[],n=0;e.text.length>n;n++){var i=e.text[n];i=i.replace(RegExp("["+d+f+"]","g"),""),r.push(i)}e.update(e.from,e.to,r)}},e.prototype.onCodeMirrorChange_=function(t,e){for(var n={},i=n,o=e;o;){var a=this.codeMirror.indexFromPos(o.from),h=o.removed.join("\n");if(h.length>0){for(var u=this.annotationList_.getAnnotatedSpansForSpan(new s(a,h.length)),c=0,l=0;u.length>l;l++){var p=u[l];i.next={start:a,end:a+p.length,removedAttributes:p.annotation.attributes,removed:h.substr(c,p.length),attributes:{},text:"",origin:o.origin},i=i.next,c+=p.length}this.annotationList_.removeSpan(new s(a,h.length))}var d=o.text.join("\n"),f=o.origin;if(d.length>0){var g;"+input"===o.origin||"paste"===o.origin?g=this.currentAttributes_||{}:f in this.outstandingChanges_?(g=this.outstandingChanges_[f].attributes,f=this.outstandingChanges_[f].origOrigin,delete this.outstandingChanges_[f]):g={},this.annotationList_.insertAnnotatedSpan(new s(a,d.length),new r(g)),i.next={start:a,end:a,removedAttributes:{},removed:"",text:d,attributes:g,origin:f},i=i.next}o=o.next}this.markLineSentinelCharactersForChanges_(e),n.next&&this.trigger("change",this,n.next)},e.prototype.markLineSentinelCharactersForChanges_=function(t){for(var e=Number.MAX_VALUE,r=-1,n=t;n;){var i=n.from.line;n.from.ch,(n.removed.length>1||n.removed[0].indexOf(d)>=0)&&(e=Math.min(e,i),r=Math.max(r,i)),n.text.length>1?(e=Math.min(e,i),r=Math.max(r,i+n.text.length-1)):n.text[0].indexOf(d)>=0&&(e=Math.min(e,i),r=Math.max(r,i)),n=n.next}this.markLineSentinelCharactersForChangedLines_(e,r)},e.prototype.markLineSentinelCharactersForChangedLines_=function(t,e){if(Number.MAX_VALUE>t)for(;t>0&&this.lineIsListItemOrIndented_(t-1);)t--;if(e>-1)for(var r=this.codeMirror.lineCount();r>e+1&&this.lineIsListItemOrIndented_(e+1);)e++;for(var n=[],i=this.codeMirror,o=t;e>=o;o++){var s=i.getLine(o),a=i.getLineHandle(o);if(i.removeLineClass(a,"text",".*"),s.length>0)for(var h=s.indexOf(d);h>=0;){for(var u=h;s.length>h&&s[h]===d;){for(var c=i.findMarksAt({line:o,ch:h}),l=0;c.length>l;l++)c[l].isForLineSentinel&&c[l].clear();h++}this.markLineSentinelCharacters_(o,u,h,n),h=s.indexOf(d,h)}else n=[]}return e},e.prototype.markLineSentinelCharacters_=function(t,e,r,n){var i=this.codeMirror,o=null,s=null,a=function(){var t=s.find();return t?t.from.line:null};if(0===e){var u=this.getLineAttributes_(t),c=u[h.LIST_TYPE],l=u[h.LINE_INDENT]||0;for(c&&0===l&&(l=1);l>=n.length;)n.push(1);"o"===c?(o=this.makeOrderedListElement_(n[l]),n[l]++):"u"===c?(o=this.makeUnorderedListElement_(),n[l]=1):"t"===c?(o=this.makeTodoListElement_(!1,a),n[l]=1):"tc"===c&&(o=this.makeTodoListElement_(!0,a),n[l]=1);var p=this.getClassNameForAttributes_(u);""!==p&&this.codeMirror.addLineClass(t,"text",p),n=n.slice(0,l+1)}var d={inclusiveLeft:!0,collapsed:!0};o&&(d.replacedWith=o);var s=i.markText({line:t,ch:e},{line:t,ch:r},d);s.isForLineSentinel=!0},e.prototype.makeOrderedListElement_=function(t){return a.elt("div",t+".",{"class":"firepad-list-left"})},e.prototype.makeUnorderedListElement_=function(){return a.elt("div","•",{"class":"firepad-list-left"})},e.prototype.toggleTodo=function(t){var e,r=h.LIST_TYPE,n=this.getCurrentLineAttributes_();r in n&&("t"===n[r]||"tc"===n[r])?"t"===n[r]?e="tc":"tc"===n[r]&&(e=t?"t":!1):e="t",this.setLineAttribute(r,e)},e.prototype.makeTodoListElement_=function(t,e){var r={type:"checkbox","class":"firepad-todo-left"};t&&(r.checked=!0);var n=a.elt("input",!1,r),i=this;return a.on(n,"click",a.stopEventAnd(function(){i.codeMirror.setCursor({line:e(),ch:0}),i.toggleTodo(!0)})),n},e.prototype.lineIsListItemOrIndented_=function(t){var e=this.getLineAttributes_(t);return(e[h.LIST_TYPE]||!1)!==!1||0!==(e[h.LINE_INDENT]||0)},e.prototype.onCursorActivity_=function(){this.updateCurrentAttributes_()},e.prototype.getCurrentAttributes_=function(){return this.currentAttributes_||this.updateCurrentAttributes_(),this.currentAttributes_},e.prototype.updateCurrentAttributes_=function(){var e=this.codeMirror,r=e.indexFromPos(e.getCursor("anchor")),n=e.indexFromPos(e.getCursor("head")),i=n;if(r>n){for(;this.end()>i;){var o=this.getRange(i,i+1);if("\n"!==o&&o!==d)break;i++}this.end()>i&&i++}else for(;i>0&&(o=this.getRange(i-1,i),"\n"===o||o===d);)i--;var s=this.annotationList_.getAnnotatedSpansForPos(i);this.currentAttributes_={};var a={};s.length>0&&!(h.LINE_SENTINEL in s[0].annotation.attributes)?a=s[0].annotation.attributes:s.length>1&&(t.utils.assert(!(h.LINE_SENTINEL in s[1].annotation.attributes),"Cursor can't be between two line sentinel characters."),a=s[1].annotation.attributes);for(var u in a)"l"!==u&&"lt"!==u&&"li"!==u&&0!==u.indexOf(h.ENTITY_SENTINEL)&&(this.currentAttributes_[u]=a[u])},e.prototype.getCurrentLineAttributes_=function(){var t=this.codeMirror,e=t.getCursor("anchor"),r=t.getCursor("head"),n=r.line;return 0===r.ch&&e.line<r.line&&n--,this.getLineAttributes_(n)},e.prototype.getLineAttributes_=function(e){var r={},n=this.codeMirror.getLine(e);if(n.length>0&&n[0]===d){var i=this.codeMirror.indexFromPos({line:e,ch:0}),o=this.annotationList_.getAnnotatedSpansForSpan(new s(i,1));t.utils.assert(1===o.length);for(var a in o[0].annotation.attributes)r[a]=o[0].annotation.attributes[a]}return r},e.prototype.clearAnnotations_=function(){this.annotationList_.updateSpan(new s(0,this.end()),function(){return new r({})})},e.prototype.newline=function(){var t=this.codeMirror,e=this;if(this.emptySelection_()){var r=t.getCursor("head").line,n=this.getLineAttributes_(r),i=n[h.LIST_TYPE];i&&1===t.getLine(r).length?this.updateLineAttributes(r,r,function(t){delete t[h.LIST_TYPE],delete t[h.LINE_INDENT]}):(t.replaceSelection("\n","end","+input"),this.updateLineAttributes(r+1,r+1,function(t){for(var o in n)t[o]=n[o];"tc"===i&&(t[h.LIST_TYPE]="t"),e.trigger("newLine",{line:r+1,attr:t})}))}else t.replaceSelection("\n","end","+input")},e.prototype.deleteLeft=function(){var t=this.codeMirror,e=t.getCursor("head"),r=this.getLineAttributes_(e.line),n=r[h.LIST_TYPE],i=r[h.LINE_INDENT],o=this.emptySelection_()&&1===e.ch;o&&n?this.updateLineAttributes(e.line,e.line,function(t){delete t[h.LIST_TYPE],delete t[h.LINE_INDENT]}):o&&i&&i>0?this.updateLineAttributes(e.line,e.line,function(t){t[h.LINE_INDENT]--}):t.deleteH(-1,"char")},e.prototype.deleteRight=function(){var t=this.codeMirror,e=t.getCursor("head"),r=t.getLine(e.line),n=this.areLineSentinelCharacters_(r),i=e.line+1<t.lineCount()?t.getLine(e.line+1):"";this.emptySelection_()&&n&&i[0]===d?t.replaceRange("",{line:e.line,ch:0},{line:e.line+1,ch:0},"+input"):t.deleteH(1,"char")},e.prototype.indent=function(){this.updateLineAttributesForSelection(function(t){var e=t[h.LINE_INDENT],r=t[h.LIST_TYPE];e?t[h.LINE_INDENT]++:t[h.LINE_INDENT]=r?2:1})},e.prototype.unindent=function(){this.updateLineAttributesForSelection(function(t){var e=t[h.LINE_INDENT],r=t[h.LIST_TYPE];e&&e>1?t[h.LINE_INDENT]=e-1:(t[h.LINE_INDENT]=!1,r&&(t[h.LIST_TYPE]=!1))})},e.prototype.getText=function(){return this.codeMirror.getValue().replace(RegExp(d,"g"),"")},e.prototype.areLineSentinelCharacters_=function(t){for(var e=0;t.length>e;e++)if(t[e]!==d)return!1;return!0},r.prototype.equals=function(t){if(!(t instanceof r))return!1;var e;for(e in this.attributes)if(t.attributes[e]!==this.attributes[e])return!1;for(e in t.attributes)if(t.attributes[e]!==this.attributes[e])return!1;return!0},e}();var t=t||{};t.RichTextCodeMirrorAdapter=function(){"use strict";function e(t){this.rtcm=t,this.cm=t.codeMirror,s(this,"onChange"),s(this,"onAttributesChange"),s(this,"onCursorActivity"),s(this,"onFocus"),s(this,"onBlur"),this.rtcm.on("change",this.onChange),this.rtcm.on("attributesChange",this.onAttributesChange),this.cm.on("cursorActivity",this.onCursorActivity),this.cm.on("focus",this.onFocus),this.cm.on("blur",this.onBlur)}function r(t,e){return t.line<e.line?-1:t.line>e.line?1:t.ch<e.ch?-1:t.ch>e.ch?1:0}function n(t,e){return 0===r(t,e)}function i(t){var e=t.lineCount()-1;return t.indexFromPos({line:e,ch:t.getLine(e).length})}function o(t,e){if(!t)throw Error(e||"assertion error")}function s(t,e){var r=t[e];t[e]=function(){r.apply(t,arguments)}}function a(t){for(var e in t)return!1;return!0}var h=t.TextOperation,u=t.WrappedOperation,c=t.Cursor;e.prototype.detach=function(){this.rtcm.off("change",this.onChange),this.rtcm.off("attributesChange",this.onAttributesChange),this.cm.off("cursorActivity",this.onCursorActivity),this.cm.off("focus",this.onFocus),this.cm.off("blur",this.onBlur)},e.operationFromCodeMirrorChange=function(t,e){for(var r=[],n=0;t;)r[n++]=t,t=t.next;var o=i(e),s=(new h).retain(o),a=(new h).retain(o);for(n=r.length-1;n>=0;n--){t=r[n];var u=t.start,c=o-u-t.text.length;s=(new h).retain(u)["delete"](t.removed.length).insert(t.text,t.attributes).retain(c).compose(s),a=a.compose((new h).retain(u)["delete"](t.text.length).insert(t.removed,t.removedAttributes).retain(c)),o+=t.removed.length-t.text.length}return[s,a]},e.operationFromAttributesChange=function(t,e){for(var r=i(e),n=new h,s=new h,a=0;t;){var u=t.start-a;o(u>=0),n.retain(u),s.retain(u);var c=t.end-t.start;n.retain(c,t.attributes),s.retain(c,t.attributesInverse),a=t.start+c,t=t.next}return n.retain(r-a),s.retain(r-a),[n,s]},e.applyOperationToCodeMirror=function(t,e){t.ops.length>10&&e.codeMirror.getWrapperElement().setAttribute("style","display: none");for(var r=t.ops,n=0,i=0,o=r.length;o>i;i++){var s=r[i];s.isRetain()?(a(s.attributes)||e.updateTextAttributes(n,n+s.chars,function(t){for(var e in s.attributes)s.attributes[e]===!1?delete t[e]:t[e]=s.attributes[e]},"RTCMADAPTER",!0),n+=s.chars):s.isInsert()?(e.insertText(n,s.text,s.attributes,"RTCMADAPTER"),n+=s.text.length):s.isDelete()&&e.removeText(n,n+s.chars,"RTCMADAPTER")}t.ops.length>10&&(e.codeMirror.getWrapperElement().setAttribute("style",""),e.codeMirror.refresh())},e.prototype.registerCallbacks=function(t){this.callbacks=t},e.prototype.onChange=function(t,r){if("RTCMADAPTER"!==r.origin){var n=e.operationFromCodeMirrorChange(r,this.cm);this.trigger("change",n[0],n[1])}},e.prototype.onAttributesChange=function(t,r){if("RTCMADAPTER"!==r.origin){var n=e.operationFromAttributesChange(r,this.cm);this.trigger("change",n[0],n[1])}},e.prototype.onCursorActivity=e.prototype.onFocus=function(){this.trigger("cursorActivity")},e.prototype.onBlur=function(){this.cm.somethingSelected()||this.trigger("blur")},e.prototype.getValue=function(){return this.cm.getValue()},e.prototype.getCursor=function(){var t,e=this.cm,r=e.getCursor(),i=e.indexFromPos(r);if(e.somethingSelected()){var o=e.getCursor(!0),s=n(r,o)?e.getCursor(!1):o;t=e.indexFromPos(s)}else t=i;return new c(i,t)},e.prototype.setCursor=function(t){this.cm.setSelection(this.cm.posFromIndex(t.position),this.cm.posFromIndex(t.selectionEnd))};var l=function(){if("undefined"!=typeof document){var t={},e=document.createElement("style");document.documentElement.getElementsByTagName("head")[0].appendChild(e);var r=e.sheet;return function(e){t[e]||(t[e]=!0,r.insertRule(e,(r.cssRules||r.rules).length))}}}();return e.prototype.setOtherCursor=function(t,e,r){var n=this.cm.posFromIndex(t.position);if("string"==typeof e&&e.match(/^#[a-fA-F0-9]{3,6}$/)){var i=this.rtcm.end();if("object"==typeof t&&"number"==typeof t.position&&"number"==typeof t.selectionEnd&&!(0>t.position||t.position>i||0>t.selectionEnd||t.selectionEnd>i)){if(t.position===t.selectionEnd){var o=this.cm.cursorCoords(n),s=document.createElement("pre");return s.className="other-client",s.style.borderLeftWidth="2px",s.style.borderLeftStyle="solid",s.innerHTML=" ",s.style.borderLeftColor=e,s.style.height=.9*(o.bottom-o.top)+"px",s.style.marginTop=o.top-o.bottom+"px",s.setAttribute("data-clientid",r),s.style.zIndex=0,this.cm.addWidget(n,s,!1),{clear:function(){var t=s.parentNode;t&&t.removeChild(s)}}}var a="selection-"+e.replace("#",""),h="."+a+" { background: "+e+"; }";l(h);var u,c;return t.selectionEnd>t.position?(u=n,c=this.cm.posFromIndex(t.selectionEnd)):(u=this.cm.posFromIndex(t.selectionEnd),c=n),this.cm.markText(u,c,{className:a})}}},e.prototype.trigger=function(t){var e=Array.prototype.slice.call(arguments,1),r=this.callbacks&&this.callbacks[t];r&&r.apply(this,e)},e.prototype.applyOperation=function(t){e.applyOperationToCodeMirror(t,this.rtcm)},e.prototype.registerUndo=function(t){this.cm.undo=t},e.prototype.registerRedo=function(t){this.cm.redo=t},e.prototype.invertOperation=function(t){for(var e,r,n=0,i=this.rtcm.codeMirror,o=new h,s=0;t.wrapped.ops.length>s;s++){var c=t.wrapped.ops[s];if(c.isRetain())if(a(c.attributes))o.retain(c.chars),n+=c.chars;else for(e=this.rtcm.getAttributeSpans(n,n+c.chars),r=0;e.length>r;r++){var l={};for(var p in c.attributes){var d=c.attributes[p],f=e[r].attributes[p];d===!1?f&&(l[p]=f):d!==f&&(l[p]=f||!1)}o.retain(e[r].length,l),n+=e[r].length}else if(c.isInsert())o["delete"](c.text.length);else if(c.isDelete()){var g=i.getRange(i.posFromIndex(n),i.posFromIndex(n+c.chars));e=this.rtcm.getAttributeSpans(n,n+c.chars);var m=0;for(r=0;e.length>r;r++)o.insert(g.substr(m,e[r].length),e[r].attributes),m+=e[r].length;n+=c.chars}}return new u(o,t.meta.invert())},e}();var t=t||{};t.Formatting=function(){function e(t){return this instanceof e?(this.attributes=t||{},void 0):new e(t)}var r=t.AttributeConstants;return e.prototype.cloneWithNewAttribute_=function(t,r){var n={};for(var i in this.attributes)n[i]=this.attributes[i];return r===!1?delete n[t]:n[t]=r,new e(n)},e.prototype.bold=function(t){return this.cloneWithNewAttribute_(r.BOLD,t)},e.prototype.italic=function(t){return this.cloneWithNewAttribute_(r.ITALIC,t)},e.prototype.underline=function(t){return this.cloneWithNewAttribute_(r.UNDERLINE,t)},e.prototype.strike=function(t){return this.cloneWithNewAttribute_(r.STRIKE,t)},e.prototype.font=function(t){return this.cloneWithNewAttribute_(r.FONT,t)},e.prototype.fontSize=function(t){return this.cloneWithNewAttribute_(r.FONT_SIZE,t)},e.prototype.color=function(t){return this.cloneWithNewAttribute_(r.COLOR,t)},e.prototype.backgroundColor=function(t){return this.cloneWithNewAttribute_(r.BACKGROUND_COLOR,t)},e}();var t=t||{};t.Text=function(){function e(r,n){return this instanceof e?(this.text=r,this.formatting=n||t.Formatting(),void 0):new e(r,n)}return e}();var t=t||{};t.LineFormatting=function(){function e(t){return this instanceof e?(this.attributes=t||{},this.attributes[r.LINE_SENTINEL]=!0,void 0):new e(t)}var r=t.AttributeConstants;return e.LIST_TYPE={NONE:!1,ORDERED:"o",UNORDERED:"u",TODO:"t",TODOCHECKED:"tc"},e.prototype.cloneWithNewAttribute_=function(t,r){var n={};for(var i in this.attributes)n[i]=this.attributes[i];return r===!1?delete n[t]:n[t]=r,new e(n)},e.prototype.indent=function(t){return this.cloneWithNewAttribute_(r.LINE_INDENT,t)},e.prototype.align=function(t){return this.cloneWithNewAttribute_(r.LINE_ALIGN,t)},e.prototype.listItem=function(e){return t.utils.assert(e===!1||"u"===e||"o"===e||"t"===e||"tc"===e),this.cloneWithNewAttribute_(r.LIST_TYPE,e)},e.prototype.getIndent=function(){return this.attributes[r.LINE_INDENT]||0},e.prototype.getAlign=function(){return this.attributes[r.LINE_ALIGN]||0},e.prototype.getListItem=function(){return this.attributes[r.LIST_TYPE]||!1
},e}();var t=t||{};t.Line=function(){function e(r,n){return this instanceof e?("[object Array]"!==Object.prototype.toString.call(r)&&(r=r===void 0?[]:[r]),this.textPieces=r,this.formatting=n||t.LineFormatting(),void 0):new e(r,n)}return e}();var t=t||{};t.ParseHtml=function(){function e(e,r,n){this.listType=e||u.UNORDERED,this.lineFormatting=r||t.LineFormatting(),this.textFormatting=n||t.Formatting()}function r(){this.lines=[],this.currentLine=[],this.currentLineListItemType=null}function n(t,n){var o=document.createElement("div");o.innerHTML=t,c=n;var s=new r,a=new e;return i(o,a,s),s.lines}function i(e,r,n){if(e.nodeType===l.ELEMENT_NODE){var i=c.fromElement(e);if(i)return n.currentLine.push(new t.Text(h.EntitySentinelCharacter,new t.Formatting(i.toAttributes()))),void 0}switch(e.nodeType){case l.TEXT_NODE:var p=e.nodeValue.replace(/[ \n\t]+/g," ");n.currentLine.push(t.Text(p,r.textFormatting));break;case l.ELEMENT_NODE:var d=e.getAttribute("style")||"";switch(r=a(r,d),e.nodeName.toLowerCase()){case"div":case"h1":case"h2":case"h3":case"p":n.newlineIfNonEmpty(r),o(e,r,n),n.newlineIfNonEmpty(r);break;case"center":r=r.withAlign("center"),n.newlineIfNonEmpty(r),o(e,r.withAlign("center"),n),n.newlineIfNonEmpty(r);break;case"b":case"strong":o(e,r.withTextFormatting(r.textFormatting.bold(!0)),n);break;case"u":o(e,r.withTextFormatting(r.textFormatting.underline(!0)),n);break;case"i":case"em":o(e,r.withTextFormatting(r.textFormatting.italic(!0)),n);break;case"s":o(e,r.withTextFormatting(r.textFormatting.strike(!0)),n);break;case"font":var f=e.getAttribute("face"),g=e.getAttribute("color"),m=parseInt(e.getAttribute("size"));f&&(r=r.withTextFormatting(r.textFormatting.font(f))),g&&(r=r.withTextFormatting(r.textFormatting.color(g))),m&&(r=r.withTextFormatting(r.textFormatting.fontSize(m))),o(e,r,n);break;case"br":n.newline(r);break;case"ul":n.newlineIfNonEmptyOrListItem(r);var v="firepad-todo"===e.getAttribute("class")?u.TODO:u.UNORDERED;o(e,r.withListType(v).withIncreasedIndent(),n),n.newlineIfNonEmpty(r);break;case"ol":n.newlineIfNonEmptyOrListItem(r),o(e,r.withListType(u.ORDERED).withIncreasedIndent(),n),n.newlineIfNonEmpty(r);break;case"li":s(e,r,n);break;case"style":break;default:o(e,r,n)}break;default:}}function o(t,e,r){if(t.hasChildNodes())for(var n=0;t.childNodes.length>n;n++)i(t.childNodes[n],e,r)}function s(t,e,r){r.newlineIfNonEmptyOrListItem(e);var n="firepad-checked"===t.getAttribute("class")?u.TODOCHECKED:e.listType;r.makeListItem(n);var i=r.currentLine;o(t,e,r),(i===r.currentLine||r.currentLine.length>0)&&r.newline(e)}function a(e,r){for(var n=e.textFormatting,i=e.lineFormatting,o=r.split(";"),s=0;o.length>s;s++){var a=o[s].split(":");if(2===a.length){var h=t.utils.trim(a[0]).toLowerCase(),u=t.utils.trim(a[1]).toLowerCase();switch(h){case"text-decoration":var c=u.indexOf("underline")>=0,l=u.indexOf("line-through")>=0;n=n.underline(c).strike(l);break;case"font-weight":var p="bold"===u||parseInt(u)>=600;n=n.bold(p);break;case"font-style":var d="italic"===u||"oblique"===u;n=n.italic(d);break;case"color":n=n.color(u.toLowerCase());break;case"background-color":n=n.backgroundColor(u.toLowerCase());break;case"text-align":i=i.align(u.toLowerCase());break;case"font-size":switch(u){case"xx-small":n=n.fontSize(9);break;case"x-small":n=n.fontSize(10);break;case"small":n=n.fontSize(12);break;case"medium":n=n.fontSize(14);break;case"large":n=n.fontSize(18);break;case"x-large":n=n.fontSize(24);break;case"xx-large":n=n.fontSize(32);break;default:n=n.fontSize(parseInt(u))}break;case"font-family":var f=t.utils.trim(u.split(",")[0]);f=f.replace(/['"]/g,""),f=f.replace(/\w\S*/g,function(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()}),n=n.font(f)}}}return e.withLineFormatting(i).withTextFormatting(n)}var h=t.RichTextCodeMirror,u=t.LineFormatting.LIST_TYPE;e.prototype.withTextFormatting=function(t){return new e(this.listType,this.lineFormatting,t)},e.prototype.withLineFormatting=function(t){return new e(this.listType,t,this.textFormatting)},e.prototype.withListType=function(t){return new e(t,this.lineFormatting,this.textFormatting)},e.prototype.withIncreasedIndent=function(){var t=this.lineFormatting.indent(this.lineFormatting.getIndent()+1);return new e(this.listType,t,this.textFormatting)},e.prototype.withAlign=function(t){var r=this.lineFormatting.align(t);return new e(this.listType,r,this.textFormatting)},r.prototype.newlineIfNonEmpty=function(t){this.cleanLine_(),this.currentLine.length>0&&this.newline(t)},r.prototype.newlineIfNonEmptyOrListItem=function(t){this.cleanLine_(),(this.currentLine.length>0||null!==this.currentLineListItemType)&&this.newline(t)},r.prototype.newline=function(e){this.cleanLine_();var r=e.lineFormatting;null!==this.currentLineListItemType&&(r=r.listItem(this.currentLineListItemType),this.currentLineListItemType=null),this.lines.push(t.Line(this.currentLine,r)),this.currentLine=[]},r.prototype.makeListItem=function(t){this.currentLineListItemType=t},r.prototype.isListItem=function(){return null!==this.currentLineListItemType},r.prototype.cleanLine_=function(){if(this.currentLine.length>0){var t=this.currentLine.length-1;this.currentLine[0].text=this.currentLine[0].text.replace(/^ +/,""),this.currentLine[t].text=this.currentLine[t].text.replace(/ +$/g,"");for(var e=0;this.currentLine.length>e;e++)this.currentLine[e].text=this.currentLine[e].text.replace(/\u00a0/g," ")}1===this.currentLine.length&&""===this.currentLine[0].text&&(this.currentLine=[])};var c,l=l||{ELEMENT_NODE:1,TEXT_NODE:3};return n}();var t=t||{};return t.Firepad=function(e){function r(t,e,i){if(!(this instanceof r))return new r(t,e,i);if(!m&&!v)throw Error("Couldn't find CodeMirror or ACE. Did you forget to include codemirror.js or ace.js?");if(m&&e instanceof m){this.codeMirror_=this.editor_=e;var o=this.codeMirror_.getValue();if(""!==o)throw Error("Can't initialize Firepad with a CodeMirror instance that already contains text.")}else if(v&&e&&e.session instanceof v.EditSession){if(this.ace_=this.editor_=e,o=this.ace_.getValue(),""!==o)throw Error("Can't initialize Firepad with an ACE instance that already contains text.")}else this.codeMirror_=this.editor_=new m(e);var h=this.codeMirror_?this.codeMirror_.getWrapperElement():this.ace_.container;this.firepadWrapper_=f.elt("div",null,{"class":"firepad"}),h.parentNode.replaceChild(this.firepadWrapper_,h),this.firepadWrapper_.appendChild(h),f.on(h,"dragstart",f.stopEvent),this.editor_.firepad=this,this.options_=i||{},this.getOption("richTextShortcuts",!1)&&(m.keyMap.richtext||this.initializeKeyMap_(),this.codeMirror_.setOption("keyMap","richtext"),this.firepadWrapper_.className+=" firepad-richtext"),this.imageInsertionUI=this.getOption("imageInsertionUI",!0),this.getOption("richTextToolbar",!1)&&(this.addToolbar_(),this.firepadWrapper_.className+=" firepad-richtext firepad-with-toolbar"),this.addPoweredByLogo_(),this.codeMirror_&&this.codeMirror_.refresh();var d=this.getOption("userId",t.push().name()),g=this.getOption("userColor",n(d));this.entityManager_=new p,this.registerBuiltinEntities_(),this.firebaseAdapter_=new c(t,d,g),this.codeMirror_?(this.richTextCodeMirror_=new a(this.codeMirror_,this.entityManager_,{cssPrefix:"firepad-"}),this.editorAdapter_=new s(this.richTextCodeMirror_)):this.editorAdapter_=new u(this.ace_),this.client_=new l(this.firebaseAdapter_,this.editorAdapter_);var y=this;this.firebaseAdapter_.on("cursor",function(){y.trigger.apply(y,["cursor"].concat([].slice.call(arguments)))}),this.codeMirror_&&this.richTextCodeMirror_.on("newLine",function(){y.trigger.apply(y,["newLine"].concat([].slice.call(arguments)))}),this.firebaseAdapter_.on("ready",function(){y.ready_=!0,this.ace_&&this.editorAdapter_.grabDocumentState(),y.trigger("ready")}),"Microsoft Internet Explorer"==navigator.appName&&navigator.userAgent.match(/MSIE 8\./)&&(window.onload=function(){var t=document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",e.styleSheet.cssText=":before,:after{content:none !important;}",t.appendChild(e),setTimeout(function(){t.removeChild(e)},0)})}function n(t){for(var e=1,r=0;t.length>r;r++)e=17*(e+t.charCodeAt(r))%360;var n=e/360;return o(n,1,.85)}function i(t,e,r){function n(t){var e=Math.round(255*t).toString(16);return 1===e.length?"0"+e:e}return"#"+n(t)+n(e)+n(r)}function o(t,e,r){if(0===e)return i(r,r,r);var n=.5>r?r*(1+e):r+e-e*r,o=2*r-n,s=function(t){return 0>t&&(t+=1),t>1&&(t-=1),1>6*t?o+6*(n-o)*t:1>2*t?n:2>3*t?o+6*(n-o)*(2/3-t):o};return i(s(t+1/3),s(t),s(t-1/3))}if(!t.RichTextCodeMirrorAdapter)throw Error("Oops! It looks like you're trying to include lib/firepad.js directly. This is actually one of many source files that make up firepad. You want dist/firepad.js instead.");var s=t.RichTextCodeMirrorAdapter,a=t.RichTextCodeMirror,h=t.RichTextToolbar,u=t.ACEAdapter,c=t.FirebaseAdapter,l=t.EditorClient,p=t.EntityManager,d=t.AttributeConstants,f=t.utils,g=t.LineFormatting.LIST_TYPE,m=e.CodeMirror,v=e.ace;return f.makeEventEmitter(r),r.fromCodeMirror=r,r.fromACE=r,r.prototype.dispose=function(){this.zombie_=!0;var t=this.codeMirror_?this.codeMirror_.getWrapperElement():this.ace_.container;this.firepadWrapper_.removeChild(t),this.firepadWrapper_.parentNode.replaceChild(t,this.firepadWrapper_),this.editor_.firepad=null,this.codeMirror_&&"richtext"===this.codeMirror_.getOption("keyMap")&&this.codeMirror_.setOption("keyMap","default"),this.firebaseAdapter_.dispose(),this.editorAdapter_.detach(),this.richTextCodeMirror_&&this.richTextCodeMirror_.detach()},r.prototype.setUserId=function(t){this.firebaseAdapter_.setUserId(t)},r.prototype.setUserColor=function(t){this.firebaseAdapter_.setColor(t)},r.prototype.getText=function(){return this.assertReady_("getText"),this.codeMirror_?this.richTextCodeMirror_.getText():this.ace_.getSession().getDocument().getValue()},r.prototype.setText=function(t){return this.ace_?this.ace_.getSession().getDocument().setValue(t):(this.codeMirror_.getWrapperElement().setAttribute("style","display: none"),this.codeMirror_.setValue(""),this.insertText(0,t),this.codeMirror_.getWrapperElement().setAttribute("style",""),this.codeMirror_.refresh(),void 0)},r.prototype.insertTextAtCursor=function(t){this.insertText(this.codeMirror_.indexFromPos(this.codeMirror_.getCursor()),t)},r.prototype.insertText=function(e,r){function n(t,r){h.richTextCodeMirror_.insertText(e,t,r||null),e+=t.length,s="\n"===t[t.length-1]}function i(e){if(e instanceof t.Text)n(e.text,e.formatting.attributes);else{if("string"!=typeof e)throw console.error("Can't insert into firepad",e),"Can't insert into firepad: "+e;n(e)}}function o(t){s&&n(a.LineSentinelCharacter,t.formatting.attributes);for(var e=0;t.textPieces.length>e;e++)i(t.textPieces[e]);n("\n")}f.assert(!this.ace_,"Not supported for ace yet."),this.assertReady_("insertText"),"[object Array]"!==Object.prototype.toString.call(r)&&(r=[r]);for(var s=0===e,h=this,u=0;r.length>u;u++)r[u]instanceof t.Line?o(r[u]):i(r[u])},r.prototype.getOperationForSpan=function(e,r){for(var n=this.richTextCodeMirror_.getRange(e,r),i=this.richTextCodeMirror_.getAttributeSpans(e,r),o=0,s=new t.TextOperation,a=0;i.length>a;a++)s.insert(n.substr(o,i[a].length),i[a].attributes),o+=i[a].length;return s},r.TODO_STYLE='<style>ul.firepad-todo { list-style: none; margin-left: 0; padding-left: 0; } ul.firepad-todo > li { padding-left: 1em; text-indent: -1em; } ul.firepad-todo > li:before { content: "\\2610"; padding-right: 5px; } ul.firepad-todo > li.firepad-checked:before { content: "\\2611"; padding-right: 5px; }</style>\n',r.prototype.getHtml=function(){return this.getHtmlFromRange(null,null)},r.prototype.getHtmlFromSelection=function(){var t=this.codeMirror_.getCursor("start"),e=this.codeMirror_.getCursor("end"),r=this.codeMirror_.indexFromPos(t),n=this.codeMirror_.indexFromPos(e);return this.getHtmlFromRange(r,n)},r.prototype.getHtmlFromRange=function(e,n){function i(t){return t===g.ORDERED?"<ol>":t===g.UNORDERED?"<ul>":'<ul class="firepad-todo">'}function o(t){return t===g.ORDERED?"</ol>":"</ul>"}function s(t,e){return t===e||t===g.TODO&&e===g.TODOCHECKED||t===g.TODOCHECKED&&e===g.TODO}var a=null!=e&&null!=n?this.getOperationForSpan(e,n):this.firebaseAdapter_.getDocument(),h="",u=!0;h+=r.EXPORT_HTML_STYLE;for(var c=[],l=!1,p=!0,m=!0,v=0,y=a.ops[v],_=!1;y;){f.assert(y.isInsert());var b=y.attributes;if(u){u=!1;var E=0,C=null,x="left";d.LINE_SENTINEL in b&&(E=b[d.LINE_INDENT]||0,C=b[d.LIST_TYPE]||null,x=b[d.LINE_ALIGN]||"left"),C&&(E=E||1),l?(h+="</li>",l=!1):p||(m&&(h+="<br/>"),h+="</div>"),p=!1,f.assert(E>=0,"Indent must not be negative.");for(;c.length>E||E===c.length&&null!==C&&!s(C,c[c.length-1]);)h+=o(c.pop());for(;E>c.length;){var L=C||g.UNORDERED;_=C==g.TODO||C==g.TODOCHECKED||_,h+=i(L),c.push(L)}var T="left"!==x?' style="text-align:'+x+'"':"";if(C){var w="";switch(C){case g.TODOCHECKED:w=' class="firepad-checked"';break;case g.TODO:w=' class="firepad-unchecked"'}h+="<li"+w+T+">",l=!0}else h+="<div"+T+">";m=!0}if(d.LINE_SENTINEL in b)y=a.ops[++v];else if(d.ENTITY_SENTINEL in b){for(var A=0;y.text.length>A;A++){var I=t.Entity.fromAttributes(b),N=this.entityManager_.exportToElement(I);h+=N.outerHTML}y=a.ops[++v]}else{var S="",M="";for(var k in b){var e,n,O=b[k];k===d.BOLD||k===d.ITALIC||k===d.UNDERLINE||k===d.STRIKE?(f.assert(O===!0),e=n=k):k===d.FONT_SIZE?(e='span style="font-size: '+O,e+="string"!=typeof O||-1===O.indexOf("px",O.length-2)?'px"':'"',n="span"):k===d.FONT?(e='span style="font-family: '+O+'"',n="span"):k===d.COLOR?(e='span style="color: '+O+'"',n="span"):k===d.BACKGROUND_COLOR?(e='span style="background-color: '+O+'"',n="span"):f.log(!1,"Encountered unknown attribute while rendering html: "+k),e&&(S+="<"+e+">"),n&&(M="</"+n+">"+M)}var R=y.text,F=R.indexOf("\n");F>=0?(u=!0,y=R.length-1>F?new t.TextOp("insert",R.substr(F+1),b):a.ops[++v],R=R.substr(0,F)):y=a.ops[++v],R=R.replace(/ +/g,function(t){return Array(t.length+1).join(" ")}).replace(/^ /," ").replace(/ $/," "),R.length>0&&(m=!1),h+=S+this.textToHtml_(R)+M}}for(l?h+="</li>":p||(m&&(h+=" "),h+="</div>");c.length>0;)h+=o(c.pop());return _&&(h=r.TODO_STYLE+h),h},r.EXPORT_HTML_STYLE="",r.prototype.textToHtml_=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/\u00a0/g," ")},r.prototype.insertHtml=function(e,r){var n=t.ParseHtml(r,this.entityManager_);this.insertText(e,n)},r.prototype.insertHtmlAtCursor=function(t){this.insertHtml(this.codeMirror_.indexFromPos(this.codeMirror_.getCursor()),t)},r.prototype.setHtml=function(e){var r=t.ParseHtml(e,this.entityManager_);this.setText(r)},r.prototype.isHistoryEmpty=function(){return this.assertReady_("isHistoryEmpty"),this.firebaseAdapter_.isHistoryEmpty()},r.prototype.bold=function(){this.richTextCodeMirror_.toggleAttribute(d.BOLD),this.codeMirror_.focus()},r.prototype.italic=function(){this.richTextCodeMirror_.toggleAttribute(d.ITALIC),this.codeMirror_.focus()},r.prototype.underline=function(){this.richTextCodeMirror_.toggleAttribute(d.UNDERLINE),this.codeMirror_.focus()},r.prototype.strike=function(){this.richTextCodeMirror_.toggleAttribute(d.STRIKE),this.codeMirror_.focus()},r.prototype.fontSize=function(t){this.richTextCodeMirror_.setAttribute(d.FONT_SIZE,t),this.codeMirror_.focus()},r.prototype.font=function(t){this.richTextCodeMirror_.setAttribute(d.FONT,t),this.codeMirror_.focus()},r.prototype.color=function(t){this.richTextCodeMirror_.setAttribute(d.COLOR,t),this.codeMirror_.focus()},r.prototype.highlight=function(){this.richTextCodeMirror_.toggleAttribute(d.BACKGROUND_COLOR,"rgba(255,255,0,.65)"),this.codeMirror_.focus()},r.prototype.align=function(t){if("left"!==t&&"center"!==t&&"right"!==t)throw Error('align() must be passed "left", "center", or "right".');this.richTextCodeMirror_.toggleLineAttribute(d.LINE_ALIGN,t),this.codeMirror_.focus()},r.prototype.orderedList=function(){this.richTextCodeMirror_.toggleLineAttribute(d.LIST_TYPE,"o"),this.codeMirror_.focus()},r.prototype.unorderedList=function(){this.richTextCodeMirror_.toggleLineAttribute(d.LIST_TYPE,"u"),this.codeMirror_.focus()},r.prototype.todo=function(){this.richTextCodeMirror_.toggleTodo(),this.codeMirror_.focus()},r.prototype.newline=function(){this.richTextCodeMirror_.newline()},r.prototype.deleteLeft=function(){this.richTextCodeMirror_.deleteLeft()},r.prototype.deleteRight=function(){this.richTextCodeMirror_.deleteRight()},r.prototype.indent=function(){this.richTextCodeMirror_.indent(),this.codeMirror_.focus()},r.prototype.unindent=function(){this.richTextCodeMirror_.unindent(),this.codeMirror_.focus()},r.prototype.undo=function(){this.codeMirror_.undo()},r.prototype.redo=function(){this.codeMirror_.redo()},r.prototype.insertEntity=function(t,e,r){this.richTextCodeMirror_.insertEntityAtCursor(t,e,r)},r.prototype.insertEntityAt=function(t,e,r,n){this.richTextCodeMirror_.insertEntityAt(t,e,r,n)},r.prototype.registerEntity=function(t,e){this.entityManager_.register(t,e)},r.prototype.getOption=function(t,e){return t in this.options_?this.options_[t]:e},r.prototype.assertReady_=function(t){if(!this.ready_)throw Error('You must wait for the "ready" event before calling '+t+".");if(this.zombie_)throw Error("You can't use a Firepad after calling dispose()!")},r.prototype.makeImageDialog_=function(){this.makeDialog_("img","Insert image url")},r.prototype.makeDialog_=function(t,e){var r=this,n=function(){var t=document.getElementById("overlay");t.style.visibility="hidden",r.firepadWrapper_.removeChild(t)},i=function(){var e=document.getElementById("overlay");e.style.visibility="hidden";var n=document.getElementById(t).value;null!==n&&r.insertEntity(t,{src:n}),r.firepadWrapper_.removeChild(e)},o=f.elt("input",null,{"class":"firepad-dialog-input",id:t,type:"text",placeholder:e,autofocus:"autofocus"}),s=f.elt("a","Submit",{"class":"firepad-btn",id:"submitbtn"});f.on(s,"click",f.stopEventAnd(i));var a=f.elt("a","Cancel",{"class":"firepad-btn"});f.on(a,"click",f.stopEventAnd(n));var h=f.elt("div",[s,a],{"class":"firepad-btn-group"}),u=f.elt("div",[o,h],{"class":"firepad-dialog-div"}),c=f.elt("div",[u],{"class":"firepad-dialog",id:"overlay"});this.firepadWrapper_.appendChild(c)},r.prototype.addToolbar_=function(){this.toolbar=new h(this.imageInsertionUI),this.toolbar.on("undo",this.undo,this),this.toolbar.on("redo",this.redo,this),this.toolbar.on("bold",this.bold,this),this.toolbar.on("italic",this.italic,this),this.toolbar.on("underline",this.underline,this),this.toolbar.on("strike",this.strike,this),this.toolbar.on("font-size",this.fontSize,this),this.toolbar.on("font",this.font,this),this.toolbar.on("color",this.color,this),this.toolbar.on("left",function(){this.align("left")},this),this.toolbar.on("center",function(){this.align("center")},this),this.toolbar.on("right",function(){this.align("right")},this),this.toolbar.on("ordered-list",this.orderedList,this),this.toolbar.on("unordered-list",this.unorderedList,this),this.toolbar.on("todo-list",this.todo,this),this.toolbar.on("indent-increase",this.indent,this),this.toolbar.on("indent-decrease",this.unindent,this),this.toolbar.on("insert-image",this.makeImageDialog_,this),this.firepadWrapper_.insertBefore(this.toolbar.element(),this.firepadWrapper_.firstChild)},r.prototype.registerBuiltinEntities_=function(){var t=["src","alt","width","height","style","class"];this.registerEntity("img",{render:function(t){f.assert(t.src,"image entity should have 'src'!");for(var e=["src","alt","width","height","style","class"],r="<img ",n=0;e.length>n;n++){var i=e[n];i in t&&(r+=" "+i+'="'+t[i]+'"')}return r+=">"},fromElement:function(e){for(var r={},n=0;t.length>n;n++){var i=t[n];e.hasAttribute(i)&&(r[i]=e.getAttribute(i))}return r}})},r.prototype.addPoweredByLogo_=function(){var t=f.elt("a",null,{"class":"powered-by-firepad"});t.setAttribute("href","http://www.firepad.io/"),t.setAttribute("target","_blank"),this.firepadWrapper_.appendChild(t)},r.prototype.initializeKeyMap_=function(){function t(t){return function(e){t.call(e.firepad)}}m.keyMap.richtext={"Ctrl-B":t(this.bold),"Cmd-B":t(this.bold),"Ctrl-I":t(this.italic),"Cmd-I":t(this.italic),"Ctrl-U":t(this.underline),"Cmd-U":t(this.underline),"Ctrl-H":t(this.highlight),"Cmd-H":t(this.highlight),Enter:t(this.newline),Delete:t(this.deleteRight),Backspace:t(this.deleteLeft),Tab:t(this.indent),"Shift-Tab":t(this.unindent),fallthrough:["default"]}},r}(this),t.Firepad.Formatting=t.Formatting,t.Firepad.Text=t.Text,t.Firepad.Entity=t.Entity,t.Firepad.LineFormatting=t.LineFormatting,t.Firepad.Line=t.Line,t.Firepad.TextOperation=t.TextOperation,t.Firepad}();