Mercurial > defr > drupal > scald > dnd
diff dnd_test/dnd_test.module @ 4:c2eb995212bf
TONS of fixes in this commit.
author | David Eads <eads@chicagotech.org> |
---|---|
date | Thu, 19 Feb 2009 12:33:19 -0600 |
parents | 5a44c430b7ac |
children | 4626f7e31aa0 |
line wrap: on
line diff
--- a/dnd_test/dnd_test.module Tue Feb 17 15:46:36 2009 -0600 +++ b/dnd_test/dnd_test.module Thu Feb 19 12:33:19 2009 -0600 @@ -1,5 +1,8 @@ <?php +/** + * Implementation of hook_menu(). + */ function dnd_test_menu() { $items = array(); $items['dnd-test/library'] = array( @@ -10,10 +13,19 @@ return $items; } +/** + * Implementation of hook_perm(). + */ function dnd_test_perm() { return array('access dnd test library'); } + +/** + * Implementation of hook_form_alter(). + * + * This demonstrates how to attach Drag and Drop to a given textarea. + */ function dnd_test_form_alter(&$form, &$form_state) { if ($form['#id'] == 'node-form' && $form['type']['#value'] == 'page') { drupal_add_css(drupal_get_path('module', 'dnd_test') .'/dnd_test.css'); @@ -26,21 +38,92 @@ } } +/** + * Implementation of hook_theme(). + */ +function dnd_test_theme() { + return array( + 'dnd_editor_item' => array( + 'arguments' => array('i' => NULL, 'size' => NULL), + 'template' => 'dnd-editor-item', + ), + 'dnd_library_item' => array( + 'arguments' => array('i' => NULL), + 'template' => 'dnd-library-item', + ), + ); +} + +/** + * Page call back that returns some JSON + */ function dnd_test_library() { + $page = ($_GET['page']) ? $_GET['page'] : 1; + $test_library = dnd_test_generate_library($page); + return drupal_json(array( + 'header' => '<h3>'. t('Test library: Page @page', array('@page' => $page)) .'</h3>', + 'library' => $test_library['library'], + 'editor_representations' => $test_library['editor_representations'], + 'footer' => '<div class="pager">'. l(t('1'), 'dnd-test/library') . ' '. l(t('2'), 'dnd-test/library', array('query' => array('page' => 2))) .'</div>', + )); +} - $var = array( - 'header' => '<h3>Test library</h3>', - 'footer' => '<div class="pager">'. l(1, 'dnd-test/library') . ' '. l(2, 'dnd-test/library', array('query' => array('page' => 2))) .'</div>', +/** + * Create contrived output + */ +function dnd_test_generate_library($page = 1, $limit = 5) { + $start = ($page * $limit) - ($limit); + $end = $page * $limit; + + $library = ''; + $editor_representations = array(); + for ($i=$start + 1; $i < $end + 1; $i++) { + $library .= theme('dnd_library_item', $i); + $editor_representations += dnd_editor_items($i); + } + return array( + 'library' => $library, + 'editor_representations' => $editor_representations, ); - $modifier = ($_GET['page'] == 2) ? 'page-2' : 'page-1'; - for ($i=1; $i < 6; $i++) { - $library = '<div class="row"><a href="" class="drop" id="image-'. $i .'-'. $modifier .'">'. theme('image', drupal_get_path('module', 'dnd_test') .'/img/'. $modifier .'-small.jpg') .'Image '. $i .'</a></div>'; - $editor = theme('image', drupal_get_path('module', 'dnd_test') .'/img/'. $modifier .'-large.jpg'); - $var['library']['image-'. $i .'-'. $modifier] = array( - 'library' => $library, - 'editor' => $editor, - ); +} + +/** + * Theme wrapper that spins out multiple library representations for a given + * editor representation. This is because we want to demonstrate how to allow + * for multiple versions (i.e. different sizes) of a single item + */ +function dnd_editor_items($i) { + $item = array(); + foreach(array(t('S'), t('M'), t('L')) as $size) { + $item['item-'. $i .'-'. $size] = theme('dnd_editor_item', $i, $size); } - drupal_json($var); - exit(); + return $item; } + +/** + * Completely contrived edit item theme function + */ +function template_preprocess_dnd_library_item(&$variables) { + $i = $variables['i']; + $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $i .'-thumb.jpg'); + $variables['title'] = t('Lorem Ipsum @count', array('@count' => $i)); + $variables['date'] = 'Feb 18 2009'; + $variables['author'] = 'David Eads'; + foreach(array(t('S'), t('M'), t('L')) as $size) { + $sizes[] = l('<span>'. $size .'</span>', '', array( + 'html' => TRUE, + 'attributes' => array( + 'class' => 'drop size-'. $size, + 'id' => 'item-'. $i .'-'. $size, + ), + 'query' => array('dnd_id' => 'item-'. $i .'-'. $size), + )); + } + $variables['sizes'] = '<ul><li>'. implode('</li><li>', $sizes) .'</li></ul>'; +} + + +function template_preprocess_dnd_editor_item(&$variables) { + list($i, $size) = array($variables['i'], $variables['size']); + $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $i .'-'. $size .'.jpg'); +}