View source
<?php
define('DND_ID_SUFFIX', '-dnd-library');
function dnd_menu() {
$items = array();
$items['admin/settings/dnd'] = array(
'title' => 'Drag and Drop Library',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'dnd_admin_form',
),
'description' => 'Configure drag-and-drop enabled textareas.',
'access arguments' => array(
'administer dnd',
),
'file' => 'dnd.admin.inc',
);
return $items;
}
function dnd_perm() {
return array(
'administer dnd',
);
}
function dnd_theme() {
return array(
'dnd_library_wrapper' => array(
'arguments' => array(
'settings' => NULL,
'element' => NULL,
),
),
);
}
function dnd_elements() {
$type = array();
$type['textarea'] = array(
'#dnd-enabled' => FALSE,
'#dnd-settings' => NULL,
'#process' => array(
'form_expand_ahah',
'dnd_process_textarea',
),
);
return $type;
}
function dnd_process_textarea($element, $edit, $form_state, $form) {
if (isset($element['#dnd-enabled']) && $element['#dnd-enabled']) {
dnd_add_library();
$settings = array(
'library_id' => $element['#id'] . DND_ID_SUFFIX,
'url' => dnd_get_library(),
);
if (is_object($element['#dnd-settings'])) {
$settings = (array) $element['#dnd-settings'] + $settings;
}
else {
if (is_array($element['#dnd-settings'])) {
$settings = $element['#dnd-settings'] + $settings;
}
}
drupal_add_js(array(
'dndDropAreas' => array(
$element['#id'] => $settings,
),
), 'setting');
}
return $element;
}
function dnd_add_library() {
static $included = FALSE;
if (!$included) {
$included = TRUE;
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/bt/other_libs/excanvas_0002/excanvas-compressed.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/bt/other_libs/jquery.hoverIntent.minified.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/bt/jquery.bt.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/jquery.url.packed.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/jquery.fieldselection.js');
drupal_add_js('misc/jquery.form.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/jquery.draganddrop.js');
drupal_add_js(drupal_get_path('module', 'dnd') . '/js/dnd-library.js');
drupal_add_css(drupal_get_path('module', 'dnd') . '/css/dnd-library.css');
drupal_add_js(array(
'dnd' => array(
'url' => url(dnd_get_library()),
),
), 'setting');
}
}
function dnd_suppress_library($set = TRUE) {
static $suppress = FALSE;
if ($set && !$suppress) {
$suppress = TRUE;
drupal_add_js(array(
'dnd' => array(
'suppress' => 1,
),
), 'setting');
}
return $suppress;
}
function dnd_wysiwyg_plugin($editor, $version = 0) {
$plugins = array();
switch ($editor) {
case 'tinymce':
if ($version > 3) {
$plugins['forcecontainer'] = array(
'title' => t('Force Container Plugin'),
'description' => t('A custom plugin to forces a selection up to the outer container of a given element.'),
'extensions' => array(
'forcecontainer' => t('Force Container'),
),
'path' => drupal_get_path('module', 'dnd') . '/js/tinymce/forcecontainer/editor_plugin_src.js',
'load' => TRUE,
'options' => array(
'forcecontainer_class' => 'dnd-drop-wrapper',
'forcecontainer_trigger_dnd' => TRUE,
),
);
}
break;
}
return $plugins;
}
function theme_dnd_library_wrapper($settings, $element = NULL) {
return '<div id="' . $settings['library_id'] . '" class="dnd-library-wrapper"></div>';
}
function dnd_get_libraries() {
static $libraries = NULL;
if (is_null($libraries)) {
$libraries = module_invoke_all('dnd_libraries_info');
drupal_alter('dnd_libraries_info', $libraries);
}
return $libraries;
}
function dnd_get_library() {
$libraries = dnd_get_libraries();
$default = variable_get('dnd_callback_url', '');
if (isset($libraries[$default])) {
$library = $default;
}
else {
reset($libraries);
$library = key($libraries);
}
return $library;
}