From 9bdfa4d5c403775bb2ebb54af5f856e14e492b3a Mon Sep 17 00:00:00 2001 From: teramako Date: Sat, 22 Nov 2008 10:18:02 +0000 Subject: * follow 2.0pre * fix: livedoorclip git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@24643 d0d07461-0603-4401-acd4-de1884942a52 --- sbmcommentsviewer.js | 77 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'sbmcommentsviewer.js') diff --git a/sbmcommentsviewer.js b/sbmcommentsviewer.js index ee8e8f7..cf9ca1d 100644 --- a/sbmcommentsviewer.js +++ b/sbmcommentsviewer.js @@ -65,26 +65,28 @@ SBMContainer.prototype = { //{{{ id, timestamp, comment, tags, extra )); }, - toHTMLString: function(format, countOnly){ - var label = (this.faviconURL ? '' : '') + - manager.type[this.type] + ' ' + this.count + '(' + this.entries.length + ')' + - (this.pageURL ? ' ' + this.pageURL + '' : ''); + toHTML: function(format, countOnly){ + var label = <> + {this.faviconURL ? : <>} + {manager.type[this.type] + ' ' + this.count + '(' + this.entries.length + ')'} + {this.pageURL ? {this.pageURL} : <>} + ; if (countOnly){ return label; } else { - let str = [ - '' - ]; - format.forEach(function(colum){ - let name = manager.format[colum] || '-'; - str.push(''); - }); - str.push(''); - this.entries.forEach(function(e){ - str.push(e.toHTMLString(format)); - }); - str.push('
' + label + '
' + name + '
'); - return str.join(''); + let xml = + + +
{label}
; + let self = this; + xml.*[xml.*.length()-1].* += (function(){ + var thead = ; + format.forEach(function(colum){ thead.* += {manager.format[colum] || '-'}; }); + var tbody = <>; + self.entries.forEach(function(e){ tbody += e.toHTML(format); }); + return thead + tbody; + })(); + return xml; } } }; //}}} @@ -112,32 +114,31 @@ function SBMEntry(id, timestamp, comment, tags, extra){ //{{{ } } //}}} SBMEntry.prototype = { //{{{ - toHTMLString: function(format){ - // E4X で書く手もあるけど、liberator.echoを使って出力すると - // toString後に"\n"が
に変換されてしまうのでStringで - var str = ['']; + toHTML: function(format){ + var xml = ; var self = this; format.forEach(function(colum){ switch(colum){ case 'id': - str.push('' + (self.userIcon ? '

' : '') + - '

' + self.id + '

'); + xml.* += + {self.userIcon ? <> {self.id} : {self.id}} + ; break; case 'timestamp': - str.push('' + self.formatDate() + ''); break; + xml.* += {self.formatDate()}; break; case 'tags': - str.push('' + self.tags.join(',') + ''); break; + xml.* += {self.tags.join(',')}; break; case 'comment': - str.push('' + self.comment + ''); break; + xml.* += {self.comment}; break; case 'tagsAndComment': - tagString = self.tags.length ? '[' + self.tags.join('][') + ']':''; - str.push('' + tagString + ' ' + self.comment + ''); break; + var tagString = self.tags.length ? '[' + self.tags.join('][') + ']':''; + xml.* += {tagString + ' '+self.comment}; + break; default: - str.push('-'); + xml.* += -; } }); - str.push(''); - return str.join(''); + return xml; }, formatDate: function(){ if (!this.timeStamp) return ''; @@ -180,9 +181,9 @@ function openSBM(url, type, format, countOnly, openToBrowser){ if (!sbmContainer) return; cacheManager.add(sbmContainer, url, type); if (openToBrowser) - manager.open(sbmContainer.toHTMLString(format,false)); + manager.open(sbmContainer.toHTML(format,false)); else - liberator.echo(sbmContainer.toHTMLString(format,countOnly), true); + liberator.echo(sbmContainer.toHTML(format,countOnly), true); } else { liberator.echoerr(sbmURL + ' ' + xhr.status, true); } @@ -237,7 +238,7 @@ var SBM = { //{{{ liberator.log(e); } var c = new SBMContainer('d', items.length, { - faviconURL: 'http://del.icio.us/favicon.ico', + faviconURL: 'http://delicious.com/favicon.ico', pageURL: pageURL }); items.forEach(function(item){ @@ -273,7 +274,7 @@ var SBM = { //{{{ getService(Components.interfaces.nsIJSON). decode(xhr.responseText); */ - var json = jsonDecode(xhr.reponseText); + var json = jsonDecode(xhr.responseText); if (json && json.isSuccess){ let c = new SBMContainer('l', json.total_clip_count, { faviconURL: 'http://clip.livedoor.com/favicon.ico', @@ -281,7 +282,7 @@ var SBM = { //{{{ }); json.Comments.forEach(function(clip){ c.add( clip.livedoor_id, new Date(clip.created_on * 1000), - clip.notes ? clip.notes.replace(//g,'>') : '', + clip.notes ? clip.notes : '', clip.tags, { userIcon: 'http://image.clip.livedoor.com/profile/' + @@ -471,9 +472,9 @@ commands.addUserCommand(['viewSBMComments'], 'SBM Comments Viewer', //{{{ liberator.log('cache avairable'); if (openToBrowser) // TODO - manager.open(cacheManager.get(url,type).toHTMLString(format,false), liberator.forceNewTab); + manager.open(cacheManager.get(url,type).toHTML(format,false), liberator.forceNewTab); else - liberator.echo(cacheManager.get(url, type).toHTMLString(format,countOnly), true); + liberator.echo(cacheManager.get(url, type).toHTML(format,countOnly), true); } else { try { openSBM(url, type, format, countOnly, openToBrowser); -- cgit v1.2.3