OSDN Git Service

6e45949fc64b5e48065a1791c0b3215f7d3a0d73
[trpgtools-onweb/AjaxChat.git] / lib / js / trpg.js
1 /*
2  Ajax Chat for TRPG ver.2.6
3  (c)2007-2009 Cake All Rights Reserved.
4  Mail : cake_67@users.sourceforge.jp
5  Home : http://trpgtools-onweb.sourceforge.jp/
6  */
7 /*****************
8  *  JaveScriptライブラリ:TRPG用
9  *****************/
10
11 // ダイス挿入
12 function insertDice(Obj, columnId) {
13     var dice = $("#dice").attr("value");
14     var revision = setNull($("#revision").attr("value"));
15     if (revision && revision.match(/[^-0-9+\*\/]/)) {
16         alert('ダイス修正値は半角数字と+,-,*,/のみで入力してください。');
17         return false;
18     }
19     if (revision) {
20         if (!revision.match(/^[-+\*\/]/)) {
21             dice = dice+'+';
22         }
23         dice = dice+revision;
24     }
25
26     var cfInput = $("#cfinput").attr("checked");
27     var fZero = $("#fzero").attr("checked");
28     var cRolling = $("#crolling").attr("checked");
29     var clit = setNull($("#clit").attr("value"));
30     var famble = setNull($("#famble").attr("value"));
31     if (cfInput) {
32         if (clit || famble) {
33             dice = dice + '@';
34         }
35         if (clit) {
36             if (cRolling) {
37                 clit = "r"+clit;
38             }
39             dice = dice + 'c' + clit;
40         }
41         if (famble) {
42             if (fZero) {
43                 famble = "z"+famble;
44             }
45             dice = dice + 'f' + famble;
46         }
47     }
48
49     // ダイス入力
50     insert(document.getElementById(columnId), '', '['+dice+']', 0)
51     document.getElementById(columnId).focus();
52     return false;
53 }
54
55 /* undefineと0をnullにする */
56 function setNull(str) {
57     if (typeof(str) != 'string') {
58         str = '0';
59     }
60     if (str == '0') str = "";
61     return str;
62 }
63
64 /* 指定ファイルを先読み */
65 function preReadFile(filePlace, filename) {
66     $.ajax({
67         type: "get",
68         ifModified: true,
69         url: filePlace,
70         cache: false,
71         success: function(data){
72             return data;
73         },
74         error: function(data){
75             alert(filename+'取得に失敗しました');
76             return false;
77         }
78     });
79 }