From e709f446937a4502544265c19f65396cd24a6581 Thu, 5 Jan 2012 11:32:42 +0100
From: Bram Goffings <bramgoffings@gmail.com>
Date: Thu, 5 Jan 2012 11:26:27 +0100
Subject: [PATCH] fullcalendar flyout

diff --git a/fullcalendar_flyout/fullcalendar_flyout.info b/fullcalendar_flyout/fullcalendar_flyout.info
new file mode 100644
index 0000000..b56722e
--- /dev/null
+++ b/fullcalendar_flyout/fullcalendar_flyout.info
@@ -0,0 +1,5 @@
+name = FullCalendar flyout
+description = Beautytips integration for the fullcalendar module.
+core = 7.x
+package = FullCalendar
+dependencies[] = fullcalendar
diff --git a/fullcalendar_flyout/fullcalendar_flyout.module b/fullcalendar_flyout/fullcalendar_flyout.module
new file mode 100644
index 0000000..c5e9bb3
--- /dev/null
+++ b/fullcalendar_flyout/fullcalendar_flyout.module
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * Add beautytips integration
+ */
+ if (module_exists('beautytips') && !function_exists('beautytips_fullcalendar_api')) {
+  function beautytips_fullcalendar_api() {
+    return array(
+      'api' => fullcalendar_api_version(),
+      'path' => drupal_get_path('module', 'fullcalendar_flyout') . '/includes',
+      'js' => TRUE,
+    );
+  }
+}
diff --git a/fullcalendar_flyout/includes/beautytips.fullcalendar.inc b/fullcalendar_flyout/includes/beautytips.fullcalendar.inc
new file mode 100644
index 0000000..2591f46
--- /dev/null
+++ b/fullcalendar_flyout/includes/beautytips.fullcalendar.inc
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * Implements hook_fullcalendar_option_info().
+ */
+function beautytips_fullcalendar_option_info() {
+  return array(
+    'beautytips' => array(
+      'name' => t('Beautytips'),
+      'js' => TRUE,
+      'parent' => 'fullcalendar_flyout',
+    ),
+  );
+}
+
+/**
+ * Implements hook_fullcalendar_option_definition().
+ */
+function beautytips_fullcalendar_option_definition() {
+  $options['beautytips']['contains'] = array(
+    'beautytips' => array(
+      'default' => FALSE,
+      'bool' => TRUE,
+    ),
+    'beautytipsStyle' => array('default' => 'default'),
+    'beautytipsSeperator' => array('default' => ' - '),
+    'beautytipsFields' => array('default' => ''),
+    'beautytipsText' => array('default' => ''),
+    'beautytipsOptions' => array('default' => array()),
+  );
+  return $options;
+}
+
+/**
+ * Implements hook_fullcalendar_options_form().
+ */
+function beautytips_fullcalendar_options_form(&$form, &$form_state, &$view) {
+    $form['beautytips']['beautytips'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show a beautytip when hovering an event'),
+      '#default_value' => $view->options['beautytips']['beautytips'],
+    );
+    $form['beautytips']['beautytipsStyle'] = array(
+      '#type' => 'select',
+      '#title' => t('Style'),
+      '#options' => array_keys(beautytips_get_styles()),
+      '#default_value' => $view->options['beautytips']['beautytipsStyle'],
+      '#description' => t('Choose the style for the beautytip'),
+      '#dependency' => array('edit-style-options-beautytips-beautytips' => array(1)),
+    );
+    $form['beautytips']['beautytipsFields'] = array(
+      '#type' => 'select',
+      '#title' => t('Beautytips Fields'),
+      '#options' => $view->display->handler->get_field_labels(),
+      '#default_value' => $view->options['beautytips']['beautytipsFields'],
+      '#description' => t('Select one or more fields for the beautytip.'),
+      '#multiple' => TRUE,
+      '#size' => count($field_options),
+      '#dependency' => array('edit-style-options-beautytips-beautytips' => array(1)),
+    );
+    $form['beautytips']['beautytipsSeperator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Seperator'),
+      '#default_value' => $view->options['beautytips']['beautytipsSeperator'],
+      '#dependency' => array('edit-style-options-beautytips-beautytips' => array(1)),
+    );
+}
+
+/**
+ * Implements hook_fullcalendar_options_submit().
+ */
+function beautytips_fullcalendar_options_submit($form, &$form_state) {
+  $values = &$form_state['values']['style_options']['beautytips'];
+
+  // Fetch beautytips style
+  $beautytipsStyles = array_keys(beautytips_get_styles());
+  $beautytipsStyle = $beautytipsStyles[$values['beautytipsStyle']];
+
+  $values['beautytipsOptions'] = beautytips_get_style($beautytipsStyle);
+
+  // Don't hardcode this and move this to another function
+  $values['beautytipsText'] = 'test';
+}
+
+/**
+ * Implements hook_fullcalendar_options_process.
+ */
+function beautytips_fullcalendar_options_process(&$variables, &$settings) {
+  global $language;
+  drupal_add_library('beautytips', 'beautytips-module');
+  // Needed for internet explorer
+  drupal_add_library('beautytips', 'excanvas_r3');
+  // Needed for rtl
+  if($language->direction) {
+    drupal_add_library('beautytips', 'beautytips-ltr');
+  }
+}
diff --git a/fullcalendar_flyout/js/beautytips.fullcalendar.js b/fullcalendar_flyout/js/beautytips.fullcalendar.js
new file mode 100644
index 0000000..e5d8df2
--- /dev/null
+++ b/fullcalendar_flyout/js/beautytips.fullcalendar.js
@@ -0,0 +1,19 @@
+(function($) {
+
+Drupal.fullcalendar.plugins.beautytips = {
+  options: function (fullcalendar) {
+    var settings = Drupal.settings.fullcalendar[fullcalendar.dom_id].beautytips;
+
+    if (!settings.beautytips)
+      return;
+
+    return {
+      eventRender: function(event, element) {
+        // The beautytipsText should be part of an array indexed on the event id
+        element.bt(settings.beautytipsText, settings.beautytipsOptions);
+      }
+    };
+  }
+};
+
+})(jQuery);
