diff --git a/build/onion-editor.js b/build/onion-editor.js index 26baab5..dbff6fc 100644 --- a/build/onion-editor.js +++ b/build/onion-editor.js @@ -3534,7 +3534,7 @@ define('plugins/core/patches/commands/bold',[],function () { return scribe.api.CommandPatch.prototype.queryEnabled.apply(this, arguments) && ! headingNode; }; - + // TODO: We can't use STRONGs because this would mean we have to // re-implement the `queryState` command, which would be difficult. @@ -10741,6 +10741,28 @@ define('onion-editor',[ scribe.use(scribePluginPlaceholder(options.placeholder)); } + // For now, we need to patch some scribe commands, just in case. + scribe.commandPatches.bold.execute = function (value) { + if (this.selection === undefined) { + document.execCommand(this.commandName, false, value || null); + } else { + scribe.transactionManager.run(function () { + document.execCommand(this.commandName, false, value || null); + }.bind(this)); + } + }; + var italicCommand = new scribe.api.CommandPatch('italic'); + italicCommand.execute = function (value) { + if (this.selection === undefined) { + document.execCommand(this.commandName, false, value || null); + } else { + scribe.transactionManager.run(function () { + document.execCommand(this.commandName, false, value || null); + }.bind(this)); + } + }; + scribe.commandPatches['italic'] = italicCommand; + var keyCommands = {}; var ctrlKey = function (event) { return event.metaKey || event.ctrlKey; }; @@ -10760,24 +10782,24 @@ define('onion-editor',[ // Bold if (options.formatting.indexOf('bold') !== -1) { - // keyCommands.bold = function (event) { return event.metaKey && event.keyCode === 66; }; // b + keyCommands.bold = function (event) { return event.metaKey && event.keyCode === 66; }; // b tags.b = {}; } // Italics if (options.formatting.indexOf('italic') !== -1) { - // keyCommands.italic = function (event) { return event.metaKey && event.keyCode === 73; }; // i + keyCommands.italic = function (event) { return event.metaKey && event.keyCode === 73; }; // i tags.i = {}; tags.em = {}; } // Strike if (options.formatting.indexOf('strike') !== -1) { - // keyCommands.strikeThrough = function (event) { return event.altKey && event.shiftKey && event.keyCode === 83; }; // s + keyCommands.strikeThrough = function (event) { return event.altKey && event.shiftKey && event.keyCode === 83; }; // s tags.s = {}; } - //Remove formatting... + // Remove formatting... keyCommands.removeFormat = function (event) { return event.altKey && event.shiftKey && event.keyCode === 65; }; // a // Links diff --git a/build/onion-editor.min.js b/build/onion-editor.min.js index aa91c90..585ce03 100644 --- a/build/onion-editor.min.js +++ b/build/onion-editor.min.js @@ -1,4 +1,4 @@ /*! onion-editor 2014-08-12 */ !function(a,b){"function"==typeof define?define(b):"object"==typeof exports?module.exports=b():a.OnionEditor=b()}(this,function(){var a,b,c;return function(d){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=s.map,p=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),a=n.concat(a),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||p)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&p&&p[d]&&(i=p[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(a,b){return function(){return n.apply(d,v.call(arguments,0).concat([a,b]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(a){if(e(r,a)){var b=r[a];delete r[a],t[a]=!0,m.apply(d,b)}if(!e(q,a)&&!e(t,a))throw new Error("No "+a);return q[a]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(a,b,c,f){var h,k,l,m,n,s,u=[],v=typeof c;if(f=f||a,"undefined"===v||"function"===v){for(b=!b.length&&c.length?["require","exports","module"]:b,n=0;ne?0:e);++d2?a(c,17,b(arguments,2),null,d):a(c,1,null,null,d)}return c}),c("lodash-amd/modern/utilities/identity",[],function(){function a(a){return a}return a}),c("lodash-amd/modern/support",["./internals/isNative"],function(a){var b=/\bthis\b/,c={};return c.funcDecomp=!a(window.WinRTError)&&b.test(function(){return this}),c.funcNames="string"==typeof Function.name,c}),c("lodash-amd/modern/internals/baseCreateCallback",["../functions/bind","../utilities/identity","./setBindData","../support"],function(a,b,c,d){function e(e,i,j){if("function"!=typeof e)return b;if("undefined"==typeof i||!("prototype"in e))return e;var k=e.__bindData__;if("undefined"==typeof k&&(d.funcNames&&(k=!e.name),k=k||!d.funcDecomp,!k)){var l=h.call(e);d.funcNames||(k=!f.test(l)),k||(k=g.test(l),c(e,k))}if(k===!1||k!==!0&&1&k[1])return e;switch(j){case 1:return function(a){return e.call(i,a)};case 2:return function(a,b){return e.call(i,a,b)};case 3:return function(a,b,c){return e.call(i,a,b,c)};case 4:return function(a,b,c,d){return e.call(i,a,b,c,d)}}return a(e,i)}var f=/^\s*function[ \n\r\t]+\w/,g=/\bthis\b/,h=Function.prototype.toString;return e}),c("lodash-amd/modern/objects/forIn",["../internals/baseCreateCallback","../internals/objectTypes"],function(a,b){var c=function(c,d,e){var f,g=c,h=g;if(!g)return h;if(!b[typeof g])return h;d=d&&"undefined"==typeof e?d:a(d,e,3);for(f in g)if(d(g[f],f,c)===!1)return h;return h};return c}),c("lodash-amd/modern/internals/arrayPool",[],function(){var a=[];return a}),c("lodash-amd/modern/internals/getArray",["./arrayPool"],function(a){function b(){return a.pop()||[]}return b}),c("lodash-amd/modern/internals/maxPoolSize",[],function(){var a=40;return a}),c("lodash-amd/modern/internals/releaseArray",["./arrayPool","./maxPoolSize"],function(a,b){function c(c){c.length=0,a.length-1:void 0});return u.pop(),v.pop(),G&&(e(u),e(v)),w}var g="[object Arguments]",h="[object Array]",i="[object Boolean]",j="[object Date]",k="[object Number]",l="[object Object]",m="[object RegExp]",n="[object String]",o=Object.prototype,p=o.toString,q=o.hasOwnProperty;return f}),c("lodash-amd/modern/utilities/property",[],function(){function a(a){return function(b){return b[a]}}return a}),c("lodash-amd/modern/functions/createCallback",["../internals/baseCreateCallback","../internals/baseIsEqual","../objects/isObject","../objects/keys","../utilities/property"],function(a,b,c,d,e){function f(f,g,h){var i=typeof f;if(null==f||"function"==i)return a(f,g,h);if("object"!=i)return e(f);var j=d(f),k=j[0],l=f[k];return 1!=j.length||l!==l||c(l)?function(a){for(var c=j.length,d=!1;c--&&(d=b(a[j[c]],f[j[c]],null,!0)););return d}:function(a){var b=a[k];return l===b&&(0!==l||1/l==1/b)}}return f}),c("lodash-amd/modern/objects/forOwn",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;if(!c[typeof h])return i;e=e&&"undefined"==typeof f?e:a(e,f,3);for(var j=-1,k=c[typeof h]&&b(h),l=k?k.length:0;++j0){var b=document.createElement(f.nodeName);a.forEach(function(a){b.appendChild(a)}),f.parentNode.insertBefore(b,f.nextElementSibling)}}if(this.queryState()){var d=new a.api.Selection,e=d.range,f=d.getContaining(function(a){return"OL"===a.nodeName||"UL"===a.nodeName}),g=d.getContaining(function(a){return"LI"===a.nodeName});a.transactionManager.run(function(){if(g){var b=new a.api.Node(g).nextAll();c(b),d.placeMarkers();var h=document.createElement("p");h.innerHTML=g.innerHTML,f.parentNode.insertBefore(h,f.nextElementSibling),g.parentNode.removeChild(g)}else{var i=Array.prototype.map.call(f.querySelectorAll("li"),function(a){return e.intersectsNode(a)&&a}).filter(function(a){return a}),j=i.slice(-1)[0],k=new a.api.Node(j).nextAll();c(k),d.placeMarkers();var l=document.createDocumentFragment();i.forEach(function(a){var b=document.createElement("p");b.innerHTML=a.innerHTML,l.appendChild(b)}),f.parentNode.insertBefore(l,f.nextElementSibling),i.forEach(function(a){a.parentNode.removeChild(a)})}0===f.childNodes.length&&f.parentNode.removeChild(f),d.selectMarkers()}.bind(this))}else a.api.Command.prototype.execute.call(this,b)},b.prototype.queryEnabled=function(){return a.api.Command.prototype.queryEnabled.call(this)&&a.allowsBlockElements()},a.commands.insertOrderedList=new b("insertOrderedList"),a.commands.insertUnorderedList=new b("insertUnorderedList")}}}),c("plugins/core/commands/outdent",[],function(){return function(){return function(a){var b=new a.api.Command("outdent");b.queryEnabled=function(){var b=new a.api.Selection,c=b.getContaining(function(a){return"UL"===a.nodeName||"OL"===a.nodeName});return a.api.Command.prototype.queryEnabled.call(this)&&a.allowsBlockElements()&&!c},a.commands.outdent=b}}}),c("plugins/core/commands/redo",[],function(){return function(){return function(a){var b=new a.api.Command("redo");b.execute=function(){var b=a.undoManager.redo();"undefined"!=typeof b&&a.restoreFromHistory(b)},b.queryEnabled=function(){return a.undoManager.position1},a.commands.undo=b,a.el.addEventListener("keydown",function(a){a.shiftKey||!a.metaKey&&!a.ctrlKey||90!==a.keyCode||(a.preventDefault(),b.execute())})}}}),c("plugins/core/commands",["./commands/indent","./commands/insert-list","./commands/outdent","./commands/redo","./commands/subscript","./commands/superscript","./commands/undo"],function(a,b,c,d,e,f,g){return{indent:a,insertList:b,outdent:c,redo:d,subscript:e,superscript:f,undo:g}}),c("lodash-amd/modern/internals/baseIndexOf",[],function(){function a(a,b,c){for(var d=(c||0)-1,e=a?a.length:0;++dh?f(0,k+h):h)||0,c(e)?l=j(e,g,h)>-1:"number"==typeof k?l=(d(e)?e.indexOf(g,h):j(e,g,h))>-1:b(e,function(a){return++i>=h?!(l=a===g):void 0}),l}var f=Math.max;return e}),c("lodash-amd/modern/objects/values",["./keys"],function(a){function b(b){for(var c=-1,d=a(b),e=d.length,f=Array(e);++c0;)a.insertBefore(b.childNodes[0],b);a.removeChild(b)}var e=["P","LI","DIV","BLOCKQUOTE","UL","OL","H1","H2","H3","H4","H5","H6"];return{isBlockElement:b,isSelectionMarkerNode:c,unwrap:d}}),c("scribe-common/src/node",[],function(){function a(a){return a.nodeType===Node.TEXT_NODE&&""===a.textContent}function b(a,b){return b.parentNode.insertBefore(a,b.nextSibling)}function c(a){return a.parentNode.removeChild(a)}return{isEmptyTextNode:a,insertAfter:b,removeNode:c}}),c("dom-observer",["lodash-amd/modern/arrays/flatten","lodash-amd/modern/collections/toArray","scribe-common/src/element","scribe-common/src/node"],function(a,b,c,d){function e(e,f){function g(e){var f=a(e.map(function(a){var c=b(a.addedNodes),d=b(a.removedNodes);return c.concat(d)})),g=f.filter(function(a){return!d.isEmptyTextNode(a)}).filter(function(a){return!c.isSelectionMarkerNode(a)});return g.length>0}var h=!1,i=new MutationObserver(function(a){if(!h&&g(a)){h=!0;try{f()}finally{setTimeout(function(){h=!1},0)}}});return i.observe(e,{attributes:!0,childList:!0,subtree:!0}),i}return e}),c("plugins/core/events",["lodash-amd/modern/collections/contains","../../dom-observer"],function(a,b){return function(){return function(c){var d=function(){setTimeout(function(){c.pushHistory()}.bind(c),0),c.el.removeEventListener("focus",d)}.bind(c);c.el.addEventListener("focus",d),c.el.addEventListener("focus",function(){function a(b){var c=document.createTreeWalker(b),d=c.currentNode;return c.firstChild()?"BR"===c.currentNode.nodeName?d:a(c.currentNode):c.currentNode}var b=new c.api.Selection;if(b.range){b.placeMarkers();var d=c.allowsBlockElements()&&c.getHTML().match(/^<\/em>/);if(b.removeMarkers(),d){var e=a(c.el.firstChild),f=b.range;f.setStart(e,0),f.setEnd(e,0),b.selection.removeAllRanges(),b.selection.addRange(f)}}}.bind(c));var e=function(){if(!c._skipFormatters){var a=new c.api.Selection,b=a.range,d=function(){b&&a.placeMarkers(),c.setHTML(c._htmlFormatterFactory.format(c.getHTML())),a.selectMarkers()}.bind(c);b?(c.undoManager.undo(),c.transactionManager.run(d)):d()}delete c._skipFormatters}.bind(c);b(c.el,e),c.allowsBlockElements()&&c.el.addEventListener("keydown",function(a){if(13===a.keyCode){var b=new c.api.Selection,d=b.range,e=b.getContaining(function(a){return/^(H[1-6])$/.test(a.nodeName)});if(e&&d.collapsed){var f=d.cloneRange();f.setEndAfter(e,0);var g=f.cloneContents();""===g.firstChild.textContent&&(a.preventDefault(),c.transactionManager.run(function(){var a=document.createElement("p"),c=document.createElement("br");a.appendChild(c),e.parentNode.insertBefore(a,e.nextElementSibling),d.setStart(a,0),d.setEnd(a,0),b.selection.removeAllRanges(),b.selection.addRange(d)}))}}}),c.allowsBlockElements()&&c.el.addEventListener("keydown",function(a){if(13===a.keyCode||8===a.keyCode){var b=new c.api.Selection,d=b.range;if(d.collapsed){var e=b.getContaining(function(a){return"LI"===a.nodeName});if(e&&""===e.textContent.trim()){a.preventDefault();var f=b.getContaining(function(a){return"UL"===a.nodeName||"OL"===a.nodeName}),g=c.getCommand("OL"===f.nodeName?"insertOrderedList":"insertUnorderedList");g.execute()}}}}),c.el.addEventListener("paste",function(b){if(b.clipboardData)b.preventDefault(),a(b.clipboardData.types,"text/html")?c.insertHTML(b.clipboardData.getData("text/html")):c.insertPlainText(b.clipboardData.getData("text/plain"));else{var d=new c.api.Selection;d.placeMarkers();var e=document.createElement("div");document.body.appendChild(e),e.setAttribute("contenteditable",!0),e.focus(),setTimeout(function(){var a=e.innerHTML;e.parentNode.removeChild(e),d.selectMarkers(),c.el.focus(),c.insertHTML(a)},1)}})}}}),c("plugins/core/formatters/html/replace-nbsp-chars",[],function(){return function(){return function(a){var b=/(\s| )+/g;a.registerHTMLFormatter("export",function(a){return a.replace(b," ")})}}}),c("lodash-amd/modern/arrays/last",["../functions/createCallback","../internals/slice"],function(a,b){function c(c,f,g){var h=0,i=c?c.length:0;if("number"!=typeof f&&null!=f){var j=i;for(f=a(f,g,3);j--&&f(c[j],j,c);)h++}else if(h=f,null==h||g)return c?c[i-1]:d;return b(c,e(0,i-h))}var d,e=Math.max;return c}),c("plugins/core/formatters/html/enforce-p-elements",["lodash-amd/modern/arrays/last","scribe-common/src/element"],function(a,b){function c(c){var d=Array.prototype.reduce.call(c.childNodes,function(c,d){function e(){var a=[d];c.push(a)}var f=a(c);if(f){var g=b.isBlockElement(f[0]);g===b.isBlockElement(d)?f.push(d):e()}else e();return c},[]),e=d.filter(function(a){var c=b.isBlockElement(a[0]);return!c});e.forEach(function(a){var b=document.createElement("p");a[0].parentNode.insertBefore(b,a[0]),a.forEach(function(a){b.appendChild(a)})}),c._isWrapped=!0}function d(a){for(var b=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT),e=b.firstChild();e;){if("BLOCKQUOTE"===e.nodeName&&!e._isWrapped){c(e),d(a);break}e=b.nextSibling()}}return function(){return function(a){a.registerHTMLFormatter("normalize",function(a){var b=document.createElement("div");return b.innerHTML=a,c(b),d(b),b.innerHTML})}}}),c("plugins/core/formatters/html/ensure-selectable-containers",["scribe-common/src/element","lodash-amd/modern/collections/contains"],function(a,b){function c(e){function f(b){return 0===b.children.length||1===b.children.length&&a.isSelectionMarkerNode(b.children[0])}for(var g=e.firstElementChild;g;)a.isSelectionMarkerNode(g)||(f(g)&&""===g.textContent.trim()&&!b(d,g.nodeName)?g.appendChild(document.createElement("br")):g.children.length>0&&c(g)),g=g.nextElementSibling}var d=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];return function(){return function(a){a.registerHTMLFormatter("normalize",function(a){var b=document.createElement("div");return b.innerHTML=a,c(b),b.innerHTML})}}}),c("lodash-amd/modern/internals/htmlEscapes",[],function(){var a={"&":"&","<":"<",">":">",'"':""","'":"'"};return a}),c("lodash-amd/modern/internals/escapeHtmlChar",["./htmlEscapes"],function(a){function b(b){return a[b]}return b}),c("lodash-amd/modern/internals/reUnescapedHtml",["./htmlEscapes","../objects/keys"],function(a,b){var c=RegExp("["+b(a).join("")+"]","g");return c}),c("lodash-amd/modern/utilities/escape",["../internals/escapeHtmlChar","../objects/keys","../internals/reUnescapedHtml"],function(a,b,c){function d(b){return null==b?"":String(b).replace(c,a)}return d}),c("plugins/core/formatters/plain-text/escape-html-characters",["lodash-amd/modern/utilities/escape"],function(a){return function(){return function(b){b.registerPlainTextFormatter(a)}}}),c("plugins/core/inline-elements-mode",[],function(){function a(a){for(var b=document.createTreeWalker(a);b.nextNode();)if(b.currentNode&&(~["br"].indexOf(b.currentNode.nodeName.toLowerCase())||b.currentNode.length>0))return!0;return!1}return function(){return function(b){b.el.addEventListener("keydown",function(c){if(13===c.keyCode){var d=new b.api.Selection,e=d.range,f=d.getContaining(function(a){return"LI"===a.nodeName||/^(H[1-6])$/.test(a.nodeName)});f||(c.preventDefault(),b.transactionManager.run(function(){"BR"===b.el.lastChild.nodeName&&b.el.removeChild(b.el.lastChild);var c=document.createElement("br");e.insertNode(c),e.collapse(!1);var f=e.cloneRange();f.setEndAfter(b.el.lastChild,0);var g=f.cloneContents();if(!a(g)){var h=document.createElement("br");e.insertNode(h)}var i=e.cloneRange();i.setStartAfter(c,0),i.setEndAfter(c,0),d.selection.removeAllRanges(),d.selection.addRange(i)}))}}.bind(this)),""===b.getHTML().trim()&&b.setContent("")}}}),c("plugins/core/patches/commands/bold",[],function(){return function(){return function(a){var b=new a.api.CommandPatch("bold");b.queryEnabled=function(){var b=new a.api.Selection,c=b.getContaining(function(a){return/^(H[1-6])$/.test(a.nodeName)});return a.api.CommandPatch.prototype.queryEnabled.apply(this,arguments)&&!c},a.commandPatches.bold=b}}}),c("plugins/core/patches/commands/indent",[],function(){var a="";return function(){return function(b){var c=new b.api.CommandPatch("indent");c.execute=function(c){b.transactionManager.run(function(){var d=new b.api.Selection,e=d.range,f="P"===e.commonAncestorContainer.nodeName&&"
"===e.commonAncestorContainer.innerHTML;if(f){var g=document.createTextNode(a);e.insertNode(g),e.setStart(g,0),e.setEnd(g,0),d.selection.removeAllRanges(),d.selection.addRange(e)}b.api.CommandPatch.prototype.execute.call(this,c),d=new b.api.Selection;var h=d.getContaining(function(a){return"BLOCKQUOTE"===a.nodeName});h&&h.removeAttribute("style")}.bind(this))},b.commandPatches.indent=c}}}),c("plugins/core/patches/commands/insert-html",["scribe-common/src/element"],function(a){return function(){return function(b){var c=new b.api.CommandPatch("insertHTML");c.execute=function(c){b.transactionManager.run(function(){function d(b){var c=document.createTreeWalker(b,NodeFilter.SHOW_ELEMENT),e=c.firstChild();if(e)do"SPAN"===e.nodeName?a.unwrap(b,e):(e.style.lineHeight=null,""===e.getAttribute("style")&&e.removeAttribute("style")),d(e);while(e=c.nextSibling())}b.api.CommandPatch.prototype.execute.call(this,c),d(b.el)}.bind(this))},b.commandPatches.insertHTML=c}}}),c("plugins/core/patches/commands/insert-list",["scribe-common/src/element","scribe-common/src/node"],function(a,b){return function(){return function(c){var d=function(a){c.api.CommandPatch.call(this,a)};d.prototype=Object.create(c.api.CommandPatch.prototype),d.prototype.constructor=d,d.prototype.execute=function(d){c.transactionManager.run(function(){if(c.api.CommandPatch.prototype.execute.call(this,d),this.queryState()){var e=new c.api.Selection,f=e.getContaining(function(a){return"OL"===a.nodeName||"UL"===a.nodeName});if(f.nextElementSibling&&0===f.nextElementSibling.childNodes.length&&b.removeNode(f.nextElementSibling),f){var g=f.parentNode;g&&/^(H[1-6]|P)$/.test(g.nodeName)&&(e.placeMarkers(),b.insertAfter(f,g),e.selectMarkers(),2===g.childNodes.length&&b.isEmptyTextNode(g.firstChild)&&b.removeNode(g),0===g.childNodes.length&&b.removeNode(g))}var h=Array.prototype.slice.call(f.childNodes);h.forEach(function(b){var c=Array.prototype.slice.call(b.childNodes);c.forEach(function(c){if("SPAN"===c.nodeName){var d=c;a.unwrap(b,d)}else c.nodeType===Node.ELEMENT_NODE&&(c.style.lineHeight=null,""===c.getAttribute("style")&&c.removeAttribute("style"))})})}}.bind(this))},c.commandPatches.insertOrderedList=new d("insertOrderedList"),c.commandPatches.insertUnorderedList=new d("insertUnorderedList")}}}),c("plugins/core/patches/commands/outdent",[],function(){return function(){return function(a){var b=new a.api.CommandPatch("outdent");b.execute=function(){a.transactionManager.run(function(){var b=new a.api.Selection,c=b.range,d=b.getContaining(function(a){return"BLOCKQUOTE"===a.nodeName});if("BLOCKQUOTE"===c.commonAncestorContainer.nodeName){b.placeMarkers(),b.selectMarkers(!0);var e=c.cloneContents();d.parentNode.insertBefore(e,d),c.deleteContents(),b.selectMarkers(),""===d.textContent&&d.parentNode.removeChild(d)}else{var f=b.getContaining(function(a){return"P"===a.nodeName});if(f){var g=new a.api.Node(f).nextAll();if(g.length){var h=document.createElement(d.nodeName);g.forEach(function(a){h.appendChild(a)}),d.parentNode.insertBefore(h,d.nextElementSibling)}b.placeMarkers(),d.parentNode.insertBefore(f,d.nextElementSibling),b.selectMarkers(),""===d.innerHTML&&d.parentNode.removeChild(d)}else a.api.CommandPatch.prototype.execute.call(this)}}.bind(this))},a.commandPatches.outdent=b}}}),c("plugins/core/patches/commands/create-link",[],function(){return function(){return function(a){var b=new a.api.CommandPatch("createLink");a.commandPatches.createLink=b,b.execute=function(b){var c=new a.api.Selection;if(c.selection.isCollapsed){var d=document.createElement("a");d.setAttribute("href",b),d.textContent=b,c.range.insertNode(d);var e=document.createRange();e.setStartBefore(d),e.setEndAfter(d),c.selection.removeAllRanges(),c.selection.addRange(e)}else a.api.CommandPatch.prototype.execute.call(this,b)}}}}),c("plugins/core/patches/events",["scribe-common/src/element"],function(a){return function(){return function(b){b.allowsBlockElements()&&b.el.addEventListener("keyup",function(c){if(8===c.keyCode||46===c.keyCode){var d=new b.api.Selection,e=d.getContaining(function(a){return"P"===a.nodeName});e&&(b.undoManager.undo(),b.transactionManager.run(function(){d.placeMarkers();var b=Array.prototype.slice.call(e.childNodes);b.forEach(function(b){if("SPAN"===b.nodeName){var c=b;a.unwrap(e,c)}else b.nodeType===Node.ELEMENT_NODE&&(b.style.lineHeight=null,""===b.getAttribute("style")&&b.removeAttribute("style"))}),d.selectMarkers()}))}})}}}),c("plugins/core/patches",["./patches/commands/bold","./patches/commands/indent","./patches/commands/insert-html","./patches/commands/insert-list","./patches/commands/outdent","./patches/commands/create-link","./patches/events"],function(a,b,c,d,e,f,g){return{commands:{bold:a,indent:b,insertHTML:c,insertList:d,outdent:e,createLink:f},events:g}}),c("plugins/core/set-root-p-element",[],function(){return function(){return function(a){""===a.getHTML().trim()&&a.setContent("


")}}}),c("api/command-patch",[],function(){return function(a){function b(a){this.commandName=a}return b.prototype.execute=function(b){a.transactionManager.run(function(){document.execCommand(this.commandName,!1,b||null)}.bind(this))},b.prototype.queryState=function(){return document.queryCommandState(this.commandName)},b.prototype.queryEnabled=function(){return document.queryCommandEnabled(this.commandName)},b}}),c("api/command",[],function(){return function(a){function b(b){this.commandName=b,this.patch=a.commandPatches[this.commandName]}return b.prototype.execute=function(b){this.patch?this.patch.execute(b):a.transactionManager.run(function(){document.execCommand(this.commandName,!1,b||null)}.bind(this))},b.prototype.queryState=function(){return this.patch?this.patch.queryState():document.queryCommandState(this.commandName)},b.prototype.queryEnabled=function(){return this.patch?this.patch.queryEnabled():document.queryCommandEnabled(this.commandName)},b}}),c("api/node",[],function(){function a(a){this.node=a}return a.prototype.getAncestor=function(a){var b=function(a){return a&&a.attributes&&a.attributes.getNamedItem("contenteditable") };if(!b(this.node))for(var c=this.node.parentNode;c&&!b(c);){if(a(c))return c;c=c.parentNode}},a.prototype.nextAll=function(){for(var a=[],b=this.node.nextSibling;b;)a.push(b),b=b.nextSibling;return a},a}),c("api/selection",[],function(){return function(a){function b(){this.selection=window.getSelection(),this.selection.rangeCount&&(this.range=this.selection.getRangeAt(0))}return b.prototype.getContaining=function(b){var c=new a.api.Node(this.range.commonAncestorContainer),d=c.node&&c.node.attributes&&c.node.attributes.getNamedItem("contenteditable");return!d&&b(c.node)?c.node:c.getAncestor(b)},b.prototype.placeMarkers=function(){var a=document.createElement("em");a.classList.add("scribe-marker");var b=document.createElement("em");b.classList.add("scribe-marker");var c=this.range.cloneRange();if(c.collapse(!1),c.insertNode(b),b.nextSibling&&b.nextSibling.nodeType===Node.TEXT_NODE&&""===b.nextSibling.data&&b.parentNode.removeChild(b.nextSibling),b.previousSibling&&b.previousSibling.nodeType===Node.TEXT_NODE&&""===b.previousSibling.data&&b.parentNode.removeChild(b.previousSibling),!this.selection.isCollapsed){var d=this.range.cloneRange();d.collapse(!0),d.insertNode(a),a.nextSibling&&a.nextSibling.nodeType===Node.TEXT_NODE&&""===a.nextSibling.data&&a.parentNode.removeChild(a.nextSibling),a.previousSibling&&a.previousSibling.nodeType===Node.TEXT_NODE&&""===a.previousSibling.data&&a.parentNode.removeChild(a.previousSibling)}this.selection.removeAllRanges(),this.selection.addRange(this.range)},b.prototype.getMarkers=function(){return a.el.querySelectorAll("em.scribe-marker")},b.prototype.removeMarkers=function(){var a=this.getMarkers();Array.prototype.forEach.call(a,function(a){a.parentNode.removeChild(a)})},b.prototype.selectMarkers=function(a){var b=this.getMarkers();if(b.length){var c=document.createRange();c.setStartBefore(b[0]),c.setEndAfter(b.length>=2?b[1]:b[0]),a||this.removeMarkers(),this.selection.removeAllRanges(),this.selection.addRange(c)}},b.prototype.isCaretOnNewLine=function(){var a=this.getContaining(function(a){return"P"===a.nodeName});if(a){var b=a.innerHTML.trim();return"P"===a.nodeName&&("
"===b||""===b)}return!1},b}}),c("api/simple-command",[],function(){return function(a,b){function c(a,c){b.api.Command.call(this,a),this.nodeName=c}return c.prototype=Object.create(a.Command.prototype),c.prototype.constructor=c,c.prototype.queryState=function(){var a=new b.api.Selection;return b.api.Command.prototype.queryState.call(this)&&!!a.getContaining(function(a){return a.nodeName===this.nodeName}.bind(this))},c}}),c("api",["./api/command-patch","./api/command","./api/node","./api/selection","./api/simple-command"],function(a,b,c,d,e){return function(f){this.CommandPatch=a(f),this.Command=b(f),this.Node=c,this.Selection=d(f),this.SimpleCommand=e(this,f)}}),c("lodash-amd/modern/objects/assign",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;var j=arguments,k=0,l="number"==typeof f?2:j.length;if(l>3&&"function"==typeof j[l-2])var m=a(j[--l-1],j[l--],2);else l>2&&"function"==typeof j[l-1]&&(m=j[--l]);for(;++kthis.maxStackSize;)this.stack.shift(),--this.position},b.prototype.undo=function(){return this.position>0?this.stack[--this.position]:void 0},b.prototype.redo=function(){return this.position$/,""))},p.prototype.getTextContent=function(){return this.el.textContent},p.prototype.pushHistory=function(){var a=this.undoManager.stack[this.undoManager.position],b=a&&a.replace(//g,"").replace(/<\/em>/g,"");if(!a||a&&this.getContent()!==b){var c=new this.api.Selection;c.placeMarkers();var d=this.getHTML();return c.removeMarkers(),this.undoManager.push(d),!0}return!1},p.prototype.getCommand=function(a){return this.commands[a]||this.commandPatches[a]||new this.api.Command(a)},p.prototype.restoreFromHistory=function(a){this.setHTML(a,!0);var b=new this.api.Selection;b.selectMarkers(),this.trigger("content-changed")},p.prototype.allowsBlockElements=function(){return this.options.allowBlockElements},p.prototype.setContent=function(a){this.allowsBlockElements()||(a+="
"),this.setHTML(a),this.trigger("content-changed")},p.prototype.insertPlainText=function(a){this.insertHTML("

"+this._plainTextFormatterFactory.format(a)+"

")},p.prototype.insertHTML=function(a){this.getCommand("insertHTML").execute(this._htmlFormatterFactory.format(a))},p.prototype.isDebugModeEnabled=function(){return this.options.debug},p.prototype.registerHTMLFormatter=function(a,b){this._htmlFormatterFactory.formatters[a].push(b)},p.prototype.registerPlainTextFormatter=function(a){this._plainTextFormatterFactory.formatters.push(a)},q.prototype.format=function(a){var b=this.formatters.reduce(function(a,b){return b(a)},a);return b},r.prototype=Object.create(q.prototype),r.prototype.constructor=r,r.prototype.format=function(a){var c=b([this.formatters.sanitize,this.formatters.normalize]),d=c.reduce(function(a,b){return b(a)},a);return d},r.prototype.formatForExport=function(a){return this.formatters.export.reduce(function(a,b){return b(a)},a)},p}),c("scribe-plugin-blockquote-command",[],function(){return function(){return function(a){var b=new a.api.SimpleCommand("blockquote","BLOCKQUOTE");b.execute=function(){var b=a.getCommand(this.queryState()?"outdent":"indent");b.execute()},b.queryEnabled=function(){var b=a.getCommand(this.queryState()?"outdent":"indent");return b.queryEnabled()},b.queryState=function(){var b=new a.api.Selection,c=b.getContaining(function(a){return"BLOCKQUOTE"===a.nodeName});return a.allowsBlockElements()&&!!c},a.commands.blockquote=b,a.allowsBlockElements()&&a.el.addEventListener("keydown",function(b){if(13===b.keyCode){var c=a.getCommand("blockquote");if(c.queryState()){var d=new a.api.Selection;d.isCaretOnNewLine()&&(b.preventDefault(),c.execute())}}})}}}),c("scribe-plugin-curly-quotes",[],function(){return function(){var a={34:'"',39:"'"},b="“",c="”",d="‘",e="’";return function(f){function g(g){var i,j=a[g.charCode];'"'===j?i=h()?c:b:"'"===j&&(i=h()?e:d),i&&(g.preventDefault(),f.transactionManager.run(function(){var a=k(i);l(a)}))}function h(){var a=i()||"";return j(a)}function i(){var a=new f.api.Selection,b=a.range.commonAncestorContainer.textContent;return b[a.range.startOffset-1]}function j(a){return/[^\s()]/.test(a)}function k(a){var b=document.createTextNode(a),c=new f.api.Selection;return c.range.deleteContents(),c.range.insertNode(b),b}function l(a){var b=document.createRange();b.setStartAfter(a),b.setEndAfter(a);var c=new f.api.Selection;c.selection.removeAllRanges(),c.selection.addRange(b)}function m(a){var f=document.createElement("div");return f.innerHTML=a,o(f,function(a){var f=a.split(/(<[^>]+?>)/);return f.map(function(a){return"<"===a[0]?a:a.replace(/([\s\S])?'([\s\S])?/g,n(d,e)).replace(/([\s\S])?"([\s\S])?/g,n(b,c))}).join("")}),f.innerHTML}function n(a,b){return function(c,d,e){d=d||"",e=e||"";var f=!d,g=!e,h=j(d),i=j(e);return h||f&&!i&&!g?d+b+e:d+a+e}}function o(a,b){var c=document.createTreeWalker(a,NodeFilter.SHOW_TEXT),d=c.firstChild();if(d)do d.data=b(d.data);while(d=c.nextSibling());return d}f.el.addEventListener("keypress",g),f.registerHTMLFormatter("normalize",m)}}}),c("scribe-plugin-formatter-plain-text-convert-new-lines-to-html",[],function(){return function(){return function(a){a.registerPlainTextFormatter(function(a){return a.replace(/\n([ \t]*\n)+/g,"

").replace(/\n/g,"
")})}}}),c("scribe-plugin-heading-command",[],function(){return function(a){return function(b){var c="",d="H"+a,e="h"+a,f=new b.api.Command("formatBlock");f.execute=function(){this.queryState()?b.api.Command.prototype.execute.call(this,"

"):b.api.Command.prototype.execute.call(this,c)},f.queryState=function(){var a=new b.api.Selection;return!!a.getContaining(function(a){return a.nodeName===d})},f.queryEnabled=function(){var a=new b.api.Selection,c=a.getContaining(function(a){return"OL"===a.nodeName||"UL"===a.nodeName});return b.api.Command.prototype.queryEnabled.apply(this,arguments)&&b.allowsBlockElements()&&!c},b.commands[e]=f}}}),c("scribe-plugin-intelligent-unlink-command",[],function(){return function(){return function(a){var b=new a.api.Command("unlink");b.execute=function(){var b=new a.api.Selection;b.selection.isCollapsed?a.transactionManager.run(function(){var c=b.getContaining(function(a){return"A"===a.nodeName});c&&new a.api.Element(c.parentNode).unwrap(c)}.bind(this)):a.api.Command.prototype.execute.apply(this,arguments)},b.queryEnabled=function(){var b=new a.api.Selection;return b.selection.isCollapsed?!!b.getContaining(function(a){return"A"===a.nodeName}):a.api.Command.prototype.queryEnabled.apply(this,arguments)},a.commands.unlink=b}}}),c("lodash-amd/modern/internals/isNative",[],function(){function a(a){return"function"==typeof a&&d.test(a)}var b=Object.prototype,c=b.toString,d=RegExp("^"+String(c).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$");return a}),c("lodash-amd/modern/internals/objectTypes",[],function(){var a={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1};return a}),c("lodash-amd/modern/objects/isObject",["../internals/objectTypes"],function(a){function b(b){return!(!b||!a[typeof b])}return b}),c("lodash-amd/modern/utilities/noop",[],function(){function a(){}return a}),c("lodash-amd/modern/internals/baseCreate",["./isNative","../objects/isObject","../utilities/noop"],function(a,b){function c(a){return b(a)?d(a):{}}var d=a(d=Object.create)&&d;return d||(c=function(){function a(){}return function(c){if(b(c)){a.prototype=c;var d=new a;a.prototype=null}return d||window.Object()}}()),c}),c("lodash-amd/modern/internals/setBindData",["./isNative","../utilities/noop"],function(a,b){var c={configurable:!1,enumerable:!1,value:null,writable:!1},d=function(){try{var b={},c=a(c=Object.defineProperty)&&c,d=c(b,b,b)&&c}catch(e){}return d}(),e=d?function(a,b){c.value=b,d(a,"__bindData__",c)}:b;return e}),c("lodash-amd/modern/internals/slice",[],function(){function a(a,b,c){b||(b=0),"undefined"==typeof c&&(c=a?a.length:0);for(var d=-1,e=c-b||0,f=Array(0>e?0:e);++d2?a(c,17,b(arguments,2),null,d):a(c,1,null,null,d)}return c}),c("lodash-amd/modern/utilities/identity",[],function(){function a(a){return a}return a}),c("lodash-amd/modern/support",["./internals/isNative"],function(a){var b=/\bthis\b/,c={};return c.funcDecomp=!a(window.WinRTError)&&b.test(function(){return this}),c.funcNames="string"==typeof Function.name,c}),c("lodash-amd/modern/internals/baseCreateCallback",["../functions/bind","../utilities/identity","./setBindData","../support"],function(a,b,c,d){function e(e,i,j){if("function"!=typeof e)return b;if("undefined"==typeof i||!("prototype"in e))return e;var k=e.__bindData__;if("undefined"==typeof k&&(d.funcNames&&(k=!e.name),k=k||!d.funcDecomp,!k)){var l=h.call(e);d.funcNames||(k=!f.test(l)),k||(k=g.test(l),c(e,k))}if(k===!1||k!==!0&&1&k[1])return e;switch(j){case 1:return function(a){return e.call(i,a)};case 2:return function(a,b){return e.call(i,a,b)};case 3:return function(a,b,c){return e.call(i,a,b,c)};case 4:return function(a,b,c,d){return e.call(i,a,b,c,d)}}return a(e,i)}var f=/^\s*function[ \n\r\t]+\w/,g=/\bthis\b/,h=Function.prototype.toString;return e}),c("lodash-amd/modern/objects/forIn",["../internals/baseCreateCallback","../internals/objectTypes"],function(a,b){var c=function(c,d,e){var f,g=c,h=g;if(!g)return h;if(!b[typeof g])return h;d=d&&"undefined"==typeof e?d:a(d,e,3);for(f in g)if(d(g[f],f,c)===!1)return h;return h};return c}),c("lodash-amd/modern/internals/arrayPool",[],function(){var a=[];return a}),c("lodash-amd/modern/internals/getArray",["./arrayPool"],function(a){function b(){return a.pop()||[]}return b}),c("lodash-amd/modern/internals/maxPoolSize",[],function(){var a=40;return a}),c("lodash-amd/modern/internals/releaseArray",["./arrayPool","./maxPoolSize"],function(a,b){function c(c){c.length=0,a.length-1:void 0});return u.pop(),v.pop(),G&&(e(u),e(v)),w}var g="[object Arguments]",h="[object Array]",i="[object Boolean]",j="[object Date]",k="[object Number]",l="[object Object]",m="[object RegExp]",n="[object String]",o=Object.prototype,p=o.toString,q=o.hasOwnProperty;return f}),c("lodash-amd/modern/internals/shimKeys",["./objectTypes"],function(a){var b=Object.prototype,c=b.hasOwnProperty,d=function(b){var d,e=b,f=[];if(!e)return f;if(!a[typeof b])return f;for(d in e)c.call(e,d)&&f.push(d);return f};return d}),c("lodash-amd/modern/objects/keys",["../internals/isNative","./isObject","../internals/shimKeys"],function(a,b,c){var d=a(d=Object.keys)&&d,e=d?function(a){return b(a)?d(a):[]}:c;return e}),c("lodash-amd/modern/utilities/property",[],function(){function a(a){return function(b){return b[a]}}return a}),c("lodash-amd/modern/functions/createCallback",["../internals/baseCreateCallback","../internals/baseIsEqual","../objects/isObject","../objects/keys","../utilities/property"],function(a,b,c,d,e){function f(f,g,h){var i=typeof f;if(null==f||"function"==i)return a(f,g,h);if("object"!=i)return e(f);var j=d(f),k=j[0],l=f[k];return 1!=j.length||l!==l||c(l)?function(a){for(var c=j.length,d=!1;c--&&(d=b(a[j[c]],f[j[c]],null,!0)););return d}:function(a){var b=a[k];return l===b&&(0!==l||1/l==1/b)}}return f}),c("lodash-amd/modern/objects/forOwn",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;if(!c[typeof h])return i;e=e&&"undefined"==typeof f?e:a(e,f,3);for(var j=-1,k=c[typeof h]&&b(h),l=k?k.length:0;++j-1||a.indexOf("/")>-1||a.indexOf("www")>-1||a.indexOf("http://")>-1||a.indexOf("https://")>-1||""===a?!1:!0}function e(a){c(),k.show(),a.addClass("link-edit"),setTimeout(function(){$("body, .link-tools .close").bind("click",f),l.val(a.attr("href").replace(m,"")),l[0].focus()},10)}function f(a){0===$(a.target).closest(".link-tools").length&&g()}function g(){b.updateContents(function(){var a=l.val();""===a?h():$(".link-edit, [href="+m+"]").attr("href",a).removeClass("link-edit")},!1),$("body, .link-tools .close").unbind("click"),k.hide()}function h(){var a=$(".link-edit, [href*="+m+"]");a[0].outerHTML=a[0].innerHTML}var i=b.el.parentNode,j=new b.api.Command("createLink"),k=$(".link-tools",i),l=$(".link-tools input",i),m="#replaceme",n=$(".search-results",k),o=a.searchHandler||function(){};j.nodeName="A",j.execute=function(){var a=this,c=new b.api.Selection;c.range.collapsed||(b._skipFormatters=!0,b.api.SimpleCommand.prototype.execute.call(a,m),e($("a[href*="+m+"]")))},$(".remove",k).click(function(){l.val(""),g()}),$(".ok",k).click(g),n.click(function(a){var b=$(a.target).closest("a");1===b.length&&(a.preventDefault(),l.val(b.attr("href")),c())}),l.bind("keyup",c).bind("keydown",function(a){(13===a.keyCode||27===a.keyCode)&&g()}),b.el.addEventListener("click",function(a){var c=(new b.api.Selection,$(a.target).closest("a"));1===c.length&&(e(c),a.preventDefault())});var p;j.queryState=function(){var a=new b.api.Selection;return!!a.getContaining(function(a){return a.nodeName===this.nodeName}.bind(this))},b.commands.linkUI=j}}}),function(a,b){"function"==typeof c&&c.amd?c("html-janitor",b):a.amdWeb=b()}(this,function(){function a(a){this.config=a}function b(a){return-1!==d.indexOf(a.nodeName)}function c(a){return document.createTreeWalker(a,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT)}var d=["P","LI","DIV"];return a.prototype.clean=function(a){var b=document.createElement("div");return b.innerHTML=a,this._sanitize(b),b.innerHTML},a.prototype._sanitize=function(a){var d=c(a),e=d.firstChild();if(e)do{var f=e.nodeName.toLowerCase(),g=this.config.tags[f];if(!e._sanitized){if(this.config.skipSanitization(e))return;if(e.nodeType!==Node.TEXT_NODE){if(e.nodeType===Node.COMMENT_NODE){a.removeChild(e),this._sanitize(a);break}var h,i="b"===f;i&&(h=Array.prototype.some.call(e.childNodes,b));var j=i&&h,k=!!a.parentNode,l=b(a)&&b(e)&&k;if(!this.config.tags[f]||j||l){if("SCRIPT"!==e.nodeName&&"STYLE"!==e.nodeName)for(;e.childNodes.length>0;)a.insertBefore(e.childNodes[0],e);a.removeChild(e),this._sanitize(a);break}for(var m=0;me?0:e);++d2?a(c,17,b(arguments,2),null,d):a(c,1,null,null,d)}return c}),c("lodash-amd/modern/utilities/identity",[],function(){function a(a){return a}return a}),c("lodash-amd/modern/support",["./internals/isNative"],function(a){var b=/\bthis\b/,c={};return c.funcDecomp=!a(window.WinRTError)&&b.test(function(){return this}),c.funcNames="string"==typeof Function.name,c}),c("lodash-amd/modern/internals/baseCreateCallback",["../functions/bind","../utilities/identity","./setBindData","../support"],function(a,b,c,d){function e(e,i,j){if("function"!=typeof e)return b;if("undefined"==typeof i||!("prototype"in e))return e;var k=e.__bindData__;if("undefined"==typeof k&&(d.funcNames&&(k=!e.name),k=k||!d.funcDecomp,!k)){var l=h.call(e);d.funcNames||(k=!f.test(l)),k||(k=g.test(l),c(e,k))}if(k===!1||k!==!0&&1&k[1])return e;switch(j){case 1:return function(a){return e.call(i,a)};case 2:return function(a,b){return e.call(i,a,b)};case 3:return function(a,b,c){return e.call(i,a,b,c)};case 4:return function(a,b,c,d){return e.call(i,a,b,c,d)}}return a(e,i)}var f=/^\s*function[ \n\r\t]+\w/,g=/\bthis\b/,h=Function.prototype.toString;return e}),c("lodash-amd/modern/internals/shimKeys",["./objectTypes"],function(a){var b=Object.prototype,c=b.hasOwnProperty,d=function(b){var d,e=b,f=[];if(!e)return f;if(!a[typeof b])return f;for(d in e)c.call(e,d)&&f.push(d);return f};return d}),c("lodash-amd/modern/objects/keys",["../internals/isNative","./isObject","../internals/shimKeys"],function(a,b,c){var d=a(d=Object.keys)&&d,e=d?function(a){return b(a)?d(a):[]}:c;return e}),c("lodash-amd/modern/objects/forOwn",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;if(!c[typeof h])return i;e=e&&"undefined"==typeof f?e:a(e,f,3);for(var j=-1,k=c[typeof h]&&b(h),l=k?k.length:0;++j3&&"function"==typeof h[i-2])var j=a(h[--i-1],h[i--],2);else i>2&&"function"==typeof h[i-1]&&(j=h[--i]);for(var k=f(arguments,1,i),l=-1,m=c(),n=c();++l3&&"function"==typeof j[l-2])var m=a(j[--l-1],j[l--],2);else l>2&&"function"==typeof j[l-1]&&(m=j[--l]);for(;++ke?0:e);++d2?a(c,17,b(arguments,2),null,d):a(c,1,null,null,d)}return c}),c("lodash-amd/modern/utilities/identity",[],function(){function a(a){return a}return a}),c("lodash-amd/modern/support",["./internals/isNative"],function(a){var b=/\bthis\b/,c={};return c.funcDecomp=!a(window.WinRTError)&&b.test(function(){return this}),c.funcNames="string"==typeof Function.name,c}),c("lodash-amd/modern/internals/baseCreateCallback",["../functions/bind","../utilities/identity","./setBindData","../support"],function(a,b,c,d){function e(e,i,j){if("function"!=typeof e)return b;if("undefined"==typeof i||!("prototype"in e))return e;var k=e.__bindData__;if("undefined"==typeof k&&(d.funcNames&&(k=!e.name),k=k||!d.funcDecomp,!k)){var l=h.call(e);d.funcNames||(k=!f.test(l)),k||(k=g.test(l),c(e,k))}if(k===!1||k!==!0&&1&k[1])return e;switch(j){case 1:return function(a){return e.call(i,a)};case 2:return function(a,b){return e.call(i,a,b)};case 3:return function(a,b,c){return e.call(i,a,b,c)};case 4:return function(a,b,c,d){return e.call(i,a,b,c,d)}}return a(e,i)}var f=/^\s*function[ \n\r\t]+\w/,g=/\bthis\b/,h=Function.prototype.toString;return e}),c("lodash-amd/modern/internals/shimKeys",["./objectTypes"],function(a){var b=Object.prototype,c=b.hasOwnProperty,d=function(b){var d,e=b,f=[];if(!e)return f;if(!a[typeof b])return f;for(d in e)c.call(e,d)&&f.push(d);return f};return d}),c("lodash-amd/modern/objects/keys",["../internals/isNative","./isObject","../internals/shimKeys"],function(a,b,c){var d=a(d=Object.keys)&&d,e=d?function(a){return b(a)?d(a):[]}:c;return e}),c("lodash-amd/modern/objects/forOwn",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;if(!c[typeof h])return i;e=e&&"undefined"==typeof f?e:a(e,f,3);for(var j=-1,k=c[typeof h]&&b(h),l=k?k.length:0;++jh?f(0,k+h):h)||0,c(e)?l=j(e,g,h)>-1:"number"==typeof k?l=(d(e)?e.indexOf(g,h):j(e,g,h))>-1:b(e,function(a){return++i>=h?!(l=a===g):void 0}),l}var f=Math.max;return e}),c("scribe-common/src/element",["lodash-amd/modern/collections/contains"],function(a){function b(b){return a(e,b.nodeName)}function c(a){return a.nodeType===Node.ELEMENT_NODE&&"scribe-marker"===a.className}function d(a,b){for(;b.childNodes.length>0;)a.insertBefore(b.childNodes[0],b);a.removeChild(b)}var e=["P","LI","DIV","BLOCKQUOTE","UL","OL","H1","H2","H3","H4","H5","H6"];return{isBlockElement:b,isSelectionMarkerNode:c,unwrap:d}}),c("scribe-plugin-smart-lists",["scribe-common/src/element"],function(a){return function(){function b(a){return"*"===a||"-"===a||"•"===a}function c(b){for(;b&&!a.isBlockElement(b);)b=b.parentNode;return b}var d={32:"Space",42:"*",45:"-",46:".",49:"1",8226:"•"};return function(a){function e(){var b,c=new a.api.Selection,d=c.selection.anchorNode;if(d.nodeType===Node.TEXT_NODE?b=d:d.firstChild.nodeType===Node.TEXT_NODE&&(b=d.firstChild),!b)throw new Error("Cannot empty non-text node!");var e=b.parentNode;b.previousSibling&&e.removeChild(b.previousSibling),e.removeChild(b)}function f(f){var j;g=h,h=i,i=d[f.charCode];var k=new a.api.Selection,l=k.range.commonAncestorContainer,m=c(l);if(m&&"P"===m.tagName){var n=b(l.textContent[0]);b(h)&&"Space"===i&&n&&(j="insertUnorderedList");var o="1."===[l.previousSibling&&l.previousSibling.textContent,l.textContent].join("").slice(0,2);"1"===g&&"."===h&&"Space"===i&&o&&(j="insertOrderedList")}j&&(f.preventDefault(),a.transactionManager.run(function(){a.getCommand(j).execute(),e()}))}var g,h,i;a.el.addEventListener("keypress",f)}}}),c("scribe-plugin-toolbar",[],function(){return function(a){return function(b){var c=a.querySelectorAll("button");Array.prototype.forEach.call(c,function(a){function c(){var c=new b.api.Selection;c.range&&(d.queryEnabled()?(a.removeAttribute("disabled"),d.queryState()?a.classList.add("active"):a.classList.remove("active")):a.setAttribute("disabled","disabled"))}var d=b.getCommand(a.dataset.commandName);a.addEventListener("click",function(){b.el.focus(),d.execute()}),b.el.addEventListener("keyup",c),b.el.addEventListener("mouseup",c),b.on("content-changed",c)})}}}),c("scribe-plugin-inline-objects",[],function(){return function(a){return function(b){function c(a){n=a,$(".embed-button",q).click(d),$(".inline-tools button",q.parentNode).click(function(a){var b=$(a.target).data("commandName");"function"==typeof r[b]&&r[b]()})}function d(a){var c,d,g=$(".embed-fly-out").height(),h=$(".embed-button").height(),i=$(a.target).closest("button").data("commandName");"embed-before"===i?(c=o.position().top-g/2+h/2,d="before"):(c=o.position().top+o.height()+parseInt(o.css("margin-top"))-g/2+h/2,d="after"),$(".embed-fly-out",q).css({top:c,left:$(b.el).css("padding-left")}).show();var j=o;$(".embed-fly-out button").bind("click.inline",function(a){var b=$(a.target).closest("button").data("commandName");f(b,j,d)}),$("body").bind("click.inline",function(a){0===$(a.target).closest(".embed-tools").length&&e()})}function e(){$("body").unbind("click.inline"),$(".embed-fly-out button").unbind("click.inline"),$(".embed-fly-out").hide()}function f(a,c,d){b.trigger("inline:insert:"+a,[function(e){b.updateContents(function(){var b=m(n[a].template,$.extend(n[a].defaults,e));$(c)[d](b),$(".inline",q).attr("contenteditable","false")})}]),$(".embed-tools",q).removeClass("active")}function g(){$(".inline-tools").hide(),$(q).removeClass("inline-active")}function h(){var a=$(p),b=a.position();$(q).addClass("inline-active"),$(".inline-tools").attr("data-type",a.attr("data-type")),$(".inline-tools .size",q).html($(p).attr("data-size")),$(".inline-tools .crop",q).html($(p).attr("data-crop")),$(".inline-tools",q).css({top:b.top+parseInt(a.css("margin-top")),left:b.left+parseInt(a.css("margin-left"))+parseInt($(".editor",q).css("margin-left")),width:a.width(),height:a.height()}).show()}function i(){return n[$(p).attr("data-type")].size}function j(){return n[$(p).attr("data-type")].crop}function k(a,b){var c=$(p).attr("data-"+a),d=b.indexOf(c)+1;d>=b.length&&(d=0),l(a,b[d]),"function"==typeof window.picturefill&&setTimeout(function(){window.picturefill(p)},100)}function l(a,c){var d=$(p).attr("data-"+a);b.updateContents(function(){$(p).removeClass(a+"-"+d).addClass(a+"-"+c).attr("data-"+a,c),h()})}function m(a,b){for(var c in b)c&&(a=a.replace(new RegExp("{{"+c+"}}","g"),b[c]));return a}var n,o,p,q=b.el.parentNode;b.el.addEventListener("mouseover",function(a){var c=$(a.target).closest(".editor>*");1===c.length?($(".embed-tools",q).css({width:$(b.el).css("padding-left"),top:c.position().top+c.css("margin-top").replace(/[^-\d\.]/g,"")/2,height:c.height()}).addClass("active"),o=c):$(".embed-tools",q).removeClass("active")}),b.el.parentNode.addEventListener("mouseleave",function(){$(".embed-tools",q).removeClass("active")}),$(".embed-tools",q).mouseover(function(){$(".embed-tools",q).addClass("active")}),$(".editor",q).mouseover(function(a){var b=$(a.target).parents(".inline");1===b.length?(p=b[b.length-1],h()):g()});var r={inline_caption:function(){var a=prompt("Caption",$(".caption",p).html());a&&b.updateContents(function(){$(".caption",p).html(a)})},inline_size:function(){var a=i();k("size",a);var b=$(p).attr("data-crop"),c=j();-1===c.indexOf(b)&&l("crop",c[0])},inline_crop:function(){var a=n[$(p).attr("data-type")].crop;k("crop",a)},inline_up:function(){g();var a=$(p).prev()[0];if(a){var c=$(p).offset().top;b.updateContents(function(){$(p).after(a),setTimeout(function(){h();var a=$(p).offset().top;window.scrollBy(0,a-c)},0)})}},inline_down:function(){g();var a=$(p).next()[0];if(a){var c=$(p).offset().top;b.updateContents(function(){$(p).before(a),setTimeout(function(){h();var a=$(p).offset().top;window.scrollBy(0,a-c)},0)})}},inline_remove:function(){b.updateContents(function(){$(p).remove()}),g()},inline_edit:function(){b.trigger("inline:edit:"+$(p).attr("data-type"),[p,function(a,c){var d=$(a).attr("data-type");b.updateContents(function(){a.outerHTML=m(n[d].template,$.extend(n[d].defaults,c))})}])}};"string"==typeof a||a instanceof String?$.ajax(a,{success:c,dataType:"json"}):c(a)}}}),c("scribe-plugin-betty-cropper",[],function(){return function(a){return function(b){function c(b){a.insertDialog().then(function(a){var c;c=-1!==a.name.toUpperCase().indexOf("GIF")?"gif":"jpg",b({image_id:a.id,format:c}),window.picturefill&&setTimeout(function(){window.picturefill($("[data-image-id="+a.id+"]")[0])},100)},function(a){console.log(a)},function(a){console.log(a)})}function d(b){e=b.getAttribute("data-image-id");var c=$(".caption",b).html(),d=b.getAttribute("data-alt");a.editDialog({id:e,caption:c,alt:d}).then(function(a){null===a.id?$(b).remove():($(b).attr("data-image-id",a.id),$(b).attr("data-alt",a.alt),$(".caption",b).html(a.caption),window.picturefill&&setTimeout(function(){window.picturefill($("[data-image-id="+a.id+"]")[0])},100))})}var e;b.on("inline:edit:image",d),b.on("inline:insert:image",c)}}}),c("scribe-plugin-youtube",[],function(){return function(){return function(a){function b(a){if(!a)return!1;var b=/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/,c=a.match(b);return c&&11==c[7].length?c[7]:!1}function c(a){var c=prompt("Youtube URL:"),d=b(c);d&&a({youtube_id:d,caption:""})}function d(a,c){var d=prompt("Youtube URL:",$(a).attr("data-youtube-id")||""),e=b(d);e&&c(a,{youtube_id:e,caption:$(".caption",a).html()})}a.on("inline:insert:youtube",c),a.on("inline:edit:youtube",d)}}}),c("scribe-plugin-embed",[],function(){return function(){return function(a){function b(a,b){h.val(unescape($(a).attr("data-code"))),i.val($(".caption",a).text());var c=$(a).attr("data-size")+"-"+$(a).attr("data-crop");$("[value="+c+"]",g).attr("checked",!0),g.modal("show"),j.click(function(){var c=h.val();""===c.trim()?k.show():(k.hide(),b(a,{code:c,caption:i.val(),escaped_code:escape(c),size:d(),crop:e()}),g.modal("hide"))}),g.modal("show")}function c(a){h.val(""),i.val(""),g.modal("show"),j.click(function(){var b=h.val();""===b.trim()?k.show():(k.hide(),a({code:b,caption:i.val(),escaped_code:escape(b),size:d(),crop:e()}),g.modal("hide"))})}function d(){var a="original";return l.length>0&&l.val().split("-")[0],a}function e(){var a="original";return l.length>0&&l.val().split("-")[1],a}a.on("inline:insert:embed",c),a.on("inline:edit:embed",b);var f=a.el.parentNode,g=$(".embed-modal",f),h=$(".embed-body",g),i=$(".embed-caption",g),j=$(".set-embed-button",g),k=$(".embed-error",g),l=$("[name=size]",g);g.on("hide.bs.modal",function(){j.unbind("click"),k.hide()})}}}),c("scribe-plugin-onion-video",[],function(){return function(a){return function(b){function c(c){function d(){}function e(){}return a.insertDialog().then(function(d){b.updateContents(function(){c({embed_url:a.videoEmbedUrl,video_id:d.attrs.id})})},function(a){e(a)},function(a){d(a)})}function d(b){var c=$(b).attr("data-video-id");a.editDialog(c)}b.on("inline:edit:onion-video",d),b.on("inline:insert:onion-video",c)}}}),c("scribe-plugin-hr",[],function(){return function(){return function(a){function b(a){a({})}a.on("inline:insert:hr",b)}}}),c("scribe-plugin-placeholder",[],function(){return function(a){return function(b){function c(){var c=b.getContent();a.container.style.display="


"===c||""===c?"":"none"}b.on("content-changed",c),a.container.innerHTML=a.text}}}),c("link-formatter",["scribe-common/src/element","lodash-amd/modern/collections/contains"],function(a){return function(a){return function(b){function c(b){return b=b.trim(),b=e(b),a.domain&&(b=d(b,a.domain)),b}function d(a,b){var c=document.createElement("a");c.href=a;var d=c.hostname;return d.indexOf(b)>-1&&c.pathname.length>1&&(a=c.pathname+c.search+c.hash),a}function e(a){return"http://"!==a.substr(0,7)&&"https://"!==a.substr(0,8)&&"mailto:"!==a.substr(0,7)&&"/"!==a.substr(0,1)?-1!=a.indexOf("@")?"mailto:"+a:"http://"+a:a}function f(a){for(var b=a.firstElementChild;b;)"A"===b.nodeName?b.hasAttribute("href")&&b.setAttribute("href",c(b.getAttribute("href"))):b.children.length>0&&f(b),b=b.nextElementSibling}b.registerHTMLFormatter("sanitize",function(a){var b=document.createElement("div");return b.innerHTML=a,f(b),b.innerHTML})}}}),c("onion-editor",["scribe","scribe-plugin-blockquote-command","scribe-plugin-curly-quotes","scribe-plugin-formatter-plain-text-convert-new-lines-to-html","scribe-plugin-heading-command","scribe-plugin-intelligent-unlink-command","scribe-plugin-keyboard-shortcuts","scribe-plugin-link-ui","scribe-plugin-sanitizer","scribe-plugin-smart-lists","scribe-plugin-toolbar","scribe-plugin-inline-objects","scribe-plugin-betty-cropper","scribe-plugin-youtube","scribe-plugin-embed","scribe-plugin-onion-video","scribe-plugin-hr","scribe-plugin-placeholder","link-formatter"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){function t(j,t){t=$.extend(u,t);var v=new a(j,{allowBlockElements:t.multiline});t.placeholder&&v.use(r(t.placeholder));var w={},x=function(a){return a.metaKey||a.ctrlKey},y={},z=function(a){return $(a).is("div.inline")};return t.multiline&&(y.p={},y.br={},y.hr={}),-1!==t.formatting.indexOf("bold")&&(y.b={}),-1!==t.formatting.indexOf("italic")&&(y.i={},y.em={}),-1!==t.formatting.indexOf("strike")&&(y.s={}),w.removeFormat=function(a){return a.altKey&&a.shiftKey&&65===a.keyCode},t.multiline&&-1!==t.formatting.indexOf("link")&&(w.linkUI=function(a){return a.metaKey&&!a.shiftKey&&75===a.keyCode},w.unlink=function(a){return a.metaKey&&a.shiftKey&&75===a.keyCode},v.use(f()),v.use(h(t.link)),v.use(s(t.link)),y.a={href:!0,target:!0}),t.multiline&&-1!==t.formatting.indexOf("list")&&(w.insertUnorderedList=function(a){return a.altKey&&a.shiftKey&&66===a.keyCode},w.insertOrderedList=function(a){return a.altKey&&a.shiftKey&&78===a.keyCode},y.ol={},y.ul={},y.li={}),t.multiline&&-1!==t.formatting.indexOf("blockquote")&&(w.blockquote=function(a){return a.altKey&&a.shiftKey&&87===a.keyCode},v.use(b()),y.blockquote={}),t.multiline&&-1!==t.formatting.indexOf("heading")&&(w.h3=function(a){return x(a)&&50===a.keyCode},w.h4=function(a){return x(a)&&51===a.keyCode},v.use(e(3)),v.use(e(4)),y.h3={},y.h4={}),t.multiline&&t.inlineObjects&&(v.use(l(t.inlineObjects)),v.use(m(t.image)),v.use(n()),v.use(o()),v.use(q()),v.use(p(t.video))),v.use(i({tags:y,skipSanitization:z})),t.statsContainer&&setInterval(function(){$(t.statsContainer).html($(v.el).text().split(" ").length)},3e3),v.updateContents=function(a,b){"undefined"==typeof b&&(b=!0),v._skipFormatters=b;var c=window.scrollY;setTimeout(function(){v.el.focus(),setTimeout(function(){v.transactionManager.run(a),window.scrollTo(0,c),v.trigger("content-changed")},20)},20)},v.use(c()),v.use(g(Object.freeze(w))),t.multiline?v.use(k($(".document-tools .toolbar-contents",j.parentNode)[0])):$(".document-tools .toolbar-contents",j.parentNode).hide(),v.el.addEventListener("keydown",function(a){if(8===a.keyCode){var b=new v.api.Selection,c=$(b.selection.anchorNode).closest(".editor>*").prev();c.hasClass("inline")&&0===b.selection.anchorOffset&&b.selection.isCollapsed&&a.preventDefault()}}),v.use(d()),this.setChangeHandler=function(a){v.on("content-changed",a)},this.setContent=function(a){a||(a="


"),v.setContent(a)},this.getContent=function(){var a=v.getContent();return a},this.scribe=v,this}var u={multiline:!0,formatting:["link","bold","italic","blockquote","heading","list"],link:{domain:"avclub.com"},video:{videoEmbedUrl:"http://example.com?videoid=",insertDialog:function(){},editDialog:function(){}},image:{insertDialog:function(){},editDialog:function(){}}};return t}),b("onion-editor")}); \ No newline at end of file +if(!h)return i;var j=arguments,k=0,l="number"==typeof f?2:j.length;if(l>3&&"function"==typeof j[l-2])var m=a(j[--l-1],j[l--],2);else l>2&&"function"==typeof j[l-1]&&(m=j[--l]);for(;++ke?0:e);++d2?a(c,17,b(arguments,2),null,d):a(c,1,null,null,d)}return c}),c("lodash-amd/modern/utilities/identity",[],function(){function a(a){return a}return a}),c("lodash-amd/modern/support",["./internals/isNative"],function(a){var b=/\bthis\b/,c={};return c.funcDecomp=!a(window.WinRTError)&&b.test(function(){return this}),c.funcNames="string"==typeof Function.name,c}),c("lodash-amd/modern/internals/baseCreateCallback",["../functions/bind","../utilities/identity","./setBindData","../support"],function(a,b,c,d){function e(e,i,j){if("function"!=typeof e)return b;if("undefined"==typeof i||!("prototype"in e))return e;var k=e.__bindData__;if("undefined"==typeof k&&(d.funcNames&&(k=!e.name),k=k||!d.funcDecomp,!k)){var l=h.call(e);d.funcNames||(k=!f.test(l)),k||(k=g.test(l),c(e,k))}if(k===!1||k!==!0&&1&k[1])return e;switch(j){case 1:return function(a){return e.call(i,a)};case 2:return function(a,b){return e.call(i,a,b)};case 3:return function(a,b,c){return e.call(i,a,b,c)};case 4:return function(a,b,c,d){return e.call(i,a,b,c,d)}}return a(e,i)}var f=/^\s*function[ \n\r\t]+\w/,g=/\bthis\b/,h=Function.prototype.toString;return e}),c("lodash-amd/modern/internals/shimKeys",["./objectTypes"],function(a){var b=Object.prototype,c=b.hasOwnProperty,d=function(b){var d,e=b,f=[];if(!e)return f;if(!a[typeof b])return f;for(d in e)c.call(e,d)&&f.push(d);return f};return d}),c("lodash-amd/modern/objects/keys",["../internals/isNative","./isObject","../internals/shimKeys"],function(a,b,c){var d=a(d=Object.keys)&&d,e=d?function(a){return b(a)?d(a):[]}:c;return e}),c("lodash-amd/modern/objects/forOwn",["../internals/baseCreateCallback","./keys","../internals/objectTypes"],function(a,b,c){var d=function(d,e,f){var g,h=d,i=h;if(!h)return i;if(!c[typeof h])return i;e=e&&"undefined"==typeof f?e:a(e,f,3);for(var j=-1,k=c[typeof h]&&b(h),l=k?k.length:0;++jh?f(0,k+h):h)||0,c(e)?l=j(e,g,h)>-1:"number"==typeof k?l=(d(e)?e.indexOf(g,h):j(e,g,h))>-1:b(e,function(a){return++i>=h?!(l=a===g):void 0}),l}var f=Math.max;return e}),c("scribe-common/src/element",["lodash-amd/modern/collections/contains"],function(a){function b(b){return a(e,b.nodeName)}function c(a){return a.nodeType===Node.ELEMENT_NODE&&"scribe-marker"===a.className}function d(a,b){for(;b.childNodes.length>0;)a.insertBefore(b.childNodes[0],b);a.removeChild(b)}var e=["P","LI","DIV","BLOCKQUOTE","UL","OL","H1","H2","H3","H4","H5","H6"];return{isBlockElement:b,isSelectionMarkerNode:c,unwrap:d}}),c("scribe-plugin-smart-lists",["scribe-common/src/element"],function(a){return function(){function b(a){return"*"===a||"-"===a||"•"===a}function c(b){for(;b&&!a.isBlockElement(b);)b=b.parentNode;return b}var d={32:"Space",42:"*",45:"-",46:".",49:"1",8226:"•"};return function(a){function e(){var b,c=new a.api.Selection,d=c.selection.anchorNode;if(d.nodeType===Node.TEXT_NODE?b=d:d.firstChild.nodeType===Node.TEXT_NODE&&(b=d.firstChild),!b)throw new Error("Cannot empty non-text node!");var e=b.parentNode;b.previousSibling&&e.removeChild(b.previousSibling),e.removeChild(b)}function f(f){var j;g=h,h=i,i=d[f.charCode];var k=new a.api.Selection,l=k.range.commonAncestorContainer,m=c(l);if(m&&"P"===m.tagName){var n=b(l.textContent[0]);b(h)&&"Space"===i&&n&&(j="insertUnorderedList");var o="1."===[l.previousSibling&&l.previousSibling.textContent,l.textContent].join("").slice(0,2);"1"===g&&"."===h&&"Space"===i&&o&&(j="insertOrderedList")}j&&(f.preventDefault(),a.transactionManager.run(function(){a.getCommand(j).execute(),e()}))}var g,h,i;a.el.addEventListener("keypress",f)}}}),c("scribe-plugin-toolbar",[],function(){return function(a){return function(b){var c=a.querySelectorAll("button");Array.prototype.forEach.call(c,function(a){function c(){var c=new b.api.Selection;c.range&&(d.queryEnabled()?(a.removeAttribute("disabled"),d.queryState()?a.classList.add("active"):a.classList.remove("active")):a.setAttribute("disabled","disabled"))}var d=b.getCommand(a.dataset.commandName);a.addEventListener("click",function(){b.el.focus(),d.execute()}),b.el.addEventListener("keyup",c),b.el.addEventListener("mouseup",c),b.on("content-changed",c)})}}}),c("scribe-plugin-inline-objects",[],function(){return function(a){return function(b){function c(a){n=a,$(".embed-button",q).click(d),$(".inline-tools button",q.parentNode).click(function(a){var b=$(a.target).data("commandName");"function"==typeof r[b]&&r[b]()})}function d(a){var c,d,g=$(".embed-fly-out").height(),h=$(".embed-button").height(),i=$(a.target).closest("button").data("commandName");"embed-before"===i?(c=o.position().top-g/2+h/2,d="before"):(c=o.position().top+o.height()+parseInt(o.css("margin-top"))-g/2+h/2,d="after"),$(".embed-fly-out",q).css({top:c,left:$(b.el).css("padding-left")}).show();var j=o;$(".embed-fly-out button").bind("click.inline",function(a){var b=$(a.target).closest("button").data("commandName");f(b,j,d)}),$("body").bind("click.inline",function(a){0===$(a.target).closest(".embed-tools").length&&e()})}function e(){$("body").unbind("click.inline"),$(".embed-fly-out button").unbind("click.inline"),$(".embed-fly-out").hide()}function f(a,c,d){b.trigger("inline:insert:"+a,[function(e){b.updateContents(function(){var b=m(n[a].template,$.extend(n[a].defaults,e));$(c)[d](b),$(".inline",q).attr("contenteditable","false")})}]),$(".embed-tools",q).removeClass("active")}function g(){$(".inline-tools").hide(),$(q).removeClass("inline-active")}function h(){var a=$(p),b=a.position();$(q).addClass("inline-active"),$(".inline-tools").attr("data-type",a.attr("data-type")),$(".inline-tools .size",q).html($(p).attr("data-size")),$(".inline-tools .crop",q).html($(p).attr("data-crop")),$(".inline-tools",q).css({top:b.top+parseInt(a.css("margin-top")),left:b.left+parseInt(a.css("margin-left"))+parseInt($(".editor",q).css("margin-left")),width:a.width(),height:a.height()}).show()}function i(){return n[$(p).attr("data-type")].size}function j(){return n[$(p).attr("data-type")].crop}function k(a,b){var c=$(p).attr("data-"+a),d=b.indexOf(c)+1;d>=b.length&&(d=0),l(a,b[d]),"function"==typeof window.picturefill&&setTimeout(function(){window.picturefill(p)},100)}function l(a,c){var d=$(p).attr("data-"+a);b.updateContents(function(){$(p).removeClass(a+"-"+d).addClass(a+"-"+c).attr("data-"+a,c),h()})}function m(a,b){for(var c in b)c&&(a=a.replace(new RegExp("{{"+c+"}}","g"),b[c]));return a}var n,o,p,q=b.el.parentNode;b.el.addEventListener("mouseover",function(a){var c=$(a.target).closest(".editor>*");1===c.length?($(".embed-tools",q).css({width:$(b.el).css("padding-left"),top:c.position().top+c.css("margin-top").replace(/[^-\d\.]/g,"")/2,height:c.height()}).addClass("active"),o=c):$(".embed-tools",q).removeClass("active")}),b.el.parentNode.addEventListener("mouseleave",function(){$(".embed-tools",q).removeClass("active")}),$(".embed-tools",q).mouseover(function(){$(".embed-tools",q).addClass("active")}),$(".editor",q).mouseover(function(a){var b=$(a.target).parents(".inline");1===b.length?(p=b[b.length-1],h()):g()});var r={inline_caption:function(){var a=prompt("Caption",$(".caption",p).html());a&&b.updateContents(function(){$(".caption",p).html(a)})},inline_size:function(){var a=i();k("size",a);var b=$(p).attr("data-crop"),c=j();-1===c.indexOf(b)&&l("crop",c[0])},inline_crop:function(){var a=n[$(p).attr("data-type")].crop;k("crop",a)},inline_up:function(){g();var a=$(p).prev()[0];if(a){var c=$(p).offset().top;b.updateContents(function(){$(p).after(a),setTimeout(function(){h();var a=$(p).offset().top;window.scrollBy(0,a-c)},0)})}},inline_down:function(){g();var a=$(p).next()[0];if(a){var c=$(p).offset().top;b.updateContents(function(){$(p).before(a),setTimeout(function(){h();var a=$(p).offset().top;window.scrollBy(0,a-c)},0)})}},inline_remove:function(){b.updateContents(function(){$(p).remove()}),g()},inline_edit:function(){b.trigger("inline:edit:"+$(p).attr("data-type"),[p,function(a,c){var d=$(a).attr("data-type");b.updateContents(function(){a.outerHTML=m(n[d].template,$.extend(n[d].defaults,c))})}])}};"string"==typeof a||a instanceof String?$.ajax(a,{success:c,dataType:"json"}):c(a)}}}),c("scribe-plugin-betty-cropper",[],function(){return function(a){return function(b){function c(b){a.insertDialog().then(function(a){var c;c=-1!==a.name.toUpperCase().indexOf("GIF")?"gif":"jpg",b({image_id:a.id,format:c}),window.picturefill&&setTimeout(function(){window.picturefill($("[data-image-id="+a.id+"]")[0])},100)},function(a){console.log(a)},function(a){console.log(a)})}function d(b){e=b.getAttribute("data-image-id");var c=$(".caption",b).html(),d=b.getAttribute("data-alt");a.editDialog({id:e,caption:c,alt:d}).then(function(a){null===a.id?$(b).remove():($(b).attr("data-image-id",a.id),$(b).attr("data-alt",a.alt),$(".caption",b).html(a.caption),window.picturefill&&setTimeout(function(){window.picturefill($("[data-image-id="+a.id+"]")[0])},100))})}var e;b.on("inline:edit:image",d),b.on("inline:insert:image",c)}}}),c("scribe-plugin-youtube",[],function(){return function(){return function(a){function b(a){if(!a)return!1;var b=/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/,c=a.match(b);return c&&11==c[7].length?c[7]:!1}function c(a){var c=prompt("Youtube URL:"),d=b(c);d&&a({youtube_id:d,caption:""})}function d(a,c){var d=prompt("Youtube URL:",$(a).attr("data-youtube-id")||""),e=b(d);e&&c(a,{youtube_id:e,caption:$(".caption",a).html()})}a.on("inline:insert:youtube",c),a.on("inline:edit:youtube",d)}}}),c("scribe-plugin-embed",[],function(){return function(){return function(a){function b(a,b){h.val(unescape($(a).attr("data-code"))),i.val($(".caption",a).text());var c=$(a).attr("data-size")+"-"+$(a).attr("data-crop");$("[value="+c+"]",g).attr("checked",!0),g.modal("show"),j.click(function(){var c=h.val();""===c.trim()?k.show():(k.hide(),b(a,{code:c,caption:i.val(),escaped_code:escape(c),size:d(),crop:e()}),g.modal("hide"))}),g.modal("show")}function c(a){h.val(""),i.val(""),g.modal("show"),j.click(function(){var b=h.val();""===b.trim()?k.show():(k.hide(),a({code:b,caption:i.val(),escaped_code:escape(b),size:d(),crop:e()}),g.modal("hide"))})}function d(){var a="original";return l.length>0&&l.val().split("-")[0],a}function e(){var a="original";return l.length>0&&l.val().split("-")[1],a}a.on("inline:insert:embed",c),a.on("inline:edit:embed",b);var f=a.el.parentNode,g=$(".embed-modal",f),h=$(".embed-body",g),i=$(".embed-caption",g),j=$(".set-embed-button",g),k=$(".embed-error",g),l=$("[name=size]",g);g.on("hide.bs.modal",function(){j.unbind("click"),k.hide()})}}}),c("scribe-plugin-onion-video",[],function(){return function(a){return function(b){function c(c){function d(){}function e(){}return a.insertDialog().then(function(d){b.updateContents(function(){c({embed_url:a.videoEmbedUrl,video_id:d.attrs.id})})},function(a){e(a)},function(a){d(a)})}function d(b){var c=$(b).attr("data-video-id");a.editDialog(c)}b.on("inline:edit:onion-video",d),b.on("inline:insert:onion-video",c)}}}),c("scribe-plugin-hr",[],function(){return function(){return function(a){function b(a){a({})}a.on("inline:insert:hr",b)}}}),c("scribe-plugin-placeholder",[],function(){return function(a){return function(b){function c(){var c=b.getContent();a.container.style.display="


"===c||""===c?"":"none"}b.on("content-changed",c),a.container.innerHTML=a.text}}}),c("link-formatter",["scribe-common/src/element","lodash-amd/modern/collections/contains"],function(a){return function(a){return function(b){function c(b){return b=b.trim(),b=e(b),a.domain&&(b=d(b,a.domain)),b}function d(a,b){var c=document.createElement("a");c.href=a;var d=c.hostname;return d.indexOf(b)>-1&&c.pathname.length>1&&(a=c.pathname+c.search+c.hash),a}function e(a){return"http://"!==a.substr(0,7)&&"https://"!==a.substr(0,8)&&"mailto:"!==a.substr(0,7)&&"/"!==a.substr(0,1)?-1!=a.indexOf("@")?"mailto:"+a:"http://"+a:a}function f(a){for(var b=a.firstElementChild;b;)"A"===b.nodeName?b.hasAttribute("href")&&b.setAttribute("href",c(b.getAttribute("href"))):b.children.length>0&&f(b),b=b.nextElementSibling}b.registerHTMLFormatter("sanitize",function(a){var b=document.createElement("div");return b.innerHTML=a,f(b),b.innerHTML})}}}),c("onion-editor",["scribe","scribe-plugin-blockquote-command","scribe-plugin-curly-quotes","scribe-plugin-formatter-plain-text-convert-new-lines-to-html","scribe-plugin-heading-command","scribe-plugin-intelligent-unlink-command","scribe-plugin-keyboard-shortcuts","scribe-plugin-link-ui","scribe-plugin-sanitizer","scribe-plugin-smart-lists","scribe-plugin-toolbar","scribe-plugin-inline-objects","scribe-plugin-betty-cropper","scribe-plugin-youtube","scribe-plugin-embed","scribe-plugin-onion-video","scribe-plugin-hr","scribe-plugin-placeholder","link-formatter"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){function t(j,t){t=$.extend(u,t);var v=new a(j,{allowBlockElements:t.multiline});t.placeholder&&v.use(r(t.placeholder)),v.commandPatches.bold.execute=function(a){void 0===this.selection?document.execCommand(this.commandName,!1,a||null):v.transactionManager.run(function(){document.execCommand(this.commandName,!1,a||null)}.bind(this))};var w=new v.api.CommandPatch("italic");w.execute=function(a){void 0===this.selection?document.execCommand(this.commandName,!1,a||null):v.transactionManager.run(function(){document.execCommand(this.commandName,!1,a||null)}.bind(this))},v.commandPatches.italic=w;var x={},y=function(a){return a.metaKey||a.ctrlKey},z={},A=function(a){return $(a).is("div.inline")};return t.multiline&&(z.p={},z.br={},z.hr={}),-1!==t.formatting.indexOf("bold")&&(x.bold=function(a){return a.metaKey&&66===a.keyCode},z.b={}),-1!==t.formatting.indexOf("italic")&&(x.italic=function(a){return a.metaKey&&73===a.keyCode},z.i={},z.em={}),-1!==t.formatting.indexOf("strike")&&(x.strikeThrough=function(a){return a.altKey&&a.shiftKey&&83===a.keyCode},z.s={}),x.removeFormat=function(a){return a.altKey&&a.shiftKey&&65===a.keyCode},t.multiline&&-1!==t.formatting.indexOf("link")&&(x.linkUI=function(a){return a.metaKey&&!a.shiftKey&&75===a.keyCode},x.unlink=function(a){return a.metaKey&&a.shiftKey&&75===a.keyCode},v.use(f()),v.use(h(t.link)),v.use(s(t.link)),z.a={href:!0,target:!0}),t.multiline&&-1!==t.formatting.indexOf("list")&&(x.insertUnorderedList=function(a){return a.altKey&&a.shiftKey&&66===a.keyCode},x.insertOrderedList=function(a){return a.altKey&&a.shiftKey&&78===a.keyCode},z.ol={},z.ul={},z.li={}),t.multiline&&-1!==t.formatting.indexOf("blockquote")&&(x.blockquote=function(a){return a.altKey&&a.shiftKey&&87===a.keyCode},v.use(b()),z.blockquote={}),t.multiline&&-1!==t.formatting.indexOf("heading")&&(x.h3=function(a){return y(a)&&50===a.keyCode},x.h4=function(a){return y(a)&&51===a.keyCode},v.use(e(3)),v.use(e(4)),z.h3={},z.h4={}),t.multiline&&t.inlineObjects&&(v.use(l(t.inlineObjects)),v.use(m(t.image)),v.use(n()),v.use(o()),v.use(q()),v.use(p(t.video))),v.use(i({tags:z,skipSanitization:A})),t.statsContainer&&setInterval(function(){$(t.statsContainer).html($(v.el).text().split(" ").length)},3e3),v.updateContents=function(a,b){"undefined"==typeof b&&(b=!0),v._skipFormatters=b;var c=window.scrollY;setTimeout(function(){v.el.focus(),setTimeout(function(){v.transactionManager.run(a),window.scrollTo(0,c),v.trigger("content-changed")},20)},20)},v.use(c()),v.use(g(Object.freeze(x))),t.multiline?v.use(k($(".document-tools .toolbar-contents",j.parentNode)[0])):$(".document-tools .toolbar-contents",j.parentNode).hide(),v.el.addEventListener("keydown",function(a){if(8===a.keyCode){var b=new v.api.Selection,c=$(b.selection.anchorNode).closest(".editor>*").prev();c.hasClass("inline")&&0===b.selection.anchorOffset&&b.selection.isCollapsed&&a.preventDefault()}}),v.use(d()),this.setChangeHandler=function(a){v.on("content-changed",a)},this.setContent=function(a){a||(a="


"),v.setContent(a)},this.getContent=function(){var a=v.getContent();return a},this.scribe=v,this}var u={multiline:!0,formatting:["link","bold","italic","blockquote","heading","list"],link:{domain:"avclub.com"},video:{videoEmbedUrl:"http://example.com?videoid=",insertDialog:function(){},editDialog:function(){}},image:{insertDialog:function(){},editDialog:function(){}}};return t}),b("onion-editor")}); \ No newline at end of file diff --git a/src/js/onion-editor.js b/src/js/onion-editor.js index dc202bc..53a1682 100644 --- a/src/js/onion-editor.js +++ b/src/js/onion-editor.js @@ -69,6 +69,28 @@ define('onion-editor',[ scribe.use(scribePluginPlaceholder(options.placeholder)); } + // For now, we need to patch some scribe commands, just in case. + scribe.commandPatches.bold.execute = function (value) { + if (this.selection === undefined) { + document.execCommand(this.commandName, false, value || null); + } else { + scribe.transactionManager.run(function () { + document.execCommand(this.commandName, false, value || null); + }.bind(this)); + } + }; + var italicCommand = new scribe.api.CommandPatch('italic'); + italicCommand.execute = function (value) { + if (this.selection === undefined) { + document.execCommand(this.commandName, false, value || null); + } else { + scribe.transactionManager.run(function () { + document.execCommand(this.commandName, false, value || null); + }.bind(this)); + } + }; + scribe.commandPatches['italic'] = italicCommand; + var keyCommands = {}; var ctrlKey = function (event) { return event.metaKey || event.ctrlKey; }; @@ -88,24 +110,24 @@ define('onion-editor',[ // Bold if (options.formatting.indexOf('bold') !== -1) { - // keyCommands.bold = function (event) { return event.metaKey && event.keyCode === 66; }; // b + keyCommands.bold = function (event) { return event.metaKey && event.keyCode === 66; }; // b tags.b = {}; } // Italics if (options.formatting.indexOf('italic') !== -1) { - // keyCommands.italic = function (event) { return event.metaKey && event.keyCode === 73; }; // i + keyCommands.italic = function (event) { return event.metaKey && event.keyCode === 73; }; // i tags.i = {}; tags.em = {}; } // Strike if (options.formatting.indexOf('strike') !== -1) { - // keyCommands.strikeThrough = function (event) { return event.altKey && event.shiftKey && event.keyCode === 83; }; // s + keyCommands.strikeThrough = function (event) { return event.altKey && event.shiftKey && event.keyCode === 83; }; // s tags.s = {}; } - //Remove formatting... + // Remove formatting... keyCommands.removeFormat = function (event) { return event.altKey && event.shiftKey && event.keyCode === 65; }; // a // Links