Index: .cvsignore =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/.cvsignore,v retrieving revision 1.6 diff -u -p -r1.6 .cvsignore --- .cvsignore 8 Dec 2008 18:58:09 -0000 1.6 +++ .cvsignore 18 Dec 2008 23:30:30 -0000 @@ -4,3 +4,4 @@ jwysiwyg* nicedit* whizzywig* yui* +codepress* Index: editors/codepress.inc =================================================================== RCS file: editors/codepress.inc diff -N editors/codepress.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ editors/codepress.inc 18 Dec 2008 21:22:30 -0000 @@ -0,0 +1,76 @@ + 'Codepress', + 'vendor url' => 'http://codepress.org', + 'download url' => 'http://sourceforge.net/project/platformdownload.php?group_id=186981', + 'library path' => wysiwyg_get_path('codepress'), + 'libraries' => array( + '' => array( + 'title' => 'Source', + 'files' => array('codepress.js'), + ), + ), + 'version callback' => 'wysiwyg_codepress_version', + 'settings callback' => 'wysiwyg_codepress_settings', + 'versions' => array( + '0.9.6' => array( + 'js files' => array('codepress.js'), + ), + ), + ); + return $editor; +} + +/** + * Detect editor version. + * + * @param $editor + * An array containing editor properties as returned from hook_editor(). + * + * @return + * The installed editor version. + */ +function wysiwyg_codepress_version($editor) { + // No version information available; hardcoded for now. + return '0.9.6'; +} + +/** + * Return runtime editor settings for a given wysiwyg profile. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $config + * An array containing wysiwyg editor profile settings. + * @param $theme + * The name of a theme/GUI/skin to use. + * + * @return + * A settings array to be populated in + * Drupal.settings.wysiwyg.configs.{editor} + */ +function wysiwyg_codepress_settings($editor, $config, $theme) { + $settings = array( + 'editorBasePath' => wysiwyg_get_path('codepress', TRUE) . '/', + ); + + // Set programming language. + // Possible values: php, html, csharp, css, generic, java, javascript, perl, + // ruby, text, sql, vbscript. + $settings['language'] = 'php'; + + // Other settings + //$settings['linenumbers-off'] = TRUE; + //$settings['autocomplete-off'] = TRUE; + //$settings['readonly-on'] = TRUE; + + return $settings; +} Index: editors/js/codepress.js =================================================================== RCS file: editors/js/codepress.js diff -N editors/js/codepress.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ editors/js/codepress.js 18 Dec 2008 23:27:49 -0000 @@ -0,0 +1,71 @@ +// $Id: nicedit.js,v 1.3 2008/12/01 14:14:41 sun Exp $ + +// @todo +$(document).unbind('DOMContentLoaded', CodePress.run); + +/** + * Initialize editor instances. + * + * @param settings + * An object containing editor settings for each input format. + */ +Drupal.wysiwyg.editor.init.codepress = function(settings) { + // @todo Move global library settings somewhere else. + for (var format in settings) { + CodePress.path = settings[format].editorBasePath; + } +}; + +/** + * Attach this editor to a target element. + */ +Drupal.wysiwyg.editor.attach.codepress = function(context, params, settings) { + var $field = $('#' + params.field); + // Codepress uses CSS classes to configure instance settings. :/ + $field.addClass(settings.language); + // Codepress inserts a new IFRAME, using the id of the target element that + // was passed. :( + var field = $field.get(0); + var oldId = field.id; + field.id = field.id + '-codepress'; + var instance = new CodePress(field); + instance.id = field.id; + instance.className = 'wysiwyg-codepress'; + $field.after(instance); + $field.attr('id', oldId); + + // @todo Wysiwyg API does not handle this globally? + $(field.form).bind('submit', Drupal.wysiwyg.editor.detach.codepress); +}; + +/** + * Detach a single or all editors. + * + * See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook. + */ +Drupal.wysiwyg.editor.detach.codepress = function(context, params) { + if (typeof params != 'undefined') { + var instance = $('#' + params.field + '-codepress', context).get(0); + if (typeof instance != 'undefined') { + // Save contents of editor back into textarea. + var $field = $(instance.textarea); + $field.val(instance.getCode()); + // Remove editor instance. + $field.attr('disabled', false); + $(instance).remove(); + } + $('#' + params.field).show(); + } + else { + $('.wysiwyg-codepress').each(function () { + // Save contents of all editors back into textareas. + var $field = $(this.textarea); + $field.val(this.getCode()); + // Remove all editor instances. + $field.attr('disabled', false); + $(this).remove(); + $field.show(); + }); + } +}; +