This file contains 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
// this is a rudimentary attempt to implement a slideshow that doesn't saturate downloads with every image upon page load; instead the first slide is embedded in the HTML and loads with the page immediately, the second upon DOM ready, and subsequent upon the advance of each slide; additionally a progress indicator is displayed and slideshow paused if the next slide is still downloading thus preventing displaying partially downloaded images, or missing images entirely | |
var slides = [ // this is an array of the html representing each slide to display, in reverse order starting with the second slide (the first should be in the HTML page, see below); this markup may contain anything (e.g. li, div, captions) and should have corresponding css, but the first img tag is assumed to be the main image which we monitor for its download state | |
'<img src="/path/to/file4.jpg">', | |
'<img src="/path/to/file3.jpg">', | |
'<img src="/path/to/file2.jpg">', | |
]; | |
// callback functions | |
function loadedSlide(){ |
This file contains 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
function string.wrap(text,cols) | |
-- takes one or more lines of text and wraps them at punctuation, whilst preserving the (tab or space) indentation | |
cols = cols or tonumber(string.match(io.popen("stty size"):read()," (%d*)")) -- sh doesn't seem to export $COLUMNS | |
local output = {} -- more memory efficient than constantly concatenating | |
local offset,char,indent,indents,wrapped | |
local function IndexString (text) local temp = {} for i=1,#text do temp[string.sub(text,i,i)]=true end return temp end -- this just makes it easier to write the values as a string on the next line | |
local punctuation = IndexString [[ ,.;:!?"[]{}()]] | |
-- iterate over each line | |
for line in string.gmatch(text.."\n","(.-)\n") do | |
-- determine indentation |