@@ -35,13 +35,24 @@ function xmlhttprequest_plugin_snippets() {
3535 $ snippets = Snippet::load_by_type_user (0 , $ user_id , $ use_global );
3636 $ snippets = Snippet::clean ($ snippets , "form " , $ bug_id );
3737
38+ # split names of textareas found in "plugin_Snippets_textarea_names" option and
39+ # make an array of "textarea[name='FIELD_NAME']" strings
40+ $ textareaSelectors = array_map (
41+ function ($ name ) {
42+ return "textarea[name=' $ name'] " ;
43+ },
44+ Snippet::get_configured_field_names ()
45+ );
46+
3847 $ data = array (
3948 "snippets " => SnippetsPlugin::$ _version ,
49+ # return configured jQuery selectors for textareas in "selector" field
50+ "selector " => implode (", " , $ textareaSelectors )
4051 );
4152
42- # arrange the available snippets into the data array
53+ # arrange the available snippets into the data array and return it in "texts" field
4354 foreach ($ snippets as $ snippet ) {
44- $ data ["bugnote_text " ][$ snippet ->id ] = $ snippet ;
55+ $ data ["texts " ][$ snippet ->id ] = $ snippet ;
4556 }
4657
4758 $ json = json_encode ($ data );
@@ -50,6 +61,7 @@ function xmlhttprequest_plugin_snippets() {
5061 plugin_pop_current ();
5162}
5263
64+
5365/**
5466 * Object representing a saved block of text.
5567 */
@@ -334,5 +346,26 @@ public static function global_url($p_is_global = true) {
334346 }
335347 return '' ;
336348 }
337- }
338349
350+ /**
351+ * Returns an array with names of form fields (text areas) where snippets should be
352+ * available for selection.
353+ */
354+ public static function get_configured_field_names () {
355+ return preg_split ("/[,;\s]+/ " , plugin_config_get ("textarea_names " , "bugnote_text " ));
356+ }
357+
358+ /**
359+ * Returns an array of ('text area field name' => 'language resource identifier') pairs
360+ * that describe available (supported) text areas. Values will be passed to lang_get().
361+ */
362+ public static function get_available_field_names () {
363+ return array (
364+ 'bugnote_text ' => 'bugnote ' ,
365+ 'description ' => 'description ' ,
366+ 'steps_to_reproduce ' => 'steps_to_reproduce ' ,
367+ 'additional_information ' => 'additional_information ' ,
368+ 'body ' => 'reminder '
369+ );
370+ }
371+ }
0 commit comments