root/platform/tdiary/plugin/bigpresen.rb

Revision 18589, 2.5 kB (checked in by maripo, 3 months ago)

initial release (かなり古いけど)

Line 
1# bigpresen.rb $Revision: 1.03 $
2#
3# bigpresen : �������ǿʹԤ����ⶶ�᥽�åɡ�����������������
4#
5#  �ѥ��� :
6#  str : �ʸ��"|"�ϥ��饤�ɤζ��ꡢ"/"�ϥ��饤������ԤȤʤ롣
7#   "|"��|"����������ϡ����\"����ƥ��������ס�
8#  width : ���饤�ɤ���������ꡣ(�ǥե��� : 480)
9#  height : ���饤�ɤι⤵���ԥ�������ꡣ(�ǥե��� : 320)
10#
11# ����ʸ�ˡ�<%= bigpresen 'str','width','height' %> �η���ǵ��Ҥ��ޤ���
12# ʸ�������ϡ�ɽ���ƥ����Ȥȥ��饤�ɤΥ������˹礦�褦��ưŪ������������
13# JavaScript��HTML�����������Τǡ������ˤ��Ƥ�������������Ȥ⤢������
14#
15# Copyright (c) 2006 Maripo Goda
16# mailto:madin@madin.jp
17# Document URL http://www.madin.jp/works/plugin.html
18# You can redistribute it and/or modify it under GPL2.
19
20@bigPresenID = 0;
21
22def bigpresen (str='', width='480',height='320')
23        scriptID = 'bp' + @bigPresenID.to_s
24        @bigPresenID += 1;
25
26        presen_ary = str.gsub("\\/",'&frasl;').gsub("\\|","&\#65073").split(/\|/);
27        presen_ary.collect!{|s|
28                s = '"' + s.gsub('/','<br>') + '"'
29        }
30        presen_str = presen_ary.join(',')
31
32return <<HTML
33<script type="text/javascript">
34<!--
35t#{scriptID} = 0;
36w#{scriptID}=#{width};
37h#{scriptID}="#{height}";
38msg#{scriptID} = new Array(#{presen_str});
39function #{scriptID} () {
40        if (t#{scriptID} < msg#{scriptID}.length) {
41                msgArr = msg#{scriptID}[t#{scriptID}].split('<br>');
42                maxPx = h#{scriptID} * 0.8;
43                for (t = 0; t < msgArr.length; t ++) {
44                        maxPx = Math.min(maxPx, w#{scriptID} * 2 * 0.9 / countLength(msgArr[t]));
45                }
46                maxPx = Math.min(maxPx, Math.floor(h#{scriptID} * 0.8 / msgArr.length));
47                with (document.getElementById("#{scriptID}")) {
48                        innerHTML = msg#{scriptID}[t#{scriptID}];
49                        style.fontSize = maxPx+"px";
50                        style.top = ((h#{scriptID}-(maxPx * msgArr.length)) / 2) + "px";
51                }
52                t#{scriptID} ++;
53        }
54        else {
55                t#{scriptID} = 0;
56                with (document.getElementById("#{scriptID}")) {
57                        innerHTML = "��EPLAY��;
58                        style.fontSize = '100%';
59                        style.top = '50%';
60                }
61        }
62}
63
64function countLength (str)
65        {
66        len = 0;
67        for (i = 0; i < str.length; i++) {
68                len ++;
69                if (escape(str.charAt(i)).length > 3) {
70                        len ++
71                }
72        }
73        return Math.max(len, 1);
74}
75-->
76</script>
77
78<noscript><p>JavaScript Required.</p></noscript>
79<div class="bigpresen" style="text-align:center; position:relative; width:#{width}px; height:#{height}px; background:#fff;border:ridge 4px #ccc;" onclick="#{scriptID}()">
80
81<span id="#{scriptID}" style="width:100%; position:absolute; top:50%; left:0; line-height:100%; color:black; font-family:'�ͣ��Х����å�', sans-serif;">��TART��/span>
82
83</div>
84
85HTML
86end
Note: See TracBrowser for help on using the browser.