Skip to content

Instantly share code, notes, and snippets.

@MACSkeptic
Created May 11, 2010 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MACSkeptic/397653 to your computer and use it in GitHub Desktop.
Save MACSkeptic/397653 to your computer and use it in GitHub Desktop.
"use strict";
var presentation = presentation || {};
presentation.slides = (function ($) {
var index = -1,
list = [],
hideEffects = ["hide", "fadeOut", "slideUp"],
showEffects = ["show", "fadeIn", "slideDown"],
cachedContainer = null;
function random() {
return Math.floor(Math.random() * hideEffects.length);
}
function findContainer() {
cachedContainer = cachedContainer || $('#slide_container');
return cachedContainer;
}
function show() {
var elem = findContainer();
elem[showEffects[random()]]('fast', function () {
prettyPrint();
if(elem.has('div.nooo').length > 0) {
elem.addClass('nooo');
}
if(elem.has('pre.prettyprint').length > 0) {
elem.addClass('code');
}
});
}
function current() {
return 'slides/' + list[index];
}
function loadThen(callback) {
return function () { findContainer().load(current(), null, callback); };
}
function hideThen(callback) {
var elem = findContainer();
elem.removeClass('nooo').removeClass('code');
elem[hideEffects[random()]]('fast', callback);
}
function render() {
hideThen(loadThen(show));
}
function findFirstSlide() {
return 0;
}
function findLastSlide() {
return (list.length - 1);
}
function isFewerThanFirstSlide(i) {
return (i <= findFirstSlide());
}
function isHigherThanLastSlide(i) {
return (i > findLastSlide());
}
function goToIndex (i) {
var currentSlide = index;
index = (isFewerThanFirstSlide(i) ?
findFirstSlide() :
(isHigherThanLastSlide(i) ?
findLastSlide() :
i)
);
if (currentSlide !== index) {
render();
}
}
function goToNextSlide() {
goToIndex(index + 1);
}
function goToPreviousSlide() {
goToIndex(index - 1);
}
function goToFirstSlide() {
goToIndex(findFirstSlide());
}
function goToLastSlide() {
goToIndex(findLastSlide());
}
return {
initialize: function () {
list.push('first_page.html');
list.push('doug_crockford_quote_1.html');
list.push('bad_ruby_code.html');
list.push('bad_js_code.html');
list.push('why.html');
list.push('bad_code.html');
list.push('crash_course.html');
list.push('values.html');
list.push('null.html');
list.push('null_typeof.html');
list.push('undefined.html');
list.push('undefined_typeof.html');
list.push('nan.html');
list.push('nan_typeof.html');
list.push('equality_versus.html');
list.push('equality_question.html');
list.push('equality_answer.html');
list.push('equality_conclusion.html');
list.push('this.html');
list.push('loose.html');
list.push('method.html');
list.push('apply.html');
list.push('constructor.html');
list.push('oops.html');
list.push('just_dont.html');
list.push('brackets_question.html');
list.push('brackets_answer.html');
list.push('semicolon.html');
list.push('brackets_explanation.html');
list.push('block_question.html');
list.push('block_answer.html');
list.push('function_scope.html');
list.push('infered_globals.html');
list.push('jslint_can.html');
list.push('sample.html');
list.push('pain.html');
list.push('jslint_will.html');
list.push('jslint_jresig.html');
list.push('immediate_function.html');
list.push('rename_jquery.html');
list.push('from_scratch.html');
list.push('augmentation.html');
list.push('factory.html');
list.push('inheritance_bad.html');
list.push('inheritance_good.html');
list.push('inheritance_sample.html');
list.push('code_0.html');
list.push('code_1.html');
list.push('code_2.html');
list.push('bad_ruby_code.html');
list.push('better_ruby_code.html');
list.push('bad_js_code.html');
list.push('better_js_code.html');
list.push('questions.html');
list.push('must_read.html');
list.push('trending_topics.html');
},
first: function () {
goToFirstSlide();
},
next: function () {
goToNextSlide();
},
previous: function () {
goToPreviousSlide();
},
last: function() {
goToLastSlide();
},
present: function () {
$.each(list, function(i, value) {
$('#slides').
append($("<option></option>").
attr("value", i).
text('[' + i + '] ' + value));
});
$('#slides').bind('change', function () {
goToIndex(parseInt($(this).val(), 10));
return false;
});
}
};
}(jQuery));
presentation.buttons = (function ($, slides) {
function buttons() { return $('.jquery_button'); }
return {
all: function () { return buttons(); },
initialize: function () {
buttons().each(function (i, domButton) {
var button = $(domButton);
button.button( {
text: false,
icons: { primary: 'ui-icon-seek-' + button.attr('icon') }
});
});
}
};
}(jQuery, presentation.slides));
presentation.engine = (function ($, slides, buttons) {
(function domIndependentInitialization() {
slides.initialize();
}());
$(function domDependentInitialization() {
buttons.initialize();
slides.present();
slides.first();
buttons.all().bind('click', function () { slides[$(this).attr('action')](); });
});
}(jQuery, presentation.slides, presentation.buttons));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment