summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorymakux2012-10-09 00:57:12 (GMT)
committer ymakux2012-10-09 00:57:12 (GMT)
commitc5535423cd40558029a6f2c5f843cf9154dcb382 (patch)
tree0c65c509f748a2bb61db4b66f12b4c57fcc4c371
Initial commit
-rw-r--r--bgstretcher.admin.inc1004
-rw-r--r--bgstretcher.info4
-rw-r--r--bgstretcher.install85
-rw-r--r--bgstretcher.module736
-rw-r--r--bgstretcher_context_reaction_bgstretcher.inc42
-rw-r--r--lib/bgstretcher.css31
-rw-r--r--lib/bgstretcher.js626
7 files changed, 2528 insertions, 0 deletions
diff --git a/bgstretcher.admin.inc b/bgstretcher.admin.inc
new file mode 100644
index 0000000..5b0a669
--- /dev/null
+++ b/bgstretcher.admin.inc
@@ -0,0 +1,1004 @@
+<?php
+
+/**
+ * @file
+ * Form builders, form validation and submit callbacks.
+ */
+
+/**
+ * Form builder. Allows administrator to add new or update an existing background stretcher.
+ */
+function bgstretcher_admin($form, &$form_state, $id = NULL, $action = NULL) {
+
+ $edit = FALSE;
+ if ($action == 'edit' && $id) {
+ // Get the existing bgstretcher from DB
+ $bgstretcher = bgstretcher_bgstretcher_get($id);
+ $settings = $bgstretcher['settings'];
+ $settings_js = $bgstretcher['settings']['js'];
+ // Set boolean flag to indicate that we're on "edit" mode now.
+ $edit = TRUE;
+ }
+
+ // We want to deal with nested form array
+ $form['#tree'] = TRUE;
+
+ $form['id'] = array(
+ '#type' => 'value',
+ '#value' => is_numeric($id) ? $id : NULL,
+ );
+
+ $form['id'] = array(
+ '#type' => 'value',
+ '#value' => is_numeric($id) ? $id : NULL,
+ );
+
+ // Main background stretcher settings
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#required' => TRUE,
+ '#default_value' => $edit ? check_plain($bgstretcher['name']) : '',
+ '#weight' => -10,
+ );
+
+ $form['css'] = array(
+ '#type' => 'textfield',
+ '#title' => t('CSS ID'),
+ '#required' => TRUE,
+ '#weight' => -5,
+ '#default_value' => $edit ? check_plain($bgstretcher['css']) : '',
+ '#description' => t("bgStretcher plugin will automatically build structure for the images list in a DOM tree.
+ This parameter is ID for the images holder.
+ Try inspecting the tree with a FireBug to get an idea how it's constructed."),
+ );
+
+ // Additional settings under vertical tabs
+ $form['settings'] = array(
+ '#type' => 'vertical_tabs',
+ '#weight' => 0,
+ );
+
+ $form['settings']['visibility'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Visibility'),
+ '#collapsible' => FALSE,
+ '#group' => 'additional_settings',
+ );
+
+ $form['settings']['source'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Source'),
+ '#collapsible' => FALSE,
+ '#group' => 'additional_settings',
+ );
+
+ $form['settings']['js'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('JS settings'),
+ '#collapsible' => FALSE,
+ '#group' => 'additional_settings',
+ );
+
+ $form['settings']['visibility']['visibility'] = array(
+ '#type' => 'radios',
+ '#title' => t('Show on specific pages'),
+ '#options' => array(t('All pages except those listed'), t('Only the listed pages')),
+ '#default_value' => $edit ? check_plain($bgstretcher['settings']['visibility']['visibility']) : 0,
+ );
+
+ $form['settings']['visibility']['path'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Paths'),
+ '#rows' => 5,
+ '#default_value' => $edit ? $bgstretcher['settings']['visibility']['path'] : '',
+ '#description' => t("Specify pages by using their paths.
+ Enter one path per line. The '*' character is a wildcard.
+ Example paths are %user for the current user's page and %user-wildcard for every user page.
+ %front is the front page.", array('%user' => 'user', '%user-wildcard' => 'user/*', '%front' => '<front>')),
+ );
+
+ // This container used as wrapper for ajax callback
+ $form['settings']['source']['wrapper'] = array(
+ '#type' => 'container',
+ '#prefix' => '<div id="bgstretcher-source-wrapper">',
+ '#suffix' => '</div>',
+ );
+
+ // Currently supported the following slide sources
+ // TODO: use a hook?
+ $options = array();
+ $options['upload'] = t('Uploaded images');
+ $options['node'] = t('Nodes');
+ $options['url'] = t('Url');
+
+ // If Views module installed, we can also use a view as slides's source
+ if (module_exists('views')) {
+ $options['view'] = t('View');
+ }
+
+ $form['settings']['source']['wrapper']['source'] = array(
+ '#type' => 'select',
+ '#title' => t('Slides source'),
+ '#options' => $options,
+ '#default_value' => $edit ? check_plain($bgstretcher['settings']['source']['source']) : 'upload',
+ '#ajax' => array(
+ 'callback' => 'bgstretcher_admin_ajax_callback',
+ 'wrapper' => 'bgstretcher-source-wrapper',
+ ),
+ );
+
+ if (isset($form_state['values']['settings']['source']['wrapper']['source']) || $edit) {
+
+ if ($edit) {
+ if (!empty($form_state['values']['settings']['source']['wrapper']['source'])) {
+ $source = $form_state['values']['settings']['source']['wrapper']['source'];
+ }
+ else {
+ $source = $settings['source']['source'];
+ }
+ }
+ else {
+ $source = $form_state['values']['settings']['source']['wrapper']['source'];
+ }
+
+ if ($source == 'node') {
+ $options = array();
+ $instances = field_info_instances('node');
+ $node_types = node_type_get_types();
+
+ foreach ($instances as $node_type => $fields) {
+ $options[$node_type] = check_plain($node_types[$node_type]->name);
+ }
+
+ if (!empty($options)) {
+ $default_node_type = $edit ? $settings['source']['node']['type'] : NULL;
+ $form['settings']['source']['wrapper']['node']['type'] = array(
+ '#type' => 'select',
+ '#title' => t('Node type'),
+ '#required' => TRUE,
+ '#options' => $options,
+ '#default_value' => $default_node_type,
+ '#ajax' => array(
+ 'callback' => 'bgstretcher_admin_ajax_callback',
+ 'wrapper' => 'bgstretcher-source-wrapper',
+ ),
+ );
+
+ if ($edit) {
+ if (!empty($form_state['values']['settings']['source']['wrapper']['node']['type'])) {
+ $node_type = $form_state['values']['settings']['source']['wrapper']['node']['type'];
+ }
+ else {
+ $node_type = $settings['source']['node']['type'];
+ }
+ }
+ else {
+ $node_type = $form_state['values']['settings']['source']['wrapper']['node']['type'];
+ }
+
+ $options = array();
+ foreach ($instances[$node_type] as $field) {
+ if ($field['widget']['module'] == 'image') {
+ $options[$field['field_name']] = t('@human_name (@system_name)', array(
+ '@human_name' => $field['label'], '@system_name' => $field['field_name']));
+ }
+ }
+
+ if (!empty($options)) {
+ $default_image_field = $edit ? $settings['source']['node']['image_field'] : NULL;
+ $form['settings']['source']['wrapper']['node']['image_field'] = array(
+ '#type' => 'select',
+ '#title' => t('Image field'),
+ '#required' => TRUE,
+ '#options' => $options,
+ '#default_value' => $default_image_field,
+ );
+ }
+ }
+ }
+
+ if ($source == 'view' && module_exists('views')) {
+ // Get all available views
+ $views = views_get_all_views();
+ $options = array();
+ foreach ($views as $view) {
+ $options[$view->name] = t('@human_name (@system_name)', array(
+ '@human_name' => $view->human_name, '@system_name' => $view->name));
+ }
+
+ if (!empty($options)) {
+ $default_view = $edit ? $settings['source']['view']['view'] : NULL;
+ $form['settings']['source']['wrapper']['view']['view'] = array(
+ '#type' => 'select',
+ '#title' => t('View'),
+ '#required' => TRUE,
+ '#options' => $options,
+ '#default_value' => $default_view,
+ '#ajax' => array(
+ 'callback' => 'bgstretcher_admin_ajax_callback',
+ 'wrapper' => 'bgstretcher-source-wrapper',
+ ),
+ );
+
+ if ($edit) {
+ $view = $settings['source']['view']['view'];
+ if (!empty($form_state['values']['settings']['source']['wrapper']['view']['view'])) {
+ $view = $form_state['values']['settings']['source']['wrapper']['view']['view'];
+ }
+ }
+ else {
+ $view = $form_state['values']['settings']['source']['wrapper']['view']['view'];
+ }
+
+ $options = array();
+ if (!empty($views[$view]->display)) {
+ foreach ($views[$view]->display as $display => $data) {
+ if (!empty($data->display_options['fields'])) {
+ $options[$display] = check_plain($data->display_title);
+ }
+ }
+ }
+
+ if (!empty($options)) {
+
+ $default_display = $edit ? $settings['source']['view']['display'] : NULL;
+ $form['settings']['source']['wrapper']['view']['display'] = array(
+ '#type' => 'select',
+ '#title' => t('Display'),
+ '#required' => TRUE,
+ '#options' => $options,
+ '#default_value' => $default_display,
+ '#ajax' => array(
+ 'callback' => 'bgstretcher_admin_ajax_callback',
+ 'wrapper' => 'bgstretcher-source-wrapper',
+ ),
+ );
+ }
+
+ if ($edit) {
+ if (!empty($form_state['values']['settings']['source']['wrapper']['view']['display'])) {
+ $display = $form_state['values']['settings']['source']['wrapper']['view']['display'];
+ }
+ else {
+ $display = $settings['source']['view']['display'];
+ }
+ }
+ else {
+ $display = $form_state['values']['settings']['source']['wrapper']['view']['display'];
+ }
+
+ $options = array();
+ if (!empty($views[$view]->display[$display]->display_options['fields'])) {
+ foreach ($views[$view]->display[$display]->display_options['fields'] as $field => $data) {
+ $field_info = field_info_field($data['field']);
+ if ($field_info['type'] == 'image') {
+ $options[$field] = t('@human_name (@system_name)', array(
+ '@human_name' => $data['label'], '@system_name' => $field));
+ }
+ }
+ }
+
+ if (!empty($options)) {
+ $default_value = $edit ? $settings['source']['view']['image_field'] : NULL;
+ $form['settings']['source']['wrapper']['view']['image_field'] = array(
+ '#type' => 'select',
+ '#title' => t('Image field'),
+ '#required' => TRUE,
+ '#options' => $options,
+ '#default_value' => $default_value,
+ '#ajax' => array(
+ 'callback' => 'bgstretcher_admin_ajax_callback',
+ 'wrapper' => 'bgstretcher-source-wrapper',
+ ),
+ );
+ }
+ }
+ }
+ }
+
+ /* ============================= Settings for Jquery Bgstretcher plugin =================================*/
+ $form['settings']['js']['additional_settings']['dimension'] = array(
+ '#type' => 'select',
+ '#title' => t('Original image dimension'),
+ '#default_value' => $edit ? $settings_js['additional_settings']['dimension'] : 'fixed',
+ '#options' => array(
+ 'fixed' => t('Fixed value'),
+ 'min' => t('Min value'),
+ 'max' => t('Max value'),
+ 'average' => t('Average value'),
+ ),
+ );
+
+ $form['settings']['js']['additional_settings']['image_style'] = array(
+ '#type' => 'select',
+ '#title' => t('Use image style'),
+ '#default_value' => $edit ? $settings_js['additional_settings']['image_style'] : '',
+ '#options' => image_style_options(),
+ );
+
+ $form['settings']['js']['additional_settings']['h'] = array(
+ '#markup' => '<h3>' . t('Main JS settings') . '</h3>',
+ );
+
+ $form['settings']['js']['resizeProportionally'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Resize proportionally'),
+ '#default_value' => $edit ? $settings_js['resizeProportionally'] : 1,
+ '#description' => t('Indicates if background image(s) will be resized proportionally or not.'),
+ );
+
+ $form['settings']['js']['resizeAnimate'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Animated resize'),
+ '#default_value' => $edit ? $settings_js['resizeAnimate'] : 0,
+ '#description' => t('Indicates if background image(s) will be resized with animation.
+ Be careful, this may slow down some PCs if your images are large.'),
+ );
+
+ $form['settings']['js']['imageWidth'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Image width'),
+ '#default_value' => $edit ? $settings_js['imageWidth'] : 1024,
+ '#description' => t("Original image's width."),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="settings[js][additional_settings][dimension]"]' => array('value' => 'fixed'),
+ ),
+ ),
+ );
+
+ $form['settings']['js']['imageHeight'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Image height'),
+ '#default_value' => $edit ? $settings_js['imageHeight'] : 768,
+ '#description' => t("Original image's height."),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="settings[js][additional_settings][dimension]"]' => array('value' => 'fixed'),
+ ),
+ ),
+ );
+
+ $form['settings']['js']['maxWidth'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Max image width'),
+ '#default_value' => $edit ? $settings_js['maxWidth'] : 'auto',
+ '#description' => t("Maximum image's width."),
+ );
+
+ $form['settings']['js']['maxHeight'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Max image height'),
+ '#default_value' => $edit ? $settings_js['maxHeight'] : 'auto',
+ '#description' => t("Maximum image's height."),
+ );
+
+ $form['settings']['js']['nextSlideDelay'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Next slide delay'),
+ '#default_value' => $edit ? $settings_js['nextSlideDelay'] : 3000,
+ '#description' => t('Numeric value in milliseconds. The parameter sets delay until next slide should start.'),
+ );
+
+ $form['settings']['js']['slideShowSpeed'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Show slide speed'),
+ '#default_value' => $edit ? $settings_js['slideShowSpeed'] : 'normal',
+ '#description' => t("Numeric value in milliseconds or jQuery string value ('fast', 'normal', 'slow').
+ The parameter sets the speed of transition between images."),
+ );
+
+ $form['settings']['js']['slideShow'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Show slide'),
+ '#default_value' => $edit ? $settings_js['slideShow'] : 1,
+ '#description' => t('Allows or disallows slideshow functionality.'),
+ );
+
+ $form['settings']['js']['transitionEffect'] = array(
+ '#type' => 'select',
+ '#title' => t('Transition effect'),
+ '#options' => array(
+ 'none' => t('None'),
+ 'fade' => t('Fade'),
+ 'simpleSlide' => t('Simple slide'),
+ 'superSlide' => t('superSlide')),
+ '#default_value' => $edit ? $settings_js['transitionEffect'] : 'fade',
+ '#description' => t('Transition effect'),
+ );
+
+ $form['settings']['js']['slideDirection'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Direction'),
+ '#default_value' => $edit ? $settings_js['slideDirection'] : 'N',
+ '#description' => t('Slide Diraction: N - north, S - south, W - west, E - East.
+ If "Transition Effect" = superSlide use also: NW, NE, SW, SE.'),
+ );
+
+ $form['settings']['js']['sequenceMode'] = array(
+ '#type' => 'select',
+ '#title' => t('Sequence Mode'),
+ '#options' => array(
+ 'normal' => t('Normal'),
+ 'back' => t('Back'),
+ 'random' => t('Random')),
+ '#default_value' => $edit ? $settings_js['sequenceMode'] : 'normal',
+ );
+
+ $form['settings']['js']['buttonPrev'] = array(
+ '#type' => 'textfield',
+ '#title' => t('"Previous" button class'),
+ '#default_value' => $edit ? $settings_js['buttonPrev'] : 'empty',
+ '#description' => t('Previous button CSS selector'),
+ );
+
+ $form['settings']['js']['buttonNext'] = array(
+ '#type' => 'textfield',
+ '#title' => t('"Next" button class'),
+ '#default_value' => $edit ? $settings_js['buttonNext'] : 'empty',
+ '#description' => t('Next button CSS selector'),
+ );
+
+ $form['settings']['js']['pagination'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pager class'),
+ '#default_value' => $edit ? $settings_js['pagination'] : 'empty',
+ '#description' => t('CSS selector for pagination'),
+ );
+
+ $form['settings']['js']['anchoring'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Anchoring'),
+ '#default_value' => $edit ? $settings_js['anchoring'] : 'left top',
+ '#description' => t('Anchoring bgStrtcher area regarding window'),
+ );
+
+ $form['settings']['js']['anchoringImg'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Anchoring image'),
+ '#default_value' => $edit ? $settings_js['anchoringImg'] : 'left top',
+ '#description' => t('Anchoring bgStrtcher area regarding window'),
+ );
+
+ $form['settings']['js']['preloadImg'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Preload images'),
+ '#default_value' => $edit ? $settings_js['preloadImg'] : 0,
+ '#description' => t('For Preload images use true'),
+ );
+
+ $form['settings']['js']['stratElementIndex'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Start element index'),
+ '#default_value' => $edit ? $settings_js['stratElementIndex'] : 0,
+ '#description' => t('Start element index'),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ '#weight' => 10,
+ '#validate' => array('_bgstretcher_admin_validate'),
+ );
+
+ return $form;
+}
+
+/**
+ * Form builder. Allows administrator to manage slides of particular background stretcher.
+ */
+function bgstretcher_slide_admin($form, &$form_state, $master_id = NULL, $action = NULL, $slide_id = NULL) {
+
+ $form['#tree'] = TRUE;
+
+ $css = '
+ #bgstretcher-slides-table tr.slide-disabled {
+ background-color: #FDD;
+ }';
+
+ $form['#attached']['css'][] = array(
+ 'data' => $css,
+ 'type' => 'inline',
+ );
+
+ if ($master_id) {
+ $slides = bgstretcher_slides_get($master_id, FALSE);
+ $bgstretcher = bgstretcher_bgstretcher_get($master_id);
+ $source = $bgstretcher['settings']['source']['source'];
+
+ if (!empty($slides)) {
+ uasort($slides, 'drupal_sort_weight');
+ foreach ($slides as $id => $slide) {
+ $status = $slide['enabled'];
+ switch ($source) {
+ case 'node' :
+ case 'upload' :
+ $variables = array(
+ 'style_name' => 'thumbnail',
+ 'path' => $slide['data'][$source]['image_uri'],
+ 'height' => NULL,
+ 'width' => NULL,
+ );
+ $image = theme('image_style', $variables);
+ break;
+ case 'url' :
+ $url = check_url($slide['data']['url']['url']);
+ $variables = array(
+ 'path' => $url,
+ 'width' => 100,
+ 'height' => 75,
+ );
+ $image = theme('image', $variables);
+ break;
+ }
+ $operations = array();
+ $title = $status ? t('Disable') : t('Enable');
+
+ $operations[] = array(
+ 'title' => $title,
+ 'href' => 'admin/structure/bgstretcher/operations',
+ 'query' => array(
+ 'action' => $status ? 'disable' : 'enable',
+ 'id' => $id,
+ 'subject' => 'slide',
+ 'token' => drupal_get_token(),
+ 'destination' => $_GET['q'],
+ ),
+ );
+
+ $operations[] = array(
+ 'title' => t('Delete'),
+ 'href' => 'admin/structure/bgstretcher/operations',
+ 'query' => array(
+ 'action' => 'delete',
+ 'id' => $id,
+ 'subject' => 'slide',
+ 'token' => drupal_get_token(),
+ 'destination' => $_GET['q'],
+ ),
+ );
+
+ $form['table'][$id]['enabled'] = array(
+ '#type' => 'hidden',
+ '#value' => $status,
+ '#tree' => FALSE,
+ );
+
+ $form['table'][$id]['image'] = array(
+ '#markup' => $image,
+ );
+
+ $form['table'][$id]['title'] = array(
+ '#type' => 'textfield',
+ '#title' => '<span class="element-invisible">' . t('Title') . '</span>',
+ '#default_value' => !empty($slide['data'][$slide['source']]['title']) ? $slide['data'][$slide['source']]['title'] : '',
+ );
+
+ $form['table'][$id]['weight'] = array(
+ '#type' => 'weight',
+ '#title' => '<span class="element-invisible">' . t('Weight') . '</span>',
+ '#default_value' => !empty($slide['weight']) ? $slide['weight'] : 0,
+ '#delta' => 10,
+ );
+
+ $form['table'][$id]['operations'] = array(
+ '#markup' => theme('links', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline')))),
+ );
+ }
+
+ $form['actions'] = array(
+ '#type' => 'actions',
+ '#tree' => FALSE,
+ '#weight' => 5,
+ );
+
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+ }
+
+ $form['master_id'] = array(
+ '#type' => 'value',
+ '#value' => $master_id,
+ );
+
+ $form['enabled'] = array(
+ '#type' => 'value',
+ '#value' => 1,
+ );
+
+ $form['data'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Add slide'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#tree' => TRUE,
+ '#weight' => 10,
+ );
+
+ $form['source'] = array(
+ '#type' => 'value',
+ '#value' => $source,
+ );
+
+ switch ($source) {
+ case 'upload' :
+ $form['data']['upload']['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#title-display' => 'invisible',
+ '#default_value' => '',
+ );
+
+ $form['data']['upload']['file'] = array(
+ '#type' => 'file',
+ '#title' => t('Choose a file'),
+ '#title_display' => 'invisible',
+ '#size' => 22,
+ '#theme_wrappers' => array(),
+ );
+
+ $form['data']['upload']['image_uri'] = array(
+ '#type' => 'value',
+ '#value' => NULL,
+ );
+
+
+ break;
+ case 'node' :
+ $node_type = $bgstretcher['settings']['source']['node']['type'];
+ $form['data']['node']['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Choose a node by title'),
+ '#autocomplete_path' => 'bgstretcher/autocomplete/node/' . $node_type,
+ );
+
+ $form['data']['node']['nid'] = array(
+ '#type' => 'value',
+ '#value' => NULL,
+ );
+
+
+ $form['data']['node']['image_field'] = array(
+ '#type' => 'value',
+ '#value' => $bgstretcher['settings']['source']['node']['image_field'],
+ );
+
+ $form['data']['node']['image_uri'] = array(
+ '#type' => 'value',
+ '#value' => NULL,
+ );
+ break;
+ case 'url' :
+ $form['data']['url']['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#title-display' => 'invisible',
+ '#default_value' => '',
+ );
+
+ $form['data']['url']['url'] = array(
+ '#type' => 'textfield',
+ '#title' => t('URL'),
+ '#title-display' => 'invisible',
+ '#default_value' => '',
+ );
+ break;
+ }
+
+ $form['data']['weight'] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight'),
+ '#default_value' => '',
+ '#delta' => 10,
+ '#tree' => FALSE,
+ );
+
+ $form['data']['image_url'] = array(
+ '#type' => 'value',
+ '#value' => NULL,
+ );
+
+ $form['data']['actions'] = array(
+ '#type' => 'actions',
+ '#tree' => FALSE,
+ );
+
+ $form['data']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add'),
+ '#weight' => 10,
+ '#validate' => array('bgstretcher_add_slide_validate'),
+ '#submit' => array('bgstretcher_add_slide_submit'),
+ );
+ }
+ return $form;
+}
+
+/**
+ * Confirmation form. Confirm to delete the given background stretcher's slide
+ */
+function bgstretcher_slide_delete_confirm($form, &$form_state, $id) {
+
+ $form['id'] = array(
+ '#type' => 'value',
+ '#value' => $id,
+ );
+
+ return confirm_form($form,
+ t('Are you sure you want to delete this slide?'),
+ $_GET['destination'],
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel'));
+}
+
+/**
+ * Confirmation form. Confirm to delete the given background stretcher
+ */
+function bgstretcher_delete_confirm($form, &$form_state, $id) {
+
+ $bgstretcher = bgstretcher_bgstretcher_get($id);
+ $name = $bgstretcher['name'];
+
+ $form['id'] = array(
+ '#type' => 'value',
+ '#value' => $id,
+ );
+
+ $form['name'] = array(
+ '#type' => 'value',
+ '#value' => $name,
+ );
+
+ return confirm_form($form,
+ t('Are you sure you want to delete %name and all its slides?', array('%name' => $name)),
+ 'admin/structure/bgstretcher',
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel'));
+}
+
+/**
+ * Submit callback. Delete specific bgstretcher
+ */
+function bgstretcher_delete_confirm_submit($form, &$form_state) {
+ $id = $form_state['values']['id'];
+ if ($form_state['values']['confirm'] && $id) {
+ if (bgstretcher_bgstretcher_delete($form_state['values']['id'])) {
+ if ($slides = bgstretcher_slides_get($id)) {
+ foreach ($slides as $slide_id => $slide) {
+ bgstretcher_slide_delete($slide_id);
+ }
+ }
+ drupal_set_message(t('%name deleted', array('%name' => $form_state['values']['name'])));
+ }
+ }
+ $form_state['redirect'] = 'admin/structure/bgstretcher';
+}
+
+/**
+ * Submit callback. Delete specific bgstretcher's slide
+ */
+function bgstretcher_slide_delete_confirm_submit($form, &$form_state) {
+ if ($form_state['values']['confirm'] && $form_state['values']['id']) {
+ bgstretcher_slide_delete($form_state['values']['id']);
+ }
+}
+
+/**
+ * Validate the "add slide" form
+ */
+function bgstretcher_add_slide_validate($form, &$form_state) {
+
+ $source = $form_state['values']['source'];
+ $master_id = $form_state['values']['master_id'];
+ unset($form_state['values']['table']);
+ $bgstretcher = bgstretcher_bgstretcher_get($master_id);
+ $settings = $bgstretcher['settings']['js']['additional_settings'];
+
+ switch ($source) {
+ case 'node' :
+ if (!drupal_strlen($form_state['values']['data']['node']['title'])) {
+ form_set_error('data][node][title', t('Please choose a valid node'));
+ return;
+ }
+
+ $title = $form_state['values']['data']['node']['title'];
+ $matches = array();
+ $nid = 0;
+
+ // This preg_match() looks for the last pattern like [33334] and if found extracts the numeric portion.
+ $result = preg_match('/\[([0-9]+)\]$/', $title, $matches);
+
+ if (!$result) {
+ form_set_error('data][node][title', t('Please choose a valid node'));
+ return;
+ }
+
+ if ($result > 0) {
+ $nid = $matches[$result];
+ $slides = bgstretcher_slides_get($master_id, FALSE);
+
+ if (!empty($slides)) {
+ foreach ($slides as $slide) {
+ if ($slide['data']['node']['nid'] == $nid) {
+ form_set_error('data][node][title', 'This node ID already exists in the stretcher');
+ return;
+ }
+ }
+ }
+
+ // Verify that it's a valid nid.
+ $node = node_load($nid);
+ if (empty($node)) {
+ form_set_error('data][node][title', t('No node with nid %nid can be found', array('%nid' => $nid)));
+ return;
+ }
+
+ $image_field = $form_state['values']['data']['node']['image_field'];
+ $item = reset(field_get_items('node', $node, $image_field));
+ $image_uri = $item['uri'];
+
+ form_set_value($form['data']['node']['title'], $node->title, $form_state);
+ form_set_value($form['data']['node']['nid'], $nid, $form_state);
+ form_set_value($form['data']['node']['image_uri'], $image_uri, $form_state);
+
+ if ($settings['image_style']) {
+ $image_url = image_style_url($settings['image_style'], $image_uri);
+ }
+ else {
+ $image_url = file_create_url($image_uri);
+ }
+ form_set_value($form['data']['image_url'], $image_url, $form_state);
+ }
+
+ break;
+ case 'upload' :
+ $file = file_save_upload('data', array(
+ 'file_validate_is_image' => array(), // Validates file is really an image.
+ 'file_validate_extensions' => array('png gif jpg jpeg'), // Validate extensions.
+ ));
+
+ if ($file) {
+ // Move the file into the Drupal file system
+ if ($file = file_move($file, BGSTRETCHER_UPLOAD_DIRECTORY)) {
+ $file->status = FILE_STATUS_PERMANENT;
+ $file = file_save($file);
+ form_set_value($form['data'][$source]['image_uri'], $file->uri, $form_state);
+
+ if ($settings['image_style']) {
+ $image_url = image_style_url($settings['image_style'], $file->uri);
+ }
+ else {
+ $image_url = file_create_url($file->uri);
+ }
+ form_set_value($form['data']['image_url'], $image_url, $form_state);
+ }
+ else {
+ form_set_error('data][upload][file', t('Failed to write the uploaded file the site\'s file folder.'));
+ }
+ }
+ else {
+ form_set_error('data][upload][file', t('No file was uploaded.'));
+ }
+ break;
+ case 'url' :
+ $url = $form_state['values']['data']['url']['url'];
+ if (drupal_strlen($url) != drupal_strlen(drupal_strip_dangerous_protocols($url))) {
+ form_set_error('data][url][url', t('Wrong URL format.'));
+ return;
+ }
+
+ if (!valid_url($url, $absolute = TRUE) || !valid_url($url, $absolute = FALSE)) {
+ form_set_error('data][url][url', t('Wrong URL format.'));
+ return;
+ }
+
+ form_set_value($form['data']['image_url'], $url, $form_state);
+ break;
+ }
+ form_set_value($form['data'], serialize($form_state['values']['data']), $form_state);
+}
+
+/**
+ * Submit callback. Add new background stretcher
+ */
+function bgstretcher_add_slide_submit($form, &$form_state) {
+ // Clean up submitted values
+ form_state_values_clean($form_state);
+ if (bgstretcher_slide_set($form_state['values'])) {
+ drupal_set_message(t('The configuration options have been saved.'));
+ }
+}
+
+/**
+ * Submit callback. Edit the given slide
+ */
+function bgstretcher_slide_admin_submit($form, &$form_state) {
+ // Clean up submitted values
+ form_state_values_clean($form_state);
+
+ $values = $form_state['values']['table'];
+ $master_id = $form_state['values']['master_id'];
+ $source = $form_state['values']['source'];
+
+ // Get all available slides that belong to the given background stretcher (if any)
+ $slides = bgstretcher_slides_get($master_id, FALSE);
+
+ if (!empty($values)) {
+ foreach ($values as $slide_id => $fields) {
+ $title = $fields['title'];
+ unset($fields['title']);
+
+ $existing_data = $slides[$slide_id]['data'];
+ $existing_data[$source]['title'] = $title;
+ $fields['data'] = serialize($existing_data);
+
+ if (bgstretcher_slide_set($fields, $slide_id)) {
+ drupal_set_message(t('The configuration options have been saved.'));
+ }
+ }
+ }
+}
+
+/**
+ * Validate new slide
+ */
+function _bgstretcher_admin_validate($form, &$form_state) {
+ $source = $form_state['values']['settings']['source']['wrapper']['source'];
+ $id = $form_state['values']['id'];
+
+ if (($source == 'node' || $source == 'view') &&
+ empty($form_state['values']['settings']['source']['wrapper'][$source]['image_field'])) {
+ form_set_error('', t('Please choose an image field.'));
+ return;
+ }
+
+ form_set_value($form['settings']['source'], $form_state['values']['settings']['source']['wrapper'], $form_state);
+
+ // Kick out unnecessary junk
+ unset($form_state['values']['settings']['source']['wrapper']);
+ unset($form_state['values']['settings']['settings__active_tab']);
+
+ if ($id && $source != 'url') {
+ $image_style = $form_state['values']['settings']['js']['additional_settings']['image_style'];
+
+ if ($slides = bgstretcher_slides_get($id)) {
+ foreach ($slides as $slide_id => $slide) {
+
+ $data = $slide['data'];
+ $image_uri = $data[$slide['source']]['image_uri'];
+ $image_url = $image_style ? image_style_url($image_style, $image_uri) : file_create_url($image_uri);
+ $data['image_url'] = $image_url;
+ $fields['data'] = serialize($data);
+ bgstretcher_slide_set($fields, $slide_id);
+ }
+ }
+ }
+ form_set_value($form['settings'], serialize($form_state['values']['settings']), $form_state);
+}
+
+/**
+ * Submit callback. Add/edit the given bgstretcher
+ */
+function bgstretcher_admin_submit($form, &$form_state) {
+
+ form_state_values_clean($form_state);
+ $id = $form_state['values']['id'];
+ unset($form_state['values']['id']);
+
+ if (bgstretcher_bgstretcher_set($id, $form_state['values'])) {
+ drupal_set_message(t('The configuration options have been saved.'));
+ $form_state['redirect'] = 'admin/structure/bgstretcher';
+ }
+}
+
+/**
+ * AJAX callback
+ */
+function bgstretcher_admin_ajax_callback($form, &$form_state) {
+ return $form['settings']['source']['wrapper'];
+}
diff --git a/bgstretcher.info b/bgstretcher.info
new file mode 100644
index 0000000..d0badb9
--- /dev/null
+++ b/bgstretcher.info
@@ -0,0 +1,4 @@
+name = Background Scretcher
+description = Integrates <a href="http://www.ajaxblender.com/bgstretcher-2-jquery-stretch-background-plugin-updated.html">bgStretcher</a> jquery plugin.
+core = 7.x
+package = Other
diff --git a/bgstretcher.install b/bgstretcher.install
new file mode 100644
index 0000000..0d2cfc4
--- /dev/null
+++ b/bgstretcher.install
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * @file
+ * Installation file for Background Scretcher module.
+ */
+
+/**
+ * Implements hook_schema().
+ */
+function bgstretcher_schema() {
+ $schema['bgstretchers'] = array(
+ 'fields' => array(
+ 'id' => array(
+ 'type' => 'serial',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE
+ ),
+ 'name' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ ),
+
+ 'css' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ ),
+
+ 'enabled' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+
+ 'settings' => array(
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'serialize' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ $schema['bgstretchers_slides'] = array(
+ 'fields' => array(
+ 'slide_id' => array(
+ 'type' => 'serial',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE
+ ),
+
+ 'master_id' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE
+ ),
+
+ 'source' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ ),
+
+ 'weight' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+
+ 'enabled' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE
+ ),
+
+ 'data' => array(
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'serialize' => TRUE,
+ ),
+ ),
+ 'primary key' => array('slide_id'),
+ );
+ return $schema;
+}
diff --git a/bgstretcher.module b/bgstretcher.module
new file mode 100644
index 0000000..5cae8ec
--- /dev/null
+++ b/bgstretcher.module
@@ -0,0 +1,736 @@
+<?php
+
+define('BGSTRETCHER_UPLOAD_DIRECTORY', 'public://bgstretcher');
+
+/**
+ * Implements hook_init().
+ */
+function bgstretcher_init() {
+ // Include all required .js and .css files
+ bgstretcher_bgstretcher_load();
+}
+
+/* =================================== Context integration ==================================== */
+
+/**
+ * Implements hook_context_plugins().
+ */
+function bgstretcher_context_plugins() {
+ $plugins = array();
+ $plugins['bgstretcher_context_reaction_bgstretcher'] = array(
+ 'handler' => array(
+ 'path' => drupal_get_path('module', 'bgstretcher'),
+ 'file' => 'bgstretcher_context_reaction_bgstretcher.inc',
+ 'class' => 'bgstretcher_context_reaction_bgstretcher',
+ 'parent' => 'context_reaction',
+ ),
+ );
+ return $plugins;
+}
+
+/**
+ * Implements hook_context_registry().
+ */
+function bgstretcher_context_registry() {
+ return array(
+ 'reactions' => array(
+ 'bgstretcher' => array(
+ 'title' => t('Background Stretcher'),
+ 'plugin' => 'bgstretcher_context_reaction_bgstretcher',
+ ),
+ ),
+ );
+}
+
+/**
+ * Implements hook_context_page_reaction().
+ */
+function bgstretcher_context_page_reaction() {
+ if (module_exists('context')) {
+ if ($plugin = context_get_plugin('reaction', 'bgstretcher')) {
+ $plugin->execute();
+ }
+ }
+}
+
+/**
+ * Implements hook_permission().
+ */
+function bgstretcher_permission() {
+ return array(
+ 'administer bgstretcher slides' => array(
+ 'title' => t('Administer bgstretcher slides'),
+ 'description' => t('Administer bgstretcher slides'),
+ ),
+ 'administer bgstretcher' => array(
+ 'title' => t('Administer background scretcher'),
+ 'description' => t('Add/edit/delete background scretchers'),
+ ),
+ );
+}
+
+/**
+ * Implements hook_menu().
+ */
+function bgstretcher_menu() {
+ $items = array();
+
+ $items['admin/structure/bgstretcher'] = array(
+ 'title' => 'Background Stretcher',
+ 'access arguments' => array('administer bgstretcher'),
+ 'page callback' => 'bgstretcher_overview',
+ );
+
+ $items['admin/structure/bgstretcher/%/edit'] = array(
+ 'title' => 'Edit Background Stretcher',
+ 'access arguments' => array('administer bgstretcher'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('bgstretcher_admin', 3, 4),
+ 'file' => 'bgstretcher.admin.inc',
+ );
+
+ $items['admin/structure/bgstretcher/add'] = array(
+ 'title' => 'Add Background Stretcher',
+ 'access arguments' => array('administer bgstretcher'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('bgstretcher_admin', NULL, 3),
+ 'file' => 'bgstretcher.admin.inc',
+ 'type' => MENU_LOCAL_ACTION,
+ );
+
+ $items['admin/structure/bgstretcher/%/delete'] = array(
+ 'title' => 'Delete Background Stretcher',
+ 'access arguments' => array('administer bgstretcher'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('bgstretcher_delete_confirm', 3),
+ 'file' => 'bgstretcher.admin.inc',
+ );
+
+ $items['admin/structure/bgstretcher/slide'] = array(
+ 'title' => 'Edit slides',
+ 'access arguments' => array('administer bgstretcher slides'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('bgstretcher_slide_admin'),
+ 'file' => 'bgstretcher.admin.inc',
+ );
+
+ $items['bgstretcher/autocomplete/node/%'] = array(
+ 'page callback' => 'bgstretcher_node_autocomplete',
+ 'page arguments' => array(3),
+ 'access arguments' => array('administer bgstretcher slides'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['admin/structure/bgstretcher/operations'] = array(
+ 'page callback' => '_bgstretcher_operations',
+ 'access arguments' => array('access administration pages'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ return $items;
+}
+
+/**
+ * Implements hook_theme().
+ */
+function bgstretcher_theme() {
+ return array(
+ 'bgstretcher_slide_admin' => array(
+ 'render element' => 'form',
+ ),
+
+ 'bgstretcher_navigation' => array(
+ 'variables' => array('bgstretcher' => array()),
+ 'function' => 'theme_bgstretcher_navigation',
+ ),
+ );
+}
+
+/**
+ * Theme function that returns navigation elements.
+ */
+function theme_bgstretcher_navigation($variables) {
+
+ $output = '';
+ $settings = $variables['bgstretcher']['settings']['js'];
+
+ // Attributes for "Previous" slide button
+ if ($settings['buttonPrev'] && $settings['buttonPrev'] != 'empty') {
+ $prev_value = drupal_substr($settings['buttonPrev'], 1);
+ $prev_attr = (strpos($settings['buttonPrev'], '#') !== FALSE) ? 'id' : 'class';
+ $prev = '' . $prev_attr . '="' . $prev_value . '"';
+ }
+ // Attributes for "Next" slide button
+ if ($settings['buttonNext'] && $settings['buttonNext'] != 'empty') {
+ $next_value = drupal_substr($settings['buttonNext'], 1);
+ $next_attr = (strpos($settings['buttonNext'], '#') !== FALSE) ? 'id' : 'class';
+ $next = '' . $next_attr . '="' . $next_value . '"';
+ }
+
+ // Attributes for pager
+ if ($settings['pagination'] && $settings['pagination'] != 'empty') {
+ $pager_value = drupal_substr($settings['pagination'], 1);
+ $pager_attr = (strpos($settings['pagination'], '#') !== FALSE) ? 'id' : 'class';
+ $pager = '' . $pager_attr . '="' . $pager_value . '"';
+ }
+
+ // Add navigation block if at least one navigation element exists
+ if (isset($prev) || isset($next) || isset($pager)) {
+ $output .= '<div class="bg-navigation">';
+ if (isset($prev)) {
+ $output .= '<div class="prev"><a href="javascript:;" ' . $prev . '>' . t('Previouse') . '</a></div>';
+ }
+ //
+ if (isset($next)) {
+ $output .= '<div class="next"><a href="javascript:;" ' . $next . '>' . t('Next') . '</a></div>';
+ }
+
+ if (isset($pager)) {
+ $output .= '<div class="bg-pager-wrapper"><div ' . $pager . '></div></div>';
+ }
+ $output .= '</div>';
+ }
+ return $output;
+}
+
+/**
+ * Theme function. Returns admin table to display and manage slides
+ */
+function theme_bgstretcher_slide_admin($variables) {
+
+ $rows = array();
+ $form = $variables['form'];
+
+ if (!empty($form['table'])) {
+ foreach (element_children($form['table']) as $id) {
+ $form['table'][$id]['weight']['#attributes']['class'] = array('bgstretcher-slide-weight');
+ $status_class = $form['table'][$id]['enabled']['#value'] ? 'slide-enabled' : 'slide-disabled';
+
+ $rows[] = array(
+ 'data' => array(
+ drupal_render($form['table'][$id]['image']),
+ drupal_render($form['table'][$id]['title']),
+ drupal_render($form['table'][$id]['weight']),
+ drupal_render($form['table'][$id]['operations']),
+ ),
+ 'class' => array('draggable', $status_class),
+ );
+ }
+ }
+
+ $header = array(t('Image'), t('Name'), t('Weight'), t('Operations'));
+ $table_id = 'bgstretcher-slides-table';
+
+ $output = theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'empty' => t('No slides yet.'),
+ 'attributes' => array('id' => $table_id),
+ ));
+
+ $output .= drupal_render_children($form);
+ drupal_add_tabledrag($table_id, 'order', 'sibling', 'bgstretcher-slide-weight');
+ return $output;
+}
+
+/* ========================================= Page callbacks ========================================= */
+
+/**
+ * Page callback. Allows to display and manage available background stretchers
+ */
+function bgstretcher_overview() {
+ $rows = array();
+ $items = bgstretcher_bgstretcher_get();
+
+ if (!empty($items)) {
+ foreach ($items as $id => $item) {
+ $source = $item['settings']['source']['source'];
+ $status = $item['enabled'];
+
+ $operations = array();
+ if (user_access('administer bgstretcher')) {
+ $operations[] = array(
+ 'title' => t('Edit'),
+ 'href' => 'admin/structure/bgstretcher/' . $id . '/edit',
+ );
+
+ $operations[] = array(
+ 'title' => t('Delete'),
+ 'href' => 'admin/structure/bgstretcher/' . $id . '/delete',
+ );
+
+ $url = url('admin/structure/bgstretcher/operations', array(
+ 'query' => array(
+ 'action' => $status ? 'disable' : 'enable',
+ 'id' => $id,
+ 'subject' => 'bgstretcher',
+ 'token' => drupal_get_token(),
+ 'destination' => $_GET['q'],
+ ),
+ ));
+
+ if ($status) {
+ $switcher = t('Enabled (<a href="@link">disable</a>)', array('@link' => $url));
+ }
+ else {
+ $switcher = t('Disabled (<a href="@link">enable</a>)', array('@link' => $url));
+ }
+ }
+
+ if (user_access('administer bgstretcher slides')) {
+
+ if ($source == 'view') {
+ $view_name = $item['settings']['source']['view']['view'];
+ $view_display = $item['settings']['source']['view']['display'];
+
+ $operations[] = array(
+ 'title' => t('Edit view'),
+ 'href' => 'admin/structure/views/view/' . $view_name . '/edit/' . $view_display,
+ );
+ }
+ else {
+ $operations[] = array(
+ 'title' => t('Slides'),
+ 'href' => 'admin/structure/bgstretcher/slide/' . $id,
+ );
+ }
+ }
+
+ $rows[] = array(
+ 'data' => array(
+ check_plain($item['name']),
+ check_plain($item['css']),
+ $item['settings']['source']['source'],
+ $switcher,
+ theme('links', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline')))),
+ ),
+ );
+ }
+ }
+
+ $header = array(
+ array('data' => t('Name')),
+ array('data' => t('CSS ID')),
+ array('data' => t('Slides source')),
+ array('data' => t('State')),
+ array('data' => t('Operations')),
+ );
+
+ return theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'empty' => t('No background stretchers yet.'),
+ ));
+}
+
+/**
+ * Page callback. Admin actions
+ */
+function _bgstretcher_operations() {
+ if (isset($_GET['action']) && isset($_GET['id']) && isset($_GET['token']) && drupal_valid_token($_GET['token'])) {
+ if ($_GET['subject'] == 'slide' && user_access('administer bgstretcher slides')) {
+ switch ($_GET['action']) {
+ case 'enable' :
+ $fields['enabled'] = 1;
+ bgstretcher_slide_set($fields, (int) $_GET['id']);
+ return drupal_goto($_GET['destination']);
+ break;
+ case 'disable' :
+ $fields['enabled'] = 0;
+ bgstretcher_slide_set($fields, (int) $_GET['id']);
+ return drupal_goto($_GET['destination']);
+ break;
+ case 'delete' :
+ module_load_include('inc', 'bgstretcher', 'bgstretcher.admin');
+ return drupal_get_form('bgstretcher_slide_delete_confirm', (int) $_GET['id']);
+ break;
+ }
+ }
+
+ if ($_GET['subject'] == 'bgstretcher' && user_access('administer bgstretcher')) {
+ switch ($_GET['action']) {
+ case 'enable' :
+ $fields['enabled'] = 1;
+ bgstretcher_bgstretcher_set((int) $_GET['id'], $fields);
+ return drupal_goto($_GET['destination']);
+ break;
+ case 'disable' :
+ $fields['enabled'] = 0;
+ bgstretcher_bgstretcher_set((int) $_GET['id'], $fields);
+ return drupal_goto($_GET['destination']);
+ break;
+ }
+ }
+ }
+ return MENU_ACCESS_DENIED;
+}
+
+/* ========================================= Helper functions ========================================= */
+
+/**
+ * Returns autocomplete suggestions
+ */
+function bgstretcher_node_autocomplete($node_type, $string = "") {
+ $matches = array();
+ if ($string) {
+ $matches = bgstretcher_nodes_by_title_get($node_type, $string);
+ }
+ drupal_json_output($matches);
+}
+
+/**
+ * Adds a bgstretcher depending on visibility settings
+ */
+function bgstretcher_bgstretcher_load() {
+
+ if ($bgstretchers = bgstretcher_bgstretcher_get(NULL, TRUE)) {
+ foreach ($bgstretchers as $bgstretcher) {
+
+ $paths = $bgstretcher['settings']['visibility']['path'];
+ $visibility = $bgstretcher['settings']['visibility']['visibility'];
+
+ // Prepare background stretcher
+ bgstretcher_bgstretcher_prepare($bgstretcher);
+
+ // Let's figure out where to load background stretcher
+ if ($paths) {
+ $page_match = FALSE;
+ $pages = drupal_strtolower($paths);
+
+ // Convert the Drupal path to lowercase
+ $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
+ // Compare the lowercase internal and lowercase path alias (if any).
+ $page_match = drupal_match_path($path, $pages);
+
+ if ($path != $_GET['q']) {
+ $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
+ }
+ $page_match = !($visibility xor $page_match);
+ }
+ else {
+ $page_match = TRUE;
+ }
+
+ // If page matches and background stretcher isn't empty
+ if ($page_match && !bgstretcher_bgstretcher_is_empty($bgstretcher)) {
+ // ...include required files
+ bgstretcher_include_files($bgstretcher);
+ }
+ }
+ }
+}
+
+/**
+ * Does final preparation for specific background stretcher
+ */
+function bgstretcher_bgstretcher_prepare(&$bgstretcher) {
+
+ $source = $bgstretcher['settings']['source']['source'];
+ $id = $bgstretcher['id'];
+
+ // Get all slides which belong to the given bgstretcher ID
+ $slides = bgstretcher_slides_get($id, TRUE);
+
+ // Sort by weight
+ uasort($slides, 'drupal_sort_weight');
+
+ // If background stretcher uses view as source, take all images from the view and attach them to the js settings.
+ if ($source == 'view') {
+ $view_name = $bgstretcher['settings']['source']['view']['view'];
+ $view_display = $bgstretcher['settings']['source']['view']['display'];
+ $view_image_field = $bgstretcher['settings']['source']['view']['image_field'];
+
+ // Get raw view result
+ if ($view = views_get_view_result($view_name, $view_display)) {
+ foreach ($view as $item) {
+ if (!empty($item->{'field_' . $view_image_field}[0]['raw']['uri'])) {
+ $image_style = $bgstretcher['settings']['js']['additional_settings']['image_style'];
+ $image_uri = $item->{'field_' . $view_image_field}[0]['raw']['uri'];
+
+ //Now generate image URL
+ $image_url = $image_style ? image_style_url($image_style, $image_uri) : file_create_url($image_uri);
+
+ // Put them into js settings
+ $bgstretcher['settings']['js']['images'][] = $image_url;
+ }
+ }
+ }
+ }
+
+ // Do the same for background stretchers which don't use view as image source
+ if ($slides) {
+ $images = array();
+ foreach ($slides as $slide_id => $slide) {
+ $images[] = $slide['data']['image_url'];
+ }
+ $bgstretcher['settings']['js']['images'] = $images;
+ }
+
+ // Final touch-ups before output
+ bgstretcher_prepare_js_settings($bgstretcher['settings']);
+
+ // Give a chance for other modules to add/modify/delete background stretcher's data
+ drupal_alter('bgstretcher', $bgstretcher);
+}
+
+/**
+ * Returns TRUE if given bgstretcher does not contain at least one slide
+ */
+function bgstretcher_bgstretcher_is_empty($bgstretcher) {
+ return empty($bgstretcher['settings']['js']['images']);
+}
+
+/**
+ * Adds all required .js and .css files.
+ */
+function bgstretcher_include_files($bgstretcher) {
+ // An ID for the images holder
+ $selector = $bgstretcher['css'];
+ // JS settings
+ $settings_js = $bgstretcher['settings']['js'];
+ $path = drupal_get_path('module', 'bgstretcher');
+
+ // Background stretcher's configuration
+ $config = '
+ (function ($) {
+ Drupal.behaviors.bgstretcher = {
+ attach: function (context, settings) {
+ $("' . $selector . ', context").bgStretcher(' . drupal_json_encode($settings_js) . ');
+ }
+ };
+ })(jQuery);
+ ';
+
+ $weight_js = 0;
+ drupal_add_js($path . '/lib/bgstretcher.js', array(
+ 'type' => 'file',
+ 'scope' => 'header',
+ 'group' => 'JS_THEME',
+ 'weight' => $weight_js,
+ ));
+
+ drupal_add_js($config, array(
+ 'type' => 'inline',
+ 'scope' => 'header',
+ 'group' => 'JS_THEME',
+ 'weight' => $weight_js + 1, // It's important to load jquery config after bgstretcher.js
+ ));
+
+ // Styling
+ drupal_add_css($path . '/lib/bgstretcher.css');
+}
+
+/**
+ * Does final processing of JS settings before output
+ */
+function bgstretcher_prepare_js_settings(&$settings) {
+
+ $dimension = $settings['js']['additional_settings']['dimension'];
+ $source = $settings['source']['source'];
+
+ if (!empty($settings['js']['images'])) {
+ foreach ($settings['js']['images'] as &$image) {
+
+ // Ensure that image's URL is safe
+ $image = check_url($image);
+
+ if ($dimension != 'fixed') {
+ // bgstretcher.js needs to know the size of original images.
+ $image_info = getimagesize($image);
+
+ // Merge images height and width into array
+ $widths[] = $image_info[0];
+ $heights[] = $image_info[1];
+ }
+ }
+
+ if ($dimension != 'fixed') {
+ switch ($dimension) {
+ case 'min' :
+ // Define the smallest image's height and width
+ $height = min($heights);
+ $width = min($widths);
+ break;
+ case 'max' :
+ // Define the greatest image's height and width
+ $height = max($heights);
+ $width = max($widths);
+ break;
+ case 'average' :
+ // Define average image's height and width
+ $height = round(array_sum($heights) / count($heights));
+ $width = round(array_sum($widths) / count($widths));
+ break;
+ }
+ // Set defined above values
+ $settings['js']['imageHeight'] = $height;
+ $settings['js']['imageWidth'] = $width;
+ }
+ // Kick out possible duplicates
+ $settings['js']['images'] = array_unique($settings['js']['images']);
+ }
+ // Remove unnecessary element in array
+ unset($settings['js']['additional_settings']);
+}
+
+
+/**
+ * Implements hook_block_info();
+ */
+function bgstretcher_block_info() {
+ $blocks = array();
+
+ if ($bgstretchers = bgstretcher_bgstretcher_get()) {
+ foreach (array_keys($bgstretchers) as $id) {
+ $blocks['navigation_bgstretcher_' . $id] = array(
+ 'info' => t('Navigation for Background Stretcher: @name', array('@name' => $bgstretchers[$id]['name'])),
+ );
+ }
+ }
+
+ return $blocks;
+}
+
+/**
+ * Implements hook_block_view();
+ */
+function bgstretcher_block_view($delta = '') {
+
+ $block = array();
+ if ($bgstretchers = bgstretcher_bgstretcher_get()) {
+ foreach (array_keys($bgstretchers) as $id) {
+ if ($delta == 'navigation_bgstretcher_' . $id) {
+ $slides = bgstretcher_slides_get($id, TRUE);
+ if (count($slides) > 1) {
+ $block['subject'] = t('Navigation for Background Stretcher: @name', array('@name' => $bgstretchers[$id]['name']));
+ $block['content'] = theme('bgstretcher_navigation', array('bgstretcher' => $bgstretchers[$id]));
+ }
+ }
+ }
+ }
+ return $block;
+}
+
+/* ========================================= Database functions ========================================= */
+
+/**
+ * Get nodes by title
+ */
+function bgstretcher_nodes_by_title_get($node_type, $string) {
+ $matches = array();
+ $result = db_select('node')
+ ->fields('node', array('nid', 'title'))
+ ->condition('type', $node_type)
+ ->condition('title', db_like($string) . '%', 'LIKE')
+ ->range(0, 10)
+ ->execute();
+
+ foreach ($result as $node) {
+ $matches[$node->title . " [$node->nid]"] = check_plain($node->title);
+ }
+ return $matches;
+}
+
+/**
+ * Get all/certain background stretcher
+ */
+function bgstretcher_bgstretcher_get($id = NULL, $enabled = FALSE) {
+ $output = array();
+ $query = db_select('bgstretchers', 'b')->fields('b');
+
+ if ($id) {
+ $query->condition('id', $id);
+ }
+
+ if ($enabled) {
+ $query->condition('enabled', 1);
+ }
+
+ $result = $query->execute()->fetchAll();
+
+ if (!empty($result)) {
+ foreach ($result as $data) {
+ $output[$data->id]['id'] = $data->id;
+ $output[$data->id]['name'] = $data->name;
+ $output[$data->id]['css'] = $data->css;
+ $output[$data->id]['enabled'] = $data->enabled;
+ $output[$data->id]['settings'] = unserialize($data->settings);
+ }
+ }
+ if ($id) {
+ return !empty($output[$id]) ? $output[$id] : array();
+ }
+ return $output;
+}
+
+/**
+ * Add/update background stretcher
+ */
+function bgstretcher_bgstretcher_set($id = NULL, $fields) {
+ return db_merge('bgstretchers')
+ ->key(array('id' => $id))
+ ->fields($fields)
+ ->updateFields($fields)
+ ->execute();
+}
+
+/**
+ * Delete background stretcher
+ */
+function bgstretcher_bgstretcher_delete($id) {
+ return db_delete('bgstretchers')
+ ->condition('id', $id)
+ ->execute();
+}
+
+/**
+ * Get all/certain background stretcher's slide
+ */
+function bgstretcher_slides_get($master_id = NULL, $enabled = FALSE) {
+ $output = array();
+ $query = db_select('bgstretchers_slides', 's')->fields('s');
+
+ if ($enabled) {
+ $query->condition('enabled', 1);
+ }
+
+ if ($master_id) {
+ $query->condition('master_id', $master_id);
+ }
+
+ $result = $query->execute()->fetchAll();
+
+ if (!empty($result)) {
+ foreach ($result as $data) {
+ $output[$data->master_id][$data->slide_id] = array(
+ 'source' => $data->source,
+ 'data' => unserialize($data->data),
+ 'enabled' => $data->enabled,
+ 'weight' => $data->weight,
+ );
+ }
+ }
+
+ if ($master_id) {
+ return !empty($output[$master_id]) ? $output[$master_id] : array();
+ }
+ return $output;
+}
+
+/**
+ * Add/update background stretcher's slide
+ */
+function bgstretcher_slide_set($fields, $id = NULL) {
+ return db_merge('bgstretchers_slides')
+ ->key(array('slide_id' => $id))
+ ->fields($fields)
+ ->updateFields($fields)
+ ->execute();
+}
+
+/**
+ * Delete background stretcher's slide
+ */
+function bgstretcher_slide_delete($id) {
+ return db_delete('bgstretchers_slides')->condition('slide_id', $id)->execute();
+}
diff --git a/bgstretcher_context_reaction_bgstretcher.inc b/bgstretcher_context_reaction_bgstretcher.inc
new file mode 100644
index 0000000..11f2a43
--- /dev/null
+++ b/bgstretcher_context_reaction_bgstretcher.inc
@@ -0,0 +1,42 @@
+<?php /** * @file * Contains bgstretcher_context_reaction_bgstretcher class. */
+/**
+ * Expose background stretchers as context reactions.
+ */
+class bgstretcher_context_reaction_bgstretcher extends context_reaction { // Plugin settings form function options_form($context) {
+ $options = array();
+ if (module_exists('bgstretcher')) {
+ if ($bgstretchers = bgstretcher_bgstretcher_get(NULL, TRUE)) {
+ foreach ($bgstretchers as $id => $bgstretcher) {
+ $options[$id] = $bgstretcher['name'];
+ }
+ }
+ }
+
+ $values = $this->fetch_from_context($context);
+ $form = array(
+ '#tree' => TRUE,
+ '#title' => check_plain($this->title),
+ 'bgstretcher' => array(
+ '#title' => check_plain($this->title),
+ '#description' => t('Which background stretcher to show when condition is met'),
+ '#type' => 'select',
+ '#options' => $options,
+ '#default_value' => isset($values['bgstretcher']) ? $values['bgstretcher'] : '',
+ ),
+ );
+ return $form;
+ } // Performs action when context conditions met
+ function execute() {
+ foreach (context_active_contexts() as $context) {
+ if (!empty($context->reactions[$this->plugin]['bgstretcher'])) {
+ $id = $context->reactions[$this->plugin]['bgstretcher'];
+ if ($bgstretcher = bgstretcher_bgstretcher_get($id, TRUE)) {
+ bgstretcher_bgstretcher_prepare($bgstretcher);
+ if (!bgstretcher_bgstretcher_is_empty($bgstretcher)) {
+ bgstretcher_include_files($bgstretcher);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/lib/bgstretcher.css b/lib/bgstretcher.css
new file mode 100644
index 0000000..e5d4fee
--- /dev/null
+++ b/lib/bgstretcher.css
@@ -0,0 +1,31 @@
+/*
+ Background Stretcher jQuery Plugin
+ 2011 ajaxBlender.com
+ For any questions please visit www.ajaxblender.com
+ or email us at support@ajaxblender.com
+*/
+
+HTML {_background: url(/images/trans.gif) no-repeat fixed;}
+.bgstretcher-area { text-align: left; }
+.bgstretcher, .bgstretcher UL, .bgstretcher UL LI {
+ position: absolute;
+ top: 0;
+ left: 0;
+}
+.bgstretcher UL, .bgstretcher UL LI {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+.bgstretcher {
+ background: black;
+ overflow: hidden;
+ width: 100%;
+ position: fixed;
+ z-index: 1;
+ _position: absolute; /*IE6 doesn't support fixed positioning*/
+ top: 0;
+ left: 0;
+}
+
+
diff --git a/lib/bgstretcher.js b/lib/bgstretcher.js
new file mode 100644
index 0000000..d73fc6c
--- /dev/null
+++ b/lib/bgstretcher.js
@@ -0,0 +1,626 @@
+/*
+ Background Stretcher jQuery Plugin
+ 2011 ajaxBlender.com
+ For any questions please visit www.ajaxblender.com
+ or email us at support@ajaxblender.com
+
+ Version: 2.0.1
+*/
+
+;(function($){
+ /* Variables */
+ var container = null;
+ var allLIs = '', containerStr = '';
+
+ var element = this;
+ var _bgStretcherPause = false;
+ var _bgStretcherAction = false;
+ var _bgStretcherTm = null;
+ var random_line = new Array();
+ var random_temp = new Array();
+ var r_image = 0;
+ var swf_mode = false;
+ var img_options = new Array();
+
+ $.fn.bgStretcher = function(settings){
+
+ if ($('.bgstretcher-page').length || $('.bgstretcher-area').length) {
+ if(typeof(console) !== 'undefined' && console != null) console.log('More than one bgStretcher');
+ return false;
+ }
+ settings = $.extend({}, $.fn.bgStretcher.defaults, settings);
+ $.fn.bgStretcher.settings = settings;
+
+ function _build(body_content){
+ if(!settings.images.length){ return; }
+
+ _genHtml(body_content);
+
+ containerStr = '#' + settings.imageContainer;
+ container = $(containerStr);
+ allLIs = '#' + settings.imageContainer + ' LI';
+ $(allLIs).hide().css({'z-index': 1, overflow: 'hidden'});
+
+ if(!container.length){ return; }
+ $(window).resize(function(){
+ _resize(body_content)
+ });
+
+ _resize(body_content);
+
+ var stratElement = 0;
+ /* Rebuild images for simpleSlide */
+ if (settings.transitionEffect == 'simpleSlide') {
+ if (settings.sequenceMode == 'random') {
+ if(typeof(console) !== 'undefined' && console != null) {
+ console.log('Effect \'simpleSlide\' don\'t be to use with mode random.');
+ console.log('Mode was automaticly set in normal.');
+ }
+ }
+ $(allLIs).css({'float': 'left', position: 'static'});
+ $(allLIs).show();
+ if ($.fn.bgStretcher.settings.slideDirection == 'NW' || $.fn.bgStretcher.settings.slideDirection == 'NE') {
+ $.fn.bgStretcher.settings.slideDirection = 'N';
+ }
+ if ($.fn.bgStretcher.settings.slideDirection == 'SW' || $.fn.bgStretcher.settings.slideDirection == 'SE') {
+ $.fn.bgStretcher.settings.slideDirection = 'S';
+ }
+ if ($.fn.bgStretcher.settings.slideDirection == 'S' || $.fn.bgStretcher.settings.slideDirection == 'E') {
+ settings.sequenceMode = 'back';
+ $(allLIs).removeClass('bgs-current');
+ $(allLIs).eq($(allLIs).length - $.fn.bgStretcher.settings.startElementIndex - 1).addClass('bgs-current');
+ if ($.fn.bgStretcher.settings.slideDirection == 'E') {
+ l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
+ t = 0;
+ } else { // S
+ t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
+ l = 0;
+ }
+ $(containerStr+' UL').css({left: l+'px', top: t+'px'});
+ } else {
+ settings.sequenceMode = 'normal';
+ if ($.fn.bgStretcher.settings.startElementIndex != 0) {
+ if ($.fn.bgStretcher.settings.slideDirection == 'N') {
+ t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
+ l = 0;
+ } else { // W
+ l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
+ t = 0;
+ console.log(l);
+ }
+ $(containerStr+' UL').css({left: l+'px', top: t+'px'});
+ }
+ }
+ }
+
+ if ($(settings.buttonNext).length || $(settings.buttonPrev).length || $(settings.pagination).length){
+ if (settings.sequenceMode == 'random') {
+ if(typeof(console) !== 'undefined' && console != null) {
+ console.log('Don\'t use random mode width prev-button, next-button and pagination.');
+ }
+ } else {
+ /* Prev and Next Buttons init */
+ if ($(settings.buttonPrev).length){
+ $(settings.buttonPrev).addClass('bgStretcherNav bgStretcherNavPrev');
+ $(settings.buttonPrev).click(function(){
+ $.fn.bgStretcher.buttonSlide('prev');
+ });
+ }
+ if ($(settings.buttonNext).length){
+ $(settings.buttonNext).addClass('bgStretcherNav bgStretcherNavNext');
+ $(settings.buttonNext).click(function(){
+ $.fn.bgStretcher.buttonSlide('next');
+ });
+ }
+ /* Pagination */
+ if ($(settings.pagination).length) {
+ $.fn.bgStretcher.pagination();
+ }
+ }
+ }
+
+ /* Random mode init */
+ if (settings.sequenceMode == 'random') {
+ var i = Math.floor(Math.random()*$(allLIs).length);
+ $.fn.bgStretcher.buildRandom(i);
+ if (settings.transitionEffect != 'simpleSlide') {
+ $.fn.bgStretcher.settings.startElementIndex = i;
+ }
+ stratElement = i;
+ } else {
+ if ($.fn.bgStretcher.settings.startElementIndex > ($(allLIs).length - 1)) $.fn.bgStretcher.settings.startElementIndex = 0;
+ stratElement = $.fn.bgStretcher.settings.startElementIndex;
+ if (settings.transitionEffect == 'simpleSlide') {
+ if ($.fn.bgStretcher.settings.slideDirection == 'S' || $.fn.bgStretcher.settings.slideDirection == 'E') {
+ stratElement = $(allLIs).length - 1 - $.fn.bgStretcher.settings.startElementIndex;
+ }
+ }
+ }
+
+ $(allLIs).eq(stratElement).show().addClass('bgs-current');
+ $.fn.bgStretcher.loadImg($(allLIs).eq(stratElement));
+
+ /* Go slideshow */
+ if(settings.slideShow && $(allLIs).length > 1){
+ _bgStretcherTm = setTimeout('jQuery.fn.bgStretcher.slideShow(\''+jQuery.fn.bgStretcher.settings.sequenceMode+'\', -1)', settings.nextSlideDelay);
+ }
+
+ };
+
+ function _resize(body_content){
+ var winW = 0;
+ var winH = 0;
+ var contH = 0;
+ var contW = 0;
+
+ if ($('BODY').hasClass('bgStretcher-container')) {
+ winW = $(window).width();
+ winH = $(window).height();
+ if (($.browser.msie) && (parseInt(jQuery.browser.version) == 6)) {
+ $(window).scroll(function(){
+ $('#'+settings.imageContainer).css('top', $(window).scrollTop());
+ });
+ }
+ } else {
+ $('.bgstretcher').css('position', 'absolute').css('top', '0px');
+ winW = body_content.width();
+ winH = body_content.height();
+ }
+
+ var imgW = 0, imgH = 0;
+ var leftSpace = 0;
+
+ // Max image size
+ if(settings.maxWidth != 'auto'){
+ if (winW > settings.maxWidth){
+ leftSpace = (winW - settings.maxWidth)/2;
+ contW = settings.maxWidth;
+ } else contW = winW;
+ } else contW = winW;
+ if(settings.maxHeight != 'auto'){
+ if (winH > settings.maxHeight){
+ contH = settings.maxHeight;
+ } else contH = winH;
+ } else contH = winH;
+
+ // Update container's size
+ container.width(contW);
+ container.height(contH);
+
+ // Non-proportional resize
+ if(!settings.resizeProportionally){
+ imgW = contH;
+ imgH = contH;
+ } else {
+ var initW = settings.imageWidth, initH = settings.imageHeight;
+ var ratio = initH / initW;
+
+ imgW = contW;
+ imgH = Math.round(contW * ratio);
+
+ if(imgH < contH){
+ imgH = contH;
+ imgW = Math.round(imgH / ratio);
+ }
+ }
+
+ // Anchoring
+ var mar_left = 0;
+ var mar_top = 0;
+ var anchor_arr;
+ if ($.fn.bgStretcher.settings.anchoring != 'left top') {
+ anchor_arr = ($.fn.bgStretcher.settings.anchoring).split(' ');
+ if (anchor_arr[0] == 'right') {
+ mar_left = (winW - contW);
+ } else {
+ if (anchor_arr[0] == 'center') mar_left = Math.round((winW - contW)/2);
+ }
+ if (anchor_arr[1] == 'bottom') {
+ mar_top = (winH - contH);
+ } else {
+ if (anchor_arr[1] == 'center') {
+ mar_top = Math.round((winH - contH)/2);
+ }
+ }
+ container.css('marginLeft', mar_left+'px').css('marginTop', mar_top+'px');
+ }
+ mar_left = 0;
+ mar_top = 0;
+ if ($.fn.bgStretcher.settings.anchoringImg != 'left top') {
+ anchor_arr = ($.fn.bgStretcher.settings.anchoringImg).split(' ');
+ if (anchor_arr[0] == 'right') {
+ mar_left = (contW - imgW);
+ } else {
+ if (anchor_arr[0] == 'center') mar_left = Math.round((contW - imgW)/2);
+ }
+ if (anchor_arr[1] == 'bottom') {
+ mar_top = (contH - imgH);
+ } else {
+ if (anchor_arr[1] == 'center') {
+ mar_top = Math.round((contH - imgH)/2);
+ }
+ }
+ }
+ img_options['mar_left'] = mar_left;
+ img_options['mar_top'] = mar_top;
+
+ // Apply new size for images
+ if (container.find('LI:first').hasClass('swf-mode')) {
+
+ var path_swf = container.find('LI:first').html();
+ container.find('LI:first').html('<div id="bgstretcher-flash">&nbsp;</div>');
+
+ var header = new SWFObject('flash/stars.swf', 'flash-obj', contW, contH, '9');
+ header.addParam('wmode', 'transparent');
+ header.write('bgstretcher-flash');
+
+ };
+ img_options['imgW'] = imgW;
+ img_options['imgH'] = imgH;
+
+ if(!settings.resizeAnimate){
+ container.children('UL').children('LI.img-loaded').find('IMG').css({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'});
+ container.children('UL').children('LI.img-loaded').find('IMG').css({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'});
+ } else {
+ container.children('UL').children('LI.img-loaded').find('IMG').animate({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'}, 'normal');
+ container.children('UL').children('LI.img-loaded').find('IMG').animate({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'}, 'normal');
+ }
+
+ $(allLIs).width(container.width()).height(container.height());
+
+ if ($.fn.bgStretcher.settings.transitionEffect == 'simpleSlide') {
+ if ($.fn.bgStretcher.settings.slideDirection == 'W' || $.fn.bgStretcher.settings.slideDirection == 'E') {
+ container.children('UL').width(container.width() * $(allLIs).length).height(container.height());
+ if ( $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) != -1 ){
+ l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * container.width()*(-1);
+ container.children('UL').css({left: l+'px'});
+ }
+ } else {
+ container.children('UL').height(container.height() * $(allLIs).length).width(container.width());
+ if ( $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) != -1 ){
+ t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
+ container.children('UL').css({top: t+'px'});
+ }
+ }
+ }
+
+ };
+
+ function _genHtml(body_content){
+ var code = '';
+ var cur_bgstretcher;
+
+ body_content.each(function(){
+ $(this).wrapInner('<div class="bgstretcher-page" />').wrapInner('<div class="bgstretcher-area" />');
+ code = '<div id="' + settings.imageContainer + '" class="bgstretcher"><ul>';
+ // if swf
+ if (settings.images.length) {
+ var ext = settings.images[0].split('.');
+ ext = ext[ext.length-1];
+
+ if (ext != 'swf') {
+ var ind = 0;
+ for(i = 0; i < settings.images.length; i++){
+ if (settings.transitionEffect == 'simpleSlide' && settings.sequenceMode == 'back')
+ ind = settings.images.length-1-i;
+ else ind = i;
+ if ($.fn.bgStretcher.settings.preloadImg) {
+ code += '<li><span class="image-path">' + settings.images[ind] + '</span></li>';
+ } else {
+ code += '<li class="img-loaded"><img src="' + settings.images[ind] + '" alt="" /></li>';
+ }
+ }
+ } else {
+ code += '<li class="swf-mode">' + settings.images[0] + '</li>';
+ }
+ }
+
+ code += '</ul></div>';
+ cur_bgstretcher = $(this).children('.bgstretcher-area');
+ $(code).prependTo(cur_bgstretcher);
+ cur_bgstretcher.css({position: 'relative'});
+ cur_bgstretcher.children('.bgstretcher-page').css({'position': 'relative', 'z-index': 3});
+ });
+
+ };
+
+ /* Start bgStretcher */
+ this.addClass('bgStretcher-container');
+ _build(this);
+ };
+
+ $.fn.bgStretcher.loadImg = function(obj){
+ if (obj.hasClass('img-loaded')) return true;
+ obj.find('SPAN.image-path').each(function(){
+ var imgsrc = $(this).html();
+ var imgalt = '';
+ var parent = $(this).parent();
+ var img = new Image();
+
+ $(img).load(function () {
+ $(this).hide();
+ parent.prepend(this);
+ $(this).fadeIn('100');
+ }).error(function () {
+ }).attr('src', imgsrc).attr('alt', imgalt);
+
+ $(img).css({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'});
+ $(img).css({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'});
+ });
+ obj.addClass('img-loaded');
+ return true;
+ }
+
+ $.fn.bgStretcher.play = function(){
+ _bgStretcherPause = false;
+ $.fn.bgStretcher._clearTimeout();
+ $.fn.bgStretcher.slideShow($.fn.bgStretcher.settings.sequenceMode, -1);
+
+ };
+
+ $.fn.bgStretcher._clearTimeout = function(){
+ if(_bgStretcherTm != null){
+ clearTimeout(_bgStretcherTm);
+ _bgStretcherTm = null;
+ }
+ }
+
+ $.fn.bgStretcher.pause = function(){
+ _bgStretcherPause = true;
+ $.fn.bgStretcher._clearTimeout();
+ };
+
+ $.fn.bgStretcher.sliderDestroy = function(){
+ var cont = $('.bgstretcher-page').html();
+ $('.bgStretcher-container').html('').html(cont).removeClass('bgStretcher-container');
+ $.fn.bgStretcher._clearTimeout();
+ _bgStretcherPause = false;
+ }
+
+ /* Slideshow */
+ $.fn.bgStretcher.slideShow = function(sequence_mode, index_next){
+ _bgStretcherAction = true;
+ if ($(allLIs).length < 2) return true;
+ var current = $(containerStr + ' LI.bgs-current');
+ var next;
+
+ $(current).stop(true, true);
+
+ if (index_next == -1) {
+ switch (sequence_mode){
+ case 'back':
+ next = current.prev();
+ if(!next.length){ next = $(containerStr + ' LI:last'); }
+ break;
+ case 'random':
+ if (r_image == $(containerStr + ' LI').length) {
+ $.fn.bgStretcher.buildRandom(random_line[$(containerStr + ' LI').length-1]);
+ r_image = 0;
+ }
+ next = $(containerStr + ' LI').eq(random_line[r_image]);
+ r_image++;
+ break;
+ default:
+ next = current.next();
+ if(!next.length){ next = $(containerStr + ' LI:first'); }
+ }
+ } else {
+ next = $(containerStr + ' LI').eq(index_next);
+ }
+
+ $(containerStr + ' LI').removeClass('bgs-current');
+ $.fn.bgStretcher.loadImg(next);
+ next.addClass('bgs-current');
+
+ switch ($.fn.bgStretcher.settings.transitionEffect){
+ case 'fade':
+ $.fn.bgStretcher.effectFade(current, next);
+ break;
+ case 'simpleSlide':
+ $.fn.bgStretcher.simpleSlide();
+ break;
+ case 'superSlide':
+ $.fn.bgStretcher.superSlide(current, next, sequence_mode);
+ break;
+ default :
+ $.fn.bgStretcher.effectNone(current, next);
+
+ }
+ if ($($.fn.bgStretcher.settings.pagination).find('LI').length) {
+ $($.fn.bgStretcher.settings.pagination).find('LI.showPage').removeClass('showPage');
+ $($.fn.bgStretcher.settings.pagination).find('LI').eq($(containerStr + ' LI').index($(containerStr + ' LI.bgs-current'))).addClass('showPage');
+ }
+
+ // callback
+ if ($.fn.bgStretcher.settings.callbackfunction) {
+ if(typeof $.fn.bgStretcher.settings.callbackfunction == 'function')
+ $.fn.bgStretcher.settings.callbackfunction.call();
+ }
+
+ if(!_bgStretcherPause){
+ _bgStretcherTm = setTimeout('jQuery.fn.bgStretcher.slideShow(\''+jQuery.fn.bgStretcher.settings.sequenceMode+'\', -1)', jQuery.fn.bgStretcher.settings.nextSlideDelay);
+ }
+ };
+
+ /* Others effects */
+ $.fn.bgStretcher.effectNone = function(current, next){
+ next.show();
+ current.hide();
+ _bgStretcherAction = false;
+ };
+ $.fn.bgStretcher.effectFade = function(current, next){
+ next.fadeIn( $.fn.bgStretcher.settings.slideShowSpeed );
+ current.fadeOut( $.fn.bgStretcher.settings.slideShowSpeed, function(){
+ _bgStretcherAction = false;
+ } );
+ };
+
+ $.fn.bgStretcher.simpleSlide = function(){
+ var t, l;
+ switch ($.fn.bgStretcher.settings.slideDirection) {
+ case 'N':
+ case 'S':
+ t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
+ l = 0;
+ break;
+ default:
+ l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
+ t = 0;
+ }
+ $(containerStr+' UL').animate({left: l+'px', top: t+'px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
+ _bgStretcherAction = false;
+ });
+
+ };
+
+ $.fn.bgStretcher.superSlide = function(current, next, sequence_mode){
+ var t, l;
+ switch ($.fn.bgStretcher.settings.slideDirection) {
+ case 'S':
+ t = $(containerStr).height();
+ l = 0;
+ break;
+ case 'E':
+ t = 0;
+ l = $(containerStr).width();
+ break;
+ case 'W':
+ t = 0;
+ l = $(containerStr).width()*(-1);
+ break;
+ case 'NW':
+ t = $(containerStr).height()*(-1);
+ l = $(containerStr).width()*(-1);
+ break;
+ case 'NE':
+ t = $(containerStr).height()*(-1);
+ l = $(containerStr).width();
+ break;
+ case 'SW':
+ t = $(containerStr).height();
+ l = $(containerStr).width()*(-1);
+ break;
+ case 'SE':
+ t = $(containerStr).height();
+ l = $(containerStr).width();
+ break;
+ default:
+ t = $(containerStr).height()*(-1);
+ l = 0;
+
+ }
+
+ if (sequence_mode == 'back') {
+ next.css({'z-index': 2, top: t+'px', left: l+'px'});
+ next.show();
+ next.animate({left: '0px', top: '0px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
+ current.hide();
+ $(this).css({'z-index': 1});
+ _bgStretcherAction = false;
+ });
+ } else {
+ current.css('z-index', 2);
+ next.show();
+ current.animate({left: l+'px', top: t+'px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
+ $(this).hide().css({'z-index': 1, top: '0px', left: '0px'});
+ _bgStretcherAction = false;
+ });
+ }
+ };
+
+ /* Build line random images */
+ $.fn.bgStretcher.buildRandom = function(el_not){
+ var l = $(allLIs).length;
+ var i, j, rt;
+ for (i = 0; i < l; i++ ) {
+ random_line[i] = i;
+ random_temp[i] = Math.random()*l;
+ }
+ for (i = 0; i < l; i++ ) {
+ for (j = 0; j < (l-i-1); j++) {
+ if (random_temp[j] > random_temp[j+1]) {
+ rt = random_temp[j];
+ random_temp[j] = random_temp[j+1];
+ random_temp[j+1] = rt;
+ rt = random_line[j];
+ random_line[j] = random_line[j+1];
+ random_line[j+1] = rt;
+ }
+ }
+ }
+
+ if (random_line[0] == el_not) {
+ rt = random_line[0];
+ random_line[0] = random_line[l-1];
+ random_line[l-1] = rt;
+ }
+ };
+
+ /* Prev and Next buttons */
+ $.fn.bgStretcher.buttonSlide = function(button_point){
+ if (_bgStretcherAction || ($(allLIs).length < 2)) return false;
+ var mode = '';
+ if (button_point == 'prev') {
+ mode = 'back';
+ if ($.fn.bgStretcher.settings.sequenceMode == 'back') mode = 'normal';
+ } else {
+ mode = $.fn.bgStretcher.settings.sequenceMode;
+ }
+ $(allLIs).stop(true, true);
+ $.fn.bgStretcher._clearTimeout();
+ $.fn.bgStretcher.slideShow(mode, -1);
+ return false;
+ };
+
+ /* Pagination */
+ $.fn.bgStretcher.pagination = function(){
+ var l = $(allLIs).length;
+ var output = ''; var i = 0;
+ if (l > 0) {
+ output += '<ul>';
+ for (i = 0; i < l; i++){
+ output += '<li><a href="javascript:;">'+(i+1)+'</a></li>';
+ }
+ output += '</ul>';
+ $($.fn.bgStretcher.settings.pagination).html(output);
+ $($.fn.bgStretcher.settings.pagination).find('LI:first').addClass('showPage');
+
+ $($.fn.bgStretcher.settings.pagination).find('A').click(function(){
+ if ($(this).parent().hasClass('showPage')) return false;
+ $(allLIs).stop(true, true);
+ $.fn.bgStretcher._clearTimeout();
+ $.fn.bgStretcher.slideShow($.fn.bgStretcher.settings.sequenceMode, $($.fn.bgStretcher.settings.pagination).find('A').index($(this)));
+ return false;
+ });
+
+ }
+ return false;
+ }
+
+ /* Default Settings */
+ $.fn.bgStretcher.defaults = {
+ imageContainer: 'bgstretcher',
+ resizeProportionally: true,
+ resizeAnimate: false,
+ images: [],
+ imageWidth: 1024,
+ imageHeight: 768,
+ maxWidth: 'auto',
+ maxHeight: 'auto',
+ nextSlideDelay: 3000,
+ slideShowSpeed: 'normal',
+ slideShow: true,
+ transitionEffect: 'fade', // none, fade, simpleSlide, superSlide
+ slideDirection: 'N', // N, S, W, E, (if superSlide - NW, NE, SW, SE)
+ sequenceMode: 'normal', // back, random
+ buttonPrev: '',
+ buttonNext: '',
+ pagination: '',
+ anchoring: 'left top', // right bottom center
+ anchoringImg: 'left top', // right bottom center
+ preloadImg: false,
+ startElementIndex: 0,
+ callbackfunction: null
+ };
+ $.fn.bgStretcher.settings = {};
+})(jQuery); \ No newline at end of file