X-Git-Url: http://www.average.org/gitweb/?p=mkgallery.git;a=blobdiff_plain;f=include%2Fgallery.js;h=39d8d846b4aa9ed7759c98195daada2942311c85;hp=25a2a5a285d876297cd6b36c6d3edf3bd4d8da99;hb=7a52825ce5f25653945b6f1ba8f1aa0098f95863;hpb=af2f2275168124e103af685035fafdc0755d45be diff --git a/include/gallery.js b/include/gallery.js index 25a2a5a..39d8d84 100644 --- a/include/gallery.js +++ b/include/gallery.js @@ -5,258 +5,135 @@ http://www.average.org/mkgallery/ Uses mootools (1.2) http://www.mootools.net/ - Uses slideshow http://www.phatfusion.net/slideshow/ + Uses multibox http://www.phatfusion.net/multibox/ + Inspired by slideshow http://www.phatfusion.net/slideshow/ */ /* - Slideshow + Use slideshow classes with the index generated by mkgallery.pl */ -var showWindow = new Class({ - - getOptions: function(){ - return { - embed: [], - zIndex: 2, - container: document.body, - onClick: $empty, - } - }, - - initialize: function(name,options){ - this.setOptions(this.getOptions(), options) - - this.options.container = $(this.options.container) - - this.container = new Element('div').addClass(name). - setProperties({ - id: name, - name: name, - }).setStyles({ - position: 'absolute', - left: '0px', - top: '0px', - width: '100%', - zIndex: this.options.zIndex, - overflow: 'hidden', - display: 'none' - }).addEvent('click', function(){ - this.options.onClick() - }.bind(this)).injectInside(this.options.container); - - this.embedded = [] - this.options.embed.each(function(el){ - var sub = new Element('div') - sub.addClass(el).setProperties({ - id: el, - name: el, - }).injectInside(this.container) - this.embedded.push(sub) - },this) - - this.position() - - window.addEvent('resize', this.position.bind(this)) - window.addEvent('scroll', this.position.bind(this)) - }, - - position: function(){ - if(this.options.container == document.body){ - this.h = window.getHeight() - this.s = window.getScrollTop() - }else{ - var myCoords = this.options.container.getCoordinates() - this.h = myCoords.height - this.s = myCoords.top - } - this.container.setStyles({ - top: this.s+'px', - height: this.h+'px' - }) - }, - - show: function(){ - this.container.setStyle('display', 'block') - }, - - hide: function(){ - this.container.setStyle('display', 'none') - } -}) -showWindow.implement(new Options) - -var showControls = new Class({ - - getOptions: function(){ - return { - next: $empty, - prev: $empty, - stop: $empty, - play: $empty, - exit: $empty, - } - }, - - initialize: function(name,options){ - this.setOptions(this.getOptions(), options) - - this.container = $(name) - - var buttons = ['prev','stop','play','next','exit','comm'] - buttons.each(function(el){ - var sub = new Element('div') - if (this.options[el]) { - sub.addEvent('click', function() { - this.options[el]() - }.bind(this)) - } - sub.addClass('controlButton').setProperties({ - id: el, - name: el, - }).injectInside(this.container) - },this) - }, - -}) -showControls.implement(new Options) - -/* Make overlay window and start slideshow */ -function showImage(id,doplay) { - var i=rimgs[id] - /* alert('show id='+id+' index='+i+' doplay='+doplay) */ - showwin.show() - show.play(i) - if (!doplay) { - show.stop() - } - return false -} - -/* Stop slideshow and return to index page */ -function showStop() { - show.quit() - showwin.hide() - /* - var img = show.newImage.getElement('img'); - if(img) { - alert('remove element: '+img.get('tag')+'.'+img.get('class')+ - '#'+img.get('id')+' src='+img.get('src')) - img.dispose() - } - - img = show.oldImage.getElement('img'); - if(img) { - alert('remove element: '+img.get('tag')+'.'+img.get('class')+ - '#'+img.get('id')+' src='+img.get('src')) - img.dispose() - } - - show.imagesHolder.getElements('img').each(function(el){ - alert('remove element: '+el.get('tag')+'.'+el.get('class')+'#'+el.get('id')+ - ' src='+el.get('src')) - el.dispose() - }) - */ - return false -} - -/* List of lists of img variations. Each image variation is a three-element */ -/* array: [width, height, url]. Index of the outer array is the global ID. */ -var vimgs=[] -/* - * [ - * [ - * [width, height, url] - * ... - * ] - * ... - * ] -*/ -/* resolve string ID to index */ -var rimgs=[] - /* Initialize everything, to be called on domready */ function init_gallery() { - $$('.conceal').each(function(el){ - el.setStyle('display', 'none') - }) - $$('a.infoBox').each(function(el){ - var url=el.get('href') - el.set('href',url+'?conceal') - }) - $$('a.showStart').each(function(el){ - el.addEvent('click', showImage.bind(el,[el.get('id'),1])) - }) - $$('a.showImage').each(function(el){ - el.addEvent('click', showImage.bind(el,[el.get('id'),0])) - }) - $$('div.varimages').each(function(el,i){ - rimgs[el.id] = i - vimgs[i] = [] - el.getElements('a').each(function(ael,j){ - dim = /(\d+)[^\d](\d+)/.exec(ael.text) - w = dim[1] - h = dim[2] - vimgs[i][j]=[w,h,ael.href,el.id,el.title] - }) - }) - /* debugging output - var msg='loaded '+vimgs.length+' image descriptions:' - vimgs.each(function(vimg,i){ - msg+='\nid='+i - vimg.each(function(vimg,i){ - msg+='\n w='+vimg[0]+' h='+vimg[1]+' url='+vimg[2] - }) - }) - alert(msg) - /* end debugging output */ - - var ovlparams = {} - ovl = new overlay(ovlparams) - - var iboxparams = { - overlay: ovl, - showNumbers: false, - showControls: true, - openFromLink: false, - movieWidth: 640, - movieHeight: 480, - descClassName: 'infoBoxDesc', - } - ibox = new multiBox('infoBox', iboxparams) - - var winparms = { - /* onClick: showStop, /* temporarily */ - embed: ['slideshowControls'], - } - showwin = new showWindow('slideshowContainer',winparms) - - var showparms = { - wait: 3000, - effect: 'fade', - duration: 1000, - loop: false, - thumbnails: false, - onClick: function(i){alert(i)}, - comment: 'comm', - } - show = new slideShow('slideshowContainer',vimgs,showparms) - var ctlparams = { - next: function(){show.next()}, - prev: function(){show.previous()}, - stop: function(){show.stop()}, - play: function(){show.play()}, - exit: function(){showStop()}, - } - ctl = new showControls('slideshowControls',ctlparams) - - parsedurl = parseUrl(document.URL) - /* alert('Anchor: '+parsedurl['anchor']+'\nURL: '+document.URL) */ - if ($chk(parsedurl['anchor'])){ - showImage(parsedurl['anchor'],0) - } + /* List of lists of img variations. Each image variation is + * a three-element array: [width, height, url]. Index of the + * outer array is the global ID. + * + * [ + * [ id, title, [ + * [ width, height, url ] + * ... + * ] + * ... + * ] + * ... + * ] + */ + var vimgs=[]; + + /* resolve string ID to index No which is the index in vimgs[] array */ + var rimgs=[]; + + /* Populate images list */ + + $$('div.varimages').each(function(el,i){ + var rel=el.get('id'); + rimgs[rel] = i; + vimgs[i] = [rel, el.title, []]; + el.getElements('a').each(function(ael,j){ + dim = /(\d+)[^\d](\d+)/.exec(ael.rel); + w = dim[1]; + h = dim[2]; + vimgs[i][2][j]=[w,h,ael.href]; + }); + }); + + /* debugging output + var msg='loaded '+vimgs.length+' image descriptions:'; + vimgs.each(function(vimg,i){ + msg+='\nid='+i+' ('+vimg[0]+') title='+vimg[1]; + vimg[2].each(function(vv,i){ + msg+='\n w='+vv[0]+' h='+vv[1]+' url='+vv[2]; + }); + }); + alert(msg); + /* end debugging output */ + + /* Initialize objects */ + + var ovlparams = {}; + ovl = new overlay(ovlparams); + + var iboxparams = { + overlay: ovl, + showNumbers: false, + showControls: true, + openFromLink: false, + movieWidth: 640, + movieHeight: 480, + descClassName: 'infoBoxDesc' + }; + ibox = new multiBox('infoBox', iboxparams); + + var winparms = { + tohide: 'indexContainer' + }; + var showwin = new showWindow('slideshowContainer',winparms); + + var ctlparams = { + }; + var ctl = new Controls('slideshowControls','slideshowContainer', + ctlparams); + + var showparms = { + cbStart: function(){ showwin.show(); }, + cbExit: function(){ showwin.hide(); } + }; + var show = new Show(vimgs,showwin,ctl,showparms); + + document.addEvent('keypress', function(ev){ + if (ev.key == 'esc') { + show.exit(); + } else if (ev.key == 'left') { + show.prev(); + } else if (ev.key == 'right') { + show.next(); + } else if (ev.key == 'space') { + show.toggleplay(); + } else { + /* alert('keypress: '+ev.key); */ + } + }); + + /* Update HTML */ + + $$('.conceal').each(function(el){ + el.setStyle('display', 'none'); + }); + $$('a.infoBox').each(function(el){ + var url=el.get('href'); + el.set('href',url+'?conceal'); + }); + + $$('a.showStart').each(function(el){ + el.addEvent('click', + show.start.bind(show,[rimgs[el.get('rel')],1])); + }); + $$('a.showImage').each(function(el){ + el.addEvent('click', + show.start.bind(show,[rimgs[el.get('rel')],0])); + }); + + /* Determine if we need to go directly into show mode */ + + parsedurl = parseUrl(document.URL); + /* alert('Anchor: '+parsedurl['anchor']+'\nURL: '+document.URL); */ + if ($chk(parsedurl['anchor'])){ + show.start(rimgs[parsedurl['anchor']],0); + } } /* Initialization */ -window.addEvent('domready',init_gallery) +window.addEvent('domready',init_gallery); +