t('jWYSIWYG settings'), 'description' => t('Allows administrators to configure several options of this module'), 'page callback' => 'drupal_get_form', 'page arguments' => array('jwysiwyg_settings'), // Only users with this role assigned will be able to admin this module 'access arguments' => array(JWYSIWYG_ADMIN), 'type' => MENU_NORMAL_ITEM, ); return $items; } /////////////////////////////////////////////////////////////////////////////////////// // Implementation of hook_elements /////////////////////////////////////////////////////////////////////////////////////// function jwysiwyg_elements() { $types = array(); $types['textarea'] = array('#process' => array('jwysiwyg_process_textarea')); return $types; } /////////////////////////////////////////////////////////////////////////////////////// // Our own function for textarea fields processing /////////////////////////////////////////////////////////////////////////////////////// function jwysiwyg_process_textarea($element) { // Never show the plugin in our own configuration textarea field if ($element['#id'] != JWYSIWYG_ACTIONS_FIELD) { // Get the current settings $visibility = variable_get(JWYSIWYG_VISIBILITY, array()); $visibility_action = $visibility[JWYSIWYG_ACTION]; // There is any restriction to show? if ($visibility_action == JWYSIWYG_ALL) { $must_show = TRUE; } else { // Get and parse the fields list $fields_list = $visibility[JWYSIWYG_FIELDS]; $fields = preg_split("/[\s,]+/", $fields_list, -1, PREG_SPLIT_NO_EMPTY); // Is this field id into our list of fields? if (array_search($element['#id'], $fields) === FALSE) { // Show only in case of not being part of a explicit field exclussion $must_show = ($visibility_action == JWYSIWYG_EXCLUDE_LIST); } else { // Show only in case of explicit field inclussion $must_show = ($visibility_action == JWYSIWYG_INCLUDE_LIST); } } if ($must_show) { // Add our own class for jQuery activation $element['#attributes'] = array('class'=>'jwysiwyg_class'); } // Only the module administrators will be able to see the helper message if (user_access(JWYSIWYG_ADMIN)) { // Set the new description, and include a
if a previous description existed. $element['#description'] .= isset($element['#description']) ? '
' : ''; $element['#description'] .= t('jwysiwyg note: The id of this field is @field', array('@field'=>$element['#id'])); } } return $element; } /////////////////////////////////////////////////////////////////////////////////////// // This module's settings form /////////////////////////////////////////////////////////////////////////////////////// function jwysiwyg_settings() { $form = array(); // Get the current settings $visibility = variable_get(JWYSIWYG_VISIBILITY, array()); $fileoptions = variable_get(JWYSIWYG_JSFILEOPTIONS, array()); // Plugin visibility settings $form[JWYSIWYG_VISIBILITY] = array( '#type' => 'fieldset', '#title' => t('Visibility settings'), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form[JWYSIWYG_VISIBILITY][JWYSIWYG_ACTION] = array( '#type' => 'radios', '#title' => t('Where to show the rich text editor?'), '#default_value' => isset($visibility[JWYSIWYG_ACTION]) ? $visibility[JWYSIWYG_ACTION] : JWYSIWYG_ACTION_DEFAULT, '#options' => array( JWYSIWYG_ALL => t('Show in each textarea'), JWYSIWYG_EXCLUDE_LIST => t('Show in all text areas, except in the fields listed bellow'), JWYSIWYG_INCLUDE_LIST => t('Show only in the fields listed bellow'), ), '#description' => t("Choose where to include the jWYSIWYG rich text editor."), '#required' => TRUE, '#weight' => -4, ); $form[JWYSIWYG_VISIBILITY][JWYSIWYG_FIELDS] = array( '#type' => 'textarea', '#title' => t('Field names'), '#default_value' => isset($visibility[JWYSIWYG_FIELDS]) ? $visibility[JWYSIWYG_FIELDS] : '', '#description' => t("Type the name of a field by line, separating them with an enter."), '#required' => FALSE, '#weight' => -3, ); // JS file to include settings // Plugin visibility settings $form[JWYSIWYG_JSFILEOPTIONS] = array( '#type' => 'fieldset', '#title' => t('Javascript file settings'), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form[JWYSIWYG_JSFILEOPTIONS][JWYSIWYG_JSFILE] = array( '#type' => 'radios', '#title' => t('Wich file to include?'), '#default_value' => isset($fileoptions[JWYSIWYG_JSFILE]) ? $fileoptions[JWYSIWYG_JSFILE] : JWYSIWYG_JSFILE_DEFAULT, '#options' => array( JWYSIWYG_JSFILEFULL => t('Include complete JS file (Recommended for debugging)'), JWYSIWYG_JSFILEMIN => t('Include minified JS file (Recommended for GZIP enabled servers, less client processing)'), JWYSIWYG_JSFILEPACKED => t('Included PACKed JS file (Smaller size, more client processing)'), ), '#description' => t("This module includes three separate copies of the JS file: The original, fully commented one (pretty nice, with CR/LF and all the stuff) a minified one and the last one packed.
Everything should be fine with any of these, but if your site is in production and you are GZIPping the content at server level, I do recommend you the minified version."), '#required' => TRUE, ); return system_settings_form($form); } /////////////////////////////////////////////////////////////////////////////////////// // Implementation of hook_help(). /////////////////////////////////////////////////////////////////////////////////////// /* function jwysiwyg_help($path, $arg) { } */ /////////////////////////////////////////////////////////////////////////////////////// // Implementation of hook_help(). /////////////////////////////////////////////////////////////////////////////////////// function jwysiwyg_perm() { return array(JWYSIWYG_ADMIN); } /////////////////////////////////////////////////////////////////////////////////////// // Implementation of hook_init(). /////////////////////////////////////////////////////////////////////////////////////// function jwysiwyg_init() { // Include the choosen javascript file $fileoptions = variable_get(JWYSIWYG_JSFILEOPTIONS, array()); switch($fileoptions[JWYSIWYG_JSFILE]) { case JWYSIWYG_JSFILEMIN: $jsfilename = 'jquery.wysiwyg.min.js'; break; case JWYSIWYG_JSFILEPACKED: $jsfilename = 'jquery.wysiwyg.pack.js'; break; case JWYSIWYG_JSFILEFULL: $jsfilename = 'jquery.wysiwyg.js'; break; } drupal_add_js(drupal_get_path('module', 'jwysiwyg') .'/js/'.$jsfilename); drupal_add_css(drupal_get_path('module', 'jwysiwyg') .'/jquery.wysiwyg.css'); $js = <<