From 29cc3af576f37f1ac778dc0aa4a3e3e2b03e7997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Augusto=20Soares?= Date: Fri, 21 Feb 2014 03:11:30 -0300 Subject: [PATCH 1/4] textarea div replacement --- build/jquery.notebook.min.css | 2 +- build/jquery.notebook.min.js | 404 +--------- index.html | 4 +- src/js/jquery.notebook.js | 1319 +++++++++++++++++---------------- 4 files changed, 670 insertions(+), 1059 deletions(-) diff --git a/build/jquery.notebook.min.css b/build/jquery.notebook.min.css index a0fb2d4..071fa61 100644 --- a/build/jquery.notebook.min.css +++ b/build/jquery.notebook.min.css @@ -1 +1 @@ -.jquery-notebook.editor{position:relative;outline:0;min-height:50px}.jquery-notebook.editor p{z-index:2;position:relative;min-height:1px}.jquery-notebook.editor p.placeholder{position:absolute;z-index:1;opacity:.5;pointer-events:none}.jquery-notebook p:first-child,.jquery-notebook p.placeholder+p{margin-top:0}.jquery-notebook.bubble{position:absolute;z-index:3;opacity:1;height:43px;left:0;top:0;opacity:0;border-radius:5px;-webkit-box-shadow:2px 2px 2px -1px rgba(0,0,0,.7),inset 0 0 1px rgba(255,255,255,.07),inset 0 0 2px rgba(255,255,255,.15000000000000002);box-shadow:2px 2px 2px -1px rgba(0,0,0,.7),inset 0 0 1px rgba(255,255,255,.07),inset 0 0 2px rgba(255,255,255,.15000000000000002);background:#323232;-webkit-transition:.5s ease-in-out;transition:.5s ease-in-out}.jquery-notebook.bubble.active{opacity:1}.jquery-notebook.bubble:after{content:'';display:block;position:absolute;left:50%;bottom:-3px;margin-left:-4px;width:8px;height:8px;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);background:#323232;-webkit-box-shadow:0 0 2px #262625;box-shadow:0 0 2px #262625}.jquery-notebook.bubble ul{padding:0;margin:0;list-style:none}.jquery-notebook.bubble ul li{display:inline}.jquery-notebook.bubble button{outline:0;border:0;background:transparent;width:41px;height:42px;font-family:FontAwesome;color:#fff;font-size:14pt;cursor:pointer;margin-top:0}.jquery-notebook.bubble button.active{color:#1ed228}.jquery-notebook.bubble button.bold:after{content:"\f032"}.jquery-notebook.bubble button.italic:after{content:"\f033"}.jquery-notebook.bubble button.underline:after{content:"\f0cd"}.jquery-notebook.bubble button.anchor:after{content:"\f0c1"}.jquery-notebook.bubble button.paste:after{content:"\f0ea"}.jquery-notebook.bubble button.h1:after{font-family:inherit;content:"h1"}.jquery-notebook.bubble button.h2:after{font-family:inherit;content:"h2"}.jquery-notebook.bubble button.ul:after{font-family:inherit;content:"\f0ca"}.jquery-notebook.bubble button.ol:after{font-family:inherit;content:"\f0cb"}.jquery-notebook .link-area{display:none}.jquery-notebook .link-area button{float:left}.jquery-notebook .link-area button:after{content:"\f00d"}.jquery-notebook input[type=text]{width:220px;height:28px;margin:6px 0 0 10px;background:0;border:0;outline:0;color:#fff;font-size:14px;float:left} \ No newline at end of file +.jquery-notebook.editor{position:relative;outline:0;min-height:50px}.jquery-notebook.editor p{z-index:2;position:relative;min-height:1px}.jquery-notebook.editor p.placeholder{position:absolute;z-index:1;opacity:.5;pointer-events:none}.jquery-notebook p:first-child,.jquery-notebook p.placeholder+p{margin-top:0}.jquery-notebook.bubble{position:absolute;z-index:3;opacity:1;height:43px;left:0;top:0;opacity:0;border-radius:5px;border:1px solid #1C1C1B;-webkit-box-shadow:0 2px 3px rgba(0,0,0,.2),inset 0 0 2px rgba(255,255,255,.2);box-shadow:0 2px 3px rgba(0,0,0,.2),inset 0 0 2px rgba(255,255,255,.2);background:#373735;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,rgba(55,55,53,1)),color-stop(100%,rgba(40,40,39,1)));background:-webkit-linear-gradient(top,rgba(55,55,53,1) 0,rgba(40,40,39,1) 100%);background:-webkit-gradient(linear,left top,left bottom,from(rgba(55,55,53,1)),to(rgba(40,40,39,1)));background:-webkit-linear-gradient(top,rgba(55,55,53,1) 0,rgba(40,40,39,1) 100%);background:linear-gradient(to bottom,rgba(55,55,53,1) 0,rgba(40,40,39,1) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#373735', endColorstr='#282827', GradientType=0);-webkit-transition:.15s ease-in-out;transition:.15s ease-in-out;-webkit-transition:.15s ease-in-out}.jquery-notebook.bubble.active{opacity:1}.jquery-notebook.bubble.jump{-webkit-transition:opacity .15s;transition:opacity .15s;-webkit-transition:opacity .15s}.jquery-notebook.bubble:after{content:'';display:block;position:absolute;left:50%;bottom:-6px;margin-left:-8px;width:16px;height:16px;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);background:#282827;-webkit-box-shadow:2px 2px 1px rgba(0,0,0,.1);box-shadow:2px 2px 1px rgba(0,0,0,.1)}.jquery-notebook.bubble ul{padding:0;margin:0;list-style:none}.jquery-notebook.bubble ul li{display:inline}.jquery-notebook.bubble button{outline:0;border:0;background:transparent;width:41px;height:42px;font-family:FontAwesome;color:#fff;font-size:14pt;cursor:pointer}.jquery-notebook.bubble button.active{color:#60D778}.jquery-notebook.bubble button.bold:after{content:"\f032"}.jquery-notebook.bubble button.italic:after{content:"\f033"}.jquery-notebook.bubble button.underline:after{content:"\f0cd"}.jquery-notebook.bubble button.anchor:after{content:"\f0c1"}.jquery-notebook.bubble button.paste:after{content:"\f0ea"}.jquery-notebook.bubble button.h1:after{font-family:inherit;content:"h1"}.jquery-notebook.bubble button.h2:after{font-family:inherit;content:"h2"}.jquery-notebook.bubble button.ul:after{font-family:inherit;content:"\f0ca"}.jquery-notebook.bubble button.ol:after{font-family:inherit;content:"\f0cb"}.jquery-notebook .link-area{display:none}.jquery-notebook .link-area button{float:left}.jquery-notebook .link-area button:after{content:"\f00d"}.jquery-notebook input[type=text]{width:220px;height:28px;margin:6px 0 0 10px;background:0;border:0;outline:0;color:#fff;font-size:14px;float:left} \ No newline at end of file diff --git a/build/jquery.notebook.min.js b/build/jquery.notebook.min.js index 62583b2..02a46bb 100644 --- a/build/jquery.notebook.min.js +++ b/build/jquery.notebook.min.js @@ -1,403 +1 @@ -! function(e, t, n) { - var o, i = function() { - var e = function(e) { - return e && "none" != e ? e.match(/(-?[0-9\.]+)/g) : [1, 0, 0, 1, 0, 0] - }, t = function(e) { - return e.css("-webkit-transform") || e.css("transform") || e.css("-moz-transform") || e.css("-o-transform") || e.css("-ms-transform") - }, n = function(n) { - var o = t(n); - return e(o) - }, o = function(e, t) { - e.css("-webkit-transform", t), e.css("-moz-transform", t), e.css("-o-transform", t), e.css("-ms-transform", t), e.css("transform", t) - }, i = function(e) { - return "matrix(" + e[0] + ", " + e[1] + ", " + e[2] + ", " + e[3] + ", " + e[4] + ", " + e[5] + ")" - }, a = function(e) { - var t = n(e); - return { - x: parseInt(t[4]), - y: parseInt(t[5]) - } - }, l = function(e, t) { - var a = n(e); - a[0] = a[3] = t; - var l = i(a); - o(e, l) - }, c = function(e, t, a) { - var l = n(e); - l[4] = t, l[5] = a; - var c = i(l); - o(e, c) - }, r = function(e, t) { - var a = n(e), - l = t * (Math.PI / 180), - c = -1 * l; - a[1] = l, a[2] = c; - var r = i(a); - o(e, r) - }; - return { - scale: l, - translate: c, - rotate: r, - getTranslate: a - } - }(), - a = "MacIntel" == n.navigator.platform, - l = 0, - c = 0, - r = { - command: !1, - shift: !1, - isSelecting: !1 - }, s = { - 66: "bold", - 73: "italic", - 85: "underline", - 112: "h1", - 113: "h2", - 122: "undo" - }, u = { - keyboard: { - isCommand: function(e, t, n) { - a && e.metaKey || !a && e.ctrlKey ? t() : n() - }, - isShift: function(e, t, n) { - e.shiftKey ? t() : n() - }, - isModifier: function(e, t) { - var n = e.which, - o = s[n]; - o && t.call(this, o) - }, - isEnter: function(e, t) { - 13 === e.which && t() - }, - isArrow: function(e, t) { - (e.which >= 37 || e.which <= 40) && t() - } - }, - html: { - addTag: function(n, o, i, a) { - var l = e(t.createElement(o)); - return l.attr("contenteditable", Boolean(a)), l.append(" "), n.append(l), i && (r.focusedElement = n.children().last(), u.cursor.set(n, 0, r.focusedElement)), l - } - }, - cursor: { - set: function(e, o, i) { - var a; - if (t.createRange) { - a = t.createRange(); - var l = n.getSelection(), - c = e.children().last(), - r = c.html().length - 1, - s = i ? i[0] : c[0], - u = "undefined" != typeof o ? o : r; - a.setStart(s, u), a.collapse(!0), l.removeAllRanges(), l.addRange(a) - } else a = t.body.createTextRange(), a.moveToElementText(i), a.collapse(!1), a.select() - } - }, - selection: { - save: function() { - if (n.getSelection) { - var e = n.getSelection(); - if (e.rangeCount > 0) return e.getRangeAt(0) - } else if (t.selection && t.selection.createRange) return t.selection.createRange(); - return null - }, - restore: function(e) { - if (e) - if (n.getSelection) { - var o = n.getSelection(); - o.removeAllRanges(), o.addRange(e) - } else t.selection && e.select && e.select() - }, - getText: function() { - var e = ""; - return n.getSelection ? e = n.getSelection().toString() : t.getSelection ? e = t.getSelection().toString() : t.selection && (e = t.selection.createRange().text), e - }, - clear: function() { - window.getSelection ? window.getSelection().empty ? window.getSelection().empty() : window.getSelection().removeAllRanges && window.getSelection().removeAllRanges() : document.selection && document.selection.empty() - }, - getContainer: function(e) { - return n.getSelection && e && e.commonAncestorContainer ? e.commonAncestorContainer : t.selection && e && e.parentElement ? e.parentElement() : null - } - }, - validation: { - isUrl: function(e) { - return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test(e) - } - } - }, d = { - updatePos: function(t, o) { - var a = n.getSelection(), - l = a.getRangeAt(0), - c = l.getBoundingClientRect(), - r = o.width(), - s = o.height(), - u = (t.offset().left, { - x: c.left + c.width / 2 - r / 2, - y: c.top - s - 8 + e(document).scrollTop() - }); - i.translate(o, u.x, u.y) - }, - updateState: function(e, t) { - t.find("button").removeClass("active"); - var o = n.getSelection(), - i = []; - d.checkForFormatting(o.focusNode, i); - for (var a = { - b: "bold", - i: "italic", - h1: "h1", - h2: "h2", - a: "anchor", - ul: "ul", - ol: "ol" - }, l = 0; l < i.length; l++) { - var c = i[l]; - t.find("button." + a[c]).addClass("active") - } - }, - checkForFormatting: function(e, t) { - var n = ["b", "i", "u", "h1", "h2", "ol", "ul", "li", "a"]; - ("#text" === e.nodeName || -1 != n.indexOf(e.nodeName.toLowerCase())) && ("#text" != e.nodeName && t.push(e.nodeName.toLowerCase()), d.checkForFormatting(e.parentNode, t)) - }, - buildMenu: function(t, n) { - var i = u.html.addTag(n, "ul", !1, !1); - for (var a in o.modifiers) { - var l = u.html.addTag(i, "li", !1, !1), - c = u.html.addTag(l, "button", !1, !1); - c.attr("editor-command", o.modifiers[a]), c.addClass(o.modifiers[a]) - } - n.find("button").click(function(n) { - n.preventDefault(); - var o = e(this).attr("editor-command"); - m.commands[o].call(t, n) - }); - var r = u.html.addTag(n, "div", !1, !1); - r.addClass("link-area"); - var s = u.html.addTag(r, "input", !1, !1); - s.attr({ - type: "text" - }); - var d = u.html.addTag(r, "button", !1, !1); - d.click(function(t) { - t.preventDefault(); - e(this).closest(".editor"); - e(this).closest(".link-area").hide(), e(this).closest(".bubble").find("ul").show() - }) - }, - show: function() { - var t = e(this).parent().find(".bubble"); - t.length || (t = u.html.addTag(e(this).parent(), "div", !1, !1), t.addClass("jquery-notebook bubble"), d.buildMenu(this, t)), t.show(), d.updateState(this, t), t.addClass("active"), d.updatePos(e(this), t) - }, - update: function() { - var t = e(this).parent().find(".bubble"); - d.updateState(this, t) - }, - clear: function() { - var t = e(this).parent().find(".bubble"); - t.hasClass("active") && (t.removeClass("active"), d.hideLinkInput.call(this), d.showButtons.call(this), setTimeout(function() { - t.hasClass("active") || t.hide() - }, 500)) - }, - hideButtons: function() { - e(this).parent().find(".bubble").find("ul").hide() - }, - showButtons: function() { - e(this).parent().find(".bubble").find("ul").show() - }, - showLinkInput: function(t) { - d.hideButtons.call(this); - var n = this, - o = e(this).parent().find(".bubble").find("input[type=text]"), - i = o.closest(".jquery-notebook").find("button.anchor").hasClass("active"); - o.unbind("keydown"), o.keydown(function(o) { - var a = e(this); - u.keyboard.isEnter(o, function() { - o.preventDefault(); - var e = a.val(); - u.validation.isUrl(e) ? (o.url = e, m.commands.createLink(o, t), d.clear.call(n)) : "" === e && i && (m.commands.removeLink(o, t), d.clear.call(n)) - }) - }), o.bind("paste", function() { - var t = e(this); - setTimeout(function() { - var e = t.val(); - /http:\/\/https?:\/\//.test(e) && (e = e.substring(7), t.val(e)) - }, 1) - }); - var a = "http://"; - if (i) { - var l = e(u.selection.getContainer(t)).closest("a"); - a = l.prop("href") || a - } - e(this).parent().find(".link-area").show(), o.val(a).focus() - }, - hideLinkInput: function() { - e(this).parent().find(".bubble").find(".link-area").hide() - } - }, f = { - bindEvents: function(t) { - t.keydown(h.keydown), t.keyup(h.keyup), t.focus(h.focus), t.bind("paste", m.paste), t.mousedown(h.mouseClick), t.mouseup(h.mouseUp), t.mousemove(h.mouseMove), t.blur(h.blur), e("body").mouseup(function(e) { - e.target == e.currentTarget && r.isSelecting && h.mouseUp.call(t, e) - }) - }, - setPlaceholder: function(t) { - if (/^\s*$/.test(e(this).text())) { - e(this).empty(); - var n = u.html.addTag(e(this), "p").addClass("placeholder"); - n.append(e(this).attr("editor-placeholder")), u.html.addTag(e(this), "p", "undefined" != typeof t.focus ? t.focus : !1, !0) - } else e(this).find(".placeholder").remove() - }, - removePlaceholder: function() { - e(this).find(".placeholder").remove() - }, - preserveElementFocus: function() { - var e = n.getSelection() ? n.getSelection().anchorNode : t.activeElement; - if (e) { - var o = e.parentNode, - i = o !== r.focusedElement, - a = this.children, - l = 0; - o === this && (o = e); - for (var c = 0; c < a.length; c++) - if (o === a[c]) { - l = c; - break - } - i && (r.focusedElement = o, r.focusedElementIndex = l) - } - }, - prepare: function(e, t) { - if (o = t, e.attr("editor-mode", o.mode), e.attr("editor-placeholder", o.placeholder), e.attr("contenteditable", !0), e.css("position", "relative"), e.addClass("jquery-notebook editor"), f.setPlaceholder.call(e, {}), f.preserveElementFocus.call(e), o.autoFocus === !0) { - var n = e.find("p:not(.placeholder)"); - u.cursor.set(e, 0, n) - } - } - }, h = { - keydown: function(e) { - var t = this; - r.command && 65 === e.which && setTimeout(function() { - d.show.call(t) - }, 50), u.keyboard.isCommand(e, function() { - r.command = !0 - }, function() { - r.command = !1 - }), u.keyboard.isShift(e, function() { - r.shift = !0 - }, function() { - r.shift = !1 - }), u.keyboard.isModifier.call(this, e, function(t) { - r.command && m.commands[t].call(this, e) - }), r.shift ? u.keyboard.isArrow.call(this, e, function() { - setTimeout(function() { - var e = u.selection.getText(); - "" !== e ? d.show.call(t) : d.clear.call(t) - }, 100) - }) : u.keyboard.isArrow.call(this, e, function() { - d.clear.call(t) - }), 13 === e.which && m.enterKey.call(this, e), 27 === e.which && d.clear.call(this), 86 === e.which && m.paste.call(this, e) - }, - keyup: function(t) { - u.keyboard.isCommand(t, function() { - r.command = !1 - }, function() { - r.command = !0 - }), f.preserveElementFocus.call(this), f.removePlaceholder.call(this), /^\s*$/.test(e(this).text()) && (e(this).empty(), u.html.addTag(e(this), "p", !0, !0)) - }, - focus: function() { - r.command = !1, r.shift = !1 - }, - mouseClick: function(t) { - var n = this; - if (r.isSelecting = !0, 2 === t.button) return setTimeout(function() { - d.show.call(n) - }, 50), void t.preventDefault(); - if (e(this).find(".bubble:visible").length) { - var o = e(this).find(".bubble:visible"), - i = o.offset().left, - a = o.offset().top, - s = o.width(), - u = o.height(); - if (l > i && i + s > l && c > a && a + u > c) return - } - }, - mouseUp: function(e) { - e.preventDefault(); - var t = this; - r.isSelecting = !1, setTimeout(function() { - var e = u.selection.save(); - e.collapsed ? d.clear.call(t) : d.show.call(t) - }, 50) - }, - mouseMove: function(e) { - l = e.pageX, c = e.pageY - }, - blur: function() { - f.setPlaceholder.call(this, { - focus: !1 - }) - } - }, m = { - commands: { - bold: function(e) { - e.preventDefault(), t.execCommand("bold", !1), d.update.call(this) - }, - italic: function(e) { - e.preventDefault(), t.execCommand("italic", !1), d.update.call(this) - }, - underline: function(e) { - e.preventDefault(), t.execCommand("underline", !1), d.update.call(this) - }, - anchor: function(e) { - e.preventDefault(); - var t = u.selection.save(); - d.showLinkInput.call(this, t) - }, - createLink: function(e, n) { - u.selection.restore(n), t.execCommand("createLink", !1, e.url), d.update.call(this) - }, - removeLink: function(t, n) { - var o = e(u.selection.getContainer(n)).closest("a"); - o.contents().first().unwrap() - }, - h1: function(n) { - n.preventDefault(), e(window.getSelection().anchorNode.parentNode).is("h1") ? t.execCommand("formatBlock", !1, "

") : t.execCommand("formatBlock", !1, "

"), d.update.call(this) - }, - h2: function(n) { - n.preventDefault(), e(window.getSelection().anchorNode.parentNode).is("h2") ? t.execCommand("formatBlock", !1, "

") : t.execCommand("formatBlock", !1, "

"), d.update.call(this) - }, - ul: function(e) { - e.preventDefault(), t.execCommand("insertUnorderedList", !1), d.update.call(this) - }, - ol: function(e) { - e.preventDefault(), t.execCommand("insertOrderedList", !1), d.update.call(this) - }, - undo: function(e) { - e.preventDefault(), t.execCommand("undo", !1) - } - }, - enterKey: function(t) { - return "inline" === e(this).attr("editor-mode") ? void t.preventDefault() : void 0 - }, - paste: function() { - var t = e(this); - setTimeout(function() { - t.find("*").each(function() { - var t = e(this); - e.each(this.attributes, function() { - "class" === this.name && t.hasClass("placeholder") || t.removeAttr(this.name) - }) - }) - }, 100) - } - }; - e.fn.notebook = function(t) { - return t = e.extend({}, e.fn.notebook.defaults, t), f.prepare(this, t), f.bindEvents(this), this - }, e.fn.notebook.defaults = { - autoFocus: !1, - placeholder: "Your text here...", - mode: "multiline", - modifiers: ["bold", "italic", "underline", "h1", "h2", "ol", "ul", "anchor"] - } -}(jQuery, document, window); \ No newline at end of file +!function(e,t,n){var o,i=function(){var e=function(e){return e&&"none"!=e?e.match(/(-?[0-9\.]+)/g):[1,0,0,1,0,0]},t=function(e){return e.css("-webkit-transform")||e.css("transform")||e.css("-moz-transform")||e.css("-o-transform")||e.css("-ms-transform")},n=function(n){var o=t(n);return e(o)},o=function(e,t){e.css("-webkit-transform",t),e.css("-moz-transform",t),e.css("-o-transform",t),e.css("-ms-transform",t),e.css("transform",t)},i=function(e){return"matrix("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+")"},a=function(e){var t=n(e);return{x:parseInt(t[4]),y:parseInt(t[5])}},l=function(e,t){var a=n(e);a[0]=a[3]=t;var l=i(a);o(e,l)},s=function(e,t,a){var l=n(e);l[4]=t,l[5]=a;var s=i(l);o(e,s)},c=function(e,t){var a=n(e),l=t*(Math.PI/180),s=-1*l;a[1]=l,a[2]=s;var c=i(a);o(e,c)};return{scale:l,translate:s,rotate:c,getTranslate:a}}(),a="MacIntel"==n.navigator.platform,l=0,s=0,c={command:!1,shift:!1,isSelecting:!1},r={66:"bold",73:"italic",85:"underline",112:"h1",113:"h2",122:"undo"},u={keyboard:{isCommand:function(e,t,n){a&&e.metaKey||!a&&e.ctrlKey?t():n()},isShift:function(e,t,n){e.shiftKey?t():n()},isModifier:function(e,t){var n=e.which,o=r[n];o&&t.call(this,o)},isEnter:function(e,t){13===e.which&&t()},isArrow:function(e,t){(e.which>=37||e.which<=40)&&t()}},html:{addTag:function(n,o,i,a){var l=e(t.createElement(o));return l.attr("contenteditable",Boolean(a)),l.append(" "),n.append(l),i&&(c.focusedElement=n.children().last(),u.cursor.set(n,0,c.focusedElement)),l}},cursor:{set:function(e,o,i){var a;if(t.createRange){a=t.createRange();var l=n.getSelection(),s=e.children().last(),c=s.html().length-1,r=i?i[0]:s[0],u="undefined"!=typeof o?o:c;a.setStart(r,u),a.collapse(!0),l.removeAllRanges(),l.addRange(a)}else a=t.body.createTextRange(),a.moveToElementText(i),a.collapse(!1),a.select()}},selection:{save:function(){if(n.getSelection){var e=n.getSelection();if(e.rangeCount>0)return e.getRangeAt(0)}else if(t.selection&&t.selection.createRange)return t.selection.createRange();return null},restore:function(e){if(e)if(n.getSelection){var o=n.getSelection();o.removeAllRanges(),o.addRange(e)}else t.selection&&e.select&&e.select()},getText:function(){var e="";return n.getSelection?e=n.getSelection().toString():t.getSelection?e=t.getSelection().toString():t.selection&&(e=t.selection.createRange().text),e},clear:function(){window.getSelection?window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges():document.selection&&document.selection.empty()},getContainer:function(e){return n.getSelection&&e&&e.commonAncestorContainer?e.commonAncestorContainer:t.selection&&e&&e.parentElement?e.parentElement():null}},validation:{isUrl:function(e){return/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test(e)}}},d={updatePos:function(t,o){var a=n.getSelection(),l=a.getRangeAt(0),s=l.getBoundingClientRect(),c=o.width(),r=o.height(),u=(t.offset().left,{x:s.left+s.width/2-c/2,y:s.top-r-8+e(document).scrollTop()});i.translate(o,u.x,u.y)},updateState:function(e,t){t.find("button").removeClass("active");var o=n.getSelection(),i=[];d.checkForFormatting(o.focusNode,i);for(var a={b:"bold",i:"italic",u:"underline",h1:"h1",h2:"h2",a:"anchor",ul:"ul",ol:"ol"},l=0;li&&i+r>l&&s>a&&a+u>s)return}},mouseUp:function(e){e.preventDefault();var t=this;c.isSelecting=!1,setTimeout(function(){var e=u.selection.save();e.collapsed?d.clear.call(t):d.show.call(t)},50)},mouseMove:function(e){l=e.pageX,s=e.pageY},blur:function(){f.setPlaceholder.call(this,{focus:!1})}},m={commands:{bold:function(e){e.preventDefault(),t.execCommand("bold",!1),d.update.call(this)},italic:function(e){e.preventDefault(),t.execCommand("italic",!1),d.update.call(this)},underline:function(e){e.preventDefault(),t.execCommand("underline",!1),d.update.call(this)},anchor:function(e){e.preventDefault();var t=u.selection.save();d.showLinkInput.call(this,t)},createLink:function(e,n){u.selection.restore(n),t.execCommand("createLink",!1,e.url),d.update.call(this)},removeLink:function(t,n){var o=e(u.selection.getContainer(n)).closest("a");o.contents().first().unwrap()},h1:function(n){n.preventDefault(),e(window.getSelection().anchorNode.parentNode).is("h1")?t.execCommand("formatBlock",!1,"

"):t.execCommand("formatBlock",!1,"

"),d.update.call(this)},h2:function(n){n.preventDefault(),e(window.getSelection().anchorNode.parentNode).is("h2")?t.execCommand("formatBlock",!1,"

"):t.execCommand("formatBlock",!1,"

"),d.update.call(this)},ul:function(e){e.preventDefault(),t.execCommand("insertUnorderedList",!1),d.update.call(this)},ol:function(e){e.preventDefault(),t.execCommand("insertOrderedList",!1),d.update.call(this)},undo:function(e){e.preventDefault(),t.execCommand("undo",!1)}},enterKey:function(t){return"inline"===e(this).attr("editor-mode")?void t.preventDefault():void 0},paste:function(){var t=e(this);setTimeout(function(){t.find("*").each(function(){var t=e(this);e.each(this.attributes,function(){"class"===this.name&&t.hasClass("placeholder")||t.removeAttr(this.name)})})},100)}};e.fn.notebook=function(t){return t=e.extend({},e.fn.notebook.defaults,t),f.prepare(this,t),f.bindEvents(this),this},e.fn.notebook.defaults={autoFocus:!1,placeholder:"Your text here...",mode:"multiline",modifiers:["bold","italic","underline","h1","h2","ol","ul","anchor"]}}(jQuery,document,window); \ No newline at end of file diff --git a/index.html b/index.html index 559829c..0397c95 100644 --- a/index.html +++ b/index.html @@ -9,12 +9,12 @@ Fork me on GitHub -
+