/system/cms/modules/pages/js/form.js

https://github.com/wiclearinghouse/pyrocms · JavaScript · 74 lines · 51 code · 18 blank · 5 comment · 7 complexity · 248b3436eb01e494cdc36807a9c7999c MD5 · raw file

  1. (function($) {
  2. $(function(){
  3. form = $('form.crud');
  4. $('input[name="title"]', form).keyup($.debounce(300, function(){
  5. slug = $('input[name="slug"]', form);
  6. if (slug.val() == 'home' || slug.val() == '404')
  7. {
  8. return;
  9. }
  10. $.post(SITE_URL + 'ajax/url_title', { title : $(this).val() }, function(new_slug){
  11. slug.val( new_slug );
  12. });
  13. }));
  14. // add another page chunk
  15. $('a.add-chunk').live('click', function(e){
  16. e.preventDefault();
  17. // The date in hexdec
  18. key = Number(new Date()).toString(16);
  19. $('#page-content ul li:last').before('<li class="page-chunk">' +
  20. '<div class="float-left">'+
  21. '<input type="text" name="chunk_slug[' + key + ']" value="chunk-' + key + '"/>' +
  22. '<select name="chunk_type[' + key + ']">' +
  23. '<option value="html">html</option>' +
  24. '<option value="markdown">markdown</option>' +
  25. '<option value="wysiwyg-simple">wysiwyg-simple</option>' +
  26. '<option selected="selected" value="wysiwyg-advanced">wysiwyg-advanced</option>' +
  27. '</select>' +
  28. '</div><div class="float-right">' +
  29. '<a href="javascript:void(0)" class="remove-chunk">Remove</a>' +
  30. '</div><br style="clear:both" />' +
  31. '<textarea id="chunk-' + key + '" class="wysiwyg-advanced" rows="20" style="width:100%" name="chunk_body[' + key + ']"></textarea>' +
  32. '</li>');
  33. // initialize the editor using the view from fragments/wysiwyg.php
  34. pyro.init_ckeditor();
  35. });
  36. $('a.remove-chunk').live('click', function(e) {
  37. e.preventDefault();
  38. $(this).closest('li.page-chunk').slideUp('slow', function(){ $(this).remove(); });
  39. });
  40. $('select[name^=chunk_type]').live('change', function() {
  41. chunk = $(this).closest('li.page-chunk');
  42. textarea = $('textarea', chunk);
  43. // Destroy existing WYSIWYG instance
  44. if (textarea.hasClass('wysiwyg-simple') || textarea.hasClass('wysiwyg-advanced'))
  45. {
  46. textarea.removeClass('wysiwyg-simple');
  47. textarea.removeClass('wysiwyg-advanced');
  48. var instance = CKEDITOR.instances[textarea.attr('id')];
  49. instance && instance.destroy();
  50. }
  51. // Set up the new instance
  52. textarea.addClass(this.value);
  53. pyro.init_ckeditor();
  54. });
  55. });
  56. })(jQuery);