Commit de658f01 authored by David Meister's avatar David Meister
Browse files

Basic functionality in place

parent d5d615eb
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -7,8 +7,13 @@
/**
 * Define constants.
 */
if(!defined('IMAGE_A_TROIS_MINIMUM_VERSION')) {
  define('IMAGE_A_TROIS_MINIMUM_VERSION', 1);
}

if(!defined('IMAGE_A_TROIS_VERSION')) {
  define('IMAGE_A_TROIS_VERSION', 1);
}

/**
* Implementation of hook_schema().
@@ -45,6 +50,16 @@ function image_a_trois_schema() {
        'length' => '255',
        'description' => 'A human readable name of an overlay.',
      ),
      'image_url' => array(
        'type' => 'varchar',
        'length' => '255',
        'description' => 'The url to the image for this overlay.',
      ),
      'paths' => array(
        'type' => 'text',
        'size' => 'normal',
        'description' => 'The paths to use this overlay on.',
      ),
    ),
    'primary key' => array('oid'),
    'unique keys' => array(
+58 −5
Original line number Diff line number Diff line
@@ -15,11 +15,15 @@ define('IMAGE_A_TROIS_VERSION', 1);
 * Implements hook_init().
 */
function image_a_trois_init() {
  $ia3_library_path = libraries_get_path('ia3');
  drupal_add_js($ia3_library_path . '/ia3.js');
  drupal_add_css($ia3_library_path . '/ia3.css');
  drupal_add_js(drupal_get_path('module', 'image_a_trois') . '/js/image_a_trois.js');
  drupal_add_library('system', 'ui.resizable');
  $overlays = ctools_export_crud_load_all('image_a_trois_overlays');
  $uri = request_path();

  foreach($overlays as $overlay) {
    if(drupal_match_path($uri, $overlay->paths)) {
      image_a_trois_overlay_enqueue($overlay);
    }
  }
  image_a_trois_overlay_dequeue();
}

/**
@@ -30,3 +34,52 @@ function image_a_trois_ctools_plugin_directory($module, $plugin) {
    return 'plugins/' . $plugin;
  }
}

/**
 * Determine whether an overlay exists.
 *
 * @param string $name
 *   The machine name for the overlay to check.
 *
 * @return  boolean
 *   TRUE if the overlay exists, FALSE otherwise.
 */
function image_a_trois_overlay_exists($name) {
  $overlays = ctools_export_crud_load_all('image_a_trois_overlays');
  return isset($overlays[$name]);
}

/**
 * Add an overlay to the current page's queue.
 */
function image_a_trois_overlay_enqueue($overlay) {
  $overlay_queue = &drupal_static(__FUNCTION__);

  if(!isset($overlay_queue[$overlay->name])) {
    $overlay_queue[$overlay->name] = $overlay->image_url;
  }
}

/**
 * Send the first three images to image_a_trois.js
 */
function image_a_trois_overlay_dequeue() {
  $overlay_queue = &drupal_static('image_a_trois_overlay_enqueue');

  if($count = count($overlay_queue)) {
    // Manage the arbitrary limit on image_a_trois.
    if($count > 3) {
      $overlay_queue = array_splice($overlay_queue, 0, 3);
    }

    // Add the libraries.
    $ia3_library_path = libraries_get_path('ia3');
    drupal_add_js($ia3_library_path . '/ia3.js');
    drupal_add_css($ia3_library_path . '/ia3.css');
    drupal_add_library('system', 'ui.resizable');

    // Add our js.
    drupal_add_js(array('image_a_trois' => $overlay_queue), array('type' => 'setting'));
    drupal_add_js(drupal_get_path('module', 'image_a_trois') . '/js/image_a_trois.js');
  }
}
+9 −3
Original line number Diff line number Diff line
(function($){
  $(function(){
    iImg = '';

    overlays = Drupal.settings.image_a_trois;
    iOpts = {
      aligned: 'center'
    };
    $.image_a_trois(iImg, iOpts);

    i = 0;
    $.each(overlays, function(key, val) {
      if (!i) {
        $.image_a_trois(val, iOpts);
      }
      i++;
    });
  });
})(jQuery);
+34 −14
Original line number Diff line number Diff line
@@ -12,29 +12,29 @@ $plugin = array(
  // The access permission to use. If not provided it will default to
  // 'administer site configuration'
  'access' => 'administer image a trois',
/*

  // You can actually define large chunks of the menu system here. Nothing
  // is required here. If you leave out the values, the prefix will default
  // to admin/structure and the item will default to the plugin name.
  'menu' => array(
    'menu prefix' => 'admin/structure',
    'menu item' => 'example',
    'menu item' => 'image-a-trois-overlays',
    // Title of the top level menu. Note this should not be translated,
    // as the menu system will translate it.
    'menu title' => 'Example',
    'menu title' => 'Image a trois overlays',
    // Description of the top level menu, which is usually needed for
    // menu items in an administration list. Will be translated
    // by the menu system.
    'menu description' => 'Administer site example objects.',
    'menu description' => 'Administer image a trois overlays.',
  ),
 */

  // These are required to provide proper strings for referring to the
  // actual type of exportable. "proper" means it will appear at the
  // beginning of a sentence.
  'title singular' => t('example'),
  'title singular proper' => t('Example'),
  'title plural' => t('examples'),
  'title plural proper' => t('Examples'),
  'title singular' => t('overlay'),
  'title singular proper' => t('Overlay'),
  'title plural' => t('overlays'),
  'title plural proper' => t('Overlays'),

  // This will provide you with a form for editing the properties on your
  // exportable, with validate and submit handler.
@@ -57,15 +57,35 @@ $plugin = array(
function image_a_trois_ctools_export_ui_form(&$form, &$form_state) {
  $overlay = $form_state['item'];

  $form['description'] = array(
  $form['info']['name']['#type'] = 'machine_name';
  $form['info']['name']['#machine_name'] = array(
    'exists' => 'image_a_trois_overlay_exists',
    'source' => array('info', 'description'),
  );

  $form['info']['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#title' => t('Overlay name'),
    '#id' => 'overlay-description',
    '#description' => t('The human readable name or description of this preset.'),
    '#default_value' => $overlay->description,
    '#required' => true,
    '#required' => TRUE,
    '#weight' => -1,
  );

  $form['info']['image_url'] = array(
    '#title' => t('Image url'),
    '#type' => 'textfield',
    '#description' => t('A relative or absolute url to the image for this overlay.'),
    '#default_value' => $overlay->image_url,
  );

  $form['info']['paths'] = array(
    '#title' => t('Overlay paths'),
    '#type' => 'textarea',
    '#description' => t('The internal paths this overlay should be used on. One path per line and <front> is the home page.'),
    '#default_value' => $overlay->paths,
  );

  $form['image_a_trois']['#collapsible'] = true;
  $form['image_a_trois']['#tree'] = true;
}