').addClass("cazary-widget-insertimage-url").attr({required:"required",placeholder:n("http://example.com/path/to/image.jpg")}))).append(e('
").addClass("cazary-widget-preview-insertimage"))));return i.on("submit","form",a).on("click",".cazary-widget-submit",a).on("keydown paste",".cazary-widget-insertimage-url",function(){var r=e(this);t.setTimeout(function(){var e=r.val();if(e!==r.data("url_old")){r.data("url_old",e);var t=i.find(".cazary-widget-preview");o(e)?(t.show(),i.find(".cazary-widget-preview-insertimage").attr("src",e)):t.hide()}},10)})}function O(r){function a(){var e=c.find(".cazary-widget-createlink-url"),t=e.val();if(i(t))t="mailto:"+t;else if(!o(t))return e.trigger("focus"),!1;return m(r,t),!1}var c=e("
").append(e("
").attr("action","#").append(e("
").append(e("
").append(e("
").text(n("Input link URL or E-mail address"))).append(e('
').addClass("cazary-widget-createlink-url").attr({required:"required",placeholder:n("http://example.com/, someone@example.com")}))).append(e('
').addClass("cazary-widget-submit").val(n("Insert")))).append(e("
").addClass("cazary-widget-preview").append(e("
").text(n("Preview"))).append(e("
").addClass("cazary-widget-preview-createlink"))));return c.on("submit","form",a).on("click",".cazary-widget-submit",a).on("keydown paste",".cazary-widget-createlink-url",function(){var r=e(this);t.setTimeout(function(){var e=r.val();if(e!==r.data("url_old")){r.data("url_old",e);var t=c.find(".cazary-widget-preview");o(e)?(t.show(),c.find(".cazary-widget-preview-createlink").attr("src",e)):t.hide()}},10)})}function E(){var e=D.getCurrentStatus();for(var t in e){var r=e[t],a=N.find(".cazary-command-"+t);if(t!==D.COMMAND.FONTNAME)if(t!==D.COMMAND.FONTSIZE)if(t!==D.COMMAND.FORECOLOR&&t!==D.COMMAND.BACKCOLOR)r===D.STATUS.ACTIVE?a.addClass("cazary-active"):a.removeClass("cazary-active"),r===D.STATUS.DISABLED?a.addClass("cazary-disabled"):a.removeClass("cazary-disabled");else{var i=N.find(".cazary-command-"+t),o=null===r?"":r;i.css("background-color",o)}else{var c=r;null===c?(r="",c=a.attr("title")):c=n(f[c]),a.text(c)}else{var s=r;null===s&&(r="",s=a.attr("title")),a.css({"font-family":r}).text(s)}}}function L(){I()?z.trigger("focus"):D.setFocus()}function v(){var t=e(D.contentDocument.body);0===t.text().length?t.addClass("empty"):t.removeClass("empty")}var A=parseInt(1e4*Math.random()),z=e(this),N=e('
').css({width:z.width()});N.prepend(s(d.commands));var M=N.find(".cazary-edit").css({height:z.height()}),b=N.find("ul.cazary-commands-list li.cazary-command-source"),k=N.find("ul.cazary-commands-list li:not(.cazary-command-source)");z.hide().before(N).insertAfter(M).addClass("cazary-source");var w=d.style,U=z.attr("placeholder");U!==r&&(w+="body.empty:before{position:fixed;color:#888;content:'"+(U=U.replace("'","\\'"))+"';}");var D=new c(M.get(0),z.val(),w),F=[D.COMMAND.BOLD,D.COMMAND.ITALIC,D.COMMAND.UNDERLINE,D.COMMAND.STRIKETHROUGH,D.COMMAND.REMOVEFORMAT,D.COMMAND.SUPERSCRIPT,D.COMMAND.SUBSCRIPT,D.COMMAND.JUSTIFYLEFT,D.COMMAND.JUSTIFYCENTER,D.COMMAND.JUSTIFYRIGHT,D.COMMAND.JUSTIFYFULL,D.COMMAND.INDENT,D.COMMAND.OUTDENT,D.COMMAND.ORDEREDLIST,D.COMMAND.UNORDEREDLIST,D.COMMAND.INSERTHORIZONTALRULE,D.COMMAND.UNLINK,D.COMMAND.UNDO,D.COMMAND.REDO],x=[D.COMMAND.FONTNAME,D.COMMAND.FONTSIZE,D.COMMAND.FORECOLOR,D.COMMAND.BACKCOLOR,D.COMMAND.INSERTIMAGE,D.COMMAND.CREATELINK];"html"===d.mode?C():p(),z.on("change",function(){var t=e(this).val();D.value(t),v()}),e(D.contentDocument).on("select",function(){E()}).on("mouseup",function(){l(),E()}).on("keydown",function(e){e.keyCode===u.ESCAPE&&l()}).on("keyup paste",function(){t.setTimeout(function(){E(),v()},10)}),e(D.contentWindow).on("focus",function(){l(),E()}).on("blur",function(){z.val(D.value())}),N.on("click","ul.cazary-commands-list li",function(t){e(this).hasClass("cazary-disabled")&&(t.stopImmediatePropagation(),L())}),b.on("click",function(){R(),L()}),e.each(F,function(){var e=this.toLowerCase();N.on("click",".cazary-command-"+e,function(){m(e)})}),e.each(x,function(){var t=this.toLowerCase();N.on("click",".cazary-command-"+t,function(){var r=e(this);return h(t,d,r),!1})})})}}(e)}),e});
--------------------------------------------------------------------------------
/dist/cazary-legacy.min.js:
--------------------------------------------------------------------------------
1 | "use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};/*! Cazary (jQuery 1.2.4+) - JavaScript WYSIWYG editor (https://github.com/shimataro/cazary) */
2 | !function(e){"object"===("undefined"==typeof module?"undefined":_typeof(module))&&"object"===_typeof(module.exports)?module.exports=e(require("jquery"),window):e(jQuery,window)}(function(e,t,r){var a=t.document,n=function(){function e(){try{var e=t.navigator;return e.browserLanguage||e.language||e.userLanguage}catch(e){return r}}var a={ja:{Font:"フォント",Size:"サイズ",Bold:"太字",Italic:"斜体",Underline:"下線","Strike-Through":"打ち消し線","Remove Format":"書式をクリア","Foreground Color":"文字色","Background Color":"背景色",Superscript:"上付き文字",Subscript:"下付き文字","Justify Left":"左揃え","Justify Center":"中央揃え","Justify Right":"右揃え","Justify Full":"両端揃え",Indent:"字下げ",Outdent:"字下げ解除","Ordered List":"番号付きリスト","Unordered List":"箇条書き","Horizontal Rule":"横線","Insert Image":"画像挿入","Insert Link":"リンク挿入",Undo:"元に戻す",Redo:"やり直し","Show Source":"HTMLソース表示","Size 1":"サイズ1","Size 2":"サイズ2","Size 3":"サイズ3","Size 4":"サイズ4","Size 5":"サイズ5","Size 6":"サイズ6","Size 7":"サイズ7","Input image URL":"画像URLを入力してください","Input link URL or E-mail address":"リンク先URLまたはメールアドレスを入力してください",Preview:"プレビュー",Insert:"挿入",Unlink:"リンク解除"},pl:{Font:"Czcionka",Size:"Rozmiar",Bold:"Pogrubienie",Italic:"Kursywa",Underline:"Podkreślenie","Strike-Through":"Przekreślenie","Remove Format":"Usuń formatowanie","Foreground Color":"Kolor czcionki","Background Color":"Kolor tła",Superscript:"Indeks górny",Subscript:"Indeks dolny","Justify Left":"Wyrównanie do lewej","Justify Center":"Wyrównaj do środka","Justify Right":"Wyrównaj do prawej","Justify Full":"Wyjustowanie",Indent:"Zwiększ wcięcie",Outdent:"Zmniejsz wcięcie","Ordered List":"Numerowanie","Unordered List":"Punktory","Horizontal Rule":"Pozioma linia","Insert Image":"Wstaw obrazek","Insert Link":"Wstaw link",Undo:"Cofnij",Redo:"Powtórz","Show Source":"Pokaż źródło","Size 1":"Rozmiar 1","Size 2":"Rozmiar 2","Size 3":"Rozmiar 3","Size 4":"Rozmiar 4","Size 5":"Rozmiar 5","Size 6":"Rozmiar 6","Size 7":"Rozmiar 7","Input image URL":"Adres obrazka","Input link URL or E-mail address":"Wprowadź adres URL lub E-mail",Preview:"Podgląd",Insert:"Wstaw",Unlink:"Usuń link"},"pt-br":{Font:"Fonte",Size:"Tamanho",Bold:"Negrito",Italic:"Itálico",Underline:"Sublinhado","Strike-Through":"Tachado","Remove Format":"Remover formatação","Foreground Color":"Cor da fonte","Background Color":"Sombreamento",Superscript:"Sobrescrito",Subscript:"Subscrito","Justify Left":"Alinhar à esquerda","Justify Center":"Centralizar","Justify Right":"Alinhar à direita","Justify Full":"Justificar",Indent:"Aumentar recuo",Outdent:"Diminuir recuo","Ordered List":"Numeração","Unordered List":"Marcadores","Horizontal Rule":"Linha horizontal","Insert Image":"Inserir imagem","Insert Link":"Inserir hiperlink",Undo:"Desfazer",Redo:"Refazer","Show Source":"Mostrar fonte","Size 1":"Tamanho 1","Size 2":"Tamanho 2","Size 3":"Tamanho 3","Size 4":"Tamanho 4","Size 5":"Tamanho 5","Size 6":"Tamanho 6","Size 7":"Tamanho 7","Input image URL":"Insira a URL da imagem","Input link URL or E-mail address":"Insira uma URL ou endereço de e-mail",Preview:"Pré-visualização",Insert:"Inserir",Unlink:"Remover hiperlink"},pt:{Font:"Tipo de letra",Size:"Tamanho",Bold:"Negrito",Italic:"Itálico",Underline:"Sublinhado","Strike-Through":"Rasurado","Remove Format":"Remover formatação","Foreground Color":"Cor do tipo de letra","Background Color":"Realçar",Superscript:"Sobrescrito",Subscript:"Subscrito","Justify Left":"Alinhar à esquerda","Justify Center":"Centrar horizontalmente","Justify Right":"Alinhar à direita","Justify Full":"Justificado",Indent:"Aumentar avanço",Outdent:"Diminuir avanço","Ordered List":"Numeração","Unordered List":"Marcas","Horizontal Rule":"Linha horizontal","Insert Image":"Inserir imagem","Insert Link":"Inserir hiperligação",Undo:"Anular",Redo:"Refazer","Show Source":"Mostrar código-fonte","Size 1":"Tamanho 1","Size 2":"Tamanho 2","Size 3":"Tamanho 3","Size 4":"Tamanho 4","Size 5":"Tamanho 5","Size 6":"Tamanho 6","Size 7":"Tamanho 7","Input image URL":"Insira a URL da imagem","Input link URL or E-mail address":"Insira uma URL ou endereço de correio eletrónico",Preview:"Pré-visualização",Insert:"Inserir",Unlink:"Remover hiperligação"}},n=function(){var t=e().toLowerCase(),n=a[t];return n!==r?n:(t=t.split("-")[0],(n=a[t])!==r?n:{})}();return function(e){return n[e]===r?e:n[e]}}(),i=function(){var e=/^[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~](\.?[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~])*@([\w\-]+\.)+(\w+)$/;return function(t){return!(t.length>256)&&(!(t.indexOf("@")>64)&&null!==t.match(e))}}(),o=function(){var e=/^https?:\/\//;return function(t){return null!==t.match(e)}}(),c=function(){var t={NORMAL:0,ACTIVE:1,DISABLED:2},a={FONTNAME:"fontname",FONTSIZE:"fontsize",BOLD:"bold",ITALIC:"italic",UNDERLINE:"underline",STRIKETHROUGH:"strikethrough",REMOVEFORMAT:"removeformat",FORECOLOR:"forecolor",BACKCOLOR:"backcolor",HILITECOLOR:"hilitecolor",SUPERSCRIPT:"superscript",SUBSCRIPT:"subscript",JUSTIFYLEFT:"justifyleft",JUSTIFYCENTER:"justifycenter",JUSTIFYRIGHT:"justifyright",JUSTIFYFULL:"justifyfull",INDENT:"indent",OUTDENT:"outdent",ORDEREDLIST:"insertorderedlist",UNORDEREDLIST:"insertunorderedlist",INSERTHORIZONTALRULE:"inserthorizontalrule",INSERTIMAGE:"insertimage",CREATELINK:"createlink",UNLINK:"unlink",UNDO:"undo",REDO:"redo"};return function(n,i,o){function c(e,t){e===a.BACKCOLOR&&s(a.HILITECOLOR)&&(e=a.HILITECOLOR),p(),R.execCommand(e,!1,t)}function s(e){try{return R.queryCommandEnabled(e)}catch(e){return!1}}function l(){var e=R.body.innerHTML;return e=e.replace(/(<\/?)p\b/gi,"$1div").replace(/(<\/?)em\b/gi,"$1i").replace(/(<\/?)strong\b/gi,"$1b").replace(/(<\/?)del\b/gi,"$1s")}function d(e){R.body.innerHTML=e}function u(e){R.open(),R.write(e),R.close()}function f(){return C.getSelection?C.getSelection().anchorNode:R.selection.createRange().parentElement()}function m(){if(C.getSelection){var e=C.getSelection();return null===e||0===e.rangeCount?"":e.getRangeAt(0).toString()}return R.selection.createRange().text}function p(){C.focus(),null!==I&&I.select()}var C=n.contentWindow,R=C.document;n.contentDocument&&(R=n.contentDocument);var I=null;this.STATUS=t,this.COMMAND=a,this.contentWindow=C,this.contentDocument=R,this.getCurrentStatus=function(){var n={fontname:null,fontsize:null,forecolor:null,backcolor:null,bold:t.NORMAL,italic:t.NORMAL,underline:t.NORMAL,strikethrough:t.NORMAL,superscript:t.NORMAL,subscript:t.NORMAL,justifyleft:t.NORMAL,justifycenter:t.NORMAL,justifyright:t.NORMAL,justifyfull:t.NORMAL,insertorderedlist:t.NORMAL,insertunorderedlist:t.NORMAL,createlink:t.NORMAL,unlink:t.NORMAL,undo:t.NORMAL,redo:t.NORMAL};""===m()&&(n[a.CREATELINK]=t.DISABLED,n[a.UNLINK]=t.DISABLED),e.each([a.CREATELINK,a.UNLINK,a.UNDO,a.REDO],function(e,r){s(r)||(n[r]=t.DISABLED)});for(var i=f();null!==i;){if(i.tagName!==r)switch(i.tagName.toLowerCase()){case"b":case"strong":n[a.BOLD]=t.ACTIVE;break;case"i":case"em":n[a.ITALIC]=t.ACTIVE;break;case"u":n[a.UNDERLINE]=t.ACTIVE;break;case"s":case"strike":case"del":n[a.STRIKETHROUGH]=t.ACTIVE;break;case"sup":n[a.SUPERSCRIPT]=t.ACTIVE;break;case"sub":n[a.SUBSCRIPT]=t.ACTIVE;break;case"ol":n[a.ORDEREDLIST]=t.ACTIVE;break;case"ul":n[a.UNORDEREDLIST]=t.ACTIVE;break;case"font":i.face.length>0&&null===n[a.FONTNAME]&&(n[a.FONTNAME]=i.face),i.size.length>0&&null===n[a.FONTSIZE]&&(n[a.FONTSIZE]=i.size),i.color.length>0&&null===n[a.FORECOLOR]&&(n[a.FORECOLOR]=i.color)}if(i.align!==r)switch(i.align.toLowerCase()){case"left":n[a.JUSTIFYLEFT]=t.ACTIVE;break;case"center":n[a.JUSTIFYCENTER]=t.ACTIVE;break;case"right":n[a.JUSTIFYRIGHT]=t.ACTIVE;break;case"justify":n[a.JUSTIFYFULL]=t.ACTIVE}if(i.style!==r){var o=i.style;if(o.fontFamily!==r){var c=o.fontFamily;c.length>0&&null===n[a.FONTNAME]&&(n[a.FONTNAME]=c)}if(o.fontWeight!==r)switch(o.fontWeight.toLowerCase()){case"bold":case"bolder":n[a.BOLD]=t.ACTIVE}if(o.fontStyle!==r)switch(o.fontStyle.toLowerCase()){case"italic":case"oblique":n[a.ITALIC]=t.ACTIVE}if(o.textDecoration!==r){var l=o.textDecoration.toLowerCase();-1!==l.indexOf("underline")&&(n[a.UNDERLINE]=t.ACTIVE),-1!==l.indexOf("line-through")&&(n[a.STRIKETHROUGH]=t.ACTIVE)}if(o.color!==r){var d=o.color;d.length>0&&null===n[a.FORECOLOR]&&(n[a.FORECOLOR]=d)}if(o.backgroundColor!==r){var u=o.backgroundColor;u.length>0&&null===n[a.BACKCOLOR]&&(n[a.BACKCOLOR]=u)}if(o.verticalAlign!==r)switch(o.verticalAlign.toLowerCase()){case"super":n[a.SUPERSCRIPT]=t.ACTIVE;break;case"sub":n[a.SUBSCRIPT]=t.ACTIVE}if(o.textAlign!==r)switch(o.textAlign.toLowerCase()){case"left":n[a.JUSTIFYLEFT]=t.ACTIVE;break;case"center":n[a.JUSTIFYCENTER]=t.ACTIVE;break;case"right":n[a.JUSTIFYRIGHT]=t.ACTIVE;break;case"justify":n[a.JUSTIFYFULL]=t.ACTIVE}}i=i.parentNode}return R.selection&&(I=R.selection.createRange()),n},this.execCommand=c,this.canExecCommand=s,this.value=function(e){if(e===r)return l();d(e)},this.getSelectedText=m,this.insertText=function(e,t){if(C.getSelection){var r=R.createTextNode(e),n=C.getSelection();n.deleteFromDocument(),n.getRangeAt(0).insertNode(r)}else R.selection.createRange().text=e;t?c(a.REMOVEFORMAT):p()},this.setFocus=p,function(e){var t='
";R.designMode="on",u(t),d(e)}(i)}}();return e.fn.extend({cazary:function(e){function s(t){"string"==typeof t&&(t=m[t]!==r?m[t]:[t]);var a=e("
").addClass("cazary-commands-wrapper");return e.each(t,function(){var t=e("
").addClass("cazary-commands-list"),i=this.toLowerCase().split(" ");e.each(i,function(){var a=this.toString();if("|"===a&&(a="separator"),u[a]!==r){var i=n(u[a]),o="cazary-command-"+a,c=e("
").attr({unselectable:"on",title:i}).addClass(o).text(i);t.append(c)}}),a.append(t)}),a}function l(){e(".cazary-panel").each(function(){var t=e(this).data("command");e(".cazary-command-"+t).removeClass("cazary-active")}).remove()}var d={ENTER:13,ESCAPE:27},u={separator:"",fontname:"Font",fontsize:"Size",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strike-Through",removeformat:"Remove Format",forecolor:"Foreground Color",backcolor:"Background Color",superscript:"Superscript",subscript:"Subscript",justifyleft:"Justify Left",justifycenter:"Justify Center",justifyright:"Justify Right",justifyfull:"Justify Full",indent:"Indent",outdent:"Outdent",insertorderedlist:"Ordered List",insertunorderedlist:"Unordered List",inserthorizontalrule:"Horizontal Rule",insertimage:"Insert Image",createlink:"Insert Link",unlink:"Unlink",undo:"Undo",redo:"Redo",source:"Show Source"},f={1:"Size 1",2:"Size 2",3:"Size 3",4:"Size 4",5:"Size 5",6:"Size 6",7:"Size 7"},m={MINIMAL:["bold italic underline strikethrough removeformat"],STANDARD:["fontname fontsize","bold italic underline strikethrough removeformat | forecolor backcolor | superscript subscript","source"],FULL:["fontname fontsize","bold italic underline strikethrough removeformat | forecolor backcolor | superscript subscript","justifyleft justifycenter justifyright justifyfull | indent outdent | insertorderedlist insertunorderedlist","inserthorizontalrule insertimage createlink unlink","undo redo","source"]};return e(function(e){e(a).bind("click",function(){l()}).bind("keydown",function(e){e.keyCode===d.ESCAPE&&l()})}),function(u){return u=e.extend({mode:"rte",style:"body{margin:0px;padding:8px;}p{margin:0px;padding:0px;}",fontnames:["sans-serif","serif","cursive","fantasy","monospace","Arial","Arial Black","Comic Sans MS","Courier New","Narrow","Garamond","Georgia","Impact","Tahoma","Times New Roman","Trebuchet MS","Verdana"],colors:[["#ffffff","#ffcccc","#ffcc99","#ffff99","#ffffcc","#99ff99","#99ffff","#ccffff","#ccccff","#ffccff"],["#cccccc","#ff6666","#ff9966","#ffff66","#ffff33","#66ff99","#33ffff","#66ffff","#9999ff","#ff99ff"],["#bbbbbb","#ff0000","#ff9900","#ffcc66","#ffff00","#33ff33","#66cccc","#33ccff","#6666cc","#cc66cc"],["#999999","#cc0000","#ff6600","#ffcc33","#ffcc00","#33cc00","#00cccc","#3366ff","#6633ff","#cc33cc"],["#666666","#990000","#cc6600","#cc9933","#999900","#009900","#339999","#3333ff","#6600cc","#993399"],["#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366"],["#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"]],commands:"STANDARD"},u),this.each(function(){function m(e,t){l(),D.execCommand(e,t),E()}function p(){z.hide(),b.css("display",""),k.removeClass("cazary-disabled"),M.removeClass("cazary-active"),E()}function C(){var e=D.value();z.val(e),b.hide(),z.css("display",""),k.addClass("cazary-disabled"),M.addClass("cazary-active")}function R(){I()?p():C()}function I(){return M.hasClass("cazary-active")}function h(t,r,n){var i=e(".cazary-panel");if(i.length>0){var o=i.data("id"),c=i.data("command");if(l(),c===t&&o===A)return void L()}var s=!1;switch(t){case D.COMMAND.FONTNAME:i=g(t,r.fontnames),s=!0;break;case D.COMMAND.FONTSIZE:i=y(t),s=!0;break;case D.COMMAND.FORECOLOR:case D.COMMAND.BACKCOLOR:i=S(t,r.colors),s=!0;break;case D.COMMAND.INSERTIMAGE:i=T(t);break;case D.COMMAND.CREATELINK:i=O(t);break;default:return null}s&&i.find("li").bind("click",function(){var r=e(this).data("param");m(t,r)});var d=n.addClass("cazary-active").offset();return d.top+=n.outerHeight(),i.addClass("cazary-panel").addClass("cazary-panel-"+t).data("id",A).data("command",t).css({left:d.left+"px",top:d.top+"px"}).bind("click",function(){return!1}).appendTo(e(a.body)).find(":text:first").trigger("focus"),i}function g(t,r){var a=e("
").addClass("cazary-widget-select");return e.each(r,function(){var t=this.toString(),r=e("
").attr({unselectable:"on",title:t}).css({"font-family":t}).data("param",t).text(t);a.append(r)}),e("
").append(a)}function y(t){var r=e("
").addClass("cazary-widget-select");return e.each(f,function(t,a){var i=n(a),o=e("
").attr({unselectable:"on",title:i}).data("param",t),c=e("
").attr({size:t}).text(a);r.append(o.append(c))}),e("
").append(r)}function S(t,r){var a=e("
");return e.each(r,function(){var t=e("
").addClass("cazary-widget-select-color");e.each(this,function(){var r=this.toString(),a=e("
").attr({unselectable:"on",title:r}).css({"background-color":r}).data("param",r).text(r);t.append(a)}),a.append(t)}),a}function T(r){function a(){var e=i.find(".cazary-widget-insertimage-url"),t=e.val();return o(t)?(m(r,t),!1):(e.trigger("focus"),!1)}var i=e("
").append(e("
").attr("action","#").append(e("
").append(e("
").append(e("
").text(n("Input image URL"))).append(e('
').addClass("cazary-widget-insertimage-url").attr({required:"required",placeholder:n("http://example.com/path/to/image.jpg")}))).append(e('
').addClass("cazary-widget-submit").val(n("Insert")))).append(e("
").addClass("cazary-widget-preview").append(e("
").text(n("Preview"))).append(e("
![]()
").addClass("cazary-widget-preview-insertimage"))));return i.find("form").bind("submit",a),i.find(".cazary-widget-submit").bind("click",a),i.find(".cazary-widget-insertimage-url").bind("keydown paste",function(){var r=e(this);t.setTimeout(function(){var e=r.val();if(e!==r.data("url_old")){r.data("url_old",e);var t=i.find(".cazary-widget-preview");o(e)?(t.show(),i.find(".cazary-widget-preview-insertimage").attr("src",e)):t.hide()}},10)}),i}function O(r){function a(){var e=c.find(".cazary-widget-createlink-url"),t=e.val();if(i(t))t="mailto:"+t;else if(!o(t))return e.trigger("focus"),!1;return m(r,t),!1}var c=e("
").append(e("
").attr("action","#").append(e("
").append(e("
").append(e("
").text(n("Input link URL or E-mail address"))).append(e('
').addClass("cazary-widget-createlink-url").attr({required:"required",placeholder:n("http://example.com/, someone@example.com")}))).append(e('
').addClass("cazary-widget-submit").val(n("Insert")))).append(e("
").addClass("cazary-widget-preview").append(e("
").text(n("Preview"))).append(e("
").addClass("cazary-widget-preview-createlink"))));return c.find("form").bind("submit",a),c.find(".cazary-widget-submit").bind("click",a),c.find(".cazary-widget-createlink-url").bind("keydown paste",function(){var r=e(this);t.setTimeout(function(){var e=r.val();if(e!==r.data("url_old")){r.data("url_old",e);var t=c.find(".cazary-widget-preview");o(e)?(t.show(),c.find(".cazary-widget-preview-createlink").attr("src",e)):t.hide()}},10)}),c}function E(){var e=D.getCurrentStatus();for(var t in e){var r=e[t],a=N.find(".cazary-command-"+t);if(t!==D.COMMAND.FONTNAME)if(t!==D.COMMAND.FONTSIZE)if(t!==D.COMMAND.FORECOLOR&&t!==D.COMMAND.BACKCOLOR)r===D.STATUS.ACTIVE?a.addClass("cazary-active"):a.removeClass("cazary-active"),r===D.STATUS.DISABLED?a.addClass("cazary-disabled"):a.removeClass("cazary-disabled");else{var i=N.find(".cazary-command-"+t),o=null===r?"":r;i.css("background-color",o)}else{var c=r;null===c?(r="",c=a.attr("title")):c=n(f[c]),a.text(c)}else{var s=r;null===s&&(r="",s=a.attr("title")),a.css({"font-family":r}).text(s)}}}function L(){I()?z.trigger("focus"):D.setFocus()}function v(){var t=e(D.contentDocument.body);0===t.text().length?t.addClass("empty"):t.removeClass("empty")}var A=parseInt(1e4*Math.random()),z=e(this),N=e('
').css({width:z.width()});N.prepend(s(u.commands));var b=N.find(".cazary-edit").css({height:z.height()}),M=N.find("ul.cazary-commands-list li.cazary-command-source"),k=N.find("ul.cazary-commands-list li:not(.cazary-command-source)");z.hide().before(N).insertAfter(b).addClass("cazary-source");var w=u.style,U=z.attr("placeholder");U!==r&&(w+="body.empty:before{position:fixed;color:#888;content:'"+(U=U.replace("'","\\'"))+"';}");var D=new c(b.get(0),z.val(),w),F=[D.COMMAND.BOLD,D.COMMAND.ITALIC,D.COMMAND.UNDERLINE,D.COMMAND.STRIKETHROUGH,D.COMMAND.REMOVEFORMAT,D.COMMAND.SUPERSCRIPT,D.COMMAND.SUBSCRIPT,D.COMMAND.JUSTIFYLEFT,D.COMMAND.JUSTIFYCENTER,D.COMMAND.JUSTIFYRIGHT,D.COMMAND.JUSTIFYFULL,D.COMMAND.INDENT,D.COMMAND.OUTDENT,D.COMMAND.ORDEREDLIST,D.COMMAND.UNORDEREDLIST,D.COMMAND.INSERTHORIZONTALRULE,D.COMMAND.UNLINK,D.COMMAND.UNDO,D.COMMAND.REDO],x=[D.COMMAND.FONTNAME,D.COMMAND.FONTSIZE,D.COMMAND.FORECOLOR,D.COMMAND.BACKCOLOR,D.COMMAND.INSERTIMAGE,D.COMMAND.CREATELINK];"html"===u.mode?C():p(),z.on("change",function(){var t=e(this).val();D.value(t),v()}),e(D.contentDocument).bind("select",function(){E()}).bind("mouseup",function(){l(),E()}).bind("keydown",function(e){e.keyCode===d.ESCAPE&&l()}).bind("keyup paste",function(){t.setTimeout(function(){E(),v()},10)}),e(D.contentWindow).bind("focus",function(){l(),E()}).bind("blur",function(){z.val(D.value())}),N.find("ul.cazary-commands-list li").bind("click",function(t){e(this).hasClass("cazary-disabled")&&(t.stopImmediatePropagation(),L())}),M.bind("click",function(){R(),L()}),e.each(F,function(){var e=this.toLowerCase();N.find(".cazary-command-"+e).bind("click",function(){m(e)})}),e.each(x,function(){var t=this.toLowerCase();N.find(".cazary-command-"+t).bind("click",function(){var r=e(this);return h(t,u,r),!1})})})}}(e)}),e});
--------------------------------------------------------------------------------
/src/themes/flat/sprite.svg:
--------------------------------------------------------------------------------
1 |
2 |
299 |
--------------------------------------------------------------------------------
/src/themes/flat/sprite.orig.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
941 |
--------------------------------------------------------------------------------
/src/cazary.es6:
--------------------------------------------------------------------------------
1 | /*! Cazary (jQuery 1.7+) - JavaScript WYSIWYG editor (https://github.com/shimataro/cazary) */
2 | (function(factory)
3 | {
4 | if(typeof module === "object" && typeof module.exports === "object")
5 | {
6 | module.exports = factory(require("jquery"), window);
7 | }
8 | else
9 | {
10 | factory(jQuery, window);
11 | }
12 | }
13 | (function($, window, undefined)
14 | {
15 | "use strict";
16 | const document = window.document;
17 |
18 | /**
19 | * simplified translation function that can be used just like GNU gettext
20 | * @function
21 | * @param {String} text: text to be translated
22 | * @return: {String} translated text
23 | */
24 | const _ = (function()
25 | {
26 | // NOTE: below placeholder will be replaced by real data in gulp task.
27 | const translation_data = {/*@TRANSLATION_DATA@*/};
28 | const current_translation_data = _getCurrentTranslationData();
29 |
30 | return function(text)
31 | {
32 | if(current_translation_data[text] === undefined)
33 | {
34 | return text;
35 | }
36 | return current_translation_data[text];
37 | };
38 |
39 | function _getCurrentTranslationData()
40 | {
41 | let language = _detectBrowserLanguage().toLowerCase();
42 | let result = translation_data[language];
43 | if(result !== undefined)
44 | {
45 | return result;
46 | }
47 |
48 | // 'en-us' -> 'en'
49 | language = language.split('-')[0];
50 | result = translation_data[language];
51 | if(result !== undefined)
52 | {
53 | return result;
54 | }
55 |
56 | return {};
57 | }
58 |
59 | /**
60 | * @see http://blog.masuidrive.jp/index.php/2008/09/19/how-to-detect-your-browser-language-from-javascript/
61 | */
62 | function _detectBrowserLanguage()
63 | {
64 | try
65 | {
66 | const navigator = window.navigator;
67 | return (navigator.browserLanguage || navigator.language || navigator.userLanguage);
68 | }
69 | catch(e)
70 | {
71 | return undefined;
72 | }
73 | }
74 | })();
75 |
76 | /**
77 | * validate email
78 | * @function
79 | * @param {String} string: email
80 | * @return: {Boolean} OK/NG
81 | */
82 | const checkEmail = (function()
83 | {
84 | const regexp = /^[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~](\.?[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~])*@([\w\-]+\.)+(\w+)$/;
85 |
86 | return function(string)
87 | {
88 | if(string.length > 256)
89 | {
90 | // length is up to 256 characters(cf. RFC 5321 4.5.3.1.3.)
91 | return false;
92 | }
93 | if(string.indexOf("@") > 64)
94 | {
95 | // length of local part is up to 64 characters(cf. RFC 5321 4.5.3.1.1.)
96 | return false;
97 | }
98 | if(string.match(regexp) === null)
99 | {
100 | return false;
101 | }
102 | return true;
103 | };
104 | })();
105 |
106 | /**
107 | * validate URL
108 | * @function
109 | * @param {String} string: URL
110 | * @return: {Boolean} OK/NG
111 | */
112 | const checkURL = (function()
113 | {
114 | const regexp = /^https?:\/\//;
115 |
116 | return function(string)
117 | {
118 | if(string.match(regexp) === null)
119 | {
120 | return false;
121 | }
122 | return true;
123 | };
124 | })();
125 |
126 | /**
127 | * Editor Component
128 | * @class
129 | */
130 | const EditorCore = (function()
131 | {
132 | const STATUS = {
133 | NORMAL: 0,
134 | ACTIVE: 1,
135 | DISABLED: 2,
136 | };
137 |
138 | const COMMAND = {
139 | FONTNAME : "fontname",
140 | FONTSIZE : "fontsize",
141 | BOLD : "bold",
142 | ITALIC : "italic",
143 | UNDERLINE : "underline",
144 | STRIKETHROUGH : "strikethrough",
145 | REMOVEFORMAT : "removeformat",
146 | FORECOLOR : "forecolor",
147 | BACKCOLOR : "backcolor",
148 | HILITECOLOR : "hilitecolor",
149 | SUPERSCRIPT : "superscript",
150 | SUBSCRIPT : "subscript",
151 | JUSTIFYLEFT : "justifyleft",
152 | JUSTIFYCENTER : "justifycenter",
153 | JUSTIFYRIGHT : "justifyright",
154 | JUSTIFYFULL : "justifyfull",
155 | INDENT : "indent",
156 | OUTDENT : "outdent",
157 | ORDEREDLIST : "insertorderedlist",
158 | UNORDEREDLIST : "insertunorderedlist",
159 | INSERTHORIZONTALRULE: "inserthorizontalrule",
160 | INSERTIMAGE : "insertimage",
161 | CREATELINK : "createlink",
162 | UNLINK : "unlink",
163 | UNDO : "undo",
164 | REDO : "redo",
165 | };
166 |
167 | return function(edit, value, style)
168 | {
169 | // init
170 | let contentWindow = edit.contentWindow;
171 | let contentDocument = contentWindow.document;
172 | if(edit.contentDocument)
173 | {
174 | // if contentDocument exists, W3C compliant
175 | contentDocument = edit.contentDocument;
176 | }
177 |
178 | // TextRange object (selected range for IE)
179 | let range = null;
180 |
181 | // public properties
182 | this.STATUS = STATUS;
183 | this.COMMAND = COMMAND;
184 |
185 | this.contentWindow = contentWindow;
186 | this.contentDocument = contentDocument;
187 |
188 | // public methods
189 | this.getCurrentStatus = _getCurrentStatus;
190 | this.execCommand = _execCommand;
191 | this.canExecCommand = _canExecCommand;
192 | this.value = _value;
193 | this.getSelectedText = _getSelectedText;
194 | this.insertText = _insertText;
195 | this.setFocus = _setFocus;
196 |
197 | // construction
198 | _construct(value);
199 |
200 | function _construct(value)
201 | {
202 | /*
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 | */
212 | const iframehtml = `
`;
213 |
214 | // contentDocument.body.contentEditable = true;
215 | contentDocument.designMode = "on";
216 |
217 | _setHTML(iframehtml);
218 | _setValue(value);
219 | }
220 |
221 | function _execCommand(commandName, parameters)
222 | {
223 | // if browser supports "hilitecolor", use it.
224 | if(commandName === COMMAND.BACKCOLOR && _canExecCommand(COMMAND.HILITECOLOR))
225 | {
226 | commandName = COMMAND.HILITECOLOR;
227 | }
228 |
229 | _setFocus();
230 | contentDocument.execCommand(commandName, false, parameters);
231 | }
232 | function _canExecCommand(commandName)
233 | {
234 | try
235 | {
236 | return contentDocument.queryCommandEnabled(commandName);
237 | }
238 | catch(e)
239 | {
240 | return false;
241 | }
242 | }
243 |
244 | function _value(value)
245 | {
246 | if(value === undefined)
247 | {
248 | return _getValue();
249 | }
250 | else
251 | {
252 | _setValue(value);
253 | }
254 | }
255 |
256 | function _getValue()
257 | {
258 | let html = contentDocument.body.innerHTML;
259 |
260 | // replace tags
261 | html = html
262 | .replace(/(<\/?)p\b/gi, "$1div")
263 | .replace(/(<\/?)em\b/gi, "$1i")
264 | .replace(/(<\/?)strong\b/gi, "$1b")
265 | .replace(/(<\/?)del\b/gi, "$1s")
266 | ;
267 | return html;
268 | }
269 | function _setValue(value)
270 | {
271 | contentDocument.body.innerHTML = value;
272 | }
273 | function _setHTML(html)
274 | {
275 | contentDocument.open();
276 | contentDocument.write(html);
277 | contentDocument.close();
278 | }
279 |
280 | function _getCurrentStatus()
281 | {
282 | const result = {
283 | fontname: null,
284 | fontsize: null,
285 |
286 | forecolor: null,
287 | backcolor: null,
288 |
289 | bold : STATUS.NORMAL,
290 | italic : STATUS.NORMAL,
291 | underline : STATUS.NORMAL,
292 | strikethrough: STATUS.NORMAL,
293 |
294 | superscript: STATUS.NORMAL,
295 | subscript : STATUS.NORMAL,
296 |
297 | justifyleft : STATUS.NORMAL,
298 | justifycenter: STATUS.NORMAL,
299 | justifyright : STATUS.NORMAL,
300 | justifyfull : STATUS.NORMAL,
301 |
302 | insertorderedlist : STATUS.NORMAL,
303 | insertunorderedlist: STATUS.NORMAL,
304 |
305 | createlink: STATUS.NORMAL,
306 | unlink : STATUS.NORMAL,
307 |
308 | undo: STATUS.NORMAL,
309 | redo: STATUS.NORMAL,
310 | };
311 | if(_getSelectedText() === "")
312 | {
313 | result[COMMAND.CREATELINK] = STATUS.DISABLED;
314 | result[COMMAND.UNLINK ] = STATUS.DISABLED;
315 | }
316 | $.each([COMMAND.CREATELINK, COMMAND.UNLINK, COMMAND.UNDO, COMMAND.REDO], function(index, value)
317 | {
318 | if(!_canExecCommand(value))
319 | {
320 | result[value] = STATUS.DISABLED;
321 | }
322 | });
323 |
324 | let node = _getCurrentNode();
325 | while(node !== null)
326 | {
327 | // check tag
328 | if(node.tagName !== undefined)
329 | {
330 | const tagName = node.tagName.toLowerCase();
331 | switch(tagName)
332 | {
333 | case "b":
334 | case "strong":
335 | result[COMMAND.BOLD] = STATUS.ACTIVE;
336 | break;
337 |
338 | case "i":
339 | case "em":
340 | result[COMMAND.ITALIC] = STATUS.ACTIVE;
341 | break;
342 |
343 | case "u":
344 | result[COMMAND.UNDERLINE] = STATUS.ACTIVE;
345 | break;
346 |
347 | case "s":
348 | case "strike":
349 | case "del":
350 | result[COMMAND.STRIKETHROUGH] = STATUS.ACTIVE;
351 | break;
352 |
353 | case "sup":
354 | result[COMMAND.SUPERSCRIPT] = STATUS.ACTIVE;
355 | break;
356 |
357 | case "sub":
358 | result[COMMAND.SUBSCRIPT] = STATUS.ACTIVE;
359 | break;
360 |
361 | case "ol":
362 | result[COMMAND.ORDEREDLIST] = STATUS.ACTIVE;
363 | break;
364 |
365 | case "ul":
366 | result[COMMAND.UNORDEREDLIST] = STATUS.ACTIVE;
367 | break;
368 |
369 | case "font":
370 | if(node.face.length > 0 && result[COMMAND.FONTNAME] === null)
371 | {
372 | result[COMMAND.FONTNAME] = node.face;
373 | }
374 | if(node.size.length > 0 && result[COMMAND.FONTSIZE] === null)
375 | {
376 | result[COMMAND.FONTSIZE] = node.size;
377 | }
378 | if(node.color.length > 0 && result[COMMAND.FORECOLOR] === null)
379 | {
380 | result[COMMAND.FORECOLOR] = node.color;
381 | }
382 | break;
383 | }
384 | }
385 |
386 | // check general attributes
387 | if(node.align !== undefined)
388 | {
389 | const align = node.align.toLowerCase();
390 | switch(align)
391 | {
392 | case "left":
393 | result[COMMAND.JUSTIFYLEFT] = STATUS.ACTIVE;
394 | break;
395 |
396 | case "center":
397 | result[COMMAND.JUSTIFYCENTER] = STATUS.ACTIVE;
398 | break;
399 |
400 | case "right":
401 | result[COMMAND.JUSTIFYRIGHT] = STATUS.ACTIVE;
402 | break;
403 |
404 | case "justify":
405 | result[COMMAND.JUSTIFYFULL] = STATUS.ACTIVE;
406 | break;
407 | }
408 | }
409 |
410 | // check CSS
411 | if(node.style !== undefined)
412 | {
413 | const style = node.style;
414 | if(style.fontFamily !== undefined)
415 | {
416 | const fontFamily = style.fontFamily;
417 | if(fontFamily.length > 0 && result[COMMAND.FONTNAME] === null)
418 | {
419 | result[COMMAND.FONTNAME] = fontFamily;
420 | }
421 | }
422 |
423 | if(style.fontWeight !== undefined)
424 | {
425 | const fontWeight = style.fontWeight.toLowerCase();
426 | switch(fontWeight)
427 | {
428 | case "bold":
429 | case "bolder":
430 | result[COMMAND.BOLD] = STATUS.ACTIVE;
431 | break;
432 | }
433 | }
434 |
435 | if(style.fontStyle !== undefined)
436 | {
437 | const fontStyle = style.fontStyle.toLowerCase();
438 | switch(fontStyle)
439 | {
440 | case "italic":
441 | case "oblique":
442 | result[COMMAND.ITALIC] = STATUS.ACTIVE;
443 | break;
444 | }
445 | }
446 |
447 | if(style.textDecoration !== undefined)
448 | {
449 | const textDecoration = style.textDecoration.toLowerCase();
450 | if(textDecoration.indexOf("underline") !== -1)
451 | {
452 | result[COMMAND.UNDERLINE] = STATUS.ACTIVE;
453 | }
454 | if(textDecoration.indexOf("line-through") !== -1)
455 | {
456 | result[COMMAND.STRIKETHROUGH] = STATUS.ACTIVE;
457 | }
458 | }
459 |
460 | if(style.color !== undefined)
461 | {
462 | const color = style.color;
463 | if(color.length > 0 && result[COMMAND.FORECOLOR] === null)
464 | {
465 | result[COMMAND.FORECOLOR] = color;
466 | }
467 | }
468 |
469 | if(style.backgroundColor !== undefined)
470 | {
471 | const color = style.backgroundColor;
472 | if(color.length > 0 && result[COMMAND.BACKCOLOR] === null)
473 | {
474 | result[COMMAND.BACKCOLOR] = color;
475 | }
476 | }
477 |
478 | if(style.verticalAlign !== undefined)
479 | {
480 | const verticalAlign = style.verticalAlign.toLowerCase();
481 | switch(verticalAlign)
482 | {
483 | case "super":
484 | result[COMMAND.SUPERSCRIPT] = STATUS.ACTIVE;
485 | break;
486 |
487 | case "sub":
488 | result[COMMAND.SUBSCRIPT] = STATUS.ACTIVE;
489 | break;
490 | }
491 | }
492 |
493 | // block
494 | if(style.textAlign !== undefined)
495 | {
496 | const textAlign = style.textAlign.toLowerCase();
497 | switch(textAlign)
498 | {
499 | case "left":
500 | result[COMMAND.JUSTIFYLEFT] = STATUS.ACTIVE;
501 | break;
502 |
503 | case "center":
504 | result[COMMAND.JUSTIFYCENTER] = STATUS.ACTIVE;
505 | break;
506 |
507 | case "right":
508 | result[COMMAND.JUSTIFYRIGHT] = STATUS.ACTIVE;
509 | break;
510 |
511 | case "justify":
512 | result[COMMAND.JUSTIFYFULL] = STATUS.ACTIVE;
513 | break;
514 | }
515 | }
516 | }
517 |
518 | node = node.parentNode;
519 | }
520 |
521 | // save selected range for IE
522 | if(contentDocument.selection)
523 | {
524 | range = contentDocument.selection.createRange();
525 | }
526 |
527 | return result;
528 | }
529 |
530 | function _getCurrentStyle()
531 | {
532 | const node = _getCurrentNode();
533 | if(node === null)
534 | {
535 | return null;
536 | }
537 | return node.currentStyle || contentDocument.defaultView.getComputedStyle(node.parentElement, "");
538 | }
539 |
540 | function _getCurrentNode()
541 | {
542 | if(contentWindow.getSelection)
543 | {
544 | return contentWindow.getSelection().anchorNode;
545 | }
546 | return contentDocument.selection.createRange().parentElement();
547 | }
548 |
549 | function _getSelectedText()
550 | {
551 | if(contentWindow.getSelection)
552 | {
553 | const selection = contentWindow.getSelection();
554 | if(selection === null || selection.rangeCount === 0)
555 | {
556 | return "";
557 | }
558 | return selection.getRangeAt(0).toString();
559 | }
560 | else
561 | {
562 | return contentDocument.selection.createRange().text;
563 | }
564 | }
565 |
566 | function _insertText(text, removeFormat)
567 | {
568 | if(contentWindow.getSelection)
569 | {
570 | const node = contentDocument.createTextNode(text);
571 | const selection = contentWindow.getSelection();
572 | selection.deleteFromDocument();
573 | selection.getRangeAt(0).insertNode(node);
574 | }
575 | else
576 | {
577 | contentDocument.selection.createRange().text = text;
578 | }
579 |
580 | if(removeFormat)
581 | {
582 | _execCommand(COMMAND.REMOVEFORMAT);
583 | }
584 | else
585 | {
586 | _setFocus();
587 | }
588 | }
589 |
590 | function _setFocus()
591 | {
592 | contentWindow.focus();
593 | if(range !== null)
594 | {
595 | range.select();
596 | }
597 | }
598 | };
599 | })();
600 |
601 | $.fn.extend(
602 | {
603 | cazary: (function($)
604 | {
605 | // keycodes
606 | const KEYCODE = {
607 | ENTER: 13,
608 | ESCAPE: 27,
609 | };
610 |
611 | /*
612 |
613 |
614 |
615 |
616 |
617 | */
618 | const CAZARY = '
';
619 |
620 | // command => name
621 | const ASSOC_COMMANDNAMES = {
622 | separator: "",
623 |
624 | fontname: "Font",
625 | fontsize: "Size",
626 |
627 | bold : "Bold",
628 | italic : "Italic",
629 | underline : "Underline",
630 | strikethrough: "Strike-Through",
631 | removeformat : "Remove Format",
632 |
633 | forecolor: "Foreground Color",
634 | backcolor: "Background Color",
635 |
636 | superscript: "Superscript",
637 | subscript : "Subscript",
638 |
639 | justifyleft : "Justify Left",
640 | justifycenter: "Justify Center",
641 | justifyright : "Justify Right",
642 | justifyfull : "Justify Full",
643 |
644 | indent : "Indent",
645 | outdent: "Outdent",
646 |
647 | insertorderedlist : "Ordered List",
648 | insertunorderedlist: "Unordered List",
649 |
650 | inserthorizontalrule: "Horizontal Rule",
651 | insertimage : "Insert Image",
652 | createlink : "Insert Link",
653 | unlink : "Unlink",
654 |
655 | undo: "Undo",
656 | redo: "Redo",
657 |
658 | source: "Show Source",
659 | };
660 | /* font sizes */
661 | const ASSOC_FONTSIZES = {
662 | 1: "Size 1",
663 | 2: "Size 2",
664 | 3: "Size 3",
665 | 4: "Size 4",
666 | 5: "Size 5",
667 | 6: "Size 6",
668 | 7: "Size 7",
669 | };
670 | /* pre-defined macros */
671 | const PRE_DEFINED_MACROS = {
672 | "MINIMAL" : ["bold italic underline strikethrough removeformat"],
673 | "STANDARD": [
674 | "fontname fontsize",
675 | "bold italic underline strikethrough removeformat | forecolor backcolor | superscript subscript",
676 | "source",
677 | ],
678 | "FULL": [
679 | "fontname fontsize",
680 | "bold italic underline strikethrough removeformat | forecolor backcolor | superscript subscript",
681 | "justifyleft justifycenter justifyright justifyfull | indent outdent | insertorderedlist insertunorderedlist",
682 | "inserthorizontalrule insertimage createlink unlink",
683 | "undo redo",
684 | "source",
685 | ],
686 | };
687 |
688 | $(function($)
689 | {
690 | // window events
691 | $(document)
692 | .on("click", function()
693 | {
694 | destroyAllPanels();
695 | })
696 | .on("keydown", function(event)
697 | {
698 | if(event.keyCode === KEYCODE.ESCAPE)
699 | {
700 | destroyAllPanels();
701 | }
702 | });
703 | });
704 |
705 | return function(options)
706 | {
707 | options = $.extend(
708 | {
709 | mode: "rte",
710 | style: "body{margin:0px;padding:8px;}p{margin:0px;padding:0px;}",
711 | fontnames: [
712 | "sans-serif", "serif", "cursive", "fantasy", "monospace",
713 | "Arial", "Arial Black", "Comic Sans MS", "Courier New", "Narrow", "Garamond",
714 | "Georgia", "Impact", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana",
715 | ],
716 | colors: [
717 | ["#ffffff", "#ffcccc", "#ffcc99", "#ffff99", "#ffffcc", "#99ff99", "#99ffff", "#ccffff", "#ccccff", "#ffccff"],
718 | ["#cccccc", "#ff6666", "#ff9966", "#ffff66", "#ffff33", "#66ff99", "#33ffff", "#66ffff", "#9999ff", "#ff99ff"],
719 | ["#bbbbbb", "#ff0000", "#ff9900", "#ffcc66", "#ffff00", "#33ff33", "#66cccc", "#33ccff", "#6666cc", "#cc66cc"],
720 | ["#999999", "#cc0000", "#ff6600", "#ffcc33", "#ffcc00", "#33cc00", "#00cccc", "#3366ff", "#6633ff", "#cc33cc"],
721 | ["#666666", "#990000", "#cc6600", "#cc9933", "#999900", "#009900", "#339999", "#3333ff", "#6600cc", "#993399"],
722 | ["#333333", "#660000", "#993300", "#996633", "#666600", "#006600", "#336666", "#000099", "#333399", "#663366"],
723 | ["#000000", "#330000", "#663300", "#663333", "#333300", "#003300", "#003333", "#000066", "#330099", "#330033"],
724 | ],
725 | commands: "STANDARD",
726 | },
727 | options);
728 |
729 | return this.each(function()
730 | {
731 | const uniqueId = parseInt(Math.random() * 10000);
732 | const $origin = $(this);
733 |
734 | // Cazary object
735 | const $cazary = $(CAZARY).css({width: $origin.width()});
736 | $cazary.prepend(createCommandsWrapper(options.commands));
737 |
738 | // editor object
739 | const $cazary_edit = $cazary.find(".cazary-edit").css({height: $origin.height()});
740 |
741 | // source command & others
742 | const $cazary_command_source = $cazary.find("ul.cazary-commands-list li.cazary-command-source");
743 | const $cazary_commands_except_source = $cazary.find("ul.cazary-commands-list li:not(.cazary-command-source)");
744 |
745 | // set objects
746 | $origin
747 | .hide()
748 | .before($cazary)
749 | .insertAfter($cazary_edit)
750 | .addClass("cazary-source")
751 | ;
752 |
753 | // add style for placeholder
754 | let style = options.style;
755 | let placeholder_text = $origin.attr("placeholder");
756 | if(placeholder_text !== undefined)
757 | {
758 | placeholder_text = placeholder_text.replace("'", "\\'");
759 | style += `body.empty:before{position:fixed;color:#888;content:'${placeholder_text}';}`;
760 | }
761 | const editor = new EditorCore($cazary_edit.get(0), $origin.val(), style);
762 |
763 | const commands_generic = [
764 | editor.COMMAND.BOLD, editor.COMMAND.ITALIC, editor.COMMAND.UNDERLINE, editor.COMMAND.STRIKETHROUGH, editor.COMMAND.REMOVEFORMAT,
765 | editor.COMMAND.SUPERSCRIPT, editor.COMMAND.SUBSCRIPT,
766 | editor.COMMAND.JUSTIFYLEFT, editor.COMMAND.JUSTIFYCENTER, editor.COMMAND.JUSTIFYRIGHT, editor.COMMAND.JUSTIFYFULL,
767 | editor.COMMAND.INDENT, editor.COMMAND.OUTDENT,
768 | editor.COMMAND.ORDEREDLIST, editor.COMMAND.UNORDEREDLIST,
769 | editor.COMMAND.INSERTHORIZONTALRULE, editor.COMMAND.UNLINK,
770 | editor.COMMAND.UNDO, editor.COMMAND.REDO,
771 | ];
772 | const commands_with_panel = [
773 | editor.COMMAND.FONTNAME, editor.COMMAND.FONTSIZE,
774 | editor.COMMAND.FORECOLOR, editor.COMMAND.BACKCOLOR,
775 | editor.COMMAND.INSERTIMAGE, editor.COMMAND.CREATELINK,
776 | ];
777 |
778 | if(options.mode === "html")
779 | {
780 | _setHtmlMode();
781 | }
782 | else
783 | {
784 | _setRteMode();
785 | }
786 |
787 | $origin
788 | .on("change", function()
789 | {
790 | // hook "change" event
791 | const value = $(this).val();
792 | editor.value(value);
793 |
794 | _setEmptyClass();
795 | });
796 |
797 | // editor events
798 | $(editor.contentDocument)
799 | .on("select", function()
800 | {
801 | _updateCommandStatus();
802 | })
803 | .on("mouseup", function()
804 | {
805 | destroyAllPanels();
806 | _updateCommandStatus();
807 | })
808 | .on("keydown", function(event)
809 | {
810 | if(event.keyCode === KEYCODE.ESCAPE)
811 | {
812 | destroyAllPanels();
813 | }
814 | })
815 | .on("keyup paste", function()
816 | {
817 | window.setTimeout(function()
818 | {
819 | _updateCommandStatus();
820 | _setEmptyClass();
821 | }, 10);
822 | });
823 |
824 | $(editor.contentWindow)
825 | .on("focus", function()
826 | {
827 | destroyAllPanels();
828 | _updateCommandStatus();
829 | })
830 | .on("blur", function()
831 | {
832 | // update original element when focus is out
833 | $origin.val(editor.value());
834 | });
835 |
836 | // cancel other handler when command is disabled
837 | $cazary
838 | .on("click", "ul.cazary-commands-list li", function(event)
839 | {
840 | const $target = $(this);
841 | if($target.hasClass("cazary-disabled"))
842 | {
843 | event.stopImmediatePropagation();
844 | _setFocus();
845 | }
846 | });
847 |
848 | // toggle RTE <-> HTML mode
849 | $cazary_command_source
850 | .on("click", function()
851 | {
852 | _toggleMode();
853 | _setFocus();
854 | });
855 |
856 | // command handler
857 | $.each(commands_generic, function()
858 | {
859 | const commandName = this.toLowerCase();
860 | $cazary
861 | .on("click", `.cazary-command-${commandName}`, function()
862 | {
863 | // execute command
864 | _execCommand(commandName);
865 | });
866 | });
867 | $.each(commands_with_panel, function()
868 | {
869 | const commandName = this.toLowerCase();
870 | $cazary
871 | .on("click", `.cazary-command-${commandName}`, function()
872 | {
873 | // open panel
874 | const $target = $(this);
875 | createPanel(commandName, options, $target);
876 | return false;
877 | });
878 | });
879 |
880 | function _execCommand(commandName, parameters)
881 | {
882 | destroyAllPanels();
883 | editor.execCommand(commandName, parameters);
884 | _updateCommandStatus();
885 | }
886 |
887 | function _setRteMode()
888 | {
889 | // set visibility
890 | $origin.hide();
891 | $cazary_edit.css("display", "");
892 |
893 | $cazary_commands_except_source.removeClass("cazary-disabled");
894 | $cazary_command_source.removeClass("cazary-active");
895 | _updateCommandStatus();
896 | }
897 |
898 | function _setHtmlMode()
899 | {
900 | const html = editor.value();
901 | $origin.val(html);
902 |
903 | $cazary_edit.hide();
904 | $origin.css("display", "");
905 |
906 | $cazary_commands_except_source.addClass("cazary-disabled");
907 | $cazary_command_source.addClass("cazary-active");
908 | }
909 |
910 | function _toggleMode()
911 | {
912 | if(_isHtmlMode())
913 | {
914 | // HTML -> RTE
915 | _setRteMode();
916 | }
917 | else
918 | {
919 | // RTE -> HTML
920 | _setHtmlMode();
921 | }
922 | }
923 |
924 | function _isHtmlMode()
925 | {
926 | return $cazary_command_source.hasClass("cazary-active");
927 | }
928 | function _isRteMode()
929 | {
930 | return !_isHtmlMode();
931 | }
932 |
933 | /**
934 | * create specified panel
935 | * @param {String} commandName: command name
936 | * @param {Object} options: options
937 | * @param {jQuery} $command: command object
938 | */
939 | function createPanel(commandName, options, $command)
940 | {
941 | let $panel = $(".cazary-panel");
942 | if($panel.length > 0)
943 | {
944 | const uniqueId_panel = $panel.data("id");
945 | const commandName_panel = $panel.data("command");
946 | destroyAllPanels();
947 | if(commandName_panel === commandName && uniqueId_panel === uniqueId)
948 | {
949 | _setFocus();
950 | return;
951 | }
952 | }
953 |
954 | let list = false;
955 | switch(commandName)
956 | {
957 | case editor.COMMAND.FONTNAME:
958 | $panel = createPanel_fontname(commandName, options.fontnames);
959 | list = true;
960 | break;
961 |
962 | case editor.COMMAND.FONTSIZE:
963 | $panel = createPanel_fontsize(commandName);
964 | list = true;
965 | break;
966 |
967 | case editor.COMMAND.FORECOLOR:
968 | case editor.COMMAND.BACKCOLOR:
969 | $panel = createPanel_color(commandName, options.colors);
970 | list = true;
971 | break;
972 |
973 | case editor.COMMAND.INSERTIMAGE:
974 | $panel = createPanel_insertimage(commandName);
975 | break;
976 |
977 | case editor.COMMAND.CREATELINK:
978 | $panel = createPanel_createlink(commandName);
979 | break;
980 |
981 | default:
982 | return null;
983 | }
984 |
985 | if(list)
986 | {
987 | // set click event to "li"
988 | $panel
989 | .on("click", "li", function()
990 | {
991 | // execute command
992 | const $target = $(this);
993 | const param = $target.data("param");
994 | _execCommand(commandName, param);
995 | });
996 | }
997 |
998 | // set class and position and
999 | const offset = $command.addClass("cazary-active").offset();
1000 | offset.top += $command.outerHeight();
1001 | $panel
1002 | .addClass("cazary-panel")
1003 | .addClass(`cazary-panel-${commandName}`)
1004 | .data("id", uniqueId)
1005 | .data("command", commandName)
1006 | .css({
1007 | left: `${offset.left}px`,
1008 | top : `${offset.top}px`,
1009 | })
1010 | .on("click", function()
1011 | {
1012 | // stop bubbling
1013 | return false;
1014 | })
1015 | .appendTo($(document.body))
1016 | .find(":text:first")
1017 | .trigger("focus");
1018 |
1019 | return $panel;
1020 | }
1021 |
1022 | function createPanel_fontname(commandName, fontnames)
1023 | {
1024 | /*
1025 |
1031 | */
1032 | const $ul = $("
").addClass("cazary-widget-select");
1033 | $.each(fontnames, function()
1034 | {
1035 | const fontName = this.toString();
1036 | const $li = $("
")
1037 | .attr({
1038 | "unselectable": "on",
1039 | "title": fontName,
1040 | })
1041 | .css({
1042 | "font-family": fontName,
1043 | })
1044 | .data("param", fontName)
1045 | .text(fontName);
1046 |
1047 | $ul.append($li);
1048 | });
1049 | return $("
").append($ul);
1050 | }
1051 |
1052 | function createPanel_fontsize(commandName)
1053 | {
1054 | /*
1055 |
1066 | */
1067 | const $ul = $("
").addClass("cazary-widget-select");
1068 | $.each(ASSOC_FONTSIZES, function(param, text)
1069 | {
1070 | const _text = _(text);
1071 | const $li = $("
")
1072 | .attr({
1073 | "unselectable": "on",
1074 | "title": _text,
1075 | })
1076 | .data("param", param);
1077 |
1078 | const $font = $("
")
1079 | .attr({
1080 | "size": param
1081 | })
1082 | .text(text);
1083 |
1084 | $ul.append($li.append($font));
1085 | });
1086 | return $("
").append($ul);
1087 | }
1088 |
1089 | function createPanel_color(commandName, colors)
1090 | {
1091 | /*
1092 |
1102 | */
1103 | const $panel = $("
");
1104 |
1105 | $.each(colors, function()
1106 | {
1107 | const $ul = $("
").addClass("cazary-widget-select-color");
1108 | $.each(this, function()
1109 | {
1110 | const colorName = this.toString();
1111 | const $li = $("
")
1112 | .attr({
1113 | "unselectable": "on",
1114 | "title": colorName,
1115 | })
1116 | .css({
1117 | "background-color": colorName,
1118 | })
1119 | .data("param", colorName)
1120 | .text(colorName);
1121 |
1122 | $ul.append($li);
1123 | });
1124 | $panel.append($ul);
1125 | });
1126 | return $panel;
1127 | }
1128 |
1129 | function createPanel_insertimage(commandName)
1130 | {
1131 | /*
1132 |
1147 | */
1148 | const $panel = $("
")
1149 | .append(
1150 | $("
")
1151 | .attr("action", "#")
1152 | .append(
1153 | $("
")
1154 | .append(
1155 | $("
")
1156 | .append(
1157 | $("
")
1158 | .text(_("Input image URL"))
1159 | )
1160 | .append(
1161 | $("
")
1162 | .addClass("cazary-widget-insertimage-url")
1163 | .attr({
1164 | "required": "required",
1165 | "placeholder": _("http://example.com/path/to/image.jpg"),
1166 | })
1167 | )
1168 | )
1169 | .append(
1170 | $("
")
1171 | .addClass("cazary-widget-submit")
1172 | .val(_("Insert"))
1173 | )
1174 | )
1175 | .append(
1176 | $("
")
1177 | .addClass("cazary-widget-preview")
1178 | .append(
1179 | $("
")
1180 | .text(_("Preview"))
1181 | )
1182 | .append(
1183 | $("
![]()
")
1184 | .addClass("cazary-widget-preview-insertimage")
1185 | )
1186 | )
1187 | );
1188 |
1189 | return $panel
1190 | .on("submit", "form", onsubmit)
1191 | .on("click", ".cazary-widget-submit", onsubmit)
1192 | .on("keydown paste", ".cazary-widget-insertimage-url", onupdate);
1193 |
1194 | function onsubmit()
1195 | {
1196 | const $url = $panel.find(".cazary-widget-insertimage-url");
1197 | const url = $url.val();
1198 | if(!checkURL(url))
1199 | {
1200 | $url.trigger("focus");
1201 | return false;
1202 | }
1203 | _execCommand(commandName, url);
1204 | return false;
1205 | }
1206 |
1207 | function onupdate()
1208 | {
1209 | const $url = $(this);
1210 | window.setTimeout(function()
1211 | {
1212 | const dataName = "url_old";
1213 | const url = $url.val();
1214 | const url_old = $url.data(dataName);
1215 | if(url === url_old)
1216 | {
1217 | return;
1218 | }
1219 | $url.data(dataName, url);
1220 | const $preview = $panel.find(".cazary-widget-preview");
1221 | if(checkURL(url))
1222 | {
1223 | $preview.show();
1224 | $panel
1225 | .find(".cazary-widget-preview-insertimage")
1226 | .attr("src", url);
1227 | }
1228 | else
1229 | {
1230 | $preview.hide();
1231 | }
1232 | }, 10);
1233 | }
1234 | }
1235 |
1236 | function createPanel_createlink(commandName)
1237 | {
1238 | /*
1239 |
1254 | */
1255 | const $panel = $("
")
1256 | .append(
1257 | $("
")
1258 | .attr("action", "#")
1259 | .append(
1260 | $("
")
1261 | .append(
1262 | $("
")
1263 | .append(
1264 | $("
")
1265 | .text(_("Input link URL or E-mail address"))
1266 | )
1267 | .append(
1268 | $("
")
1269 | .addClass("cazary-widget-createlink-url")
1270 | .attr({
1271 | "required": "required",
1272 | "placeholder": _("http://example.com/, someone@example.com"),
1273 | })
1274 | )
1275 | )
1276 | .append(
1277 | $("
")
1278 | .addClass("cazary-widget-submit")
1279 | .val(_("Insert"))
1280 | )
1281 | )
1282 | .append(
1283 | $("
")
1284 | .addClass("cazary-widget-preview")
1285 | .append(
1286 | $("
")
1287 | .text(_("Preview"))
1288 | )
1289 | .append(
1290 | $("
")
1291 | .addClass("cazary-widget-preview-createlink")
1292 | )
1293 | )
1294 | );
1295 |
1296 | return $panel
1297 | .on("submit", "form", onsubmit)
1298 | .on("click", ".cazary-widget-submit", onsubmit)
1299 | .on("keydown paste", ".cazary-widget-createlink-url", onupdate);
1300 |
1301 | function onsubmit()
1302 | {
1303 | const $url = $panel.find(".cazary-widget-createlink-url");
1304 | let url = $url.val();
1305 | if(checkEmail(url))
1306 | {
1307 | url = `mailto:${url}`;
1308 | }
1309 | else if(!checkURL(url))
1310 | {
1311 | $url.trigger("focus");
1312 | return false;
1313 | }
1314 | _execCommand(commandName, url);
1315 | return false;
1316 | }
1317 |
1318 | function onupdate()
1319 | {
1320 | const $url = $(this);
1321 | window.setTimeout(function()
1322 | {
1323 | const dataName = "url_old";
1324 | const url = $url.val();
1325 | const url_old = $url.data(dataName);
1326 | if(url === url_old)
1327 | {
1328 | return;
1329 | }
1330 | $url.data(dataName, url);
1331 | const $preview = $panel.find(".cazary-widget-preview");
1332 | if(checkURL(url))
1333 | {
1334 | $preview.show();
1335 | $panel
1336 | .find(".cazary-widget-preview-createlink")
1337 | .attr("src", url);
1338 | }
1339 | else
1340 | {
1341 | $preview.hide();
1342 | }
1343 | }, 10);
1344 | }
1345 | }
1346 |
1347 | /**
1348 | * update command status
1349 | * when to be called:
1350 | *
1351 | * - after switched to RTE mode
1352 | * - after execCommand method
1353 | * - select event to RTE object
1354 | * - click event to RTE object
1355 | * - keyup event to RTE object
1356 | * - focus event to RTE object
1357 | *
1358 | */
1359 | function _updateCommandStatus()
1360 | {
1361 | const status = editor.getCurrentStatus();
1362 | for(const name in status)
1363 | {
1364 | let value = status[name];
1365 | const $element = $cazary.find(`.cazary-command-${name}`);
1366 |
1367 | // set font name
1368 | if(name === editor.COMMAND.FONTNAME)
1369 | {
1370 | let title = value;
1371 | if(title === null)
1372 | {
1373 | value = "";
1374 | title = $element.attr("title");
1375 | }
1376 | $element.css({"font-family": value}).text(title);
1377 | continue;
1378 | }
1379 |
1380 | // set font size
1381 | if(name === editor.COMMAND.FONTSIZE)
1382 | {
1383 | let title = value;
1384 | if(title === null)
1385 | {
1386 | value = "";
1387 | title = $element.attr("title");
1388 | }
1389 | else
1390 | {
1391 | title = _(ASSOC_FONTSIZES[title]);
1392 | }
1393 | $element.text(title);
1394 | continue;
1395 | }
1396 |
1397 | // set font color
1398 | if(name === editor.COMMAND.FORECOLOR || name === editor.COMMAND.BACKCOLOR)
1399 | {
1400 | const $command = $cazary.find(`.cazary-command-${name}`);
1401 | const color = (value === null) ? "" : value;
1402 | $command.css("background-color", color);
1403 | continue;
1404 | }
1405 |
1406 | if(value === editor.STATUS.ACTIVE)
1407 | {
1408 | $element.addClass("cazary-active");
1409 | }
1410 | else
1411 | {
1412 | $element.removeClass("cazary-active");
1413 | }
1414 | if(value === editor.STATUS.DISABLED)
1415 | {
1416 | $element.addClass("cazary-disabled");
1417 | }
1418 | else
1419 | {
1420 | $element.removeClass("cazary-disabled");
1421 | }
1422 | }
1423 | }
1424 |
1425 | /**
1426 | * set focus to editor window
1427 | */
1428 | function _setFocus()
1429 | {
1430 | if(_isHtmlMode())
1431 | {
1432 | $origin.trigger("focus");
1433 | }
1434 | else
1435 | {
1436 | editor.setFocus();
1437 | }
1438 | }
1439 |
1440 | /**
1441 | * set/unset "empty" class to body
1442 | */
1443 | function _setEmptyClass()
1444 | {
1445 | const $body = $(editor.contentDocument.body);
1446 | if($body.text().length === 0)
1447 | {
1448 | $body.addClass("empty");
1449 | }
1450 | else
1451 | {
1452 | $body.removeClass("empty");
1453 | }
1454 | }
1455 | });
1456 | };
1457 |
1458 | function createCommandsWrapper(commands)
1459 | {
1460 | /*
1461 |
1462 |
1463 | - AAA
1464 | ...
1465 |
1466 |
1467 | - BBB
1468 | ...
1469 |
1470 | ...
1471 |
1472 | */
1473 | if(typeof(commands) === "string")
1474 | {
1475 | if(PRE_DEFINED_MACROS[commands] !== undefined)
1476 | {
1477 | commands = PRE_DEFINED_MACROS[commands];
1478 | }
1479 | else
1480 | {
1481 | commands = [commands];
1482 | }
1483 | }
1484 |
1485 | const $obj = $("
").addClass("cazary-commands-wrapper");
1486 | $.each(commands, function()
1487 | {
1488 | const $ul = $("
").addClass("cazary-commands-list");
1489 | const command_list = this.toLowerCase().split(" ");
1490 | $.each(command_list, function()
1491 | {
1492 | let command = this.toString();
1493 | if(command === "|")
1494 | {
1495 | command = "separator";
1496 | }
1497 |
1498 | if(ASSOC_COMMANDNAMES[command] === undefined)
1499 | {
1500 | return;
1501 | }
1502 |
1503 | const text = _(ASSOC_COMMANDNAMES[command]);
1504 | const className = `cazary-command-${command}`;
1505 |
1506 | const $li = $("
")
1507 | .attr({
1508 | "unselectable": "on",
1509 | "title": text,
1510 | })
1511 | .addClass(className)
1512 | .text(text);
1513 |
1514 | $ul.append($li);
1515 | });
1516 | $obj.append($ul);
1517 | });
1518 | return $obj;
1519 | }
1520 |
1521 | /**
1522 | * destroy all panels
1523 | */
1524 | function destroyAllPanels()
1525 | {
1526 | $(".cazary-panel")
1527 | .each(function()
1528 | {
1529 | const commandName = $(this).data("command");
1530 | const selector = `.cazary-command-${commandName}`;
1531 | $(selector).removeClass("cazary-active");
1532 | })
1533 | .remove();
1534 | }
1535 | })($)
1536 | });
1537 | return $;
1538 | }));
1539 |
--------------------------------------------------------------------------------