Widget:Pagination: Difference between revisions

From TwogPedia
(Created page with "<includeonly> <button data-page="1" id="currentPage" onclick="updateTemplate()">Load more</button> <script> function updateTemplate() { var parameters = ''; var currentPageEl = document.getElementById("currentPage") var currentPage = parseInt(currentPageEl?.dataset.page) + 1; var contentContainer = document.getElementById("<!--{$id|escape:'html'}-->"); // Loop through all the parameters given <!--{foreach from=$arg key=key item=item}--> paramete...")
 
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:


function updateTemplate() {
function updateTemplate() {
   var parameters = '';
   var parameters = '';
    
    
Line 14: Line 13:
   var contentContainer = document.getElementById("<!--{$id|escape:'html'}-->");
   var contentContainer = document.getElementById("<!--{$id|escape:'html'}-->");


   // Loop through all the parameters given
   var encodedParams = "<!--{$arg|escape:'javascript'}-->"
  <!--{foreach from=$arg key=key item=item}-->
  var sentParams = {}
    parameters += '|' + "<!--{$key|escape:'html'}-->" + '=' + "<!--{$item|escape:'html'}-->"
  if ( encodedParams ) sentParams = JSON.parse(encodedParams)
  <!--{/foreach}-->
 
  for (let key in sentParams) {
      parameters += '|' + key + '=' + sentParams[key]
  }


   parameters += '|page=' + currentPage + '|more=true|template=' + "<!--{$template|escape:'html'}-->"
   parameters += '|page=' + currentPage + '|more=true|template=' + "<!--{$template|escape:'html'}-->"
Line 25: Line 27:


   // Replace the content in the dynamic content container with the parsed template
   // Replace the content in the dynamic content container with the parsed template
   $.get(mw.util.wikiScript('api'), { action: 'parse', format: 'json', text: parserFunction }, function(data) {
   $.get(mw.util.wikiScript('api'), { action: 'parse', format: 'json', text: parserFunction }, function(data) {
     var parsedContent = data.parse.text['*'];
     var parsedContent = data.parse.text['*'];
Line 41: Line 42:
     }  
     }  
   });
   });
}
}


</script>
</script>
</includeonly>
</includeonly>

Latest revision as of 21:20, 28 July 2023