You are here

popup.module in Popup 6.x

Same filename and directory in other branches
  1. 8 popup.module
  2. 7 popup.module
  3. 7.x popup.module

File

popup.module
View source
<?php

/**
 * Implementation of hook_init
 *
 * Adds popup Script, settings and Style
 *
 */
function popup_init() {
  $path = drupal_get_path('module', 'popup');
  drupal_add_css($path . '/popup.css');
  drupal_add_js($path . '/popup.js');
  $effects = module_invoke_all('popup_effects');
  drupal_add_js(array(
    'popup' => array(
      'effects' => $effects,
      'linger' => variable_get('popup-hover-linger', 250),
    ),
  ), 'setting');
}

/**
 * Implementation of hook_popup_effects
 *
 * This hook allows modules to supply Javascript methods to showing/hiding
 * popups.
 *
 * @return a keyed array
 *
 * in the form:
 *
 * array(
 *   'show' => array(
 *     'effect-name' => 'javascript to show the popup',
 *     ...
 *   ),
 *   'hide' => array(
 *     'effect-name' => 'javascript to hide the popup'
 *     ...
 *   ),
 *  );
 *
 * The Javascript is executed within the context of the PopupElement wrapper
 * ojbect. The following properties are available as JQuery objects:
 *
 *  element:  The popup element wrapper
 *  title:    the title element of the popup
 *  body:     the body element of the popup. Keep in mind that the body is no
 *            longer contained within the popup element wrapper, but within its
 *            own wrapper within the #popup-active-overlay element at the end
 *            of the HTML body.
 *  wrapper:  Wrapper of the popup element body. This has the same id as the
 *            popup element, with "-active" appended.
 *  origin:   Invisible div element prepended to the element wrapper, to
 *            establish the popup top/left offset in relation to the document.
 *
 */
function popup_popup_effects() {
  return array(
    'show' => array(
      'default' => "this.body.show();",
      'fade' => "\n        if (this.opacity){\n          this.body.fadeTo('medium',this.opacity);\n        }else{\n          this.body.fadeIn('medium');\n        }",
      'slide-down' => "this.body.slideDown('medium')",
      'slide-down-fade' => "\n        this.body.animate(\n          {\n            height:'show',\n            opacity:(this.opacity ? this.opacity : 'show')\n          }, 'medium'\n        );",
    ),
    'hide' => array(
      'default' => "this.body.hide();",
      'fade' => "this.body.fadeOut('medium');",
      'slide-down' => "this.body.slideUp('medium');",
      'slide-down-fade' => "\n        this.body.animate(\n          {\n            height:'hide',\n            opacity:'hide'\n          }, 'medium'\n        );",
    ),
  );
}

/**
 * Implementation of hook_footer
 *
 * Inserts the popup overlay to embed popup bodies in.
 */
function popup_footer() {
  return '<div id="popup-active-overlay"></div>';
}

/**
 * Implementation of hook_menu
 */
function popup_menu() {
  $path = drupal_get_path('module', 'popup');
  return array(
    'admin/settings/popup' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'popup.admin.inc',
      'file path' => $path . '/includes',
      'page arguments' => array(
        'popup_admin_settings',
      ),
      'page callback' => 'drupal_get_form',
      'title' => 'Popup elements',
      'type' => MENU_NORMAL_ITEM,
    ),
    'ahah/popup' => array(
      'access arguments' => array(
        'access content',
      ),
      'file' => 'popup.util.inc',
      'file path' => $path . '/includes',
      'page callback' => 'popup_get_ahah',
      'type' => MENU_CALLBACK,
    ),
  );
}

/**
 * Implementation of hook_perm
 */
function popup_perm() {
  return array(
    'administer popup elements',
  );
}

/**
 * Implementation of hook_theme
 */
function popup_theme() {
  module_load_include('inc', 'popup', 'includes/popup.util');
  $styles = _popup_styles();
  $theme = _popup_theme_array();
  foreach ($styles as $style => $path) {
    $theme += _popup_theme_array(_popup_title_to_key($style), $path);
  }
  $theme += array(
    'popup_ahah_placeholder' => array(
      'arguments' => array(
        'type' => '',
        'attributes' => array(),
      ),
    ),
  );
  return $theme;
}

/**
 * Implementation of hook_popup_styles
 *
 * This hook allows modules to provide popup display styles. Note that the
 * templates of these styles cannot be overridden by the theme.
 *
 * @return a keyed array
 *
 * in the form:
 *
 * array(
 *  'Style name 1' => 'path/to/style-1',
 *  'Style label 2' => 'path/to/style-2',
 *  ...
 * )
 *
 * For style-1 the following files must exist in the path/to/style-1 directory:
 *
 *   popup-element-body.tpl.php
 *   popup-element-title.tpl.php
 *   popup-element.tpl.php
 *
 * For style-1 the following files may exist in the path/to/style-1 directory,
 * and will be included if present:
 *
 *   popup-element.css
 *   popup-element.js
 *
 */
function popup_popup_styles() {
  $path = drupal_get_path('module', 'popup') . '/styles';
  return array(
    'McPopup' => $path . '/McPopup',
    'Bent white' => $path . '/bent_white',
    'Black' => $path . '/black',
    'Obsidian' => $path . '/obsidian',
    'White' => $path . '/white',
  );
}

/* ---- Preprocessors ---- */

/**
 * Popup element preprocessor
 *
 * Adds CSS of the selected style
 *
 */
function popup_preprocess_popup_element($variables) {
  module_load_include('inc', 'popup', 'includes/popup.util');
  $style = $variables['style'] ? $variables['style'] : variable_get('popup-style', 'white');
  $styles = _popup_styles();
  $path = $styles[$style];
  drupal_add_css($path . '/popup-element.css', array(
    'media' => 'screen, projection',
    'preprocess' => variable_get('popup-preprocess', FALSE),
  ));
  if (file_exists($path . '/popup-element.js')) {
    drupal_add_js($path . '/popup-element.js', 'module', 'header', FALSE, TRUE, variable_get('popup-preprocess', FALSE));
  }
}

/* ---- Theme implementations ---- */
function theme_popup_ahah_placeholder($type, $attributes) {
  $hash = _popup_cache_attributes($attributes);
  $extra = $attributes['ajax_extra'];
  return '<div class="popup-ahah-placeholder">' . t('Loading') . '<a href="/ahah/popup/' . $type . '/' . $hash . '/' . $extra . '"></a>' . '</div><noscript><p class="error">' . t('Please enable Javascript to be able to view this content.') . '</p></noscript>';
}

Functions

Namesort descending Description
popup_footer Implementation of hook_footer
popup_init Implementation of hook_init
popup_menu Implementation of hook_menu
popup_perm Implementation of hook_perm
popup_popup_effects Implementation of hook_popup_effects
popup_popup_styles Implementation of hook_popup_styles
popup_preprocess_popup_element Popup element preprocessor
popup_theme Implementation of hook_theme
theme_popup_ahah_placeholder