For the latest updates, send a blank email to our SUBSCRIPTION ADDRESS
HEADLINES | CLASSIFIED | SPORTS | FORUM | BUSINESS | ENTERTAINMENT
Vol. 1, Issue 9
The News Organ of Liberty City
Thursday October 18th, 2001
Seplogo.gif
" Yesterday's News Today "

MediaWiki:Monobook.js: Difference between revisions

From Liberty Tree
Jump to navigationJump to search
(Created page with "→‎All JavaScript here will be loaded for users of the MonoBook skin: $(document).ready(function(){ var $archives = $("#p-ARCHIVES"); var dropdownTitle = $archives.find("h3").text(); var $label = $("<label>").attr("for", "archive-select").text(dropdownTitle); var $select = $("<select>") .attr("id", "archive-select"); var $defaultOption = $("<option>") .attr("value", "") .text(dropdo...")
 
No edit summary
Line 2: Line 2:


$(document).ready(function(){
$(document).ready(function(){
   var $archives = $("#p-ARCHIVES");
   // Helper function that converts a container into a select dropdown.
  var dropdownTitle = $archives.find("h3").text();
  function createSelectFromContainer(containerSelector, selectId) {
 
    var $container = $(containerSelector);
  var $label = $("<label>").attr("for", "archive-select").text(dropdownTitle);
    var dropdownTitle = $container.find("h3").text();
 
   
  var $select = $("<select>")
    // Create a label element.
                  .attr("id", "archive-select");
    var $label = $("<label>").attr("for", selectId).text(dropdownTitle);
 
   
  var $defaultOption = $("<option>")
    // Create the select element.
    var $select = $("<select>").attr("id", selectId);
   
    // Add a default, disabled option.
    var $defaultOption = $("<option>")
                           .attr("value", "")
                           .attr("value", "")
                           .text(dropdownTitle)
                           .text(dropdownTitle)
                           .prop("disabled", true)
                           .prop("disabled", true)
                           .prop("selected", true);
                           .prop("selected", true);
  $select.append($defaultOption);
    $select.append($defaultOption);
 
   
  $archives.find("div > ul > li").each(function(){
    // Create options from each list item.
    var $anchor = $(this).find("a");
    $container.find("div > ul > li").each(function(){
    var text = $anchor.text();
      var $anchor = $(this).find("a");
    var value = $anchor.attr("href") || text;
      var text = $anchor.text();
    var $option = $("<option>").attr("value", value).text(text);
      var value = $anchor.attr("href") || text;
    $select.append($option);
      var $option = $("<option>").attr("value", value).text(text);
  });
      $select.append($option);
 
    });
  // Append the new elements to the container.
   
  $archives.empty().append($label).append($select);
    // Replace the container's content with the label and the new select.
    $container.empty().append($label).append($select);
   
    // Bind a change event that redirects based on the selected option.
    $select.on("change", function(){
      var url = $(this).val();
      if (url) {
        window.location.href = url;
      }
    });
  }
    
    
   // Attach the change event handler via jQuery.
   // Apply the transformation to both containers.
   $("#archive-select").on("change", function(){
   createSelectFromContainer("#p-ARCHIVES", "archive-select");
    var url = $(this).val();
  createSelectFromContainer("#p-ARCHIVES-mobilejs", "archive-select-mobilejs");
    if (url) {
      window.location.href = url;
    }
  });
});
});

Revision as of 11:05, 6 February 2025

/* All JavaScript here will be loaded for users of the MonoBook skin */

$(document).ready(function(){
  // Helper function that converts a container into a select dropdown.
  function createSelectFromContainer(containerSelector, selectId) {
    var $container = $(containerSelector);
    var dropdownTitle = $container.find("h3").text();
    
    // Create a label element.
    var $label = $("<label>").attr("for", selectId).text(dropdownTitle);
    
    // Create the select element.
    var $select = $("<select>").attr("id", selectId);
    
    // Add a default, disabled option.
    var $defaultOption = $("<option>")
                          .attr("value", "")
                          .text(dropdownTitle)
                          .prop("disabled", true)
                          .prop("selected", true);
    $select.append($defaultOption);
    
    // Create options from each list item.
    $container.find("div > ul > li").each(function(){
      var $anchor = $(this).find("a");
      var text = $anchor.text();
      var value = $anchor.attr("href") || text;
      var $option = $("<option>").attr("value", value).text(text);
      $select.append($option);
    });
    
    // Replace the container's content with the label and the new select.
    $container.empty().append($label).append($select);
    
    // Bind a change event that redirects based on the selected option.
    $select.on("change", function(){
      var url = $(this).val();
      if (url) {
        window.location.href = url;
      }
    });
  }
  
  // Apply the transformation to both containers.
  createSelectFromContainer("#p-ARCHIVES", "archive-select");
  createSelectFromContainer("#p-ARCHIVES-mobilejs", "archive-select-mobilejs");
});