123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- function ctools_modal_add_js() {
-
- static $done = FALSE;
- if ($done) {
- return;
- }
- $settings = array(
- 'CToolsModal' => array(
- 'loadingText' => t('Loading...'),
- 'closeText' => t('Close Window'),
- 'closeImage' => theme('image', array(
- 'path' => ctools_image_path('icon-close-window.png'),
- 'title' => t('Close window'),
- 'alt' => t('Close window'),
- )),
- 'throbber' => theme('image', array(
- 'path' => ctools_image_path('throbber.gif'),
- 'title' => t('Loading...'),
- 'alt' => t('Loading'),
- )),
- ),
- );
- drupal_add_js($settings, 'setting');
- drupal_add_library('system', 'jquery.form');
- drupal_add_library('system', 'drupal.progress');
- drupal_add_library('system', 'drupal.ajax');
- drupal_add_library('system', 'ui');
- ctools_add_js('modal');
- ctools_add_css('modal');
- $done = TRUE;
- }
- function ctools_modal_add_plugin_js($plugins) {
- $css = array();
- $js = array(drupal_get_path('module', 'ctools') . '/js/dependent.js' => TRUE);
- foreach ($plugins as $subtype) {
- if (isset($subtype['js'])) {
- foreach ($subtype['js'] as $file) {
- if (file_exists($file)) {
- $js[$file] = TRUE;
- }
- else if (file(exists($subtype['path'] . '/' . $file))) {
- $js[$subtype['path'] . '/' . $file] = TRUE;
- }
- }
- }
- if (isset($subtype['css'])) {
- foreach ($subtype['css'] as $file) {
- if (file_exists($file)) {
- $css[$file] = TRUE;
- }
- else if (file(exists($subtype['path'] . '/' . $file))) {
- $css[$subtype['path'] . '/' . $file] = TRUE;
- }
- }
- }
- }
- foreach (array_keys($js) as $file) {
- drupal_add_js($file);
- }
- foreach (array_keys($css) as $file) {
- drupal_add_css($file);
- }
- }
- function ctools_modal_command_display($title, $html) {
- if (is_array($html)) {
- $html = drupal_render($html);
- }
- return array(
- 'command' => 'modal_display',
- 'title' => $title,
- 'output' => $html,
- );
- }
- function ctools_modal_command_dismiss() {
- return array(
- 'command' => 'modal_dismiss',
- );
- }
- function ctools_modal_command_loading() {
- return array(
- 'command' => 'modal_loading',
- );
- }
- function ctools_modal_image_button($image, $dest, $alt, $class = '') {
- return ctools_ajax_text_button(theme('image', array('path' => $image)), $dest, $alt, $class, 'ctools-use-modal');
- }
- function ctools_modal_text_button($text, $dest, $alt, $class = '') {
- return ctools_ajax_text_button($text, $dest, $alt, $class, 'ctools-use-modal');
- }
- function ctools_modal_form_wrapper($form_id, &$form_state) {
-
-
-
- if (!empty($form_state['reset_html_ids']) && !empty($_POST['ajax_html_ids'])) {
- unset($_POST['ajax_html_ids']);
- }
-
- $form_state += array(
- 're_render' => FALSE,
- 'no_redirect' => !empty($form_state['ajax']),
- );
- $output = drupal_build_form($form_id, $form_state);
- if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
- return ctools_modal_form_render($form_state, $output);
- }
- return $output;
- }
- function ctools_modal_form_render($form_state, $output) {
- if (is_array($output)) {
- $output = drupal_render($output);
- }
- $title = empty($form_state['title']) ? drupal_get_title() : $form_state['title'];
-
- if ($messages = theme('status_messages')) {
- $output = $messages . $output;
- }
- $commands = array();
-
- $commands[] = ctools_modal_command_display($title, $output);
- return $commands;
- }
- function ctools_modal_render($title, $output) {
- $commands = array();
- $commands[] = ctools_modal_command_display($title, $output);
- print ajax_render($commands);
- }
|