Ero sivun ”Widget:ThreadsX” versioiden välillä
Järvi-meriwikistä
(19 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 1: | Rivi 1: | ||
<includeonly> | <includeonly> | ||
+ | |||
<div id="<!--{$id|default:JwThreads|escape:'html'}-->_container"></div> | <div id="<!--{$id|default:JwThreads|escape:'html'}-->_container"></div> | ||
+ | |||
<script type="text/javascript"> | <script type="text/javascript"> | ||
− | function <!--{$id|default:JwThreads|escape:'html'}-->_func() { | + | function <!--{$id|default:JwThreads|escape:'html'}-->_func() { |
− | + | var page = "<!--{$page|default:x|escape:'html'}-->"; | |
− | + | var amountNr = <!--{$amount|default:5|escape:'html'}-->; | |
− | + | var lang = "<!--{$lang|default:fi|escape:'html'}-->"; | |
+ | var nothreads = "<!--{$nothreads|default:Nothreads|escape:'html'}-->"; | ||
− | + | var searchStr = "action=query"; | |
− | + | searchStr += "&list=threads&thdir=older&thlimit=" + amountNr.toString(); | |
− | + | if (page != 'x') { searchStr += '&thpage=' + page; } | |
− | searchStr += "& | + | |
− | + | searchStr += "&thrender=true"; | |
+ | searchStr += "&thprop=subject|page|parent|created|author|id"; | ||
+ | searchStr += "&format=json"; | ||
+ | |||
+ | function success(request) { | ||
− | + | console.log( request ); | |
− | + | ||
− | + | var threads = request.query.threads; | |
− | + | var threadsA = []; | |
− | + | var threadsO = {}; | |
+ | /* | ||
+ | for ( var t in threads ) { threadsA.push( threads[ t ] ); } | ||
+ | threadsA.sort(function(a,b) { return parseFloat(a.created) - parseFloat(b.created) } ); | ||
− | + | for ( var t in threadsA ) { | |
− | + | id = threadsA[ t ].id; | |
− | + | parent = threadsA[ t ].parent; | |
− | + | if ( parent === null ) { | |
+ | threadsO[ id ]; | ||
+ | if ( typeof threadsO[ threadsA[ t ].id ] | ||
+ | threadsO.push( threads[ t ] ); } | ||
+ | |||
+ | console.log(threadsA); | ||
+ | */ | ||
+ | var threadsArr = new Array(); | ||
+ | var output = '<div class="rss-box"><ul class="lake-rss-items">'; | ||
+ | var alternate = 0; | ||
− | + | for (var x in threads) { threadsArr.push(threads[x]); } | |
− | + | threadsArr.sort(function(a,b) { | |
− | + | return parseFloat(b.created) - parseFloat(a.created) | |
− | + | } ); | |
− | + | var added = 0; | |
− | + | for (var y=0; y<threadsArr.length; y++) { | |
− | + | ||
− | + | if (threadsArr[y].pagens == 1 || (threadsArr[y].pagens == 5 && threadsArr[y].pagetitle.indexOf('Hiekkalaatikko') == -1)) { | |
− | + | nicepage = threadsArr[y].pagetitle.replace(/^.+:/, ''); | |
− | + | //href = '//www.jarviwiki.fi/wiki/Viestiketju:' + encodeURI(threadsArr[y].pagetitle) + '/' + threadsArr[y].subject.split('?').join('%3F').split('"').join('%22') + '#' + encodeURI(threadsArr[y].subject) + '_' + threadsArr[y].id; | |
− | + | href = '//www.jarviwiki.fi/wiki/' + encodeURI(threadsArr[y].pagetitle) + '#' + threadsArr[y].subject.split(' ').join('_').split('ä').join('.C3.A4').split('?').join('.3F').split('"').join('.22') + '_' + threadsArr[y].id; | |
− | + | dateStr = threadsArr[y].created; | |
− | + | created = new Date(dateStr.substr(0,4), (parseInt(dateStr.substr(4,2)) - 1), (parseInt(dateStr.substr(6,2)))); | |
− | + | alternate++; | |
− | + | output += '<li class="rss-item alternate' + parseInt(alternate % 2) + '">'; | |
− | + | output += '<h6 class="rss-heading"><a class="rss-item" href="' + href + '" title="' + threadsArr[y].subject + '">' + threadsArr[y].subject + '</a></h6>'; | |
− | + | output += '<p class="rss-author"><a href="//www.jarviwiki.fi/wiki/Käyttäjä:' + encodeURI(threadsArr[y].author.name) + '">' + threadsArr[y].author.name + '</a> '; | |
− | + | if (threadsArr[y].parent == null) { | |
− | + | if (lang == 'sv') { | |
− | + | output += 'startade <b>en ny tråd</b>.'; | |
− | + | } else if (lang == 'en') { | |
− | + | output += 'started <b>a new thread</b>.'; | |
+ | } else { | ||
+ | output += 'aloitti <b>uuden keskustelun</b>.'; | ||
+ | } | ||
} else { | } else { | ||
− | output += ' | + | if (lang == 'sv') { |
+ | output += 'kommenterade tråden.'; | ||
+ | } else if (lang == 'en') { | ||
+ | output += 'commented on a thread.'; | ||
+ | } else { | ||
+ | output += 'kommentoi keskustelua.'; | ||
+ | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | output += '<p class="rss-date">' + created.inRelationToToday(lang) + '</p>'; | |
− | + | output += '</li>'; | |
− | + | added++; | |
− | + | } | |
− | + | if (added >= amountNr) { break; } | |
− | + | } | |
+ | |||
+ | if (added == 0) { | ||
+ | output += nothreads; | ||
+ | } | ||
− | + | output += '</ul></div>'; | |
− | + | jQuery("#<!--{$id|default:JwThreads|escape:'html'}-->_container").append(output); | |
− | + | } | |
− | + | jQuery.ajax({ | |
− | + | type: 'GET', | |
− | + | url: "//www.jarviwiki.fi/w/api.php", | |
− | + | data: searchStr, | |
− | + | success: success, | |
− | + | dataType: 'jsonp' | |
− | + | }); | |
− | } | + | } |
function <!--{$id|default:JwThreads|escape:'html'}-->_jQueryTest() { | function <!--{$id|default:JwThreads|escape:'html'}-->_jQueryTest() { |