/*------------------------------------------------------------------------*\ * The Element Slider Version 2.1 (shinyshell.net) * * * * Author: Electron * * Date: 04-04-2008 (Re-architecture of the script from 02-11-2006) * * Copyright: (c) 2006-2008 Electron. All rights reserved and so forth. * \*------------------------------------------------------------------------*/ // The number of pixels one step will jump. Smaller is smoother but slower var slideconfig_steps = 5; // The speed at which the slider will slide (microseconds between shifts) var slideconfig_speed = 1; // ------------------------------------------------------------------------- // No configuration needs to be done below this point // ------------------------------------------------------------------------- // this could be useful, for example to launch a stream of alert()s if (navigator.appName.indexOf('Microsoft') != -1) { var is_ie = true; } else { var is_ie = false; } /** * Register an element (div) to slide when a control element is clicked. * * @param string - An element that will trigger the slide when clicked * @param string - The ID string of the element that will do the sliding * @param string - The ID of a container DIV directly inside the sliding one * @param string - Direction of the initial slide ("up" or "down") */ function RegisterSlide(anchor_name, sliding_name, container_name, direction) { if (typeof direction == "undefined") { // the first slide will move upwards unless otherwise specified direction = "up"; } // save the elements for other functions to use anchor_element = document.getElementById(anchor_name); anchor_element['slideparams'] = new Array( 'executing', 'inty', 'ie', // generic element ids 'anchor_id', 'sliding_id', // various stuff 'original_height', 'container_height', 'previous_loop_height', 'slide_direction', 'current_direction', // CharChange(R) variables 'charcontainer_id', 'do_charchange', 'charup', 'chardown' ); anchor_element['slideparams']['executing'] = false; anchor_element['slideparams']['anchor_id'] = anchor_name; anchor_element['slideparams']['sliding_id'] = sliding_name; anchor_element['slideparams']['original_height'] = document.getElementById(sliding_name).clientHeight; anchor_element['slideparams']['container_height'] = document.getElementById(container_name).clientHeight; anchor_element['slideparams']['slide_direction'] = direction.toLowerCase(); anchor_element.onclick = SlideControl; } /** * Register an element for a CharChange(R) character change based on * the direction of the slide. * * @param string - ID string of the controller element (button) * @param string - ID string of the CharChange containing element * @param string - What will be displayed when sliding UP * @param string - What is to be shown when sliding DOWN */ function RegisterCharChange(anchor_name, charcontainer_name, upstring, downstring) { anchor_elm = document.getElementById(anchor_name); if (typeof anchor_elm["slideparams"] == "undefined") { // charchange is not something important enough to send an error return false; } anchor_elm['slideparams']['do_charchange'] = true; anchor_elm['slideparams']['charup'] = upstring; anchor_elm['slideparams']['chardown'] = downstring; anchor_elm['slideparams']['charcontainer_id'] = charcontainer_name; } /** * Register an element for a CharChange(R) character change based on * the direction of the slide. * * @param string - ID string of the controller element (button) * @param string - Direction the menu is sliding */ function CharChange(anchor_name, direction) { anchor_elm = document.getElementById(anchor_name); if (typeof anchor_elm["slideparams"] == "undefined") { // charchange is not something important enough to send an error return false; } sp = anchor_elm['slideparams']; // whether to do charchange at all... if (sp['do_charchange']) { if (direction == "up") { document.getElementById(sp['charcontainer_id']).innerHTML = sp['charup']; } else { document.getElementById(sp['charcontainer_id']).innerHTML = sp['chardown']; } } } /** * [Internal] * * Controls the sliding of the element based on the current status. */ function SlideControl() { var sp = this['slideparams']; var next_direction = sp['slide_direction']; var current_direction = sp['current_direction']; if (sp['executing'] == true) { // the slide is already in progress, so execute a change of direction window.clearInterval(this['slideparams']['inty']); if (current_direction == "up") { if (sp['original_height'] == 0) { CharChange(this.id, "up"); } else { CharChange(this.id, "down"); } sp['inty'] = window.setInterval("SlideDown('" + this.id + "')", slideconfig_speed); } else { if (sp['original_height'] == 0) { CharChange(this.id, "down"); } else { CharChange(this.id, "up"); } sp['inty'] = window.setInterval("SlideUp('" + this.id + "')", slideconfig_speed); } } else { if (next_direction == "up") { if (sp['original_height'] == 0) { CharChange(this.id, "down"); } else { CharChange(this.id, "up"); } sp['executing'] = true; sp['inty'] = window.setInterval("SlideUp('" + this.id + "')", slideconfig_speed); } else { if (sp['original_height'] == 0) { CharChange(this.id, "up"); } else { CharChange(this.id, "down"); } sp['executing'] = true; sp['inty'] = window.setInterval("SlideDown('" + this.id + "')", slideconfig_speed); } } } /** * [Internal] * * Executes the sliding upwards (called by SlideControl) * * @param string - ID string of the controller element (button) */ function SlideUp(anchor_id) { var anchor_elm = document.getElementById(anchor_id); var sliding_elm = document.getElementById(anchor_elm['slideparams']['sliding_id']); anchor_elm['slideparams']['current_direction'] = 'up'; var height = parseInt(sliding_elm.clientHeight, 10); // hide the overflowing content as the box slides closed sliding_elm.style.overflow = 'hidden'; var newheight = height - slideconfig_steps; if (newheight > slideconfig_steps) { sliding_elm.style.height = newheight + 'px'; anchor_elm['slideparams']['previous_loop_height'] = newheight; } else { sliding_elm.style.height = '0px'; height = 0; window.clearInterval(anchor_elm['slideparams']['inty']); anchor_elm['slideparams']['executing'] = false; anchor_elm['slideparams']['slide_direction'] = "down"; } } /** * [Internal] * * Executes the sliding downwards (called by SlideControl) * * @param string - ID string of the controller element (button) */ function SlideDown(anchor_id) { var anchor_elm = document.getElementById(anchor_id); var sliding_elm = document.getElementById(anchor_elm['slideparams']['sliding_id']); anchor_elm['slideparams']['current_direction'] = 'down'; var height = parseInt(sliding_elm.clientHeight, 10); var newheight = height + slideconfig_steps; sliding_elm.style.height = newheight + 'px'; anchor_elm['slideparams']['previous_loop_height'] = newheight; if (newheight >= anchor_elm['slideparams']['container_height']) { newheight = anchor_elm['slideparams']['original_height']; } if (newheight == anchor_elm['slideparams']['original_height']) { sliding_elm.style.height = anchor_elm['slideparams']['container_height'] + 'px'; window.clearInterval(anchor_elm['slideparams']['inty']); anchor_elm['slideparams']['executing'] = false; anchor_elm['slideparams']['slide_direction'] = "up"; } }