/[drupal]/contributions/modules/spajax/spajaxtest.module
ViewVC logotype

Contents of /contributions/modules/spajax/spajaxtest.module

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Jan 31 20:58:22 2006 UTC (3 years, 9 months ago) by jjeff
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial commit of the Scriptaculous/Prototype Ajax module.
1 <?php
2
3 // $Id$
4
5 // spajaxtest.module for Drupal by Jeff Robbins
6
7 /**
8 * @abstract
9 * A number of test pages to show what the Scriptaculous/Prototype/AJAX (spajax)
10 * module is capable of and how the code works
11 */
12
13 /**
14 * Test callback page with examples of how to use the code
15 *
16 */
17 function spajaxtest_test(){
18 if ($_POST['edit']){
19 $sorted = spajax_get_sort($_POST['edit']['sort']);
20 $output = "<p>Sortable order: ". implode(', ', $sorted) ."</p>";
21 return $output;
22 }
23 $output .= '<h1>Sorting</h1>';
24 $output .= "<p>Sortable lists with the ability to move items from one list to the other.</p>";
25 $items1 = array('item 1', 'item 2', 'item 3', 'item 4');
26 $options = array('containment' => array('list1', 'list2')); // items can be moved between these lists
27 $output .= theme_sortable_list($items1, 'List One', $options, array('id' => 'list1'));
28 $items2 = array('item A', 'item B', 'item C');
29 $output .= theme_sortable_list($items2, 'List Two', $options, array('id' => 'list2'));
30
31 $output .= '<h1>Drag and Drop</h1>';
32 $output .= "<div id='dragbox' class='draggable' style='border:1px solid #666;background-color:#DDD;width:100px;height:100px;'>This box is draggable.</div>";
33 spajax_draggable_element('dragbox');
34
35 $output .= '<h1>Simple JS Link</h1>';
36 $output .= '<p>'.spajax_link_to_function("Greeting", "alert('Hello world!')").'</p>';
37
38 $output .= '<h1>Effects</h1>';
39 $output .= '<div>'.spajax_link_to_function('blind up', spajax_visual_effect('BlindUp', 'blindbox')).'</div>';
40 $output .= '<div>'.spajax_link_to_function('blind down', spajax_visual_effect('BlindDown', 'blindbox')).'</div>';
41 $output .= "<div id='blindbox' class='blind' style='border:1px solid #666;background-color:#DDD;width:100px;height:200px;'><p>Box full of content.</p><p>Blah blah</p><p>Blah</p></div>";
42
43 $output .= "<h2>Slider Controls</h2>";
44 $output .= '<div id="track1" style="width:200px;background-color:#aaa;height:5px;">
45 <div id="handle1" style="width:5px;height:10px;background-color:#f00;"> </div>
46 </div>
47
48 <p id="debug1"> </p>';
49 // notice that the keys for functions are prefixed with #
50 // these functions also use Prototype's $() shorthand command to locate the elements
51 $options = array(
52 'sliderValue' => 0.5,
53 '#onSlide' => "function(v){\$('debug1').innerHTML='slide: '+v}",
54 '#onChange' => "function(v){\$('debug1').innerHTML='changed! '+v}"
55 );
56 spajax_slider('handle1', 'track1', $options);
57
58 /* This isn't working
59 $output .= "<h2>Dynamic Elements (in progress)</h2>\n";
60 // problems:
61 // is it possible to get just *part* of a form?
62
63 $form['#tree'] = true;
64 $form['input'] = array('#type' => 'textfield', '#title' => 'email');
65 // generating error...
66 _form_builder('foo', $form); // this will populate the form array so there are no errors
67 //$form['#printed'] = false;
68 $html = form_render($form);
69 spajax_create_function('add_email_field', spajax_insert_html('dynform', $html, 'Bottom'));
70 $output .= spajax_link_to_function('add another field', 'add_email_field()');
71 $output .= "<div id='dynform'>\n$html\n</div>";
72 */
73
74 return $output;
75 }
76
77 function spajaxtest_inplace_test($op = NULL){
78 if ($op == 'callback'){
79 if($val = $_POST['value']){ // prototype defaults to sending content using this variable
80 variable_set('spajax_inplace_test', $val);
81 print $val;
82 }
83 exit;
84 }
85
86 $output .= "<p>Scriptaculous has an in-place editor that allows you to edit content without reloading the page. Click in the next paragraph to edit it. Submit your content. It will be saved and appear on this page in the future.</p>";
87
88 $output .= "<div id='editable'>";
89 $output .= variable_get('spajax_inplace_test', 'You can edit this text!');
90 $output .= "</div>";
91
92 spajax_in_place_editor('editable', 'spajax/test/inplace/callback', array('rows' => 5));
93
94 return $output;
95 }
96
97 function spajaxtest_sortable_test(){
98 if ($edit = $_POST['edit']){
99 $order = spajax_get_sort($edit['sort']);
100 drupal_set_message('Order: '. implode(', ', $order));
101 }
102
103 $output .= "<p>Scriptaculous has a the ability to make elements on the page sortable.</p>
104 <p>The spajax.module extends this to create a new form element type called 'sortable'. The order of the elements are stored in a hidden field and submitted with the form.</p>
105 <p>Sort the following, then submit.</p>";
106 $items = array('first' => 'This one was first', 'second' => 'This one was second', 'third' => 'This one was third');
107 //$options = array('#onUpdate' => "function(){alert(Sortable.serialize('formsort'));}");
108 $form['sort'] = array('#type' => 'sortable', '#items' => $items, '#title' => t('Sortable'), '#attributes' => array('id' => 'formsort'));
109 $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
110 $output .= drupal_get_form('sort_test', $form);
111 return $output;
112 }
113
114 /**
115 * ************************ Drupal Hooks **************************
116 */
117
118 /**
119 * Implementation of hook_menu()
120 *
121 */
122
123 function spajaxtest_menu($may_cache){
124 $items = array();
125 if ($may_cache) {
126 // test stuff
127 $items[] = array('path' => 'spajax/test', 'access' => TRUE, 'title' => 'spajax test', 'callback' => 'spajaxtest_test', 'type' => MENU_NORMAL_ITEM | MENU_EXPANDED);
128 $items[] = array('path' => 'spajax/test/inplace', 'access' => TRUE, 'title' => 'in place editing', 'callback' => 'spajaxtest_inplace_test');
129 $items[] = array('path' => 'spajax/test/sortable', 'access' => TRUE, 'title' => 'sortable form element', 'callback' => 'spajaxtest_sortable_test');
130 }
131 return $items;
132 }
133
134 function spajaxtest_help($section){
135 switch($section){
136 case 'admin/modules#description':
137 return t('Test code for the SPAjax module. Provides a few pages to show what can be done.');
138 }
139 }

  ViewVC Help
Powered by ViewVC 1.1.2