Created
October 11, 2010 14:10
-
-
Save LeeRJohnson/620560 to your computer and use it in GitHub Desktop.
The good pieces from COL Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var col['ui'] = | |
rotator: { | |
playing: false, | |
toolbar: function(settings) { | |
//TODO: Update to JQuery UI button | |
function createButton(config) { | |
var btn = $('<a />') // LinkButton | |
.attr('href', '#') // + config.label | |
.attr('rel', config.label) // .addClass(config.label) // old CSS support | |
.attr('title', config.label) | |
.append($('<span />') | |
.addClass('ui-icon ui-icon-' + config.icon) | |
.html(config.label)) | |
.button() | |
return btn; | |
} | |
var config = { | |
label: 'next', | |
icon: 'seek-next' | |
}; | |
var next = createButton(config); | |
config.label = 'prev'; | |
config.icon = 'seek-prev'; | |
var prev = createButton(config); | |
config.label = 'pause'; | |
config.icon = 'pause'; | |
var pause = createButton(config); | |
config.label = 'play'; | |
config.icon = 'play'; | |
var play = createButton(config); | |
var bar = $('<ul />') | |
.addClass('ui-rotator-nav ui-tabs-nav ui-helper-reset ui-helper-clearfix') | |
.append(prev) | |
.append(play) | |
.append(pause) | |
.append(next); | |
$(bar).find('a[rel]').wrap('<li></li>'); | |
return bar; | |
}, | |
defaults: { | |
delay: 2000, | |
autoStart: true, | |
showTabs: true, | |
showControls: true, | |
id: "ui-rotator" | |
}, | |
init: function(tabs, settings) { | |
$root = $(tabs); | |
var config = jQuery.extend({}, col.ui.rotator.defaults, settings); | |
$root | |
.data('rotator', config) | |
//Add Event Handlers | |
.bind('rotatorplay', function(event, ui) { | |
colui.rotator.play(event.target, config.delay); | |
return false; | |
}) | |
.bind('rotatorpause', function(event, ui) { | |
colui.rotator.pause(event.target); | |
}) | |
.bind('rotatornext', function(event, ui) { | |
colui.rotator.next(event.target); | |
}) | |
.bind('rotatorprev', function(event, ui) { | |
colui.rotator.prev(event.target); | |
}) | |
//init control events | |
.append(colui.rotator.toolbar({})).andSelf() | |
.find('a[rel=prev]').bind('click', function(e) { | |
$root.triggerHandler('rotatorprev'); | |
return false; | |
}).click(function() { return false; }).andSelf() | |
.find('a[rel=next]').bind('click', function(e) { | |
$root.triggerHandler('rotatornext'); | |
}).andSelf() | |
.find('a[rel=play]').bind('click', function(e) { | |
$root.triggerHandler('rotatorplay'); | |
}).andSelf() | |
.find('a[rel=pause]').bind('click', function(e) { | |
$root.triggerHandler('rotatorpause'); | |
}).andSelf() | |
; | |
//auto play | |
if (config.autoStart) { $root.trigger('rotatorplay', config.delay); } | |
}, | |
play: function(target, delay) { | |
var $root = $(target); | |
$root.tabs('rotate', delay).addClass('ui-state-playing'); | |
}, | |
pause: function(target) { | |
var $root = $(target); | |
$root.tabs('rotate', 0).removeClass('ui-state-playing'); | |
}, | |
prev: function(target) { | |
var $root = $(target); | |
var i = colUtil.loopToIndex($root.tabs('option', 'selected'), -1, $root.tabs('length')); | |
$root.tabs('option', 'selected', i); | |
}, | |
next: function(target) { | |
var $root = $(target); | |
var i = colUtil.loopToIndex($root.tabs('option', 'selected'), 1, $root.tabs('length')); | |
$root.tabs('option', 'selected', i); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created: 20090328 | |
Updated: 2010-10-07 | |
Authors: Lee R Johnson - http://leerjohnson.com/ | |
Created specifically for http://online.chemeketa.edu | |
to add parsing, importing, etc. utilites. | |
----------------------------------------------------------- */ | |
var col['utils'] = { | |
/** | |
* Parses the the CCC fiscal year Term Id from | |
* @param {int} tid The Learning Server Term Id or CCC Term Id. | |
* @returns A string representing the full Term Id | |
*/ | |
toTermCode: function(tid) { | |
return colUtil.toTermYear(tid) + parseInt(tid % 4.25 + 1) * 10; | |
}, | |
/** | |
* Parses the the Term label from... | |
* @param {int} tid The Learning Server Term Id or CCC Term Id. | |
* @returns A string representing the term label | |
*/ | |
toTermLabel: function(tid) { | |
switch (parseInt(tid % 4.25 + 1)) { | |
case 1: return 'summer'; break; ; | |
case 2: return 'fall'; break; | |
case 3: return 'winter'; break; | |
case 4: return 'spring'; break; | |
} | |
}, | |
/** | |
* Parses the the CCC fiscal year from | |
* @param {int} tid The Learning Server Term Id or CCC Term Id. | |
* @returns A string representing a year YYYY. | |
*/ | |
toTermYear: function(tid) { | |
return (tid < 1990) | |
? parseInt(tid / 4 + 1989.75).toString()//1989.75 = 198940 | |
: tid.substr(0, 3);//Just the YEAR | |
}, | |
/** | |
* Find the next or prev index number: | |
* @param {int} from The starting index | |
* @param {int} by A positive for next or negative for prev | |
* @param {int} of a number of items | |
* @returns a int indicating the next index | |
*/ | |
loopToIndex: function(from, by, of) { | |
var i = from + by; | |
i = (i > from) | |
? (i % of)//make zero next after last | |
: ((i < 0) ? i + of : i); //takes negitive out of end | |
return i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment