Hello, guys!

First of all, there is a new version of jScrollPane script with strong API.
Check out this site: http://jscrollpane.kelvinluck.com

Second. I started to wrote new version of this module.
This version have administer section of module with all damned settings :-)

Here is the code:

/////////////jscrollpane.module////////////


/**
 * Implementation of hook_menu().
 */
function jscrollpane_menu() {
	$items['admin/settings/jscrollpane'] = array(
    'title'              => 'Jscrollpane settings',
    'description'        => 'Settings for jscrollpane.',
    'page callback'      => 'drupal_get_form',
    'page arguments' 	   => array('jscrollpane_admin_settings'),
	  'access callback'    => 'user_access',
	  'access arguments'   => array('administer jscrollpane'),
	//  'file'			   => 'admin.inc',
);
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function jscrollpane_perm() {
  return array('administer jscrollpane');
}

/**
 * Implementation of hook_init().
 */
function jscrollpane_init() {

  $jscrollpane_path = drupal_get_path('module', 'jscrollpane');
  $dir= $jscrollpane_path . '/themes';
  $themes = scandir($dir);

  drupal_add_css($jscrollpane_path .'/css/jquery.jscrollpane.css');
  drupal_add_css($jscrollpane_path . '/themes/' . variable_get('theme','lozenge') . '/style/jquery.jscrollpane.' . variable_get('theme','lozenge') . '.css');
  drupal_add_js($jscrollpane_path .'/js/jquery.jscrollpane.min.js');
  drupal_add_js($jscrollpane_path .'/js/jquery.mousewheel.js');
  drupal_add_js($jscrollpane_path .'/js/mwheelIntent.js');
  if (variable_get('jscrollpane_custom_options', '0')) {
    $js_settings = array(
      'selector'                 => variable_get('jscrollpane_selector', '.scroll-pane'),
      'custom_options'           => variable_get('jscrollpane_custom_options','0') ? TRUE : FALSE,
      'showArrows'               => variable_get('jscrollpane_showarrows', '0') ? TRUE : FALSE,
      'maintainPosition'         => variable_get('jscrollpane_maintainposition', '1') ? TRUE : FALSE,
      'autoReinitialise'         => variable_get('jscrollpane_autoreinitialise', '0') ? TRUE : FALSE,
      'autoReinitialiseDelay'    => variable_get('jscrollpane_autoreinitialisedelay', '500') ? TRUE : FALSE,
      'verticalDragMinHeight'    => variable_get('jscrollpane_verticaldragminheight', '0'),
      'verticalDragMaxHeight'    => variable_get('jscrollpane_verticaldragmaxheight', '99999'),
      'horizontalDragMinWidth'   => variable_get('jscrollpane_verticaldragminwidth', '0'),
      'horizontalDragMaxWidth'   => variable_get('jscrollpane_verticaldragmaxwidth', '99999'),
      'animateScroll'            => variable_get('jscrollpane_animatescroll', '0') ? TRUE : FALSE,
      'animateDuration'          => variable_get('jscrollpane_animateduration', '300'),
      'animateEase'              => variable_get('jscrollpane_animateease', 'linear'),
      'hijackInternalLinks'      => variable_get('jscrollpane_hijackinternallinks', '0') ? TRUE : FALSE,
      'verticalGutter'           => variable_get('jscrollpane_verticalgutter', '4'),
      'horizontalGutter'         => variable_get('jscrollpane_horizontalgutter', '4'),
      'mouseWheelSpeed'          => variable_get('jscrollpane_mousewheelspeed', '10'),
      'arrowButtonSpeed'         => variable_get('jscrollpane_arrowbuttonspeed', '10'),
      'arrowRepeatFreq'          => variable_get('jscrollpane_arrowrepeatfreq', '100'),
      'arrowScrollOnHover'       => variable_get('jscrollpane_arrowscrollonhover', '0') ? TRUE : FALSE,
      'verticalArrowPositions'   => variable_get('jscrollpane_verticalarrowpositions', 'split'),
      'horizontalArrowPositions' => variable_get('jscrollpane_horizontalarrowpositions', 'split'),
      'enableKeyboardNavigation' => variable_get('jscrollpane_enablekeyboardnavigation', '1') ? TRUE : FALSE,
      'hideFocus'                => variable_get('jscrollpane_hidefocus', 0) ? TRUE : FALSE,
      'clickOnTrack'             => variable_get('jscrollpane_clickontrack', '1') ? TRUE : FALSE,
      'trackClickSpeed'          => variable_get('jscrollpane_trackclickspeed', '30'),
      'trackClickRepeatFreq'     => variable_get('jscrollpane_trackclickrepeatfreq', '100'),
    );
    drupal_add_js(array('jscrollpane' => $js_settings), 'setting');
    drupal_add_js($jscrollpane_path .'/js/jscrollpane_init.js');
  }
}

function jscrollpane_admin_settings($form_state) {

  $jscrollpane_path = drupal_get_path('module', 'jscrollpane');
  $dir= $jscrollpane_path . '/themes';
  $themes = scandir($dir);

  $form['jscrollpane_header'] = array(
    '#value'         => t('This page details the various options that you can pass into the settings object when you initialise jScrollPane.Note that there is also a number of changes you can make through the <a href="http://jscrollpane.kelvinluck.com/api.html">API</a> after the scrollpane is already initialised and a number of <a href="http://jscrollpane.kelvinluck.com/events.html">events</a> you can listen to.'),
    '#weight'        => '0',
  );
  $form['theme'] = array(
    '#type' => 'select',
    '#title' => t('Select theme'),
    '#default_value' => variable_get('feed_item_length','lozenge'),
    '#description' => t('You can style jScrollPane however you like using simple CSS. Chose you theme.'),
    '#options' => $themes,
  );
  $form['jscrollpane_selector'] = array (
    '#type'          => 'textfield',
	  '#size'          => 60,
    '#title'         => t('jQuery selector'),
    '#description'   => t('Type jQuery selector which will find the content you want to apply jScrollPane to'),
    '#default_value' => variable_get('jscrollpane_selector', '.scroll-pane'),
	  '#weight'        => '1',
  );
  $form['jscrollpane_custom_options'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('Custom options'),
    '#description'   => t('Swith on this checkbox if you want to make custom options.'),
    '#default_value' => variable_get('jscrollpane_showarrows', '0'),
	  '#weight'        => '1',
  );
  $form['jscrollpane_showarrows'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('showArrows - boolean (default false)'),
    '#description'   => t('Whether arrows should be shown on the generated scroll pane. When set to false only the scrollbar track and drag will be shown, if set to true then arrows buttons will also be shown. <a href="http://jscrollpane.kelvinluck.com/arrows.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_custom_options', '0'),
	  '#weight'        => '2',
  );
  $form['jscrollpane_maintainposition'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('maintainPosition - boolean (default true)'),
    '#description'   => t('Whether the scrollpane should attempt to maintain it`s position whenever it is reinitialised. If true then the viewport of the scrollpane will remain the same when it is reinitialised, if false then the viewport will jump back up to the top when the scrollpane is reinitialised.'),
    '#default_value' => variable_get('jscrollpane_maintainposition', '1'),
	  '#weight'        => '4',
  );
  $form['jscrollpane_autoreinitialise'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('autoReinitialise - boolean (default false)'),
    '#description'   => t('Whether jScrollPane should automatically reinitialise itself periodically after you have initially initialised it. This can help with instances when the size of the content of the scrollpane (or the surrounding element) changes. However, it does involve an overhead of running a javascript function on a timer so it is recommended only to activate where necessary. <a href="http://jscrollpane.kelvinluck.com/auto_reinitialise.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_autoreinitialise', '0'),
	  '#weight'        => '6',
  );
  $form['jscrollpane_autoreinitialisedelay'] = array(
    '#type'          => 'textfield',
	  '#size'          => 10,
    '#title'         => t('autoReinitialiseDelay - int (default 500)'),
    '#description'   => t('The number of milliseconds between each reinitialisation (if autoReinitialise is true)'),
    '#default_value' => variable_get('jscrollpane_autoreinitialisedelay', '500'),
	  '#weight'        => '8',
  );
  $form['jscrollpane_verticaldragminheight'] = array(
    '#type'          => 'textfield',
	  '#size'          => 10,
    '#title'         => t('verticalDragMinHeight - int (default 0)'),
    '#description'   => t('The smallest height that the vertical drag can have. The size of the drag elements is based on the proportion of the size of the content to the size of the viewport but is contrained within the minimum and maximum dimensions given. <a href="http://jscrollpane.kelvinluck.com/drag_size.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_verticaldragminheight', '0'),
	  '#weight'        => '10',
  );
  $form['jscrollpane_verticaldragmaxheight'] = array(
    '#type'          => 'textfield',
	  '#size'       	 => 10,
    '#title'         => t('verticalDragMaxHeight - int (default 99999)'),
    '#description'   => t('See verticalDragMinHeight.'),
    '#default_value' => variable_get('jscrollpane_verticaldragmaxheight', '99999'),
	  '#weight'        => '12',
  );
  $form['jscrollpane_verticaldragminwidth'] = array(
    '#type'          => 'textfield',
	  '#size'        	 => 10,
    '#title'         => t('horizontalDragMinWidth - int (default 0)'),
    '#description'   => t('See verticalDragMinHeight.'),
    '#default_value' => variable_get('jscrollpane_verticaldragminwidth', '0'),
	  '#weight'        => '14',
  );
  $form['jscrollpane_verticaldragmaxwidth'] = array(
    '#type'          => 'textfield',
	  '#size'     		 => 10,
    '#title'         => t('horizontalDragMaxWidth - int (default 99999)'),
    '#description'   => t('See verticalDragMinHeight.'),
    '#default_value' => variable_get('jscrollpane_verticaldragmaxwidth', '99999'),
	  '#weight'        => '16',
  );
  $form['jscrollpane_animatescroll'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('animateScroll - boolean (default false)'),
    '#description'   => t('Whether to use animation when calling <a href="http://jscrollpane.kelvinluck.com/api.html#scrollTo">scrollTo</a> or <a href="http://jscrollpane.kelvinluck.com/api.html#scrollBy">scrollBy</a>. You can control the animation speed and easing by using the animateDuration and animateEase settings or if you want to exercise more complete control then you can override the <a href="http://jscrollpane.kelvinluck.com/api.html#animate">animate</a> API method. <a href="http://jscrollpane.kelvinluck.com/scroll_to_animate.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_animatescroll', '0'),
	  '#weight'        => '18',
	);
  $form['jscrollpane_animateduration'] = array(
    '#type'          => 'textfield',
	  '#size'      		 => 10,
    '#title'         => t('animateDuration - int (default 300)'),
    '#description'   => t('The number of milliseconds taken to animate to a new position (see animateScroll).'),
    '#default_value' => variable_get('jscrollpane_animateduration', '300'),
	  '#weight'        => '16',
  );
  $form['jscrollpane_animateease'] = array(
    '#type'          => 'textfield',
	  '#size'     		 => 10,
    '#title'         => t('animateEase - string (default `linear`)'),
    '#description'   => t('The type of easing to use when animating to a new position (see animateScroll and easing)'),
    '#default_value' => variable_get('jscrollpane_animateease', 'linear'),
	  '#weight'        => '18',
  );
  $form['jscrollpane_hijackinternallinks'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('hijackInternalLinks - boolean (default false)'),
    '#description'   => t('Whether internal links on the page should be hijacked so that if they point so content within a jScrollPane then they automatically scroll the jScrollPane to the correct place. <a href="http://jscrollpane.kelvinluck.com/anchors.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_hijackinternallinks', '0'),
	  '#weight'        => '20',
	);
  $form['jscrollpane_verticalgutter'] = array(
    '#type'          => 'textfield',
	  '#size'     		 => 10,
    '#title'         => t('verticalGutter - int (default 4)'),
    '#description'   => t('The amount of space between the side of the content and the vertical scrollbar.'),
    '#default_value' => variable_get('jscrollpane_verticalgutter', '4'),
	  '#weight'        => '22',
  );
  $form['jscrollpane_horizontalgutter'] = array(
    '#type'          => 'textfield',
	  '#size'      		 => 10,
    '#title'         => t('horizontalGutter - int (default 4)'),
    '#description'   => t('The amount of space between the bottom of the content and the horizontal scrollbar.'),
    '#default_value' => variable_get('jscrollpane_horizontalgutter', '4'),
	  '#weight'        => '24',
  );
  $form['jscrollpane_mousewheelspeed'] = array(
    '#type'          => 'textfield',
	  '#size'       	 => 10,
    '#title'         => t('mouseWheelSpeed - int (default 10)'),
    '#description'   => t('A multiplier which is used to control the amount that the scrollpane scrolls each time the mouse wheel is turned.'),
    '#default_value' => variable_get('jscrollpane_mousewheelspeed', '10'),
	  '#weight'        => '26',
  );
  $form['jscrollpane_arrowbuttonspeed'] = array(
    '#type'          => 'textfield',
	  '#size'     		 => 10,
    '#title'         => t('arrowButtonSpeed - int (default 10)'),
    '#description'   => t('A multiplier which is used to control the amount that the scrollpane scrolls each time on of the arrow buttons is pressed.'),
    '#default_value' => variable_get('jscrollpane_arrowbuttonspeed', '10'),
	  '#weight'        => '28',
  );
  $form['jscrollpane_arrowrepeatfreq'] = array(
    '#type'          => 'textfield',
	  '#size'     		 => 10,
    '#title'         => t('arrowRepeatFreq - int (default 100)'),
    '#description'   => t('The number of milliseconds between each repeated scroll event when the mouse is held down over one of the arrow keys.'),
    '#default_value' => variable_get('jscrollpane_arrowrepeatfreq', '100'),
	  '#weight'        => '30',
  );
  $form['jscrollpane_arrowscrollonhover'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('arrowScrollOnHover - boolean (default false)'),
    '#description'   => t('Whether the arrow buttons should cause the jScrollPane to scroll while you are hovering over them. <a href="http://jscrollpane.kelvinluck.com/arrow_hover.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_arrowscrollonhover', '0'),
	  '#weight'        => '32',
	);
  $form['jscrollpane_verticalarrowpositions'] = array(
    '#type'          => 'radios',
    '#title'         => t('verticalArrowPositions - string [split|before|after|os] (default split)'),
    '#description'   => t('Where the vertical arrows should appear relative to the vertical track. <a href="http://jscrollpane.kelvinluck.com/arrow_positions.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_verticalarrowpositions', 'split'),
    '#options'       => array('split', 'before', 'after', 'os'),
    '#weight'        => '34',
  );
  $form['jscrollpane_horizontalarrowpositions'] = array(
    '#type'          => 'radios',
    '#title'         => t('horizontalArrowPositions - string [split|before|after|os] (default split)'),
    '#description'   => t('Where the horizontal arrows should appear relative to the horizontal track. <a href="http://jscrollpane.kelvinluck.com/arrow_positions.html">Demo</a>.'),
    '#default_value' => variable_get('jscrollpane_horizontalarrowpositions', 'split'),
    '#options'       => array('split', 'before', 'after', 'os'),
    '#weight'        => '36',
  );
  $form['jscrollpane_enablekeyboardnavigation'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('enableKeyboardNavigation - boolean (default true)'),
    '#description'   => t('Whether keyboard navigation should be enabled (e.g. whether the user can focus the scrollpane and then use the arrow (and other) keys to navigate around.'),
    '#default_value' => variable_get('jscrollpane_enablekeyboardnavigation', '1'),
	  '#weight'        => '38',
	);
  $form['jscrollpane_hidefocus'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('hideFocus - boolean (default false)'),
    '#description'   => t('Whether the focus outline should be hidden in all browsers. For best accessibility you should not change this option. You can style the outline with the CSS property outline and outline-offset.'),
    '#default_value' => variable_get('jscrollpane_hidefocus', '0'),
	  '#weight'        => '40',
	);
  $form['jscrollpane_clickontrack'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('clickOnTrack - boolean (default true)'),
    '#description'   => t('Whether clicking on the track (e.g. the area behind the drag) should scroll towards the point clicked on. Defaults to true as this is the native behaviour in these situations.'),
    '#default_value' => variable_get('jscrollpane_clickontrack', '1'),
	  '#weight'        => '42',
	);
  $form['jscrollpane_trackclickspeed'] = array(
    '#type'          => 'textfield',
	  '#size'      		 => 10,
    '#title'         => t('trackClickSpeed - int (default 30)'),
    '#description'   => t('A multiplier which is used to control the amount that the scrollpane scrolls each trackClickRepeatFreq while the mouse button is held down over the track.'),
    '#default_value' => variable_get('jscrollpane_trackclickspeed', '30'),
	  '#weight'        => '44',
  );
  $form['jscrollpane_trackclickrepeatfreq'] = array(
    '#type'          => 'textfield',
	  '#size'      		 => 10,
    '#title'         => t('trackClickRepeatFreq - int (default 100)'),
    '#description'   => t('The number of milliseconds between each repeated scroll event when the mouse is held down over the track.'),
    '#default_value' => variable_get('jscrollpane_trackclickrepeatfreq', '100'),
	  '#weight'        => '46',
  );

  return system_settings_form($form);
}

///////////jscrollpane_init.js///////////

Drupal.behaviors.jscrollpane = function (context) {
var settings = Drupal.settings.jscrollpane;
$(function()
{
  if(custom_options){
    $("'" + settings.selector + "'").jScrollPane(
      {showArrows:settings.showArrows,
       maintainPosition:settings.maintainPosition,
       autoReinitialise:settings.autoReinitialise,
       autoReinitialiseDelay:settings.autoReinitialiseDelay,
       verticalDragMinHeight:settings.verticalDragMinHeight,
       verticalDragMaxHeight:settings.verticalDragMaxHeight,
       horizontalDragMinWidth:settings.horizontalDragMinWidth,
       horizontalDragMaxWidth:settings.horizontalDragMaxWidth,
       animateScroll:settings.animateScroll,
       animateDuration:settings.animateDuration,
       animateEase:settings.animateEase,
       hijackInternalLinks:settings.hijackInternalLinks,
       verticalGutter:settings.verticalGutter,
       horizontalGutter:settings.horizontalGutter,
       mouseWheelSpeed:settings.mouseWheelSpeed,
       arrowButtonSpeed:settings.arrowButtonSpeed,
       arrowRepeatFreq:settings.arrowRepeatFreq,
       arrowScrollOnHover:settings.arrowScrollOnHover,
       verticalArrowPositions:settings.verticalArrowPositions,
       horizontalArrowPositions:settings.horizontalArrowPositions,
       enableKeyboardNavigation:settings.enableKeyboardNavigation,
       hideFocus:settings.hideFocus,
       clickOnTrack:settings.clickOnTrack,
       trackClickSpeed:settings.trackClickSpeed,
       trackClickRepeatFreq:settings.trackClickRepeatFreq
      }
    );
  }
  else {
    $("'" + settings.selector + "'").jScrollPane();
  }
});
};

So, there's no working code yet.

There's a few problems here:

1)New version of code supporting themes.
I have some folder which calling 'themes'. So I just giving select option ($themes array) in admin section to chose theme, I use this code:

$jscrollpane_path = drupal_get_path('module', 'jscrollpane');
  $dir= $jscrollpane_path . '/themes';
  $themes = scandir($dir);

Not a good idea. But now I haven't got another.

2) This selector $("'" + settings.selector + "'") doesn't work and I don't know how I can pass selector setting through drupal js api, Could you?

Let's decide these problems and commit the code!

Comments

zkrebs’s picture

Highly interested in this, thanks.

botris’s picture

Nice, subscribe

amitaibu’s picture

Status: Needs work » Needs review
StatusFileSize
new19.63 KB

Here's a zip of a better module that exposes the API. from the docs:

/**
 * API function to add jScrollpane on a page.
 *
 * @code
 *   // foo class will get default scroll.
 *   $commands[] = array('selector' => '.foo');
 *
 *   // bar ID will get scroll with min and max scroll set to 80px.
 *   $commands[] = array(
 *    'selector' => '#bar',
 *    'options' => array(
 *      'verticalDragMinHeight' => 80,
 *      'verticalDragMaxHeight' => 80,
 *    ),
 *   );
 *
 *   jscrollpane_add_jscroll($commands);
 * @endcode
 */
amitaibu’s picture

Title: 2.x version code » Make module API to be used via PHP

better title

amitaibu’s picture

zkrebs’s picture

Does any of this expose a UI to Drupal Administration?

pribeh’s picture

Hi Amitaibu, could you provide an example of how to use your module? Where should I put $commands[] = array('selector' => '.foo'); function to determine the selector?

Thanks!