// Shining - http://shining.heroku.com
// Copyright (c) 2010 Julio Cesar Ody - See LICENSE.txt
(function($) {
var KEY = { SPACE: 32, RIGHT: 39, LEFT: 37 };
Shining = {
// slides
slides: {
length: function() { return this._slides.length; },
current: function() {
if (arguments.length) {
this._current = this._slides.indexOf(arguments[0]);
return this.current();
} else {
return (typeof this._current == 'undefined' ? this._slides[0] : this._slides[this._current]);
}
},
all: function() { return this._slides; },
first: function() { return this._slides[0]; },
last: function() { return this._slides[ this._slides.length - 1 ]; },
next: function() { return this._slides[ this._slides.indexOf(this.current()) + 1 ]; },
previous: function() {
var previous = this._slides[ this._slides.indexOf(this.current()) - 1 ];
return previous || this.first();
},
add: function(slides) { return Array.prototype.push.apply(this._slides, slides); },
loaded: function(name) { return !!Shining.slides._loaded[name]; },
totalLoaded: function() { var len = 0; for (var i in this._loaded) len++; return len; },
_slides: [],
_loaded: {},
_current: 0
},
// public methods
firstSlide: function() { playSlide(Shining.slides.first()); },
lastSlide: function() { playSlide(Shining.slides.last()); },
nextSlide: function() { trigger('nextslide'); },
previousSlide: function() { trigger('previousslide'); },
setTheme: setTheme,
playSlide: playSlide,
help: help,
note: note,
when: when,
trigger: trigger,
pluginProcesses: {},
centerSlide: centerSlide,
// slide scripts
scripts: {
LINE: /^(\d[.\d]*),[\s]*(.*)/, parsed: [], processes: [],
nextSlide: function() { Shining.nextSlide(); },
previousSlide: function() { Shining.previousSlide(); },
at: function(seconds, method) {
Shining.scripts.processes.push(setTimeout(method, parseFloat(seconds) * 1000));
},
parse: function(script) {
var lines = script.split("\n"), tokens, parsed = [];
for (var i = 0; lines.length > i; i++) {
if (Shining.scripts.LINE.test(lines[i])) {
tokens = lines[i].match(Shining.scripts.LINE);
var time = tokens[1], code = tokens[2];
parsed.push(time);
if (code.length) parsed.push(code);
} else {
if (isNaN(parsed[parsed.length - 1])) {
parsed[parsed.length - 1] += ("; " + lines[i]);
} else {
parsed.push(lines[i]);
}
}
}
return parsed;
},
runSlide: function(name) {
var script = Shining.slides._loaded[name].script;
this.run(script);
},
run: function(script) {
if (typeof script == 'undefined' || script == '') return false;
var parsed = Shining.scripts.parse(script), all = [];
for (var i = 0; parsed.length > i; i += 2) {
all.push(["at(", parsed[i], ", function() { ", parsed[i+1], " })"].join(''));
}
with(Shining.scripts) { eval(all.join(';')); };
},
reap: function() {
$(Shining.scripts.processes).each(function() { clearTimeout(this); });
return Shining.scripts.processes = [];
}
}
};
// Transitions
var Transitions = {
'fade': {
enter: function() { $('div.slide').fadeIn(200); },
leave: function() { $('div.slide').fadeOut(200); }
},
'none': {
enter: function() { $('div.slide').show(); },
leave: function() { $('div.slide').hide(); }
}
}
function help(message, duration, force) {
if (Shining.config.help == false && force != true) return false;
$('#help').remove();
return $('
')
.html(message)
.appendTo('body')
.animate({opacity: 1})
.delay(duration || 500)
.fadeOut(200, function() { $('#help').remove(); });
}
function note(message, duration) {
if (message == false) return $('#note').dequeue();
$('#note').remove();
return $('