moostick dot js

A Mootools-powered, unobtrusive, Javascript news ticker library.  /mouthful

About

Moostick will take in any type of li-containing element and turn it into an animated news ticker, fading between each headline at a set interval.

Version

  • Version: 1.0

Homepage

Requirements

Copyright

copyright © 2007 Stephane Daury: http://stephane.daury.org/

License

MIT License http://www.opensource.org- /licenses- /mit-license.php

Copyright © 2007 Stephane Daury http://stephane.daury.org/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Summary
A Mootools-powered, unobtrusive, Javascript news ticker library.
(singleton) Utility class containing helper methods that will be helpful in other classes.
Query string helper for the Moostick script (NOT the document that included it).
Checks if the sent value is an array or convert it.
(singleton) A multi-list utility wrapper for the Moostick class and processes.
One or more list (ul, ol...)
Boolean.
Passthru variable.
Passthru variable.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the MstkInit.lists you passed in.
Passthru variable.
Sets the default properties and launches the Moostick modification process if in auto-start mode.
AKA the Kamikaze mode.
AKA the cautious mode.
Modifies the presentation and behaviour of li-containing elements to act as pseudo news tickers, and extends their DOM with itself (eg: myUL.moostick) for easy manipulation.
Moostick release version
A single list (ul, ol...)
Boolean.
Defines duration for which each headline is displayed including transition time, which can be adjusted through Moostick.fxOptions.
MooTools effect options for the opacity change used in the transition.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you passed in.
Set to true to bypass element styles validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you sent.
True if the first time we run.
Element schedule object.
Opacity change effect.
MooTools pseudo constructor.
Calls Moostick.initialize on-demand, always in auto-start mode.
Stops the ticker completely, including the attached mouse events.
Pauses the ticker.
Un-pauses the ticker.
AKA the Kamikaze mode.
AKA the cautious mode.
Sets the mouse events to pause the ticker when the mourse cursor enters the display area.
Loops through the list’s li elements to set the styles and opacity.
Prepares for and schedules Moostick._run.
Moostick transition: move first to last, fade new first in then set opacity on new last to 0.
Handles the MooTools opacity effect, from 0 to 1

Procedural code

Safety checkMoostick checks that MooTools is present to avoid errors and prompts to either cancel or be redirected to the MooTools site for more info.
Auto start modeMoostick auto-starts by default, unless passed init=0 in the script’s query string for more selective interaction.  MstkHelpers must be implemented before this step.

MstkHelpers

(singleton) Utility class containing helper methods that will be helpful in other classes.

Notes

  • Can be used before “ondomready” or “onload” are achieved, and is currently required by the auto-start procedure.
  • Can be used directly or have its methods implemented other Classes.

Example

alert(MstkHelpers.qsVar('myKey'));
Summary
Query string helper for the Moostick script (NOT the document that included it).
Checks if the sent value is an array or convert it.

Public Methods

qsVar

qsVar: function(key)

Query string helper for the Moostick script (NOT the document that included it).  Takes a query string key, and returns the value, or false if not found.

Arguments

keythe key (key=val) to search for, as string.

Returns

valthe key’s value as string or false if not found.

checkArray

checkArray: function(val)

Checks if the sent value is an array or convert it.  Very useful when you do not know if you are dealing with an single element through $()/$E()/etc or multiple elements through $$()/$E()/etc.

Arguments

valthe value to check

Returns

valthe sent value if already an array, or a single-item array.

MstkInit

(singleton) A multi-list utility wrapper for the Moostick class and processes.

Notes

  • Used in auto-start mode to scan the DOM for targeted elements.
  • Also supports concept of safe v. fast mode, like <MooStick>.
  • When opting to turn off auto-start, it is advised to instantiate the Moostick class directly with a single known list.  On the other hand, MstkInit will let you pass multiple ones, such as when dealing with css classes instead of ids, etc.

Example

// Enable Moostick on any element with "my-custom-class" css class.
MstkInit.go($$('.my-custom-class'), true);
Summary
One or more list (ul, ol...)
Boolean.
Passthru variable.
Passthru variable.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the MstkInit.lists you passed in.
Passthru variable.
Sets the default properties and launches the Moostick modification process if in auto-start mode.
AKA the Kamikaze mode.
AKA the cautious mode.

Public Properties

lists

One or more list (ul, ol...) from $(), $$(), etc.  If passed as false, MstkInit will try to search the DOM for list with an id of moostick, or lists with a class of moostick.

autoStart

Boolean.  Should the constructor launch the DOM modification process, or just set the properties.

interval

Passthru variable.  See: Moostick.interval.

fxOptions

Passthru variable.  See: Moostick.fxOptions.

trust4Speed

Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the MstkInit.lists you passed in.

trustOpacity

Passthru variable.  See: Moostick.trustOpacity.

Public Methods

go

go: function(lists,
autoStart,
interval,
fxOptions,
trust4Speed,
trustOpacity)

Sets the default properties and launches the Moostick modification process if in auto-start mode.

Arguments

listsSee: MstkInit.lists
autoStartSee: MstkInit.autoStart
intervalSee: MstkInit.interval
fxOptionsSee: MstkInit.fxOptions
trust4SpeedSee: MstkInit.trust4Speed
trustOpacitySee: MstkInit.trustOpacity

Private Methods

_fastMode

_fastMode: function()

AKA the Kamikaze mode.  Instantiate a Moostick object for each MstkInit.lists, without any validation, besides making sure we have an array to loop on.

_safeMode

_safeMode: function()

AKA the cautious mode.  First validates the passed MstkInit.lists or tries to auto-discover targeted DOM elements with “moostick” as an id or class, then calls Moostick for each list.

Moostick

Modifies the presentation and behaviour of li-containing elements to act as pseudo news tickers, and extends their DOM with itself (eg: myUL.moostick) for easy manipulation.

Example: Programming

// Auto-discovery mode, looking for li-containing elements with
// an id (single) or class of "moostick", then auto-starts.
new Moostick();
$('moostick').moostick.stopTick();

// Instantiate Moostick for the "my-custom-id" element. Do
// not auto-start. Fade every 5 seconds, for 1/2 second.
// Trust the list I sent, but handle the opacity assignment.
var myList = new Moostick(
$('my-custom-id'),
false,
5000,
{duration: 500},
true,
false
);
myList.startTick();
Summary
Moostick release version
A single list (ul, ol...)
Boolean.
Defines duration for which each headline is displayed including transition time, which can be adjusted through Moostick.fxOptions.
MooTools effect options for the opacity change used in the transition.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you passed in.
Set to true to bypass element styles validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you sent.
True if the first time we run.
Element schedule object.
Opacity change effect.
MooTools pseudo constructor.
Calls Moostick.initialize on-demand, always in auto-start mode.
Stops the ticker completely, including the attached mouse events.
Pauses the ticker.
Un-pauses the ticker.
AKA the Kamikaze mode.
AKA the cautious mode.
Sets the mouse events to pause the ticker when the mourse cursor enters the display area.
Loops through the list’s li elements to set the styles and opacity.
Prepares for and schedules Moostick._run.
Moostick transition: move first to last, fade new first in then set opacity on new last to 0.
Handles the MooTools opacity effect, from 0 to 1

Public Properties

version

Moostick release version

list

A single list (ul, ol...) from $(), $E(), etc.  This is the element to which Mostick will attach itself.  EG: myUL.moostick.stopTick();

autoStart

Boolean.  Should the constructor launch the DOM modification process, or just set the properties.

interval

Defines duration for which each headline is displayed including transition time, which can be adjusted through Moostick.fxOptions.

fxOptions

MooTools effect options for the opacity change used in the transition.  See the MooTools docs for details.  http://docs.mootools.net- /Effects- /Fx-Base.js#Fx.Base

trust4Speed

Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you passed in.  See also: Moostick.trustOpacity.

trustOpacity

Set to true to bypass element styles validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you sent.  When ON, we do not loop through each li to set the opacity to 0, therefore assuming you dealt with it in your stylesheets.

Private Properties

_firstRun

True if the first time we run.

_elSched

Element schedule object.

_fx

Opacity change effect.

Public Methods

initialize

initialize: function(list,
autoStart,
interval,
fxOptions,
trust4Speed,
trustOpacity)

MooTools pseudo constructor.  Sets the default properties and launches the Moostick modification process if in auto-start mode.

Arguments

listSee: Moostick.list
autoStartSee: Moostick.autoStart
intervalSee: Moostick.interval
fxOptionsSee: Moostick.fxOptions
trust4SpeedSee: Moostick.trust4Speed
trustOpacitySee: Moostick.trustOpacity

startTick

startTick: function(list,
interval,
fxOptions,
trust4Speed,
trustOpacity)

Calls Moostick.initialize on-demand, always in auto-start mode.

Arguments

listsSee: Moostick.list
intervalSee: Moostick.interval
fxOptionsSee: Moostick.fxOptions
trust4SpeedSee: Moostick.trust4Speed
trustOpacitySee: Moostick.trustOpacity

See also

Moostick.stopTick, Moostick.pauseTick and Moostick.resumeTick.

stopTick

stopTick: function()

Stops the ticker completely, including the attached mouse events.

See also

Moostick.startTick.

pauseTick

pauseTick: function()

Pauses the ticker.

See also

Moostick.resumeTick and Moostick.stopTick.

resumeTick

resumeTick: function()

Un-pauses the ticker.

See also

Moostick.pauseTick and Moostick.stopTick.

Private Methods

_fastMode

_fastMode: function()

AKA the Kamikaze mode.  Bypasses all element validation.

_safeMode

_safeMode: function()

AKA the cautious mode.  Validates the passed Moostick.list and tries to apply arbitray default styles before lauching the ticker.

_setMouseEvents

_setMouseEvents: function()

Sets the mouse events to pause the ticker when the mourse cursor enters the display area.  Greatly helps with usability, while still remaining unobstrusive.  Uses MooTools’ mouseenter and mouseenter.

_liHandler

_liHandler: function(styles)

Loops through the list’s li elements to set the styles and opacity.

Arguments

stylesSee http://docs.mootools.net- /Native- /Element.js#Element.setStyles

_schedule

_schedule: function()

Prepares for and schedules Moostick._run.  Also sets up Moostick._setMouseEvents.

_run

_run: function()

Moostick transition: move first to last, fade new first in then set opacity on new last to 0.

_fadeIn

_fadeIn: function(item)

Handles the MooTools opacity effect, from 0 to 1

Arguments

itemli element to apply the effect to.
qsVar: function(key)
Query string helper for the Moostick script (NOT the document that included it).
checkArray: function(val)
Checks if the sent value is an array or convert it.
One or more list (ul, ol...)
go: function(lists,
autoStart,
interval,
fxOptions,
trust4Speed,
trustOpacity)
Sets the default properties and launches the Moostick modification process if in auto-start mode.
_fastMode: function()
AKA the Kamikaze mode.
_safeMode: function()
AKA the cautious mode.
MooTools effect options for the opacity change used in the transition.
A single list (ul, ol...)
initialize: function(list,
autoStart,
interval,
fxOptions,
trust4Speed,
trustOpacity)
MooTools pseudo constructor.
startTick: function(list,
interval,
fxOptions,
trust4Speed,
trustOpacity)
Calls Moostick.initialize on-demand, always in auto-start mode.
stopTick: function()
Stops the ticker completely, including the attached mouse events.
pauseTick: function()
Pauses the ticker.
resumeTick: function()
Un-pauses the ticker.
_fastMode: function()
AKA the Kamikaze mode.
_safeMode: function()
AKA the cautious mode.
_setMouseEvents: function()
Sets the mouse events to pause the ticker when the mourse cursor enters the display area.
_liHandler: function(styles)
Loops through the list’s li elements to set the styles and opacity.
_schedule: function()
Prepares for and schedules Moostick._run.
_run: function()
Moostick transition: move first to last, fade new first in then set opacity on new last to 0.
_fadeIn: function(item)
Handles the MooTools opacity effect, from 0 to 1
Modifies the presentation and behaviour of li-containing elements to act as pseudo news tickers, and extends their DOM with itself (eg: myUL.moostick) for easy manipulation.
(singleton) Utility class containing helper methods that will be helpful in other classes.
Defines duration for which each headline is displayed including transition time, which can be adjusted through Moostick.fxOptions.
Set to true to bypass element styles validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you sent.
Boolean.
Passthru variable.
Passthru variable.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the MstkInit.lists you passed in.
Passthru variable.
Boolean.
Set to true to bypass element validation, for increased rendering speed, but only if you’re absolutely sure about the Moostick.list you passed in.