You are here

isotope.module in Isotope (with Masonry and Packery) 7

Same filename and directory in other branches
  1. 8 isotope.module
  2. 6 isotope.module
  3. 7.2 isotope.module

Defines the default hooks that the history js module implements.

File

isotope.module
View source
<?php

/**
 * @file
 * Defines the default hooks that the history js module implements.
 */

/**
 * Implements hook_permission().
 */
function isotope_permission() {
  return array(
    'administer isotope' => array(
      'title' => t('Administer Isotope JS'),
      'description' => t('Set configuration options for Isotope.js'),
    ),
  );
}

/**
 * Implements hook_menu().
 *
 * Defines the admin settings page for the module
 */
function isotope_menu() {
  $items['admin/config/user-interface/isotope'] = array(
    'title' => 'Isotope.js Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'isotope_admin',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'access administer isotope',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'includes/isotope.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_init().
 *
 * Checks for conflicts, and displays warnings if they are detected
 * Adds the configured library javascript to the site
 */
function isotope_init() {
  drupal_add_library('isotope', 'jquery.isotope', TRUE);
  if (variable_get('isotope_css', TRUE)) {
    drupal_add_css(drupal_get_path('module', 'isotope') . '/css/isotope.css');
  }
}

/**
 * Implements hook_page_build().
 */
function isotope_page_build(&$page) {
  if (module_exists('context')) {
    if ($plugin = context_get_plugin('reaction', 'isotope')) {
      $plugin
        ->execute();
    }
  }
}

/**
 * Implements hook_library().
 *
 * Checks to see if the Library exists, and makes it available
 * with the settings configured by the admin_settings form
 */
function isotope_library() {
  $libraries = array();
  $libpath = libraries_get_path('isotope');
  $jspath = array();
  $jspath['jquery.isotope'] = $libpath . '/jquery.isotope.min.js';
  $jspath['jquery.infinitescroll'] = $libpath . '/js/jquery.infinitescroll.min.js';
  $jspath['jquery.bbq'] = $libpath . '/js/jquery.ba-bbq.min.js';
  $jspath['isotope.jquery'] = $libpath . '/js/jquery-1.7.1.min.js';
  $dependencies = array();
  $settings = variable_get('isotope_libraries', array());
  $useisobbq = !empty($settings['jquery.ba-bbq']);
  $useisoscroll = !empty($settings['jquery.infinitescroll']);
  $libraries['jquery.isotope'] = array(
    'title' => 'David Desandro\'s Isotope.js',
    'website' => 'https://github.com/desandro/isotope/',
    'version' => '1.5.03',
    'js' => array(
      $jspath['jquery.isotope'] => array(),
    ),
    'dependencies' => array(),
  );
  $libraries['jquery.infinitescroll'] = array(
    'title' => 'David Desandro\'s Isotope.js',
    'website' => 'https://github.com/desandro/isotope/',
    'version' => '2.0b2.110713',
    'js' => array(
      $jspath['jquery.infinitescroll'] => array(),
    ),
  );
  $libraries['jquery.bbq'] = array(
    'title' => 'jQuery BBQ',
    'website' => 'http://benalman.com/projects/jquery-bbq-plugin/',
    'version' => '1.2.1',
    'js' => array(
      $jspath['jquery.bbq'] => array(),
    ),
  );
  if ($useisoscroll) {
    $libraries['jquery.isotope']['dependencies'][] = array(
      'isotope',
      'jquery.infinitescroll',
    );
  }
  if ($useisobbq) {
    $libraries['jquery.isotope']['dependencies'][] = array(
      'system',
      'jquery.bbq',
    );
  }
  return $libraries;
}

/**
 * Implements hook_library_alter().
 */
function isotope_library_alter(&$libraries, $module) {
  module_load_include('module', 'libraries');
  $libpath = libraries_get_path('isotope');
  $settings = variable_get('isotope_libraries', array());
  $useisobbq = !empty($settings['jquery.ba-bbq']);
  $useisojq = !empty($settings['jquery-1.7.1']);
  if (is_dir($libpath) != TRUE) {
    if ($useisobbq && $module == 'system' && isset($libraries['jquery.bbq'])) {
      $bbqpath = $libpath . '/js/jquery.ba-bbq.min.js';
      $libraries['jquery.bbq']['version'] = '1.2.1-isotope';
      $libraries['jquery.bbq']['js'] = array(
        $bbqpath => array(),
      );
    }
    if ($useisojq && $module == 'system' && isset($libraries['jquery'])) {
      $jqpath = $libpath . '/js/jquery-1.7.1.min.js';
      $libraries['jquery']['version'] = '1.7.1-isotope';
      $oldsettings = array();
      if (isset($libraries['jquery']['js']['misc/jquery.js'])) {
        $oldsettings = $libraries['jquery']['js']['misc/jquery.js'];
      }
      $libraries['jquery']['js'] = array(
        $jqpath => $oldsettings,
      );
    }
  }
}

/**
 * Implements hook_context_plugins().
 */
function isotope_context_plugins() {
  $plugins = array();
  $plugins['isotope_reaction'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'isotope') . '/plugins',
      'file' => 'isotope_reaction.inc',
      'class' => 'isotope_reaction',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_context_registry().
 */
function isotope_context_registry() {
  return array(
    'reactions' => array(
      'isotope' => array(
        'title' => t('Isotope'),
        'description' => t('Set a basic Isotope configuration.'),
        'plugin' => 'isotope_reaction',
      ),
    ),
  );
}