eads@2: 'Drag and drop test library',
eads@2: 'page callback' => 'dnd_test_library',
eads@2: 'access arguments' => array('access dnd test library'),
eads@2: );
eads@2: return $items;
eads@2: }
eads@2:
eads@4: /**
eads@4: * Implementation of hook_perm().
eads@4: */
eads@2: function dnd_test_perm() {
eads@2: return array('access dnd test library');
eads@2: }
eads@2:
eads@4: /**
eads@4: * Implementation of hook_form_alter().
eads@4: *
eads@4: * This demonstrates how to attach Drag and Drop to a given textarea.
eads@4: */
eads@2: function dnd_test_form_alter(&$form, &$form_state) {
eads@2: if ($form['#id'] == 'node-form' && $form['type']['#value'] == 'page') {
eads@2: drupal_add_css(drupal_get_path('module', 'dnd_test') .'/dnd_test.css');
eads@2: $form['body_field']['body']['#dnd-enabled'] = TRUE;
eads@2: $form['body_field']['body']['#dnd-settings'] = array(
eads@2: 'drop_selector' => '#edit-body-dnd-library .drop',
eads@2: 'url' => 'dnd-test/library',
eads@2: );
eads@2: $form['body_field']['body']['#rows'] = 28;
eads@2: }
eads@2: }
eads@2:
eads@4: /**
eads@4: * Implementation of hook_theme().
eads@4: */
eads@4: function dnd_test_theme() {
eads@4: return array(
eads@4: 'dnd_editor_item' => array(
eads@4: 'arguments' => array('i' => NULL, 'size' => NULL),
eads@4: 'template' => 'dnd-editor-item',
eads@4: ),
eads@4: 'dnd_library_item' => array(
eads@4: 'arguments' => array('i' => NULL),
eads@4: 'template' => 'dnd-library-item',
eads@4: ),
eads@17: 'dnd_library_preview' => array(
eads@17: 'arguments' => array('i' => NULL),
eads@17: 'template' => 'dnd-library-preview',
eads@17: ),
eads@4: );
eads@4: }
eads@4:
eads@4: /**
eads@4: * Page call back that returns some JSON
eads@4: */
eads@2: function dnd_test_library() {
eads@4: $page = ($_GET['page']) ? $_GET['page'] : 1;
eads@4: $test_library = dnd_test_generate_library($page);
eads@4: return drupal_json(array(
eads@4: 'header' => '
'. t('Test library: Page @page', array('@page' => $page)) .'
',
eads@4: 'library' => $test_library['library'],
eads@4: 'editor_representations' => $test_library['editor_representations'],
eads@17: 'library_previews' => $test_library['library_previews'],
eads@4: 'footer' => '',
eads@4: ));
eads@4: }
eads@2:
eads@4: /**
eads@4: * Create contrived output
eads@4: */
eads@10: function dnd_test_generate_library($page = 1, $limit = 12) {
eads@4: $start = ($page * $limit) - ($limit);
eads@4: $end = $page * $limit;
eads@4:
eads@4: $library = '';
eads@4: $editor_representations = array();
eads@17: $library_previews = array();
eads@4: for ($i=$start + 1; $i < $end + 1; $i++) {
eads@4: $library .= theme('dnd_library_item', $i);
eads@4: $editor_representations += dnd_editor_items($i);
eads@17: $library_previews['dnd-test-'. $i] = theme('dnd_library_preview', $i);
eads@4: }
eads@4: return array(
eads@4: 'library' => $library,
eads@4: 'editor_representations' => $editor_representations,
eads@17: 'library_previews' => $library_previews,
eads@2: );
eads@4: }
eads@4:
eads@4: /**
eads@4: * Theme wrapper that spins out multiple library representations for a given
eads@14: * editor representation. This is because we want to demonstrate how to allow
eads@4: * for multiple versions (i.e. different sizes) of a single item
eads@4: */
eads@4: function dnd_editor_items($i) {
eads@4: $item = array();
eads@4: foreach(array(t('S'), t('M'), t('L')) as $size) {
eads@12: $item[$i .'-'. $size] = theme('dnd_editor_item', $i, $size);
eads@2: }
eads@4: return $item;
eads@2: }
eads@4:
eads@4: /**
eads@17: * Completely contrived library preview theme function
eads@17: */
eads@17: function template_preprocess_dnd_library_preview(&$variables) {
eads@17: template_preprocess_dnd_library_item($variables);
eads@17:
eads@17: $variables['id'] = 'dnd-preview-'. $variables['i'];
eads@18: $variables['image'] = '
';
eads@17:
eads@17: $variables['description'] = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
eads@17: }
eads@17:
eads@17:
eads@17: /**
eads@4: * Completely contrived edit item theme function
eads@4: */
eads@4: function template_preprocess_dnd_library_item(&$variables) {
eads@12: global $_SERVER;
eads@12:
eads@4: $i = $variables['i'];
eads@9:
eads@9: if ($i % 3 == 0) {
eads@9: $img = 3;
eads@9: }
eads@9: else if ($i % 2 == 0) {
eads@9: $img = 2;
eads@9: }
eads@9: else {
eads@9: $img = 1;
eads@9: }
eads@9:
eads@17: $variables['img_num'] = $img;
eads@17: $variables['id'] = 'dnd-test-'. $i;
eads@14: $variables['image'] = '
';
eads@4: $variables['title'] = t('Lorem Ipsum @count', array('@count' => $i));
eads@4: $variables['date'] = 'Feb 18 2009';
eads@4: $variables['author'] = 'David Eads';
eads@4: foreach(array(t('S'), t('M'), t('L')) as $size) {
eads@14: $sizes[] = '
';
eads@4: }
eads@4: $variables['sizes'] = '- '. implode('
- ', $sizes) .'
';
eads@4: }
eads@4:
eads@4:
eads@4: function template_preprocess_dnd_editor_item(&$variables) {
eads@4: list($i, $size) = array($variables['i'], $variables['size']);
eads@9:
eads@9: if ($i % 3 == 0) {
eads@9: $img = 3;
eads@9: }
eads@9: else if ($i % 2 == 0) {
eads@9: $img = 2;
eads@9: }
eads@9: else {
eads@9: $img = 1;
eads@9: }
eads@15: $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-'. $size .'.jpg', 'foo', 'foo', array('class' => 'dnd-dropped'));
eads@4: }