// Home Sweet Global Namespace var sf = {}; // Namespace for objects defined and used locally in templates sf.local = {}; // Namespace for plugin-specific javascript, // to be loaded later in separate files sf.plugins = {}; /* ********************************************************************* */ /* HOUSEKEEPING */ Array.prototype.rotate = (function() { var unshift = Array.prototype.unshift, splice = Array.prototype.splice; return function(count) { var len = this.length >>> 0, count = count >> 0; unshift.apply(this, splice.call(this, count % len, len)); return this; }; })(); sf.util = { // Function splits string into array of substrings of len or less. // Splits happen at the last space. splitString: function(str,len){ var arr = []; var words = str.split(" "); var line = words[0]; for(var i=1;i/custom.js }, initRow: function(row) { // expects the jQuery DOM object // For each character, construct a drum array and // attach that array to the element's .data() object row.find("span").each(function() { var parent = $(this).closest("div"); if(parent.hasClass("number")){ var drum = new sf.display.NumDrum(); // Numbers only } else if(parent.hasClass("character")) { var drum = new sf.display.CharDrum(); // Characters only } else if(parent.hasClass("image")) { var drum = new sf.display.ImageDrum(); // Images } else { var drum = new sf.display.FullDrum(); // The full set } $(this).data("order", drum.order); // Finally, set each character to a space. sf.display.change($(this), " "); }); }, loadSequentially: function() { var input = arguments[0], container = arguments[1], rows = container.find(".row"), i=0, stagger = sf.options.stagger ? sf.options.stagger : 1000; var loop = function() { setTimeout(function () { if(input[i]) { sf.display.loadRow(input[i],$(rows[i])); } i++; if (i < rows.length) { loop(i); } }, stagger); }; loop(); }, loadRow: function() { var input = arguments[0], row = arguments[1], // the row object key,group; // load the keys array into the .[key] groups for(key in input) { if(input.hasOwnProperty(key)){ group = row.find("."+key); if(group.length > 0) { sf.display.loadGroup(input[key], group); // put that value into that group's data store group.data("contents",input[key]); } } } }, loadGroup: function() { // load a string into a group of display elements var input = arguments[0], // the input (which may be a string or a int) input = input+"", // force it into a string target = arguments[1], // the group object elements = target.find("span").closest("div"), // may have separators, so check for spans strLen = elements.size(), i, characters; // ################################### // STATUS INDICATORS // Add the class "on" to the correct element if(target.hasClass("status")) { target.find("div").removeClass("on"); target.find(".s"+input).addClass("on"); // ################################### // IMAGES // Only one display element--no need to iterate } else if(target.find(".image").length > 0){ sf.display.change(target.find("span"), input, false); // ################################### // NORMAL CHARACTERS // otherwise, this group is composed of split-flap character or number elements } else { input = input.toUpperCase(); // get individual characters and pad the array // with spaces (to clear any existing characters) characters = input.split(""); for(i=0;i