[8962] | 1 | /** |
---|
[11036] | 2 | * randomPict v1.0.1 |
---|
[8962] | 3 | * |
---|
[11036] | 4 | * | release | date | |
---|
| 5 | * | 1.0.1 | 2011-05-24 | * mantis bug:2311 |
---|
| 6 | * | | | . broken javascript if random pic set is empty |
---|
| 7 | * | | | |
---|
[8962] | 8 | */ |
---|
| 9 | function randomPict(opt) |
---|
| 10 | { |
---|
| 11 | var options={ |
---|
| 12 | fixedHeight:0, |
---|
| 13 | pictures:[], |
---|
| 14 | showName:'n', |
---|
| 15 | showComment:'n', |
---|
| 16 | delay:0 |
---|
| 17 | }, |
---|
| 18 | properties={ |
---|
| 19 | vIntervalID:0, |
---|
| 20 | vCurrentPict:0, |
---|
| 21 | nameDOM:'', |
---|
| 22 | commentDOM:'', |
---|
| 23 | img:new Image() |
---|
| 24 | }, |
---|
| 25 | |
---|
| 26 | init = function (opt) |
---|
| 27 | { |
---|
| 28 | $.extend(options, opt); |
---|
| 29 | |
---|
| 30 | switch(options.showName) |
---|
| 31 | { |
---|
| 32 | case 'o': |
---|
| 33 | properties.nameDOM='iammRPicNameO'; |
---|
| 34 | break; |
---|
| 35 | case 'u': |
---|
| 36 | properties.nameDOM='iammRPicNameU'; |
---|
| 37 | break; |
---|
| 38 | } |
---|
| 39 | switch(options.showComment) |
---|
| 40 | { |
---|
| 41 | case 'o': |
---|
| 42 | properties.commentDOM='iammRPicCommentO'; |
---|
| 43 | break; |
---|
| 44 | case 'u': |
---|
| 45 | properties.commentDOM='iammRPicCommentU'; |
---|
| 46 | break; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | if(properties.nameDOM!='') $('#'+properties.nameDOM).css('display', 'block'); |
---|
| 50 | if(properties.commentDOM!='') $('#'+properties.commentDOM).css('display', 'block'); |
---|
| 51 | |
---|
| 52 | if(options.delay>0) properties.vIntervalID = window.setInterval(getNextPicture, options.delay); |
---|
| 53 | |
---|
| 54 | if(options.fixedHeight>0) $('#irandompicinner').css('height', options.fixedHeight+'px'); |
---|
| 55 | |
---|
| 56 | preloadImages(); |
---|
| 57 | }, |
---|
| 58 | |
---|
| 59 | preloadImages = function () |
---|
| 60 | { |
---|
| 61 | $(properties.img).bind('load', |
---|
| 62 | function () |
---|
| 63 | { |
---|
| 64 | properties.vCurrentPict++; |
---|
| 65 | if(properties.vCurrentPict>=options.pictures.length) |
---|
| 66 | { |
---|
| 67 | properties.vCurrentPict=-1; |
---|
| 68 | getNextPicture(); |
---|
| 69 | } |
---|
| 70 | else |
---|
| 71 | { |
---|
| 72 | properties.img.src=options.pictures[properties.vCurrentPict].thumb; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | ); |
---|
| 76 | properties.img.src=options.pictures[properties.vCurrentPict].thumb; |
---|
| 77 | }, |
---|
| 78 | |
---|
| 79 | computePositionTop = function() |
---|
| 80 | { |
---|
[9002] | 81 | $("#iamm_ill0").css({top:($('#irandompicinner').innerHeight()-$("#iamm_ill0").innerHeight())/2}); |
---|
[8962] | 82 | }, |
---|
| 83 | |
---|
| 84 | getNextPicture = function() |
---|
| 85 | { |
---|
| 86 | properties.vCurrentPict++; |
---|
| 87 | if(properties.vCurrentPict>=options.pictures.length) properties.vCurrentPict=0; |
---|
| 88 | |
---|
| 89 | $('#iamm_ill0').fadeTo(200, 0, |
---|
| 90 | function () |
---|
| 91 | { |
---|
| 92 | if(properties.nameDOM!='') $('#'+properties.nameDOM).html(options.pictures[properties.vCurrentPict].name); |
---|
| 93 | if(properties.commentDOM!='') $('#'+properties.commentDOM).html(options.pictures[properties.vCurrentPict].comment); |
---|
| 94 | |
---|
| 95 | $('#iammRPicLink').attr('href', options.pictures[properties.vCurrentPict].link); |
---|
| 96 | $('#iammRPicImg').attr('src', options.pictures[properties.vCurrentPict].thumb); |
---|
| 97 | computePositionTop(); |
---|
| 98 | $('#iamm_ill0').fadeTo(200, 1); |
---|
| 99 | } |
---|
| 100 | ); |
---|
| 101 | |
---|
| 102 | }; |
---|
| 103 | |
---|
| 104 | init(opt); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | $(document).ready( |
---|
| 109 | function () |
---|
[11036] | 110 | { |
---|
| 111 | var rPict; |
---|
| 112 | if(typeof randomPictOpt!=='undefined') |
---|
| 113 | { |
---|
| 114 | rPict=new randomPict(randomPictOpt); |
---|
| 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | $('#mbAMM_randompict').remove(); |
---|
| 119 | } |
---|
[8962] | 120 | } |
---|
| 121 | ); |
---|