eads@2: 'Drag and drop test library', eads@28: 'page callback' => 'dnd_test_dnd_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: $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@28: 'url' => 'dnd-test/library/?json', 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@28: * Overloaded page callback. eads@4: */ eads@28: function dnd_test_dnd_library($element = NULL) { eads@28: $page = (array_key_exists('page', $_GET)) ? $_GET['page'] : 1; eads@28: drupal_add_css(drupal_get_path('module', 'dnd_test') .'/dnd_test.css'); eads@28: drupal_json(dnd_test_generate_library($page)); eads@4: } eads@2: eads@4: /** eads@4: * Create contrived output eads@4: */ eads@24: function dnd_test_generate_library($page = 1, $limit = 8) { eads@4: $start = ($page * $limit) - ($limit); eads@4: $end = $page * $limit; eads@4: eads@28: $library = theme('dnd_library_header', $page); 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@24: $item[$i .'-'. $size] = array( eads@24: 'body' => theme('dnd_editor_item', $i, $size), eads@24: 'title' => 'Item '. $i .'-S', eads@24: ); 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@21: $variables['image'] = ''; eads@17: eads@21: $variables['description'] = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; 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'] = ''; 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@23: $variables['image'] = theme('image', drupal_get_path('module', 'dnd_test') .'/img/item-'. $img .'-'. $size .'.jpg', '', '', array('class' => 'dnd-dropped', 'id' => 'dnd-id-'. $i)); eads@4: } eads@20: eads@20: function template_preprocess_dnd_library_header(&$variables) {}