Changeset 24643
- Timestamp:
- 11/22/08 19:18:02 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/sbmcommentsviewer.js
r22654 r24643 66 66 )); 67 67 }, 68 toHTMLString: function(format, countOnly){ 69 var label = (this.faviconURL ? '<img src="' + this.faviconURL + '" width="16" height="16"/>' : '') + 70 manager.type[this.type] + ' ' + this.count + '(' + this.entries.length + ')' + 71 (this.pageURL ? ' <a href="' + this.pageURL + '">' + this.pageURL + '</a>' : ''); 68 toHTML: function(format, countOnly){ 69 var label = <> 70 {this.faviconURL ? <img src={this.faviconURL} width="16" height="16"/> : <></>} 71 {manager.type[this.type] + ' ' + this.count + '(' + this.entries.length + ')'} 72 {this.pageURL ? <a href="#">{this.pageURL}</a> : <></>} 73 </>; 72 74 if (countOnly){ 73 75 return label; 74 76 } else { 75 let str = [76 '<table id="liberator-sbmcommentsviewer"><caption style="text-align:left;" class="hl-Title">' + label + '</caption><tr>'77 ];78 format.forEach(function(colum){79 let name = manager.format[colum] || '-';80 str.push('<th>' + name + '</th>');81 });82 str.push('</tr>');83 this.entries.forEach(function(e){84 s tr.push(e.toHTMLString(format));85 });86 str.push('</table>');87 return str.join('');77 let xml = <table id="liberator-sbmcommentsviewer"> 78 <caption style="text-align:left" class="hl-Title">{label}</caption> 79 <tr/> 80 </table>; 81 let self = this; 82 xml.*[xml.*.length()-1].* += (function(){ 83 var thead = <tr/>; 84 format.forEach(function(colum){ thead.* += <th>{manager.format[colum] || '-'}</th>; }); 85 var tbody = <></>; 86 self.entries.forEach(function(e){ tbody += e.toHTML(format); }); 87 return thead + tbody; 88 })(); 89 return xml; 88 90 } 89 91 } … … 113 115 } //}}} 114 116 SBMEntry.prototype = { //{{{ 115 toHTMLString: function(format){ 116 // E4X で書く手もあるけど、liberator.echoを使って出力すると 117 // toString後に"\n"が<br/>に変換されてしまうのでStringで 118 var str = ['<tr>']; 117 toHTML: function(format){ 118 var xml = <tr/>; 119 119 var self = this; 120 120 format.forEach(function(colum){ 121 121 switch(colum){ 122 122 case 'id': 123 str.push('<td class="liberator-sbmcommentsviewer-id">' + (self.userIcon ? '<p style="display:table-cell;vertical-align:middle;padding-right:3px;"><img src="'+self.userIcon +'" width="16" height="16"/></p>' : '') + 124 '<p style="display:table-cell;vertical-align:middle;">' + self.id + '</p></td>'); 123 xml.* += <td class="liberator-sbmcommentsviewer-id"> 124 {self.userIcon ? <><img src={self.userIcon} width="16" height="16"/> {self.id}</> : <span>{self.id}</span>} 125 </td>; 125 126 break; 126 127 case 'timestamp': 127 str.push('<td class="liberator-sbmcommentsviewer-timestamp">' + self.formatDate() + '</td>'); break;128 xml.* += <td class="liberator-sbmcommentsviewer-timestamp">{self.formatDate()}</td>; break; 128 129 case 'tags': 129 str.push('<td class="liberator-sbmcommentsviewer-tags">' + self.tags.join(',') + '</td>'); break;130 xml.* += <td class="liberator-sbmcommentsviewer-tags">{self.tags.join(',')}</td>; break; 130 131 case 'comment': 131 str.push('<td class="liberator-sbmcommentsviewer-comment" style="white-space:normal;">' + self.comment + '</td>'); break;132 xml.* += <td class="liberator-sbmcommentsviewer-comment" style="white-space:normal;">{self.comment}</td>; break; 132 133 case 'tagsAndComment': 133 tagString = self.tags.length ? '[' + self.tags.join('][') + ']':''; 134 str.push('<td class="liberator-sbmcommentsviewer-tagsAndComment" style="white-space:normal;">' + tagString + ' ' + self.comment + '</td>'); break; 134 var tagString = self.tags.length ? '[' + self.tags.join('][') + ']':''; 135 xml.* += <td class="liberator-sbmcommentsviewer-tagsAndComment" style="white-space:normal;">{tagString + ' '+self.comment}</td>; 136 break; 135 137 default: 136 str.push('<td>-</td>');138 xml.* += <td>-</td>; 137 139 } 138 140 }); 139 str.push('</tr>'); 140 return str.join(''); 141 return xml; 141 142 }, 142 143 formatDate: function(){ … … 181 182 cacheManager.add(sbmContainer, url, type); 182 183 if (openToBrowser) 183 manager.open(sbmContainer.toHTML String(format,false));184 manager.open(sbmContainer.toHTML(format,false)); 184 185 else 185 liberator.echo(sbmContainer.toHTML String(format,countOnly), true);186 liberator.echo(sbmContainer.toHTML(format,countOnly), true); 186 187 } else { 187 188 liberator.echoerr(sbmURL + ' ' + xhr.status, true); … … 238 239 } 239 240 var c = new SBMContainer('d', items.length, { 240 faviconURL: 'http://del .icio.us/favicon.ico',241 faviconURL: 'http://delicious.com/favicon.ico', 241 242 pageURL: pageURL 242 243 }); … … 274 275 decode(xhr.responseText); 275 276 */ 276 var json = jsonDecode(xhr.re ponseText);277 var json = jsonDecode(xhr.responseText); 277 278 if (json && json.isSuccess){ 278 279 let c = new SBMContainer('l', json.total_clip_count, { … … 282 283 json.Comments.forEach(function(clip){ 283 284 c.add( clip.livedoor_id, new Date(clip.created_on * 1000), 284 clip.notes ? clip.notes .replace(/</g,'<').replace(/>/g,'>'): '',285 clip.notes ? clip.notes : '', 285 286 clip.tags, 286 287 { … … 472 473 if (openToBrowser) 473 474 // TODO 474 manager.open(cacheManager.get(url,type).toHTML String(format,false), liberator.forceNewTab);475 manager.open(cacheManager.get(url,type).toHTML(format,false), liberator.forceNewTab); 475 476 else 476 liberator.echo(cacheManager.get(url, type).toHTML String(format,countOnly), true);477 liberator.echo(cacheManager.get(url, type).toHTML(format,countOnly), true); 477 478 } else { 478 479 try {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)