Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /js/view.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download) (as text)
Fri Dec 4 12:17:36 2009 UTC (14 years, 5 months ago) by berupon
File MIME type: application/x-javascript
File size: 7253 byte(s)
まだ完成していないけど途中経過の記録というか…backupとしてcommit
1 berupon 4 EJS.Helpers.prototype.date_tag = function(name, value , html_options) {
2     if(! (value instanceof Date))
3     value = new Date()
4    
5     var month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
6     var years = [], months = [], days =[];
7     var year = value.getFullYear();
8     var month = value.getMonth();
9     var day = value.getDate();
10     for(var y = year - 15; y < year+15 ; y++)
11     {
12     years.push({value: y, text: y})
13     }
14     for(var m = 0; m < 12; m++)
15     {
16     months.push({value: (m), text: month_names[m]})
17     }
18     for(var d = 0; d < 31; d++)
19     {
20     days.push({value: (d+1), text: (d+1)})
21     }
22     var year_select = this.select_tag(name+'[year]', year, years, {id: name+'[year]'} )
23     var month_select = this.select_tag(name+'[month]', month, months, {id: name+'[month]'})
24     var day_select = this.select_tag(name+'[day]', day, days, {id: name+'[day]'})
25    
26     return year_select+month_select+day_select;
27     }
28    
29     EJS.Helpers.prototype.form_tag = function(action, html_options) {
30    
31    
32     html_options = html_options || {};
33     html_options.action = action
34     if(html_options.multipart == true) {
35     html_options.method = 'post';
36     html_options.enctype = 'multipart/form-data';
37     }
38    
39     return this.start_tag_for('form', html_options)
40     }
41    
42     EJS.Helpers.prototype.form_tag_end = function() { return this.tag_end('form'); }
43    
44     EJS.Helpers.prototype.hidden_field_tag = function(name, value, html_options) {
45     return this.input_field_tag(name, value, 'hidden', html_options);
46     }
47    
48     EJS.Helpers.prototype.input_field_tag = function(name, value , inputType, html_options) {
49    
50     html_options = html_options || {};
51     html_options.id = html_options.id || name;
52     html_options.value = value || '';
53     html_options.type = inputType || 'text';
54     html_options.name = name;
55    
56     return this.single_tag_for('input', html_options)
57     }
58    
59     EJS.Helpers.prototype.is_current_page = function(url) {
60     return (window.location.href == url || window.location.pathname == url ? true : false);
61     }
62    
63     EJS.Helpers.prototype.link_to = function(name, url, html_options) {
64     if(!name) var name = 'null';
65     if(!html_options) var html_options = {}
66    
67     if(html_options.confirm){
68     html_options.onclick =
69     " var ret_confirm = confirm(\""+html_options.confirm+"\"); if(!ret_confirm){ return false;} "
70     html_options.confirm = null;
71     }
72     html_options.href=url
73     return this.start_tag_for('a', html_options)+name+ this.tag_end('a');
74     }
75    
76     EJS.Helpers.prototype.submit_link_to = function(name, url, html_options){
77     if(!name) var name = 'null';
78     if(!html_options) var html_options = {}
79     html_options.onclick = html_options.onclick || '' ;
80    
81     if(html_options.confirm){
82     html_options.onclick =
83     " var ret_confirm = confirm(\""+html_options.confirm+"\"); if(!ret_confirm){ return false;} "
84     html_options.confirm = null;
85     }
86    
87     html_options.value = name;
88     html_options.type = 'submit'
89     html_options.onclick=html_options.onclick+
90     (url ? this.url_for(url) : '')+'return false;';
91     //html_options.href='#'+(options ? Routes.url_for(options) : '')
92     return this.start_tag_for('input', html_options)
93     }
94    
95     EJS.Helpers.prototype.link_to_if = function(condition, name, url, html_options, post, block) {
96     return this.link_to_unless((condition == false), name, url, html_options, post, block);
97     }
98    
99     EJS.Helpers.prototype.link_to_unless = function(condition, name, url, html_options, block) {
100     html_options = html_options || {};
101     if(condition) {
102     if(block && typeof block == 'function') {
103     return block(name, url, html_options, block);
104     } else {
105     return name;
106     }
107     } else
108     return this.link_to(name, url, html_options);
109     }
110    
111     EJS.Helpers.prototype.link_to_unless_current = function(name, url, html_options, block) {
112     html_options = html_options || {};
113     return this.link_to_unless(this.is_current_page(url), name, url, html_options, block)
114     }
115    
116    
117     EJS.Helpers.prototype.password_field_tag = function(name, value, html_options) { return this.input_field_tag(name, value, 'password', html_options); }
118    
119     EJS.Helpers.prototype.select_tag = function(name, value, choices, html_options) {
120     html_options = html_options || {};
121     html_options.id = html_options.id || name;
122     html_options.value = value;
123     html_options.name = name;
124    
125     var txt = ''
126     txt += this.start_tag_for('select', html_options)
127    
128     for(var i = 0; i < choices.length; i++)
129     {
130     var choice = choices[i];
131     var optionOptions = {value: choice.value}
132     if(choice.value == value)
133     optionOptions.selected ='selected'
134     txt += this.start_tag_for('option', optionOptions )+choice.text+this.tag_end('option')
135     }
136     txt += this.tag_end('select');
137     return txt;
138     }
139    
140     EJS.Helpers.prototype.single_tag_for = function(tag, html_options) { return this.tag(tag, html_options, '/>');}
141    
142     EJS.Helpers.prototype.start_tag_for = function(tag, html_options) { return this.tag(tag, html_options); }
143    
144     EJS.Helpers.prototype.submit_tag = function(name, html_options) {
145     html_options = html_options || {};
146     //html_options.name = html_options.id || 'commit';
147     html_options.type = html_options.type || 'submit';
148     html_options.value = name || 'Submit';
149     return this.single_tag_for('input', html_options);
150     }
151    
152     EJS.Helpers.prototype.tag = function(tag, html_options, end) {
153     if(!end) var end = '>'
154     var txt = ' '
155     for(var attr in html_options) {
156     if(html_options[attr] != null)
157     var value = html_options[attr].toString();
158     else
159     var value=''
160     if(attr == "Class") // special case because "class" is a reserved word in IE
161     attr = "class";
162     if( value.indexOf("'") != -1 )
163     txt += attr+'=\"'+value+'\" '
164     else
165     txt += attr+"='"+value+"' "
166     }
167     return '<'+tag+txt+end;
168     }
169    
170     EJS.Helpers.prototype.tag_end = function(tag) { return '</'+tag+'>'; }
171    
172     EJS.Helpers.prototype.text_area_tag = function(name, value, html_options) {
173     html_options = html_options || {};
174     html_options.id = html_options.id || name;
175     html_options.name = html_options.name || name;
176     value = value || ''
177     if(html_options.size) {
178     html_options.cols = html_options.size.split('x')[0]
179     html_options.rows = html_options.size.split('x')[1];
180     delete html_options.size
181     }
182    
183     html_options.cols = html_options.cols || 50;
184     html_options.rows = html_options.rows || 4;
185    
186     return this.start_tag_for('textarea', html_options)+value+this.tag_end('textarea')
187     }
188     EJS.Helpers.prototype.text_tag = EJS.Helpers.prototype.text_area_tag
189    
190     EJS.Helpers.prototype.text_field_tag = function(name, value, html_options) { return this.input_field_tag(name, value, 'text', html_options); }
191    
192     EJS.Helpers.prototype.url_for = function(url) {
193     return 'window.location="'+url+'";'
194     }
195     EJS.Helpers.prototype.img_tag = function(image_location, alt, options){
196     options = options || {};
197     options.src = image_location
198     options.alt = alt
199     return this.single_tag_for('img', options)
200     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26