/[drupal]/contributions/modules/widgeditor/widgeditor.module
ViewVC logotype

Contents of /contributions/modules/widgeditor/widgeditor.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Thu Dec 4 05:05:34 2008 UTC (11 months, 3 weeks ago) by Gurpartap
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Changes since 1.3: +34 -20 lines
File MIME type: text/x-php
#118100 - css/widgContent.css Not Found
#171757 - widgEditor for custom textareas
#168686 - Integration with IMCE
1 <?php
2 // $Id: widgeditor.module,v 1.1.2.4 2007/07/15 14:01:46 Gurpartap Exp $
3
4 function widgeditor_perm() {
5 return array('use widgEditor');
6 }
7
8 function widgeditor_menu() {
9 $items = array();
10
11 $items['admin/settings/widgeditor'] = array(
12 'title' => t('widgEditor'),
13 'description' => t('Enable widgEditor for specific textareas and toggle default behavior.'),
14 'page callback' => 'drupal_get_form',
15 'page arguments' => array('widgeditor_admin_settings'),
16 'access callback' => 'user_access',
17 'access arguments' => array('administer site configuration'),
18 'type' => MENU_NORMAL_ITEM,
19 );
20
21 return $items;
22 }
23
24 function widgeditor_admin_settings() {
25 $form = array();
26
27 $form['widgeditor']['widgeditor_default_enabled'] = array(
28 '#type' => 'checkbox',
29 '#title' => t("Enable widgEditor by default"),
30 '#default_value' => variable_get('widgeditor_default_enabled', 1),
31 );
32 $form['widgeditor']['widgeditor_textareas'] = array(
33 '#type' => 'textarea',
34 '#title' => t("Enable widgEditor for textareas with these IDs"),
35 '#description' => t('Enter one ID per line. Default is:<br /><em>edit-body<br />edit-comment</em>'),
36 '#default_value' => variable_get('widgeditor_textareas', "edit-body\nedit-comment"),
37 );
38
39 return system_settings_form($form);
40 }
41
42 function widgeditor_form_alter(&$form, $form_state, $form_id) {
43 static $js_added = FALSE;
44 $textareas = variable_get('widgeditor_textareas', "edit-body\nedit-comment");
45 $textareas = trim($textareas);
46 $textareas = str_replace(array("\r\n", "\n", "\r"), ',', $textareas);
47 $textareas = str_replace(' ', '', $textareas);
48
49 // Convert textareas into an array.
50 $textareas = explode(',', $textareas);
51
52 $def_enabled = variable_get('widgeditor_default_enabled', 1);
53 if (!user_access('use widgEditor')) return;
54
55 if (count($textareas) > 0 && !$js_added) {
56 widgeditor_add_javascript($textareas, $def_enabled);
57 $js_added = TRUE;
58 }
59 }
60
61 function widgeditor_add_javascript($textareas = array(), $def_enabled) {
62 $query = '';
63 $path = drupal_get_path('module', 'widgeditor');
64
65 foreach ($textareas as $i => $ta) {
66 $pattern = '/(\d+)-(\w+)/i';
67 $replacement = 'edit-$2';
68 $query .= " textareas[$i] = \"" . preg_replace($pattern, $replacement, $ta) . "\";\n";
69 }
70
71 drupal_add_js($path . '/' . 'scripts/widgEditor.js');
72 drupal_add_css($path . '/' . 'scripts/css/widgEditor.css');
73 drupal_add_js(array(
74 'widgeditor' => array(
75 'imce' => module_exists('imce'),
76 'widgContent' => base_path() . drupal_get_path('module', 'widgeditor') . '/scripts/css/widgContent.css'
77 ),
78 ), 'setting');
79 if ($def_enabled) {
80 drupal_add_js('
81 if (Drupal.jsEnabled) {
82 $(document).ready(function() {
83 var textareas = new Array();
84 ' . $query . '
85 for (i=0;i<textareas.length;i++) {
86 $("textarea#"+textareas[i]).attr("class", "widgEditor");
87 }
88 });
89 }
90 ', 'inline');}
91 else {
92 drupal_add_js('
93 if (Drupal.jsEnabled) {
94 $(document).ready(function() {
95 var textareas = new Array();
96 ' . $query . '
97 for (i=0;i<textareas.length;i++) {
98 $("textarea#"+textareas[i]).after(\'<div><a style="cursor: pointer;" id="widgEditor-id" class="widgEditor-\' + textareas[i] +\'">' . t('Enable rich text editor') . '</a></div>\');
99 }
100 $("a#widgEditor-id").click(function(){
101 var string1= $(this).attr("class");
102 var pattern=/(widgEditor)-(\w+)-(\w+)/i;
103 if (pattern.test(string1) == true) {
104 $("textarea#"+string1.replace(/widgEditor-/, "")).attr("class", "widgEditor");
105 widgInit();
106 $(this).hide("slow");
107 }
108 });
109 });
110 }
111 ', 'inline');
112 }
113 }

  ViewVC Help
Powered by ViewVC 1.1.2