freshereditor.min.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. (function() {
  2. (function($) {
  3. var methods;
  4. methods = {
  5. edit: function(isEditing) {
  6. return this.each(function() {
  7. return $(this).attr("contentEditable", isEditing || false);
  8. });
  9. },
  10. save: function(callback) {
  11. return this.each(function() {
  12. return callback($(this).attr('id'), $(this).html());
  13. });
  14. },
  15. createlink: function() {
  16. var urlPrompt;
  17. urlPrompt = prompt("Enter URL:", "http://");
  18. return document.execCommand("createlink", false, urlPrompt);
  19. },
  20. insertimage: function() {
  21. var urlPrompt;
  22. urlPrompt = prompt("Enter Image URL:", "http://");
  23. return document.execCommand("insertimage", false, urlPrompt);
  24. },
  25. formatblock: function(block) {
  26. return document.execCommand("formatblock", null, block);
  27. },
  28. init: function(opts) {
  29. var $toolbar, button, command, commands, excludes, font, font_list, fontnames, fontsize, fontsizes, group, groups, options, shortcuts, size_list, _i, _j, _k, _l, _len, _len2, _len3, _len4;
  30. options = opts || {};
  31. groups = [
  32. [
  33. {
  34. name: 'bold',
  35. label: "<span style='font-weight:bold;'>B</span>",
  36. title: 'Bold (Ctrl+B)',
  37. classname: 'toolbar_bold'
  38. }, {
  39. name: 'italic',
  40. label: "<span style='font-style:italic;'>I</span>",
  41. title: 'Italic (Ctrl+I)',
  42. classname: 'toolbar_italic'
  43. }, {
  44. name: 'underline',
  45. label: "<span style='text-decoration:underline!important;'>U</span>",
  46. title: 'Underline (Ctrl+U)',
  47. classname: 'toolbar_underline'
  48. }, {
  49. name: 'strikethrough',
  50. label: "<span style='text-shadow:none;text-decoration:line-through;'>ABC</span>",
  51. title: 'Strikethrough',
  52. classname: 'toolbar_strikethrough'
  53. }, {
  54. name: 'removeFormat',
  55. label: "<i class='icon-minus'></i>",
  56. title: 'Remove Formating (Ctrl+M)',
  57. classname: 'toolbar_remove'
  58. }
  59. ], [
  60. {
  61. name: 'fontname',
  62. label: "F <span class='caret'></span>",
  63. title: 'Select font name',
  64. classname: 'toolbar_fontname dropdown-toggle',
  65. dropdown: true
  66. }
  67. ], [
  68. {
  69. name: 'FontSize',
  70. label: "<span style='font:bold 16px;'>A</span><span style='font-size:8px;'>A</span> <span class='caret'></span>",
  71. title: 'Select font size',
  72. classname: 'toolbar_fontsize dropdown-toggle',
  73. dropdown: true
  74. }
  75. ], [
  76. {
  77. name: 'forecolor',
  78. label: "<div style='color:#ff0000;'>A <span class='caret'></span></div>",
  79. title: 'Select font color',
  80. classname: 'toolbar_forecolor dropdown-toggle',
  81. dropdown: true
  82. }
  83. ], [
  84. {
  85. name: 'backcolor',
  86. label: "<div style='display:inline-block;margin:3px;margin-top:8px;width:15px;height:12px;background-color:#0000ff;'></div> <span class='caret'></span>",
  87. title: 'Select background color',
  88. classname: 'toolbar_bgcolor dropdown-toggle',
  89. dropdown: true
  90. }
  91. ], [
  92. {
  93. name: 'justifyleft',
  94. label: "<i class='icon-align-left' style='margin-top:2px;'></i>",
  95. title: 'Left justify',
  96. classname: 'toolbar_justifyleft'
  97. }, {
  98. name: 'justifycenter',
  99. label: "<i class='icon-align-center' style='margin-top:2px;'></i>",
  100. title: 'Center justify',
  101. classname: 'toolbar_justifycenter'
  102. }, {
  103. name: 'justifyright',
  104. label: "<i class='icon-align-right' style='margin-top:2px;'></i>",
  105. title: 'Right justify',
  106. classname: 'toolbar_justifyright'
  107. }, {
  108. name: 'justifyfull',
  109. label: "<i class='icon-align-justify' style='margin-top:2px;'></i>",
  110. title: 'Full justify',
  111. classname: 'toolbar_justifyfull'
  112. }
  113. ], [
  114. {
  115. name: 'createlink',
  116. label: '@',
  117. title: 'Link to a web page (Ctrl+L)',
  118. userinput: "yes",
  119. classname: 'toolbar_link'
  120. }, {
  121. name: 'insertimage',
  122. label: "<i style='margin-top:2px;' class='icon-picture'></i>",
  123. title: 'Insert an image (Ctrl+G)',
  124. userinput: "yes",
  125. classname: 'toolbar_image'
  126. }, {
  127. name: 'insertorderedlist',
  128. label: "<i class='icon-list-alt' style='margin-top:2px;'></i>",
  129. title: 'Insert ordered list',
  130. classname: 'toolbar_ol'
  131. }, {
  132. name: 'insertunorderedlist',
  133. label: "<i class='icon-list' style='margin-top:2px;'></i>",
  134. title: 'Insert unordered list',
  135. classname: 'toolbar_ul'
  136. }
  137. ], [
  138. {
  139. name: 'insertparagraph',
  140. label: 'P',
  141. title: 'Insert a paragraph (Ctrl+Alt+0)',
  142. classname: 'toolbar_p',
  143. block: 'p'
  144. }, {
  145. name: 'insertheading1',
  146. label: 'H1',
  147. title: "Heading 1 (Ctrl+Alt+1)",
  148. classname: 'toolbar_h1',
  149. block: 'h1'
  150. }, {
  151. name: 'insertheading2',
  152. label: 'H2',
  153. title: "Heading 2 (Ctrl+Alt+2)",
  154. classname: 'toolbar_h2',
  155. block: 'h2'
  156. }, {
  157. name: 'insertheading3',
  158. label: 'H3',
  159. title: "Heading 3 (Ctrl+Alt+3)",
  160. classname: 'toolbar_h3',
  161. block: 'h3'
  162. }, {
  163. name: 'insertheading4',
  164. label: 'H4',
  165. title: "Heading 4 (Ctrl+Alt+4)",
  166. classname: 'toolbar_h4',
  167. block: 'h4'
  168. }
  169. ], [
  170. {
  171. name: 'blockquote',
  172. label: "<i style='margin-top:2px;' class='icon-comment'></i>",
  173. title: 'Blockquote (Ctrl+Q)',
  174. classname: 'toolbar_blockquote',
  175. block: 'blockquote'
  176. }, {
  177. name: 'code',
  178. label: '{&nbsp;}',
  179. title: 'Code (Ctrl+Alt+K)',
  180. classname: 'toolbar_code',
  181. block: 'pre'
  182. }, {
  183. name: 'superscript',
  184. label: 'x<sup>2</sup>',
  185. title: 'Superscript',
  186. classname: 'toolbar_superscript'
  187. }, {
  188. name: 'subscript',
  189. label: 'x<sub>2</sub>',
  190. title: 'Subscript',
  191. classname: 'toolbar_subscript'
  192. }
  193. ]
  194. ];
  195. if (options.toolbar_selector != null) {
  196. $toolbar = $(options.toolbar_selector);
  197. } else {
  198. $(this).before("<div id='editor-toolbar'></div>");
  199. $toolbar = $('#editor-toolbar');
  200. }
  201. $toolbar.addClass('fresheditor-toolbar');
  202. $toolbar.append("<div class='btn-toolbar'></div>");
  203. excludes = options.excludes || [];
  204. for (_i = 0, _len = groups.length; _i < _len; _i++) {
  205. commands = groups[_i];
  206. group = '';
  207. for (_j = 0, _len2 = commands.length; _j < _len2; _j++) {
  208. command = commands[_j];
  209. if (jQuery.inArray(command.name, excludes) < 0) {
  210. button = "<a href='#' class='btn toolbar-btn toolbar-cmd " + command.classname + "' title='" + command.title + "' command='" + command.name + "'";
  211. if (command.userinput != null) {
  212. button += " userinput='" + command.userinput + "'";
  213. }
  214. if (command.block != null) {
  215. button += " block='" + command.block + "'";
  216. }
  217. if (command.dropdown) {
  218. button += " data-toggle='dropdown'";
  219. }
  220. button += ">" + command.label + "</a>";
  221. group += button;
  222. }
  223. }
  224. $('.btn-toolbar', $toolbar).append("<div class='btn-group'>" + group + "</div>");
  225. }
  226. $("[data-toggle='dropdown']").removeClass('toolbar-cmd');
  227. if (jQuery.inArray('fontname', excludes) < 0) {
  228. fontnames = ["Arial", "Arial Black", "Comic Sans MS", "Courier New", "Georgia", "Helvetica", "Sans Serif", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana"];
  229. font_list = '';
  230. for (_k = 0, _len3 = fontnames.length; _k < _len3; _k++) {
  231. font = fontnames[_k];
  232. font_list += "<li><a href='#' class='fontname-option' style='font-family:" + font + ";'>" + font + "</a></li>";
  233. }
  234. $('.toolbar_fontname').after("<ul class='dropdown-menu'>" + font_list + "</ul>");
  235. $('.fontname-option').on('click', function() {
  236. document.execCommand("fontname", false, $(this).text());
  237. $(this).closest('.btn-group').removeClass('open');
  238. return false;
  239. });
  240. }
  241. if (jQuery.inArray('FontSize', excludes) < 0) {
  242. fontsizes = [
  243. {
  244. size: 1,
  245. point: 8
  246. }, {
  247. size: 2,
  248. point: 10
  249. }, {
  250. size: 3,
  251. point: 12
  252. }, {
  253. size: 4,
  254. point: 14
  255. }, {
  256. size: 5,
  257. point: 18
  258. }, {
  259. size: 6,
  260. point: 24
  261. }, {
  262. size: 7,
  263. point: 36
  264. }
  265. ];
  266. size_list = '';
  267. for (_l = 0, _len4 = fontsizes.length; _l < _len4; _l++) {
  268. fontsize = fontsizes[_l];
  269. size_list += "<li><a href='#' class='font-option fontsize-option' style='font-size:" + fontsize.point + "px;' fontsize='" + fontsize.size + "'>" + fontsize.size + "(" + fontsize.point + "pt)</a></li>";
  270. }
  271. $('.toolbar_fontsize').after("<ul class='dropdown-menu'>" + size_list + "</ul>");
  272. $('a.fontsize-option').on('click', function() {
  273. console.log($(this).attr('fontsize'));
  274. document.execCommand("FontSize", false, $(this).attr('fontsize'));
  275. $(this).closest('.btn-group').removeClass('open');
  276. return false;
  277. });
  278. }
  279. function getColorChart(id) {
  280. return '<table id="' + id + '" class="hue-colorchart">' +
  281. '<tbody><tr><td bgcolor="#FBEFEF"></td><td bgcolor="#FBF2EF"></td><td bgcolor="#FBF5EF"></td><td bgcolor="#FBF8EF"></td><td bgcolor="#FBFBEF"></td><td bgcolor="#F8FBEF"></td><td bgcolor="#F5FBEF"></td><td bgcolor="#F2FBEF"></td><td bgcolor="#EFFBEF"></td><td bgcolor="#EFFBF2"></td><td bgcolor="#EFFBF5"></td><td bgcolor="#EFFBF8"></td><td bgcolor="#EFFBFB"></td><td bgcolor="#EFF8FB"></td><td bgcolor="#EFF5FB"></td><td bgcolor="#EFF2FB"></td><td bgcolor="#EFEFFB"></td><td bgcolor="#F2EFFB"></td><td bgcolor="#F5EFFB"></td><td bgcolor="#F8EFFB"></td><td bgcolor="#FBEFFB"></td><td bgcolor="#FBEFF8"></td><td bgcolor="#FBEFF5"></td><td bgcolor="#FBEFF2"></td><td bgcolor="#FFFFFF"></td></tr>' +
  282. '<tr><td bgcolor="#F8E0E0"></td><td bgcolor="#F8E6E0"></td><td bgcolor="#F8ECE0"></td><td bgcolor="#F7F2E0"></td><td bgcolor="#F7F8E0"></td><td bgcolor="#F1F8E0"></td><td bgcolor="#ECF8E0"></td><td bgcolor="#E6F8E0"></td><td bgcolor="#E0F8E0"></td><td bgcolor="#E0F8E6"></td><td bgcolor="#E0F8EC"></td><td bgcolor="#E0F8F1"></td><td bgcolor="#E0F8F7"></td><td bgcolor="#E0F2F7"></td><td bgcolor="#E0ECF8"></td><td bgcolor="#E0E6F8"></td><td bgcolor="#E0E0F8"></td><td bgcolor="#E6E0F8"></td><td bgcolor="#ECE0F8"></td><td bgcolor="#F2E0F7"></td><td bgcolor="#F8E0F7"></td><td bgcolor="#F8E0F1"></td><td bgcolor="#F8E0EC"></td><td bgcolor="#F8E0E6"></td><td bgcolor="#FAFAFA"></td></tr>' +
  283. '<tr><td bgcolor="#F6CECE"></td><td bgcolor="#F6D8CE"></td><td bgcolor="#F6E3CE"></td><td bgcolor="#F5ECCE"></td><td bgcolor="#F5F6CE"></td><td bgcolor="#ECF6CE"></td><td bgcolor="#E3F6CE"></td><td bgcolor="#D8F6CE"></td><td bgcolor="#CEF6CE"></td><td bgcolor="#CEF6D8"></td><td bgcolor="#CEF6E3"></td><td bgcolor="#CEF6EC"></td><td bgcolor="#CEF6F5"></td><td bgcolor="#CEECF5"></td><td bgcolor="#CEE3F6"></td><td bgcolor="#CED8F6"></td><td bgcolor="#CECEF6"></td><td bgcolor="#D8CEF6"></td><td bgcolor="#E3CEF6"></td><td bgcolor="#ECCEF5"></td><td bgcolor="#F6CEF5"></td><td bgcolor="#F6CEEC"></td><td bgcolor="#F6CEE3"></td><td bgcolor="#F6CED8"></td><td bgcolor="#F2F2F2"></td></tr>' +
  284. '<tr><td bgcolor="#F5A9A9"></td><td bgcolor="#F5BCA9"></td><td bgcolor="#F5D0A9"></td><td bgcolor="#F3E2A9"></td><td bgcolor="#F2F5A9"></td><td bgcolor="#E1F5A9"></td><td bgcolor="#D0F5A9"></td><td bgcolor="#BCF5A9"></td><td bgcolor="#A9F5A9"></td><td bgcolor="#A9F5BC"></td><td bgcolor="#A9F5D0"></td><td bgcolor="#A9F5E1"></td><td bgcolor="#A9F5F2"></td><td bgcolor="#A9E2F3"></td><td bgcolor="#A9D0F5"></td><td bgcolor="#A9BCF5"></td><td bgcolor="#A9A9F5"></td><td bgcolor="#BCA9F5"></td><td bgcolor="#D0A9F5"></td><td bgcolor="#E2A9F3"></td><td bgcolor="#F5A9F2"></td><td bgcolor="#F5A9E1"></td><td bgcolor="#F5A9D0"></td><td bgcolor="#F5A9BC"></td><td bgcolor="#E6E6E6"></td></tr>' +
  285. '<tr><td bgcolor="#F78181"></td><td bgcolor="#F79F81"></td><td bgcolor="#F7BE81"></td><td bgcolor="#F5DA81"></td><td bgcolor="#F3F781"></td><td bgcolor="#D8F781"></td><td bgcolor="#BEF781"></td><td bgcolor="#9FF781"></td><td bgcolor="#81F781"></td><td bgcolor="#81F79F"></td><td bgcolor="#81F7BE"></td><td bgcolor="#81F7D8"></td><td bgcolor="#81F7F3"></td><td bgcolor="#81DAF5"></td><td bgcolor="#81BEF7"></td><td bgcolor="#819FF7"></td><td bgcolor="#8181F7"></td><td bgcolor="#9F81F7"></td><td bgcolor="#BE81F7"></td><td bgcolor="#DA81F5"></td><td bgcolor="#F781F3"></td><td bgcolor="#F781D8"></td><td bgcolor="#F781BE"></td><td bgcolor="#F7819F"></td><td bgcolor="#D8D8D8"></td></tr>' +
  286. '<tr><td bgcolor="#FA5858"></td><td bgcolor="#FA8258"></td><td bgcolor="#FAAC58"></td><td bgcolor="#F7D358"></td><td bgcolor="#F4FA58"></td><td bgcolor="#D0FA58"></td><td bgcolor="#ACFA58"></td><td bgcolor="#82FA58"></td><td bgcolor="#58FA58"></td><td bgcolor="#58FA82"></td><td bgcolor="#58FAAC"></td><td bgcolor="#58FAD0"></td><td bgcolor="#58FAF4"></td><td bgcolor="#58D3F7"></td><td bgcolor="#58ACFA"></td><td bgcolor="#5882FA"></td><td bgcolor="#5858FA"></td><td bgcolor="#8258FA"></td><td bgcolor="#AC58FA"></td><td bgcolor="#D358F7"></td><td bgcolor="#FA58F4"></td><td bgcolor="#FA58D0"></td><td bgcolor="#FA58AC"></td><td bgcolor="#FA5882"></td><td bgcolor="#BDBDBD"></td></tr>' +
  287. '<tr><td bgcolor="#FE2E2E"></td><td bgcolor="#FE642E"></td><td bgcolor="#FE9A2E"></td><td bgcolor="#FACC2E"></td><td bgcolor="#F7FE2E"></td><td bgcolor="#C8FE2E"></td><td bgcolor="#9AFE2E"></td><td bgcolor="#64FE2E"></td><td bgcolor="#2EFE2E"></td><td bgcolor="#2EFE64"></td><td bgcolor="#2EFE9A"></td><td bgcolor="#2EFEC8"></td><td bgcolor="#2EFEF7"></td><td bgcolor="#2ECCFA"></td><td bgcolor="#2E9AFE"></td><td bgcolor="#2E64FE"></td><td bgcolor="#2E2EFE"></td><td bgcolor="#642EFE"></td><td bgcolor="#9A2EFE"></td><td bgcolor="#CC2EFA"></td><td bgcolor="#FE2EF7"></td><td bgcolor="#FE2EC8"></td><td bgcolor="#FE2E9A"></td><td bgcolor="#FE2E64"></td><td bgcolor="#A4A4A4"></td></tr>' +
  288. '<tr><td bgcolor="#FF0000"></td><td bgcolor="#FF4000"></td><td bgcolor="#FF8000"></td><td bgcolor="#FFBF00"></td><td bgcolor="#FFFF00"></td><td bgcolor="#BFFF00"></td><td bgcolor="#80FF00"></td><td bgcolor="#40FF00"></td><td bgcolor="#00FF00"></td><td bgcolor="#00FF40"></td><td bgcolor="#00FF80"></td><td bgcolor="#00FFBF"></td><td bgcolor="#00FFFF"></td><td bgcolor="#00BFFF"></td><td bgcolor="#0080FF"></td><td bgcolor="#0040FF"></td><td bgcolor="#0000FF"></td><td bgcolor="#4000FF"></td><td bgcolor="#8000FF"></td><td bgcolor="#BF00FF"></td><td bgcolor="#FF00FF"></td><td bgcolor="#FF00BF"></td><td bgcolor="#FF0080"></td><td bgcolor="#FF0040"></td><td bgcolor="#848484"></td></tr>' +
  289. '<tr><td bgcolor="#DF0101"></td><td bgcolor="#DF3A01"></td><td bgcolor="#DF7401"></td><td bgcolor="#DBA901"></td><td bgcolor="#D7DF01"></td><td bgcolor="#A5DF00"></td><td bgcolor="#74DF00"></td><td bgcolor="#3ADF00"></td><td bgcolor="#01DF01"></td><td bgcolor="#01DF3A"></td><td bgcolor="#01DF74"></td><td bgcolor="#01DFA5"></td><td bgcolor="#01DFD7"></td><td bgcolor="#01A9DB"></td><td bgcolor="#0174DF"></td><td bgcolor="#013ADF"></td><td bgcolor="#0101DF"></td><td bgcolor="#3A01DF"></td><td bgcolor="#7401DF"></td><td bgcolor="#A901DB"></td><td bgcolor="#DF01D7"></td><td bgcolor="#DF01A5"></td><td bgcolor="#DF0174"></td><td bgcolor="#DF013A"></td><td bgcolor="#6E6E6E"></td></tr>' +
  290. '<tr><td bgcolor="#B40404"></td><td bgcolor="#B43104"></td><td bgcolor="#B45F04"></td><td bgcolor="#B18904"></td><td bgcolor="#AEB404"></td><td bgcolor="#86B404"></td><td bgcolor="#5FB404"></td><td bgcolor="#31B404"></td><td bgcolor="#04B404"></td><td bgcolor="#04B431"></td><td bgcolor="#04B45F"></td><td bgcolor="#04B486"></td><td bgcolor="#04B4AE"></td><td bgcolor="#0489B1"></td><td bgcolor="#045FB4"></td><td bgcolor="#0431B4"></td><td bgcolor="#0404B4"></td><td bgcolor="#3104B4"></td><td bgcolor="#5F04B4"></td><td bgcolor="#8904B1"></td><td bgcolor="#B404AE"></td><td bgcolor="#B40486"></td><td bgcolor="#B4045F"></td><td bgcolor="#B40431"></td><td bgcolor="#585858"></td></tr>' +
  291. '<tr><td bgcolor="#8A0808"></td><td bgcolor="#8A2908"></td><td bgcolor="#8A4B08"></td><td bgcolor="#886A08"></td><td bgcolor="#868A08"></td><td bgcolor="#688A08"></td><td bgcolor="#4B8A08"></td><td bgcolor="#298A08"></td><td bgcolor="#088A08"></td><td bgcolor="#088A29"></td><td bgcolor="#088A4B"></td><td bgcolor="#088A68"></td><td bgcolor="#088A85"></td><td bgcolor="#086A87"></td><td bgcolor="#084B8A"></td><td bgcolor="#08298A"></td><td bgcolor="#08088A"></td><td bgcolor="#29088A"></td><td bgcolor="#4B088A"></td><td bgcolor="#6A0888"></td><td bgcolor="#8A0886"></td><td bgcolor="#8A0868"></td><td bgcolor="#8A084B"></td><td bgcolor="#8A0829"></td><td bgcolor="#424242"></td></tr>' +
  292. '<tr><td bgcolor="#610B0B"></td><td bgcolor="#61210B"></td><td bgcolor="#61380B"></td><td bgcolor="#5F4C0B"></td><td bgcolor="#5E610B"></td><td bgcolor="#4B610B"></td><td bgcolor="#38610B"></td><td bgcolor="#21610B"></td><td bgcolor="#0B610B"></td><td bgcolor="#0B6121"></td><td bgcolor="#0B6138"></td><td bgcolor="#0B614B"></td><td bgcolor="#0B615E"></td><td bgcolor="#0B4C5F"></td><td bgcolor="#0B3861"></td><td bgcolor="#0B2161"></td><td bgcolor="#0B0B61"></td><td bgcolor="#210B61"></td><td bgcolor="#380B61"></td><td bgcolor="#4C0B5F"></td><td bgcolor="#610B5E"></td><td bgcolor="#610B4B"></td><td bgcolor="#610B38"></td><td bgcolor="#610B21"></td><td bgcolor="#2E2E2E"></td></tr>' +
  293. '<tr><td bgcolor="#3B0B0B"></td><td bgcolor="#3B170B"></td><td bgcolor="#3B240B"></td><td bgcolor="#3A2F0B"></td><td bgcolor="#393B0B"></td><td bgcolor="#2E3B0B"></td><td bgcolor="#243B0B"></td><td bgcolor="#173B0B"></td><td bgcolor="#0B3B0B"></td><td bgcolor="#0B3B17"></td><td bgcolor="#0B3B24"></td><td bgcolor="#0B3B2E"></td><td bgcolor="#0B3B39"></td><td bgcolor="#0B2F3A"></td><td bgcolor="#0B243B"></td><td bgcolor="#0B173B"></td><td bgcolor="#0B0B3B"></td><td bgcolor="#170B3B"></td><td bgcolor="#240B3B"></td><td bgcolor="#2F0B3A"></td><td bgcolor="#3B0B39"></td><td bgcolor="#3B0B2E"></td><td bgcolor="#3B0B24"></td><td bgcolor="#3B0B17"></td><td bgcolor="#1C1C1C"></td></tr>' +
  294. '<tr><td bgcolor="#2A0A0A"></td><td bgcolor="#2A120A"></td><td bgcolor="#2A1B0A"></td><td bgcolor="#29220A"></td><td bgcolor="#292A0A"></td><td bgcolor="#222A0A"></td><td bgcolor="#1B2A0A"></td><td bgcolor="#122A0A"></td><td bgcolor="#0A2A0A"></td><td bgcolor="#0A2A12"></td><td bgcolor="#0A2A1B"></td><td bgcolor="#0A2A22"></td><td bgcolor="#0A2A29"></td><td bgcolor="#0A2229"></td><td bgcolor="#0A1B2A"></td><td bgcolor="#0A122A"></td><td bgcolor="#0A0A2A"></td><td bgcolor="#120A2A"></td><td bgcolor="#1B0A2A"></td><td bgcolor="#220A29"></td><td bgcolor="#2A0A29"></td><td bgcolor="#2A0A22"></td><td bgcolor="#2A0A1B"></td><td bgcolor="#2A0A12"></td><td bgcolor="#151515"></td></tr>' +
  295. '<tr><td bgcolor="#190707"></td><td bgcolor="#190B07"></td><td bgcolor="#191007"></td><td bgcolor="#181407"></td><td bgcolor="#181907"></td><td bgcolor="#141907"></td><td bgcolor="#101907"></td><td bgcolor="#0B1907"></td><td bgcolor="#071907"></td><td bgcolor="#07190B"></td><td bgcolor="#071910"></td><td bgcolor="#071914"></td><td bgcolor="#071918"></td><td bgcolor="#071418"></td><td bgcolor="#071019"></td><td bgcolor="#070B19"></td><td bgcolor="#070719"></td><td bgcolor="#0B0719"></td><td bgcolor="#100719"></td><td bgcolor="#140718"></td><td bgcolor="#190718"></td><td bgcolor="#190714"></td><td bgcolor="#190710"></td><td bgcolor="#19070B"></td><td bgcolor="#000000"></td></tr>' +
  296. '</tbody></table>';
  297. }
  298. if (jQuery.inArray('forecolor', excludes) < 0) {
  299. $("a.toolbar_forecolor").after("<ul class='dropdown-menu colorpanel'><input type='text' id='forecolor-input' value='#000000' style='margin-bottom: 0px' /><div id='forecolor-preview' style='height:20px; margin: 4px; cursor: pointer'></div>" + getColorChart("forecolor-chart") + "</ul>");
  300. $("#forecolor-chart td").on("mouseover", function () {
  301. $("#forecolor-preview").css("background-color", $(this).attr("bgcolor")).data("color", $(this).attr("bgcolor"));
  302. $("#forecolor-input").val($(this).attr("bgcolor"));
  303. });
  304. $("#forecolor-chart td").on("mousedown", function () {
  305. var color = $(this).attr("bgcolor");
  306. document.execCommand("forecolor", false, color);
  307. $(this).closest(".btn-group").removeClass("open");
  308. $(".toolbar_forecolor div").css({
  309. "color": color
  310. });
  311. });
  312. $("#forecolor-input").on("click", function (e) {
  313. e.stopImmediatePropagation();
  314. e.preventDefault();
  315. });
  316. $("#forecolor-input").on("keyup", function (e) {
  317. e.stopImmediatePropagation();
  318. e.preventDefault();
  319. $("#forecolor-preview").css("background-color", $("#forecolor-input").val()).data("color", $("#forecolor-input").val());
  320. });
  321. $("#forecolor-preview").on("mousedown", function () {
  322. var color = $(this).data("color");
  323. document.execCommand("forecolor", false, color);
  324. $(this).closest(".btn-group").removeClass("open");
  325. $(".toolbar_forecolor div").css({
  326. "color": color
  327. });
  328. });
  329. }
  330. if (jQuery.inArray('backcolor', excludes) < 0) {
  331. $("a.toolbar_bgcolor").after("<ul class='dropdown-menu colorpanel'><input type='text' id='bgcolor-input' value='#000000' style='margin-bottom: 0px' /><div id='bgcolor-preview' style='height:20px; margin: 4px; cursor: pointer'></div>" + getColorChart("bgcolor-chart") + "</ul>");
  332. $("#bgcolor-chart td").on("mouseover", function () {
  333. $("#bgcolor-preview").css("background-color", $(this).attr("bgcolor")).data("color", $(this).attr("bgcolor"));
  334. $("#bgcolor-input").val($(this).attr("bgcolor"));
  335. });
  336. $("#bgcolor-chart td").on("mousedown", function () {
  337. var color = $(this).attr("bgcolor");
  338. document.execCommand("backcolor", false, color);
  339. $(this).closest(".btn-group").removeClass("open");
  340. $(".toolbar_bgcolor div").css({
  341. "background-color": color
  342. });
  343. });
  344. $("#bgcolor-input").on("click", function (e) {
  345. e.stopImmediatePropagation();
  346. e.preventDefault();
  347. });
  348. $("#bgcolor-input").on("keyup", function (e) {
  349. e.stopImmediatePropagation();
  350. e.preventDefault();
  351. $("#bgcolor-preview").css("background-color", $("#bgcolor-input").val()).data("color", $("#bgcolor-input").val());
  352. });
  353. $("#bgcolor-preview").on("mousedown", function () {
  354. var color = $(this).data("color");
  355. document.execCommand("backcolor", false, color);
  356. $(this).closest(".btn-group").removeClass("open");
  357. $(".toolbar_bgcolor div").css({
  358. "background-color": color
  359. });
  360. });
  361. }
  362. $(this).on('focus', function() {
  363. var $this;
  364. $this = $(this);
  365. $this.data('before', $this.html());
  366. return $this;
  367. }).on('blur keyup paste', function() {
  368. var $this;
  369. $this = $(this);
  370. if ($this.data('before') !== $this.html()) {
  371. $this.data('before', $this.html());
  372. $this.trigger('change');
  373. }
  374. return $this;
  375. });
  376. $("a.toolbar-cmd").on('click', function() {
  377. var ceNode, cmd, dummy, range;
  378. cmd = $(this).attr('command');
  379. if ($(this).attr('userinput') === 'yes') {
  380. methods[cmd].apply(this);
  381. } else if ($(this).attr('block')) {
  382. methods['formatblock'].apply(this, ["<" + ($(this).attr('block')) + ">"]);
  383. } else {
  384. if ((cmd === 'justifyright') || (cmd === 'justifyleft') || (cmd === 'justifycenter') || (cmd === 'justifyfull')) {
  385. try {
  386. document.execCommand(cmd, false, null);
  387. } catch (e) {
  388. if (e && e.result === 2147500037) {
  389. range = window.getSelection().getRangeAt(0);
  390. dummy = document.createElement('br');
  391. ceNode = range.startContainer.parentNode;
  392. while ((ceNode != null) && ceNode.contentEditable !== 'true') {
  393. ceNode = ceNode.parentNode;
  394. }
  395. if (!ceNode) {
  396. throw 'Selected node is not editable!';
  397. }
  398. ceNode.insertBefore(dummy, ceNode.childNodes[0]);
  399. document.execCommand(cmd, false, null);
  400. dummy.parentNode.removeChild(dummy);
  401. } else if (console && console.log) {
  402. console.log(e);
  403. }
  404. }
  405. } else {
  406. document.execCommand(cmd, false, null);
  407. }
  408. }
  409. return false;
  410. });
  411. shortcuts = [
  412. {
  413. keys: 'Ctrl+l',
  414. method: function() {
  415. return methods.createlink.apply(this);
  416. }
  417. }, {
  418. keys: 'Ctrl+g',
  419. method: function() {
  420. return methods.insertimage.apply(this);
  421. }
  422. }, {
  423. keys: 'Ctrl+Alt+U',
  424. method: function() {
  425. return document.execCommand('insertunorderedlist', false, null);
  426. }
  427. }, {
  428. keys: 'Ctrl+Alt+O',
  429. method: function() {
  430. return document.execCommand('insertorderedlist', false, null);
  431. }
  432. }, {
  433. keys: 'Ctrl+q',
  434. method: function() {
  435. return methods.formatblock.apply(this, ["<blockquote>"]);
  436. }
  437. }, {
  438. keys: 'Ctrl+Alt+k',
  439. method: function() {
  440. return methods.formatblock.apply(this, ["<pre>"]);
  441. }
  442. }, {
  443. keys: 'Ctrl+.',
  444. method: function() {
  445. return document.execCommand('superscript', false, null);
  446. }
  447. }, {
  448. keys: 'Ctrl+Shift+.',
  449. method: function() {
  450. return document.execCommand('subscript', false, null);
  451. }
  452. }, {
  453. keys: 'Ctrl+Alt+0',
  454. method: function() {
  455. return methods.formatblock.apply(this, ["p"]);
  456. }
  457. }, {
  458. keys: 'Ctrl+b',
  459. method: function() {
  460. return document.execCommand('bold', false, null);
  461. }
  462. }, {
  463. keys: 'Ctrl+i',
  464. method: function() {
  465. return document.execCommand('italic', false, null);
  466. }
  467. }, {
  468. keys: 'Ctrl+Alt+1',
  469. method: function() {
  470. return methods.formatblock.apply(this, ["H1"]);
  471. }
  472. }, {
  473. keys: 'Ctrl+Alt+2',
  474. method: function() {
  475. return methods.formatblock.apply(this, ["H2"]);
  476. }
  477. }, {
  478. keys: 'Ctrl+Alt+3',
  479. method: function() {
  480. return methods.formatblock.apply(this, ["H3"]);
  481. }
  482. }, {
  483. keys: 'Ctrl+Alt+4',
  484. method: function() {
  485. return methods.formatblock.apply(this, ["H4"]);
  486. }
  487. }, {
  488. keys: 'Ctrl+m',
  489. method: function() {
  490. return document.execCommand("removeFormat", false, null);
  491. }
  492. }, {
  493. keys: 'Ctrl+u',
  494. method: function() {
  495. return document.execCommand('underline', false, null);
  496. }
  497. }, {
  498. keys: 'tab',
  499. method: function() {
  500. return document.execCommand('indent', false, null);
  501. }
  502. }, {
  503. keys: 'Ctrl+tab',
  504. method: function() {
  505. return document.execCommand('indent', false, null);
  506. }
  507. }, {
  508. keys: 'Shift+tab',
  509. method: function() {
  510. return document.execCommand('outdent', false, null);
  511. }
  512. }
  513. ];
  514. $.each(shortcuts, function(index, elem) {
  515. return shortcut.add(elem.keys, function() {
  516. elem.method();
  517. return false;
  518. }, {
  519. 'type': 'keydown',
  520. 'propagate': false
  521. });
  522. });
  523. return this.each(function() {
  524. var $this, data, tooltip;
  525. $this = $(this);
  526. data = $this.data('fresheditor');
  527. tooltip = $('<div/>', {
  528. text: $this.attr('title')
  529. });
  530. if (!data) {
  531. return $(this).data('fresheditor', {
  532. target: $this,
  533. tooltip: tooltip
  534. });
  535. }
  536. });
  537. }
  538. };
  539. return $.fn.freshereditor = function(method) {
  540. if (methods[method]) {
  541. methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  542. } else if (typeof method === 'object' || !method) {
  543. methods.init.apply(this, arguments);
  544. } else {
  545. $.error('Method ' + method + ' does not exist on jQuery.contentEditable');
  546. }
  547. };
  548. })(jQuery);
  549. }).call(this);