source: extensions/AMenuManager/js/amm_randomPictPublic.js @ 11036

Last change on this file since 11036 was 11036, checked in by grum, 13 years ago

fix bug:2311, bug:2312 (random pict bug)

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1/**
2 * randomPict v1.0.1
3 *
4 * | release | date       |
5 * | 1.0.1   | 2011-05-24 | * mantis bug:2311
6 * |         |            |   . broken javascript if random pic set is empty
7 * |         |            |
8 */
9function 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  {
81    $("#iamm_ill0").css({top:($('#irandompicinner').innerHeight()-$("#iamm_ill0").innerHeight())/2});
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 ()
110  {   
111    var rPict;
112    if(typeof randomPictOpt!=='undefined')
113    {
114      rPict=new randomPict(randomPictOpt);
115    }
116    else
117    {
118      $('#mbAMM_randompict').remove();
119    }
120  }
121);
Note: See TracBrowser for help on using the repository browser.