jquery.jeditable.ckeditor.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * CKEditor input for Jeditable
  3. *
  4. * Adapted from Wysiwyg input for Jeditable by Mike Tuupola
  5. * http://www.appelsiini.net/2008/9/wysiwyg-for-jeditable
  6. *
  7. * Copyright (c) 2009 Jeremy Bell
  8. *
  9. * Licensed under the MIT license:
  10. * http://www.opensource.org/licenses/mit-license.php
  11. *
  12. * Depends on CKEditor:
  13. * http://ckeditor/
  14. *
  15. */
  16. (function($) {
  17. $.generateId = function() {
  18. return arguments.callee.prefix + arguments.callee.count++;
  19. };
  20. $.generateId.prefix = 'jq$';
  21. $.generateId.count = 0;
  22. $.fn.generateId = function() {
  23. return this.each(function() {
  24. this.id = $.generateId();
  25. });
  26. };
  27. })(jQuery);
  28. (function($) {
  29. $.editable.addInputType('ckeditor', {
  30. /* Use default textarea instead of writing code here again. */
  31. //element : $.editable.types.textarea.element,
  32. element : function(settings, original) {
  33. /* Hide textarea to avoid flicker. */
  34. var textarea = $('<textarea>').css("opacity", "0").generateId();
  35. if (settings.rows) {
  36. textarea.attr('rows', settings.rows);
  37. } else {
  38. textarea.height(settings.height);
  39. }
  40. if (settings.cols) {
  41. textarea.attr('cols', settings.cols);
  42. } else {
  43. textarea.width(settings.width);
  44. }
  45. $(this).append(textarea);
  46. return(textarea);
  47. },
  48. content : function(string, settings, original) {
  49. /* jWYSIWYG plugin uses .text() instead of .val() */
  50. /* For some reason it did not work work with generated */
  51. /* textareas so I am forcing the value here with .text() */
  52. $('textarea', this).text(string);
  53. },
  54. plugin : function(settings, original) {
  55. var self = this;
  56. if (settings.ckeditor) {
  57. setTimeout(function() { CKEDITOR.replace($('textarea', self).attr('id'), settings.ckeditor); }, 0);
  58. } else {
  59. setTimeout(function() { CKEDITOR.replace($('textarea', self).attr('id')); }, 0);
  60. }
  61. },
  62. submit : function(settings, original) {
  63. $('textarea', this).val(CKEDITOR.instances[$('textarea', this).attr('id')].getData());
  64. CKEDITOR.instances[$('textarea', this).attr('id')].destroy();
  65. }
  66. });
  67. })(jQuery);